Skip to content

Commit

Permalink
MPX header module unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Juha Heiskanen authored and juhhei01 committed Feb 13, 2018
1 parent 55309e8 commit 6b6e509
Show file tree
Hide file tree
Showing 7 changed files with 458 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/nanostack/unittest/6LoWPAN/ws_mpx_header/Makefile
@@ -0,0 +1,33 @@
include ../../makefile_defines.txt

COMPONENT_NAME = ws_mpx_header_unit

#This must be changed manually
SRC_FILES = \
../../../../../source/6LoWPAN/ws/ws_mpx_header.c

TEST_SRC_FILES = \
main.cpp \
ws_mpx_headertest.cpp \
test_ws_mpx_header.c \
../../stub/common_functions_stub.c \
../../stub/nsdynmemLIB_stub.c \
../../stub/mbed_trace_stub.c \
../../stub/platform_stub.c \
../../stub/address_stub.c \
../../stub/etx_stub.c \
../../stub/protocol_stats_stub.c \
../../stub/randLIB_stub.c \
../../stub/mesh_stub.c \
../../stub/nsdynmemLIB_stub.c \
../../stub/mbed_trace_stub.c \
../../stub/buffer_dyn_stub.c \
../../stub/protocol_core_stub.c \
../../stub/socket_stub.c \
../../stub/iphc_decompress_stub.c \


include ../../MakefileWorker.mk

CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT

28 changes: 28 additions & 0 deletions test/nanostack/unittest/6LoWPAN/ws_mpx_header/main.cpp
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2016, 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.
*/

#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/MockSupportPlugin.h"
int main(int ac, char** av)
{
return CommandLineTestRunner::RunAllTests(ac, av);
}

IMPORT_TEST_GROUP(ws_mpx_header);

208 changes: 208 additions & 0 deletions test/nanostack/unittest/6LoWPAN/ws_mpx_header/test_ws_mpx_header.c
@@ -0,0 +1,208 @@
/*
* 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.
*/
#include "nsconfig.h"
#include <string.h>
#include "ns_types.h"
#include "ns_list.h"
#include "ns_trace.h"
#include "nsdynmemLIB.h"
#include "common_functions.h"
#include "mac_common_defines.h"
#include "6LoWPAN/ws/ws_mpx_header.h"
#include "common_functions_stub.h"

bool test_ws_llc_mpx_header_frame_parse()
{
mpx_msg_t mpx_msg;
uint8_t temp_buffer[10];

if (ws_llc_mpx_header_frame_parse(temp_buffer, 0, &mpx_msg) ) {
return false;
}

temp_buffer[0] = MPX_FT_FULL_FRAME;
temp_buffer[0] |= (15 << 3);

common_functions_stub.readuint16_from_queue = 0;
common_functions_stub.uint16_value = 4;

if (ws_llc_mpx_header_frame_parse(temp_buffer, 2, &mpx_msg) ) {
return false;
}

if (!ws_llc_mpx_header_frame_parse(temp_buffer, 5, &mpx_msg) ) {
return false;
}

if (mpx_msg.frame_length != 2 || mpx_msg.frame_ptr != &temp_buffer[3] || mpx_msg.transfer_type != MPX_FT_FULL_FRAME || mpx_msg.transaction_id != 15 || mpx_msg.multiplex_id != 4) {
return false;
}

temp_buffer[0] = MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID;
temp_buffer[0] |= (16 << 3);

if (!ws_llc_mpx_header_frame_parse(temp_buffer, 5, &mpx_msg) ) {
return false;
}

if (mpx_msg.frame_length != 4 || mpx_msg.frame_ptr != &temp_buffer[1] || mpx_msg.transfer_type != MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID || mpx_msg.transaction_id != 16) {
return false;
}

temp_buffer[0] = MPX_FT_FIRST_OR_SUB_FRAGMENT;
temp_buffer[0] |= (17 << 3);
temp_buffer[1] = 0;

common_functions_stub.readuint16_from_queue = 2;
//common_functions_stub.uint16_value = 100;
common_functions_stub.uint16_value_queue[1] = 40;
common_functions_stub.uint16_value_queue[0] = 20;

if (ws_llc_mpx_header_frame_parse(temp_buffer, 2, &mpx_msg) ) {
return false;
}
common_functions_stub.readuint16_from_queue = 2;
common_functions_stub.uint16_value_queue[1] = 40;
common_functions_stub.uint16_value_queue[0] = 20;
if (ws_llc_mpx_header_frame_parse(temp_buffer, 3, &mpx_msg) ) {
return false;
}
common_functions_stub.readuint16_from_queue = 2;
common_functions_stub.uint16_value_queue[1] = 40;
common_functions_stub.uint16_value_queue[0] = 20;
if (ws_llc_mpx_header_frame_parse(temp_buffer, 5, &mpx_msg) ) {
return false;
}
common_functions_stub.readuint16_from_queue = 2;
common_functions_stub.uint16_value_queue[1] = 40;
common_functions_stub.uint16_value_queue[0] = 20;


if (!ws_llc_mpx_header_frame_parse(temp_buffer, 10, &mpx_msg) ) {
return false;
}

if (mpx_msg.frame_length != 4 || mpx_msg.frame_ptr != &temp_buffer[6] || mpx_msg.transfer_type != MPX_FT_FIRST_OR_SUB_FRAGMENT
|| mpx_msg.transaction_id != 17 || mpx_msg.multiplex_id != 20 || mpx_msg.total_upper_layer_size != 40) {
return false;
}

temp_buffer[0] = MPX_FT_FIRST_OR_SUB_FRAGMENT;
temp_buffer[0] |= (18 << 3);
temp_buffer[1] = 1;

if (!ws_llc_mpx_header_frame_parse(temp_buffer, 10, &mpx_msg) ) {
return false;
}

if (mpx_msg.frame_length != 8 || mpx_msg.frame_ptr != &temp_buffer[2] || mpx_msg.transfer_type != MPX_FT_FIRST_OR_SUB_FRAGMENT
|| mpx_msg.transaction_id != 18 ) {
return false;
}
temp_buffer[0] = MPX_FT_ABORT;
temp_buffer[0] |= (19 << 3);
if (ws_llc_mpx_header_frame_parse(temp_buffer, 10, &mpx_msg) ) {
return false;
}



common_functions_stub.readuint16_from_queue = 0;
common_functions_stub.uint16_value = 400;

if (!ws_llc_mpx_header_frame_parse(temp_buffer, 3, &mpx_msg) ) {
return false;
}

if (mpx_msg.frame_length || mpx_msg.transfer_type != MPX_FT_ABORT
|| mpx_msg.transaction_id != 19 || mpx_msg.total_upper_layer_size != 400) {
return false;
}
if (!ws_llc_mpx_header_frame_parse(temp_buffer, 1, &mpx_msg) ) {
return false;
}

if (mpx_msg.frame_length || mpx_msg.transfer_type != MPX_FT_ABORT
|| mpx_msg.transaction_id != 19 || mpx_msg.total_upper_layer_size) {
return false;
}

temp_buffer[0] = 7;
temp_buffer[0] |= (19 << 3);
if (ws_llc_mpx_header_frame_parse(temp_buffer, 3, &mpx_msg) ) {
return false;
}


return true;
}

