A shell that runs x86_64 assembly
c
x86-64
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

asmsh_check.h 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef _asmsh_check_h__
  2. #define _asmsh_check_h__
  3. #include <check.h>
  4. #include <errno.h>
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <libgen.h>
  8. #include <fcntl.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. /**@brief Start a asmsh test
  12. *@param const char* suite_str test suite string
  13. *@param const char* tc_str test case string
  14. */
  15. #define ASMSH_CHECK_START(suite_str, tc_str) \
  16. Suite * asmsh_test_suite(void) \
  17. {\
  18. Suite *s;\
  19. TCase *tc;\
  20. s = suite_create(suite_str);\
  21. tc = tcase_create(tc_str);
  22. /**@brief Set the setup & teardown fixture
  23. *@param void (*setup)()
  24. *@param void (*teardown)()
  25. */
  26. #define ASMSH_SET_FIXTURE(setup, teardown) \
  27. tcase_add_checked_fixture(tc, setup, teardown)
  28. /**@brief Add a test function defined using START_TEST(name) { ... } END_TEST
  29. */
  30. #define ASMSH_ADD_TEST(test) tcase_add_test(tc, test)
  31. #define ASMSH_ADD_LOOP_TEST(test, start, stop) tcase_add_loop_test(tc, test, start, stop);
  32. /**@brief End a asmsh test */
  33. #define ASMSH_CHECK_END \
  34. suite_add_tcase(s, tc);\
  35. return s;\
  36. }\
  37. \
  38. int main(int argc, char **argv) {\
  39. int n_fail;\
  40. Suite *su;\
  41. SRunner *sr;\
  42. n_fail = chdir(dirname(argv[0])); /* move in ./tests dir */ \
  43. if(n_fail < 0)\
  44. {\
  45. perror("Unable to chdir in tests folder");\
  46. }\
  47. su = asmsh_test_suite();\
  48. sr = srunner_create(su);\
  49. srunner_set_fork_status(sr, CK_FORK);\
  50. srunner_run_all(sr, CK_VERBOSE);\
  51. n_fail = srunner_ntests_failed(sr);\
  52. srunner_free(sr);\
  53. return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\
  54. }
  55. #define ck_assert_printf(test, format, ...) {\
  56. char _err_msg[512];\
  57. snprintf(_err_msg, sizeof(char) * 512,format, __VA_ARGS__);\
  58. ck_assert_msg(test, _err_msg);\
  59. }
  60. #define close_stdpipe() {\
  61. close(STDPIPE);\
  62. STDPIPE = -1;\
  63. }
  64. #define send_sample_stdpipe(id) {\
  65. int ret;\
  66. char buff[1024];\
  67. while((ret= read(samples_fd[id], buff, 1024)) > 0)\
  68. {\
  69. ret = write(STDPIPE, buff, strlen(buff));\
  70. if(ret < 0)\
  71. {\
  72. perror("Unable to write through pipe");\
  73. ck_abort_msg("Unable to write through pipe");\
  74. }\
  75. }\
  76. if(ret < 0)\
  77. {\
  78. perror("Unable to read through pipe");\
  79. ck_abort_msg("Unable to read through pipe");\
  80. }\
  81. }
  82. #endif