diff options
Diffstat (limited to 'test_utils')
-rw-r--r-- | test_utils/test_common.h | 2 | ||||
-rw-r--r-- | test_utils/test_main.c | 102 | ||||
-rw-r--r-- | test_utils/test_utils.c | 96 | ||||
-rw-r--r-- | test_utils/test_utils.h | 10 |
4 files changed, 105 insertions, 105 deletions
diff --git a/test_utils/test_common.h b/test_utils/test_common.h index 42119c06..6250235c 100644 --- a/test_utils/test_common.h +++ b/test_utils/test_common.h @@ -471,4 +471,6 @@ void assertVersion(const char *prog, const char *base); #include <dmalloc.h> #endif +#include "test_utils.h" + #endif /* TEST_COMMON_H */ diff --git a/test_utils/test_main.c b/test_utils/test_main.c index 48ae2628..467e367e 100644 --- a/test_utils/test_main.c +++ b/test_utils/test_main.c @@ -3462,6 +3462,12 @@ assertion_entry_compare_acls(const char *file, int line, * DEFINE_TEST(test_function) * for each test. */ +struct test_list_t +{ + void (*func)(void); + const char *name; + int failures; +}; /* Use "list.h" to declare all of the test functions. */ #undef DEFINE_TEST @@ -3753,6 +3759,100 @@ success: return p; } +/* Filter tests against a glob pattern. Returns non-zero if test matches + * pattern, zero otherwise. A '^' at the beginning of the pattern negates + * the return values (i.e. returns zero for a match, non-zero otherwise. + */ +static int +test_filter(const char *pattern, const char *test) +{ + int retval = 0; + int negate = 0; + const char *p = pattern; + const char *t = test; + + if (p[0] == '^') + { + negate = 1; + p++; + } + + while (1) + { + if (p[0] == '\\') + p++; + else if (p[0] == '*') + { + while (p[0] == '*') + p++; + if (p[0] == '\\') + p++; + if ((t = strchr(t, p[0])) == 0) + break; + } + if (p[0] != t[0]) + break; + if (p[0] == '\0') { + retval = 1; + break; + } + p++; + t++; + } + + return (negate) ? !retval : retval; +} + +static int +get_test_set(int *test_set, int limit, const char *test) +{ + int start, end; + int idx = 0; + + if (test == NULL) { + /* Default: Run all tests. */ + for (;idx < limit; idx++) + test_set[idx] = idx; + return (limit); + } + if (*test >= '0' && *test <= '9') { + const char *vp = test; + start = 0; + while (*vp >= '0' && *vp <= '9') { + start *= 10; + start += *vp - '0'; + ++vp; + } + if (*vp == '\0') { + end = start; + } else if (*vp == '-') { + ++vp; + if (*vp == '\0') { + end = limit - 1; + } else { + end = 0; + while (*vp >= '0' && *vp <= '9') { + end *= 10; + end += *vp - '0'; + ++vp; + } + } + } else + return (-1); + if (start < 0 || end >= limit || start > end) + return (-1); + while (start <= end) + test_set[idx++] = start++; + } else { + for (start = 0; start < limit; ++start) { + const char *name = tests[start].name; + if (test_filter(test, name)) + test_set[idx++] = start; + } + } + return ((idx == 0)?-1:idx); +} + int main(int argc, char **argv) { @@ -4049,7 +4149,7 @@ main(int argc, char **argv) do { int test_num; - test_num = get_test_set(test_set, limit, *argv, tests); + test_num = get_test_set(test_set, limit, *argv); if (test_num < 0) { printf("*** INVALID Test %s\n", *argv); free(refdir_alloc); diff --git a/test_utils/test_utils.c b/test_utils/test_utils.c index db6c31b2..b7966761 100644 --- a/test_utils/test_utils.c +++ b/test_utils/test_utils.c @@ -32,100 +32,6 @@ #include <string.h> #include <assert.h> -/* Filter tests against a glob pattern. Returns non-zero if test matches - * pattern, zero otherwise. A '^' at the beginning of the pattern negates - * the return values (i.e. returns zero for a match, non-zero otherwise. - */ -static int -test_filter(const char *pattern, const char *test) -{ - int retval = 0; - int negate = 0; - const char *p = pattern; - const char *t = test; - - if (p[0] == '^') - { - negate = 1; - p++; - } - - while (1) - { - if (p[0] == '\\') - p++; - else if (p[0] == '*') - { - while (p[0] == '*') - p++; - if (p[0] == '\\') - p++; - if ((t = strchr(t, p[0])) == 0) - break; - } - if (p[0] != t[0]) - break; - if (p[0] == '\0') { - retval = 1; - break; - } - p++; - t++; - } - - return (negate) ? !retval : retval; -} - -int get_test_set(int *test_set, int limit, const char *test, - struct test_list_t *tests) -{ - int start, end; - int idx = 0; - - if (test == NULL) { - /* Default: Run all tests. */ - for (;idx < limit; idx++) - test_set[idx] = idx; - return (limit); - } - if (*test >= '0' && *test <= '9') { - const char *vp = test; - start = 0; - while (*vp >= '0' && *vp <= '9') { - start *= 10; - start += *vp - '0'; - ++vp; - } - if (*vp == '\0') { - end = start; - } else if (*vp == '-') { - ++vp; - if (*vp == '\0') { - end = limit - 1; - } else { - end = 0; - while (*vp >= '0' && *vp <= '9') { - end *= 10; - end += *vp - '0'; - ++vp; - } - } - } else - return (-1); - if (start < 0 || end >= limit || start > end) - return (-1); - while (start <= end) - test_set[idx++] = start++; - } else { - for (start = 0; start < limit; ++start) { - const char *name = tests[start].name; - if (test_filter(test, name)) - test_set[idx++] = start; - } - } - return ((idx == 0)?-1:idx); -} - static inline uint64_t xorshift64(uint64_t *state) { @@ -146,7 +52,7 @@ xorshift64(uint64_t *state) * took ~22 seconds, whereas using a xorshift random number generator (that can * be inlined) reduces it to ~17 seconds on QEMU RISC-V. */ -void +static void fill_with_pseudorandom_data_seed(uint64_t seed, void *buffer, size_t size) { uint64_t *aligned_buffer; diff --git a/test_utils/test_utils.h b/test_utils/test_utils.h index 3f61f6b2..41457890 100644 --- a/test_utils/test_utils.h +++ b/test_utils/test_utils.h @@ -30,15 +30,7 @@ #include <stddef.h> #include <stdint.h> -struct test_list_t -{ - void (*func)(void); - const char *name; - int failures; -}; - -int get_test_set(int *, int, const char *, struct test_list_t *); +/* Fill a buffer with pseudorandom data */ void fill_with_pseudorandom_data(void* buffer, size_t size); -void fill_with_pseudorandom_data_seed(uint64_t seed, void* buffer, size_t size); #endif /* TEST_UTILS_H */ |