Add fixtures (#150)

This commit is contained in:
Alex Kotov 2022-12-17 16:26:20 +04:00 committed by GitHub
parent 22ec69dfca
commit 79c8bcad6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 217 additions and 54 deletions

11
.gitignore vendored
View File

@ -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

View File

@ -1,10 +1,11 @@
2022-12-17 Alex Kotov <kotovalexarian@gmail.com>
* configure.ac: Feature "--(enable|disable)-fixtures" has been added
* src/multiboot2/*_print.c: Print some values in hex
2022-12-16 Alex Kotov <kotovalexarian@gmail.com>
* 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 <kotovalexarian@gmail.com>

View File

@ -13,6 +13,10 @@ endif
SUBDIRS += .
if ENABLE_FIXTURES
SUBDIRS += fixtures
endif
if ENABLE_CHECKS
SUBDIRS += examples tests
endif

View File

@ -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
```

View File

@ -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|

View File

@ -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']

View File

@ -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|

View File

@ -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__,
)

View File

@ -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])])

53
fixtures/Makefile.am Normal file
View File

@ -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

View File

@ -0,0 +1,84 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}

View File

@ -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 #

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_header_example0.h"
#include "../fixtures/multiboot2_header_example0.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_header_example1.h"
#include "../fixtures/multiboot2_header_example1.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_header_example2.h"
#include "../fixtures/multiboot2_header_example2.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_info_example0.h"
#include "../fixtures/multiboot2_info_example0.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_info_example1.h"
#include "../fixtures/multiboot2_info_example1.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_info_example2.h"
#include "../fixtures/multiboot2_info_example2.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -7,8 +7,8 @@
#include <assert.h>
#include <stdint.h>
#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 { \

View File

@ -4,8 +4,8 @@
#include <kernaux/multiboot2.h>
#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()
{

View File

@ -7,8 +7,8 @@
#include <assert.h>
#include "multiboot2_info_example1.h"
#include "multiboot2_info_example2.h"
#include "../fixtures/multiboot2_info_example1.h"
#include "../fixtures/multiboot2_info_example2.h"
#include <kernaux/macro/packing_start.run>

View File

@ -7,8 +7,8 @@
#include <assert.h>
#include "multiboot2_info_example1.h"
#include "multiboot2_info_example2.h"
#include "../fixtures/multiboot2_info_example1.h"
#include "../fixtures/multiboot2_info_example2.h"
#include <kernaux/macro/packing_start.run>