123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #ifndef _asmsh_check_h__
- #define _asmsh_check_h__
-
- #include <check.h>
- #include <errno.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <libgen.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
-
- /**@brief Start a asmsh test
- *@param const char* suite_str test suite string
- *@param const char* tc_str test case string
- */
- #define ASMSH_CHECK_START(suite_str, tc_str) \
- Suite * asmsh_test_suite(void) \
- {\
- Suite *s;\
- TCase *tc;\
- s = suite_create(suite_str);\
- tc = tcase_create(tc_str);
-
-
- /**@brief Set the setup & teardown fixture
- *@param void (*setup)()
- *@param void (*teardown)()
- */
- #define ASMSH_SET_FIXTURE(setup, teardown) \
- tcase_add_checked_fixture(tc, setup, teardown)
- /**@brief Add a test function defined using START_TEST(name) { ... } END_TEST
- */
- #define ASMSH_ADD_TEST(test) tcase_add_test(tc, test)
- #define ASMSH_ADD_LOOP_TEST(test, start, stop) tcase_add_loop_test(tc, test, start, stop);
- #define ASMSH_ADD_LOOP(test, samples) tcase_add_loop_test(tc, test, 0, sizeof(samples)/sizeof(*samples));
-
- /**@brief End a asmsh test */
- #define ASMSH_CHECK_END \
- suite_add_tcase(s, tc);\
- return s;\
- }\
- \
- int main(int argc, char **argv) {\
- int n_fail;\
- Suite *su;\
- SRunner *sr;\
- n_fail = chdir(dirname(argv[0])); /* move in ./tests dir */ \
- if(n_fail < 0)\
- {\
- perror("Unable to chdir in tests folder");\
- }\
- su = asmsh_test_suite();\
- sr = srunner_create(su);\
- srunner_set_fork_status(sr, CK_FORK);\
- srunner_run_all(sr, CK_VERBOSE);\
- n_fail = srunner_ntests_failed(sr);\
- srunner_free(sr);\
- return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\
- }
-
- #define ck_assert_printf(test, format, ...) {\
- char _err_msg[512];\
- snprintf(_err_msg, sizeof(char) * 512,format, __VA_ARGS__);\
- ck_assert_msg(test, _err_msg);\
- }
-
- #define close_stdpipe() {\
- close(STDPIPE);\
- STDPIPE = -1;\
- }
-
- #define send_sample_stdpipe(id) {\
- int ret;\
- char buff[1024];\
- while((ret= read(samples_fd[id], buff, 1024)) > 0)\
- {\
- ret = write(STDPIPE, buff, strlen(buff));\
- if(ret < 0)\
- {\
- perror("Unable to write through pipe");\
- ck_abort_msg("Unable to write through pipe");\
- }\
- }\
- if(ret < 0)\
- {\
- perror("Unable to read through pipe");\
- ck_abort_msg("Unable to read through pipe");\
- }\
- }
-
-
- #endif
|