1313
1414#include <openthread/instance.h>
1515
16- /* Instance address used when testing serialization of a function that takes otInstance* */
17- #define INSTANCE_ADDR UINT32_MAX
18-
1916static void nrf_rpc_err_handler (const struct nrf_rpc_err_report * report )
2017{
2118 zassert_ok (report -> code );
@@ -28,40 +25,34 @@ static void tc_setup(void *f)
2825 mock_nrf_rpc_tr_expect_reset ();
2926}
3027
31- /* Test serialization of otInstanceInitSingle() returning 0 */
28+ /* Test serialization of otInstanceInitSingle() */
3229ZTEST (ot_rpc_instance , test_otInstanceInitSingle_0 )
3330{
3431 otInstance * instance ;
32+ otInstance * instance2 ;
3533
36- mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_INIT_SINGLE ), RPC_RSP (0 ));
34+ /* Verify a non-null instance is returned from the function. */
35+ mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_INIT_SINGLE ), RPC_RSP ());
3736 instance = otInstanceInitSingle ();
3837 mock_nrf_rpc_tr_expect_done ();
3938
40- zassert_equal (instance , NULL );
41- }
42-
43- /* Test serialization of otInstanceInitSingle() returning max allowed 0xffffffff */
44- ZTEST (ot_rpc_instance , test_otInstanceInitSingle_max )
45- {
46- otInstance * instance ;
39+ zassert_not_null (instance , NULL );
4740
48- mock_nrf_rpc_tr_expect_add ( RPC_CMD ( OT_RPC_CMD_INSTANCE_INIT_SINGLE ),
49- RPC_RSP ( CBOR_UINT32 ( UINT32_MAX ) ));
50- instance = otInstanceInitSingle ();
41+ /* Verify that the same instance is returned for subsequent calls. */
42+ mock_nrf_rpc_tr_expect_add ( RPC_CMD ( OT_RPC_CMD_INSTANCE_INIT_SINGLE ), RPC_RSP ( ));
43+ instance2 = otInstanceInitSingle ();
5144 mock_nrf_rpc_tr_expect_done ();
5245
53- zassert_equal (instance , ( void * ) UINT32_MAX );
46+ zassert_equal (instance , instance2 );
5447}
5548
5649/* Test serialization of otInstanceGetId() returning 0 */
5750ZTEST (ot_rpc_instance , test_otInstanceGetId_0 )
5851{
59- otInstance * instance = (otInstance * )INSTANCE_ADDR ;
6052 uint32_t id ;
6153
62- mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_GET_ID , CBOR_UINT32 (INSTANCE_ADDR )),
63- RPC_RSP (0 ));
64- id = otInstanceGetId (instance );
54+ mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_GET_ID ), RPC_RSP (0 ));
55+ id = otInstanceGetId (NULL );
6556 mock_nrf_rpc_tr_expect_done ();
6657
6758 zassert_equal (id , 0 );
@@ -70,12 +61,11 @@ ZTEST(ot_rpc_instance, test_otInstanceGetId_0)
7061/* Test serialization of otInstanceGetId() returning max allowed UINT32_MAX */
7162ZTEST (ot_rpc_instance , test_otInstanceGetId_max )
7263{
73- otInstance * instance = (otInstance * )INSTANCE_ADDR ;
7464 uint32_t id ;
7565
76- mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_GET_ID , CBOR_UINT32 ( INSTANCE_ADDR ) ),
66+ mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_GET_ID ),
7767 RPC_RSP (CBOR_UINT32 (UINT32_MAX )));
78- id = otInstanceGetId (instance );
68+ id = otInstanceGetId (NULL );
7969 mock_nrf_rpc_tr_expect_done ();
8070
8171 zassert_equal (id , UINT32_MAX );
@@ -84,13 +74,11 @@ ZTEST(ot_rpc_instance, test_otInstanceGetId_max)
8474/* Test serialization of otInstanceIsInitialized() returning false */
8575ZTEST (ot_rpc_instance , test_otInstanceIsInitialized_false )
8676{
87- otInstance * instance = (otInstance * )INSTANCE_ADDR ;
8877 bool initialized ;
8978
90- mock_nrf_rpc_tr_expect_add (
91- RPC_CMD (OT_RPC_CMD_INSTANCE_IS_INITIALIZED , CBOR_UINT32 (INSTANCE_ADDR )),
92- RPC_RSP (CBOR_FALSE ));
93- initialized = otInstanceIsInitialized (instance );
79+ mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_IS_INITIALIZED ),
80+ RPC_RSP (CBOR_FALSE ));
81+ initialized = otInstanceIsInitialized (NULL );
9482 mock_nrf_rpc_tr_expect_done ();
9583
9684 zassert_false (initialized );
@@ -99,13 +87,10 @@ ZTEST(ot_rpc_instance, test_otInstanceIsInitialized_false)
9987/* Test serialization of otInstanceIsInitialized() returning true */
10088ZTEST (ot_rpc_instance , test_otInstanceIsInitialized_true )
10189{
102- otInstance * instance = (otInstance * )INSTANCE_ADDR ;
10390 bool initialized ;
10491
105- mock_nrf_rpc_tr_expect_add (
106- RPC_CMD (OT_RPC_CMD_INSTANCE_IS_INITIALIZED , CBOR_UINT32 (INSTANCE_ADDR )),
107- RPC_RSP (CBOR_TRUE ));
108- initialized = otInstanceIsInitialized (instance );
92+ mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_IS_INITIALIZED ), RPC_RSP (CBOR_TRUE ));
93+ initialized = otInstanceIsInitialized (NULL );
10994 mock_nrf_rpc_tr_expect_done ();
11095
11196 zassert_true (initialized );
@@ -114,24 +99,19 @@ ZTEST(ot_rpc_instance, test_otInstanceIsInitialized_true)
11499/* Test serialization of otInstanceFinalize() */
115100ZTEST (ot_rpc_instance , test_otInstanceFinalize )
116101{
117- otInstance * instance = (otInstance * )INSTANCE_ADDR ;
118-
119- mock_nrf_rpc_tr_expect_add (
120- RPC_CMD (OT_RPC_CMD_INSTANCE_FINALIZE , CBOR_UINT32 (INSTANCE_ADDR )), RPC_RSP ());
121- otInstanceFinalize (instance );
102+ mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_FINALIZE ), RPC_RSP ());
103+ otInstanceFinalize (NULL );
122104 mock_nrf_rpc_tr_expect_done ();
123105}
124106
125107/* Test serialization of otInstanceErasePersistentInfo() returning success */
126108ZTEST (ot_rpc_instance , test_otInstanceErasePersistentInfo_ok )
127109{
128- otInstance * instance = (otInstance * )INSTANCE_ADDR ;
129110 otError error ;
130111
131- mock_nrf_rpc_tr_expect_add (
132- RPC_CMD (OT_RPC_CMD_INSTANCE_ERASE_PERSISTENT_INFO , CBOR_UINT32 (INSTANCE_ADDR )),
133- RPC_RSP (OT_ERROR_NONE ));
134- error = otInstanceErasePersistentInfo (instance );
112+ mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_ERASE_PERSISTENT_INFO ),
113+ RPC_RSP (OT_ERROR_NONE ));
114+ error = otInstanceErasePersistentInfo (NULL );
135115 mock_nrf_rpc_tr_expect_done ();
136116
137117 zassert_equal (error , OT_ERROR_NONE );
@@ -140,13 +120,11 @@ ZTEST(ot_rpc_instance, test_otInstanceErasePersistentInfo_ok)
140120/* Test serialization of otInstanceErasePersistentInfo() returning error */
141121ZTEST (ot_rpc_instance , test_otInstanceErasePersistentInfo_error )
142122{
143- otInstance * instance = (otInstance * )INSTANCE_ADDR ;
144123 otError error ;
145124
146- mock_nrf_rpc_tr_expect_add (
147- RPC_CMD (OT_RPC_CMD_INSTANCE_ERASE_PERSISTENT_INFO , CBOR_UINT32 (INSTANCE_ADDR )),
148- RPC_RSP (OT_ERROR_INVALID_STATE ));
149- error = otInstanceErasePersistentInfo (instance );
125+ mock_nrf_rpc_tr_expect_add (RPC_CMD (OT_RPC_CMD_INSTANCE_ERASE_PERSISTENT_INFO ),
126+ RPC_RSP (OT_ERROR_INVALID_STATE ));
127+ error = otInstanceErasePersistentInfo (NULL );
150128 mock_nrf_rpc_tr_expect_done ();
151129
152130 zassert_equal (error , OT_ERROR_INVALID_STATE );
0 commit comments