lwip_unittests.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "lwip_check.h"
  2. #include "udp/test_udp.h"
  3. #include "tcp/test_tcp.h"
  4. #include "tcp/test_tcp_oos.h"
  5. #include "core/test_mem.h"
  6. #include "core/test_pbuf.h"
  7. #include "etharp/test_etharp.h"
  8. #include "dhcp/test_dhcp.h"
  9. #include "mdns/test_mdns.h"
  10. #include "lwip/init.h"
  11. Suite* create_suite(const char* name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
  12. {
  13. size_t i;
  14. Suite *s = suite_create(name);
  15. for(i = 0; i < num_tests; i++) {
  16. TCase *tc_core = tcase_create(name);
  17. if ((setup != NULL) || (teardown != NULL)) {
  18. tcase_add_checked_fixture(tc_core, setup, teardown);
  19. }
  20. tcase_add_named_test(tc_core, tests[i]);
  21. suite_add_tcase(s, tc_core);
  22. }
  23. return s;
  24. }
  25. #ifdef LWIP_UNITTESTS_LIB
  26. int lwip_unittests_run(void)
  27. #else
  28. int main(void)
  29. #endif
  30. {
  31. int number_failed;
  32. SRunner *sr;
  33. size_t i;
  34. suite_getter_fn* suites[] = {
  35. udp_suite,
  36. tcp_suite,
  37. tcp_oos_suite,
  38. mem_suite,
  39. pbuf_suite,
  40. etharp_suite,
  41. dhcp_suite,
  42. mdns_suite
  43. };
  44. size_t num = sizeof(suites)/sizeof(void*);
  45. LWIP_ASSERT("No suites defined", num > 0);
  46. lwip_init();
  47. sr = srunner_create((suites[0])());
  48. for(i = 1; i < num; i++) {
  49. srunner_add_suite(sr, ((suite_getter_fn*)suites[i])());
  50. }
  51. #ifdef LWIP_UNITTESTS_NOFORK
  52. srunner_set_fork_status(sr, CK_NOFORK);
  53. #endif
  54. #ifdef LWIP_UNITTESTS_FORK
  55. srunner_set_fork_status(sr, CK_FORK);
  56. #endif
  57. srunner_run_all(sr, CK_NORMAL);
  58. number_failed = srunner_ntests_failed(sr);
  59. srunner_free(sr);
  60. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  61. }