|
8 | 8 | #include <sys/param.h> |
9 | 9 | #include <string.h> |
10 | 10 | #include "inttypes.h" |
| 11 | +#include "freertos/FreeRTOS.h" |
| 12 | +#include "freertos/task.h" |
| 13 | +#include "freertos/semphr.h" |
11 | 14 | #include "esp_log.h" |
12 | 15 | #include "esp_attr.h" |
13 | 16 | #include "unity.h" |
@@ -71,6 +74,59 @@ TEST_CASE("Can find paddr caps by any paddr offset", "[mmu]") |
71 | 74 | TEST_ESP_OK(esp_mmu_unmap(ptr0)); |
72 | 75 | } |
73 | 76 |
|
| 77 | +typedef struct { |
| 78 | + SemaphoreHandle_t done; |
| 79 | +} test_task_arg_t; |
| 80 | + |
| 81 | +void map_task(void *varg) |
| 82 | +{ |
| 83 | + esp_err_t ret = ESP_FAIL; |
| 84 | + test_task_arg_t* args = (test_task_arg_t*) varg; |
| 85 | + |
| 86 | + const esp_partition_t *part = s_get_partition(); |
| 87 | + srand(199); |
| 88 | + int cnt = 0; |
| 89 | + while (true) { |
| 90 | + if (cnt >= 10000) { |
| 91 | + break; |
| 92 | + } |
| 93 | + size_t i = rand() % part->size; |
| 94 | + void *ptr0 = NULL; |
| 95 | + size_t phys_addr = part->address + i; |
| 96 | + size_t region_offset = phys_addr & (CONFIG_MMU_PAGE_SIZE - 1); |
| 97 | + size_t mmap_addr = phys_addr & ~(CONFIG_MMU_PAGE_SIZE - 1); |
| 98 | + ret = esp_mmu_map(mmap_addr, 1 + region_offset, MMU_TARGET_FLASH0, MMU_MEM_CAP_READ | MMU_MEM_CAP_8BIT, ESP_MMU_MMAP_FLAG_PADDR_SHARED, &ptr0); |
| 99 | + if (ret == ESP_OK) { |
| 100 | + esp_mmu_unmap(ptr0); |
| 101 | + } |
| 102 | + cnt++; |
| 103 | + vTaskDelay(pdMS_TO_TICKS(1)); |
| 104 | + } |
| 105 | + |
| 106 | + xSemaphoreGive(args->done); |
| 107 | + vTaskDelete(NULL); |
| 108 | +} |
| 109 | + |
| 110 | +TEST_CASE("Test mmap concurrency", "[mmu][manual][ignore]") |
| 111 | +{ |
| 112 | + test_task_arg_t args0 = { |
| 113 | + .done = xSemaphoreCreateBinary(), |
| 114 | + }; |
| 115 | + |
| 116 | + test_task_arg_t args1 = { |
| 117 | + .done = xSemaphoreCreateBinary(), |
| 118 | + }; |
| 119 | + |
| 120 | + xTaskCreate(map_task, "map0_task", 8096, &args0, 1, NULL); |
| 121 | + xTaskCreate(map_task, "map1_task", 8096, &args1, 1, NULL); |
| 122 | + |
| 123 | + xSemaphoreTake(args0.done, portMAX_DELAY); |
| 124 | + xSemaphoreTake(args1.done, portMAX_DELAY); |
| 125 | + vTaskDelay(100); |
| 126 | + vSemaphoreDelete(args0.done); |
| 127 | + vSemaphoreDelete(args1.done); |
| 128 | +} |
| 129 | + |
74 | 130 | #if CONFIG_SPIRAM |
75 | 131 | #if !CONFIG_IDF_TARGET_ESP32 //ESP32 doesn't support using `esp_mmu_map` to map to PSRAM |
76 | 132 | TEST_CASE("Can find paddr when mapping to psram", "[mmu]") |
|
0 commit comments