#ifndef _asmsh_check_h__ #define _asmsh_check_h__ #include #include #include #include #include #include #include #include /**@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); /**@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