heap: fix random alloc test timing out in CI
#include "unity.h"
#include "esp_attr.h"
#include "esp_heap_caps.h"
+#include "esp_log.h"
#include <stdlib.h>
#include <sys/param.h>
#include <string.h>
#if !defined(CONFIG_HEAP_POISONING_COMPREHENSIVE) && !defined(CONFIG_HEAP_POISONING_LIGHT)
#define NUM_POINTERS 128
-#define ITERATIONS 10000
+#define ITERATIONS 5000
+
+static const char *TAG = "test_heap";
TEST_CASE("Heap many random allocations timings", "[heap]")
{
@@ -32,7 +35,7 @@ TEST_CASE("Heap many random allocations timings", "[heap]")
for (int i = 0; i < ITERATIONS; i++) {
uint8_t n = (uint32_t)rand() % NUM_POINTERS;
- if (ITERATIONS % 4 == 0) {
+ if (i % 4 == 0) {
/* 1 in 4 iterations, try to realloc the buffer instead
of using malloc/free
*/
@@ -42,7 +45,7 @@ TEST_CASE("Heap many random allocations timings", "[heap]")
void *new_p = heap_caps_realloc(p[n], new_size, MALLOC_CAP_DEFAULT);
realloc_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
- printf("realloc %p -> %p (%zu -> %zu) time spent cycles: %lld \n", p[n], new_p, s[n], new_size, realloc_time_average);
+ ESP_LOGD(TAG, "realloc %p -> %p (%zu -> %zu) time spent cycles: %lld \n", p[n], new_p, s[n], new_size, realloc_time_average);
heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true);
if (new_size == 0 || new_p != NULL) {
p[n] = new_p;
@@ -67,7 +70,7 @@ TEST_CASE("Heap many random allocations timings", "[heap]")
heap_caps_free(p[n]);
free_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
- printf("freed %p (%zu) time spent cycles: %lld\n", p[n], s[n], free_time_average);
+ ESP_LOGD(TAG, "freed %p (%zu) time spent cycles: %lld\n", p[n], s[n], free_time_average);
if (!heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true)) {
printf("FAILED iteration %d after freeing %p\n", i, p[n]);
@@ -82,7 +85,7 @@ TEST_CASE("Heap many random allocations timings", "[heap]")
p[n] = heap_caps_malloc(s[n], MALLOC_CAP_DEFAULT);
alloc_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
- printf("malloc %p (%zu) time spent cycles: %lld \n", p[n], s[n], alloc_time_average);
+ ESP_LOGD(TAG, "malloc %p (%zu) time spent cycles: %lld \n", p[n], s[n], alloc_time_average);
if (!heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true)) {
printf("FAILED iteration %d after mallocing %p (%zu bytes)\n", i, p[n], s[n]);
