From 79c8bcad6a33e94a0e0708e387065be43c7577e9 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sat, 17 Dec 2022 16:26:20 +0400 Subject: [PATCH 1/4] Add fixtures (#150) --- .gitignore | 11 +++ ChangeLog | 3 +- Makefile.am | 4 + README.md | 3 +- bindings/mruby/test/cmdline.rb | 4 +- bindings/mruby/test/sprintf.rb | 6 +- .../ruby/spec/lib/kernaux/cmdline_spec.rb | 5 +- .../ruby/spec/lib/kernaux/sprintf_spec.rb | 6 +- configure.ac | 12 ++- fixtures/Makefile.am | 53 ++++++++++++ {common => fixtures}/cmdline.yml | 0 fixtures/multiboot2_bin_examples_gen.c.in | 84 +++++++++++++++++++ .../multiboot2_header_example0.h | 0 .../multiboot2_header_example1.h | 0 .../multiboot2_header_example2.h | 0 .../multiboot2_info_example0.h | 0 .../multiboot2_info_example1.h | 0 .../multiboot2_info_example2.h | 0 {common => fixtures}/printf.yml | 0 {common => fixtures}/printf_fmt.yml | 0 {common => fixtures}/printf_orig.yml | 0 tests/Makefile.am | 52 ++++++------ tests/multiboot2_header_print0.c | 2 +- tests/multiboot2_header_print1.c | 2 +- tests/multiboot2_header_print2.c | 2 +- tests/multiboot2_info_print0.c | 2 +- tests/multiboot2_info_print1.c | 2 +- tests/multiboot2_info_print2.c | 2 +- tests/test_multiboot2_common_packing.c | 4 +- tests/test_multiboot2_header_helpers.c | 4 +- tests/test_multiboot2_info_helpers.c | 4 +- tests/test_multiboot2_info_validation.c | 4 +- 32 files changed, 217 insertions(+), 54 deletions(-) create mode 100644 fixtures/Makefile.am rename {common => fixtures}/cmdline.yml (100%) create mode 100644 fixtures/multiboot2_bin_examples_gen.c.in rename {tests => fixtures}/multiboot2_header_example0.h (100%) rename {tests => fixtures}/multiboot2_header_example1.h (100%) rename {tests => fixtures}/multiboot2_header_example2.h (100%) rename {tests => fixtures}/multiboot2_info_example0.h (100%) rename {tests => fixtures}/multiboot2_info_example1.h (100%) rename {tests => fixtures}/multiboot2_info_example2.h (100%) rename {common => fixtures}/printf.yml (100%) rename {common => fixtures}/printf_fmt.yml (100%) rename {common => fixtures}/printf_orig.yml (100%) diff --git a/.gitignore b/.gitignore index 2c4d0de..d5e2e45 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ /Makefile.in /examples/Makefile.in +/fixtures/Makefile.in /include/Makefile.in /libc/Makefile.in /libc/include/Makefile.in @@ -77,6 +78,7 @@ /Makefile /examples/Makefile +/fixtures/Makefile /include/Makefile /libc/Makefile /libc/include/Makefile @@ -84,6 +86,15 @@ /include/kernaux/version.h +/fixtures/multiboot2_bin_examples_gen +/fixtures/multiboot2_bin_examples_gen.c +/fixtures/multiboot2_header_example0.bin +/fixtures/multiboot2_header_example1.bin +/fixtures/multiboot2_header_example2.bin +/fixtures/multiboot2_info_example0.bin +/fixtures/multiboot2_info_example1.bin +/fixtures/multiboot2_info_example2.bin + /examples/assert /examples/cmdline /examples/generic_display diff --git a/ChangeLog b/ChangeLog index 4958063..6c0267a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,11 @@ 2022-12-17 Alex Kotov + * configure.ac: Feature "--(enable|disable)-fixtures" has been added * src/multiboot2/*_print.c: Print some values in hex 2022-12-16 Alex Kotov - * configure.ac: Feature "--with[out]-multiboot2" has been added + * configure.ac: Package "--with[out]-multiboot2" has been added * include/kernaux/multiboot2.h: Has been made stable 2022-12-14 Alex Kotov diff --git a/Makefile.am b/Makefile.am index cb51c70..de9909f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,10 @@ endif SUBDIRS += . +if ENABLE_FIXTURES +SUBDIRS += fixtures +endif + if ENABLE_CHECKS SUBDIRS += examples tests endif diff --git a/README.md b/README.md index 79f7fa7..96754bb 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ stable options. * `--enable-checks-pthreads` - enable tests that require pthreads * `--enable-checks-python` - enable tests that require Python 3 with YAML and Jinja2 +* `--enable-fixtures` - enable fixtures for tests and bindings #### Packages @@ -195,7 +196,7 @@ environment. ``` ./autogen.sh # if present -./configure --enable-checks # or --enable-checks-all, but see prerequisites +./configure --enable-fixtures --enable-checks # or --enable-checks-all, but see prerequisites make ``` diff --git a/bindings/mruby/test/cmdline.rb b/bindings/mruby/test/cmdline.rb index 1a305f1..c24536c 100644 --- a/bindings/mruby/test/cmdline.rb +++ b/bindings/mruby/test/cmdline.rb @@ -70,8 +70,8 @@ if KernAux::Version.with_cmdline? end end - assert 'usign common tests' do - cmdline_yml = File.expand_path('../../../../common/cmdline.yml', __FILE__) + assert 'usign fixtures' do + cmdline_yml = File.expand_path('../../../../fixtures/cmdline.yml', __FILE__) YAML.load(File.read(cmdline_yml)).each do |test| escape_str = lambda do |str| diff --git a/bindings/mruby/test/sprintf.rb b/bindings/mruby/test/sprintf.rb index d656b5a..affabf1 100644 --- a/bindings/mruby/test/sprintf.rb +++ b/bindings/mruby/test/sprintf.rb @@ -65,12 +65,12 @@ if KernAux::Version.with_printf? end [ - ['', 'using regular tests'], - ['_orig', 'using original tests'], + ['', 'using regular fixtures'], + ['_orig', 'using original fixtures'], ].each do |(suffix, description)| assert description do printf_yml = - File.expand_path("../../../../common/printf#{suffix}.yml", __FILE__) + File.expand_path("../../../../fixtures/printf#{suffix}.yml", __FILE__) YAML.load(File.read(printf_yml)).each do |test| expected = test['result'] diff --git a/bindings/ruby/spec/lib/kernaux/cmdline_spec.rb b/bindings/ruby/spec/lib/kernaux/cmdline_spec.rb index b5d427b..280d504 100644 --- a/bindings/ruby/spec/lib/kernaux/cmdline_spec.rb +++ b/bindings/ruby/spec/lib/kernaux/cmdline_spec.rb @@ -91,8 +91,9 @@ KernAux::Version.with_cmdline? and RSpec.describe KernAux, '.cmdline' do end end - context 'using common tests' do - cmdline_yml = File.expand_path('../../../../../common/cmdline.yml', __dir__) + context 'using fixtures' do + cmdline_yml = + File.expand_path('../../../../../fixtures/cmdline.yml', __dir__) YAML.safe_load_file(cmdline_yml).each do |test| escape_str = lambda do |str| diff --git a/bindings/ruby/spec/lib/kernaux/sprintf_spec.rb b/bindings/ruby/spec/lib/kernaux/sprintf_spec.rb index c4593cb..e172052 100644 --- a/bindings/ruby/spec/lib/kernaux/sprintf_spec.rb +++ b/bindings/ruby/spec/lib/kernaux/sprintf_spec.rb @@ -39,12 +39,12 @@ KernAux::Version.with_printf? and RSpec.describe KernAux, '.sprintf' do end [ - ['', 'using regular tests'], - ['_orig', 'using original tests'], + ['', 'using regular fixtures'], + ['_orig', 'using original fixtures'], ].each do |(suffix, description)| context description do printf_yml = File.expand_path( - "../../../../../common/printf#{suffix}.yml", + "../../../../../fixtures/printf#{suffix}.yml", __dir__, ) diff --git a/configure.ac b/configure.ac index efb63a9..80b4445 100644 --- a/configure.ac +++ b/configure.ac @@ -26,6 +26,8 @@ AC_CONFIG_SRCDIR([src/assert.c]) AC_CONFIG_FILES([ Makefile examples/Makefile + fixtures/Makefile + fixtures/multiboot2_bin_examples_gen.c include/Makefile libc/Makefile libc/include/Makefile @@ -49,6 +51,7 @@ AC_ARG_ENABLE([float], AS_HELP_STRING([--disable-float], [dis AC_ARG_ENABLE([werror], AS_HELP_STRING([--disable-werror], [disable -Werror])) dnl Features (disabled by default) +AC_ARG_ENABLE([fixtures], AS_HELP_STRING([--enable-fixtures], [enable fixtures for tests and bindings])) AC_ARG_ENABLE([freestanding], AS_HELP_STRING([--enable-freestanding], [build for freestanding environment])) AC_ARG_ENABLE([split-libc], AS_HELP_STRING([--enable-split-libc], [split off libc])) AC_ARG_ENABLE([checks], AS_HELP_STRING([--enable-checks], [enable usual tests and examples])) @@ -134,6 +137,7 @@ AS_IF([test "$enable_float" = no ], [enable_float=no], [ena AS_IF([test "$enable_werror" = no ], [enable_werror=no], [enable_werror=yes]) dnl Features (disabled by default) +AS_IF([test "$enable_fixtures" = yes], [enable_fixtures=yes], [enable_fixtures=no]) AS_IF([test "$enable_freestanding" = yes], [enable_freestanding=yes], [enable_freestanding=no]) AS_IF([test "$enable_split_libc" = yes], [enable_split_libc=yes], [enable_split_libc=no]) AS_IF([test "$enable_checks" = yes], [enable_checks=yes], [enable_checks=no]) @@ -170,8 +174,10 @@ AS_IF([test "$with_libc" = yes], [with_libc=yes], [wit # Test args # ############# -AS_IF([test "$enable_checks" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding tests])) -AS_IF([test "$enable_checks" = yes -a "$with_libc" = yes], AC_MSG_ERROR([can not use package `libc' with tests])) +AS_IF([test "$enable_checks" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding tests])) +AS_IF([test "$enable_fixtures" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding fixtures])) +AS_IF([test "$enable_checks" = yes -a "$with_libc" = yes], AC_MSG_ERROR([can not use package `libc' with tests])) +AS_IF([test "$enable_fixtures" = yes -a "$with_libc" = yes], AC_MSG_ERROR([can not use package `libc' with fixtures])) AS_IF([test "$with_printf" = yes -a "$with_ntoa" = no], AC_MSG_ERROR([package `printf' requires package `ntoa'])) AS_IF([test "$with_printf" = yes -a "$with_printf_fmt" = no], AC_MSG_ERROR([package `printf' requires package `printf-fmt'])) @@ -197,6 +203,7 @@ AM_CONDITIONAL([ENABLE_FLOAT], [test "$enable_float" = yes]) AM_CONDITIONAL([ENABLE_WERROR], [test "$enable_werror" = yes]) dnl Features (disabled by default) +AM_CONDITIONAL([ENABLE_FIXTURES], [test "$enable_fixtures" = yes]) AM_CONDITIONAL([ENABLE_FREESTANDING], [test "$enable_freestanding" = yes]) AM_CONDITIONAL([ENABLE_SPLIT_LIBC], [test "$enable_split_libc" = yes]) AM_CONDITIONAL([ENABLE_CHECKS], [test "$enable_checks" = yes]) @@ -249,6 +256,7 @@ AS_IF([test "$enable_werror" = yes], [AC_DEFINE([ENABLE_WERROR], dnl Features (disabled by default) AS_IF([test "$enable_split_libc" = yes], [AC_DEFINE([ENABLE_SPLIT_LIBC], [1], [split off libc])]) +AS_IF([test "$enable_fixtures" = yes], [AC_DEFINE([ENABLE_FIXTURES], [1], [enabled fixtures for tests and bindings])]) AS_IF([test "$enable_freestanding" = yes], [AC_DEFINE([ENABLE_FREESTANDING], [1], [build for freestanding environment])]) AS_IF([test "$enable_checks" = yes], [AC_DEFINE([ENABLE_CHECKS], [1], [enabled usual tests and examples])]) AS_IF([test "$enable_checks_cppcheck" = yes], [AC_DEFINE([ENABLE_CHECKS_CPPCHECK], [1], [enabled cppcheck])]) diff --git a/fixtures/Makefile.am b/fixtures/Makefile.am new file mode 100644 index 0000000..39b92e0 --- /dev/null +++ b/fixtures/Makefile.am @@ -0,0 +1,53 @@ +include $(top_srcdir)/make/shared.am + +noinst_PROGRAMS = +nodist_noinst_DATA = + +######################################### +# multiboot2_(header|info)_example*.bin # +######################################### + +if WITH_MULTIBOOT2 +nodist_noinst_DATA += \ + multiboot2_header_example0.bin \ + multiboot2_header_example1.bin \ + multiboot2_header_example2.bin \ + multiboot2_info_example0.bin \ + multiboot2_info_example1.bin \ + multiboot2_info_example2.bin +endif + +multiboot2_header_example0.bin: multiboot2_bin_examples_gen + ./multiboot2_bin_examples_gen header 0 + +multiboot2_header_example1.bin_examples_gen: multiboot2_bin + ./multiboot2_bin_examples_gen header 1 + +multiboot2_header_example2.bin: multiboot2_bin_examples_gen + ./multiboot2_bin_examples_gen header 2 + +multiboot2_info_example0.bin: multiboot2_bin_examples_gen + ./multiboot2_bin_examples_gen info 0 + +multiboot2_info_example1.bin: multiboot2_bin_examples_gen + ./multiboot2_bin_examples_gen info 1 + +multiboot2_info_example2.bin: multiboot2_bin_examples_gen + ./multiboot2_bin_examples_gen info 2 + +############################### +# multiboot2_bin_examples_gen # +############################### + +if WITH_MULTIBOOT2 +noinst_PROGRAMS += multiboot2_bin_examples_gen +multiboot2_bin_examples_gen_LDADD = $(top_builddir)/libkernaux.la +nodist_multiboot2_bin_examples_gen_SOURCES = multiboot2_bin_examples_gen.c +multiboot2_bin_examples_gen_SOURCES = \ + multiboot2_header_example0.h \ + multiboot2_header_example1.h \ + multiboot2_header_example2.h \ + multiboot2_info_example0.h \ + multiboot2_info_example1.h \ + multiboot2_info_example2.h +endif diff --git a/common/cmdline.yml b/fixtures/cmdline.yml similarity index 100% rename from common/cmdline.yml rename to fixtures/cmdline.yml diff --git a/fixtures/multiboot2_bin_examples_gen.c.in b/fixtures/multiboot2_bin_examples_gen.c.in new file mode 100644 index 0000000..668906a --- /dev/null +++ b/fixtures/multiboot2_bin_examples_gen.c.in @@ -0,0 +1,84 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include +#include +#include + +#include "multiboot2_header_example0.h" +#include "multiboot2_header_example1.h" +#include "multiboot2_header_example2.h" +#include "multiboot2_info_example0.h" +#include "multiboot2_info_example1.h" +#include "multiboot2_info_example2.h" + +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(); +} + +#define EXAMPLE(type, number) do { \ + static const char *const filename = \ + "@abs_top_builddir@/fixtures/multiboot2_"#type"_example"#number".bin"; \ + FILE *const file = fopen(filename, "w"); \ + assert(file); \ + assert( \ + fwrite( \ + &multiboot2_##type##_example##number, \ + 1, \ + sizeof(multiboot2_##type##_example##number), \ + file \ + ) == sizeof(multiboot2_##type##_example##number) \ + ); \ + assert(fclose(file) == 0); \ +} while (0) + +int main(const int argc, const char *const *const argv) +{ + kernaux_assert_cb = assert_cb; + + assert(argc == 3); + + const char *const type = argv[1]; + const char *const number = argv[2]; + + if (strcmp(type, "header") == 0) { + if (strcmp(number, "0") == 0) { + EXAMPLE(header, 0); + } + else if (strcmp(number, "1") == 0) { + EXAMPLE(header, 1); + } + else if (strcmp(number, "2") == 0) { + EXAMPLE(header, 2); + } + else { + abort(); + } + } else if (strcmp(type, "info") == 0) { + if (strcmp(number, "0") == 0) { + EXAMPLE(info, 0); + } + else if (strcmp(number, "1") == 0) { + EXAMPLE(info, 1); + } + else if (strcmp(number, "2") == 0) { + EXAMPLE(info, 2); + } + else { + abort(); + } + } else { + abort(); + } + + exit(EXIT_SUCCESS); +} diff --git a/tests/multiboot2_header_example0.h b/fixtures/multiboot2_header_example0.h similarity index 100% rename from tests/multiboot2_header_example0.h rename to fixtures/multiboot2_header_example0.h diff --git a/tests/multiboot2_header_example1.h b/fixtures/multiboot2_header_example1.h similarity index 100% rename from tests/multiboot2_header_example1.h rename to fixtures/multiboot2_header_example1.h diff --git a/tests/multiboot2_header_example2.h b/fixtures/multiboot2_header_example2.h similarity index 100% rename from tests/multiboot2_header_example2.h rename to fixtures/multiboot2_header_example2.h diff --git a/tests/multiboot2_info_example0.h b/fixtures/multiboot2_info_example0.h similarity index 100% rename from tests/multiboot2_info_example0.h rename to fixtures/multiboot2_info_example0.h diff --git a/tests/multiboot2_info_example1.h b/fixtures/multiboot2_info_example1.h similarity index 100% rename from tests/multiboot2_info_example1.h rename to fixtures/multiboot2_info_example1.h diff --git a/tests/multiboot2_info_example2.h b/fixtures/multiboot2_info_example2.h similarity index 100% rename from tests/multiboot2_info_example2.h rename to fixtures/multiboot2_info_example2.h diff --git a/common/printf.yml b/fixtures/printf.yml similarity index 100% rename from common/printf.yml rename to fixtures/printf.yml diff --git a/common/printf_fmt.yml b/fixtures/printf_fmt.yml similarity index 100% rename from common/printf_fmt.yml rename to fixtures/printf_fmt.yml diff --git a/common/printf_orig.yml b/fixtures/printf_orig.yml similarity index 100% rename from common/printf_orig.yml rename to fixtures/printf_orig.yml diff --git a/tests/Makefile.am b/tests/Makefile.am index 7db522c..6796b1b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -14,7 +14,7 @@ multiboot2_header_print0_LDADD = $(top_builddir)/libkernaux.la multiboot2_header_print0_SOURCES = \ main.c \ multiboot2_header_print0.c \ - multiboot2_header_example0.h + ../fixtures/multiboot2_header_example0.h endif ############################ @@ -27,7 +27,7 @@ multiboot2_header_print1_LDADD = $(top_builddir)/libkernaux.la multiboot2_header_print1_SOURCES = \ main.c \ multiboot2_header_print1.c \ - multiboot2_header_example1.h + ../fixtures/multiboot2_header_example1.h endif ############################ @@ -40,7 +40,7 @@ multiboot2_header_print2_LDADD = $(top_builddir)/libkernaux.la multiboot2_header_print2_SOURCES = \ main.c \ multiboot2_header_print2.c \ - multiboot2_header_example2.h + ../fixtures/multiboot2_header_example2.h endif ########################## @@ -53,7 +53,7 @@ multiboot2_info_print0_LDADD = $(top_builddir)/libkernaux.la multiboot2_info_print0_SOURCES = \ main.c \ multiboot2_info_print0.c \ - multiboot2_info_example0.h + ../fixtures/multiboot2_info_example0.h endif ########################## @@ -66,7 +66,7 @@ multiboot2_info_print1_LDADD = $(top_builddir)/libkernaux.la multiboot2_info_print1_SOURCES = \ main.c \ multiboot2_info_print1.c \ - multiboot2_info_example1.h + ../fixtures/multiboot2_info_example1.h endif ########################## @@ -79,7 +79,7 @@ multiboot2_info_print2_LDADD = $(top_builddir)/libkernaux.la multiboot2_info_print2_SOURCES = \ main.c \ multiboot2_info_print2.c \ - multiboot2_info_example2.h + ../fixtures/multiboot2_info_example2.h endif ################## @@ -121,7 +121,7 @@ test_cmdline_gen_SOURCES = \ test_cmdline_gen.c \ cmdline_gen.py \ cmdline_gen.jinja \ - $(top_srcdir)/common/cmdline.yml \ + $(top_srcdir)/fixtures/cmdline.yml \ cmdline_test.h \ cmdline_test.c endif @@ -129,8 +129,8 @@ endif CLEANFILES += test_cmdline_gen.c -test_cmdline_gen.c: $(top_srcdir)/tests/cmdline_gen.py $(top_srcdir)/tests/cmdline_gen.jinja $(top_srcdir)/common/cmdline.yml - $(PYTHON) $(top_srcdir)/tests/cmdline_gen.py $(top_srcdir)/tests/cmdline_gen.jinja $(top_srcdir)/common/cmdline.yml test_cmdline_gen.c +test_cmdline_gen.c: $(top_srcdir)/tests/cmdline_gen.py $(top_srcdir)/tests/cmdline_gen.jinja $(top_srcdir)/fixtures/cmdline.yml + $(PYTHON) $(top_srcdir)/tests/cmdline_gen.py $(top_srcdir)/tests/cmdline_gen.jinja $(top_srcdir)/fixtures/cmdline.yml test_cmdline_gen.c ############ # test_elf # @@ -190,8 +190,8 @@ test_multiboot2_common_packing_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_common_packing_SOURCES = \ main.c \ test_multiboot2_common_packing.c \ - multiboot2_header_example2.h \ - multiboot2_info_example2.h + ../fixtures/multiboot2_header_example2.h \ + ../fixtures/multiboot2_info_example2.h endif ################################## @@ -204,8 +204,8 @@ test_multiboot2_header_helpers_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_header_helpers_SOURCES = \ main.c \ test_multiboot2_header_helpers.c \ - multiboot2_header_example1.h \ - multiboot2_header_example2.h + ../fixtures/multiboot2_header_example1.h \ + ../fixtures/multiboot2_header_example2.h endif ################################ @@ -234,8 +234,8 @@ test_multiboot2_header_validation_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_header_validation_SOURCES = \ main.c \ test_multiboot2_header_validation.c \ - multiboot2_header_example1.h \ - multiboot2_header_example2.h + ../fixtures/multiboot2_header_example1.h \ + ../fixtures/multiboot2_header_example2.h endif ################################ @@ -248,8 +248,8 @@ test_multiboot2_info_helpers_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_info_helpers_SOURCES = \ main.c \ test_multiboot2_info_helpers.c \ - multiboot2_info_example1.h \ - multiboot2_info_example2.h + ../fixtures/multiboot2_info_example1.h \ + ../fixtures/multiboot2_info_example2.h endif ############################## @@ -278,8 +278,8 @@ test_multiboot2_info_validation_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_info_validation_SOURCES = \ main.c \ test_multiboot2_info_validation.c \ - multiboot2_info_example1.h \ - multiboot2_info_example2.h + ../fixtures/multiboot2_info_example1.h \ + ../fixtures/multiboot2_info_example2.h endif ############# @@ -359,14 +359,14 @@ test_printf_fmt_gen_SOURCES = \ test_printf_fmt_gen.c \ printf_fmt_gen.py \ printf_fmt_gen.jinja \ - $(top_srcdir)/common/printf_fmt.yml + $(top_srcdir)/fixtures/printf_fmt.yml endif endif CLEANFILES += test_printf_fmt_gen.c -test_printf_fmt_gen.c: $(top_srcdir)/tests/printf_fmt_gen.py $(top_srcdir)/tests/printf_fmt_gen.jinja $(top_srcdir)/common/printf_fmt.yml - $(PYTHON) $(top_srcdir)/tests/printf_fmt_gen.py $(top_srcdir)/tests/printf_fmt_gen.jinja $(top_srcdir)/common/printf_fmt.yml test_printf_fmt_gen.c +test_printf_fmt_gen.c: $(top_srcdir)/tests/printf_fmt_gen.py $(top_srcdir)/tests/printf_fmt_gen.jinja $(top_srcdir)/fixtures/printf_fmt.yml + $(PYTHON) $(top_srcdir)/tests/printf_fmt_gen.py $(top_srcdir)/tests/printf_fmt_gen.jinja $(top_srcdir)/fixtures/printf_fmt.yml test_printf_fmt_gen.c ################### # test_printf_gen # @@ -381,15 +381,15 @@ test_printf_gen_SOURCES = \ test_printf_gen.c \ printf_gen.py \ printf_gen.jinja \ - $(top_srcdir)/common/printf.yml \ - $(top_srcdir)/common/printf_orig.yml + $(top_srcdir)/fixtures/printf.yml \ + $(top_srcdir)/fixtures/printf_orig.yml endif endif CLEANFILES += test_printf_gen.c -test_printf_gen.c: $(top_srcdir)/tests/printf_gen.py $(top_srcdir)/tests/printf_gen.jinja $(top_srcdir)/common/printf.yml $(top_srcdir)/common/printf_orig.yml - $(PYTHON) $(top_srcdir)/tests/printf_gen.py $(top_srcdir)/tests/printf_gen.jinja $(top_srcdir)/common/printf.yml $(top_srcdir)/common/printf_orig.yml test_printf_gen.c +test_printf_gen.c: $(top_srcdir)/tests/printf_gen.py $(top_srcdir)/tests/printf_gen.jinja $(top_srcdir)/fixtures/printf.yml $(top_srcdir)/fixtures/printf_orig.yml + $(PYTHON) $(top_srcdir)/tests/printf_gen.py $(top_srcdir)/tests/printf_gen.jinja $(top_srcdir)/fixtures/printf.yml $(top_srcdir)/fixtures/printf_orig.yml test_printf_gen.c #################### # test_units_human # diff --git a/tests/multiboot2_header_print0.c b/tests/multiboot2_header_print0.c index 89836d3..407e221 100644 --- a/tests/multiboot2_header_print0.c +++ b/tests/multiboot2_header_print0.c @@ -12,7 +12,7 @@ #include #include -#include "multiboot2_header_example0.h" +#include "../fixtures/multiboot2_header_example0.h" static void my_putc(void *display KERNAUX_UNUSED, char c) { diff --git a/tests/multiboot2_header_print1.c b/tests/multiboot2_header_print1.c index 0eab3d2..fe16b40 100644 --- a/tests/multiboot2_header_print1.c +++ b/tests/multiboot2_header_print1.c @@ -12,7 +12,7 @@ #include #include -#include "multiboot2_header_example1.h" +#include "../fixtures/multiboot2_header_example1.h" static void my_putc(void *display KERNAUX_UNUSED, char c) { diff --git a/tests/multiboot2_header_print2.c b/tests/multiboot2_header_print2.c index 50b41bb..1d00386 100644 --- a/tests/multiboot2_header_print2.c +++ b/tests/multiboot2_header_print2.c @@ -12,7 +12,7 @@ #include #include -#include "multiboot2_header_example2.h" +#include "../fixtures/multiboot2_header_example2.h" static void my_putc(void *display KERNAUX_UNUSED, char c) { diff --git a/tests/multiboot2_info_print0.c b/tests/multiboot2_info_print0.c index 642a7aa..ddcf46d 100644 --- a/tests/multiboot2_info_print0.c +++ b/tests/multiboot2_info_print0.c @@ -12,7 +12,7 @@ #include #include -#include "multiboot2_info_example0.h" +#include "../fixtures/multiboot2_info_example0.h" static void my_putc(void *display KERNAUX_UNUSED, char c) { diff --git a/tests/multiboot2_info_print1.c b/tests/multiboot2_info_print1.c index 095821a..8770af9 100644 --- a/tests/multiboot2_info_print1.c +++ b/tests/multiboot2_info_print1.c @@ -12,7 +12,7 @@ #include #include -#include "multiboot2_info_example1.h" +#include "../fixtures/multiboot2_info_example1.h" static void my_putc(void *display KERNAUX_UNUSED, char c) { diff --git a/tests/multiboot2_info_print2.c b/tests/multiboot2_info_print2.c index 30ed471..8e0f1bf 100644 --- a/tests/multiboot2_info_print2.c +++ b/tests/multiboot2_info_print2.c @@ -12,7 +12,7 @@ #include #include -#include "multiboot2_info_example2.h" +#include "../fixtures/multiboot2_info_example2.h" static void my_putc(void *display KERNAUX_UNUSED, char c) { diff --git a/tests/test_multiboot2_common_packing.c b/tests/test_multiboot2_common_packing.c index b54653f..f9215fb 100644 --- a/tests/test_multiboot2_common_packing.c +++ b/tests/test_multiboot2_common_packing.c @@ -7,8 +7,8 @@ #include #include -#include "multiboot2_header_example2.h" -#include "multiboot2_info_example2.h" +#include "../fixtures/multiboot2_header_example2.h" +#include "../fixtures/multiboot2_info_example2.h" #define HEAD_SIZEOF1(type, inst, size) \ do { \ diff --git a/tests/test_multiboot2_header_helpers.c b/tests/test_multiboot2_header_helpers.c index 5af933d..10d2aa1 100644 --- a/tests/test_multiboot2_header_helpers.c +++ b/tests/test_multiboot2_header_helpers.c @@ -4,8 +4,8 @@ #include -#include "multiboot2_header_example1.h" -#include "multiboot2_header_example2.h" +#include "../fixtures/multiboot2_header_example1.h" +#include "../fixtures/multiboot2_header_example2.h" void test_main() { diff --git a/tests/test_multiboot2_info_helpers.c b/tests/test_multiboot2_info_helpers.c index 7a6c34e..bd9592e 100644 --- a/tests/test_multiboot2_info_helpers.c +++ b/tests/test_multiboot2_info_helpers.c @@ -7,8 +7,8 @@ #include -#include "multiboot2_info_example1.h" -#include "multiboot2_info_example2.h" +#include "../fixtures/multiboot2_info_example1.h" +#include "../fixtures/multiboot2_info_example2.h" #include diff --git a/tests/test_multiboot2_info_validation.c b/tests/test_multiboot2_info_validation.c index 4501756..0aebdf4 100644 --- a/tests/test_multiboot2_info_validation.c +++ b/tests/test_multiboot2_info_validation.c @@ -7,8 +7,8 @@ #include -#include "multiboot2_info_example1.h" -#include "multiboot2_info_example2.h" +#include "../fixtures/multiboot2_info_example1.h" +#include "../fixtures/multiboot2_info_example2.h" #include From f46438fa85197802a5dc8f1fadb43480485d648b Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sat, 17 Dec 2022 16:46:03 +0400 Subject: [PATCH 2/4] Fix typo & test fixtures on CI (#151) --- .cirrus.yml | 2 +- .github/workflows/main.yml | 2 +- .openbsd.yml | 2 +- fixtures/Makefile.am | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index b05e32b..41d3ee4 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -12,7 +12,7 @@ main_freebsd_task: - pip install --user Jinja2 PyYAML main_build_script: - ./autogen.sh - - ./configure --enable-debug --enable-checks-all CFLAGS='-O3' + - ./configure --enable-debug --enable-fixtures --enable-checks-all CFLAGS='-O3' - make - sudo make install main_test_script: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2962234..9e4175b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure ${{matrix.debug}} --enable-checks --enable-checks-pthreads --enable-checks-python CC='${{matrix.cc}}' CFLAGS='${{matrix.opt}}' + run: ./configure ${{matrix.debug}} --enable-fixtures --enable-checks --enable-checks-pthreads --enable-checks-python CC='${{matrix.cc}}' CFLAGS='${{matrix.opt}}' - name: make run: make - name: check diff --git a/.openbsd.yml b/.openbsd.yml index cfd6ca3..e583868 100644 --- a/.openbsd.yml +++ b/.openbsd.yml @@ -31,7 +31,7 @@ tasks: - build: | cd libkernaux ./autogen.sh - ./configure --enable-debug --enable-checks-all CFLAGS='-O3' + ./configure --enable-debug --enable-fixtures --enable-checks-all CFLAGS='-O3' make doas make install - test: | diff --git a/fixtures/Makefile.am b/fixtures/Makefile.am index 39b92e0..b04300f 100644 --- a/fixtures/Makefile.am +++ b/fixtures/Makefile.am @@ -20,7 +20,7 @@ endif multiboot2_header_example0.bin: multiboot2_bin_examples_gen ./multiboot2_bin_examples_gen header 0 -multiboot2_header_example1.bin_examples_gen: multiboot2_bin +multiboot2_header_example1.bin: multiboot2_bin_examples_gen ./multiboot2_bin_examples_gen header 1 multiboot2_header_example2.bin: multiboot2_bin_examples_gen From a1262ac64de2e7cbd34b0eaee57e3d7143f9491d Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 18 Dec 2022 09:18:55 +0400 Subject: [PATCH 3/4] Fix printf hack in the bindings (#152) --- .cirrus.yml | 2 +- .github/workflows/mruby.yml | 3 --- .github/workflows/ruby.yml | 3 --- README.md | 6 ++++++ bindings/mruby/Rakefile | 14 +++++++++++++- bindings/mruby/src/assert.c | 3 --- bindings/mruby/src/cmdline.c | 4 ---- bindings/mruby/src/main.h | 6 ++++++ bindings/mruby/src/ntoa.c | 2 -- bindings/mruby/src/printf.c | 21 +++++++++------------ bindings/ruby/Rakefile | 16 ++++++++++++++-- bindings/ruby/ext/default/main.h | 6 ++++++ bindings/ruby/ext/default/printf.c | 21 +++++++++------------ 13 files changed, 64 insertions(+), 43 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 41d3ee4..ba5f266 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -46,7 +46,7 @@ ruby_freebsd_task: CPATH: '/usr/local/include' LIBRARY_PATH: '/usr/local/lib' dependencies_script: - - pkg install --yes autoconf automake git libtool wget + - pkg install --yes autoconf automake cppcheck git libtool wget dependencies_ruby_script: - wget https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.3.tar.gz - tar -xzf ruby-3.0.3.tar.gz diff --git a/.github/workflows/mruby.yml b/.github/workflows/mruby.yml index 4e08365..afd12f7 100644 --- a/.github/workflows/mruby.yml +++ b/.github/workflows/mruby.yml @@ -46,6 +46,3 @@ jobs: - working-directory: bindings/mruby name: lint run: rake - - working-directory: bindings/mruby - name: cppcheck - run: cppcheck --quiet --error-exitcode=1 --std=c99 --enable=warning,style,performance,portability . diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 2ea62d7..d5a2ca6 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -44,6 +44,3 @@ jobs: - working-directory: bindings/ruby name: test & lint run: SKIP_COVERAGE='${{matrix.packages.skip_coverage}}' rake - - working-directory: bindings/ruby - name: cppcheck - run: cppcheck --quiet --error-exitcode=1 --std=c99 --enable=warning,style,performance,portability . diff --git a/README.md b/README.md index 96754bb..833b761 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,12 @@ make You can test with `make check`. +#### See also + +* [GitHub Actions](/.github/) for **GNU/Linux** build environment +* [Cirrus CI](/.cirrus.yml) for **FreeBSD** build environment +* [sourcehut CI](/.openbsd.yml) for **OpenBSD** build environment + ### Cross Create configuration script with `./autogen.sh` (if present). diff --git a/bindings/mruby/Rakefile b/bindings/mruby/Rakefile index 567628a..d71d39f 100644 --- a/bindings/mruby/Rakefile +++ b/bindings/mruby/Rakefile @@ -4,7 +4,7 @@ desc 'Run default checks' task default: :lint desc 'Run code analysis tools' -task lint: :rubocop +task lint: %i[rubocop cppcheck] desc 'Fix code style (rubocop --auto-correct)' task fix: 'rubocop:auto_correct' @@ -15,3 +15,15 @@ begin rescue LoadError nil end + +desc 'Run cppcheck' +task :cppcheck do + sh( + 'cppcheck', + '--quiet', + '--error-exitcode=1', + '--std=c99', + '--enable=warning,style,performance,portability', + __dir__, + ) +end diff --git a/bindings/mruby/src/assert.c b/bindings/mruby/src/assert.c index b9f5d66..0942a99 100644 --- a/bindings/mruby/src/assert.c +++ b/bindings/mruby/src/assert.c @@ -1,8 +1,5 @@ #include "main.h" -#include -#include - #include #include #include diff --git a/bindings/mruby/src/cmdline.c b/bindings/mruby/src/cmdline.c index 7826675..9dd1aa7 100644 --- a/bindings/mruby/src/cmdline.c +++ b/bindings/mruby/src/cmdline.c @@ -1,9 +1,5 @@ #include "main.h" -#include -#include -#include - #include #include #include diff --git a/bindings/mruby/src/main.h b/bindings/mruby/src/main.h index 5270041..a38d805 100644 --- a/bindings/mruby/src/main.h +++ b/bindings/mruby/src/main.h @@ -4,6 +4,12 @@ #include #include +#include +#include +#include +#include +#include + void current_mrb_start(mrb_state *mrb); void current_mrb_finish(mrb_state *mrb); mrb_state *current_mrb_get(); diff --git a/bindings/mruby/src/ntoa.c b/bindings/mruby/src/ntoa.c index d1dd384..f8f9c03 100644 --- a/bindings/mruby/src/ntoa.c +++ b/bindings/mruby/src/ntoa.c @@ -1,7 +1,5 @@ #include "main.h" -#include - #include #include #include diff --git a/bindings/mruby/src/printf.c b/bindings/mruby/src/printf.c index 02b05f0..71bc1ef 100644 --- a/bindings/mruby/src/printf.c +++ b/bindings/mruby/src/printf.c @@ -29,8 +29,7 @@ void init_printf(mrb_state *const mrb) mrb_value rb_KernAux_sprintf(mrb_state *const mrb, mrb_value self) { - // FIXME: const - char *format; + const char *format; mrb_value *args; mrb_int argc; mrb_get_args(mrb, "z*", &format, &args, &argc); @@ -45,12 +44,9 @@ mrb_value rb_KernAux_sprintf(mrb_state *const mrb, mrb_value self) continue; } - // FIXME: unnecessary - const char *const old_format = format; ++format; struct KernAux_PrintfFmt_Spec spec = - // FIXME: no type cast - KernAux_PrintfFmt_Spec_create_out((const char**)&format); + KernAux_PrintfFmt_Spec_create_out(&format); if (spec.set_width) { TAKE_ARG; @@ -87,14 +83,16 @@ mrb_value rb_KernAux_sprintf(mrb_state *const mrb, mrb_value self) DynArg_use_str(&dynarg, RSTRING_CSTR(mrb, arg_rb)); } + // 1 additional byte for the '%' character. + // 1 additional byte for the terminating '\0' character. + char old_format[2 + spec.format_limit - spec.format_start]; + memset(old_format, '\0', sizeof(old_format)); + old_format[0] = '%'; + strncpy(&old_format[1], spec.format_start, sizeof(old_format) - 2); + char buffer[BUFFER_SIZE]; int slen; - // FIXME: it's a hack - // TODO: convert printf format spec to string - const char tmp = *format; - *format = '\0'; - if (spec.set_width) { if (spec.set_precision) { if (dynarg.use_dbl) { @@ -133,7 +131,6 @@ mrb_value rb_KernAux_sprintf(mrb_state *const mrb, mrb_value self) } } - *format = tmp; mrb_str_cat(mrb, result, buffer, slen); } diff --git a/bindings/ruby/Rakefile b/bindings/ruby/Rakefile index 2675fc7..5bf5204 100644 --- a/bindings/ruby/Rakefile +++ b/bindings/ruby/Rakefile @@ -20,13 +20,13 @@ CLEAN << 'doc' CLEAN << 'spec/examples.txt' desc 'Run default checks' -task default: %i[test lint yard:cov] +task default: %i[test lint] desc 'Run tests' task test: :spec desc 'Run code analysis tools' -task lint: :rubocop +task lint: %i[rubocop cppcheck yard:cov] desc 'Fix code style (rubocop --auto-correct)' task fix: 'rubocop:auto_correct' @@ -66,6 +66,18 @@ task :console do sh 'bundle', 'exec', File.expand_path(File.join('bin', 'console'), __dir__) end +desc 'Run cppcheck' +task :cppcheck do + sh( + 'cppcheck', + '--quiet', + '--error-exitcode=1', + '--std=c99', + '--enable=warning,style,performance,portability', + __dir__, + ) +end + namespace :yard do desc 'Measure documentation coverage' task :cov do diff --git a/bindings/ruby/ext/default/main.h b/bindings/ruby/ext/default/main.h index 74d2187..ddbb2ff 100644 --- a/bindings/ruby/ext/default/main.h +++ b/bindings/ruby/ext/default/main.h @@ -4,6 +4,12 @@ #include #include +#include +#include +#include +#include +#include + extern ID rb_intern_call; extern ID rb_intern_freeze; extern ID rb_intern_LESS; diff --git a/bindings/ruby/ext/default/printf.c b/bindings/ruby/ext/default/printf.c index b2785b6..e73ddf0 100644 --- a/bindings/ruby/ext/default/printf.c +++ b/bindings/ruby/ext/default/printf.c @@ -31,8 +31,7 @@ VALUE rb_KernAux_sprintf(const int argc, VALUE *const argv, VALUE self) { if (argc == 0) rb_raise(rb_eArgError, "too few arguments"); - // FIXME: const - char *format = StringValueCStr(argv[0]); + const char *format = StringValueCStr(argv[0]); int arg_index = 1; VALUE result = rb_str_new_literal(""); @@ -43,12 +42,9 @@ VALUE rb_KernAux_sprintf(const int argc, VALUE *const argv, VALUE self) continue; } - // FIXME: unnecessary - const char *const old_format = format; ++format; struct KernAux_PrintfFmt_Spec spec = - // FIXME: no type cast - KernAux_PrintfFmt_Spec_create_out((const char**)&format); + KernAux_PrintfFmt_Spec_create_out(&format); if (spec.set_width) { TAKE_ARG; @@ -82,14 +78,16 @@ VALUE rb_KernAux_sprintf(const int argc, VALUE *const argv, VALUE self) DynArg_use_str(&dynarg, StringValueCStr(arg_rb)); } + // 1 additional byte for the '%' character. + // 1 additional byte for the terminating '\0' character. + char old_format[2 + spec.format_limit - spec.format_start]; + memset(old_format, '\0', sizeof(old_format)); + old_format[0] = '%'; + strncpy(&old_format[1], spec.format_start, sizeof(old_format) - 2); + char buffer[BUFFER_SIZE]; int slen; - // FIXME: it's a hack - // TODO: convert printf format spec to string - const char tmp = *format; - *format = '\0'; - if (spec.set_width) { if (spec.set_precision) { if (dynarg.use_dbl) { @@ -128,7 +126,6 @@ VALUE rb_KernAux_sprintf(const int argc, VALUE *const argv, VALUE self) } } - *format = tmp; rb_str_cat(result, buffer, slen); } From 6ec080ddfa54b7050f775361359807bd6c2ee200 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 19 Dec 2022 12:40:13 +0400 Subject: [PATCH 4/4] Improve build system (#153) --- .gitignore | 73 +--- build/.keep | 0 configure.ac | 2 + examples/.gitignore | 21 ++ fixtures/.gitignore | 8 + fixtures/Makefile.am | 8 + fixtures/multiboot2_header_example0.txt | 11 + fixtures/multiboot2_header_example1.txt | 52 +++ fixtures/multiboot2_header_example2.txt | 100 ++++++ fixtures/multiboot2_info_example0.txt | 8 + fixtures/multiboot2_info_example1.txt | 129 +++++++ fixtures/multiboot2_info_example2.txt | 234 +++++++++++++ include/.gitignore | 1 + tests/.gitignore | 33 ++ tests/Makefile.am | 10 +- tests/test_multiboot2_header_print.c | 218 ------------ tests/test_multiboot2_header_print.c.in | 61 ++++ tests/test_multiboot2_info_print.c | 441 ------------------------ tests/test_multiboot2_info_print.c.in | 61 ++++ 19 files changed, 740 insertions(+), 731 deletions(-) create mode 100644 build/.keep create mode 100644 examples/.gitignore create mode 100644 fixtures/.gitignore create mode 100644 fixtures/multiboot2_header_example0.txt create mode 100644 fixtures/multiboot2_header_example1.txt create mode 100644 fixtures/multiboot2_header_example2.txt create mode 100644 fixtures/multiboot2_info_example0.txt create mode 100644 fixtures/multiboot2_info_example1.txt create mode 100644 fixtures/multiboot2_info_example2.txt create mode 100644 include/.gitignore create mode 100644 tests/.gitignore delete mode 100644 tests/test_multiboot2_header_print.c create mode 100644 tests/test_multiboot2_header_print.c.in delete mode 100644 tests/test_multiboot2_info_print.c create mode 100644 tests/test_multiboot2_info_print.c.in diff --git a/.gitignore b/.gitignore index d5e2e45..3eca097 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +/build/* +!/build/.keep + ########################## # Common generated files # ########################## @@ -38,8 +41,6 @@ /m4/* !/m4/.keep -# Custom - /Makefile.in /examples/Makefile.in /fixtures/Makefile.in @@ -58,7 +59,6 @@ /libtool /stamp-h1 -# Temporary /confcache /confdefs.h /confinc.mk @@ -74,8 +74,6 @@ /tests/test_*.log /tests/test_*.trs -# Custom - /Makefile /examples/Makefile /fixtures/Makefile @@ -83,68 +81,3 @@ /libc/Makefile /libc/include/Makefile /tests/Makefile - -/include/kernaux/version.h - -/fixtures/multiboot2_bin_examples_gen -/fixtures/multiboot2_bin_examples_gen.c -/fixtures/multiboot2_header_example0.bin -/fixtures/multiboot2_header_example1.bin -/fixtures/multiboot2_header_example2.bin -/fixtures/multiboot2_info_example0.bin -/fixtures/multiboot2_info_example1.bin -/fixtures/multiboot2_info_example2.bin - -/examples/assert -/examples/cmdline -/examples/generic_display -/examples/generic_malloc -/examples/generic_mutex -/examples/macro_bits -/examples/macro_cast -/examples/macro_container_of -/examples/macro_packing -/examples/macro_static_test -/examples/memmap -/examples/multiboot2_header_macro -/examples/ntoa -/examples/panic -/examples/pfa -/examples/printf_file -/examples/printf_file_va -/examples/printf_fmt -/examples/printf_str -/examples/printf_str_va -/examples/units_human - -/tests/multiboot2_header_print0 -/tests/multiboot2_header_print1 -/tests/multiboot2_header_print2 -/tests/multiboot2_info_print0 -/tests/multiboot2_info_print1 -/tests/multiboot2_info_print2 -/tests/test_arch_i386 -/tests/test_cmdline -/tests/test_cmdline_gen -/tests/test_cmdline_gen.c -/tests/test_elf -/tests/test_free_list -/tests/test_mbr -/tests/test_memmap -/tests/test_multiboot2_common_packing -/tests/test_multiboot2_header_helpers -/tests/test_multiboot2_header_print -/tests/test_multiboot2_header_validation -/tests/test_multiboot2_info_helpers -/tests/test_multiboot2_info_print -/tests/test_multiboot2_info_validation -/tests/test_ntoa -/tests/test_ntoa_assert -/tests/test_pfa -/tests/test_pfa_assert -/tests/test_printf -/tests/test_printf_fmt_gen -/tests/test_printf_fmt_gen.c -/tests/test_printf_gen -/tests/test_printf_gen.c -/tests/test_units_human diff --git a/build/.keep b/build/.keep new file mode 100644 index 0000000..e69de29 diff --git a/configure.ac b/configure.ac index 80b4445..6b632b0 100644 --- a/configure.ac +++ b/configure.ac @@ -33,6 +33,8 @@ AC_CONFIG_FILES([ libc/include/Makefile include/kernaux/version.h tests/Makefile + tests/test_multiboot2_header_print.c + tests/test_multiboot2_info_print.c ]) AM_INIT_AUTOMAKE([1.16 subdir-objects]) diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..61817ae --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,21 @@ +/assert +/cmdline +/generic_display +/generic_malloc +/generic_mutex +/macro_bits +/macro_cast +/macro_container_of +/macro_packing +/macro_static_test +/memmap +/multiboot2_header_macro +/ntoa +/panic +/pfa +/printf_file +/printf_file_va +/printf_fmt +/printf_str +/printf_str_va +/units_human diff --git a/fixtures/.gitignore b/fixtures/.gitignore new file mode 100644 index 0000000..248bdd9 --- /dev/null +++ b/fixtures/.gitignore @@ -0,0 +1,8 @@ +/multiboot2_bin_examples_gen +/multiboot2_bin_examples_gen.c +/multiboot2_header_example0.bin +/multiboot2_header_example1.bin +/multiboot2_header_example2.bin +/multiboot2_info_example0.bin +/multiboot2_info_example1.bin +/multiboot2_info_example2.bin diff --git a/fixtures/Makefile.am b/fixtures/Makefile.am index b04300f..060b2b2 100644 --- a/fixtures/Makefile.am +++ b/fixtures/Makefile.am @@ -3,6 +3,14 @@ include $(top_srcdir)/make/shared.am noinst_PROGRAMS = nodist_noinst_DATA = +EXTRA_DIST = \ + multiboot2_header_example0.txt \ + multiboot2_header_example1.txt \ + multiboot2_header_example2.txt \ + multiboot2_info_example0.txt \ + multiboot2_info_example1.txt \ + multiboot2_info_example2.txt + ######################################### # multiboot2_(header|info)_example*.bin # ######################################### diff --git a/fixtures/multiboot2_header_example0.txt b/fixtures/multiboot2_header_example0.txt new file mode 100644 index 0000000..4a9ceda --- /dev/null +++ b/fixtures/multiboot2_header_example0.txt @@ -0,0 +1,11 @@ +Multiboot 2 header { + u32 magic: 0xe85250d6 + u32 arch: 0 (i386) + u32 size: 24 + u32 checksum: 0x17adaf12 +} +Multiboot 2 header tag { + u16 type: 0 (none) + u16 flags: 0x0 () + u32 size: 8 +} diff --git a/fixtures/multiboot2_header_example1.txt b/fixtures/multiboot2_header_example1.txt new file mode 100644 index 0000000..eb8385e --- /dev/null +++ b/fixtures/multiboot2_header_example1.txt @@ -0,0 +1,52 @@ +Multiboot 2 header { + u32 magic: 0xe85250d6 + u32 arch: 4 (MIPS32) + u32 size: 104 + u32 checksum: 0x17adaebe +} +Multiboot 2 header tag { + u16 type: 4 (flags) + u16 flags: 0x0 () + u32 size: 12 + u32 console_flags: 0x0 () +} +Multiboot 2 header tag { + u16 type: 4 (flags) + u16 flags: 0x0 () + u32 size: 12 + u32 console_flags: 0x1 ( + REQUIRE_CONSOLE + ) +} +Multiboot 2 header tag { + u16 type: 4 (flags) + u16 flags: 0x0 () + u32 size: 12 + u32 console_flags: 0x2 ( + EGA_SUPPORT + ) +} +Multiboot 2 header tag { + u16 type: 4 (flags) + u16 flags: 0x0 () + u32 size: 12 + u32 console_flags: 0x3 ( + REQUIRE_CONSOLE | + EGA_SUPPORT + ) +} +Multiboot 2 header tag { + u16 type: 1 (information request) + u16 flags: 0x1 ( + OPTIONAL + ) + u32 size: 12 + u32 mbi_tag_types[]: [ + 0 (none) + ] +} +Multiboot 2 header tag { + u16 type: 0 (none) + u16 flags: 0x0 () + u32 size: 8 +} diff --git a/fixtures/multiboot2_header_example2.txt b/fixtures/multiboot2_header_example2.txt new file mode 100644 index 0000000..7d66af3 --- /dev/null +++ b/fixtures/multiboot2_header_example2.txt @@ -0,0 +1,100 @@ +Multiboot 2 header { + u32 magic: 0xe85250d6 + u32 arch: 0 (i386) + u32 size: 272 + u32 checksum: 0x17adae1a +} +Multiboot 2 header tag { + u16 type: 1 (information request) + u16 flags: 0x0 () + u32 size: 96 + u32 mbi_tag_types[]: [ + 0 (none) + 1 (boot cmd line) + 2 (boot loader name) + 3 (module) + 4 (basic memory info) + 5 (BIOS boot device) + 6 (memory map) + 7 (VBE info) + 8 (framebuffer info) + 9 (ELF symbols) + 10 (APM table) + 11 (EFI 32bit system table ptr) + 12 (EFI 64bit system table ptr) + 13 (SMBIOS tables) + 14 (ACPI old RSDP) + 15 (ACPI new RSDP) + 16 (networking info) + 17 (EFI memory map) + 18 (EFI boot services not terminated) + 19 (EFI 32bit image handle ptr) + 20 (EFI 64bit image handle ptr) + 21 (image load base phys addr) + ] +} +Multiboot 2 header tag { + u16 type: 2 (address) + u16 flags: 0x0 () + u32 size: 24 + u32 header_addr: 0xcafebabe + u32 load_addr: 0xdeadbeaf + u32 load_end_addr: 0xdeadbabe + u32 bss_end_addr: 0xcafebeaf +} +Multiboot 2 header tag { + u16 type: 3 (entry address) + u16 flags: 0x0 () + u32 size: 12 + u32 entry_addr: 0xcafebabe +} +Multiboot 2 header tag { + u16 type: 4 (flags) + u16 flags: 0x0 () + u32 size: 12 + u32 console_flags: 0x0 () +} +Multiboot 2 header tag { + u16 type: 5 (framebuffer) + u16 flags: 0x0 () + u32 size: 20 + u32 width: 80 + u32 height: 25 + u32 depth: 8 +} +Multiboot 2 header tag { + u16 type: 6 (module alignment) + u16 flags: 0x0 () + u32 size: 8 +} +Multiboot 2 header tag { + u16 type: 7 (EFI boot services) + u16 flags: 0x0 () + u32 size: 8 +} +Multiboot 2 header tag { + u16 type: 8 (EFI i386 entry address) + u16 flags: 0x0 () + u32 size: 12 + u32 entry_addr: 0xcafebabe +} +Multiboot 2 header tag { + u16 type: 9 (EFI amd64 entry address) + u16 flags: 0x0 () + u32 size: 12 + u32 entry_addr: 0xdeadbeaf +} +Multiboot 2 header tag { + u16 type: 10 (relocatable header) + u16 flags: 0x0 () + u32 size: 24 + u32 min_addr: 0xcafebabe + u32 max_addr: 0xdeadbeaf + u32 align: 8 + u32 preference: 1 (lowest) +} +Multiboot 2 header tag { + u16 type: 0 (none) + u16 flags: 0x0 () + u32 size: 8 +} diff --git a/fixtures/multiboot2_info_example0.txt b/fixtures/multiboot2_info_example0.txt new file mode 100644 index 0000000..9fbe289 --- /dev/null +++ b/fixtures/multiboot2_info_example0.txt @@ -0,0 +1,8 @@ +Multiboot 2 info { + u32 size: 16 + u32 reserved: 0x0 +} +Multiboot 2 info tag { + u32 type: 0 (none) + u32 size: 8 +} diff --git a/fixtures/multiboot2_info_example1.txt b/fixtures/multiboot2_info_example1.txt new file mode 100644 index 0000000..93efa0e --- /dev/null +++ b/fixtures/multiboot2_info_example1.txt @@ -0,0 +1,129 @@ +Multiboot 2 info { + u32 size: 864 + u32 reserved: 0x0 +} +Multiboot 2 info tag { + u32 type: 21 (image load base phys addr) + u32 size: 12 + u32 load_base_addr: 0x400000 +} +Multiboot 2 info tag { + u32 type: 1 (boot cmd line) + u32 size: 21 + char cmdline[]: "hello kernel" +} +Multiboot 2 info tag { + u32 type: 2 (boot loader name) + u32 size: 30 + char name[]: "GRUB 2.02-2ubuntu8.20" +} +Multiboot 2 info tag { + u32 type: 10 (APM table) + u32 size: 28 + u16 version: 258 + u16 cseg: 61440 + u32 offset: 54479 + u16 cseg_16: 61440 + u16 dseg: 61440 + u16 flags: 3 + u16 cseg_len: 65520 + u16 cseg_16_len: 65520 + u16 dseg_len: 65520 +} +Multiboot 2 info tag { + u32 type: 3 (module) + u32 size: 29 + u32 mod_start: 0x102000 + u32 mod_end: 0x10329c + char cmdline[]: "hello module" +} +Multiboot 2 info tag { + u32 type: 3 (module) + u32 size: 17 + u32 mod_start: 0x104000 + u32 mod_end: 0x105254 + char cmdline[]: "" +} +Multiboot 2 info tag { + u32 type: 6 (memory map) + u32 size: 160 + u32 entry_size: 24 + u32 entry_version: 0 + varies(entry_size) entries[]: [ + [0] entry: { + u64 base_addr: 0x0 + u64 length: 654336 + u32 type: 1 + u32 reserved: 0x0 + } + [1] entry: { + u64 base_addr: 0x9fc00 + u64 length: 1024 + u32 type: 2 + u32 reserved: 0x0 + } + [2] entry: { + u64 base_addr: 0xf0000 + u64 length: 65536 + u32 type: 2 + u32 reserved: 0x0 + } + [3] entry: { + u64 base_addr: 0x100000 + u64 length: 133038080 + u32 type: 1 + u32 reserved: 0x0 + } + [4] entry: { + u64 base_addr: 0x7fe0000 + u64 length: 131072 + u32 type: 2 + u32 reserved: 0x0 + } + [5] entry: { + u64 base_addr: 0xfffc0000 + u64 length: 262144 + u32 type: 2 + u32 reserved: 0x0 + } + ] +} +Multiboot 2 info tag { + u32 type: 9 (ELF symbols) + u32 size: 420 + u32 num: 10 + u32 entsize: 40 + u32 shndx: 9 +} +Multiboot 2 info tag { + u32 type: 4 (basic memory info) + u32 size: 16 + u32 mem_lower: 639 + u32 mem_upper: 129920 +} +Multiboot 2 info tag { + u32 type: 5 (BIOS boot device) + u32 size: 20 + u32 biosdev: 224 + u32 partition: 4294967295 + u32 sub_partition: 4294967295 +} +Multiboot 2 info tag { + u32 type: 8 (framebuffer info) + u32 size: 32 + u64 framebuffer_addr: 0xb8000 + u32 framebuffer_pitch: 160 + u32 framebuffer_width: 80 + u32 framebuffer_height: 25 + u8 framebuffer_bpp: 16 + u8 framebuffer_type: 2 + u16 reserved: 0x0 +} +Multiboot 2 info tag { + u32 type: 14 (ACPI old RSDP) + u32 size: 28 +} +Multiboot 2 info tag { + u32 type: 0 (none) + u32 size: 8 +} diff --git a/fixtures/multiboot2_info_example2.txt b/fixtures/multiboot2_info_example2.txt new file mode 100644 index 0000000..6ac5c40 --- /dev/null +++ b/fixtures/multiboot2_info_example2.txt @@ -0,0 +1,234 @@ +Multiboot 2 info { + u32 size: 1816 + u32 reserved: 0x0 +} +Multiboot 2 info tag { + u32 type: 1 (boot cmd line) + u32 size: 23 + char cmdline[]: "Hello, Kernel!" +} +Multiboot 2 info tag { + u32 type: 2 (boot loader name) + u32 size: 30 + char name[]: "GRUB 2.02-2ubuntu8.20" +} +Multiboot 2 info tag { + u32 type: 3 (module) + u32 size: 33 + u32 mod_start: 0x7b + u32 mod_end: 0x1c8 + char cmdline[]: "Hello, Module 1!" +} +Multiboot 2 info tag { + u32 type: 3 (module) + u32 size: 33 + u32 mod_start: 0x7b + u32 mod_end: 0x1c8 + char cmdline[]: "Hello, Module 2!" +} +Multiboot 2 info tag { + u32 type: 4 (basic memory info) + u32 size: 16 + u32 mem_lower: 123 + u32 mem_upper: 456 +} +Multiboot 2 info tag { + u32 type: 5 (BIOS boot device) + u32 size: 20 + u32 biosdev: 0 + u32 partition: 1 + u32 sub_partition: 2 +} +Multiboot 2 info tag { + u32 type: 6 (memory map) + u32 size: 160 + u32 entry_size: 24 + u32 entry_version: 0 + varies(entry_size) entries[]: [ + [0] entry: { + u64 base_addr: 0x0 + u64 length: 654336 + u32 type: 1 + u32 reserved: 0x0 + } + [1] entry: { + u64 base_addr: 0x9fc00 + u64 length: 1024 + u32 type: 2 + u32 reserved: 0x0 + } + [2] entry: { + u64 base_addr: 0xf0000 + u64 length: 65536 + u32 type: 2 + u32 reserved: 0x0 + } + [3] entry: { + u64 base_addr: 0x100000 + u64 length: 133038080 + u32 type: 1 + u32 reserved: 0x0 + } + [4] entry: { + u64 base_addr: 0x7fe0000 + u64 length: 131072 + u32 type: 2 + u32 reserved: 0x0 + } + [5] entry: { + u64 base_addr: 0xfffc0000 + u64 length: 262144 + u32 type: 2 + u32 reserved: 0x0 + } + ] +} +Multiboot 2 info tag { + u32 type: 7 (VBE info) + u32 size: 784 + u16 vbe_mode: 0 + u16 vbe_interface_seg: 123 + u16 vbe_interface_off: 456 + u16 vbe_interface_len: 789 + u8 vbe_control_info[]: [ + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 123 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 123 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ] + u8 vbe_mode_info[]: [ + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ] +} +Multiboot 2 info tag { + u32 type: 8 (framebuffer info) + u32 size: 40 + u64 framebuffer_addr: 0x7b + u32 framebuffer_pitch: 456 + u32 framebuffer_width: 123 + u32 framebuffer_height: 456 + u8 framebuffer_bpp: 8 + u8 framebuffer_type: 1 + u16 reserved: 0x0 +} +Multiboot 2 info tag { + u32 type: 9 (ELF symbols) + u32 size: 420 + u32 num: 10 + u32 entsize: 40 + u32 shndx: 9 +} +Multiboot 2 info tag { + u32 type: 10 (APM table) + u32 size: 28 + u16 version: 0 + u16 cseg: 123 + u32 offset: 456 + u16 cseg_16: 789 + u16 dseg: 123 + u16 flags: 1 + u16 cseg_len: 456 + u16 cseg_16_len: 789 + u16 dseg_len: 123 +} +Multiboot 2 info tag { + u32 type: 11 (EFI 32bit system table ptr) + u32 size: 12 + u32 pointer: 0 +} +Multiboot 2 info tag { + u32 type: 12 (EFI 64bit system table ptr) + u32 size: 16 + u64 pointer: 0 +} +Multiboot 2 info tag { + u32 type: 13 (SMBIOS tables) + u32 size: 24 + u8 major: 1 + u8 minor: 2 + u8 reserved[6]: [0x0, 0x0, 0x0, 0x0, 0x0, 0x0] +} +Multiboot 2 info tag { + u32 type: 14 (ACPI old RSDP) + u32 size: 16 +} +Multiboot 2 info tag { + u32 type: 15 (ACPI new RSDP) + u32 size: 16 +} +Multiboot 2 info tag { + u32 type: 16 (networking info) + u32 size: 16 +} +Multiboot 2 info tag { + u32 type: 17 (EFI memory map) + u32 size: 24 + u32 descriptor_size: 123 + u32 descriptor_version: 1 +} +Multiboot 2 info tag { + u32 type: 18 (EFI boot services not terminated) + u32 size: 8 +} +Multiboot 2 info tag { + u32 type: 19 (EFI 32bit image handle ptr) + u32 size: 12 + u32 pointer: 0 +} +Multiboot 2 info tag { + u32 type: 20 (EFI 64bit image handle ptr) + u32 size: 16 + u64 pointer: 0 +} +Multiboot 2 info tag { + u32 type: 21 (image load base phys addr) + u32 size: 12 + u32 load_base_addr: 0x7b +} +Multiboot 2 info tag { + u32 type: 0 (none) + u32 size: 8 +} diff --git a/include/.gitignore b/include/.gitignore new file mode 100644 index 0000000..5441d2a --- /dev/null +++ b/include/.gitignore @@ -0,0 +1 @@ +/kernaux/version.h diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..e98bf74 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,33 @@ +/multiboot2_header_print0 +/multiboot2_header_print1 +/multiboot2_header_print2 +/multiboot2_info_print0 +/multiboot2_info_print1 +/multiboot2_info_print2 +/test_arch_i386 +/test_cmdline +/test_cmdline_gen +/test_cmdline_gen.c +/test_elf +/test_free_list +/test_mbr +/test_memmap +/test_multiboot2_common_packing +/test_multiboot2_header_helpers +/test_multiboot2_header_print +/test_multiboot2_header_print.c +/test_multiboot2_header_validation +/test_multiboot2_info_helpers +/test_multiboot2_info_print +/test_multiboot2_info_print.c +/test_multiboot2_info_validation +/test_ntoa +/test_ntoa_assert +/test_pfa +/test_pfa_assert +/test_printf +/test_printf_fmt_gen +/test_printf_fmt_gen.c +/test_printf_gen +/test_printf_gen.c +/test_units_human diff --git a/tests/Makefile.am b/tests/Makefile.am index 6796b1b..0441986 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -217,7 +217,10 @@ TESTS += test_multiboot2_header_print test_multiboot2_header_print_DEPENDENCIES = \ multiboot2_header_print0 \ multiboot2_header_print1 \ - multiboot2_header_print2 + multiboot2_header_print2 \ + ../fixtures/multiboot2_header_example0.txt \ + ../fixtures/multiboot2_header_example1.txt \ + ../fixtures/multiboot2_header_example2.txt test_multiboot2_header_print_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_header_print_SOURCES = \ main.c \ @@ -261,7 +264,10 @@ TESTS += test_multiboot2_info_print test_multiboot2_info_print_DEPENDENCIES = \ multiboot2_info_print0 \ multiboot2_info_print1 \ - multiboot2_info_print2 + multiboot2_info_print2 \ + ../fixtures/multiboot2_info_example0.txt \ + ../fixtures/multiboot2_info_example1.txt \ + ../fixtures/multiboot2_info_example2.txt test_multiboot2_info_print_LDADD = $(top_builddir)/libkernaux.la test_multiboot2_info_print_SOURCES = \ main.c \ diff --git a/tests/test_multiboot2_header_print.c b/tests/test_multiboot2_header_print.c deleted file mode 100644 index 9d4e87f..0000000 --- a/tests/test_multiboot2_header_print.c +++ /dev/null @@ -1,218 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#ifndef __USE_POSIX2 -#define __USE_POSIX2 -#endif -#include - -static const char output0[] = - "Multiboot 2 header {\n" - " u32 magic: 0xe85250d6\n" - " u32 arch: 0 (i386)\n" - " u32 size: 24\n" - " u32 checksum: 0x17adaf12\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 0 (none)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 8\n" - "}\n"; - -static const char output1[] = - "Multiboot 2 header {\n" - " u32 magic: 0xe85250d6\n" - " u32 arch: 4 (MIPS32)\n" - " u32 size: 104\n" - " u32 checksum: 0x17adaebe\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 4 (flags)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 12\n" - " u32 console_flags: 0x0 ()\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 4 (flags)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 12\n" - " u32 console_flags: 0x1 (\n" - " REQUIRE_CONSOLE\n" - " )\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 4 (flags)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 12\n" - " u32 console_flags: 0x2 (\n" - " EGA_SUPPORT\n" - " )\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 4 (flags)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 12\n" - " u32 console_flags: 0x3 (\n" - " REQUIRE_CONSOLE |\n" - " EGA_SUPPORT\n" - " )\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 1 (information request)\n" - " u16 flags: 0x1 (\n" - " OPTIONAL\n" - " )\n" - " u32 size: 12\n" - " u32 mbi_tag_types[]: [\n" - " 0 (none)\n" - " ]\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 0 (none)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 8\n" - "}\n"; - -static const char output2[] = - "Multiboot 2 header {\n" - " u32 magic: 0xe85250d6\n" - " u32 arch: 0 (i386)\n" - " u32 size: 272\n" - " u32 checksum: 0x17adae1a\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 1 (information request)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 96\n" - " u32 mbi_tag_types[]: [\n" - " 0 (none)\n" - " 1 (boot cmd line)\n" - " 2 (boot loader name)\n" - " 3 (module)\n" - " 4 (basic memory info)\n" - " 5 (BIOS boot device)\n" - " 6 (memory map)\n" - " 7 (VBE info)\n" - " 8 (framebuffer info)\n" - " 9 (ELF symbols)\n" - " 10 (APM table)\n" - " 11 (EFI 32bit system table ptr)\n" - " 12 (EFI 64bit system table ptr)\n" - " 13 (SMBIOS tables)\n" - " 14 (ACPI old RSDP)\n" - " 15 (ACPI new RSDP)\n" - " 16 (networking info)\n" - " 17 (EFI memory map)\n" - " 18 (EFI boot services not terminated)\n" - " 19 (EFI 32bit image handle ptr)\n" - " 20 (EFI 64bit image handle ptr)\n" - " 21 (image load base phys addr)\n" - " ]\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 2 (address)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 24\n" - " u32 header_addr: 0xcafebabe\n" - " u32 load_addr: 0xdeadbeaf\n" - " u32 load_end_addr: 0xdeadbabe\n" - " u32 bss_end_addr: 0xcafebeaf\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 3 (entry address)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 12\n" - " u32 entry_addr: 0xcafebabe\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 4 (flags)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 12\n" - " u32 console_flags: 0x0 ()\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 5 (framebuffer)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 20\n" - " u32 width: 80\n" - " u32 height: 25\n" - " u32 depth: 8\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 6 (module alignment)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 8\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 7 (EFI boot services)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 8\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 8 (EFI i386 entry address)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 12\n" - " u32 entry_addr: 0xcafebabe\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 9 (EFI amd64 entry address)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 12\n" - " u32 entry_addr: 0xdeadbeaf\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 10 (relocatable header)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 24\n" - " u32 min_addr: 0xcafebabe\n" - " u32 max_addr: 0xdeadbeaf\n" - " u32 align: 8\n" - " u32 preference: 1 (lowest)\n" - "}\n" - "Multiboot 2 header tag {\n" - " u16 type: 0 (none)\n" - " u16 flags: 0x0 ()\n" - " u32 size: 8\n" - "}\n"; - -void test_main() -{ - { - FILE *const fd = popen("./multiboot2_header_print0", "r"); - assert(fd != NULL); - - for (const char *ch = output0; *ch; ++ch) { - assert(fgetc(fd) == *ch); - } - - const int status = pclose(fd); - assert(status == 0); - } - - { - FILE *const fd = popen("./multiboot2_header_print1", "r"); - assert(fd != NULL); - - for (const char *ch = output1; *ch; ++ch) { - assert(fgetc(fd) == *ch); - } - - const int status = pclose(fd); - assert(status == 0); - } - - { - FILE *const fd = popen("./multiboot2_header_print2", "r"); - assert(fd != NULL); - - for (const char *ch = output2; *ch; ++ch) { - assert(fgetc(fd) == *ch); - } - - const int status = pclose(fd); - assert(status == 0); - } -} diff --git a/tests/test_multiboot2_header_print.c.in b/tests/test_multiboot2_header_print.c.in new file mode 100644 index 0000000..00cc39e --- /dev/null +++ b/tests/test_multiboot2_header_print.c.in @@ -0,0 +1,61 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#ifndef __USE_POSIX2 +#define __USE_POSIX2 +#endif +#include + +void test_main() +{ + { + FILE *const print_file = + popen("@abs_top_builddir@/tests/multiboot2_header_print0", "r"); + FILE *const text_file = + fopen("@abs_top_srcdir@/fixtures/multiboot2_header_example0.txt", "r"); + assert(print_file != NULL); + assert(text_file != NULL); + + while (!feof(text_file)) { + assert(fgetc(print_file) == fgetc(text_file)); + } + + assert(pclose(print_file) == 0); + assert(fclose(text_file) == 0); + } + + { + FILE *const print_file = + popen("@abs_top_builddir@/tests/multiboot2_header_print1", "r"); + FILE *const text_file = + fopen("@abs_top_srcdir@/fixtures/multiboot2_header_example1.txt", "r"); + assert(print_file != NULL); + assert(text_file != NULL); + + while (!feof(text_file)) { + assert(fgetc(print_file) == fgetc(text_file)); + } + + assert(pclose(print_file) == 0); + assert(fclose(text_file) == 0); + } + + { + FILE *const print_file = + popen("@abs_top_builddir@/tests/multiboot2_header_print2", "r"); + FILE *const text_file = + fopen("@abs_top_srcdir@/fixtures/multiboot2_header_example2.txt", "r"); + assert(print_file != NULL); + assert(text_file != NULL); + + while (!feof(text_file)) { + assert(fgetc(print_file) == fgetc(text_file)); + } + + assert(pclose(print_file) == 0); + assert(fclose(text_file) == 0); + } +} diff --git a/tests/test_multiboot2_info_print.c b/tests/test_multiboot2_info_print.c deleted file mode 100644 index 2f5d7cf..0000000 --- a/tests/test_multiboot2_info_print.c +++ /dev/null @@ -1,441 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifndef __USE_POSIX2 -#define __USE_POSIX2 -#endif -#include - -static const char output0[] = - "Multiboot 2 info {\n" - " u32 size: 16\n" - " u32 reserved: 0x0\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 0 (none)\n" - " u32 size: 8\n" - "}\n"; - -static const char output1[] = - "Multiboot 2 info {\n" - " u32 size: 864\n" - " u32 reserved: 0x0\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 21 (image load base phys addr)\n" - " u32 size: 12\n" - " u32 load_base_addr: 0x400000\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 1 (boot cmd line)\n" - " u32 size: 21\n" - " char cmdline[]: \"hello kernel\"\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 2 (boot loader name)\n" - " u32 size: 30\n" - " char name[]: \"GRUB 2.02-2ubuntu8.20\"\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 10 (APM table)\n" - " u32 size: 28\n" - " u16 version: 258\n" - " u16 cseg: 61440\n" - " u32 offset: 54479\n" - " u16 cseg_16: 61440\n" - " u16 dseg: 61440\n" - " u16 flags: 3\n" - " u16 cseg_len: 65520\n" - " u16 cseg_16_len: 65520\n" - " u16 dseg_len: 65520\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 3 (module)\n" - " u32 size: 29\n" - " u32 mod_start: 0x102000\n" - " u32 mod_end: 0x10329c\n" - " char cmdline[]: \"hello module\"\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 3 (module)\n" - " u32 size: 17\n" - " u32 mod_start: 0x104000\n" - " u32 mod_end: 0x105254\n" - " char cmdline[]: \"\"\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 6 (memory map)\n" - " u32 size: 160\n" - " u32 entry_size: 24\n" - " u32 entry_version: 0\n" - " varies(entry_size) entries[]: [\n" - " [0] entry: {\n" - " u64 base_addr: 0x0\n" - " u64 length: 654336\n" - " u32 type: 1\n" - " u32 reserved: 0x0\n" - " }\n" - " [1] entry: {\n" - " u64 base_addr: 0x9fc00\n" - " u64 length: 1024\n" - " u32 type: 2\n" - " u32 reserved: 0x0\n" - " }\n" - " [2] entry: {\n" - " u64 base_addr: 0xf0000\n" - " u64 length: 65536\n" - " u32 type: 2\n" - " u32 reserved: 0x0\n" - " }\n" - " [3] entry: {\n" - " u64 base_addr: 0x100000\n" - " u64 length: 133038080\n" - " u32 type: 1\n" - " u32 reserved: 0x0\n" - " }\n" - " [4] entry: {\n" - " u64 base_addr: 0x7fe0000\n" - " u64 length: 131072\n" - " u32 type: 2\n" - " u32 reserved: 0x0\n" - " }\n" - " [5] entry: {\n" - " u64 base_addr: 0xfffc0000\n" - " u64 length: 262144\n" - " u32 type: 2\n" - " u32 reserved: 0x0\n" - " }\n" - " ]\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 9 (ELF symbols)\n" - " u32 size: 420\n" - " u32 num: 10\n" - " u32 entsize: 40\n" - " u32 shndx: 9\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 4 (basic memory info)\n" - " u32 size: 16\n" - " u32 mem_lower: 639\n" - " u32 mem_upper: 129920\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 5 (BIOS boot device)\n" - " u32 size: 20\n" - " u32 biosdev: 224\n" - " u32 partition: 4294967295\n" - " u32 sub_partition: 4294967295\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 8 (framebuffer info)\n" - " u32 size: 32\n" - " u64 framebuffer_addr: 0xb8000\n" - " u32 framebuffer_pitch: 160\n" - " u32 framebuffer_width: 80\n" - " u32 framebuffer_height: 25\n" - " u8 framebuffer_bpp: 16\n" - " u8 framebuffer_type: 2\n" - " u16 reserved: 0x0\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 14 (ACPI old RSDP)\n" - " u32 size: 28\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 0 (none)\n" - " u32 size: 8\n" - "}\n"; - -static const char output2_part1[] = - "Multiboot 2 info {\n" - " u32 size: 1816\n" - " u32 reserved: 0x0\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 1 (boot cmd line)\n" - " u32 size: 23\n" - " char cmdline[]: \"Hello, Kernel!\"\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 2 (boot loader name)\n" - " u32 size: 30\n" - " char name[]: \"GRUB 2.02-2ubuntu8.20\"\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 3 (module)\n" - " u32 size: 33\n" - " u32 mod_start: 0x7b\n" - " u32 mod_end: 0x1c8\n" - " char cmdline[]: \"Hello, Module 1!\"\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 3 (module)\n" - " u32 size: 33\n" - " u32 mod_start: 0x7b\n" - " u32 mod_end: 0x1c8\n" - " char cmdline[]: \"Hello, Module 2!\"\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 4 (basic memory info)\n" - " u32 size: 16\n" - " u32 mem_lower: 123\n" - " u32 mem_upper: 456\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 5 (BIOS boot device)\n" - " u32 size: 20\n" - " u32 biosdev: 0\n" - " u32 partition: 1\n" - " u32 sub_partition: 2\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 6 (memory map)\n" - " u32 size: 160\n" - " u32 entry_size: 24\n" - " u32 entry_version: 0\n" - " varies(entry_size) entries[]: [\n" - " [0] entry: {\n" - " u64 base_addr: 0x0\n" - " u64 length: 654336\n" - " u32 type: 1\n" - " u32 reserved: 0x0\n" - " }\n" - " [1] entry: {\n" - " u64 base_addr: 0x9fc00\n" - " u64 length: 1024\n" - " u32 type: 2\n" - " u32 reserved: 0x0\n" - " }\n" - " [2] entry: {\n" - " u64 base_addr: 0xf0000\n" - " u64 length: 65536\n" - " u32 type: 2\n" - " u32 reserved: 0x0\n" - " }\n" - " [3] entry: {\n" - " u64 base_addr: 0x100000\n" - " u64 length: 133038080\n" - " u32 type: 1\n" - " u32 reserved: 0x0\n" - " }\n" - " [4] entry: {\n" - " u64 base_addr: 0x7fe0000\n" - " u64 length: 131072\n" - " u32 type: 2\n" - " u32 reserved: 0x0\n" - " }\n" - " [5] entry: {\n" - " u64 base_addr: 0xfffc0000\n" - " u64 length: 262144\n" - " u32 type: 2\n" - " u32 reserved: 0x0\n" - " }\n" - " ]\n" - "}\n"; - -static const char output2_part2[] = - "Multiboot 2 info tag {\n" - " u32 type: 7 (VBE info)\n" - " u32 size: 784\n" - " u16 vbe_mode: 0\n" - " u16 vbe_interface_seg: 123\n" - " u16 vbe_interface_off: 456\n" - " u16 vbe_interface_len: 789\n" - " u8 vbe_control_info[]: [\n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 123 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 123\n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " ]\n" - " u8 vbe_mode_info[]: [\n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255\n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n" - " ]\n" - "}\n"; - -static const char output2_part3[] = - "Multiboot 2 info tag {\n" - " u32 type: 8 (framebuffer info)\n" - " u32 size: 40\n" - " u64 framebuffer_addr: 0x7b\n" - " u32 framebuffer_pitch: 456\n" - " u32 framebuffer_width: 123\n" - " u32 framebuffer_height: 456\n" - " u8 framebuffer_bpp: 8\n" - " u8 framebuffer_type: 1\n" - " u16 reserved: 0x0\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 9 (ELF symbols)\n" - " u32 size: 420\n" - " u32 num: 10\n" - " u32 entsize: 40\n" - " u32 shndx: 9\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 10 (APM table)\n" - " u32 size: 28\n" - " u16 version: 0\n" - " u16 cseg: 123\n" - " u32 offset: 456\n" - " u16 cseg_16: 789\n" - " u16 dseg: 123\n" - " u16 flags: 1\n" - " u16 cseg_len: 456\n" - " u16 cseg_16_len: 789\n" - " u16 dseg_len: 123\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 11 (EFI 32bit system table ptr)\n" - " u32 size: 12\n" - " u32 pointer: 0\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 12 (EFI 64bit system table ptr)\n" - " u32 size: 16\n" - " u64 pointer: 0\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 13 (SMBIOS tables)\n" - " u32 size: 24\n" - " u8 major: 1\n" - " u8 minor: 2\n" - " u8 reserved[6]: [0x0, 0x0, 0x0, 0x0, 0x0, 0x0]\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 14 (ACPI old RSDP)\n" - " u32 size: 16\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 15 (ACPI new RSDP)\n" - " u32 size: 16\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 16 (networking info)\n" - " u32 size: 16\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 17 (EFI memory map)\n" - " u32 size: 24\n" - " u32 descriptor_size: 123\n" - " u32 descriptor_version: 1\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 18 (EFI boot services not terminated)\n" - " u32 size: 8\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 19 (EFI 32bit image handle ptr)\n" - " u32 size: 12\n" - " u32 pointer: 0\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 20 (EFI 64bit image handle ptr)\n" - " u32 size: 16\n" - " u64 pointer: 0\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 21 (image load base phys addr)\n" - " u32 size: 12\n" - " u32 load_base_addr: 0x7b\n" - "}\n" - "Multiboot 2 info tag {\n" - " u32 type: 0 (none)\n" - " u32 size: 8\n" - "}\n"; - -void test_main() -{ - { - FILE *const fd = popen("./multiboot2_info_print0", "r"); - assert(fd != NULL); - - for (const char *ch = output0; *ch; ++ch) { - assert(fgetc(fd) == *ch); - } - - const int status = pclose(fd); - assert(status == 0); - } - - { - FILE *const fd = popen("./multiboot2_info_print1", "r"); - assert(fd != NULL); - - for (const char *ch = output1; *ch; ++ch) { - assert(fgetc(fd) == *ch); - } - - const int status = pclose(fd); - assert(status == 0); - } - - { - const size_t part1_len = strlen(output2_part1); - const size_t part2_len = strlen(output2_part2); - const size_t part3_len = strlen(output2_part3); - char *const output2 = malloc(1 + part1_len + part2_len + part3_len); - assert(output2); - strcpy(output2, output2_part1); - strcat(output2, output2_part2); - strcat(output2, output2_part3); - - FILE *const fd = popen("./multiboot2_info_print2", "r"); - assert(fd != NULL); - - for (const char *ch = output2; *ch; ++ch) { - assert(fgetc(fd) == *ch); - } - - const int status = pclose(fd); - assert(status == 0); - } -} diff --git a/tests/test_multiboot2_info_print.c.in b/tests/test_multiboot2_info_print.c.in new file mode 100644 index 0000000..d4155a9 --- /dev/null +++ b/tests/test_multiboot2_info_print.c.in @@ -0,0 +1,61 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#ifndef __USE_POSIX2 +#define __USE_POSIX2 +#endif +#include + +void test_main() +{ + { + FILE *const print_file = + popen("@abs_top_builddir@/tests/multiboot2_info_print0", "r"); + FILE *const text_file = + fopen("@abs_top_srcdir@/fixtures/multiboot2_info_example0.txt", "r"); + assert(print_file != NULL); + assert(text_file != NULL); + + while (!feof(text_file)) { + assert(fgetc(print_file) == fgetc(text_file)); + } + + assert(pclose(print_file) == 0); + assert(fclose(text_file) == 0); + } + + { + FILE *const print_file = + popen("@abs_top_builddir@/tests/multiboot2_info_print1", "r"); + FILE *const text_file = + fopen("@abs_top_srcdir@/fixtures/multiboot2_info_example1.txt", "r"); + assert(print_file != NULL); + assert(text_file != NULL); + + while (!feof(text_file)) { + assert(fgetc(print_file) == fgetc(text_file)); + } + + assert(pclose(print_file) == 0); + assert(fclose(text_file) == 0); + } + + { + FILE *const print_file = + popen("@abs_top_builddir@/tests/multiboot2_info_print2", "r"); + FILE *const text_file = + fopen("@abs_top_srcdir@/fixtures/multiboot2_info_example2.txt", "r"); + assert(print_file != NULL); + assert(text_file != NULL); + + while (!feof(text_file)) { + assert(fgetc(print_file) == fgetc(text_file)); + } + + assert(pclose(print_file) == 0); + assert(fclose(text_file) == 0); + } +}