2022-06-17 14:45:52 +08:00
|
|
|
#include "test_common.h"
|
2022-10-28 18:39:50 +08:00
|
|
|
TEST_START
|
2022-06-17 14:45:52 +08:00
|
|
|
|
|
|
|
extern PikaEventListener* g_pika_device_event_listener;
|
2022-07-01 23:10:51 +08:00
|
|
|
#if PIKA_EVENT_ENABLE
|
2022-06-17 14:45:52 +08:00
|
|
|
TEST(event, gpio) {
|
|
|
|
/* init */
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
/* run */
|
2022-12-23 18:19:16 +08:00
|
|
|
pikaVM_runSingleFile(pikaMain, "test/python/TemplateDevice/gpio_cb.py");
|
2022-06-17 14:45:52 +08:00
|
|
|
|
2022-06-21 03:29:29 +00:00
|
|
|
#define EVENT_SIGAL_IO_RISING_EDGE 0x01
|
|
|
|
#define EVENT_SIGAL_IO_FALLING_EDGE 0x02
|
|
|
|
#define GPIO_PA8_EVENT_ID 0x08
|
2022-06-17 14:45:52 +08:00
|
|
|
|
|
|
|
/* simulate run in the call back */
|
2022-12-28 06:41:36 +08:00
|
|
|
pks_eventListener_sendSignal(g_pika_device_event_listener,
|
|
|
|
GPIO_PA8_EVENT_ID, EVENT_SIGAL_IO_RISING_EDGE);
|
|
|
|
pks_eventListener_sendSignal(g_pika_device_event_listener,
|
|
|
|
GPIO_PA8_EVENT_ID,
|
|
|
|
EVENT_SIGAL_IO_FALLING_EDGE);
|
2022-06-17 14:45:52 +08:00
|
|
|
/* assert */
|
2022-11-02 12:25:02 +08:00
|
|
|
|
|
|
|
obj_run(pikaMain, "io1.eventTest()");
|
|
|
|
|
2022-11-05 12:34:18 +08:00
|
|
|
EXPECT_STREQ(log_buff[3], "get rising edge!\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[2], "get falling edge!\r\n");
|
|
|
|
EXPECT_STREQ(log_buff[1], "get rising edge!\r\n");
|
2022-06-17 14:45:52 +08:00
|
|
|
EXPECT_STREQ(log_buff[0], "get falling edge!\r\n");
|
2022-11-02 12:25:02 +08:00
|
|
|
|
2022-11-05 12:34:18 +08:00
|
|
|
for (int i = 0; i < 255; i++) {
|
|
|
|
obj_run(pikaMain, "io1.eventTest()");
|
|
|
|
}
|
|
|
|
|
2022-11-05 13:20:23 +08:00
|
|
|
/* simulate run in the call back */
|
2022-12-18 19:22:43 +08:00
|
|
|
Arg* res_123 = pks_eventListener_sendSignalAwaitResult(
|
2022-11-05 13:20:23 +08:00
|
|
|
g_pika_device_event_listener, GPIO_PA8_EVENT_ID, 123);
|
2022-12-18 19:22:43 +08:00
|
|
|
Arg* res_456 = pks_eventListener_sendSignalAwaitResult(
|
2022-11-05 13:20:23 +08:00
|
|
|
g_pika_device_event_listener, GPIO_PA8_EVENT_ID, 456);
|
2022-12-28 06:41:36 +08:00
|
|
|
|
2022-11-05 13:20:23 +08:00
|
|
|
EXPECT_EQ(arg_getInt(res_123), 123);
|
|
|
|
EXPECT_EQ(arg_getInt(res_456), 456);
|
|
|
|
|
2022-12-28 23:39:18 +08:00
|
|
|
/* simulate task queue overflow */
|
|
|
|
for (int i = 0; i < PIKA_EVENT_LIST_SIZE * 2; i++) {
|
|
|
|
_do_pks_eventListener_send(
|
|
|
|
g_pika_device_event_listener, GPIO_PA8_EVENT_ID,
|
|
|
|
arg_newInt(EVENT_SIGAL_IO_FALLING_EDGE), PIKA_FALSE);
|
|
|
|
}
|
|
|
|
|
2022-12-28 06:41:36 +08:00
|
|
|
obj_run(pikaMain, "io1.close()");
|
|
|
|
|
2022-06-17 14:45:52 +08:00
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-08-09 16:21:52 +08:00
|
|
|
|
|
|
|
TEST(event, remove_regist) {
|
|
|
|
/* init */
|
|
|
|
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
|
|
|
/* run */
|
2022-12-18 19:22:43 +08:00
|
|
|
pks_eventListener_init(&g_pika_device_event_listener);
|
2022-08-09 16:21:52 +08:00
|
|
|
PikaObj* testobj = newNormalObj(New_TinyObj);
|
2022-12-18 19:22:43 +08:00
|
|
|
pks_eventListener_registEvent(g_pika_device_event_listener, 0, testobj);
|
2022-08-09 16:21:52 +08:00
|
|
|
EXPECT_EQ(testobj->refcnt, 2);
|
2022-12-18 19:22:43 +08:00
|
|
|
pks_eventListener_removeEvent(g_pika_device_event_listener, 0);
|
2022-08-09 16:21:52 +08:00
|
|
|
EXPECT_EQ(testobj->refcnt, 1);
|
|
|
|
/* deinit */
|
|
|
|
obj_deinit(pikaMain);
|
|
|
|
obj_deinit(testobj);
|
2022-12-18 19:22:43 +08:00
|
|
|
pks_eventListener_deinit(&g_pika_device_event_listener);
|
2022-08-09 16:21:52 +08:00
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
2022-07-01 23:10:51 +08:00
|
|
|
#endif
|
2022-10-28 18:39:50 +08:00
|
|
|
|
|
|
|
TEST_END
|