diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/alloc.c | 56 | ||||
-rw-r--r-- | tests/bfs/color_ca.out | 4 | ||||
-rw-r--r-- | tests/bfs/color_ca.sh | 10 | ||||
-rw-r--r-- | tests/bfs/color_ca_incapable.out | 27 | ||||
-rw-r--r-- | tests/bfs/color_ca_incapable.sh | 1 | ||||
-rw-r--r-- | tests/bfs/color_ext_case_nul.out | 27 | ||||
-rw-r--r-- | tests/bfs/color_ext_case_nul.sh | 5 | ||||
-rw-r--r-- | tests/bfs/color_ls.out | 4 | ||||
-rw-r--r-- | tests/bfs/color_notdir_slash_error.out | 0 | ||||
-rw-r--r-- | tests/bfs/color_notdir_slash_error.sh | 2 | ||||
-rw-r--r-- | tests/bit.c | 7 | ||||
-rw-r--r-- | tests/gnu/L_printf_types.out | 17 | ||||
-rw-r--r-- | tests/gnu/L_printf_types.sh | 1 | ||||
-rw-r--r-- | tests/posix/exec_substring_plus.out | 19 | ||||
-rw-r--r-- | tests/posix/exec_substring_plus.sh | 14 | ||||
-rw-r--r-- | tests/run.sh | 2 | ||||
-rw-r--r-- | tests/sighook.c | 21 | ||||
-rw-r--r-- | tests/trie.c | 5 | ||||
-rw-r--r-- | tests/util.sh | 2 |
19 files changed, 197 insertions, 27 deletions
diff --git a/tests/alloc.c b/tests/alloc.c index f91b428..4aae515 100644 --- a/tests/alloc.c +++ b/tests/alloc.c @@ -10,27 +10,45 @@ #include <stdlib.h> #include <stdint.h> +struct flexible { + alignas(64) int foo[8]; + int bar[]; +}; + +/** Check varena_realloc() poisoning for a size combination. */ +static struct flexible *check_varena_realloc(struct varena *varena, struct flexible *flexy, size_t old_count, size_t new_count) { + flexy = varena_realloc(varena, flexy, old_count, new_count); + bfs_everify(flexy); + + for (size_t i = 0; i < new_count; ++i) { + if (i < old_count) { + bfs_check(flexy->bar[i] == (int)i); + } else { + flexy->bar[i] = i; + } + } + + return flexy; +} + void check_alloc(void) { + // Check aligned allocation + void *ptr; + bfs_everify((ptr = zalloc(64, 129))); + bfs_check((uintptr_t)ptr % 64 == 0); + bfs_echeck((ptr = xrealloc(ptr, 64, 129, 65))); + bfs_check((uintptr_t)ptr % 64 == 0); + free(ptr); + // Check sizeof_flex() - struct flexible { - alignas(64) int foo[8]; - int bar[]; - }; bfs_check(sizeof_flex(struct flexible, bar, 0) >= sizeof(struct flexible)); bfs_check(sizeof_flex(struct flexible, bar, 16) % alignof(struct flexible) == 0); - size_t too_many = SIZE_MAX / sizeof(int) + 1; + // volatile to suppress -Walloc-size-larger-than + volatile size_t too_many = SIZE_MAX / sizeof(int) + 1; bfs_check(sizeof_flex(struct flexible, bar, too_many) == align_floor(alignof(struct flexible), SIZE_MAX)); - // Corner case: sizeof(type) > align_ceil(alignof(type), offsetof(type, member)) - // Doesn't happen in typical ABIs - bfs_check(flex_size(8, 16, 4, 4, 1) == 16); - // Make sure we detect allocation size overflows -#if __GNUC__ && !__clang__ -# pragma GCC diagnostic ignored "-Walloc-size-larger-than=" -#endif - bfs_check(ALLOC_ARRAY(int, too_many) == NULL && errno == EOVERFLOW); bfs_check(ZALLOC_ARRAY(int, too_many) == NULL && errno == EOVERFLOW); bfs_check(ALLOC_FLEX(struct flexible, bar, too_many) == NULL && errno == EOVERFLOW); @@ -41,10 +59,20 @@ void check_alloc(void) { VARENA_INIT(&varena, struct flexible, bar); for (size_t i = 0; i < 256; ++i) { - bfs_verify(varena_alloc(&varena, i)); + bfs_everify(varena_alloc(&varena, i)); struct arena *arena = &varena.arenas[varena.narenas - 1]; bfs_check(arena->size >= sizeof_flex(struct flexible, bar, i)); } + // Check varena_realloc() (un)poisoning + struct flexible *flexy = varena_alloc(&varena, 160); + bfs_everify(flexy); + + flexy = check_varena_realloc(&varena, flexy, 0, 160); + flexy = check_varena_realloc(&varena, flexy, 160, 192); + flexy = check_varena_realloc(&varena, flexy, 192, 160); + flexy = check_varena_realloc(&varena, flexy, 160, 320); + flexy = check_varena_realloc(&varena, flexy, 320, 96); + varena_destroy(&varena); } diff --git a/tests/bfs/color_ca.out b/tests/bfs/color_ca.out new file mode 100644 index 0000000..bf74202 --- /dev/null +++ b/tests/bfs/color_ca.out @@ -0,0 +1,4 @@ +[01;34m.[0m +[01;34m./[0m[01;36mlink[0m +[01;34m./[0m[30;41mcapable[0m +[01;34m./[0mnormal diff --git a/tests/bfs/color_ca.sh b/tests/bfs/color_ca.sh new file mode 100644 index 0000000..3aaaaf1 --- /dev/null +++ b/tests/bfs/color_ca.sh @@ -0,0 +1,10 @@ +test "$UNAME" = "Linux" || skip +invoke_bfs . -quit -capable || skip + +cd "$TEST" + +"$XTOUCH" normal capable +bfs_sudo setcap all+ep capable || skip +ln -s capable link + +LS_COLORS="ca=30;41:" bfs_diff . -color diff --git a/tests/bfs/color_ca_incapable.out b/tests/bfs/color_ca_incapable.out new file mode 100644 index 0000000..a439814 --- /dev/null +++ b/tests/bfs/color_ca_incapable.out @@ -0,0 +1,27 @@ +[01;34m$'rainbow/\e[1m'[0m +[01;34m$'rainbow/\e[1m/'[0m$'\e[0m' +[01;34mrainbow[0m +[01;34mrainbow/[0m[01;32mexec.sh[0m +[01;34mrainbow/[0m[01;35msocket[0m +[01;34mrainbow/[0m[01;36mbroken[0m +[01;34mrainbow/[0m[01;36mchardev_link[0m +[01;34mrainbow/[0m[01;36mlink.txt[0m +[01;34mrainbow/[0m[30;42msticky_ow[0m +[01;34mrainbow/[0m[30;43msgid[0m +[01;34mrainbow/[0m[33mpipe[0m +[01;34mrainbow/[0m[34;42mow[0m +[01;34mrainbow/[0m[37;41msugid[0m +[01;34mrainbow/[0m[37;41msuid[0m +[01;34mrainbow/[0m[37;44msticky[0m +[01;34mrainbow/[0mfile.dat +[01;34mrainbow/[0mfile.txt +[01;34mrainbow/[0mlower.gz +[01;34mrainbow/[0mlower.tar +[01;34mrainbow/[0mlower.tar.gz +[01;34mrainbow/[0mlu.tar.GZ +[01;34mrainbow/[0mmh1 +[01;34mrainbow/[0mmh2 +[01;34mrainbow/[0mul.TAR.gz +[01;34mrainbow/[0mupper.GZ +[01;34mrainbow/[0mupper.TAR +[01;34mrainbow/[0mupper.TAR.GZ diff --git a/tests/bfs/color_ca_incapable.sh b/tests/bfs/color_ca_incapable.sh new file mode 100644 index 0000000..f46a127 --- /dev/null +++ b/tests/bfs/color_ca_incapable.sh @@ -0,0 +1 @@ +LS_COLORS="ca=30;41:" bfs_diff rainbow -color diff --git a/tests/bfs/color_ext_case_nul.out b/tests/bfs/color_ext_case_nul.out new file mode 100644 index 0000000..8ccd9a7 --- /dev/null +++ b/tests/bfs/color_ext_case_nul.out @@ -0,0 +1,27 @@ +[01;34m$'rainbow/\e[1m'[0m +[01;34m$'rainbow/\e[1m/'[0m$'\e[0m' +[01;34mrainbow[0m +[01;34mrainbow/[0m[01;31mlower.gz[0m +[01;34mrainbow/[0m[01;31mlower.tar.gz[0m +[01;34mrainbow/[0m[01;31mlu.tar.GZ[0m +[01;34mrainbow/[0m[01;31mul.TAR.gz[0m +[01;34mrainbow/[0m[01;31mupper.GZ[0m +[01;34mrainbow/[0m[01;31mupper.TAR.GZ[0m +[01;34mrainbow/[0m[01;32mexec.sh[0m +[01;34mrainbow/[0m[01;35msocket[0m +[01;34mrainbow/[0m[01;36mbroken[0m +[01;34mrainbow/[0m[01;36mchardev_link[0m +[01;34mrainbow/[0m[01;36mlink.txt[0m +[01;34mrainbow/[0m[30;42msticky_ow[0m +[01;34mrainbow/[0m[30;43msgid[0m +[01;34mrainbow/[0m[33mpipe[0m +[01;34mrainbow/[0m[34;42mow[0m +[01;34mrainbow/[0m[37;41msugid[0m +[01;34mrainbow/[0m[37;41msuid[0m +[01;34mrainbow/[0m[37;44msticky[0m +[01;34mrainbow/[0mfile.dat +[01;34mrainbow/[0mfile.txt +[01;34mrainbow/[0mlower.tar +[01;34mrainbow/[0mmh1 +[01;34mrainbow/[0mmh2 +[01;34mrainbow/[0mupper.TAR diff --git a/tests/bfs/color_ext_case_nul.sh b/tests/bfs/color_ext_case_nul.sh new file mode 100644 index 0000000..68fea1c --- /dev/null +++ b/tests/bfs/color_ext_case_nul.sh @@ -0,0 +1,5 @@ +# Regression test: embedded NUL bytes in an extension caused an assertion +# failure in the trie implementation + +export LS_COLORS='*.gz=01;31:*\0.GZ=01;32:' +bfs_diff rainbow -color diff --git a/tests/bfs/color_ls.out b/tests/bfs/color_ls.out index f69eb9c..cc64318 100644 --- a/tests/bfs/color_ls.out +++ b/tests/bfs/color_ls.out @@ -8,5 +8,5 @@ [01;34mfoo/bar/[0m[01;31mnowhere/nothing[0m [01;34mfoo/bar/[0mbaz [01;34mfoo/bar/[0mbaz -[01;34mfoo/bar/baz[0m[01;31m//qux[0m -[01;34mfoo/bar/baz[0m[01;31m//qux[0m +[01;34mfoo/bar/[0mbaz[01;31m//qux[0m +[01;34mfoo/bar/[0mbaz[01;31m//qux[0m diff --git a/tests/bfs/color_notdir_slash_error.out b/tests/bfs/color_notdir_slash_error.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/bfs/color_notdir_slash_error.out diff --git a/tests/bfs/color_notdir_slash_error.sh b/tests/bfs/color_notdir_slash_error.sh new file mode 100644 index 0000000..ca26d50 --- /dev/null +++ b/tests/bfs/color_notdir_slash_error.sh @@ -0,0 +1,2 @@ +# Regression test: infinite loop printing the error message for .../notdir/nowhere +! bfs_diff -color links/notdir/nowhere diff --git a/tests/bit.c b/tests/bit.c index cc95785..5a3871d 100644 --- a/tests/bit.c +++ b/tests/bit.c @@ -81,6 +81,13 @@ void check_bit(void) { check_eq(bswap((uint32_t)0x12345678), 0x78563412); check_eq(bswap((uint64_t)0x1234567812345678), 0x7856341278563412); + // Make sure we can bswap() every unsigned type + (void)bswap((unsigned char)0); + (void)bswap((unsigned short)0); + (void)bswap(0U); + (void)bswap(0UL); + (void)bswap(0ULL); + check_eq(count_ones(0x0U), 0); check_eq(count_ones(0x1U), 1); check_eq(count_ones(0x2U), 1); diff --git a/tests/gnu/L_printf_types.out b/tests/gnu/L_printf_types.out new file mode 100644 index 0000000..734b15f --- /dev/null +++ b/tests/gnu/L_printf_types.out @@ -0,0 +1,17 @@ +(links) () d d +(links/broken) (nowhere) l N +(links/deeply) () d d +(links/deeply/nested) () d d +(links/deeply/nested/broken) (nowhere) l N +(links/deeply/nested/dir) () d d +(links/deeply/nested/file) () f f +(links/deeply/nested/link) () f f +(links/file) () f f +(links/hardlink) () f f +(links/notdir) (symlink/file) l N +(links/skip) () d d +(links/skip/broken) (nowhere) l N +(links/skip/dir) () d d +(links/skip/file) () f f +(links/skip/link) () f f +(links/symlink) () f f diff --git a/tests/gnu/L_printf_types.sh b/tests/gnu/L_printf_types.sh new file mode 100644 index 0000000..caa9083 --- /dev/null +++ b/tests/gnu/L_printf_types.sh @@ -0,0 +1 @@ +bfs_diff -L links -printf '(%p) (%l) %y %Y\n' diff --git a/tests/posix/exec_substring_plus.out b/tests/posix/exec_substring_plus.out new file mode 100644 index 0000000..a7ccfe4 --- /dev/null +++ b/tests/posix/exec_substring_plus.out @@ -0,0 +1,19 @@ +basic +basic/a +basic/b +basic/c +basic/c/d +basic/e +basic/e/f +basic/g +basic/g/h +basic/i +basic/j +basic/j/foo +basic/k +basic/k/foo +basic/k/foo/bar +basic/l +basic/l/foo +basic/l/foo/bar +basic/l/foo/bar/baz diff --git a/tests/posix/exec_substring_plus.sh b/tests/posix/exec_substring_plus.sh new file mode 100644 index 0000000..90309b0 --- /dev/null +++ b/tests/posix/exec_substring_plus.sh @@ -0,0 +1,14 @@ +# https://pubs.opengroup.org/onlinepubs/9799919799/utilities/find.html +# +# Only a <plus-sign> that immediately follows an argument containing only +# the two characters "{}" shall punctuate the end of the primary expression. +# Other uses of the <plus-sign> shall not be treated as special. +# ... +# If a utility_name or argument string contains the two characters "{}", but +# not just the two characters "{}", it is implementation-defined whether +# find replaces those two characters or uses the string without change. + +invoke_bfs basic -exec printf '%s %s %s %s\n' {} {}+ +{} + \; | sed 's/ .*//' >"$OUT" +sort_output +diff_output + diff --git a/tests/run.sh b/tests/run.sh index 612e11a..164790e 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -159,7 +159,7 @@ comake() { exec {READY_PIPE}<&${COPROC[0]} {DONE_PIPE}>&${COPROC[1]} } -# Print the current test progess +# Print the current test progress progress() { if [ "${BAR:-}" ]; then print_bar "$(printf "$@")" diff --git a/tests/sighook.c b/tests/sighook.c index aa01c36..0cb8de2 100644 --- a/tests/sighook.c +++ b/tests/sighook.c @@ -4,14 +4,14 @@ #include "tests.h" #include "atomic.h" -#include "thread.h" #include "sighook.h" +#include "thread.h" +#include "xtime.h" #include <stddef.h> #include <errno.h> #include <pthread.h> #include <signal.h> -#include <sys/time.h> /** Counts SIGALRM deliveries. */ static atomic size_t count = 0; @@ -60,11 +60,17 @@ void check_sighook(void) { return; } + // Check that we can unregister and re-register a hook + sigunhook(hook); + hook = sighook(SIGALRM, alrm_hook, NULL, SH_CONTINUE); + if (!bfs_echeck(hook, "sighook(SIGALRM)")) { + return; + } + // Create a timer that sends SIGALRM every 100 microseconds - struct itimerval ival = {0}; - ival.it_value.tv_usec = 100; - ival.it_interval.tv_usec = 100; - if (!bfs_echeck(setitimer(ITIMER_REAL, &ival, NULL) == 0)) { + struct timespec ival = { .tv_nsec = 100 * 1000 }; + struct timer *timer = xtimer_start(&ival); + if (!bfs_echeck(timer)) { goto unhook; } @@ -104,8 +110,7 @@ void check_sighook(void) { bfs_echeck(errno == 0, "pthread_sigmask()"); untime: // Stop the timer - ival.it_value.tv_usec = 0; - bfs_echeck(setitimer(ITIMER_REAL, &ival, NULL) == 0); + xtimer_stop(timer); unhook: // Unregister the SIGALRM hook sigunhook(hook); diff --git a/tests/trie.c b/tests/trie.c index 9e9a294..6e6024a 100644 --- a/tests/trie.c +++ b/tests/trie.c @@ -20,9 +20,11 @@ static const char *keys[] = { "quuuux", "pre", - "pref", "prefi", + "pref", "prefix", + "p", + "pRefix", "AAAA", "AADD", @@ -75,6 +77,7 @@ void check_trie(void) { size_t i = 0; for_trie (leaf, &trie) { bfs_check(leaf == trie_find_str(&trie, keys[i])); + bfs_check(leaf == trie_insert_str(&trie, keys[i])); bfs_check(!leaf->prev || leaf->prev->next == leaf); bfs_check(!leaf->next || leaf->next->prev == leaf); ++i; diff --git a/tests/util.sh b/tests/util.sh index 76b72b9..d8b7036 100644 --- a/tests/util.sh +++ b/tests/util.sh @@ -70,7 +70,7 @@ stdenv() { fi } -# Drop root priviliges or bail +# Drop root privileges or bail drop_root() { if command -v capsh &>/dev/null; then if capsh --has-p=cap_dac_override &>/dev/null || capsh --has-p=cap_dac_read_search &>/dev/null; then |