Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ src/tscore/ParseRulesCType
src/tscore/ParseRulesCTypeToLower
src/tscore/ParseRulesCTypeToUpper
src/tscore/mkdfa
src/tscore/test_arena
src/tscore/test_atomic
src/tscore/test_freelist
src/tscore/test_Vec
Expand Down
6 changes: 2 additions & 4 deletions src/tscore/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
include $(top_srcdir)/build/tidy.mk

noinst_PROGRAMS = mkdfa CompileParseRules
check_PROGRAMS = test_arena test_atomic test_freelist test_geometry test_Vec test_X509HostnameValidator test_tscore
check_PROGRAMS = test_atomic test_freelist test_geometry test_Vec test_X509HostnameValidator test_tscore

TESTS_ENVIRONMENT = LSAN_OPTIONS=suppressions=suppression.txt

Expand Down Expand Up @@ -237,9 +237,6 @@ test_atomic_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la
test_freelist_SOURCES = test_freelist.cc
test_freelist_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@

test_arena_SOURCES = test_arena.cc
test_arena_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@

test_Vec_SOURCES = test_Vec.cc
test_Vec_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@

Expand All @@ -258,6 +255,7 @@ test_tscore_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la
test_tscore_SOURCES = \
unit_tests/unit_test_main.cc \
unit_tests/test_AcidPtr.cc \
unit_tests/test_arena.cc \
unit_tests/test_ArgParser.cc \
unit_tests/test_BufferWriter.cc \
unit_tests/test_BufferWriterFormat.cc \
Expand Down
49 changes: 8 additions & 41 deletions src/tscore/test_arena.cc → src/tscore/unit_tests/test_arena.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/****************************************************************************

ArenaTest.cc
test_arena.cc

Description:

Expand All @@ -33,6 +33,8 @@

****************************************************************************/

#include "catch.hpp"

#include "tscore/Arena.h"
#include <cstdio>

Expand All @@ -47,29 +49,11 @@ fill_test_data(char *ptr, int size, int seed)
}
}

int
check_test_data(char *ptr, int size, int seed)
{
int fail = 0;
char a = 'a' + (seed % 52);

for (int i = 0; i < size; i++) {
if (ptr[i] != a) {
fail++;
}
a = (a + 1) % 52;
}

return fail;
}

int
test_block_boundries()
TEST_CASE("test arena", "[libts][arena]")
{
const int sizes_to_test = 12;
const int regions_to_test = 1024 * 2;
char **test_regions = new char *[regions_to_test];
int failures = 0;
Arena *a = new Arena();

for (int i = 0; i < sizes_to_test; i++) {
Expand All @@ -89,14 +73,12 @@ test_block_boundries()

// Now check to make sure the data is correct
for (j = 0; j < regions_to_test; j++) {
int f = check_test_data(test_regions[j], test_size, j);

if (f != 0) {
fprintf(stderr, "block_boundries test failed. size %d region %d\n", test_size, j);
failures++;
char a = 'a' + (j % 52);
for (int k = 0; k < test_size; k++) {
REQUIRE(test_regions[j][k] == a);
a = (a + 1) % 52;
}
}

// Now free the regions
for (j = 0; j < regions_to_test; j++) {
a->free(test_regions[j], test_size);
Expand All @@ -107,19 +89,4 @@ test_block_boundries()

delete[] test_regions;
delete a;
return failures;
}

int
main()
{
int failures = 0;

failures += test_block_boundries();

if (failures) {
return 1;
} else {
return 0;
}
}