forked from ARMmbed/mbed-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented mode switch PHR build and parse (ARMmbed#2665)
- Loading branch information
Jarkko Paso
authored
Aug 18, 2021
1 parent
cbd8a15
commit e1558fb
Showing
9 changed files
with
334 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
include ../../makefile_defines.txt | ||
|
||
COMPONENT_NAME = mac_mode_switch_unit | ||
|
||
#This must be changed manually | ||
SRC_FILES = \ | ||
../../../../../source/MAC/IEEE802_15_4/mac_mode_switch.c | ||
|
||
TEST_SRC_FILES = \ | ||
main.cpp \ | ||
mac_mode_switch_test.cpp \ | ||
test_mac_mode_switch.c \ | ||
../../stub/mbed_trace_stub.c \ | ||
|
||
include ../../MakefileWorker.mk | ||
|
||
CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT | ||
|
38 changes: 38 additions & 0 deletions
38
test/nanostack/unittest/mac/mac_mode_switch/mac_mode_switch_test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2021, Pelion 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_mac_mode_switch.h" | ||
|
||
TEST_GROUP(mac_mode_switch) | ||
{ | ||
void setup() { | ||
} | ||
|
||
void teardown() { | ||
} | ||
}; | ||
|
||
TEST(mac_mode_switch, test_mac_calculate_mode_switch_checksum) | ||
{ | ||
CHECK(test_mac_calculate_mode_switch_checksum()); | ||
} | ||
|
||
TEST(mac_mode_switch, test_mac_calculate_mode_switch_parity) | ||
{ | ||
CHECK(test_mac_calculate_mode_switch_parity()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2021, Pelion 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(mac_mode_switch); | ||
|
83 changes: 83 additions & 0 deletions
83
test/nanostack/unittest/mac/mac_mode_switch/test_mac_mode_switch.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2020, Pelion 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 "test_mac_mode_switch.h" | ||
#include "mac_defines.h" | ||
#include "nsdynmemLIB_stub.h" | ||
#include "MAC/IEEE802_15_4/mac_mode_switch.h" | ||
|
||
static protocol_interface_rf_mac_setup_s mac_setup; | ||
|
||
uint16_t common_read_16_bit_inverse(const uint8_t data_buf[__static 2]) | ||
{ | ||
uint16_t temp_16; | ||
temp_16 = *data_buf++; | ||
temp_16 += (uint16_t)(*data_buf++) << 8; | ||
return temp_16; | ||
} | ||
|
||
uint8_t *common_write_16_bit_inverse(uint16_t value, uint8_t ptr[__static 2]) | ||
{ | ||
*ptr++ = value; | ||
*ptr++ = value >> 8; | ||
return ptr; | ||
} | ||
|
||
static uint8_t test_parse_checksum(uint16_t mode_switch_phr) | ||
{ | ||
return (mode_switch_phr & MASK_MODE_SWITCH_CHECKSUM) >> SHIFT_MODE_SWITCH_CHECKSUM; | ||
} | ||
|
||
static uint8_t test_parse_parity(uint16_t mode_switch_phr) | ||
{ | ||
return (mode_switch_phr & MASK_MODE_SWITCH_PARITY) >> SHIFT_MODE_SWITCH_PARITY; | ||
} | ||
|
||
#define TEST_SEQUENCE_LENGTH 10 | ||
|
||
bool test_mac_calculate_mode_switch_checksum() | ||
{ | ||
uint8_t test_data[2]; | ||
uint8_t phy_modes[TEST_SEQUENCE_LENGTH] = {0x40, 0x54, 0x00, 0x01, 0xff, 0x55, 0x80, 0xa5, 0x5a, 0xda}; | ||
uint8_t results[TEST_SEQUENCE_LENGTH] = {0x0f, 0x0e, 0x09, 0x07, 0x0d, 0x00, 0x0a, 0x02, 0x06, 0x05}; | ||
for (int i = 0; i < TEST_SEQUENCE_LENGTH; i++) { | ||
mac_build_mode_switch_phr(&mac_setup, &test_data, phy_modes[i]); | ||
uint8_t checksum = test_parse_checksum(common_read_16_bit_inverse(test_data)); | ||
if (checksum != results[i]) { | ||
printf("Fail: Mode switch PHR, PHY mode id %x, checksum %x, expected %x\r\n", phy_modes[i], checksum, results[i]); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
bool test_mac_calculate_mode_switch_parity() | ||
{ | ||
uint8_t test_data[2]; | ||
uint8_t phy_modes[TEST_SEQUENCE_LENGTH] = {0x40, 0x54, 0x00, 0x01, 0xff, 0x55, 0x80, 0xa5, 0x5a, 0xda}; | ||
uint8_t results[TEST_SEQUENCE_LENGTH] = {0, 1, 1, 1, 0, 1, 0, 0, 1, 0}; | ||
for (int i = 0; i < TEST_SEQUENCE_LENGTH; i++) { | ||
mac_build_mode_switch_phr(&mac_setup, &test_data, phy_modes[i]); | ||
uint8_t parity = test_parse_parity(common_read_16_bit_inverse(test_data)); | ||
if (parity != results[i]) { | ||
printf("Fail: Mode switch PHR, PHY mode id %x, parity %x, expected %x\r\n", phy_modes[i], parity, results[i]); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
Oops, something went wrong.