diff options
author | Matt Fleming <matt.fleming@intel.com> | 2013-07-17 14:53:08 +0100 |
---|---|---|
committer | Matt Fleming <matt.fleming@intel.com> | 2013-07-23 14:58:41 +0100 |
commit | 82546447f46cab11f13380fe658b1f79cdd38654 (patch) | |
tree | f236c3eeddcab926f1dbba768c549f2cb61b9847 /tests | |
parent | 21f8596c58a9791e7ea1f4ba93be17eed60a05b6 (diff) | |
download | syslinux-82546447f46cab11f13380fe658b1f79cdd38654.tar.gz |
tests: Syslinux unit tests
Improve our faith in the validity of the Syslinux code by writing unit
tests where possible. These should be used in addition to the regression
tests - unit tests are a means of doing very fine-grained testing of
code, whereas the regression tests are end-to-end tests that exercise
abstract functionality.
Unit tests run on your development machine and above all else, their
execution time should be kept to a minimum to encourage repeated runs of
the unit testsuite.
The Syslinux header hierarchy has been reconstructed under
tests/unittest/include. This allows us to reuse header files where
appropriate by simply creating a file with the same name and including
the original, e.g.
tests/unittest/include/com32.h:
#include <../../../com32/include/com32.h>
Places where we need to override definitions (so that the tests build in
a dev environment) obviously won't include the original header file, but
such scenarios should be kept to a minimum, since you're not really
testing any Syslinux code that way.
To execute the collection of unit tests type,
make unittest
Sample output might look like,
Executing unit tests
Running library unit tests...
[+] zonelist passed
[+] movebits passed
[+] memscan passed
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittest/include/com32.h | 1 | ||||
-rw-r--r-- | tests/unittest/include/core.h | 8 | ||||
-rw-r--r-- | tests/unittest/include/dprintf.h | 6 | ||||
-rw-r--r-- | tests/unittest/include/klibc/compiler.h | 15 | ||||
-rw-r--r-- | tests/unittest/include/linux/list.h | 9 | ||||
-rw-r--r-- | tests/unittest/include/minmax.h | 1 | ||||
-rw-r--r-- | tests/unittest/include/pxe.h | 3 | ||||
-rw-r--r-- | tests/unittest/include/syslinux/align.h | 1 | ||||
-rw-r--r-- | tests/unittest/include/syslinux/memscan.h | 1 | ||||
-rw-r--r-- | tests/unittest/include/syslinux/movebits.h | 1 | ||||
-rw-r--r-- | tests/unittest/include/unittest.h | 29 |
11 files changed, 75 insertions, 0 deletions
diff --git a/tests/unittest/include/com32.h b/tests/unittest/include/com32.h new file mode 100644 index 00000000..38b63d2d --- /dev/null +++ b/tests/unittest/include/com32.h @@ -0,0 +1 @@ +#include "../../../com32/include/com32.h" diff --git a/tests/unittest/include/core.h b/tests/unittest/include/core.h new file mode 100644 index 00000000..edfb75b7 --- /dev/null +++ b/tests/unittest/include/core.h @@ -0,0 +1,8 @@ +#ifndef _CORE_H_ +#define _CORE_H_ + +#include <klibc/compiler.h> + +#define __lowmem + +#endif /* _CORE_H_ */ diff --git a/tests/unittest/include/dprintf.h b/tests/unittest/include/dprintf.h new file mode 100644 index 00000000..de251e16 --- /dev/null +++ b/tests/unittest/include/dprintf.h @@ -0,0 +1,6 @@ +#ifndef _DPRINTF_H_ +#define _DPRINTF_H_ + +#define dprintf + +#endif /* _DPRINTF_H_ */ diff --git a/tests/unittest/include/klibc/compiler.h b/tests/unittest/include/klibc/compiler.h new file mode 100644 index 00000000..470a51cb --- /dev/null +++ b/tests/unittest/include/klibc/compiler.h @@ -0,0 +1,15 @@ +#ifndef _COMPILER_H_ +#define _COMPILER_H_ + +#define __export + +/* Packed structures */ +#define __packed __attribute__((packed)) + +/* Weak symbols */ +#define __weak + +/* Specific calling conventions */ +#define __cdecl + +#endif /* _COMPILER_H_ */ diff --git a/tests/unittest/include/linux/list.h b/tests/unittest/include/linux/list.h new file mode 100644 index 00000000..c553a148 --- /dev/null +++ b/tests/unittest/include/linux/list.h @@ -0,0 +1,9 @@ +#undef container_of +/* + * The container_of construct: if p is a pointer to member m of + * container class c, then return a pointer to the container of which + * *p is a member. + */ +#define container_of(p, c, m) ((c *)((char *)(p) - offsetof(c,m))) + +#include <../../../com32/include/linux/list.h> diff --git a/tests/unittest/include/minmax.h b/tests/unittest/include/minmax.h new file mode 100644 index 00000000..dfe4504d --- /dev/null +++ b/tests/unittest/include/minmax.h @@ -0,0 +1 @@ +#include <../../../com32/include/minmax.h> diff --git a/tests/unittest/include/pxe.h b/tests/unittest/include/pxe.h new file mode 100644 index 00000000..03c4ca6d --- /dev/null +++ b/tests/unittest/include/pxe.h @@ -0,0 +1,3 @@ +#include <../../../com32/include/syslinux/pxe_api.h> + +#define PKTBUF_SIZE 2048 diff --git a/tests/unittest/include/syslinux/align.h b/tests/unittest/include/syslinux/align.h new file mode 100644 index 00000000..d7dc3bd3 --- /dev/null +++ b/tests/unittest/include/syslinux/align.h @@ -0,0 +1 @@ +#include <../../../com32/include/syslinux/align.h> diff --git a/tests/unittest/include/syslinux/memscan.h b/tests/unittest/include/syslinux/memscan.h new file mode 100644 index 00000000..6509e648 --- /dev/null +++ b/tests/unittest/include/syslinux/memscan.h @@ -0,0 +1 @@ +#include <../../../com32/include/syslinux/memscan.h> diff --git a/tests/unittest/include/syslinux/movebits.h b/tests/unittest/include/syslinux/movebits.h new file mode 100644 index 00000000..0749faaf --- /dev/null +++ b/tests/unittest/include/syslinux/movebits.h @@ -0,0 +1 @@ +#include <../../../com32/include/syslinux/movebits.h> diff --git a/tests/unittest/include/unittest.h b/tests/unittest/include/unittest.h new file mode 100644 index 00000000..9f23d805 --- /dev/null +++ b/tests/unittest/include/unittest.h @@ -0,0 +1,29 @@ +#ifndef _UNITTEST_H_ +#define _UNITTEST_H_ + +#include </usr/include/sys/types.h> +#include </usr/include/stdint.h> +#include </usr/include/assert.h> +#include </usr/include/stdlib.h> +#include </usr/include/stdio.h> +#include </usr/include/stdint.h> + +/* + * Provide a version of assert() that prints helpful error messages when + * the condition is false, but doesn't abort the running program. + */ +#define syslinux_assert(condition, ...) \ + if (!condition) {\ + fprintf(stderr, "Assertion failed at %s:%d: \"", __FILE__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\"\n"); \ + } + +#define syslinux_assert_str(condition, ...) \ + if (!(condition)) { \ + fprintf(stderr, "Assertion failed at %s:%d: \"", __FILE__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\", expr \"%s\"\n", __STRING(condition)); \ + } + +#endif /* _UNITTEST_H_ */ |