Merge branch '46-just-use-clang-format-to-reformat-sources' into 'master'

Reformat source code with clang-format

Closes #46

See merge request isc-projects/bind9!2156

(cherry picked from commit 7099e79a9b)

4c3b063e Import Linux kernel .clang-format with small modifications
f50b1e06 Use clang-format to reformat the source files
11341c76 Update the definition files for Windows
df6c1f76 Remove tkey_test (which is no-op anyway)
This commit is contained in:
Ondřej Surý
2020-02-12 14:33:32 +00:00
parent dbe15330fe
commit c931d8e417
974 changed files with 75952 additions and 74434 deletions

View File

@@ -18,13 +18,12 @@
#if HAVE_CMOCKA
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <inttypes.h>
#include <math.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -43,8 +42,7 @@
#define REPS 25000
typedef double (pvalue_func_t)(isc_mem_t *mctx,
uint16_t *values, size_t length);
typedef double(pvalue_func_t)(isc_mem_t *mctx, uint16_t *values, size_t length);
/* igamc(), igam(), etc. were adapted (and cleaned up) from the Cephes
* math library:
@@ -54,15 +52,17 @@ typedef double (pvalue_func_t)(isc_mem_t *mctx,
*
* The Cephes math library was released into the public domain as part
* of netlib.
*/
*/
static double MACHEP = 1.11022302462515654042E-16;
static double MAXLOG = 7.09782712893383996843E2;
static double big = 4.503599627370496e15;
static double biginv = 2.22044604925031308085e-16;
static double biginv = 2.22044604925031308085e-16;
static double igamc(double a, double x);
static double igam(double a, double x);
static double
igamc(double a, double x);
static double
igam(double a, double x);
/* Set to true (or use -v option) for verbose output */
static bool verbose = false;
@@ -77,7 +77,8 @@ typedef enum {
} isc_random_func;
static int
_setup(void **state) {
_setup(void **state)
{
isc_result_t result;
UNUSED(state);
@@ -89,7 +90,8 @@ _setup(void **state) {
}
static int
_teardown(void **state) {
_teardown(void **state)
{
UNUSED(state);
isc_test_end();
@@ -98,7 +100,8 @@ _teardown(void **state) {
}
static double
igamc(double a, double x) {
igamc(double a, double x)
{
double ans, ax, c, yc, r, t, y, z;
double pk, pkm1, pkm2, qk, qkm1, qkm2;
@@ -130,8 +133,8 @@ igamc(double a, double x) {
y += 1.0;
z += 2.0;
yc = y * c;
pk = pkm1 * z - pkm2 * yc;
qk = qkm1 * z - qkm2 * yc;
pk = pkm1 * z - pkm2 * yc;
qk = qkm1 * z - qkm2 * yc;
if (qk != 0) {
r = pk / qk;
t = fabs((ans - r) / r);
@@ -156,7 +159,8 @@ igamc(double a, double x) {
}
static double
igam(double a, double x) {
igam(double a, double x)
{
double ans, ax, c, r;
if ((x <= 0) || (a <= 0))
@@ -167,7 +171,7 @@ igam(double a, double x) {
/* Compute x**a * exp(-x) / md_gamma(a) */
ax = a * log(x) - x - lgamma(a);
if (ax < -MAXLOG ) {
if (ax < -MAXLOG) {
print_error("# igam: UNDERFLOW, ax=%f\n", ax);
return (0.0);
}
@@ -187,12 +191,13 @@ igam(double a, double x) {
return (ans * ax / a);
}
static int8_t scounts_table[65536];
static int8_t scounts_table[65536];
static uint8_t bitcounts_table[65536];
static int8_t
scount_calculate(uint16_t n) {
int i;
scount_calculate(uint16_t n)
{
int i;
int8_t sc;
sc = 0;
@@ -212,8 +217,9 @@ scount_calculate(uint16_t n) {
}
static uint8_t
bitcount_calculate(uint16_t n) {
int i;
bitcount_calculate(uint16_t n)
{
int i;
uint8_t bc;
bc = 0;
@@ -231,7 +237,8 @@ bitcount_calculate(uint16_t n) {
}
static void
tables_init(void) {
tables_init(void)
{
uint32_t i;
for (i = 0; i < 65536; i++) {
@@ -248,11 +255,12 @@ tables_init(void) {
* This function destroys (modifies) the data passed in bits.
*/
static uint32_t
matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) {
size_t i, j, k;
matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols)
{
size_t i, j, k;
unsigned int rt = 0;
uint32_t rank = 0;
uint32_t tmp;
uint32_t rank = 0;
uint32_t tmp;
for (k = 0; k < rows; k++) {
i = k;
@@ -294,17 +302,18 @@ matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) {
}
static void
random_test(pvalue_func_t *func, isc_random_func test_func) {
random_test(pvalue_func_t *func, isc_random_func test_func)
{
uint32_t m;
uint32_t j;
uint32_t histogram[11] = { 0 };
uint32_t passed;
double proportion;
double p_hat;
double lower_confidence, higher_confidence;
double chi_square;
double p_value_t;
double alpha;
double proportion;
double p_hat;
double lower_confidence, higher_confidence;
double chi_square;
double p_value_t;
double alpha;
tables_init();
@@ -312,27 +321,27 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
passed = 0;
for (j = 0; j < m; j++) {
uint32_t i;
uint32_t values[REPS];
uint32_t i;
uint32_t values[REPS];
uint16_t *uniform_values;
double p_value;
double p_value;
switch (test_func) {
case ISC_RANDOM8:
for (i = 0; i < (sizeof(values) / sizeof(*values)); i++)
{
for (i = 0; i < (sizeof(values) / sizeof(*values));
i++) {
values[i] = isc_random8();
}
break;
case ISC_RANDOM16:
for (i = 0; i < (sizeof(values) / sizeof(*values)); i++)
{
for (i = 0; i < (sizeof(values) / sizeof(*values));
i++) {
values[i] = isc_random16();
}
break;
case ISC_RANDOM32:
for (i = 0; i < (sizeof(values) / sizeof(*values)); i++)
{
for (i = 0; i < (sizeof(values) / sizeof(*values));
i++) {
values[i] = isc_random32();
}
break;
@@ -343,8 +352,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
uniform_values = (uint16_t *)values;
for (i = 0;
i < (sizeof(values) / (sizeof(*uniform_values)));
i++)
{
i++) {
uniform_values[i] =
isc_random_uniform(UINT16_MAX);
}
@@ -361,7 +369,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
assert_in_range(p_value, 0.0, 1.0);
i = (int) floor(p_value * 10);
i = (int)floor(p_value * 10);
histogram[i]++;
}
@@ -370,7 +378,7 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
* 4.2.1 in NIST SP 800-22).
*/
alpha = 0.01; /* the significance level */
proportion = (double) passed / (double) m;
proportion = (double)passed / (double)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));
@@ -431,12 +439,13 @@ random_test(pvalue_func_t *func, isc_random_func test_func) {
* RANDOM test suite.
*/
static double
monobit(isc_mem_t *mctx, uint16_t *values, size_t length) {
size_t i;
int32_t scount;
monobit(isc_mem_t *mctx, uint16_t *values, size_t length)
{
size_t i;
int32_t scount;
uint32_t numbits;
double s_obs;
double p_value;
double s_obs;
double p_value;
UNUSED(mctx);
@@ -463,20 +472,21 @@ monobit(isc_mem_t *mctx, uint16_t *values, size_t length) {
* This is the runs test taken from the NIST SP 800-22 RNG test suite.
*/
static double
runs(isc_mem_t *mctx, uint16_t *values, size_t length) {
size_t i;
runs(isc_mem_t *mctx, uint16_t *values, size_t length)
{
size_t i;
uint32_t bcount;
uint32_t numbits;
double pi;
double tau;
double pi;
double tau;
uint32_t j;
uint32_t b;
uint8_t bit_this;
uint8_t bit_prev;
uint8_t bit_this;
uint8_t bit_prev;
uint32_t v_obs;
double numer;
double denom;
double p_value;
double numer;
double denom;
double p_value;
UNUSED(mctx);
@@ -490,7 +500,7 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) {
print_message("# numbits=%u, bcount=%u\n", numbits, bcount);
}
pi = (double) bcount / (double) numbits;
pi = (double)bcount / (double)numbits;
tau = 2.0 / sqrt(numbits);
/* Preconditions (section 2.3.7 in NIST SP 800-22) */
@@ -540,15 +550,16 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) {
* test suite.
*/
static double
blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) {
blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length)
{
uint32_t i;
uint32_t numbits;
uint32_t mbits;
uint32_t mwords;
uint32_t numblocks;
double *pi;
double chi_square;
double p_value;
double * pi;
double chi_square;
double p_value;
numbits = length * sizeof(*values) * 8;
mbits = 32000;
@@ -562,7 +573,7 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) {
/* Preconditions (section 2.2.7 in NIST SP 800-22) */
assert_true(numbits >= 100);
assert_true(mbits >= 20);
assert_true((double) mbits > (0.01 * numbits));
assert_true((double)mbits > (0.01 * numbits));
assert_true(numblocks < 100);
assert_true(numbits >= (mbits * numblocks));
@@ -604,20 +615,21 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) {
* test suite.
*/
static double
binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) {
binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length)
{
uint32_t i;
size_t matrix_m;
size_t matrix_q;
size_t matrix_m;
size_t matrix_q;
uint32_t num_matrices;
size_t numbits;
size_t numbits;
uint32_t fm_0;
uint32_t fm_1;
uint32_t fm_rest;
double term1;
double term2;
double term3;
double chi_square;
double p_value;
double term1;
double term2;
double term3;
double chi_square;
double p_value;
UNUSED(mctx);
@@ -640,11 +652,11 @@ binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) {
* takes up uint32_t array of size 32.
*/
uint32_t bits[32];
int j;
int j;
uint32_t rank;
for (j = 0; j < 32; j++) {
size_t idx;
size_t idx;
uint32_t r1;
uint32_t r2;
@@ -668,11 +680,14 @@ binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) {
/* Compute chi_square */
term1 = ((fm_0 - (0.2888 * num_matrices)) *
(fm_0 - (0.2888 * num_matrices))) / (0.2888 * num_matrices);
(fm_0 - (0.2888 * num_matrices))) /
(0.2888 * num_matrices);
term2 = ((fm_1 - (0.5776 * num_matrices)) *
(fm_1 - (0.5776 * num_matrices))) / (0.5776 * num_matrices);
(fm_1 - (0.5776 * num_matrices))) /
(0.5776 * num_matrices);
term3 = ((fm_rest - (0.1336 * num_matrices)) *
(fm_rest - (0.1336 * num_matrices))) / (0.1336 * num_matrices);
(fm_rest - (0.1336 * num_matrices))) /
(0.1336 * num_matrices);
chi_square = term1 + term2 + term3;
@@ -692,7 +707,8 @@ binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) {
/* Monobit test for the RANDOM */
static void
isc_random32_monobit(void **state) {
isc_random32_monobit(void **state)
{
UNUSED(state);
random_test(monobit, ISC_RANDOM32);
@@ -700,7 +716,8 @@ isc_random32_monobit(void **state) {
/* Runs test for the RANDOM */
static void
isc_random32_runs(void **state) {
isc_random32_runs(void **state)
{
UNUSED(state);
random_test(runs, ISC_RANDOM32);
@@ -708,7 +725,8 @@ isc_random32_runs(void **state) {
/* Block frequency test for the RANDOM */
static void
isc_random32_blockfrequency(void **state) {
isc_random32_blockfrequency(void **state)
{
UNUSED(state);
random_test(blockfrequency, ISC_RANDOM32);
@@ -716,7 +734,8 @@ isc_random32_blockfrequency(void **state) {
/* Binary matrix rank test for the RANDOM */
static void
isc_random32_binarymatrixrank(void **state) {
isc_random32_binarymatrixrank(void **state)
{
UNUSED(state);
random_test(binarymatrixrank, ISC_RANDOM32);
@@ -728,7 +747,8 @@ isc_random32_binarymatrixrank(void **state) {
/* Monobit test for the RANDOM */
static void
isc_random_bytes_monobit(void **state) {
isc_random_bytes_monobit(void **state)
{
UNUSED(state);
random_test(monobit, ISC_RANDOM_BYTES);
@@ -736,7 +756,8 @@ isc_random_bytes_monobit(void **state) {
/* Runs test for the RANDOM */
static void
isc_random_bytes_runs(void **state) {
isc_random_bytes_runs(void **state)
{
UNUSED(state);
random_test(runs, ISC_RANDOM_BYTES);
@@ -744,7 +765,8 @@ isc_random_bytes_runs(void **state) {
/* Block frequency test for the RANDOM */
static void
isc_random_bytes_blockfrequency(void **state) {
isc_random_bytes_blockfrequency(void **state)
{
UNUSED(state);
random_test(blockfrequency, ISC_RANDOM_BYTES);
@@ -752,20 +774,21 @@ isc_random_bytes_blockfrequency(void **state) {
/* Binary matrix rank test for the RANDOM */
static void
isc_random_bytes_binarymatrixrank(void **state) {
isc_random_bytes_binarymatrixrank(void **state)
{
UNUSED(state);
random_test(binarymatrixrank, ISC_RANDOM_BYTES);
}
/***
*** Tests for isc_random_uniform() function:
***/
/* Monobit test for the RANDOM */
static void
isc_random_uniform_monobit(void **state) {
isc_random_uniform_monobit(void **state)
{
UNUSED(state);
random_test(monobit, ISC_RANDOM_UNIFORM);
@@ -773,7 +796,8 @@ isc_random_uniform_monobit(void **state) {
/* Runs test for the RANDOM */
static void
isc_random_uniform_runs(void **state) {
isc_random_uniform_runs(void **state)
{
UNUSED(state);
random_test(runs, ISC_RANDOM_UNIFORM);
@@ -781,7 +805,8 @@ isc_random_uniform_runs(void **state) {
/* Block frequency test for the RANDOM */
static void
isc_random_uniform_blockfrequency(void **state) {
isc_random_uniform_blockfrequency(void **state)
{
UNUSED(state);
random_test(blockfrequency, ISC_RANDOM_UNIFORM);
@@ -789,7 +814,8 @@ isc_random_uniform_blockfrequency(void **state) {
/* Binary matrix rank test for the RANDOM */
static void
isc_random_uniform_binarymatrixrank(void **state) {
isc_random_uniform_binarymatrixrank(void **state)
{
UNUSED(state);
random_test(binarymatrixrank, ISC_RANDOM_UNIFORM);
@@ -799,7 +825,8 @@ isc_random_uniform_binarymatrixrank(void **state) {
/* Monobit test for the RANDOM */
static void
isc_nonce_bytes_monobit(void **state) {
isc_nonce_bytes_monobit(void **state)
{
UNUSED(state);
random_test(monobit, ISC_NONCE_BYTES);
@@ -807,7 +834,8 @@ isc_nonce_bytes_monobit(void **state) {
/* Runs test for the RANDOM */
static void
isc_nonce_bytes_runs(void **state) {
isc_nonce_bytes_runs(void **state)
{
UNUSED(state);
random_test(runs, ISC_NONCE_BYTES);
@@ -815,7 +843,8 @@ isc_nonce_bytes_runs(void **state) {
/* Block frequency test for the RANDOM */
static void
isc_nonce_bytes_blockfrequency(void **state) {
isc_nonce_bytes_blockfrequency(void **state)
{
UNUSED(state);
random_test(blockfrequency, ISC_NONCE_BYTES);
@@ -823,14 +852,16 @@ isc_nonce_bytes_blockfrequency(void **state) {
/* Binary matrix rank test for the RANDOM */
static void
isc_nonce_bytes_binarymatrixrank(void **state) {
isc_nonce_bytes_binarymatrixrank(void **state)
{
UNUSED(state);
random_test(binarymatrixrank, ISC_NONCE_BYTES);
}
int
main(int argc, char **argv) {
main(int argc, char **argv)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(isc_random32_monobit),
cmocka_unit_test(isc_random32_runs),
@@ -869,7 +900,8 @@ main(int argc, char **argv) {
#include <stdio.h>
int
main(void) {
main(void)
{
printf("1..0 # Skipped: cmocka not available\n");
return (0);
}