Refactor the way we use memory context from isctest.c

This commit renames isctest {mctx,lctx} to test_{mctx,lctx} and cleans
up their usage in the individual unit tests.  This allows embedding
library .c files directly into the unit tests.
This commit is contained in:
Ondřej Surý
2019-11-09 14:01:08 +01:00
parent 229b7d85e8
commit 8de64964a3
17 changed files with 185 additions and 130 deletions

View File

@@ -39,6 +39,8 @@
#include <isc/result.h>
#include <isc/util.h>
#include "isctest.h"
#define REPS 25000
typedef double (pvalue_func_t)(isc_mem_t *mctx,
@@ -74,6 +76,27 @@ typedef enum {
ISC_NONCE_BYTES
} isc_random_func;
static int
_setup(void **state) {
isc_result_t result;
UNUSED(state);
result = isc_test_begin(NULL, true, 0);
assert_int_equal(result, ISC_R_SUCCESS);
return (0);
}
static int
_teardown(void **state) {
UNUSED(state);
isc_test_end();
return (0);
}
static double
igamc(double a, double x) {
double ans, ax, c, yc, r, t, y, z;
@@ -272,7 +295,6 @@ matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) {
static void
random_test(pvalue_func_t *func, isc_random_func test_func) {
isc_mem_t *mctx = NULL;
uint32_t m;
uint32_t j;
uint32_t histogram[11] = { 0 };
@@ -286,8 +308,6 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
tables_init();
isc_mem_create(&mctx);
m = 1000;
passed = 0;
@@ -334,7 +354,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
break;
}
p_value = (*func)(mctx, (uint16_t *)values, REPS * 2);
p_value = (*func)(test_mctx, (uint16_t *)values, REPS * 2);
if (p_value >= 0.01) {
passed++;
}
@@ -841,7 +861,7 @@ main(int argc, char **argv) {
}
}
return (cmocka_run_group_tests(tests, NULL, NULL));
return (cmocka_run_group_tests(tests, _setup, _teardown));
}
#else /* HAVE_CMOCKA */