Debian Codegraph @

regressions/ck_pr/validate/ck_pr_bin.c

raw
1 /*
2 * Copyright 2011 David Joseph.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #include <ck_pr.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31
32 #include "../../common.h"
33 #define REPEAT 2000000
34
35 #define TEST_BINARY(K, S, T, P, D) \
36 static void \
37 run_test_##K##_##S(void) \
38 { \
39 int i, r; \
40 T serial_result = 65535; \
41 T ck_result = 65535; \
42 \
43 puts("***TESTING ck_pr_" #K "_" #S "***"); \
44 common_srand((unsigned int)getpid()); \
45 for (i = 0; i < REPEAT; ++i) { \
46 r = common_rand(); \
47 serial_result = serial_result P r; \
48 ck_pr_##K##_##S(&ck_result, r); \
49 } \
50 \
51 printf("Value of operation " #K " on 2000000 " \
52 "random numbers\n\tusing " #P ": %" #D ",\n" \
53 "\tusing ck_pr_"#K"_"#S": %" #D "\n", \
54 serial_result, ck_result); \
55 (serial_result == ck_result) ? puts("SUCCESS.") \
56 : puts("FAILURE."); \
57 \
58 return; \
59 } \
60
61 #define GENERATE_TEST(K, P) \
62 TEST_BINARY(K, int, int, P, d) \
63 TEST_BINARY(K, uint, unsigned int, P, u) \
64 static void \
65 run_test_##K(void) \
66 { \
67 run_test_##K##_int(); \
68 run_test_##K##_uint(); \
69 \
70 return; \
71 }
72
73 GENERATE_TEST(add, +)
74 GENERATE_TEST(sub, -)
75 GENERATE_TEST(and, &)
76 GENERATE_TEST(or, |)
77 GENERATE_TEST(xor, ^)
78
79 #undef GENERATE_TEST
80 #undef TEST_BINARY
81
82 int
83 main(void)
84 {
85 run_test_add();
86 run_test_sub();
87 run_test_and();
88 run_test_or();
89 run_test_xor();
90
91 return (0);
92 }
93
94