Skip to content

Commit

Permalink
SUITE_NAME
Browse files Browse the repository at this point in the history
  • Loading branch information
nelhage committed Jun 26, 2010
1 parent b34759d commit 5a97c6d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 37 deletions.
46 changes: 24 additions & 22 deletions test/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ static void gc_core_teardown(void) {
gc_pop_roots();
}

BEGIN_SUITE(gc, "GC Test Suite");
#define SUITE_NAME gc

BEGIN_TEST_CASE(gc, core, "GC Core");
DEFINE_FIXTURE(gc, core, gc_core_setup, gc_core_teardown);
BEGIN_SUITE("GC Test Suite");

TEST(gc, core, sanity_check)
BEGIN_TEST_CASE(core, "GC Core");
DEFINE_FIXTURE(core, gc_core_setup, gc_core_teardown);

TEST(core, sanity_check)
{
reg1 = sc_alloc_cons();
sc_set_car(reg1, sc_make_number(32));
Expand All @@ -44,15 +46,15 @@ TEST(gc, core, sanity_check)
}
END_TEST

TEST(gc, core, booleans)
TEST(core, booleans)
{
fail_unless(sc_booleanp(sc_true));
fail_unless(sc_booleanp(sc_false));
fail_unless(sc_true != sc_false);
}
END_TEST

TEST(gc, core, objs_survive_gc)
TEST(core, objs_survive_gc)
{
reg1 = sc_alloc_cons();
sc_set_car(reg1, sc_make_number(32));
Expand All @@ -73,7 +75,7 @@ TEST(gc, core, objs_survive_gc)
}
END_TEST

TEST(gc, core, frees_mem)
TEST(core, frees_mem)
{
#ifndef TEST_STRESS_GC
uint32_t free_mem;
Expand All @@ -88,7 +90,7 @@ TEST(gc, core, frees_mem)
}
END_TEST

TEST(gc, core, cons_cycle)
TEST(core, cons_cycle)
{
uint32_t free_mem;
reg1 = sc_alloc_cons();
Expand Down Expand Up @@ -124,7 +126,7 @@ TEST(gc, core, cons_cycle)
}
END_TEST

TEST(gc, core, basic_vector)
TEST(core, basic_vector)
{
int i;
reg1 = sc_alloc_vector(10);
Expand All @@ -144,7 +146,7 @@ TEST(gc, core, basic_vector)
}
END_TEST

