aboutsummaryrefslogtreecommitdiff
path: root/test/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/main.c')
-rw-r--r--test/main.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/test/main.c b/test/main.c
index 5c0656c..8c2fffe 100644
--- a/test/main.c
+++ b/test/main.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdlib.h>
#include <stdatomic.h>
#include <time.h>
#include "test_framework.h"
@@ -13,7 +14,7 @@ atomic_flag test_framework_assertion_failed = ATOMIC_FLAG_INIT;
static void report(const char *clr, const char *label, const char *name, clock_t taken) {
- printf("\x1B[%sm[%s] %s (%lfs)\n",
+ printf("\x1B[%sm[%s] %s (%lfs)\x1B[0m\n",
clr, label, name, (double)taken / CLOCKS_PER_SEC);
}
@@ -41,10 +42,39 @@ static void report_failure(const char *name, clock_t taken) {
static int run_tests(void) {
RUN_TEST(hashtable_unit1);
RUN_TEST(hashtable);
+ RUN_TEST(utf8_unit1);
+ RUN_TEST(utf8_random);
+ RUN_TEST(utf8_random_valid);
+ RUN_TEST(utf8_exhaustive_1);
return 0;
}
+static unsigned int random_seed_from_device(void) {
+ FILE *f = fopen("/dev/urandom", "r");
+ if (!f) {
+ fprintf(stderr, "Cannot open /dev/urandom\n");
+ exit(1);
+ }
+ unsigned int seed;
+ int nread = fread(&seed, 1, sizeof seed, f);
+ if (nread < (int)sizeof seed) {
+ fprintf(stderr, "Cannot read from /dev/urandom\n");
+ exit(1);
+ }
+ fclose(f);
+ return seed;
+}
int main(void) {
+ unsigned int seed;
+ const char *seed_env_var = getenv("SEED");
+ if (seed_env_var && seed_env_var[0]) {
+ seed = strtol(seed_env_var, NULL, 10);
+ } else {
+ seed = random_seed_from_device();
+ }
+ fprintf(stderr, "seed = %u\n", seed);
+ srandom(seed);
+
return run_tests();
}