test_udp.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. }
  26. static void
  27. udp_teardown(void)
  28. {
  29. udp_remove_all();
  30. }
  31. /* Test functions */
  32. START_TEST(test_udp_new_remove)
  33. {
  34. struct udp_pcb* pcb;
  35. LWIP_UNUSED_ARG(_i);
  36. fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 0);
  37. pcb = udp_new();
  38. fail_unless(pcb != NULL);
  39. if (pcb != NULL) {
  40. fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 1);
  41. udp_remove(pcb);
  42. fail_unless(MEMP_STATS_GET(used, MEMP_UDP_PCB) == 0);
  43. }
  44. }
  45. END_TEST
  46. /** Create the suite including all tests for this module */
  47. Suite *
  48. udp_suite(void)
  49. {
  50. testfunc tests[] = {
  51. TESTFUNC(test_udp_new_remove),
  52. };
  53. return create_suite("UDP", tests, sizeof(tests)/sizeof(testfunc), udp_setup, udp_teardown);
  54. }