TEST(gc, core, large_allocs)
TEST(core, large_allocs)
{
int i;
for(i=0;i<2000;i++) {
Expand All @@ -159,7 +161,7 @@ TEST(gc, core, large_allocs)
}
END_TEST

TEST(gc, core, many_allocs)
TEST(core, many_allocs)
{
int i;
reg2 = reg1 = sc_alloc_cons();
Expand All @@ -186,7 +188,7 @@ void gc_reloc_external() {
gc_relocate(&external_root);
}

TEST(gc, core, root_hook)
TEST(core, root_hook)
{
gc_register_gc_root_hook(gc_reloc_external);
external_root = sc_alloc_cons();
Expand All @@ -201,7 +203,7 @@ TEST(gc, core, root_hook)
}
END_TEST

TEST(gc, core, roots)
TEST(core, roots)
{
gc_handle reg;

Expand All @@ -222,7 +224,7 @@ TEST(gc, core, roots)
}
END_TEST

TEST(gc, core, live_roots)
TEST(core, live_roots)
{
gc_handle reg;
reg = reg1 = sc_alloc_cons();
Expand All @@ -241,7 +243,7 @@ TEST(gc, core, live_roots)
}
END_TEST

END_TEST_CASE(gc, core);
END_TEST_CASE(core);

static void obarray_setup() {
obarray_init();
Expand All @@ -251,11 +253,11 @@ static void obarray_teardown() {

}

BEGIN_TEST_CASE(gc, obarray, "obarray");
DEFINE_FIXTURE(gc, obarray, gc_core_setup, gc_core_teardown);
DEFINE_FIXTURE(gc, obarray, obarray_setup, obarray_teardown);
BEGIN_TEST_CASE(obarray, "obarray");
DEFINE_FIXTURE(obarray, gc_core_setup, gc_core_teardown);
DEFINE_FIXTURE(obarray, obarray_setup, obarray_teardown);

TEST(gc, obarray, sancheck)
TEST(obarray, sancheck)
{
reg1 = sc_intern_symbol("hello");
fail_unless(sc_symbolp(reg1));
Expand All @@ -265,7 +267,7 @@ TEST(gc, obarray, sancheck)
}
END_TEST

TEST(gc, obarray, realloc)
TEST(obarray, realloc)
{
int i;
char str[2] = "a";
Expand All @@ -283,8 +285,8 @@ TEST(gc, obarray, realloc)
}
END_TEST

END_TEST_CASE(gc, obarray);
END_SUITE(gc);
END_TEST_CASE(obarray);
END_SUITE;

Suite *gc_suite()
{
Expand Down
44 changes: 29 additions & 15 deletions test/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ struct test_suite {
const char *suite_name;
};

#define BEGIN_SUITE(sym, name) \
#define BEGIN_SUITE(name) _BEGIN_SUITE(SUITE_NAME, name)
#define _BEGIN_SUITE(sym, name) __BEGIN_SUITE(sym, name)
#define __BEGIN_SUITE(sym, name) \
extern struct test_case _begin_ ## sym ## _cases[]; \
extern struct test_case _end_ ## sym ## _cases[]; \
struct test_suite _suite_ ## sym = { \
Expand All @@ -31,11 +33,14 @@ struct test_suite {
struct test_case _begin_ ## sym ## _cases[0] \
__attribute__((section(".data." #sym ".cases"))); \

#define BEGIN_TEST_CASE(suite, test, name) \
_BEGIN_TEST_CASE(suite, suite ## _ ## test, \
#define BEGIN_TEST_CASE(test, name) _BEGIN_TEST_CASE(SUITE_NAME, test, name)
#define _BEGIN_TEST_CASE(sym, test, name) __BEGIN_TEST_CASE(sym, test, name)

#define __BEGIN_TEST_CASE(suite, test, name) \
_BEGIN_TEST_CASE_IMPL(suite, suite ## _ ## test, \
".data." #suite "." #test, name)

#define _BEGIN_TEST_CASE(suite, sym, sec, name) \
#define _BEGIN_TEST_CASE_IMPL(suite, sym, sec, name) \
extern test_func _begin_ ## sym ## _funcs[]; \
extern test_hook _begin_ ## sym ## _setup[]; \
extern test_hook _begin_ ## sym ## _teardown[]; \
Expand All @@ -60,8 +65,10 @@ struct test_suite {
__attribute__((section(sec ".teardown"))) \


#define DEFINE_FIXTURE(suite, test, setup, teardown) \
_SETUP_HOOK(suite, test, setup) \
#define DEFINE_FIXTURE(test, setup, teardown) \
_DEFINE_FIXTURE(SUITE_NAME, test, setup, teardown)
#define _DEFINE_FIXTURE(suite, test, setup, teardown) \
_SETUP_HOOK(suite, test, setup) \
_TEARDOWN_HOOK(suite, test, teardown)

#define _SETUP_HOOK(suite, test, hook) \
Expand All @@ -74,30 +81,37 @@ struct test_suite {
__attribute__((section(".data." #suite "." #test ".teardown"))) = \
hook;

#define TEST(suite, test, fn) \
_TEST(suite ## _ ## test, \
".data." #suite "." #test, \
suite##_##test##_##fn)

#define _TEST(sym, sec, fn) \
#define TEST(test, fn) _TEST(SUITE_NAME, test, fn)
#define _TEST(sym, test, fn) __TEST(sym, test, fn)
#define __TEST(suite, test, fn) \
_TEST_IMPL(suite ## _ ## test, \
".data." #suite "." #test, \
suite##_##test##_##fn)

#define _TEST_IMPL(sym, sec, fn) \
static void fn(int); \
test_func _test_##fn __used \
__attribute__((section(sec ".funcs"))) = fn; \
START_TEST(fn)

#define END_TEST_CASE(suite, test) \
_END_TEST_CASE(suite ## _ ## test, \
#define END_TEST_CASE(test) _END_TEST_CASE(SUITE_NAME, test)
#define _END_TEST_CASE(sym, test) __END_TEST_CASE(sym, test)
#define __END_TEST_CASE(suite, test) \
_END_TEST_CASE_IMPL(suite ## _ ## test, \
".data." #suite "." #test) \

#define _END_TEST_CASE(sym, sec) \
#define _END_TEST_CASE_IMPL(sym, sec) \
test_func _end_ ## sym ## _funcs[0] \
__attribute__((section(sec ".funcs"))); \
test_hook _end_ ## sym ## _setup[0] \
__attribute__((section(sec ".setup"))); \
test_hook _end_ ## sym ## _teardown[0] \
__attribute__((section(sec ".teardown")))

#define END_SUITE(sym) \
#define END_SUITE _END_SUITE(SUITE_NAME)
#define _END_SUITE(sym) __END_SUITE(sym)
#define __END_SUITE(sym) \
struct test_case _end_##sym##_cases[0] \
__attribute__((section(".data." #sym ".cases")))

Expand Down

0 comments on commit 5a97c6d

Please sign in to comment.