2
0

testutil.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /*
  2. * Copyright 2014-2019 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_TESTUTIL_H
  10. # define OSSL_TESTUTIL_H
  11. #include <stdarg.h>
  12. #include <openssl/err.h>
  13. #include <openssl/e_os2.h>
  14. #include <openssl/bn.h>
  15. /*-
  16. * Simple unit tests should implement setup_tests().
  17. * This function should return zero if the registration process fails.
  18. * To register tests, call ADD_TEST or ADD_ALL_TESTS:
  19. *
  20. * int setup_tests(void)
  21. * {
  22. * ADD_TEST(test_foo);
  23. * ADD_ALL_TESTS(test_bar, num_test_bar);
  24. * return 1;
  25. * }
  26. *
  27. * Tests that require clean up after execution should implement:
  28. *
  29. * void cleanup_tests(void);
  30. *
  31. * The cleanup_tests function will be called even if setup_tests()
  32. * returns failure.
  33. *
  34. * In some cases, early initialization before the framework is set up
  35. * may be needed. In such a case, this should be implemented:
  36. *
  37. * int global_init(void);
  38. *
  39. * This function should return zero if there is an unrecoverable error and
  40. * non-zero if the initialization was successful.
  41. */
  42. /* Adds a simple test case. */
  43. # define ADD_TEST(test_function) add_test(#test_function, test_function)
  44. /*
  45. * Simple parameterized tests. Calls test_function(idx) for each 0 <= idx < num.
  46. */
  47. # define ADD_ALL_TESTS(test_function, num) \
  48. add_all_tests(#test_function, test_function, num, 1)
  49. /*
  50. * A variant of the same without TAP output.
  51. */
  52. # define ADD_ALL_TESTS_NOSUBTEST(test_function, num) \
  53. add_all_tests(#test_function, test_function, num, 0)
  54. /*-
  55. * Test cases that share common setup should use the helper
  56. * SETUP_TEST_FIXTURE and EXECUTE_TEST macros for test case functions.
  57. *
  58. * SETUP_TEST_FIXTURE will call set_up() to create a new TEST_FIXTURE_TYPE
  59. * object called "fixture". It will also allocate the "result" variable used
  60. * by EXECUTE_TEST. set_up() should take a const char* specifying the test
  61. * case name and return a TEST_FIXTURE_TYPE by reference.
  62. *
  63. * EXECUTE_TEST will pass fixture to execute_func() by reference, call
  64. * tear_down(), and return the result of execute_func(). execute_func() should
  65. * take a TEST_FIXTURE_TYPE by reference and return 1 on success and 0 on
  66. * failure. The tear_down function is responsible for deallocation of the
  67. * result variable, if required.
  68. *
  69. * Unit tests can define their own SETUP_TEST_FIXTURE and EXECUTE_TEST
  70. * variations like so:
  71. *
  72. * #define SETUP_FOOBAR_TEST_FIXTURE()\
  73. * SETUP_TEST_FIXTURE(FOOBAR_TEST_FIXTURE, set_up_foobar)
  74. *
  75. * #define EXECUTE_FOOBAR_TEST()\
  76. * EXECUTE_TEST(execute_foobar, tear_down_foobar)
  77. *
  78. * Then test case functions can take the form:
  79. *
  80. * static int test_foobar_feature()
  81. * {
  82. * SETUP_FOOBAR_TEST_FIXTURE();
  83. * [...set individual members of fixture...]
  84. * EXECUTE_FOOBAR_TEST();
  85. * }
  86. */
  87. # define SETUP_TEST_FIXTURE(TEST_FIXTURE_TYPE, set_up)\
  88. TEST_FIXTURE_TYPE *fixture = set_up(TEST_CASE_NAME); \
  89. int result = 0
  90. # define EXECUTE_TEST(execute_func, tear_down)\
  91. if (fixture != NULL) {\
  92. result = execute_func(fixture);\
  93. tear_down(fixture);\
  94. }
  95. /*
  96. * TEST_CASE_NAME is defined as the name of the test case function where
  97. * possible; otherwise we get by with the file name and line number.
  98. */
  99. # if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
  100. # if defined(_MSC_VER)
  101. # define TEST_CASE_NAME __FUNCTION__
  102. # else
  103. # define testutil_stringify_helper(s) #s
  104. # define testutil_stringify(s) testutil_stringify_helper(s)
  105. # define TEST_CASE_NAME __FILE__ ":" testutil_stringify(__LINE__)
  106. # endif /* _MSC_VER */
  107. # else
  108. # define TEST_CASE_NAME __func__
  109. # endif /* __STDC_VERSION__ */
  110. /*
  111. * Tests that need access to command line arguments should use the functions:
  112. * test_get_argument(int n) to get the nth argument, the first argument is
  113. * argument 0. This function returns NULL on error.
  114. * test_get_argument_count() to get the count of the arguments.
  115. * test_has_option(const char *) to check if the specified option was passed.
  116. * test_get_option_argument(const char *) to get an option which includes an
  117. * argument. NULL is returns if the option is not found.
  118. * const char *test_get_program_name(void) returns the name of the test program
  119. * being executed.
  120. */
  121. const char *test_get_program_name(void);
  122. char *test_get_argument(size_t n);
  123. size_t test_get_argument_count(void);
  124. int test_has_option(const char *option);
  125. const char *test_get_option_argument(const char *option);
  126. /*
  127. * Internal helpers. Test programs shouldn't use these directly, but should
  128. * rather link to one of the helper main() methods.
  129. */
  130. void add_test(const char *test_case_name, int (*test_fn) (void));
  131. void add_all_tests(const char *test_case_name, int (*test_fn)(int idx), int num,
  132. int subtest);
  133. /*
  134. * Declarations for user defined functions.
  135. * The first two return a boolean indicating that the test should not proceed.
  136. */
  137. int global_init(void);
  138. int setup_tests(void);
  139. void cleanup_tests(void);
  140. /*
  141. * Test assumption verification helpers.
  142. */
  143. #define PRINTF_FORMAT(a, b)
  144. #if defined(__GNUC__) && defined(__STDC_VERSION__)
  145. /*
  146. * Because we support the 'z' modifier, which made its appearance in C99,
  147. * we can't use __attribute__ with pre C99 dialects.
  148. */
  149. # if __STDC_VERSION__ >= 199901L
  150. # undef PRINTF_FORMAT
  151. # define PRINTF_FORMAT(a, b) __attribute__ ((format(printf, a, b)))
  152. # endif
  153. #endif
  154. # define DECLARE_COMPARISON(type, name, opname) \
  155. int test_ ## name ## _ ## opname(const char *, int, \
  156. const char *, const char *, \
  157. const type, const type);
  158. # define DECLARE_COMPARISONS(type, name) \
  159. DECLARE_COMPARISON(type, name, eq) \
  160. DECLARE_COMPARISON(type, name, ne) \
  161. DECLARE_COMPARISON(type, name, lt) \
  162. DECLARE_COMPARISON(type, name, le) \
  163. DECLARE_COMPARISON(type, name, gt) \
  164. DECLARE_COMPARISON(type, name, ge)
  165. DECLARE_COMPARISONS(int, int)
  166. DECLARE_COMPARISONS(unsigned int, uint)
  167. DECLARE_COMPARISONS(char, char)
  168. DECLARE_COMPARISONS(unsigned char, uchar)
  169. DECLARE_COMPARISONS(long, long)
  170. DECLARE_COMPARISONS(unsigned long, ulong)
  171. DECLARE_COMPARISONS(time_t, time_t)
  172. /*
  173. * Because this comparison uses a printf format specifier that's not
  174. * universally known (yet), we provide an option to not have it declared.
  175. */
  176. # ifndef TESTUTIL_NO_size_t_COMPARISON
  177. DECLARE_COMPARISONS(size_t, size_t)
  178. # endif
  179. /*
  180. * Pointer comparisons against other pointers and null.
  181. * These functions return 1 if the test is true.
  182. * Otherwise, they return 0 and pretty-print diagnostics.
  183. * These should not be called directly, use the TEST_xxx macros below instead.
  184. */
  185. DECLARE_COMPARISON(void *, ptr, eq)
  186. DECLARE_COMPARISON(void *, ptr, ne)
  187. int test_ptr(const char *file, int line, const char *s, const void *p);
  188. int test_ptr_null(const char *file, int line, const char *s, const void *p);
  189. /*
  190. * Equality tests for strings where NULL is a legitimate value.
  191. * These calls return 1 if the two passed strings compare true.
  192. * Otherwise, they return 0 and pretty-print diagnostics.
  193. * These should not be called directly, use the TEST_xxx macros below instead.
  194. */
  195. DECLARE_COMPARISON(char *, str, eq)
  196. DECLARE_COMPARISON(char *, str, ne)
  197. /*
  198. * Same as above, but for strncmp.
  199. */
  200. int test_strn_eq(const char *file, int line, const char *, const char *,
  201. const char *a, const char *b, size_t s);
  202. int test_strn_ne(const char *file, int line, const char *, const char *,
  203. const char *a, const char *b, size_t s);
  204. /*
  205. * Equality test for memory blocks where NULL is a legitimate value.
  206. * These calls return 1 if the two memory blocks compare true.
  207. * Otherwise, they return 0 and pretty-print diagnostics.
  208. * These should not be called directly, use the TEST_xxx macros below instead.
  209. */
  210. int test_mem_eq(const char *, int, const char *, const char *,
  211. const void *, size_t, const void *, size_t);
  212. int test_mem_ne(const char *, int, const char *, const char *,
  213. const void *, size_t, const void *, size_t);
  214. /*
  215. * Check a boolean result for being true or false.
  216. * They return 1 if the condition is true (i.e. the value is non-zero).
  217. * Otherwise, they return 0 and pretty-prints diagnostics using |s|.
  218. * These should not be called directly, use the TEST_xxx macros below instead.
  219. */
  220. int test_true(const char *file, int line, const char *s, int b);
  221. int test_false(const char *file, int line, const char *s, int b);
  222. /*
  223. * Comparisons between BIGNUMs.
  224. * BIGNUMS can be compared against other BIGNUMs or zero.
  225. * Some additional equality tests against 1 & specific values are provided.
  226. * Tests for parity are included as well.
  227. */
  228. DECLARE_COMPARISONS(BIGNUM *, BN)
  229. int test_BN_eq_zero(const char *file, int line, const char *s, const BIGNUM *a);
  230. int test_BN_ne_zero(const char *file, int line, const char *s, const BIGNUM *a);
  231. int test_BN_lt_zero(const char *file, int line, const char *s, const BIGNUM *a);
  232. int test_BN_le_zero(const char *file, int line, const char *s, const BIGNUM *a);
  233. int test_BN_gt_zero(const char *file, int line, const char *s, const BIGNUM *a);
  234. int test_BN_ge_zero(const char *file, int line, const char *s, const BIGNUM *a);
  235. int test_BN_eq_one(const char *file, int line, const char *s, const BIGNUM *a);
  236. int test_BN_odd(const char *file, int line, const char *s, const BIGNUM *a);
  237. int test_BN_even(const char *file, int line, const char *s, const BIGNUM *a);
  238. int test_BN_eq_word(const char *file, int line, const char *bns, const char *ws,
  239. const BIGNUM *a, BN_ULONG w);
  240. int test_BN_abs_eq_word(const char *file, int line, const char *bns,
  241. const char *ws, const BIGNUM *a, BN_ULONG w);
  242. /*
  243. * Pretty print a failure message.
  244. * These should not be called directly, use the TEST_xxx macros below instead.
  245. */
  246. void test_error(const char *file, int line, const char *desc, ...)
  247. PRINTF_FORMAT(3, 4);
  248. void test_error_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
  249. void test_info(const char *file, int line, const char *desc, ...)
  250. PRINTF_FORMAT(3, 4);
  251. void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
  252. void test_note(const char *desc, ...) PRINTF_FORMAT(1, 2);
  253. void test_openssl_errors(void);
  254. void test_perror(const char *s);
  255. /*
  256. * The following macros provide wrapper calls to the test functions with
  257. * a default description that indicates the file and line number of the error.
  258. *
  259. * The following macros guarantee to evaluate each argument exactly once.
  260. * This allows constructs such as: if (!TEST_ptr(ptr = OPENSSL_malloc(..)))
  261. * to produce better contextual output than:
  262. * ptr = OPENSSL_malloc(..);
  263. * if (!TEST_ptr(ptr))
  264. */
  265. # define TEST_int_eq(a, b) test_int_eq(__FILE__, __LINE__, #a, #b, a, b)
  266. # define TEST_int_ne(a, b) test_int_ne(__FILE__, __LINE__, #a, #b, a, b)
  267. # define TEST_int_lt(a, b) test_int_lt(__FILE__, __LINE__, #a, #b, a, b)
  268. # define TEST_int_le(a, b) test_int_le(__FILE__, __LINE__, #a, #b, a, b)
  269. # define TEST_int_gt(a, b) test_int_gt(__FILE__, __LINE__, #a, #b, a, b)
  270. # define TEST_int_ge(a, b) test_int_ge(__FILE__, __LINE__, #a, #b, a, b)
  271. # define TEST_uint_eq(a, b) test_uint_eq(__FILE__, __LINE__, #a, #b, a, b)
  272. # define TEST_uint_ne(a, b) test_uint_ne(__FILE__, __LINE__, #a, #b, a, b)
  273. # define TEST_uint_lt(a, b) test_uint_lt(__FILE__, __LINE__, #a, #b, a, b)
  274. # define TEST_uint_le(a, b) test_uint_le(__FILE__, __LINE__, #a, #b, a, b)
  275. # define TEST_uint_gt(a, b) test_uint_gt(__FILE__, __LINE__, #a, #b, a, b)
  276. # define TEST_uint_ge(a, b) test_uint_ge(__FILE__, __LINE__, #a, #b, a, b)
  277. # define TEST_char_eq(a, b) test_char_eq(__FILE__, __LINE__, #a, #b, a, b)
  278. # define TEST_char_ne(a, b) test_char_ne(__FILE__, __LINE__, #a, #b, a, b)
  279. # define TEST_char_lt(a, b) test_char_lt(__FILE__, __LINE__, #a, #b, a, b)
  280. # define TEST_char_le(a, b) test_char_le(__FILE__, __LINE__, #a, #b, a, b)
  281. # define TEST_char_gt(a, b) test_char_gt(__FILE__, __LINE__, #a, #b, a, b)
  282. # define TEST_char_ge(a, b) test_char_ge(__FILE__, __LINE__, #a, #b, a, b)
  283. # define TEST_uchar_eq(a, b) test_uchar_eq(__FILE__, __LINE__, #a, #b, a, b)
  284. # define TEST_uchar_ne(a, b) test_uchar_ne(__FILE__, __LINE__, #a, #b, a, b)
  285. # define TEST_uchar_lt(a, b) test_uchar_lt(__FILE__, __LINE__, #a, #b, a, b)
  286. # define TEST_uchar_le(a, b) test_uchar_le(__FILE__, __LINE__, #a, #b, a, b)
  287. # define TEST_uchar_gt(a, b) test_uchar_gt(__FILE__, __LINE__, #a, #b, a, b)
  288. # define TEST_uchar_ge(a, b) test_uchar_ge(__FILE__, __LINE__, #a, #b, a, b)
  289. # define TEST_long_eq(a, b) test_long_eq(__FILE__, __LINE__, #a, #b, a, b)
  290. # define TEST_long_ne(a, b) test_long_ne(__FILE__, __LINE__, #a, #b, a, b)
  291. # define TEST_long_lt(a, b) test_long_lt(__FILE__, __LINE__, #a, #b, a, b)
  292. # define TEST_long_le(a, b) test_long_le(__FILE__, __LINE__, #a, #b, a, b)
  293. # define TEST_long_gt(a, b) test_long_gt(__FILE__, __LINE__, #a, #b, a, b)
  294. # define TEST_long_ge(a, b) test_long_ge(__FILE__, __LINE__, #a, #b, a, b)
  295. # define TEST_ulong_eq(a, b) test_ulong_eq(__FILE__, __LINE__, #a, #b, a, b)
  296. # define TEST_ulong_ne(a, b) test_ulong_ne(__FILE__, __LINE__, #a, #b, a, b)
  297. # define TEST_ulong_lt(a, b) test_ulong_lt(__FILE__, __LINE__, #a, #b, a, b)
  298. # define TEST_ulong_le(a, b) test_ulong_le(__FILE__, __LINE__, #a, #b, a, b)
  299. # define TEST_ulong_gt(a, b) test_ulong_gt(__FILE__, __LINE__, #a, #b, a, b)
  300. # define TEST_ulong_ge(a, b) test_ulong_ge(__FILE__, __LINE__, #a, #b, a, b)
  301. # define TEST_size_t_eq(a, b) test_size_t_eq(__FILE__, __LINE__, #a, #b, a, b)
  302. # define TEST_size_t_ne(a, b) test_size_t_ne(__FILE__, __LINE__, #a, #b, a, b)
  303. # define TEST_size_t_lt(a, b) test_size_t_lt(__FILE__, __LINE__, #a, #b, a, b)
  304. # define TEST_size_t_le(a, b) test_size_t_le(__FILE__, __LINE__, #a, #b, a, b)
  305. # define TEST_size_t_gt(a, b) test_size_t_gt(__FILE__, __LINE__, #a, #b, a, b)
  306. # define TEST_size_t_ge(a, b) test_size_t_ge(__FILE__, __LINE__, #a, #b, a, b)
  307. # define TEST_time_t_eq(a, b) test_time_t_eq(__FILE__, __LINE__, #a, #b, a, b)
  308. # define TEST_time_t_ne(a, b) test_time_t_ne(__FILE__, __LINE__, #a, #b, a, b)
  309. # define TEST_time_t_lt(a, b) test_time_t_lt(__FILE__, __LINE__, #a, #b, a, b)
  310. # define TEST_time_t_le(a, b) test_time_t_le(__FILE__, __LINE__, #a, #b, a, b)
  311. # define TEST_time_t_gt(a, b) test_time_t_gt(__FILE__, __LINE__, #a, #b, a, b)
  312. # define TEST_time_t_ge(a, b) test_time_t_ge(__FILE__, __LINE__, #a, #b, a, b)
  313. # define TEST_ptr_eq(a, b) test_ptr_eq(__FILE__, __LINE__, #a, #b, a, b)
  314. # define TEST_ptr_ne(a, b) test_ptr_ne(__FILE__, __LINE__, #a, #b, a, b)
  315. # define TEST_ptr(a) test_ptr(__FILE__, __LINE__, #a, a)
  316. # define TEST_ptr_null(a) test_ptr_null(__FILE__, __LINE__, #a, a)
  317. # define TEST_str_eq(a, b) test_str_eq(__FILE__, __LINE__, #a, #b, a, b)
  318. # define TEST_str_ne(a, b) test_str_ne(__FILE__, __LINE__, #a, #b, a, b)
  319. # define TEST_strn_eq(a, b, n) test_strn_eq(__FILE__, __LINE__, #a, #b, a, b, n)
  320. # define TEST_strn_ne(a, b, n) test_strn_ne(__FILE__, __LINE__, #a, #b, a, b, n)
  321. # define TEST_mem_eq(a, m, b, n) test_mem_eq(__FILE__, __LINE__, #a, #b, a, m, b, n)
  322. # define TEST_mem_ne(a, m, b, n) test_mem_ne(__FILE__, __LINE__, #a, #b, a, m, b, n)
  323. # define TEST_true(a) test_true(__FILE__, __LINE__, #a, (a) != 0)
  324. # define TEST_false(a) test_false(__FILE__, __LINE__, #a, (a) != 0)
  325. # define TEST_BN_eq(a, b) test_BN_eq(__FILE__, __LINE__, #a, #b, a, b)
  326. # define TEST_BN_ne(a, b) test_BN_ne(__FILE__, __LINE__, #a, #b, a, b)
  327. # define TEST_BN_lt(a, b) test_BN_lt(__FILE__, __LINE__, #a, #b, a, b)
  328. # define TEST_BN_gt(a, b) test_BN_gt(__FILE__, __LINE__, #a, #b, a, b)
  329. # define TEST_BN_le(a, b) test_BN_le(__FILE__, __LINE__, #a, #b, a, b)
  330. # define TEST_BN_ge(a, b) test_BN_ge(__FILE__, __LINE__, #a, #b, a, b)
  331. # define TEST_BN_eq_zero(a) test_BN_eq_zero(__FILE__, __LINE__, #a, a)
  332. # define TEST_BN_ne_zero(a) test_BN_ne_zero(__FILE__, __LINE__, #a, a)
  333. # define TEST_BN_lt_zero(a) test_BN_lt_zero(__FILE__, __LINE__, #a, a)
  334. # define TEST_BN_gt_zero(a) test_BN_gt_zero(__FILE__, __LINE__, #a, a)
  335. # define TEST_BN_le_zero(a) test_BN_le_zero(__FILE__, __LINE__, #a, a)
  336. # define TEST_BN_ge_zero(a) test_BN_ge_zero(__FILE__, __LINE__, #a, a)
  337. # define TEST_BN_eq_one(a) test_BN_eq_one(__FILE__, __LINE__, #a, a)
  338. # define TEST_BN_eq_word(a, w) test_BN_eq_word(__FILE__, __LINE__, #a, #w, a, w)
  339. # define TEST_BN_abs_eq_word(a, w) test_BN_abs_eq_word(__FILE__, __LINE__, #a, #w, a, w)
  340. # define TEST_BN_odd(a) test_BN_odd(__FILE__, __LINE__, #a, a)
  341. # define TEST_BN_even(a) test_BN_even(__FILE__, __LINE__, #a, a)
  342. /*
  343. * TEST_error(desc, ...) prints an informative error message in the standard
  344. * format. |desc| is a printf format string.
  345. */
  346. # if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
  347. # define TEST_error test_error_c90
  348. # define TEST_info test_info_c90
  349. # else
  350. # define TEST_error(...) test_error(__FILE__, __LINE__, __VA_ARGS__)
  351. # define TEST_info(...) test_info(__FILE__, __LINE__, __VA_ARGS__)
  352. # endif
  353. # define TEST_note test_note
  354. # define TEST_openssl_errors test_openssl_errors
  355. # define TEST_perror test_perror
  356. extern BIO *bio_out;
  357. extern BIO *bio_err;
  358. /*
  359. * Formatted output for strings, memory and bignums.
  360. */
  361. void test_output_string(const char *name, const char *m, size_t l);
  362. void test_output_bignum(const char *name, const BIGNUM *bn);
  363. void test_output_memory(const char *name, const unsigned char *m, size_t l);
  364. /*
  365. * Utilities to parse a test file.
  366. */
  367. #define TESTMAXPAIRS 20
  368. typedef struct pair_st {
  369. char *key;
  370. char *value;
  371. } PAIR;
  372. typedef struct stanza_st {
  373. const char *test_file; /* Input file name */
  374. BIO *fp; /* Input file */
  375. int curr; /* Current line in file */
  376. int start; /* Line where test starts */
  377. int errors; /* Error count */
  378. int numtests; /* Number of tests */
  379. int numskip; /* Number of skipped tests */
  380. int numpairs;
  381. PAIR pairs[TESTMAXPAIRS];
  382. BIO *key; /* temp memory BIO for reading in keys */
  383. char buff[4096]; /* Input buffer for a single key/value */
  384. } STANZA;
  385. /*
  386. * Prepare to start reading the file |testfile| as input.
  387. */
  388. int test_start_file(STANZA *s, const char *testfile);
  389. int test_end_file(STANZA *s);
  390. /*
  391. * Read a stanza from the test file. A stanza consists of a block
  392. * of lines of the form
  393. * key = value
  394. * The block is terminated by EOF or a blank line.
  395. * Return 1 if found, 0 on EOF or error.
  396. */
  397. int test_readstanza(STANZA *s);
  398. /*
  399. * Clear a stanza, release all allocated memory.
  400. */
  401. void test_clearstanza(STANZA *s);
  402. /*
  403. * Glue an array of strings together and return it as an allocated string.
  404. * Optionally return the whole length of this string in |out_len|
  405. */
  406. char *glue_strings(const char *list[], size_t *out_len);
  407. /*
  408. * Pseudo random number generator of low quality but having repeatability
  409. * across platforms. The two calls are replacements for random(3) and
  410. * srandom(3).
  411. */
  412. uint32_t test_random(void);
  413. void test_random_seed(uint32_t sd);
  414. /* Create a file path from a directory and a filename */
  415. char *test_mk_file_path(const char *dir, const char *file);
  416. #endif /* OSSL_TESTUTIL_H */