test_pbuf.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "test_pbuf.h"
  2. #include "lwip/pbuf.h"
  3. #include "lwip/stats.h"
  4. #if !LWIP_STATS || !MEM_STATS ||!MEMP_STATS
  5. #error "This tests needs MEM- and MEMP-statistics enabled"
  6. #endif
  7. #if LWIP_DNS
  8. #error "This test needs DNS turned off (as it mallocs on init)"
  9. #endif
  10. /* Setups/teardown functions */
  11. static void
  12. pbuf_setup(void)
  13. {
  14. }
  15. static void
  16. pbuf_teardown(void)
  17. {
  18. }
  19. /* Test functions */
  20. /** Call pbuf_copy on a pbuf with zero length */
  21. START_TEST(test_pbuf_copy_zero_pbuf)
  22. {
  23. struct pbuf *p1, *p2, *p3;
  24. err_t err;
  25. LWIP_UNUSED_ARG(_i);
  26. fail_unless(lwip_stats.mem.used == 0);
  27. fail_unless(lwip_stats.memp[MEMP_PBUF_POOL].used == 0);
  28. p1 = pbuf_alloc(PBUF_RAW, 1024, PBUF_RAM);
  29. fail_unless(p1 != NULL);
  30. fail_unless(p1->ref == 1);
  31. p2 = pbuf_alloc(PBUF_RAW, 2, PBUF_POOL);
  32. fail_unless(p2 != NULL);
  33. fail_unless(p2->ref == 1);
  34. p2->len = p2->tot_len = 0;
  35. pbuf_cat(p1, p2);
  36. fail_unless(p1->ref == 1);
  37. fail_unless(p2->ref == 1);
  38. p3 = pbuf_alloc(PBUF_RAW, p1->tot_len, PBUF_POOL);
  39. err = pbuf_copy(p3, p1);
  40. fail_unless(err == ERR_VAL);
  41. pbuf_free(p1);
  42. pbuf_free(p3);
  43. fail_unless(lwip_stats.mem.used == 0);
  44. fail_unless(lwip_stats.mem.used == 0);
  45. fail_unless(lwip_stats.memp[MEMP_PBUF_POOL].used == 0);
  46. }
  47. END_TEST
  48. /** Create the suite including all tests for this module */
  49. Suite *
  50. pbuf_suite(void)
  51. {
  52. TFun tests[] = {
  53. test_pbuf_copy_zero_pbuf
  54. };
  55. return create_suite("PBUF", tests, sizeof(tests)/sizeof(TFun), pbuf_setup, pbuf_teardown);
  56. }