From: Ondřej Surý Date: Thu, 19 Apr 2018 15:48:28 +0000 (-0700) Subject: Also test the higher part of the confidence interval X-Git-Tag: v9.13.0~37^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d3220643c42d77decca49d6f39cef69cc6ce7bf;p=thirdparty%2Fbind9.git Also test the higher part of the confidence interval --- diff --git a/lib/isc/tests/random_test.c b/lib/isc/tests/random_test.c index ed4551ba8ae..3c7b8ff23e9 100644 --- a/lib/isc/tests/random_test.c +++ b/lib/isc/tests/random_test.c @@ -256,13 +256,14 @@ random_test(pvalue_func_t *func, isc_boolean_t word_sized) { isc_rng_t *rng; isc_uint32_t m; isc_uint32_t j; - isc_uint32_t histogram[11]; + isc_uint32_t histogram[11] = { 0 }; isc_uint32_t passed; double proportion; double p_hat; - double lower_confidence; + double lower_confidence, higher_confidence; double chi_square; double p_value_t; + double alpha; tables_init(); @@ -276,25 +277,24 @@ random_test(pvalue_func_t *func, isc_boolean_t word_sized) { m = 1000; passed = 0; - for (j = 0; j < 11; j++) - histogram[j] = 0; - for (j = 0; j < m; j++) { isc_uint32_t i; isc_uint16_t values[REPS]; double p_value; if (word_sized) { - for (i = 0; i < REPS; i++) + for (i = 0; i < REPS; i++) { isc_rng_randombytes(rng, &values[i], sizeof(values[i])); + } } else { isc_rng_randombytes(rng, values, sizeof(values)); } p_value = (*func)(mctx, values, REPS); - if (p_value >= 0.01) + if (p_value >= 0.01) { passed++; + } ATF_REQUIRE(p_value >= 0.0); ATF_REQUIRE(p_value <= 1.0); @@ -305,32 +305,35 @@ random_test(pvalue_func_t *func, isc_boolean_t word_sized) { isc_rng_detach(&rng); - /* Fold histogram[10] (p_value = 1.0) into histogram[9] for - * interval [0.9, 1.0] - */ - histogram[9] += histogram[10]; - histogram[10] = 0; - /* * Check proportion of sequences passing a test (see section * 4.2.1 in NIST SP 800-22). */ + alpha = 0.01; /* the significance level */ proportion = (double) passed / (double) m; - p_hat = 1 - 0.01; /* alpha is 0.01 in the NIST tests */ - lower_confidence = p_hat - (3.0 * sqrt((p_hat * (1 - p_hat)) / m)); + p_hat = 1.0 - alpha; + lower_confidence = p_hat - (3.0 * sqrt((p_hat * (1.0 - p_hat)) / m)); + higher_confidence = p_hat + (3.0 * sqrt((p_hat * (1.0 - p_hat)) / m)); /* Debug message, not displayed when running via atf-run */ printf("passed=%u/1000\n", passed); - printf("lower_confidence=%f, proportion=%f\n", - lower_confidence, proportion); + printf("higher_confidence=%f, lower_confidence=%f, proportion=%f\n", + higher_confidence, lower_confidence, proportion); ATF_REQUIRE(proportion >= lower_confidence); + ATF_REQUIRE(proportion <= higher_confidence); /* * Check uniform distribution of p-values (see section 4.2.2 in * NIST SP 800-22). */ + /* Fold histogram[10] (p_value = 1.0) into histogram[9] for + * interval [0.9, 1.0] + */ + histogram[9] += histogram[10]; + histogram[10] = 0; + /* Pre-requisite that at least 55 sequences are processed. */ ATF_REQUIRE(m >= 55);