1#ifndef SSEC_TEST_UTILS_H
2#define SSEC_TEST_UTILS_H
9static inline __attribute__((always_inline))
void escape(
void *
p) { __asm__ __volatile__(
"" :
"+m,r"(
p) : :
"memory"); }
12 { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
14 { NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE }
19#define TEST_CASE(test_func) \
20 { #test_func, test_func, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
22#define TEST_CASE_SETUP(test_func, setup, teardown) \
23 { #test_func, test_func, setup, teardown, MUNIT_TEST_OPTION_NONE, NULL }
25#define BENCHMARK(test_func, setup, teardown, params) \
26 { #test_func, test_func, setup, teardown, MUNIT_TEST_OPTION_SINGLE_ITERATION, params }
28#define SUITE(suite_name, test_cases) \
29 { suite_name, test_cases, NULL, 0, MUNIT_SUITE_OPTION_NONE }
31#define SUITE_IT(suite_name, test_cases, iterations) \
32 { suite_name, test_cases, NULL, iterations, MUNIT_SUITE_OPTION_NONE }
34#define SUITE_OF_SUITE(suite_name, nested_suite) \
35 { suite_name, NULL, nested_suite, 0, MUNIT_SUITE_OPTION_NONE }
38#define RANDOM_FP_ELEMENT(out) \
40 munit_rand_memory(FIELD_BYTES, (munit_uint8_t *) (out)); \
41 (out)[FIELD_64BITS_WORDS - 1] &= MASK_FIELD_ELEMENT; \
42 while (!multiprecision_is_smaller((out), FIELD_CHARACTERISTIC, FIELD_64BITS_WORDS)) { \
43 munit_rand_memory(FIELD_BYTES, (munit_uint8_t *) (out)); \
44 (out)[FIELD_64BITS_WORDS - 1] &= MASK_FIELD_ELEMENT; \
48#define RANDOM_SEED(out) \
50 munit_rand_memory(SECURITY_BITS / 8, (munit_uint8_t *) (out)); \
53static void RANDOM_FP2_ELEMENT(
fp2_t *output) {
58#define RANDOM_BIT_STRING(out) \
60 munit_rand_memory(BIT_LENGTH_PATH / 8, (munit_uint8_t *) (out)); \
64#define RANDOM_TRIT_STRING(out) \
66 uint8_t bound = 0xF3; \
67 for(int i = 0; i < (TRITLENGTH_PATH / 5); i++) { \
69 munit_rand_memory(1, (munit_uint8_t *) (&trit_str)); \
70 while (issmaller(bound, trit_str)) { \
71 munit_rand_memory(1, (munit_uint8_t *) (&trit_str)); \
78#define MAX_MARKER_LEN 50
80static inline int FindMarker(FILE *infile,
const char *marker) {
85 len = (int) strlen(marker);
90 for (
i = 0;
i < len;
i++) {
91 curr_line = fgetc(infile);
93 if (curr_line == EOF) {
100 if (!strncmp(line, marker, len)) {
104 for (
i = 0;
i < len - 1;
i++) {
105 line[
i] = line[
i + 1];
107 curr_line = fgetc(infile);
108 line[len - 1] = curr_line;
109 if (curr_line == EOF) {
116static inline int convert_to_hex(
int ch) {
117 if (ch >= 48 && ch <= 57) {
119 }
else if (ch >= 64 && ch <= 70) {
125static inline int ReadHex(FILE *infile,
unsigned char *A,
int Length,
char *str) {
132 memset(A, 0x00, Length);
134 if (FindMarker(infile, str)) {
135 while (count < Length) {
138 ch1 = convert_to_hex(ch1);
139 ch2 = convert_to_hex(ch2);
140 A[count] = ((
unsigned char) (ch1 << 4) | (
unsigned char) ch2);
149static inline void file_print_bytes(FILE *
fp,
const char *txt,
const uint8_t *data_bytes, uint32_t data_bytes_length) {
150 fprintf(
fp,
"%s", txt);
152 for (uint32_t
i = 0;
i < data_bytes_length;
i++) {
153 fprintf(
fp,
"%02X", data_bytes[
i]);
uint64_t fp[NUMBER_OF_WORDS]
#define RANDOM_FP_ELEMENT(out)