test_udp.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "test_udp.h"
  2. #include "lwip/udp.h"
  3. #include "lwip/stats.h"
  4. #if !LWIP_STATS || !UDP_STATS || !MEMP_STATS
  5. #error "This tests needs UDP- and MEMP-statistics enabled"
  6. #endif
  7. /* Helper functions */
  8. static void
  9. udp_remove_all(void)
  10. {
  11. struct udp_pcb *pcb = udp_pcbs;
  12. struct udp_pcb *pcb2;
  13. while(pcb != NULL) {
  14. pcb2 = pcb;
  15. pcb = pcb->next;
  16. udp_remove(pcb2);
  17. }
  18. fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 0);
  19. }
  20. /* Setups/teardown functions */
  21. static void
  22. udp_setup(void)
  23. {
  24. udp_remove_all();
  25. lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
  26. }
  27. static void
  28. udp_teardown(void)
  29. {
  30. udp_remove_all();
  31. lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
  32. }
  33. /* Test functions */
  34. START_TEST(test_udp_new_remove)
  35. {
  36. struct udp_pcb* pcb;
  37. LWIP_UNUSED_ARG(_i);
  38. fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 0);
  39. pcb = udp_new();
  40. fail_unless(pcb != NULL);
  41. if (pcb != NULL) {
  42. fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 1);
  43. udp_remove(pcb);
  44. fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 0);
  45. }
  46. }
  47. END_TEST
  48. /** Create the suite including all tests for this module */
  49. Suite *
  50. udp_suite(void)
  51. {
  52. testfunc tests[] = {
  53. TESTFUNC(test_udp_new_remove),
  54. };
  55. return create_suite("UDP", tests, sizeof(tests)/sizeof(testfunc), udp_setup, udp_teardown);
  56. }