فهرست منبع

esp_event: revert changes in !5702

Renz Christian Bagaporo 6 سال پیش
والد
کامیت
f356d54365

+ 1 - 6
components/esp_event/test/CMakeLists.txt

@@ -1,8 +1,3 @@
-set(srcdirs .)
-if(IDF_TARGET STREQUAL "esp32")
-    list(APPEND srcdirs "esp32")
-endif()
-
-idf_component_register(SRC_DIRS ${srcdirs}
+idf_component_register(SRC_DIRS "."
                        PRIV_INCLUDE_DIRS . ../private_include
                        PRIV_REQUIRES unity test_utils esp_event driver)

+ 0 - 1
components/esp_event/test/component.mk

@@ -2,6 +2,5 @@
 #Component Makefile
 #
 
-COMPONENT_SRCDIRS += esp32
 COMPONENT_PRIV_INCLUDEDIRS := ../private_include .
 COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive

+ 61 - 49
components/esp_event/test/esp32/test_event.c → components/esp_event/test/test_event.c

@@ -5,7 +5,6 @@
 #include "sdkconfig.h"
 
 #include "freertos/FreeRTOS.h"
-#include "esp_event.h"
 #include "freertos/task.h"
 #include "freertos/portmacro.h"
 #include "esp_log.h"
@@ -289,6 +288,38 @@ static void test_teardown(void)
 #define TIMER_SCALE           (TIMER_BASE_CLK / TIMER_DIVIDER)  // convert counter value to seconds
 #define TIMER_INTERVAL0_SEC   (2.0) // sample test interval for the first timer
 
+#if CONFIG_ESP_EVENT_POST_FROM_ISR
+static void test_handler_post_from_isr(void* event_handler_arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
+{
+    SemaphoreHandle_t *sem = (SemaphoreHandle_t*) event_handler_arg;
+    // Event data is just the address value (maybe have been truncated due to casting).
+    int *data = (int*) event_data;
+    TEST_ASSERT_EQUAL(*data, (int) (*sem));
+    xSemaphoreGive(*sem);
+}
+
+void IRAM_ATTR test_event_on_timer_alarm(void* para)
+{
+    /* Retrieve the interrupt status and the counter value
+       from the timer that reported the interrupt */
+    uint64_t timer_counter_value =
+        timer_group_get_counter_value_in_isr(TIMER_GROUP_0, TIMER_0);
+    timer_group_intr_clr_in_isr(TIMER_GROUP_0, TIMER_0);
+    timer_counter_value += (uint64_t) (TIMER_INTERVAL0_SEC * TIMER_SCALE);
+    timer_group_set_alarm_value_in_isr(TIMER_GROUP_0, TIMER_0, timer_counter_value);
+
+    int data = (int) para;
+    // Posting events with data more than 4 bytes should fail.
+    TEST_ASSERT_EQUAL(ESP_ERR_INVALID_ARG, esp_event_isr_post(s_test_base1, TEST_EVENT_BASE1_EV1, &data, 5, NULL));
+    // This should succeedd, as data is int-sized. The handler for the event checks that the passed event data
+    // is correct.
+    BaseType_t task_unblocked;
+    TEST_ASSERT_EQUAL(ESP_OK, esp_event_isr_post(s_test_base1, TEST_EVENT_BASE1_EV1, &data, sizeof(data), &task_unblocked));
+    if (task_unblocked == pdTRUE) {
+        portYIELD_FROM_ISR();
+    }
+}
+#endif //CONFIG_ESP_EVENT_POST_FROM_ISR
 
 TEST_CASE("can create and delete event loops", "[event]")
 {
@@ -904,7 +935,7 @@ TEST_CASE("performance test - dedicated task", "[event]")
     performance_test(true);
 }
 
-TEST_CASE_ESP32("performance test - no dedicated task", "[event]")
+TEST_CASE("performance test - no dedicated task", "[event]")
 {
     performance_test(false);
 }
@@ -1216,58 +1247,39 @@ TEST_CASE("can properly prepare event data posted to loop", "[event]")
     TEST_TEARDOWN();
 }
 
-#endif // CONFIG_ESP_EVENT_POST_FROM_ISR
-
-#ifdef CONFIG_ESP_EVENT_LOOP_PROFILING
-TEST_CASE("can dump event loop profile", "[event]")
+TEST_CASE("can post events from interrupt handler", "[event]")
 {
-    /* this test aims to verify that dumping event loop statistics succeed */
+    SemaphoreHandle_t sem = xSemaphoreCreateBinary();
+
+    /* Select and initialize basic parameters of the timer */
+    timer_config_t config;
+    config.divider = TIMER_DIVIDER;
+    config.counter_dir = TIMER_COUNT_UP;
+    config.counter_en = TIMER_PAUSE;
+    config.alarm_en = TIMER_ALARM_EN;
+    config.intr_type = TIMER_INTR_LEVEL;
+    config.auto_reload = false;
+    timer_init(TIMER_GROUP_0, TIMER_0, &config);
+
+    /* Timer's counter will initially start from value below.
+       Also, if auto_reload is set, this value will be automatically reload on alarm */
+    timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0x00000000ULL);
+
+    /* Configure the alarm value and the interrupt on alarm. */
+    timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, TIMER_INTERVAL0_SEC * TIMER_SCALE);
+    timer_enable_intr(TIMER_GROUP_0, TIMER_0);
+    timer_isr_register(TIMER_GROUP_0, TIMER_0, test_event_on_timer_alarm,
+        (void *) sem, ESP_INTR_FLAG_IRAM, NULL);
+
+    timer_start(TIMER_GROUP_0, TIMER_0);
 
     TEST_SETUP();
 
