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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #define ASMSH_ADD_LOOP(test, samples) tcase_add_loop_test(tc, test, 0, sizeof(samples)/sizeof(*samples));
  33. /**@brief End a asmsh test */
  34. #define ASMSH_CHECK_END \
  35. suite_add_tcase(s, tc);\
  36. return s;\
  37. }\
  38. \
  39. int main(int argc, char **argv) {\
  40. int n_fail;\
  41. Suite *su;\
  42. SRunner *sr;\
  43. n_fail = chdir(dirname(argv[0])); /* move in ./tests dir */ \
  44. if(n_fail < 0)\
  45. {\
  46. perror("Unable to chdir in tests folder");\
  47. }\
  48. su = asmsh_test_suite();\
  49. sr = srunner_create(su);\
  50. srunner_set_fork_status(sr, CK_FORK);\
  51. srunner_run_all(sr, CK_VERBOSE);\
  52. n_fail = srunner_ntests_failed(sr);\
  53. srunner_free(sr);\
  54. return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\
  55. }
  56. #define ck_assert_printf(test, format, ...) {\
  57. char _err_msg[512];\
  58. snprintf(_err_msg, sizeof(char) * 512,format, __VA_ARGS__);\
  59. ck_assert_msg(test, _err_msg);\
  60. }
  61. #define close_stdpipe() {\
  62. close(STDPIPE);\
  63. STDPIPE = -1;\
  64. }
  65. #define send_sample_stdpipe(id) {\
  66. int ret;\
  67. char buff[1024];\
  68. while((ret= read(samples_fd[id], buff, 1024)) > 0)\
  69. {\
  70. ret = write(STDPIPE, buff, strlen(buff));\
  71. if(ret < 0)\
  72. {\
  73. perror("Unable to write through pipe");\
  74. ck_abort_msg("Unable to write through pipe");\
  75. }\
  76. }\
  77. if(ret < 0)\
  78. {\
  79. perror("Unable to read through pipe");\
  80. ck_abort_msg("Unable to read through pipe");\
  81. }\
  82. }
  83. #endif