diff --git a/test/nanostack/unittest/6LoWPAN/ws_ie_lib/test_ws_ie_lib.c b/test/nanostack/unittest/6LoWPAN/ws_ie_lib/test_ws_ie_lib.c index f03aed54fd0..1d18d3e6634 100644 --- a/test/nanostack/unittest/6LoWPAN/ws_ie_lib/test_ws_ie_lib.c +++ b/test/nanostack/unittest/6LoWPAN/ws_ie_lib/test_ws_ie_lib.c @@ -25,6 +25,7 @@ #include "6LoWPAN/ws/ws_ie_lib.h" #include "6LoWPAN/ws/ws_common_defines.h" #include "common_functions_stub.h" +#include "mac_ie_lib_stub.h" bool test_ws_ie_lib_header() { @@ -117,3 +118,275 @@ bool test_ws_ie_lib_payload() return true; } + +bool test_ws_wp_nested_hopping_schedule_length() +{ + uint16_t length; + ws_hopping_schedule_t shedule; + + memset (&shedule, 0, sizeof(ws_hopping_schedule_t)); + length = ws_wp_nested_hopping_schedule_length(&shedule, true); + if (length != 4 + 2 +2) + { + return false; + } + + shedule.channel_plan = 1; + shedule.channel_function = 1; + length = ws_wp_nested_hopping_schedule_length(&shedule, true); + if (length != 4 + 6) + { + return false; + } + shedule.channel_plan = 2; + shedule.channel_function = 3; + + length = ws_wp_nested_hopping_schedule_length(&shedule, true); + if (length != 6) + { + return false; + } + + length = ws_wp_nested_hopping_schedule_length(&shedule, false); + if (length != 12) + { + return false; + } + return true; +} + +bool test_ws_wp_nested_hopping_schedule_write() +{ + uint8_t temp_buf[20]; + uint8_t *ptr; + ws_hopping_schedule_t shedule; + memset (&shedule, 0, sizeof(ws_hopping_schedule_t)); + + ptr = ws_wp_nested_hopping_schedule_write(temp_buf, &shedule, true); + if (ptr != temp_buf + 8 + 2) { + return false; + } + + shedule.channel_plan = 1; + shedule.channel_function = 1; + ptr = ws_wp_nested_hopping_schedule_write(temp_buf, &shedule, true); + if (ptr != temp_buf + 10 + 2) { + return false; + } + + shedule.channel_plan = 2; + shedule.channel_function = 3; + ptr = ws_wp_nested_hopping_schedule_write(temp_buf, &shedule, false); + if (ptr != temp_buf + 10 + 2 + 2) { + return false; + } + + return true; +} + +bool test_ws_wh_utt_read() +{ + uint8_t temp_buf[20]; + ws_utt_ie_t utt_ie; + mac_ie_lib_stub_def.value_uint8 = 0; + if (ws_wh_utt_read(temp_buf, 8, &utt_ie) ) { + return false; + } + + mac_ie_lib_stub_def.value_uint8 = 4; + return ws_wh_utt_read(temp_buf, 8, &utt_ie); +} + +bool test_ws_wh_bt_read() +{ + uint8_t temp_buf[20]; + ws_bt_ie_t bt_ie; + mac_ie_lib_stub_def.value_uint8 = 0; + if (ws_wh_bt_read(temp_buf, 8, &bt_ie) ) { + return false; + } + + mac_ie_lib_stub_def.value_uint8 = 5; + return ws_wh_bt_read(temp_buf, 8, &bt_ie); +} + +bool test_ws_wp_nested_us_read() +{ + + ws_us_ie_t ws_us_ie; + uint8_t temp_buf[20]; + mac_ie_lib_stub_def.value_uint16 = 3; + temp_buf[3] = 0; + if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie) ){ + return false; + } + + mac_ie_lib_stub_def.value_uint16 = 4; + if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie) ){ + return false; + } + + mac_ie_lib_stub_def.value_uint16 = 7; + if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie) ){ + return false; + } + + mac_ie_lib_stub_def.value_uint16 = 8; + if (!ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) { + return false; + } + temp_buf[3] = 1; + + if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) { + return false; + } + mac_ie_lib_stub_def.value_uint16 = 12; + if (!ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) { + return false; + } + temp_buf[3] = 2; + if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) { + return false; + } + + temp_buf[3] = 1 << 3; + mac_ie_lib_stub_def.value_uint16 = 6; + if (!ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) { + return false; + } + + temp_buf[3] = 3 << 3; + mac_ie_lib_stub_def.value_uint16 = 7; + temp_buf[6] = 2; + if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) { + return false; + } + mac_ie_lib_stub_def.value_uint16 = 9; + if (!ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) { + return false; + } + + temp_buf[3] = 4 << 3; + if (ws_wp_nested_us_read(temp_buf, 40, &ws_us_ie)) { + return false; + } + + return true; + +} + + +bool test_ws_wp_nested_bs_read() +{ + + ws_bs_ie_t ws_bs_ie; + uint8_t temp_buf[20]; + mac_ie_lib_stub_def.value_uint16 = 9; + temp_buf[9] = 0; + if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie) ){ + return false; + } + + mac_ie_lib_stub_def.value_uint16 = 10; + if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie) ){ + return false; + } + + mac_ie_lib_stub_def.value_uint16 = 13; + if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie) ){ + return false; + } + + mac_ie_lib_stub_def.value_uint16 = 14; + if (!ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) { + return false; + } + + temp_buf[9] = 1; + if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) { + return false; + } + + mac_ie_lib_stub_def.value_uint16 = 18; + if (!ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) { + return false; + } + + temp_buf[9] = 2; + if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) { + return false; + } + + temp_buf[9] = 4 << 3; + if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) { + return false; + } + + temp_buf[9] = 1 << 3; + mac_ie_lib_stub_def.value_uint16 = 12; + if (!ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) { + return false; + } + + temp_buf[9] = 3 << 3; + temp_buf[12] = 2; + mac_ie_lib_stub_def.value_uint16 = 13; + if (ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) { + return false; + } + + mac_ie_lib_stub_def.value_uint16 = 15; + if (!ws_wp_nested_bs_read(temp_buf, 40, &ws_bs_ie)) { + return false; + } + + return true; + +} + +bool test_ws_wp_nested_pan_read() +{ + ws_pan_information_t ws_pan_ie; + uint8_t temp_buf[20]; + mac_ie_lib_stub_def.value_uint16 = 4; + if (ws_wp_nested_pan_read(temp_buf, 20, &ws_pan_ie)) { + return false; + } + mac_ie_lib_stub_def.value_uint16 = 5; + + return ws_wp_nested_pan_read(temp_buf, 20, &ws_pan_ie); +} + +bool test_ws_wp_nested_pan_version_read() +{ + uint16_t ws_pan_version; + uint8_t temp_buf[20]; + mac_ie_lib_stub_def.value_uint16 = 4; + if (ws_wp_nested_pan_version_read(temp_buf, 20, &ws_pan_version)) { + return false; + } + + mac_ie_lib_stub_def.value_uint16 = 2; + if (!ws_wp_nested_pan_version_read(temp_buf, 20, &ws_pan_version)) { + return false; + } + + return true; +} + +bool test_ws_wp_nested_gtkhash_read() +{ + uint8_t temp_buf[40]; + mac_ie_lib_stub_def.value_uint16 = 4; + if (ws_wp_nested_gtkhash_read(temp_buf, 40)) { + return false; + } + + mac_ie_lib_stub_def.value_uint16 = 32; + if (!ws_wp_nested_gtkhash_read(temp_buf, 20)) { + return false; + } + + return true; +} + diff --git a/test/nanostack/unittest/6LoWPAN/ws_ie_lib/test_ws_ie_lib.h b/test/nanostack/unittest/6LoWPAN/ws_ie_lib/test_ws_ie_lib.h index 0a3f7ab1f87..90b8fd017bc 100644 --- a/test/nanostack/unittest/6LoWPAN/ws_ie_lib/test_ws_ie_lib.h +++ b/test/nanostack/unittest/6LoWPAN/ws_ie_lib/test_ws_ie_lib.h @@ -28,6 +28,24 @@ bool test_ws_ie_lib_header(); bool test_ws_ie_lib_payload(); +bool test_ws_wp_nested_hopping_schedule_length(); + +bool test_ws_wp_nested_hopping_schedule_write(); + +bool test_ws_wh_utt_read(); + +bool test_ws_wh_bt_read(); + +bool test_ws_wp_nested_us_read(); + +bool test_ws_wp_nested_bs_read(); + +bool test_ws_wp_nested_pan_read(); + +bool test_ws_wp_nested_pan_version_read(); + +bool test_ws_wp_nested_gtkhash_read(); + #ifdef __cplusplus } #endif diff --git a/test/nanostack/unittest/6LoWPAN/ws_ie_lib/ws_ie_libtest.cpp b/test/nanostack/unittest/6LoWPAN/ws_ie_lib/ws_ie_libtest.cpp index 333d1958487..e898bea5899 100644 --- a/test/nanostack/unittest/6LoWPAN/ws_ie_lib/ws_ie_libtest.cpp +++ b/test/nanostack/unittest/6LoWPAN/ws_ie_lib/ws_ie_libtest.cpp @@ -39,6 +39,53 @@ TEST(ws_ie_lib, test_ws_ie_lib_payload) CHECK(test_ws_ie_lib_payload()); } +TEST(ws_ie_lib, test_ws_wp_nested_hopping_schedule_length) +{ + CHECK(test_ws_wp_nested_hopping_schedule_length()); +} + +TEST(ws_ie_lib, test_ws_wp_nested_hopping_schedule_write) +{ + CHECK(test_ws_wp_nested_hopping_schedule_write()); +} + +TEST(ws_ie_lib, test_ws_wh_utt_read) +{ + CHECK(test_ws_wh_utt_read()); +} + +TEST(ws_ie_lib, test_ws_wh_bt_read) +{ + CHECK(test_ws_wh_bt_read()); +} + +TEST(ws_ie_lib, test_ws_wp_nested_us_read) +{ + CHECK(test_ws_wp_nested_us_read()); +} + +TEST(ws_ie_lib, test_ws_wp_nested_bs_read) +{ + CHECK(test_ws_wp_nested_bs_read()); +} + +TEST(ws_ie_lib, test_ws_wp_nested_pan_read) +{ + CHECK(test_ws_wp_nested_pan_read()); +} + +TEST(ws_ie_lib, test_ws_wp_nested_pan_version_read) +{ + CHECK(test_ws_wp_nested_pan_version_read()); +} + +TEST(ws_ie_lib, test_ws_wp_nested_gtkhash_read) +{ + CHECK(test_ws_wp_nested_gtkhash_read()); +} + + + diff --git a/test/nanostack/unittest/6LoWPAN/ws_llc_data_service/test_ws_llc_data_service.c b/test/nanostack/unittest/6LoWPAN/ws_llc_data_service/test_ws_llc_data_service.c index 9533e676b39..964801db089 100644 --- a/test/nanostack/unittest/6LoWPAN/ws_llc_data_service/test_ws_llc_data_service.c +++ b/test/nanostack/unittest/6LoWPAN/ws_llc_data_service/test_ws_llc_data_service.c @@ -40,6 +40,8 @@ #include "ws_mpx_header_stub.h" #include "mac_neighbor_table_stub.h" #include "ws_neighbour_class_stub.h" +#include "ws_ie_lib_stub.h" +#include "address_stub.h" static mcps_data_indication_ext *data_indication_cb; @@ -221,7 +223,7 @@ bool test_asynch_msg_send() return false; } test_handle = 0xff; - + nsdynmemlib_stub.returnCounter = 0; if (ws_llc_asynch_request(&interface, &asynch_request) != 0) { return false; } @@ -390,19 +392,32 @@ bool test_mpx_msg_rx() ie_ext.payloadIeList = payload_buf; ie_ext.payloadIeListLength = 100; + ws_ie_lib_stub.utt_ie.message_type = WS_FT_DATA; + ws_ie_lib_stub.utt_bool_value = false; + ws_neighbor_stub.neigh_entry = NULL; mac_neighbor_table_stub.test_neigh = NULL; mac_ie_lib_stub_def.value_uint8 = 0; data_indication_cb(NULL, &data_ind, &ie_ext); + //No UTT at message mac_ie_lib_stub_def.value_uint8 = 0; data_indication_cb(&api, &data_ind, &ie_ext); + + ws_ie_lib_stub.utt_bool_value = true; mac_ie_lib_stub_def.value_uint8 = 4; mac_ie_lib_stub_def.value_uint16 = 0; data_indication_cb(&api, &data_ind, &ie_ext); mac_ie_lib_stub_def.value_uint16 = 90; + ws_neighbor_class_entry_t neigh_entry; + ws_neighbor_stub.neigh_entry = &neigh_entry; + + mac_neighbor_table_entry_t test_neigh; + test_neigh.index = 0; + + mac_neighbor_table_stub.test_neigh = &test_neigh; ws_mpx_stub.mpx_msg.transfer_type = MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID; ws_mpx_stub.mpx_msg.multiplex_id = 0; @@ -417,10 +432,15 @@ bool test_mpx_msg_rx() ws_mpx_stub.mpx_msg.multiplex_id = 0xA0ED; mpx_ind_data_length = 90; mpx_data_ind_ok = false; + address_stub.uint8_value = 1; + data_ind.DstAddrMode = 3; data_indication_cb(&api, &data_ind, &ie_ext); if (!mpx_data_ind_ok) { return false; } + address_stub.uint8_value = 0; + ws_ie_lib_stub.bt_bool_value = true; + ws_ie_lib_stub.utt_ie.message_type = WS_FT_PAN_CONF_SOL; header_buf[0] = WS_FT_PAN_CONF_SOL; mac_ie_lib_stub_def.value_uint16 = 0; data_indication_cb(&api, &data_ind, &ie_ext); diff --git a/test/nanostack/unittest/stub/mac_ie_lib_stub.c b/test/nanostack/unittest/stub/mac_ie_lib_stub.c index 186588b1bfc..13067eed4b6 100644 --- a/test/nanostack/unittest/stub/mac_ie_lib_stub.c +++ b/test/nanostack/unittest/stub/mac_ie_lib_stub.c @@ -55,6 +55,7 @@ uint16_t mac_ie_payload_discover(uint8_t *payload_ptr, uint16_t length, mac_payl uint8_t mac_ie_header_discover(uint8_t *header_ptr, uint16_t length, mac_header_IE_t * header_ie) { header_ie->content_ptr = header_ptr; + header_ie->length = mac_ie_lib_stub_def.value_uint8; return mac_ie_lib_stub_def.value_uint8; } @@ -62,11 +63,13 @@ uint8_t mac_ie_header_discover(uint8_t *header_ptr, uint16_t length, mac_header_ uint8_t mac_ie_header_sub_id_discover(uint8_t *header_ptr, uint16_t length, mac_header_IE_t * header_ie, uint8_t sub_id) { header_ie->content_ptr = header_ptr; + header_ie->length = mac_ie_lib_stub_def.value_uint8; return mac_ie_lib_stub_def.value_uint8; } uint16_t mac_ie_nested_discover(uint8_t *payload_ptr, uint16_t length, mac_nested_payload_IE_t * nested_ie) { nested_ie->content_ptr = payload_ptr; + nested_ie->length = mac_ie_lib_stub_def.value_uint16; return mac_ie_lib_stub_def.value_uint16; } diff --git a/test/nanostack/unittest/stub/ws_ie_lib_stub.c b/test/nanostack/unittest/stub/ws_ie_lib_stub.c index 5e72a39ba25..459a77b9dd5 100644 --- a/test/nanostack/unittest/stub/ws_ie_lib_stub.c +++ b/test/nanostack/unittest/stub/ws_ie_lib_stub.c @@ -40,6 +40,9 @@ #include "mac_common_defines.h" #include "6LoWPAN/MAC/mac_ie_lib.h" #include "6LoWPAN/ws/ws_common_defines.h" +#include "ws_ie_lib_stub.h" + +ws_ie_lib_stub_def ws_ie_lib_stub; uint8_t *ws_wh_utt_write(uint8_t *ptr, uint8_t message_type) { @@ -148,3 +151,40 @@ uint16_t ws_wp_nested_hopping_schedule_length(struct ws_hoopping_schedule_s *hop } } + +bool ws_wh_utt_read(uint8_t *data, uint16_t length, struct ws_utt_ie *utt_ie) +{ + *utt_ie = ws_ie_lib_stub.utt_ie; + return ws_ie_lib_stub.utt_bool_value; +} + +bool ws_wh_bt_read(uint8_t *data, uint16_t length, struct ws_bt_ie * bt_ie) +{ + *bt_ie = ws_ie_lib_stub.bt_ie; + return ws_ie_lib_stub.bt_bool_value; +} + +bool ws_wp_nested_us_read(uint8_t *data, uint16_t length, struct ws_us_ie *us_ie) +{ + return false; +} + +bool ws_wp_nested_bs_read(uint8_t *data, uint16_t length, struct ws_bs_ie *bs_ie) +{ + return false; +} + +bool ws_wp_nested_pan_read(uint8_t *data, uint16_t length, struct ws_pan_information_s *pan_congiguration) +{ + return false; +} + +bool ws_wp_nested_pan_version_read(uint8_t *data, uint16_t length, uint16_t *pan_version) +{ + return false; +} + +uint8_t * ws_wp_nested_gtkhash_read(uint8_t *data, uint16_t length) +{ + return NULL; +} diff --git a/test/nanostack/unittest/stub/ws_ie_lib_stub.h b/test/nanostack/unittest/stub/ws_ie_lib_stub.h new file mode 100644 index 00000000000..081a3aa8b99 --- /dev/null +++ b/test/nanostack/unittest/stub/ws_ie_lib_stub.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WS_IE_LIB_STUB_H_ +#define WS_IE_LIB_STUB_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include "inttypes.h" +#include "6LoWPAN/ws/ws_common_defines.h" + +typedef struct { + ws_utt_ie_t utt_ie; + bool utt_bool_value; + ws_bt_ie_t bt_ie; + bool bt_bool_value; +} ws_ie_lib_stub_def; + +extern ws_ie_lib_stub_def ws_ie_lib_stub; + +#ifdef __cplusplus +} +#endif + + +#endif /* WS_IE_LIB_STUB_H_ */