-    esp_event_loop_handle_t loop;
-
-    esp_event_loop_args_t loop_args = test_event_get_default_loop_args();
-
-    loop_args.task_name = NULL;
-    loop_args.queue_size = 5;
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_loop_create(&loop_args, &loop));
-
-    int count = 0;
-
-    simple_arg_t arg = {
-        .data = &count,
-        .mutex = xSemaphoreCreateMutex()
-    };
-
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, ESP_EVENT_ANY_BASE, ESP_EVENT_ANY_ID, test_event_simple_handler, &arg));
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base1, ESP_EVENT_ANY_ID, test_event_simple_handler, &arg));
-
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base1, TEST_EVENT_BASE1_EV1, test_event_simple_handler, &arg));
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base1, TEST_EVENT_BASE1_EV2, test_event_simple_handler, &arg));
-
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base2, TEST_EVENT_BASE1_EV1, test_event_simple_handler, &arg));
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register_with(loop, s_test_base2, TEST_EVENT_BASE1_EV2, test_event_simple_handler, &arg));
+    TEST_ASSERT_EQUAL(ESP_OK, esp_event_handler_register(s_test_base1, TEST_EVENT_BASE1_EV1,
+                                                        test_handler_post_from_isr, &sem));
 
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_post_to(loop, s_test_base1, TEST_EVENT_BASE1_EV1, NULL, 0, 1));
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_post_to(loop, s_test_base2, TEST_EVENT_BASE1_EV1, NULL, 0, 1));
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_post_to(loop, s_test_base1, TEST_EVENT_BASE1_EV2, NULL, 0, 1));
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_post_to(loop, s_test_base2, TEST_EVENT_BASE1_EV2, NULL, 0, 1));
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_post_to(loop, s_test_base1, TEST_EVENT_BASE1_EV1, NULL, 0, 1));
-    TEST_ASSERT_EQUAL(ESP_ERR_TIMEOUT, esp_event_post_to(loop, s_test_base2, TEST_EVENT_BASE1_EV1, NULL, 0, 1));
-
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_loop_run(loop, pdMS_TO_TICKS(10)));
-
-    // 5 invocations of loop-levlel handlers + 3 invocation of base-level handlers (s_test_base1) +
-    // 5 invocations of respective event-level handlers
-    TEST_ASSERT_EQUAL(13, count);
-
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_dump(stdout));
-
-    TEST_ASSERT_EQUAL(ESP_OK, esp_event_loop_delete(loop));
-
-    vSemaphoreDelete(arg.mutex);
+    xSemaphoreTake(sem, portMAX_DELAY);
 
     TEST_TEARDOWN();
 }
-#endif // CONFIG_ESP_EVENT_LOOP_PROFILING
+#endif // CONFIG_ESP_EVENT_POST_FROM_ISR

+ 1 - 2
examples/system/esp_event/default_event_loop/example_test.py

@@ -4,7 +4,6 @@ import sys
 
 try:
     import IDF
-    from IDF.IDFDUT import ESP32DUT
 except ImportError:
     # this is a test case write with tiny-test-fw.
     # to run test cases outside tiny-test-fw,
@@ -94,7 +93,7 @@ def _test_iteration_events(dut):
 
 @IDF.idf_example_test(env_tag='Example_WIFI')
 def test_default_event_loop_example(env, extra_data):
-    dut = env.get_dut('default_event_loop', 'examples/system/esp_event/default_event_loop', dut_class=ESP32DUT)
+    dut = env.get_dut('default_event_loop', 'examples/system/esp_event/default_event_loop')
 
     _test_iteration_events(dut)
     _test_timer_events(dut)

+ 1 - 2
examples/system/esp_event/user_event_loops/example_test.py

@@ -4,7 +4,6 @@ import sys
 
 try:
     import IDF
-    from IDF.IDFDUT import ESP32DUT
 except ImportError:
     # this is a test case write with tiny-test-fw.
     # to run test cases outside tiny-test-fw,
@@ -23,7 +22,7 @@ TASK_ITERATION_HANDLING = "handling TASK_EVENTS:TASK_ITERATION_EVENT from {}, it
 
 @IDF.idf_example_test(env_tag='Example_WIFI')
 def test_user_event_loops_example(env, extra_data):
-    dut = env.get_dut('user_event_loops', 'examples/system/esp_event/user_event_loops', dut_class=ESP32DUT)
+    dut = env.get_dut('user_event_loops', 'examples/system/esp_event/user_event_loops')
 
     dut.start_app()