aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2020-09-10 21:31:26 +0100
committerTomasz Kramkowski <tk@the-tk.com>2020-09-10 21:31:26 +0100
commit7e0a7379352fbaf96ecd478b6b428a6d1c18ac1f (patch)
tree48cc42fb5b1ade8d420ffa3557de368f54940b31
parentb270e1fba25e48e972900f7ea391eedba5ce7672 (diff)
downloadpack-7e0a7379352fbaf96ecd478b6b428a6d1c18ac1f.tar.gz
pack-7e0a7379352fbaf96ecd478b6b428a6d1c18ac1f.tar.xz
pack-7e0a7379352fbaf96ecd478b6b428a6d1c18ac1f.zip
Use sections to generate list of tests
-rw-r--r--test_gen.c2
-rw-r--r--unpack_test.c29
2 files changed, 11 insertions, 20 deletions
diff --git a/test_gen.c b/test_gen.c
index 0687146..7b36afc 100644
--- a/test_gen.c
+++ b/test_gen.c
@@ -148,7 +148,7 @@ static void generate_simple(FILE *out, enum fmt fmt)
sign = islower(fi->fmt);
- fprintf(out, "TEST(%s)\n", cname(fi->type));
+ fprintf(out, "TEST(%s, \"simple unpack %s\")\n", cname(fi->type), fi->type);
fprintf(out, "{\n");
fprintf(out, "\t%s v[1] = { __LINE__ };\n", fi->type);
for (size_t e = 0; e < sizeof endian / sizeof endian[0]; e++) {
diff --git a/unpack_test.c b/unpack_test.c
index d6e5a5e..a9e599b 100644
--- a/unpack_test.c
+++ b/unpack_test.c
@@ -16,9 +16,12 @@ struct test {
char *desc;
};
-#define TEST(name) static bool test_##name(void)
-#define TEST_ENTRY(name, description) { test_##name, description }
-#define TEST_ENTRY_END { NULL, NULL }
+#define TEST(name, desc) static bool test_##name(void); \
+ static struct test testinfo_##name \
+ __attribute__((__section__("tests"))) \
+ __attribute__((__used__)) = \
+ { test_##name, desc }; \
+ static bool test_##name(void)
#define DATA(...) (unsigned char []){ __VA_ARGS__ }, sizeof (unsigned char []){ __VA_ARGS__ }
#define CHECK(test) if (!(test)) { puts("! " #test); return false; }
@@ -35,22 +38,10 @@ struct test {
int main(void)
{
+ extern struct test __start_tests, __stop_tests;
+
pack_trace = PACK_TRACE_OFF;
- struct test tests[] = {
- TEST_ENTRY(signed_char, "signed char unpacking"),
- TEST_ENTRY(unsigned_char, "unsigned char unpacking"),
- TEST_ENTRY(signed_short, "signed short unpacking"),
- TEST_ENTRY(unsigned_short, "unsigned short unpacking"),
- TEST_ENTRY(signed_int, "signed int unpacking"),
- TEST_ENTRY(unsigned_int, "unsigned int unpacking"),
- TEST_ENTRY(signed_long, "signed long unpacking"),
- TEST_ENTRY(unsigned_long, "unsigned long unpacking"),
- TEST_ENTRY(signed_long_long, "signed long long unpacking"),
- TEST_ENTRY(unsigned_long_long, "unsigned long long unpacking"),
- TEST_ENTRY_END
- };
-
- for (int i = 0; tests[i].func != NULL; i++)
- printf("%s %s\n", tests[i].func() ? " OK " : "FAIL", tests[i].desc);
+ for (struct test *t = &__start_tests; t < &__stop_tests; t++)
+ printf("%s %s\n", t->func() ? " OK " : "FAIL", t->desc);
}