bool test_ws_llc_mpx_header_write()
{
mpx_msg_t mpx_msg;
uint8_t temp_buffer[10];

mpx_msg.transfer_type = MPX_FT_FULL_FRAME;
mpx_msg.transaction_id = 15;

uint8_t *ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
if (ptr != &temp_buffer[3]) {
return false;
}

mpx_msg.transfer_type = MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID;
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
if (ptr != &temp_buffer[1]) {
return false;
}

mpx_msg.transfer_type = MPX_FT_FIRST_OR_SUB_FRAGMENT;
mpx_msg.fragment_number = 0;
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
if (ptr != &temp_buffer[6]) {
return false;
}

mpx_msg.transfer_type = MPX_FT_FIRST_OR_SUB_FRAGMENT;
mpx_msg.fragment_number = 1;
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
if (ptr != &temp_buffer[2]) {
return false;
}

mpx_msg.transfer_type = MPX_FT_ABORT;
mpx_msg.total_upper_layer_size = 0;
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
if (ptr != &temp_buffer[1]) {
return false;
}

mpx_msg.transfer_type = MPX_FT_ABORT;
mpx_msg.total_upper_layer_size = 400;
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
if (ptr != &temp_buffer[3]) {
return false;
}

mpx_msg.transfer_type = 7;
ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg);
if (ptr != &temp_buffer[1]) {
return false;
}

return true;
}
35 changes: 35 additions & 0 deletions test/nanostack/unittest/6LoWPAN/ws_mpx_header/test_ws_mpx_header.h
@@ -0,0 +1,35 @@
/*
* 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 TEST_WS_MPX_HEADER_H_
#define TEST_WS_MPX_HEADER_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>

bool test_ws_llc_mpx_header_frame_parse();

bool test_ws_llc_mpx_header_write();

#ifdef __cplusplus
}
#endif

#endif /* TEST_WS_MPX_HEADER_H_ */
@@ -0,0 +1,61 @@
/*
* 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.
*/

/*
* Copyright (c) 2016, 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.
*/
#include "CppUTest/TestHarness.h"
#include "test_ws_mpx_header.h"

TEST_GROUP(ws_mpx_header)
{
void setup()
{
}

void teardown()
{
}
};

TEST(ws_mpx_header, test_ws_llc_mpx_header_frame_parse)
{
CHECK(test_ws_llc_mpx_header_frame_parse());
}

TEST(ws_mpx_header, test_ws_llc_mpx_header_write)
{
CHECK(test_ws_llc_mpx_header_write());
}





0 comments on commit 6b6e509

Please sign in to comment.