| 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 <stdio.h> |
| 28 |
#include <stdlib.h> |
| 29 |
#include <unistd.h> |
| 30 |
#include <ck_pr.h> |
| 31 |
|
| 32 |
#include "../../common.h" |
| 33 |
#define REPEAT 2000000 |
| 34 |
|
| 35 |
#define TEST_N(K, S, T, P, D) \ |
| 36 |
static void \ |
| 37 |
run_test_##K##_##S(void) \ |
| 38 |
{ \ |
| 39 |
int i, r; \ |
| 40 |
T x = 0, y = 0; \ |
| 41 |
\ |
| 42 |
puts("***TESTING ck_pr_"#K"_"#S"***"); \ |
| 43 |
common_srand((unsigned int)getpid()); \ |
| 44 |
for (i = 0; i < REPEAT; ++i) { \ |
| 45 |
r = common_rand(); \ |
| 46 |
x += r; \ |
| 47 |
x = P x; \ |
| 48 |
y += r; \ |
| 49 |
ck_pr_##K##_##S(&y); \ |
| 50 |
} \ |
| 51 |
\ |
| 52 |
printf("Value of operation "#K" on 2000000 " \ |
| 53 |
"random numbers\n" \ |
| 54 |
"\tusing "#P": %"#D",\n" \ |
| 55 |
"\tusing ck_pr_"#K"_"#S": %"#D",\n", \ |
| 56 |
x, y); \ |
| 57 |
(x == y) ? puts("SUCCESS.") \ |
| 58 |
: puts("FAILURE."); \ |
| 59 |
\ |
| 60 |
return; \ |
| 61 |
} |
| 62 |
|
| 63 |
#define GENERATE_TEST(K, P) \ |
| 64 |
TEST_N(K, int, int, P, d) \ |
| 65 |
TEST_N(K, uint, unsigned int, P, u) \ |
| 66 |
static void \ |
| 67 |
run_test_##K(void) \ |
| 68 |
{ \ |
| 69 |
run_test_##K##_int(); \ |
| 70 |
run_test_##K##_uint(); \ |
| 71 |
\ |
| 72 |
return; \ |
| 73 |
} |
| 74 |
|
| 75 |
GENERATE_TEST(not, ~) |
| 76 |
GENERATE_TEST(neg, -) |
| 77 |
|
| 78 |
#undef GENERATE_TEST |
| 79 |
#undef TEST_N |
| 80 |
|
| 81 |
int |
| 82 |
main(void) |
| 83 |
{ |
| 84 |
run_test_not(); |
| 85 |
run_test_neg(); |
| 86 |
|
| 87 |
return (0); |
| 88 |
} |
| 89 |
|
| 90 |
|