diff --git a/examples/main.c b/examples/main.c index 8232adbb..f89d4a14 100644 --- a/examples/main.c +++ b/examples/main.c @@ -1,3 +1,7 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include @@ -5,9 +9,12 @@ void example_main(); -static void assert_cb(const char *file, const int line, const char *msg) -{ - fprintf(stderr, "%s:%i:%s\n", file, line, msg); +static void assert_cb( + const char *const file, + const int line, + const char *const msg +) { + fprintf(stderr, "%s:%d:%s\n", file, line, msg); abort(); } diff --git a/tests/Makefile.am b/tests/Makefile.am index e7975ff7..6031286f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,8 +12,7 @@ if WITH_MULTIBOOT2 noinst_PROGRAMS += multiboot2_header_print1 multiboot2_header_print1_LDADD = $(top_builddir)/libkernaux.la multiboot2_header_print1_SOURCES = \ - helper.c \ - helper.h \ + main.c \ multiboot2_header_print1.c \ multiboot2_header_example1.h endif @@ -26,8 +25,7 @@ if WITH_MULTIBOOT2 noinst_PROGRAMS += multiboot2_header_print2 multiboot2_header_print2_LDADD = $(top_builddir)/libkernaux.la multiboot2_header_print2_SOURCES = \ - helper.c \ - helper.h \ + main.c \ multiboot2_header_print2.c \ multiboot2_header_example2.h endif @@ -40,8 +38,7 @@ if WITH_MULTIBOOT2 noinst_PROGRAMS += multiboot2_info_print1 multiboot2_info_print1_LDADD = $(top_builddir)/libkernaux.la multiboot2_info_print1_SOURCES = \ - helper.c \ - helper.h \ + main.c \ multiboot2_info_print1.c \ multiboot2_info_example1.h endif @@ -54,8 +51,7 @@ if WITH_MULTIBOOT2 noinst_PROGRAMS += multiboot2_info_print2 multiboot2_info_print2_LDADD = $(top_builddir)/libkernaux.la multiboot2_info_print2_SOURCES = \ - helper.c \ - helper.h \ + main.c \ multiboot2_info_print2.c \ multiboot2_info_example2.h endif @@ -68,8 +64,7 @@ if WITH_ALLOC TESTS += test_alloc test_alloc_LDADD = $(top_builddir)/libkernaux.la test_alloc_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_alloc.c endif @@ -81,8 +76,7 @@ if WITH_CMDLINE TESTS += test_cmdline test_cmdline_LDADD = $(top_builddir)/libkernaux.la test_cmdline_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_cmdline.c endif @@ -95,8 +89,7 @@ if WITH_CMDLINE TESTS += test_cmdline_gen test_cmdline_gen_LDADD = $(top_builddir)/libkernaux.la test_cmdline_gen_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_cmdline_gen.c \ cmdline_gen.py \ cmdline_gen.jinja \ @@ -117,8 +110,7 @@ if WITH_ELF TESTS += test_elf test_elf_LDADD = $(top_builddir)/libkernaux.la test_elf_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_elf.c endif @@ -130,8 +122,7 @@ if WITH_MBR TESTS += test_mbr test_mbr_LDADD = $(top_builddir)/libkernaux.la test_mbr_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_mbr.c endif @@ -143,8 +134,7 @@ if WITH_MEMMAP TESTS += test_memmap test_memmap_LDADD = $(top_builddir)/libkernaux.la test_memmap_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_memmap.c endif @@ -156,8 +146,7 @@ if WITH_MULTIBOOT2 TESTS += test_multiboot2_common_packing test_multiboot2_common_packing_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_common_packing_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_multiboot2_common_packing.c \ multiboot2_header_example2.h \ multiboot2_info_example2.h @@ -171,8 +160,7 @@ if WITH_MULTIBOOT2 TESTS += test_multiboot2_header_helpers test_multiboot2_header_helpers_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_header_helpers_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_multiboot2_header_helpers.c \ multiboot2_header_example1.h \ multiboot2_header_example2.h @@ -189,8 +177,7 @@ test_multiboot2_header_print_DEPENDENCIES = \ multiboot2_header_print2 test_multiboot2_header_print_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_header_print_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_multiboot2_header_print.c endif @@ -202,8 +189,7 @@ if WITH_MULTIBOOT2 TESTS += test_multiboot2_header_validation test_multiboot2_header_validation_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_header_validation_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_multiboot2_header_validation.c \ multiboot2_header_example1.h \ multiboot2_header_example2.h @@ -217,8 +203,7 @@ if WITH_MULTIBOOT2 TESTS += test_multiboot2_info_helpers test_multiboot2_info_helpers_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_info_helpers_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_multiboot2_info_helpers.c \ multiboot2_info_example1.h \ multiboot2_info_example2.h @@ -235,8 +220,7 @@ test_multiboot2_info_print_DEPENDENCIES = \ multiboot2_info_print2 test_multiboot2_info_print_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_info_print_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_multiboot2_info_print.c endif @@ -248,8 +232,7 @@ if WITH_MULTIBOOT2 TESTS += test_multiboot2_info_validation test_multiboot2_info_validation_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_info_validation_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_multiboot2_info_validation.c \ multiboot2_info_example1.h \ multiboot2_info_example2.h @@ -263,8 +246,7 @@ if WITH_NTOA TESTS += test_ntoa test_ntoa_LDADD = $(top_builddir)/libkernaux.la test_ntoa_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_ntoa.c endif @@ -277,8 +259,7 @@ if WITH_NTOA TESTS += test_ntoa_assert test_ntoa_assert_LDADD = $(top_builddir)/libkernaux.la test_ntoa_assert_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_ntoa_assert.c endif endif @@ -291,8 +272,7 @@ if WITH_PFA TESTS += test_pfa test_pfa_LDADD = $(top_builddir)/libkernaux.la test_pfa_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_pfa.c endif @@ -305,8 +285,7 @@ if WITH_PFA TESTS += test_pfa_assert test_pfa_assert_LDADD = $(top_builddir)/libkernaux.la test_pfa_assert_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_pfa_assert.c endif endif @@ -320,8 +299,7 @@ if WITH_PRINTF_FMT TESTS += test_printf_fmt_gen test_printf_fmt_gen_LDADD = $(top_builddir)/libkernaux.la test_printf_fmt_gen_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_printf_fmt_gen.c \ printf_fmt_gen.py \ printf_fmt_gen.jinja \ @@ -343,8 +321,7 @@ if WITH_PRINTF TESTS += test_printf_gen test_printf_gen_LDADD = $(top_builddir)/libkernaux.la test_printf_gen_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_printf_gen.c \ printf_gen.py \ printf_gen.jinja \ @@ -366,7 +343,6 @@ if WITH_UNITS TESTS += test_units_human test_units_human_LDADD = $(top_builddir)/libkernaux.la test_units_human_SOURCES = \ - helper.c \ - helper.h \ + main.c \ test_units_human.c endif diff --git a/tests/cmdline_gen.jinja b/tests/cmdline_gen.jinja index cd763088..7852df3c 100644 --- a/tests/cmdline_gen.jinja +++ b/tests/cmdline_gen.jinja @@ -24,7 +24,7 @@ static void test( const char *const *const expected_argv ); -int main() +void test_main() { {% for case in cases %} { @@ -58,8 +58,6 @@ int main() ); } {% endfor %} - - return 0; } void test( diff --git a/tests/helper.h b/tests/helper.h deleted file mode 100644 index 5399734e..00000000 --- a/tests/helper.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef KERNAUX_INCLUDED_TESTS_HELPER -#define KERNAUX_INCLUDED_TESTS_HELPER - -#ifdef __cplusplus -extern "C" { -#endif - -void setup_assert_abort(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/tests/helper.c b/tests/main.c similarity index 59% rename from tests/helper.c rename to tests/main.c index 194afbc1..453b5054 100644 --- a/tests/helper.c +++ b/tests/main.c @@ -7,14 +7,9 @@ #include #include -static void assert_cb_abort(const char *file, int line, const char *msg); +void test_main(int argc, char **argv); -void setup_assert_abort() -{ - kernaux_assert_cb = assert_cb_abort; -} - -void assert_cb_abort( +static void assert_cb( const char *const file, const int line, const char *const msg @@ -22,3 +17,10 @@ void assert_cb_abort( fprintf(stderr, "%s:%d:%s\n", file, line, msg); abort(); } + +int main(int argc, char **argv) +{ + kernaux_assert_cb = assert_cb; + test_main(argc, argv); + exit(EXIT_SUCCESS); +} diff --git a/tests/multiboot2_header_print1.c b/tests/multiboot2_header_print1.c index 33e20ba4..b9608e08 100644 --- a/tests/multiboot2_header_print1.c +++ b/tests/multiboot2_header_print1.c @@ -18,7 +18,7 @@ static void my_printf(const char *format, ...) va_end(va); } -int main() +void test_main() { assert(KernAux_Multiboot2_Header_is_valid( (struct KernAux_Multiboot2_Header*)&multiboot2_header_example1 @@ -28,6 +28,4 @@ int main() (struct KernAux_Multiboot2_Header*)&multiboot2_header_example1, my_printf ); - - return 0; } diff --git a/tests/multiboot2_header_print2.c b/tests/multiboot2_header_print2.c index eff5bc83..faf79ec7 100644 --- a/tests/multiboot2_header_print2.c +++ b/tests/multiboot2_header_print2.c @@ -18,7 +18,7 @@ static void my_printf(const char *format, ...) va_end(va); } -int main() +void test_main() { assert(KernAux_Multiboot2_Header_is_valid( &multiboot2_header_example2.multiboot2_header @@ -28,6 +28,4 @@ int main() &multiboot2_header_example2.multiboot2_header, my_printf ); - - return 0; } diff --git a/tests/multiboot2_info_print1.c b/tests/multiboot2_info_print1.c index 5e044224..e4bc4112 100644 --- a/tests/multiboot2_info_print1.c +++ b/tests/multiboot2_info_print1.c @@ -18,7 +18,7 @@ static void my_printf(const char *format, ...) va_end(va); } -int main() +void test_main() { assert(KernAux_Multiboot2_Info_is_valid( (struct KernAux_Multiboot2_Info*)multiboot2_info_example1 @@ -28,6 +28,4 @@ int main() (struct KernAux_Multiboot2_Info*)multiboot2_info_example1, my_printf ); - - return 0; } diff --git a/tests/multiboot2_info_print2.c b/tests/multiboot2_info_print2.c index 705a0793..82007b65 100644 --- a/tests/multiboot2_info_print2.c +++ b/tests/multiboot2_info_print2.c @@ -18,7 +18,7 @@ static void my_printf(const char *format, ...) va_end(va); } -int main() +void test_main() { assert(KernAux_Multiboot2_Info_is_valid( &multiboot2_info_example2.multiboot2_info @@ -28,6 +28,4 @@ int main() &multiboot2_info_example2.multiboot2_info, my_printf ); - - return 0; } diff --git a/tests/printf_fmt_gen.jinja b/tests/printf_fmt_gen.jinja index 90cc611a..ecda4a07 100644 --- a/tests/printf_fmt_gen.jinja +++ b/tests/printf_fmt_gen.jinja @@ -6,7 +6,7 @@ #include -int main() +void test_main() { {% for case in cases %} { @@ -30,6 +30,4 @@ int main() assert(spec.base == {{ case.out.base }}); } {% endfor %} - - return 0; } diff --git a/tests/printf_gen.jinja b/tests/printf_gen.jinja index 5fc98d9c..faa7de1d 100644 --- a/tests/printf_gen.jinja +++ b/tests/printf_gen.jinja @@ -61,7 +61,7 @@ static void test(const char *const expected, const char *const format, ...) assert(strcmp(expected, buffer) == 0); } -int main() +void test_main() { #ifdef WITH_IO memset(buffer, '\0', sizeof(buffer)); @@ -81,6 +81,4 @@ int main() #endif {% endif %} {% endfor %} - - return 0; } diff --git a/tests/test_alloc.c b/tests/test_alloc.c index fe6a8c05..8523539a 100644 --- a/tests/test_alloc.c +++ b/tests/test_alloc.c @@ -4,8 +4,6 @@ #define KERNAUX_PRIVATE_NO -#include "helper.h" - #include #include @@ -14,12 +12,10 @@ static void test_default(); static void test_cross_zone_defrag(); -int main() +void test_main() { - setup_assert_abort(); test_default(); test_cross_zone_defrag(); - return 0; } void test_default() diff --git a/tests/test_cmdline.c b/tests/test_cmdline.c index cb109be2..618783f7 100644 --- a/tests/test_cmdline.c +++ b/tests/test_cmdline.c @@ -39,7 +39,7 @@ static const char *const argv_a_X4[] = { "a", "a", "a", "a" }; static const char *const argv_a_X5[] = { "a", "a", "a", "a", "a" }; static const char *const argv_a_X6[] = { "a", "a", "a", "a", "a", "a" }; -int main() +void test_main() { test("\\ \\ \\ \\ \\ \\ \\ \\ \\ ", 3, 0, true, "", 3, argv_spaceX3_X3); test("\\\\\\\\\\\\ \\\\\\\\\\\\ \\\\\\\\\\\\", 3, 0, true, "", 3, argv_backslashX3_X3); @@ -131,8 +131,6 @@ int main() test(buffer, 256, 4096, false, "buffer overflow", 0, NULL); free(buffer); } - - return 0; } void test( diff --git a/tests/test_elf.c b/tests/test_elf.c index baf6c90d..29f77fab 100644 --- a/tests/test_elf.c +++ b/tests/test_elf.c @@ -11,7 +11,7 @@ #define BUFFER_SIZE (1024 * 1024) -int main(int argc, char **argv) +void test_main(int argc, char **argv) { assert(argc >= 1); @@ -25,6 +25,4 @@ int main(int argc, char **argv) assert(KernAux_ELF_Header_is_valid((struct KernAux_ELF_Header*)buffer)); fclose(fd); - - return 0; } diff --git a/tests/test_mbr.c b/tests/test_mbr.c index 5c61898a..5ff45b36 100644 --- a/tests/test_mbr.c +++ b/tests/test_mbr.c @@ -9,7 +9,7 @@ static void create_valid_mbr(struct KernAux_Mbr *mbr); -int main() +void test_main() { struct KernAux_Mbr mbr; @@ -31,8 +31,6 @@ int main() } // TODO: test partition table - - return 0; } void create_valid_mbr(struct KernAux_Mbr *const mbr) diff --git a/tests/test_memmap.c b/tests/test_memmap.c index f075acf1..98638fca 100644 --- a/tests/test_memmap.c +++ b/tests/test_memmap.c @@ -48,7 +48,7 @@ static void expect_assert() #define MEMSET memset(memmap, 0xff, sizeof(memmap)) #define MEMMAP (*memmap) -int main() +void test_main() { kernaux_assert_cb = assert_cb; @@ -228,6 +228,4 @@ int main() } assert(assert_count_ctr == assert_count_exp); - - return 0; } diff --git a/tests/test_multiboot2_common_packing.c b/tests/test_multiboot2_common_packing.c index d47f2717..facf4222 100644 --- a/tests/test_multiboot2_common_packing.c +++ b/tests/test_multiboot2_common_packing.c @@ -74,7 +74,7 @@ info += 8 + (tag) + (data) + (align); \ } while (0) -int main() +void test_main() { assert(sizeof(struct KernAux_Multiboot2_Header) == 16); assert(sizeof(struct KernAux_Multiboot2_Info) == 8); @@ -161,6 +161,4 @@ int main() INFO2(efi_64bit_image_handle_ptr, 8, /**/ 0 ); INFO2(image_load_base_phys_addr, 4, /**/ 4 ); INFO0(none /**/ /**/ /**/ ); - - return 0; } diff --git a/tests/test_multiboot2_header_helpers.c b/tests/test_multiboot2_header_helpers.c index f2320b4e..5af933d1 100644 --- a/tests/test_multiboot2_header_helpers.c +++ b/tests/test_multiboot2_header_helpers.c @@ -7,8 +7,7 @@ #include "multiboot2_header_example1.h" #include "multiboot2_header_example2.h" -int main() +void test_main() { // TODO: write this - return 0; } diff --git a/tests/test_multiboot2_header_print.c b/tests/test_multiboot2_header_print.c index 97c8bdce..d43b3e52 100644 --- a/tests/test_multiboot2_header_print.c +++ b/tests/test_multiboot2_header_print.c @@ -71,7 +71,7 @@ static const char output2[] = " flags: 0\n" " size: 8\n"; -int main() +void test_main() { { FILE *const fd = popen("./multiboot2_header_print1", "r"); @@ -96,6 +96,4 @@ int main() const int status = pclose(fd); assert(status == 0); } - - return 0; } diff --git a/tests/test_multiboot2_header_validation.c b/tests/test_multiboot2_header_validation.c index 30a2860b..b4a65072 100644 --- a/tests/test_multiboot2_header_validation.c +++ b/tests/test_multiboot2_header_validation.c @@ -2,8 +2,7 @@ #include "config.h" #endif -int main() +void test_main() { // TODO: write this - return 0; } diff --git a/tests/test_multiboot2_info_helpers.c b/tests/test_multiboot2_info_helpers.c index b6667e8c..6fa90452 100644 --- a/tests/test_multiboot2_info_helpers.c +++ b/tests/test_multiboot2_info_helpers.c @@ -121,7 +121,7 @@ static const struct { #pragma pack(pop) #endif -int main() +void test_main() { assert(KernAux_Multiboot2_Info_is_valid( (struct KernAux_Multiboot2_Info*)multiboot2_info_example1 @@ -401,6 +401,4 @@ int main() &multiboot2_with_two_boot_cmd_lines.multiboot2_info ) == multiboot2_with_two_boot_cmd_lines.tag_boot_cmd_line1.cmdline ); - - return 0; } diff --git a/tests/test_multiboot2_info_print.c b/tests/test_multiboot2_info_print.c index 8692cf81..0310f5f8 100644 --- a/tests/test_multiboot2_info_print.c +++ b/tests/test_multiboot2_info_print.c @@ -268,7 +268,7 @@ static const char output2[] = " type: 0 (none)\n" " size: 8\n"; -int main() +void test_main() { { FILE *const fd = popen("./multiboot2_info_print1", "r"); @@ -293,6 +293,4 @@ int main() const int status = pclose(fd); assert(status == 0); } - - return 0; } diff --git a/tests/test_multiboot2_info_validation.c b/tests/test_multiboot2_info_validation.c index 0c2158b3..8fff14b2 100644 --- a/tests/test_multiboot2_info_validation.c +++ b/tests/test_multiboot2_info_validation.c @@ -786,7 +786,7 @@ static const struct { * main * ********/ -int main() +void test_main() { // Multiboot2 @@ -1129,6 +1129,4 @@ int main() assert(KernAux_Multiboot2_ITag_ELFSymbols_is_valid( &tag_elf_symbols_with_zero_ent_size_valid )); - - return 0; } diff --git a/tests/test_ntoa.c b/tests/test_ntoa.c index 0788a69a..05a8e62a 100644 --- a/tests/test_ntoa.c +++ b/tests/test_ntoa.c @@ -517,7 +517,7 @@ static const char *str_end(const char *str) for (;; ++str) if (*str == '\0') return str; } -int main() +void test_main() { { char buffer[KERNAUX_UTOA_MIN_BUFFER_SIZE + 3]; @@ -774,6 +774,4 @@ int main() assert(end2 == str_end(buffer)); } } - - return 0; } diff --git a/tests/test_ntoa_assert.c b/tests/test_ntoa_assert.c index 5fb42aba..77865545 100644 --- a/tests/test_ntoa_assert.c +++ b/tests/test_ntoa_assert.c @@ -74,7 +74,7 @@ static const char *str_end(const char *str) for (;; ++str) if (*str == '\0') return str; } -int main() +void test_main() { kernaux_assert_cb = assert_cb; @@ -147,6 +147,4 @@ int main() test_itoa_assert(buffer, 37); test_itoa_assert(buffer, -37); } - - return 0; } diff --git a/tests/test_pfa.c b/tests/test_pfa.c index 041007e3..70a3620d 100644 --- a/tests/test_pfa.c +++ b/tests/test_pfa.c @@ -6,7 +6,7 @@ #include -int main() +void test_main() { struct KernAux_PFA pfa; @@ -83,6 +83,4 @@ int main() } assert(KernAux_PFA_alloc_pages(&pfa, 1) == 0); - - return 0; } diff --git a/tests/test_pfa_assert.c b/tests/test_pfa_assert.c index b574ebed..00ae6977 100644 --- a/tests/test_pfa_assert.c +++ b/tests/test_pfa_assert.c @@ -25,7 +25,7 @@ static void assert_cb( longjmp(jmpbuf, 1); } -int main() +void test_main() { if (setjmp(jmpbuf) != 0) abort(); @@ -98,6 +98,4 @@ int main() } else { assert(count == 10); } - - return 0; } diff --git a/tests/test_units_human.c b/tests/test_units_human.c index 200d15c4..0dc4488e 100644 --- a/tests/test_units_human.c +++ b/tests/test_units_human.c @@ -26,7 +26,7 @@ static void test_bin( const char *result ); -int main() +void test_main() { test_raw(0, KERNAUX_UNIT_BIT, "0 bit"); test_raw(0, KERNAUX_UNIT_BYTE, "0 Byte"); @@ -134,8 +134,6 @@ int main() test_bin(UINT32_MAX, KERNAUX_UNIT_BYTE, KERNAUX_UNITPFX_GIBI, "4294967295 GiB"); test_bin(UINT64_MAX, KERNAUX_UNIT_BIT, KERNAUX_UNITPFX_GIBI, "18446744073709551615 Gibit"); test_bin(UINT64_MAX, KERNAUX_UNIT_BYTE, KERNAUX_UNITPFX_GIBI, "18446744073709551615 GiB"); - - return 0; } void test_raw(