| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,74 @@ |
| 1 |
+#ifndef THEFT_H |
|
| 2 |
+#define THEFT_H |
|
| 3 |
+ |
|
| 4 |
+#include <stdlib.h> |
|
| 5 |
+#include <stdio.h> |
|
| 6 |
+#include <stdint.h> |
|
| 7 |
+#include <stdbool.h> |
|
| 8 |
+ |
|
| 9 |
+/* Version 0.2.0 */ |
|
| 10 |
+#define THEFT_VERSION_MAJOR 0 |
|
| 11 |
+#define THEFT_VERSION_MINOR 2 |
|
| 12 |
+#define THEFT_VERSION_PATCH 0 |
|
| 13 |
+ |
|
| 14 |
+/* A property can have at most this many arguments. */ |
|
| 15 |
+#define THEFT_MAX_ARITY 10 |
|
| 16 |
+ |
|
| 17 |
+#include "theft_types.h" |
|
| 18 |
+ |
|
| 19 |
+/* Default number of trials to run. */ |
|
| 20 |
+#define THEFT_DEF_TRIALS 100 |
|
| 21 |
+ |
|
| 22 |
+/* Min and max bits used to determine bloom filter size. |
|
| 23 |
+ * (A larger value uses more memory, but reduces the odds of an |
|
| 24 |
+ * untested argument combination being falsely skipped.) */ |
|
| 25 |
+#define THEFT_BLOOM_BITS_MIN 13 /* 1 KB */ |
|
| 26 |
+#define THEFT_BLOOM_BITS_MAX 33 /* 1 GB */ |
|
| 27 |
+ |
|
| 28 |
+/* Initialize a theft test runner. |
|
| 29 |
+ * BLOOM_BITS sets the size of the table used for detecting |
|
| 30 |
+ * combinations of arguments that have already been tested. |
|
| 31 |
+ * If 0, a default size will be chosen based on trial count. |
|
| 32 |
+ * (This will only be used if all property types have hash |
|
| 33 |
+ * callbacks defined.) The bloom filter can also be disabled |
|
| 34 |
+ * by setting BLOOM_BITS to THEFT_BLOOM_DISABLE. |
|
| 35 |
+ * |
|
| 36 |
+ * Returns a NULL if malloc fails or BLOOM_BITS is out of bounds. */ |
|
| 37 |
+struct theft *theft_init(uint8_t bloom_bits); |
|
| 38 |
+ |
|
| 39 |
+/* Free a property-test runner. */ |
|
| 40 |
+void theft_free(struct theft *t); |
|
| 41 |
+ |
|
| 42 |
+/* (Re-)initialize the random number generator with a specific seed. */ |
|
| 43 |
+void theft_set_seed(struct theft *t, uint64_t seed); |
|
| 44 |
+ |
|
| 45 |
+/* Get a random 64-bit integer from the test runner's PRNG. */ |
|
| 46 |
+theft_hash theft_random(struct theft *t); |
|
| 47 |
+ |
|
| 48 |
+/* Get a random double from the test runner's PRNG. */ |
|
| 49 |
+double theft_random_double(struct theft *t); |
|
| 50 |
+ |
|
| 51 |
+/* Change T's output stream handle to OUT. (Default: stdout.) */ |
|
| 52 |
+void theft_set_output_stream(struct theft *t, FILE *out); |
|
| 53 |
+ |
|
| 54 |
+/* Run a series of randomized trials of a property function. |
|
| 55 |
+ * |
|
| 56 |
+ * Configuration is specified in CFG; many fields are optional. |
|
| 57 |
+ * See the type definition in `theft_types.h`. */ |
|
| 58 |
+theft_run_res |
|
| 59 |
+theft_run(struct theft *t, struct theft_cfg *cfg); |
|
| 60 |
+ |
|
| 61 |
+/* Hash a buffer in one pass. (Wraps the below functions.) */ |
|
| 62 |
+theft_hash theft_hash_onepass(uint8_t *data, size_t bytes); |
|
| 63 |
+ |
|
| 64 |
+/* Init/reset a hasher for incremental hashing. |
|
| 65 |
+ * Returns true, or false if you gave it a NULL pointer. */ |
|
| 66 |
+void theft_hash_init(struct theft_hasher *h); |
|
| 67 |
+ |
|
| 68 |
+/* Sink more data into an incremental hash. */ |
|
| 69 |
+void theft_hash_sink(struct theft_hasher *h, uint8_t *data, size_t bytes); |
|
| 70 |
+ |
|
| 71 |
+/* Finish hashing and get the result. */ |
|
| 72 |
+theft_hash theft_hash_done(struct theft_hasher *h); |
|
| 73 |
+ |
|
| 74 |
+#endif |