Przeglądaj źródła

test: add npl_eventq test

Jackistang 4 lat temu
rodzic
commit
0b6c05087b
2 zmienionych plików z 51 dodań i 4 usunięć
  1. 5 4
      SConscript
  2. 46 0
      tests/npl_os.c

+ 5 - 4
SConscript

@@ -32,10 +32,11 @@ src += [
 ]
 
 # For test
-# src += [
-#     'tests/hci_transport_h4.c',
-#     'tests/chipset.c'
-# ]
+src += [
+    # 'tests/hci_transport_h4.c',
+    # 'tests/chipset.c'
+    'tests/npl_os.c'
+]
 
 inc += [cwd + '/include']
 

+ 46 - 0
tests/npl_os.c

@@ -0,0 +1,46 @@
+#include <rtthread.h>
+#include "nimble/nimble_npl.h"
+#include "utest.h"
+
+struct ble_npl_eventq evq;
+
+static rt_err_t utest_tc_init(void)
+{
+    ble_npl_eventq_init(&evq);
+    return RT_EOK;
+}
+
+static rt_err_t utest_tc_cleanup(void)
+{
+    return RT_EOK;
+}
+
+static int evt_arg = 10; 
+static void ble_npl_event_cb(struct ble_npl_event *ev)
+{
+    uassert_int_equal(ev->arg, &evt_arg);
+}
+
+static void testBleNplEventqSendSuccess(void)
+{
+    struct ble_npl_event evt;
+    ble_npl_event_init(&evt, ble_npl_event_cb, &evt_arg);
+    ble_npl_eventq_put(&evq, &evt);
+    struct ble_npl_event *recv_evt = ble_npl_eventq_get(&evq, 100);
+    uassert_not_null(recv_evt);
+    uassert_int_equal(recv_evt, &evt);
+    ble_npl_event_run(&evt);
+}
+
+static void testBleNplEventqRecvFail(void)
+{
+    struct ble_npl_event *recv_evt = ble_npl_eventq_get(&evq, 100);
+    uassert_null(recv_evt);
+}
+
+static void testcase_chipset(void)
+{
+    UTEST_UNIT_RUN(testBleNplEventqSendSuccess);
+    UTEST_UNIT_RUN(testBleNplEventqRecvFail);
+}
+UTEST_TC_EXPORT(testcase_chipset, "npl.os", utest_tc_init, utest_tc_cleanup, 1000);