summaryrefslogtreecommitdiff
path: root/test_utils/test_utils.c
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@acm.org>2022-02-01 19:33:41 -0800
committerTim Kientzle <kientzle@acm.org>2022-02-01 19:33:41 -0800
commite93b6c3009982d951dbb27c8dc0d02069273a56a (patch)
treee9409dbb8dc4ae8b7f08a9077fed77e6c79b19e6 /test_utils/test_utils.c
parent3665c7587d6561f0209da1716f86fbebb9a26778 (diff)
downloadlibarchive-e93b6c3009982d951dbb27c8dc0d02069273a56a.tar.gz
Reorganize test code a bit
A few guiding principles: * Each test source file includes ONLY "test.h" to make it easy to create new tests. * Each test suite has a "test.h" that includes "test_util/test_common.h" to get access to all the common testing utility functions. So "test_common.h" is then responsible for including any smaller headers that declare specific pieces of shared test functionality. I've also pulled some test filtering logic that was _only_ used in test_main.c into that file, and repurposed "test_utils.[ch]" for common utility code. (Eventually, a lot of the assertion helpers currently in "test_main.c" should probably be organized into one or more source files of their own.)
Diffstat (limited to 'test_utils/test_utils.c')
-rw-r--r--test_utils/test_utils.c96
1 files changed, 1 insertions, 95 deletions
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;