test_leak.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Tests for a leak tag
  3. */
  4. #include <stdio.h>
  5. #include "unity.h"
  6. #include "esp_heap_caps_init.h"
  7. #include "esp_system.h"
  8. #include <stdlib.h>
  9. static char* check_calloc(int size)
  10. {
  11. char *arr = calloc(size, sizeof(char));
  12. TEST_ASSERT_NOT_NULL(arr);
  13. return arr;
  14. }
  15. TEST_CASE("Check for leaks (no leak)", "[heap]")
  16. {
  17. char *arr = check_calloc(1000);
  18. free(arr);
  19. }
  20. TEST_CASE("Check for leaks (leak)", "[heap][ignore]")
  21. {
  22. check_calloc(1000);
  23. }
  24. TEST_CASE("Not check for leaks", "[heap][leaks]")
  25. {
  26. check_calloc(1000);
  27. }
  28. TEST_CASE("Set a leak level = 7016", "[heap][leaks=7016]")
  29. {
  30. check_calloc(7000);
  31. }
  32. static void test_fn(void)
  33. {
  34. check_calloc(1000);
  35. }
  36. TEST_CASE_MULTIPLE_STAGES("Not check for leaks in MULTIPLE_STAGES mode", "[heap][leaks]", test_fn, test_fn, test_fn);
  37. TEST_CASE_MULTIPLE_STAGES("Check for leaks in MULTIPLE_STAGES mode (leak)", "[heap][ignore]", test_fn, test_fn, test_fn);
  38. static void test_fn2(void)
  39. {
  40. check_calloc(1000);
  41. esp_restart();
  42. }
  43. static void test_fn3(void)
  44. {
  45. check_calloc(1000);
  46. }
  47. TEST_CASE_MULTIPLE_STAGES("Check for leaks in MULTIPLE_STAGES mode (manual reset)", "[heap][leaks][reset=SW_CPU_RESET, SW_CPU_RESET]", test_fn2, test_fn2, test_fn3);