From cc67500d3e9802cd78e278c435200e9a0717f374 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 18 Sep 2017 14:49:23 +0800 Subject: [PATCH] unit test: adapt tests to single core configuration --- components/esp32/test/test_delay.c | 4 ++++ components/esp32/test/test_fp.c | 2 +- components/fatfs/test/test_fatfs_common.c | 14 ++++++++------ .../freertos/test/test_freertos_isinisrcontext.c | 2 ++ components/freertos/test/test_newlib_reent.c | 2 +- components/freertos/test/test_preemption.c | 2 ++ components/freertos/test/test_spinlocks.c | 3 +++ components/newlib/test/test_time.c | 3 +++ components/spi_flash/test/test_spi_flash.c | 2 +- components/spiffs/test/test_spiffs.c | 15 ++++++++------- components/wear_levelling/test/test_wl.c | 14 ++++++++------ 11 files changed, 41 insertions(+), 22 deletions(-) diff --git a/components/esp32/test/test_delay.c b/components/esp32/test/test_delay.c index 7cecc0de75..b32299ec85 100644 --- a/components/esp32/test/test_delay.c +++ b/components/esp32/test/test_delay.c @@ -51,9 +51,11 @@ TEST_CASE("ets_delay produces correct delay on both CPUs", "[delay]") TEST_ASSERT( xSemaphoreTake(args.done, delay_ms * 2 / portTICK_PERIOD_MS) ); TEST_ASSERT_INT32_WITHIN(1000, args.delay_us, args.result); +#if portNUM_PROCESSORS == 2 xTaskCreatePinnedToCore(test_delay_task, "", 2048, (void*) &args, 3, NULL, 1); TEST_ASSERT( xSemaphoreTake(args.done, delay_ms * 2 / portTICK_PERIOD_MS) ); TEST_ASSERT_INT32_WITHIN(1000, args.delay_us, args.result); +#endif ref_clock_deinit(); vSemaphoreDelete(args.done); @@ -72,9 +74,11 @@ TEST_CASE("vTaskDelay produces correct delay on both CPUs", "[delay]") TEST_ASSERT( xSemaphoreTake(args.done, delay_ms * 2 / portTICK_PERIOD_MS) ); TEST_ASSERT_INT32_WITHIN(1000, args.delay_us, args.result); +#if portNUM_PROCESSORS == 2 xTaskCreatePinnedToCore(test_delay_task, "", 2048, (void*) &args, 3, NULL, 1); TEST_ASSERT( xSemaphoreTake(args.done, delay_ms * 2 / portTICK_PERIOD_MS) ); TEST_ASSERT_INT32_WITHIN(1000, args.delay_us, args.result); +#endif ref_clock_deinit(); vSemaphoreDelete(args.done); diff --git a/components/esp32/test/test_fp.c b/components/esp32/test/test_fp.c index 1b88e9722c..180999f9bc 100644 --- a/components/esp32/test/test_fp.c +++ b/components/esp32/test/test_fp.c @@ -180,7 +180,7 @@ TEST_CASE("context switch saves FP registers", "[fp]") state.fail = 0; xTaskCreatePinnedToCore(tskTestFP, "tsk1", 2048, &state, 3, NULL, 0); xTaskCreatePinnedToCore(tskTestFP, "tsk2", 2048, &state, 3, NULL, 0); - xTaskCreatePinnedToCore(tskTestFP, "tsk3", 2048, &state, 3, NULL, 1); + xTaskCreatePinnedToCore(tskTestFP, "tsk3", 2048, &state, 3, NULL, portNUM_PROCESSORS - 1); xTaskCreatePinnedToCore(tskTestFP, "tsk4", 2048, &state, 3, NULL, 0); while (state.done != 4) { vTaskDelay(100 / portTICK_PERIOD_MS); diff --git a/components/fatfs/test/test_fatfs_common.c b/components/fatfs/test/test_fatfs_common.c index a2f35c3db7..ca27cdd4ba 100644 --- a/components/fatfs/test/test_fatfs_common.c +++ b/components/fatfs/test/test_fatfs_common.c @@ -404,8 +404,10 @@ void test_fatfs_concurrent(const char* filename_prefix) printf("writing f1 and f2\n"); - xTaskCreatePinnedToCore(&read_write_task, "rw1", 2048, &args1, 3, NULL, 0); - xTaskCreatePinnedToCore(&read_write_task, "rw2", 2048, &args2, 3, NULL, 1); + const int cpuid_0 = 0; + const int cpuid_1 = portNUM_PROCESSORS - 1; + xTaskCreatePinnedToCore(&read_write_task, "rw1", 2048, &args1, 3, NULL, cpuid_0); + xTaskCreatePinnedToCore(&read_write_task, "rw2", 2048, &args2, 3, NULL, cpuid_1); xSemaphoreTake(args1.done, portMAX_DELAY); printf("f1 done\n"); @@ -421,10 +423,10 @@ void test_fatfs_concurrent(const char* filename_prefix) printf("reading f1 and f2, writing f3 and f4\n"); - xTaskCreatePinnedToCore(&read_write_task, "rw3", 2048, &args3, 3, NULL, 1); - xTaskCreatePinnedToCore(&read_write_task, "rw4", 2048, &args4, 3, NULL, 0); - xTaskCreatePinnedToCore(&read_write_task, "rw1", 2048, &args1, 3, NULL, 0); - xTaskCreatePinnedToCore(&read_write_task, "rw2", 2048, &args2, 3, NULL, 1); + xTaskCreatePinnedToCore(&read_write_task, "rw3", 2048, &args3, 3, NULL, cpuid_1); + xTaskCreatePinnedToCore(&read_write_task, "rw4", 2048, &args4, 3, NULL, cpuid_0); + xTaskCreatePinnedToCore(&read_write_task, "rw1", 2048, &args1, 3, NULL, cpuid_0); + xTaskCreatePinnedToCore(&read_write_task, "rw2", 2048, &args2, 3, NULL, cpuid_1); xSemaphoreTake(args1.done, portMAX_DELAY); printf("f1 done\n"); diff --git a/components/freertos/test/test_freertos_isinisrcontext.c b/components/freertos/test/test_freertos_isinisrcontext.c index a163688ccd..085e60ddb0 100644 --- a/components/freertos/test/test_freertos_isinisrcontext.c +++ b/components/freertos/test/test_freertos_isinisrcontext.c @@ -46,7 +46,9 @@ TEST_CASE("xPortInIsrContext test", "[freertos]") { xTaskCreatePinnedToCore(testthread, "tst" , 4096, NULL, 3, NULL, 0); vTaskDelay(150 / portTICK_PERIOD_MS); +#if portNUM_PROCESSORS == 2 xTaskCreatePinnedToCore(testthread, "tst" , 4096, NULL, 3, NULL, 1); vTaskDelay(150 / portTICK_PERIOD_MS); +#endif } diff --git a/components/freertos/test/test_newlib_reent.c b/components/freertos/test/test_newlib_reent.c index e0ec4aa458..17346a6979 100644 --- a/components/freertos/test/test_newlib_reent.c +++ b/components/freertos/test/test_newlib_reent.c @@ -50,7 +50,7 @@ TEST_CASE("Test for per-task non-reentrant tasks", "[freertos]") error = 0; xTaskCreatePinnedToCore(tskTestRand, "tsk1", 2048, (void *)100, 3, NULL, 0); xTaskCreatePinnedToCore(tskTestRand, "tsk2", 2048, (void *)200, 3, NULL, 0); - xTaskCreatePinnedToCore(tskTestRand, "tsk3", 2048, (void *)300, 3, NULL, 1); + xTaskCreatePinnedToCore(tskTestRand, "tsk3", 2048, (void *)300, 3, NULL, portNUM_PROCESSORS - 1); xTaskCreatePinnedToCore(tskTestRand, "tsk4", 2048, (void *)400, 3, NULL, 0); while (done != 4) { vTaskDelay(1000 / portTICK_PERIOD_MS); diff --git a/components/freertos/test/test_preemption.c b/components/freertos/test/test_preemption.c index 83ab49bf43..62625600c4 100644 --- a/components/freertos/test/test_preemption.c +++ b/components/freertos/test/test_preemption.c @@ -72,6 +72,7 @@ TEST_CASE("Yield from lower priority task, same CPU", "[freertos]") } +#if portNUM_PROCESSORS == 2 TEST_CASE("Yield from lower priority task, other CPU", "[freertos]") { uint32_t trigger_ccount, yield_ccount, now_ccount, delta; @@ -106,3 +107,4 @@ TEST_CASE("Yield from lower priority task, other CPU", "[freertos]") vTaskDelete(sender_task); } } +#endif // portNUM_PROCESSORS == 2 diff --git a/components/freertos/test/test_spinlocks.c b/components/freertos/test/test_spinlocks.c index 2ddbb07f85..68880ce936 100644 --- a/components/freertos/test/test_spinlocks.c +++ b/components/freertos/test/test_spinlocks.c @@ -62,6 +62,8 @@ TEST_CASE("portMUX recursive locks (no contention)", "[freertos]") BENCHMARK_END("no contention recursive"); } +#if portNUM_PROCESSORS == 2 + static volatile int shared_value; static portMUX_TYPE shared_mux; static xSemaphoreHandle done_sem; @@ -130,4 +132,5 @@ TEST_CASE("portMUX high contention", "[freertos]") TEST_ASSERT_EQUAL_INT(REPEAT_OPS * TOTAL_TASKS, shared_value); } +#endif // portNUM_PROCESSORS == 2 diff --git a/components/newlib/test/test_time.c b/components/newlib/test/test_time.c index a230a220bc..8cf9bc6c39 100644 --- a/components/newlib/test/test_time.c +++ b/components/newlib/test/test_time.c @@ -11,6 +11,8 @@ #include "sdkconfig.h" +#if portNUM_PROCESSORS == 2 + // https://github.com/espressif/arduino-esp32/issues/120 TEST_CASE("Reading RTC registers on APP CPU doesn't affect clock", "[newlib]") { @@ -48,3 +50,4 @@ TEST_CASE("Reading RTC registers on APP CPU doesn't affect clock", "[newlib]") TEST_ASSERT_TRUE(xSemaphoreTake(done, 5000 / portTICK_RATE_MS)); } +#endif // portNUM_PROCESSORS == 2 diff --git a/components/spi_flash/test/test_spi_flash.c b/components/spi_flash/test/test_spi_flash.c index f3bd3dc104..e47cdf840c 100644 --- a/components/spi_flash/test/test_spi_flash.c +++ b/components/spi_flash/test/test_spi_flash.c @@ -157,7 +157,7 @@ TEST_CASE("spi flash functions can run along with IRAM interrupts", "[spi_flash] timer_enable_intr(TIMER_GROUP_0, TIMER_0); timer_start(TIMER_GROUP_0, TIMER_0); - xTaskCreatePinnedToCore(read_task, "r", 2048, &read_arg, 3, NULL, 1); + xTaskCreatePinnedToCore(read_task, "r", 2048, &read_arg, 3, NULL, portNUM_PROCESSORS - 1); xSemaphoreTake(read_arg.done, portMAX_DELAY); timer_pause(TIMER_GROUP_0, TIMER_0); diff --git a/components/spiffs/test/test_spiffs.c b/components/spiffs/test/test_spiffs.c index d60e4a54c4..daf11ddc94 100644 --- a/components/spiffs/test/test_spiffs.c +++ b/components/spiffs/test/test_spiffs.c @@ -346,9 +346,10 @@ void test_spiffs_concurrent(const char* filename_prefix) read_write_test_arg_t args2 = READ_WRITE_TEST_ARG_INIT(names[1], 2); printf("writing f1 and f2\n"); - - xTaskCreatePinnedToCore(&read_write_task, "rw1", 2048, &args1, 3, NULL, 0); - xTaskCreatePinnedToCore(&read_write_task, "rw2", 2048, &args2, 3, NULL, 1); + const int cpuid_0 = 0; + const int cpuid_1 = portNUM_PROCESSORS - 1; + xTaskCreatePinnedToCore(&read_write_task, "rw1", 2048, &args1, 3, NULL, cpuid_0); + xTaskCreatePinnedToCore(&read_write_task, "rw2", 2048, &args2, 3, NULL, cpuid_1); xSemaphoreTake(args1.done, portMAX_DELAY); printf("f1 done\n"); @@ -364,10 +365,10 @@ void test_spiffs_concurrent(const char* filename_prefix) printf("reading f1 and f2, writing f3 and f4\n"); - xTaskCreatePinnedToCore(&read_write_task, "rw3", 2048, &args3, 3, NULL, 1); - xTaskCreatePinnedToCore(&read_write_task, "rw4", 2048, &args4, 3, NULL, 0); - xTaskCreatePinnedToCore(&read_write_task, "rw1", 2048, &args1, 3, NULL, 0); - xTaskCreatePinnedToCore(&read_write_task, "rw2", 2048, &args2, 3, NULL, 1); + xTaskCreatePinnedToCore(&read_write_task, "rw3", 2048, &args3, 3, NULL, cpuid_1); + xTaskCreatePinnedToCore(&read_write_task, "rw4", 2048, &args4, 3, NULL, cpuid_0); + xTaskCreatePinnedToCore(&read_write_task, "rw1", 2048, &args1, 3, NULL, cpuid_0); + xTaskCreatePinnedToCore(&read_write_task, "rw2", 2048, &args2, 3, NULL, cpuid_1); xSemaphoreTake(args1.done, portMAX_DELAY); printf("f1 done\n"); diff --git a/components/wear_levelling/test/test_wl.c b/components/wear_levelling/test/test_wl.c index c7d29bb1ae..8aa3e6f439 100644 --- a/components/wear_levelling/test/test_wl.c +++ b/components/wear_levelling/test/test_wl.c @@ -109,8 +109,10 @@ TEST_CASE("multiple tasks can access wl handle simultaneously", "[wear_levelling const size_t stack_size = 4096; printf("writing 1 and 2\n"); - xTaskCreatePinnedToCore(&read_write_task, "rw1", stack_size, &args1, 3, NULL, 0); - xTaskCreatePinnedToCore(&read_write_task, "rw2", stack_size, &args2, 3, NULL, 1); + const int cpuid_0 = 0; + const int cpuid_1 = portNUM_PROCESSORS - 1; + xTaskCreatePinnedToCore(&read_write_task, "rw1", stack_size, &args1, 3, NULL, cpuid_0); + xTaskCreatePinnedToCore(&read_write_task, "rw2", stack_size, &args2, 3, NULL, cpuid_1); xSemaphoreTake(args1.done, portMAX_DELAY); printf("f1 done\n"); @@ -125,10 +127,10 @@ TEST_CASE("multiple tasks can access wl handle simultaneously", "[wear_levelling read_write_test_arg_t args4 = READ_WRITE_TEST_ARG_INIT(3 * sector_size, 4, handle, sector_size/sizeof(uint32_t)); printf("reading 1 and 2, writing 3 and 4\n"); - xTaskCreatePinnedToCore(&read_write_task, "rw3", stack_size, &args3, 3, NULL, 1); - xTaskCreatePinnedToCore(&read_write_task, "rw4", stack_size, &args4, 3, NULL, 0); - xTaskCreatePinnedToCore(&read_write_task, "rw1", stack_size, &args1, 3, NULL, 0); - xTaskCreatePinnedToCore(&read_write_task, "rw2", stack_size, &args2, 3, NULL, 1); + xTaskCreatePinnedToCore(&read_write_task, "rw3", stack_size, &args3, 3, NULL, cpuid_1); + xTaskCreatePinnedToCore(&read_write_task, "rw4", stack_size, &args4, 3, NULL, cpuid_0); + xTaskCreatePinnedToCore(&read_write_task, "rw1", stack_size, &args1, 3, NULL, cpuid_0); + xTaskCreatePinnedToCore(&read_write_task, "rw2", stack_size, &args2, 3, NULL, cpuid_1); xSemaphoreTake(args1.done, portMAX_DELAY); printf("f1 done\n");