diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-05 18:05:47 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-05 18:10:28 +0200 |
| commit | 6f338b97a222dee630c9b13896cf443254667dfb (patch) | |
| tree | e05fae60a580d5a3eccaa31330db9a161ce932e9 /tools | |
| parent | 3135b159bb08bc5bf3e39e0c3ab865935447cc16 (diff) | |
| download | nissy-core-6f338b97a222dee630c9b13896cf443254667dfb.tar.gz nissy-core-6f338b97a222dee630c9b13896cf443254667dfb.zip | |
Added distribution check to tool
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/000_gendata/gendata.c | 10 | ||||
| -rw-r--r-- | tools/expected_distributions.h | 86 | ||||
| -rw-r--r-- | tools/nissy_extra.h | 5 | ||||
| -rw-r--r-- | tools/tool.h | 1 |
4 files changed, 97 insertions, 5 deletions
diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c index 9533432..2798862 100644 --- a/tools/000_gendata/gendata.c +++ b/tools/000_gendata/gendata.c | |||
| @@ -18,11 +18,11 @@ run(void) { | |||
| 18 | goto gendata_run_finish; | 18 | goto gendata_run_finish; |
| 19 | default: | 19 | default: |
| 20 | nissy_datainfo(buf, write_stdout); | 20 | nissy_datainfo(buf, write_stdout); |
| 21 | printf("\n"); | 21 | if (check_distribution(solver, buf)) { |
| 22 | printf("Succesfully generated %" PRId64 " bytes. " | 22 | printf("\n"); |
| 23 | "See above for details on the tables.\n", size); | 23 | printf("Generated %" PRId64 " bytes.\n", size); |
| 24 | 24 | writetable(buf, size, filename); | |
| 25 | writetable(buf, size, filename); | 25 | } |
| 26 | break; | 26 | break; |
| 27 | } | 27 | } |
| 28 | 28 | ||
diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h index 535cab2..0f3fec3 100644 --- a/tools/expected_distributions.h +++ b/tools/expected_distributions.h | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | uint64_t expected_cocsep[21] = { | ||
| 2 | [0] = 1, | ||
| 3 | [1] = 6, | ||
| 4 | [2] = 63, | ||
| 5 | [3] = 468, | ||
| 6 | [4] = 3068, | ||
| 7 | [5] = 15438, | ||
| 8 | [6] = 53814, | ||
| 9 | [7] = 71352, | ||
| 10 | [8] = 8784, | ||
| 11 | [9] = 96 | ||
| 12 | }; | ||
| 13 | |||
| 1 | uint64_t expected_h48[12][9][21] = { | 14 | uint64_t expected_h48[12][9][21] = { |
| 2 | [0] = { | 15 | [0] = { |
| 3 | [2] = { | 16 | [2] = { |
| @@ -31,3 +44,76 @@ uint64_t expected_h48[12][9][21] = { | |||
| 31 | }, | 44 | }, |
| 32 | }, | 45 | }, |
| 33 | }; | 46 | }; |
| 47 | |||
| 48 | static bool | ||
| 49 | distribution_equal(const uint64_t *expected, const uint64_t *actual, int n) | ||
| 50 | { | ||
| 51 | bool equal; | ||
| 52 | int i; | ||
| 53 | |||
| 54 | for (i = 0, equal = true; i <= n; i++) { | ||
| 55 | if (expected[i] != actual[i]) { | ||
| 56 | equal = false; | ||
| 57 | printf("Wrong value for %d: expected %" PRIu64 | ||
| 58 | ", actual %" PRIu64 "\n", | ||
| 59 | i, expected[i], actual[i]); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | return equal; | ||
| 64 | } | ||
| 65 | |||
| 66 | static bool | ||
| 67 | check_cocsep(const void *data) | ||
| 68 | { | ||
| 69 | tableinfo_t info; | ||
| 70 | |||
| 71 | readtableinfo(data, &info); | ||
| 72 | return distribution_equal( | ||
| 73 | expected_cocsep, info.distribution, info.maxvalue); | ||
| 74 | } | ||
| 75 | |||
| 76 | static bool | ||
| 77 | unknown_h48(uint8_t h, uint8_t k) | ||
| 78 | { | ||
| 79 | if (k != 2 && k != 4) | ||
| 80 | return true; | ||
| 81 | |||
| 82 | if (k == 4 && h != 0) | ||
| 83 | return true; | ||
| 84 | |||
| 85 | return k == 2 && h > 1; | ||
| 86 | } | ||
| 87 | |||
| 88 | STATIC bool | ||
| 89 | check_distribution(const char *solver, const void *data) | ||
| 90 | { | ||
| 91 | tableinfo_t info = {0}; | ||
| 92 | |||
| 93 | if (!strcmp(solver, "h48")) { | ||
| 94 | readtableinfo(data, &info); | ||
| 95 | if (!distribution_equal( | ||
| 96 | expected_cocsep, info.distribution, info.maxvalue)) { | ||
| 97 | printf("ERROR! cocsep distribution is incorrect\n"); | ||
| 98 | return false; | ||
| 99 | } | ||
| 100 | printf("cocsep distribution is correct\n"); | ||
| 101 | |||
| 102 | readtableinfo_n(data, 2, &info); | ||
| 103 | if (unknown_h48(info.h48h, info.bits)) | ||
| 104 | goto check_distribution_unknown; | ||
| 105 | |||
| 106 | if (!distribution_equal(expected_h48[info.h48h][info.bits], | ||
| 107 | info.distribution, info.maxvalue)) { | ||
| 108 | printf("ERROR! h48 distribution is incorrect\n"); | ||
| 109 | return false; | ||
| 110 | } | ||
| 111 | |||
| 112 | printf("h48 distribution is correct\n"); | ||
| 113 | return true; | ||
| 114 | } | ||
| 115 | |||
| 116 | check_distribution_unknown: | ||
| 117 | printf("Distribution unknown, not checked\n"); | ||
| 118 | return true; | ||
| 119 | } | ||
diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h index 1e714a7..f9baf00 100644 --- a/tools/nissy_extra.h +++ b/tools/nissy_extra.h | |||
| @@ -3,5 +3,10 @@ This header file exposes certain functions that are meant to be used | |||
| 3 | for testing purposes only. | 3 | for testing purposes only. |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #define STATIC static | ||
| 7 | #define LOG printf | ||
| 8 | |||
| 9 | #include "../src/solvers/tables.h" | ||
| 10 | |||
| 6 | size_t gendata_h48_derive(uint8_t, const void *, void *); | 11 | size_t gendata_h48_derive(uint8_t, const void *, void *); |
| 7 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); | 12 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); |
diff --git a/tools/tool.h b/tools/tool.h index 9fee050..2aaabae 100644 --- a/tools/tool.h +++ b/tools/tool.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include <inttypes.h> | 4 | #include <inttypes.h> |
| 5 | #include <stdio.h> | 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| 7 | #include <string.h> | ||
| 7 | 8 | ||
| 8 | #include "../src/nissy.h" | 9 | #include "../src/nissy.h" |
| 9 | #include "nissy_extra.h" | 10 | #include "nissy_extra.h" |
