2015-03-03 12:51:35 +00:00
|
|
|
/*
|
2015-03-19 17:38:38 +00:00
|
|
|
* BIRD -- Unit Test Framework (BIRD Test)
|
2015-03-03 12:51:35 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2015-03-17 10:27:40 +00:00
|
|
|
#ifndef _BIRDTEST_H_
|
|
|
|
#define _BIRDTEST_H_
|
|
|
|
|
2015-03-03 12:51:35 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
extern int bt_verbose;
|
|
|
|
extern const char *bt_filename;
|
|
|
|
extern const char *bt_test_id;
|
|
|
|
|
2015-03-17 10:27:40 +00:00
|
|
|
void bt_init(int argc, char *argv[]);
|
|
|
|
void bt_test_case5(int (*fn)(void), const char *id, const char *dsc, int forked, int timeout);
|
2015-03-27 13:03:47 +00:00
|
|
|
int bt_rand_num(void);
|
2015-03-03 12:51:35 +00:00
|
|
|
|
2015-03-13 17:30:03 +00:00
|
|
|
#define BT_SUCCESS 0
|
|
|
|
#define BT_FAILURE 1
|
|
|
|
|
2015-03-17 10:27:40 +00:00
|
|
|
#define BT_DEFAULT_TIMEOUT 5
|
|
|
|
#define BT_DEFAULT_FORKING 1
|
|
|
|
|
2015-03-27 13:03:47 +00:00
|
|
|
#define BT_RANDOM_SEED 982451653
|
|
|
|
|
2015-03-17 10:27:40 +00:00
|
|
|
#define bt_test_case(fn,dsc) \
|
|
|
|
bt_test_case4(fn, dsc, BT_DEFAULT_FORKING, BT_DEFAULT_TIMEOUT)
|
|
|
|
|
|
|
|
#define bt_test_case4(fn,dsc,f,t) \
|
|
|
|
bt_test_case5(fn, #fn, dsc, f, t)
|
2015-03-03 12:51:35 +00:00
|
|
|
|
|
|
|
#define bt_log(format, ...) \
|
|
|
|
fprintf(stderr, "%s: " format "\n", bt_filename, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define bt_note(format, ...) \
|
|
|
|
do { if (bt_verbose) bt_log(format, ##__VA_ARGS__); } while (0)
|
|
|
|
|
2015-03-13 17:27:33 +00:00
|
|
|
#define bt_debug(format, ...) \
|
|
|
|
do { if (bt_verbose > 1) printf(format, ##__VA_ARGS__); } while (0)
|
|
|
|
|
2015-03-03 12:51:35 +00:00
|
|
|
#define bt_abort() \
|
|
|
|
bt_abort_msg("Aborted at %s:%d", __FILE__, __LINE__)
|
|
|
|
|
|
|
|
#define bt_abort_msg(format, ...) \
|
|
|
|
do { bt_log(format, ##__VA_ARGS__); abort(); } while (0)
|
|
|
|
|
|
|
|
#define bt_assert(test) \
|
|
|
|
bt_assert_msg(test, "Assertion (%s) failed at %s:%d", #test, __FILE__, __LINE__)
|
|
|
|
|
|
|
|
#define bt_assert_msg(test,format, ...) \
|
|
|
|
do { if (!(test)) bt_abort_msg(format, ##__VA_ARGS__); } while (0)
|
|
|
|
|
|
|
|
#define bt_syscall(test,format, ...) \
|
|
|
|
do { if (test) { bt_log(format ": %s", ##__VA_ARGS__, strerror(errno)); exit(3); } } while (0)
|
2015-03-17 10:27:40 +00:00
|
|
|
|
2015-03-27 13:04:37 +00:00
|
|
|
#define bt_check(fn, in_arr, expected_arr, len) \
|
|
|
|
do { \
|
|
|
|
unsigned int bt_i_; \
|
|
|
|
for (bt_i_ = 0; bt_i_ < len; bt_i_++) \
|
|
|
|
{ \
|
|
|
|
bt_debug("%s(%u) = %u", #fn, in_arr[bt_i_], fn(in_arr[bt_i_])); \
|
|
|
|
if(fn(in_arr[bt_i_]) != expected_arr[bt_i_]) \
|
|
|
|
{ \
|
|
|
|
bt_debug(", expected %u FAIL! \n", expected_arr[bt_i_]); \
|
|
|
|
bt_abort_msg("%s(%u) = %u, but expected %u", #fn, in_arr[bt_i_], fn(in_arr[bt_i_]), expected_arr[bt_i_]); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
bt_debug(" OK \n"); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2015-03-17 10:27:40 +00:00
|
|
|
#endif /* _BIRDTEST_H_ */
|