mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #8341 from ARMmbed/release-candidate
Release candidate for mbed-os-5.10.1pull/8776/head mbed-os-5.10.1
commit
c53d51fe92
|
@ -267,3 +267,4 @@ matrix:
|
|||
script:
|
||||
- echo 'Checking that there is no GPL licence text in code'
|
||||
- ! git grep -q --ignore-case "gnu general public";
|
||||
- ! git grep -q --ignore-case "gnu library general public";
|
||||
|
|
|
@ -33,3 +33,9 @@ We have a [developer website](https://os.mbed.com) for asking questions, engagin
|
|||
## Getting started for contributors
|
||||
|
||||
We also have a [contributing and publishing guide](https://os.mbed.com/contributing/) that covers licensing, contributor agreements and style guidelines.
|
||||
|
||||
## Documentation
|
||||
|
||||
For more information about Mbed OS, please see [our published documentation](https://os.mbed.com/docs/latest). It includes published Doxygen for our APIs, step-by-step tutorials, porting information and background reference materials about our architecture and tools.
|
||||
|
||||
To contribute to this documentation, please see the [mbed-os-5-docs repo](https://github.com/ARMmbed/mbed-os-5-docs).
|
||||
|
|
|
@ -36,9 +36,6 @@ class SystemResetTest(BaseHostTest):
|
|||
def __init__(self):
|
||||
super(SystemResetTest, self).__init__()
|
||||
self.reset = False
|
||||
cycle_s = self.get_config_item('program_cycle_s')
|
||||
self.program_cycle_s = cycle_s if cycle_s is not None else DEFAULT_CYCLE_PERIOD
|
||||
|
||||
self.test_steps_sequence = self.test_steps()
|
||||
# Advance the coroutine to it's first yield statement.
|
||||
self.test_steps_sequence.send(None)
|
||||
|
@ -61,14 +58,16 @@ class SystemResetTest(BaseHostTest):
|
|||
"""Reset the device and check the status
|
||||
"""
|
||||
system_reset = yield
|
||||
|
||||
self.reset = False
|
||||
|
||||
wait_after_reset = self.get_config_item('forced_reset_timeout')
|
||||
wait_after_reset = wait_after_reset if wait_after_reset is not None else DEFAULT_CYCLE_PERIOD
|
||||
|
||||
self.send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DUMMY)
|
||||
time.sleep(self.program_cycle_s)
|
||||
time.sleep(wait_after_reset)
|
||||
self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
|
||||
|
||||
system_reset = yield
|
||||
|
||||
if self.reset == False:
|
||||
raise RuntimeError('Platform did not reset as expected.')
|
||||
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
"""
|
||||
Copyright (c) 2018 ARM Limited
|
||||
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.
|
||||
"""
|
||||
|
||||
"""
|
||||
This script is the host script for trng test sequence, it send the
|
||||
step signaling sequence and receive and transmit data to the device after
|
||||
reset if necesarry (default loading and storing mechanism while reseting the device
|
||||
is NVstore, in case NVstore isn't enabled we'll use current infrastructure,
|
||||
for more details see main.cpp file)
|
||||
"""
|
||||
|
||||
import time
|
||||
from mbed_host_tests import BaseHostTest
|
||||
from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector
|
||||
from time import sleep
|
||||
|
||||
DEFAULT_CYCLE_PERIOD = 1.0
|
||||
MSG_VALUE_DUMMY = '0'
|
||||
MSG_TRNG_READY = 'ready'
|
||||
MSG_TRNG_BUFFER = 'buffer'
|
||||
MSG_TRNG_TEST_STEP1 = 'check_step1'
|
||||
MSG_TRNG_TEST_STEP2 = 'check_step2'
|
||||
MSG_KEY_SYNC = '__sync'
|
||||
MSG_KEY_RESET_COMPLETE = 'reset_complete'
|
||||
MSG_KEY_TEST_SUITE_ENDED = 'Test_suite_ended'
|
||||
MSG_KEY_EXIT = 'exit'
|
||||
|
||||
class TRNGResetTest(BaseHostTest):
|
||||
"""Test for the TRNG API.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(TRNGResetTest, self).__init__()
|
||||
self.did_reset = False
|
||||
self.ready = False
|
||||
self.suite_ended = False
|
||||
self.buffer = 0
|
||||
self.test_steps_sequence = self.test_steps()
|
||||
# Advance the coroutine to it's first yield statement.
|
||||
self.test_steps_sequence.send(None)
|
||||
|
||||
#define callback functions for msg handling
|
||||
def setup(self):
|
||||
self.register_callback(MSG_TRNG_READY, self.cb_device_ready)
|
||||
self.register_callback(MSG_TRNG_BUFFER, self.cb_trng_buffer)
|
||||
self.register_callback(MSG_KEY_TEST_SUITE_ENDED, self.cb_device_test_suit_ended)
|
||||
self.register_callback(MSG_KEY_RESET_COMPLETE, self.cb_reset_complete)
|
||||
|
||||
#receive sent data from device before reset
|
||||
def cb_trng_buffer(self, key, value, timestamp):
|
||||
"""Acknowledge device rebooted correctly and feed the test execution
|
||||
"""
|
||||
self.buffer = value
|
||||
|
||||
try:
|
||||
if self.test_steps_sequence.send(value):
|
||||
self.notify_complete(True)
|
||||
except (StopIteration, RuntimeError) as exc:
|
||||
self.notify_complete(False)
|
||||
|
||||
def cb_device_ready(self, key, value, timestamp):
|
||||
"""Acknowledge device rebooted correctly and feed the test execution
|
||||
"""
|
||||
self.ready = True
|
||||
|
||||
try:
|
||||
if self.test_steps_sequence.send(value):
|
||||
self.notify_complete(True)
|
||||
except (StopIteration, RuntimeError) as exc:
|
||||
self.notify_complete(False)
|
||||
|
||||
def cb_reset_complete(self, key, value, timestamp):
|
||||
"""Acknowledge reset complete
|
||||
"""
|
||||
self.did_reset = True
|
||||
|
||||
try:
|
||||
if self.test_steps_sequence.send(value):
|
||||
self.notify_complete(True)
|
||||
except (StopIteration, RuntimeError) as exc:
|
||||
self.notify_complete(False)
|
||||
|
||||
def cb_device_test_suit_ended(self, key, value, timestamp):
|
||||
"""Acknowledge device finished a test step correctly and feed the test execution
|
||||
"""
|
||||
self.suite_ended = True
|
||||
|
||||
try:
|
||||
if self.test_steps_sequence.send(value):
|
||||
self.notify_complete(True)
|
||||
except (StopIteration, RuntimeError) as exc:
|
||||
self.notify_complete(False)
|
||||
|
||||
#define test steps and actions
|
||||
def test_steps(self):
|
||||
"""Test step 1
|
||||
"""
|
||||
wait_for_communication = yield
|
||||
|
||||
self.ready = False
|
||||
self.did_reset = False
|
||||
self.suite_ended = False
|
||||
self.send_kv(MSG_TRNG_TEST_STEP1, MSG_VALUE_DUMMY)
|
||||
wait_for_communication = yield
|
||||
if self.buffer == 0:
|
||||
raise RuntimeError('Phase 1: No buffer received.')
|
||||
|
||||
self.reset()
|
||||
|
||||
"""Test step 2 (After reset)
|
||||
"""
|
||||
wait_for_communication = yield
|
||||
if self.did_reset == False:
|
||||
raise RuntimeError('Phase 1: Platform did not reset as expected.')
|
||||
|
||||
self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
|
||||
|
||||
wait_for_communication = yield
|
||||
|
||||
if self.ready == False:
|
||||
raise RuntimeError('Phase 1: Platform not ready as expected.')
|
||||
|
||||
self.send_kv(MSG_TRNG_TEST_STEP2, self.buffer)
|
||||
|
||||
wait_for_communication = yield
|
||||
|
||||
if self.suite_ended == False:
|
||||
raise RuntimeError('Test failed.')
|
||||
|
||||
self.send_kv(MSG_KEY_EXIT, MSG_VALUE_DUMMY)
|
||||
|
||||
# The sequence is correct -- test passed.
|
||||
yield
|
|
@ -473,11 +473,14 @@ void ticker_speed_test(void)
|
|||
|
||||
/* ---- Test fire_interrupt function. ---- */
|
||||
counter = NUM_OF_CALLS;
|
||||
/* Disable ticker interrupt which would interfere with speed test */
|
||||
core_util_critical_section_enter();
|
||||
start = us_ticker_read();
|
||||
while (counter--) {
|
||||
intf->fire_interrupt();
|
||||
}
|
||||
stop = us_ticker_read();
|
||||
core_util_critical_section_exit();
|
||||
|
||||
TEST_ASSERT(diff_us(start, stop, us_ticker_info) < (NUM_OF_CALLS * (MAX_FUNC_EXEC_TIME_US + DELTA_FUNC_EXEC_TIME_US)));
|
||||
|
||||
|
@ -569,7 +572,7 @@ utest::v1::status_t lp_ticker_teardown(const Case *const source, const size_t pa
|
|||
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(30, "default_auto");
|
||||
GREENTEA_SETUP(80, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,192 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018-2018 ARM Limited
|
||||
*
|
||||
* 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 MBED_QSPI_FLASH_MX25R6435F_H
|
||||
#define MBED_QSPI_FLASH_MX25R6435F_H
|
||||
|
||||
|
||||
#define QSPI_FLASH_CHIP_STRING "macronix MX25R6435F"
|
||||
|
||||
// Command for reading status register
|
||||
#define QSPI_CMD_RDSR 0x05
|
||||
// Command for reading configuration register
|
||||
#define QSPI_CMD_RDCR0 0x15
|
||||
// Command for writing status/configuration register
|
||||
#define QSPI_CMD_WRSR 0x01
|
||||
// Command for reading security register
|
||||
#define QSPI_CMD_RDSCUR 0x2B
|
||||
|
||||
// Command for setting Reset Enable
|
||||
#define QSPI_CMD_RSTEN 0x66
|
||||
// Command for setting Reset
|
||||
#define QSPI_CMD_RST 0x99
|
||||
|
||||
// Command for setting write enable
|
||||
#define QSPI_CMD_WREN 0x06
|
||||
// Command for setting write disable
|
||||
#define QSPI_CMD_WRDI 0x04
|
||||
|
||||
// WRSR operations max time [us] (datasheet max time + 15%)
|
||||
#define QSPI_WRSR_MAX_TIME 34500 // 30ms
|
||||
// general wait max time [us]
|
||||
#define QSPI_WAIT_MAX_TIME 100000 // 100ms
|
||||
|
||||
|
||||
// Commands for writing (page programming)
|
||||
#define QSPI_CMD_WRITE_1IO 0x02 // 1-1-1 mode
|
||||
#define QSPI_CMD_WRITE_4IO 0x38 // 1-4-4 mode
|
||||
|
||||
// write operations max time [us] (datasheet max time + 15%)
|
||||
#define QSPI_PAGE_PROG_MAX_TIME 11500 // 10ms
|
||||
|
||||
#define QSPI_PAGE_SIZE 256 // 256B
|
||||
|
||||
// Commands for reading
|
||||
#define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode
|
||||
#define QSPI_CMD_READ_1IO 0x03 // 1-1-1 mode
|
||||
#define QSPI_CMD_READ_2IO 0xBB // 1-2-2 mode
|
||||
#define QSPI_CMD_READ_1I2O 0x3B // 1-1-2 mode
|
||||
#define QSPI_CMD_READ_4IO 0xEB // 1-4-4 mode
|
||||
#define QSPI_CMD_READ_1I4O 0x6B // 1-1-4 mode
|
||||
|
||||
#define QSPI_READ_1IO_DUMMY_CYCLE 0
|
||||
#define QSPI_READ_FAST_DUMMY_CYCLE 8
|
||||
#define QSPI_READ_2IO_DUMMY_CYCLE 4
|
||||
#define QSPI_READ_1I2O_DUMMY_CYCLE 8
|
||||
#define QSPI_READ_4IO_DUMMY_CYCLE 6
|
||||
#define QSPI_READ_1I4O_DUMMY_CYCLE 8
|
||||
|
||||
// Commands for erasing
|
||||
#define QSPI_CMD_ERASE_SECTOR 0x20 // 4kB
|
||||
#define QSPI_CMD_ERASE_BLOCK_32 0x52 // 32kB
|
||||
#define QSPI_CMD_ERASE_BLOCK_64 0xD8 // 64kB
|
||||
#define QSPI_CMD_ERASE_CHIP 0x60 // or 0xC7
|
||||
|
||||
// erase operations max time [us] (datasheet max time + 15%)
|
||||
#define QSPI_ERASE_SECTOR_MAX_TIME 276000 // 240 ms
|
||||
#define QSPI_ERASE_BLOCK_32_MAX_TIME 3450000 // 3s
|
||||
#define QSPI_ERASE_BLOCK_64_MAX_TIME 4025000 // 3.5s
|
||||
|
||||
// max frequency for basic rw operation
|
||||
#define QSPI_COMMON_MAX_FREQUENCY 32000000
|
||||
|
||||
#define QSPI_STATUS_REG_SIZE 1
|
||||
#define QSPI_CONFIG_REG_0_SIZE 2
|
||||
#define QSPI_SECURITY_REG_SIZE 1
|
||||
#define QSPI_MAX_REG_SIZE 2
|
||||
|
||||
// status register
|
||||
#define STATUS_BIT_WIP (1 << 0) // write in progress bit
|
||||
#define STATUS_BIT_WEL (1 << 1) // write enable latch
|
||||
#define STATUS_BIT_BP0 (1 << 2) //
|
||||
#define STATUS_BIT_BP1 (1 << 3) //
|
||||
#define STATUS_BIT_BP2 (1 << 4) //
|
||||
#define STATUS_BIT_BP3 (1 << 5) //
|
||||
#define STATUS_BIT_QE (1 << 6) // Quad Enable
|
||||
#define STATUS_BIT_SRWD (1 << 7) // status register write protect
|
||||
|
||||
// configuration register 0
|
||||
// bit 0, 1, 2, 4, 5, 7 reserved
|
||||
#define CONFIG0_BIT_TB (1 << 3) // Top/Bottom area protect
|
||||
#define CONFIG0_BIT_DC (1 << 6) // Dummy Cycle
|
||||
|
||||
// configuration register 1
|
||||
// bit 0, 2, 3, 4, 5, 6, 7 reserved
|
||||
#define CONFIG1_BIT_LH (1 << 1) // 0 = Ultra Low power mode, 1 = High performance mode
|
||||
|
||||
|
||||
// single quad enable flag for both dual and quad mode
|
||||
#define QUAD_ENABLE() \
|
||||
\
|
||||
uint8_t reg_data[QSPI_STATUS_REG_SIZE]; \
|
||||
\
|
||||
if (write_enable(qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
\
|
||||
reg_data[0] = STATUS_BIT_QE; \
|
||||
qspi.cmd.build(QSPI_CMD_WRSR); \
|
||||
\
|
||||
if (qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
|
||||
reg_data, QSPI_STATUS_REG_SIZE, NULL, 0) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
\
|
||||
memset(reg_data, 0, QSPI_STATUS_REG_SIZE); \
|
||||
if (read_register(STATUS_REG, reg_data, \
|
||||
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
return ((reg_data[0] & STATUS_BIT_QE) != 0 ? \
|
||||
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
|
||||
|
||||
|
||||
|
||||
#define QUAD_DISABLE() \
|
||||
\
|
||||
uint8_t reg_data[QSPI_STATUS_REG_SIZE]; \
|
||||
\
|
||||
if (write_enable(qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
\
|
||||
reg_data[0] = 0; \
|
||||
qspi.cmd.build(QSPI_CMD_WRSR); \
|
||||
\
|
||||
if (qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
|
||||
reg_data, QSPI_STATUS_REG_SIZE, NULL, 0) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
\
|
||||
reg_data[0] = 0; \
|
||||
if (read_register(STATUS_REG, reg_data, \
|
||||
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
return ((reg_data[0] & STATUS_BIT_QE) == 0 ? \
|
||||
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
|
||||
|
||||
|
||||
|
||||
#define FAST_MODE_ENABLE() \
|
||||
\
|
||||
qspi_status_t ret; \
|
||||
const int32_t reg_size = QSPI_STATUS_REG_SIZE + QSPI_CONFIG_REG_0_SIZE; \
|
||||
uint8_t reg_data[reg_size]; \
|
||||
\
|
||||
if (read_register(STATUS_REG, reg_data, \
|
||||
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
if (read_register(CONFIG_REG0, reg_data + QSPI_STATUS_REG_SIZE, \
|
||||
QSPI_CONFIG_REG_0_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
reg_data[2] |= CONFIG1_BIT_LH; \
|
||||
qspi.cmd.build(QSPI_CMD_WRSR); \
|
||||
\
|
||||
return qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
|
||||
reg_data, reg_size, NULL, 0)
|
||||
|
||||
|
||||
|
||||
#endif // MBED_QSPI_FLASH_MX25R6435F_H
|
|
@ -13,11 +13,11 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_QSPI_FLASH_MX25R3235F_H
|
||||
#define MBED_QSPI_FLASH_MX25R3235F_H
|
||||
#ifndef MBED_QSPI_FLASH_MX25RXX35F_H
|
||||
#define MBED_QSPI_FLASH_MX25RXX35F_H
|
||||
|
||||
|
||||
#define QSPI_FLASH_CHIP_STRING "macronix MX25R3235F"
|
||||
#define QSPI_FLASH_CHIP_STRING "macronix MX25RXX35F"
|
||||
|
||||
// Command for reading status register
|
||||
#define QSPI_CMD_RDSR 0x05
|
||||
|
@ -52,6 +52,8 @@
|
|||
#define QSPI_PAGE_PROG_MAX_TIME 11500 // 10ms
|
||||
|
||||
#define QSPI_PAGE_SIZE 256 // 256B
|
||||
#define QSPI_SECTOR_SIZE 4096 // 4kB
|
||||
#define QSPI_SECTOR_COUNT 32 // adjusted to MX25R1035F smallest one from MX25RXX35F family
|
||||
|
||||
// Commands for reading
|
||||
#define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode
|
||||
|
@ -79,7 +81,7 @@
|
|||
#define QSPI_ERASE_BLOCK_32_MAX_TIME 3450000 // 3s
|
||||
#define QSPI_ERASE_BLOCK_64_MAX_TIME 4025000 // 3.5s
|
||||
|
||||
// max frequency for basic rw operation
|
||||
// max frequency for basic rw operation (for fast mode)
|
||||
#define QSPI_COMMON_MAX_FREQUENCY 32000000
|
||||
|
||||
#define QSPI_STATUS_REG_SIZE 1
|
||||
|
@ -107,21 +109,28 @@
|
|||
#define CONFIG1_BIT_LH (1 << 1) // 0 = Ultra Low power mode, 1 = High performance mode
|
||||
|
||||
|
||||
// single quad enable flag for both dual and quad mode
|
||||
#define QUAD_ENABLE() \
|
||||
|
||||
#define EXTENDED_SPI_ENABLE() \
|
||||
\
|
||||
uint8_t reg_data[QSPI_STATUS_REG_SIZE]; \
|
||||
const int32_t reg_size = QSPI_STATUS_REG_SIZE + QSPI_CONFIG_REG_0_SIZE; \
|
||||
uint8_t reg_data[reg_size] = { 0 }; \
|
||||
\
|
||||
if (read_register(STATUS_REG, reg_data, \
|
||||
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
if (read_register(CONFIG_REG0, reg_data + QSPI_STATUS_REG_SIZE, \
|
||||
QSPI_CONFIG_REG_0_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
if (write_enable(qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
\
|
||||
reg_data[0] = STATUS_BIT_QE; \
|
||||
qspi.cmd.build(QSPI_CMD_WRSR); \
|
||||
\
|
||||
if (qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
|
||||
reg_data, QSPI_STATUS_REG_SIZE, NULL, 0) != QSPI_STATUS_OK) { \
|
||||
if (write_register(QSPI_CMD_WRSR, reg_data, \
|
||||
reg_size, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
|
@ -137,20 +146,28 @@
|
|||
|
||||
|
||||
|
||||
#define QUAD_DISABLE() \
|
||||
#define EXTENDED_SPI_DISABLE() \
|
||||
\
|
||||
uint8_t reg_data[QSPI_STATUS_REG_SIZE]; \
|
||||
const int32_t reg_size = QSPI_STATUS_REG_SIZE + QSPI_CONFIG_REG_0_SIZE; \
|
||||
uint8_t reg_data[reg_size] = { 0 }; \
|
||||
\
|
||||
if (read_register(STATUS_REG, reg_data, \
|
||||
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
if (read_register(CONFIG_REG0, reg_data + QSPI_STATUS_REG_SIZE, \
|
||||
QSPI_CONFIG_REG_0_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
if (write_enable(qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
\
|
||||
reg_data[0] = 0; \
|
||||
qspi.cmd.build(QSPI_CMD_WRSR); \
|
||||
reg_data[0] &= ~(STATUS_BIT_QE); \
|
||||
\
|
||||
if (qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
|
||||
reg_data, QSPI_STATUS_REG_SIZE, NULL, 0) != QSPI_STATUS_OK) { \
|
||||
if (write_register(QSPI_CMD_WRSR, reg_data, \
|
||||
reg_size, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
|
@ -168,7 +185,6 @@
|
|||
|
||||
#define FAST_MODE_ENABLE() \
|
||||
\
|
||||
qspi_status_t ret; \
|
||||
const int32_t reg_size = QSPI_STATUS_REG_SIZE + QSPI_CONFIG_REG_0_SIZE; \
|
||||
uint8_t reg_data[reg_size]; \
|
||||
\
|
||||
|
@ -181,12 +197,58 @@
|
|||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
reg_data[2] |= CONFIG1_BIT_LH; \
|
||||
qspi.cmd.build(QSPI_CMD_WRSR); \
|
||||
if (write_enable(qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
return qspi_command_transfer(&qspi.handle, qspi.cmd.get(), \
|
||||
reg_data, reg_size, NULL, 0)
|
||||
reg_data[2] |= CONFIG1_BIT_LH; \
|
||||
if (write_register(QSPI_CMD_WRSR, reg_data, \
|
||||
reg_size, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
\
|
||||
if (read_register(CONFIG_REG0, reg_data, \
|
||||
QSPI_CONFIG_REG_0_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
return ((reg_data[1] & CONFIG1_BIT_LH) != 0 ? \
|
||||
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
|
||||
|
||||
|
||||
#define FAST_MODE_DISABLE() \
|
||||
\
|
||||
const int32_t reg_size = QSPI_STATUS_REG_SIZE + QSPI_CONFIG_REG_0_SIZE; \
|
||||
uint8_t reg_data[reg_size]; \
|
||||
\
|
||||
if (read_register(STATUS_REG, reg_data, \
|
||||
QSPI_STATUS_REG_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
if (read_register(CONFIG_REG0, reg_data + QSPI_STATUS_REG_SIZE, \
|
||||
QSPI_CONFIG_REG_0_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
if (write_enable(qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
reg_data[2] &= ~(CONFIG1_BIT_LH); \
|
||||
if (write_register(QSPI_CMD_WRSR, reg_data, \
|
||||
reg_size, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
\
|
||||
if (read_register(CONFIG_REG0, reg_data, \
|
||||
QSPI_CONFIG_REG_0_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
return ((reg_data[1] & CONFIG1_BIT_LH) == 0 ? \
|
||||
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
|
||||
|
||||
#endif // MBED_QSPI_FLASH_MX25R3235F_H
|
||||
|
||||
#endif // MBED_QSPI_FLASH_MX25RXX35F_H
|
|
@ -58,18 +58,24 @@
|
|||
#define QSPI_CMD_WRITE_1IO 0x02 // 1-1-1 mode
|
||||
#define QSPI_CMD_WRITE_2IO 0xD2 // 1-2-2 mode
|
||||
#define QSPI_CMD_WRITE_4IO 0x12 // 1-4-4 mode
|
||||
#define QSPI_CMD_WRITE_DPI 0xD2 // 2-2-2 mode
|
||||
#define QSPI_CMD_WRITE_QPI 0x12 // 4-4-4 mode
|
||||
|
||||
// write operations max time [us] (datasheet max time + 15%)
|
||||
#define QSPI_PAGE_PROG_MAX_TIME 5750 // 5ms
|
||||
|
||||
#define QSPI_PAGE_SIZE 256 // 256B
|
||||
#define QSPI_SECTOR_SIZE 4096 // 4kB
|
||||
#define QSPI_SECTOR_COUNT 4096
|
||||
|
||||
// Commands for reading
|
||||
#define QSPI_CMD_READ_1IO_FAST 0x0B // 1-1-1 mode
|
||||
#define QSPI_CMD_READ_1IO 0x03 // 1-1-1 mode
|
||||
#define QSPI_CMD_READ_2IO 0xBB // 1-2-2 mode
|
||||
#define QSPI_CMD_READ_DPI 0xBB // 2-2-2 mode
|
||||
#define QSPI_CMD_READ_1I2O 0x3B // 1-1-2 mode
|
||||
#define QSPI_CMD_READ_4IO 0xEB // 1-4-4 mode
|
||||
#define QSPI_CMD_READ_QPI 0xEB // 4-4-4 mode
|
||||
#define QSPI_CMD_READ_1I4O 0x6B // 1-1-4 mode
|
||||
|
||||
|
||||
|
@ -88,7 +94,7 @@
|
|||
#define QSPI_CMD_ERASE_CHIP 0x60 // or 0xC7
|
||||
|
||||
// erase operations max time [us] (datasheet max time + 15%)
|
||||
#define QSPI_ERASE_SECTOR_MAX_TIME 276000 // 240 ms
|
||||
#define QSPI_ERASE_SECTOR_MAX_TIME 920000 // 0.8s
|
||||
#define QSPI_ERASE_BLOCK_32_MAX_TIME 3000000 // 3s
|
||||
#define QSPI_ERASE_BLOCK_64_MAX_TIME 3500000 // 3.5s
|
||||
|
||||
|
@ -155,28 +161,122 @@
|
|||
|
||||
|
||||
#define DUAL_ENABLE() \
|
||||
/* TODO: add implementation */ \
|
||||
return QSPI_STATUS_OK
|
||||
\
|
||||
uint8_t reg_data[QSPI_CONFIG_REG_2_SIZE]; \
|
||||
\
|
||||
memset(reg_data, 0, QSPI_CONFIG_REG_2_SIZE); \
|
||||
if (read_register(QSPI_CMD_RDCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
if (write_enable(qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
reg_data[0] = reg_data[0] & ~(CONFIG2_BIT_DE); \
|
||||
if (write_register(QSPI_CMD_WRCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
qspi.cmd.configure(MODE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8); \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
memset(reg_data, 0, QSPI_CONFIG_REG_2_SIZE); \
|
||||
if (read_register(QSPI_CMD_RDCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
return ((reg_data[0] & (CONFIG2_BIT_DE)) == 0 ? \
|
||||
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
|
||||
|
||||
|
||||
#define DUAL_DISABLE() \
|
||||
/* TODO: add implementation */ \
|
||||
return QSPI_STATUS_OK
|
||||
\
|
||||
uint8_t reg_data[QSPI_CONFIG_REG_2_SIZE]; \
|
||||
\
|
||||
memset(reg_data, 0, QSPI_CONFIG_REG_2_SIZE); \
|
||||
if (read_register(QSPI_CMD_RDCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
if (write_enable(qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
reg_data[0] = reg_data[0] | (CONFIG2_BIT_DE); \
|
||||
if (write_register(QSPI_CMD_WRCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8); \
|
||||
memset(reg_data, 0, QSPI_CONFIG_REG_2_SIZE); \
|
||||
if (read_register(QSPI_CMD_RDCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
return ((reg_data[0] & CONFIG2_BIT_DE) != 1 ? \
|
||||
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
|
||||
|
||||
|
||||
#define QUAD_ENABLE() \
|
||||
/* TODO: add implementation */ \
|
||||
return QSPI_STATUS_OK
|
||||
\
|
||||
uint8_t reg_data[QSPI_CONFIG_REG_2_SIZE]; \
|
||||
\
|
||||
memset(reg_data, 0, QSPI_CONFIG_REG_2_SIZE); \
|
||||
if (read_register(QSPI_CMD_RDCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
if (write_enable(qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
reg_data[0] = reg_data[0] & ~(CONFIG2_BIT_QE); \
|
||||
if (write_register(QSPI_CMD_WRCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
qspi.cmd.configure(MODE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8); \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
memset(reg_data, 0, QSPI_CONFIG_REG_2_SIZE); \
|
||||
if (read_register(QSPI_CMD_RDCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
return ((reg_data[0] & (CONFIG2_BIT_QE)) == 0 ? \
|
||||
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
|
||||
|
||||
|
||||
#define QUAD_DISABLE() \
|
||||
/* TODO: add implementation */ \
|
||||
return QSPI_STATUS_OK
|
||||
|
||||
|
||||
#define FAST_MODE_ENABLE() \
|
||||
/* TODO: add implementation */ \
|
||||
return QSPI_STATUS_OK
|
||||
|
||||
\
|
||||
uint8_t reg_data[QSPI_CONFIG_REG_2_SIZE]; \
|
||||
\
|
||||
memset(reg_data, 0, QSPI_CONFIG_REG_2_SIZE); \
|
||||
if (read_register(QSPI_CMD_RDCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
if (write_enable(qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
reg_data[0] = reg_data[0] | (CONFIG2_BIT_QE); \
|
||||
if (write_register(QSPI_CMD_WRCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi); \
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8); \
|
||||
memset(reg_data, 0, QSPI_CONFIG_REG_2_SIZE); \
|
||||
if (read_register(QSPI_CMD_RDCR2, reg_data, \
|
||||
QSPI_CONFIG_REG_2_SIZE, qspi) != QSPI_STATUS_OK) { \
|
||||
return QSPI_STATUS_ERROR; \
|
||||
} \
|
||||
\
|
||||
return ((reg_data[0] & CONFIG2_BIT_QE) != 1 ? \
|
||||
QSPI_STATUS_OK : QSPI_STATUS_ERROR)
|
||||
|
||||
#endif // MBED_QSPI_FLASH_N25Q128A_H
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#ifndef MBED_QSPI_FLASH_CONFIG_H
|
||||
#define MBED_QSPI_FLASH_CONFIG_H
|
||||
|
||||
#include "../../MX25R6435F_config.h"
|
||||
#include "../../MX25RXX35F_config.h"
|
||||
|
||||
// NRF doesn't uses read/write opcodes, instead it uses commands id's.
|
||||
// Before sending it to H/W opcodes are mapped to id's in Mbed hal qspi implementation
|
||||
|
@ -29,5 +29,9 @@
|
|||
#undef QSPI_CMD_READ_1IO
|
||||
#define QSPI_CMD_READ_1IO QSPI_CMD_READ_1IO_FAST
|
||||
|
||||
#ifdef QSPI_SECTOR_COUNT
|
||||
#undef QSPI_SECTOR_COUNT
|
||||
#define QSPI_SECTOR_COUNT 2048 // for MX25R6435F
|
||||
#endif
|
||||
|
||||
#endif // MBED_QSPI_FLASH_CONFIG_H
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#ifndef MBED_QSPI_FLASH_CONFIG_H
|
||||
#define MBED_QSPI_FLASH_CONFIG_H
|
||||
|
||||
#include "../../MX25R6435F_config.h"
|
||||
#include "../../MX25RXX35F_config.h"
|
||||
|
||||
|
||||
#endif // MBED_QSPI_FLASH_CONFIG_H
|
||||
|
|
|
@ -16,7 +16,11 @@
|
|||
#ifndef MBED_QSPI_FLASH_CONFIG_H
|
||||
#define MBED_QSPI_FLASH_CONFIG_H
|
||||
|
||||
#include "../../MX25R3235F_config.h"
|
||||
#include "../../MX25RXX35F_config.h"
|
||||
|
||||
#ifdef QSPI_SECTOR_COUNT
|
||||
#undef QSPI_SECTOR_COUNT
|
||||
#define QSPI_SECTOR_COUNT 1024 // for MX25R3235F
|
||||
#endif
|
||||
|
||||
#endif // MBED_QSPI_FLASH_CONFIG_H
|
||||
|
|
|
@ -52,7 +52,7 @@ uint8_t rx_buf[DATA_SIZE_1024];
|
|||
#define TEST_FLASH_ADDRESS 0x0
|
||||
|
||||
#define TEST_REPEAT_SINGLE 1
|
||||
#define TEST_REPEAT_MULTIPLE 16
|
||||
#define TEST_REPEAT_MULTIPLE 4
|
||||
|
||||
// write block of data in single write operation
|
||||
#define WRITE_SINGLE 1
|
||||
|
@ -74,6 +74,13 @@ uint8_t rx_buf[DATA_SIZE_1024];
|
|||
#define QCSN static_cast<PinName>(QSPI_FLASH1_CSN)
|
||||
|
||||
|
||||
static uint32_t gen_flash_address()
|
||||
{
|
||||
srand(ticker_read(get_us_ticker_data()));
|
||||
uint32_t address = (((uint32_t)rand()) % QSPI_SECTOR_COUNT) * QSPI_SECTOR_SIZE;
|
||||
return address;
|
||||
}
|
||||
|
||||
static void log_data(const char *str, uint8_t *data, uint32_t size)
|
||||
{
|
||||
utest_printf("%s: ", str);
|
||||
|
@ -100,7 +107,6 @@ static void _qspi_write_read_test(Qspi &qspi, qspi_bus_width_t write_inst_width,
|
|||
size_t buf_len = data_size;
|
||||
|
||||
for (uint32_t tc = 0; tc < test_count; tc++) {
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
|
||||
|
||||
srand(ticker_read(get_us_ticker_data()));
|
||||
for (uint32_t i = 0; i < data_size; i++) {
|
||||
|
@ -125,6 +131,11 @@ static void _qspi_write_read_test(Qspi &qspi, qspi_bus_width_t write_inst_width,
|
|||
WAIT_FOR(WAIT_MAX_TIME, qspi);
|
||||
}
|
||||
|
||||
// switching to extended-SPI/DPI/QPI mode here for write operation
|
||||
// for DPI/QPI qspi.cmd is automatically switched to 2_2_2/4_4_4 mode
|
||||
ret = mode_enable(qspi, write_inst_width, write_addr_width, write_data_width);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
|
||||
const uint32_t write_size = data_size / write_count;
|
||||
for (uint32_t wc = 0, write_start = flash_addr; wc < write_count; wc++, write_start += write_size) {
|
||||
ret = write_enable(qspi);
|
||||
|
@ -140,18 +151,32 @@ static void _qspi_write_read_test(Qspi &qspi, qspi_bus_width_t write_inst_width,
|
|||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
TEST_ASSERT_EQUAL(write_size, buf_len);
|
||||
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
|
||||
if(is_extended_mode(write_inst_width, write_addr_width, write_data_width)) {
|
||||
// on some flash chips in extended-SPI mode, control commands works only in 1-1-1 mode
|
||||
// so switching back to 1-1-1 mode
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
|
||||
}
|
||||
|
||||
WAIT_FOR(PAGE_PROG_MAX_TIME, qspi);
|
||||
|
||||
timer.stop();
|
||||
write_time = timer.read_us();
|
||||
}
|
||||
|
||||
// switching back to single channel SPI
|
||||
ret = mode_disable(qspi, write_inst_width, write_addr_width, write_data_width);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
|
||||
if (read_frequency != QSPI_NONE) {
|
||||
qspi_frequency(&qspi.handle, read_frequency);
|
||||
WAIT_FOR(WAIT_MAX_TIME, qspi);
|
||||
}
|
||||
|
||||
// switching to extended-SPI/DPI/QPI mode here for read operation
|
||||
// for DPI/QPI qspi.cmd is automatically switched to 2_2_2/4_4_4 mode
|
||||
ret = mode_enable(qspi, read_inst_width, read_addr_width, read_data_width);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
|
||||
memset(rx_buf, 0, sizeof(rx_buf));
|
||||
const uint32_t read_size = data_size / read_count;
|
||||
qspi.cmd.configure(read_inst_width, read_addr_width, read_data_width, read_alt_width, read_addr_size, read_alt_size, read_dummy_cycles);
|
||||
|
@ -168,6 +193,17 @@ static void _qspi_write_read_test(Qspi &qspi, qspi_bus_width_t write_inst_width,
|
|||
timer.stop();
|
||||
read_time = timer.read_us();
|
||||
}
|
||||
qspi.cmd.set_dummy_cycles(0);
|
||||
|
||||
if(is_extended_mode(read_inst_width, read_addr_width, read_data_width)) {
|
||||
// on some flash chips in extended-SPI mode, control commands works only in 1-1-1 mode
|
||||
// so switching back to 1-1-1 mode
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
|
||||
}
|
||||
|
||||
// switching back to single channel SPI
|
||||
ret = mode_disable(qspi, read_inst_width, read_addr_width, read_data_width);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
|
||||
for (uint32_t i = 0; i < data_size; i++) {
|
||||
if (tx_buf[i] != rx_buf[i]) {
|
||||
|
@ -217,43 +253,29 @@ void qspi_write_read_test(void)
|
|||
{
|
||||
qspi_status_t ret;
|
||||
Qspi qspi;
|
||||
|
||||
uint32_t addr = flash_addr;
|
||||
if (addr == 0) {
|
||||
// if no specified address selected, use random one to extend flash life
|
||||
addr = gen_flash_address();
|
||||
}
|
||||
|
||||
qspi_init(&qspi.handle, QPIN_0, QPIN_1, QPIN_2, QPIN_3, QSCK, QCSN, QSPI_COMMON_MAX_FREQUENCY, 0);
|
||||
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
|
||||
flash_init(qspi);
|
||||
|
||||
if (is_dual_cmd(write_inst_width, write_addr_width, write_data_width) ||
|
||||
is_dual_cmd(read_inst_width, read_addr_width, read_data_width)) {
|
||||
ret = dual_enable(qspi);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi);
|
||||
}
|
||||
|
||||
if (is_quad_cmd(write_inst_width, write_addr_width, write_data_width) ||
|
||||
is_quad_cmd(read_inst_width, read_addr_width, read_data_width)) {
|
||||
ret = quad_enable(qspi);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi);
|
||||
}
|
||||
|
||||
ret = write_enable(qspi);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi);
|
||||
// switch memory to high performance mode (if available)
|
||||
ret = fast_mode_enable(qspi);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi);
|
||||
|
||||
#ifdef QSPI_TEST_LOG_FLASH_STATUS
|
||||
//utest_printf("Status register:\r\n");
|
||||
log_register(STATUS_REG, QSPI_STATUS_REG_SIZE, qspi, "Status register");
|
||||
//utest_printf("Config register 0:\r\n");
|
||||
log_register(CONFIG_REG0, QSPI_CONFIG_REG_0_SIZE, qspi, "Config register 0");
|
||||
#ifdef CONFIG_REG1
|
||||
//utest_printf("Config register 1:\r\n");
|
||||
log_register(CONFIG_REG1, QSPI_CONFIG_REG_1_SIZE, qspi, "Config register 1");
|
||||
#endif
|
||||
#ifdef CONFIG_REG2
|
||||
//utest_printf("Config register 2:\r\n");
|
||||
log_register(CONFIG_REG2, QSPI_CONFIG_REG_2_SIZE, qspi, "Config register 2");
|
||||
#endif
|
||||
#endif
|
||||
|
@ -262,23 +284,10 @@ void qspi_write_read_test(void)
|
|||
write_addr_size, write_alt_size, write_frequency, write_count, read_inst_width,
|
||||
read_addr_width, read_data_width, read_alt_width, read_cmd, read_dummy_cycles,
|
||||
read_addr_size, read_alt_size, read_frequency, read_count, test_count,
|
||||
data_size, flash_addr);
|
||||
data_size, addr);
|
||||
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
|
||||
|
||||
if (is_dual_cmd(write_inst_width, write_addr_width, write_data_width) ||
|
||||
is_dual_cmd(read_inst_width, read_addr_width, read_data_width)) {
|
||||
ret = dual_disable(qspi);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi);
|
||||
}
|
||||
|
||||
if (is_quad_cmd(write_inst_width, write_addr_width, write_data_width) ||
|
||||
is_quad_cmd(read_inst_width, read_addr_width, read_data_width)) {
|
||||
ret = quad_disable(qspi);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
WAIT_FOR(WRSR_MAX_TIME, qspi);
|
||||
}
|
||||
ret = fast_mode_disable(qspi);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
|
||||
qspi_free(&qspi.handle);
|
||||
}
|
||||
|
@ -315,16 +324,12 @@ void qspi_init_free_test(void)
|
|||
flash_init(qspi);
|
||||
|
||||
#ifdef QSPI_TEST_LOG_FLASH_STATUS
|
||||
//utest_printf("Status register:\r\n");
|
||||
log_register(STATUS_REG, QSPI_STATUS_REG_SIZE, qspi, "Status register");
|
||||
//utest_printf("Config register 0:\r\n");
|
||||
log_register(CONFIG_REG0, QSPI_CONFIG_REG_0_SIZE, qspi, "Config register 0");
|
||||
#ifdef CONFIG_REG1
|
||||
//utest_printf("Config register 1:\r\n");
|
||||
log_register(CONFIG_REG1, QSPI_CONFIG_REG_1_SIZE, qspi, "Config register 1");
|
||||
#endif
|
||||
#ifdef CONFIG_REG2
|
||||
//utest_printf("Config register 2:\r\n");
|
||||
log_register(CONFIG_REG2, QSPI_CONFIG_REG_2_SIZE, qspi, "Config register 2");
|
||||
#endif
|
||||
#endif
|
||||
|
@ -338,37 +343,33 @@ void qspi_frequency_test(void)
|
|||
{
|
||||
Qspi qspi;
|
||||
qspi_status_t ret;
|
||||
int freq = QSPI_COMMON_MAX_FREQUENCY;
|
||||
|
||||
ret = qspi_init(&qspi.handle, QPIN_0, QPIN_1, QPIN_2, QPIN_3, QSCK, QCSN, QSPI_COMMON_MAX_FREQUENCY, 0);
|
||||
ret = qspi_init(&qspi.handle, QPIN_0, QPIN_1, QPIN_2, QPIN_3, QSCK, QCSN, freq, 0);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
|
||||
ret = qspi_frequency(&qspi.handle, QSPI_COMMON_MAX_FREQUENCY);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
// check if the memory is working properly
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
|
||||
flash_init(qspi);
|
||||
_qspi_write_read_test(qspi, WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_NONE, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_NONE, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS);
|
||||
_qspi_write_read_test(qspi, WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, freq, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, freq, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS);
|
||||
|
||||
ret = qspi_frequency(&qspi.handle, QSPI_COMMON_MAX_FREQUENCY / 2);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
freq /= 2;
|
||||
// check if the memory is working properly
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
|
||||
flash_init(qspi);
|
||||
_qspi_write_read_test(qspi, WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_NONE, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_NONE, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS);
|
||||
_qspi_write_read_test(qspi, WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, freq, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, freq, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS);
|
||||
|
||||
ret = qspi_frequency(&qspi.handle, QSPI_COMMON_MAX_FREQUENCY / 4);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
freq /= 2;
|
||||
// check if the memory is working properly
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
|
||||
flash_init(qspi);
|
||||
_qspi_write_read_test(qspi, WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_NONE, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_NONE, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS);
|
||||
_qspi_write_read_test(qspi, WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, freq, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, freq, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS);
|
||||
|
||||
ret = qspi_frequency(&qspi.handle, QSPI_COMMON_MAX_FREQUENCY / 8);
|
||||
TEST_ASSERT_EQUAL(QSPI_STATUS_OK, ret);
|
||||
freq /= 2;
|
||||
// check if the memory is working properly
|
||||
qspi.cmd.configure(MODE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8);
|
||||
flash_init(qspi);
|
||||
_qspi_write_read_test(qspi, WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_NONE, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_NONE, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS);
|
||||
_qspi_write_read_test(qspi, WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, freq, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, freq, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS);
|
||||
|
||||
qspi_free(&qspi.handle);
|
||||
}
|
||||
|
@ -387,69 +388,184 @@ Case cases[] = {
|
|||
// read/x1 write/x1 - read/write block of data in single write/read operation
|
||||
// read/x4 write/x4 - read/write block of data in adjacent locations in multiple write/read operations
|
||||
// repeat/xN - test repeat count (new data pattern each time)
|
||||
// 1-1-1 - single channel SPI
|
||||
// 1-1-2 - Dual data (extended SPI)
|
||||
// 1-2-2 - Dual I/O (extended SPI)
|
||||
// 1-1-4 - Quad data (extended SPI)
|
||||
// 1-4-4 - Quad I/O (extended SPI)
|
||||
// 2-2-2 - DPI (multi-channel SPI)
|
||||
// 4-4-4 - QPI (multi-channel SPI)
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-1)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x4 read(1-1-1)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-1)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-1)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-1)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x4 read(1-1-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-2)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x4 read(1-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-2-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-2-2)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-2-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef READ_2_2_2
|
||||
Case("qspi write(1-1-1)/x1 read(2-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x4 read(2-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(2-2-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(2-2-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#endif
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x4 read(1-1-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-4)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-1-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x4 read(1-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-4-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(1-4-4)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef QSPI_CMD_WRITE_2IO
|
||||
Case("qspi write(1-1-1)/x1 read(1-4-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef READ_4_4_4
|
||||
Case("qspi write(1-1-1)/x1 read(4-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x4 read(4-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(4-4-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-1-1)/x1 read(4-4-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#endif
|
||||
|
||||
#ifdef WRITE_1_2_2
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-1)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x4 read(1-1-1)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-1)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-1)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-1)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x4 read(1-1-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-2)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x4 read(1-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-2-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-2-2)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-2-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef READ_2_2_2
|
||||
Case("qspi write(1-2-2)/x1 read(2-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x4 read(2-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(2-2-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(2-2-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#endif
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x4 read(1-1-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-4)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-1-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x4 read(1-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-4-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-4-4)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(1-4-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef READ_4_4_4
|
||||
Case("qspi write(1-2-2)/x1 read(4-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x4 read(4-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(4-4-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-2-2)/x1 read(4-4-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#endif
|
||||
#ifdef QSPI_CMD_WRITE_4IO
|
||||
#endif
|
||||
|
||||
#ifdef WRITE_2_2_2
|
||||
Case("qspi write(2-2-2)/x1 read(1-1-1)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x4 read(1-1-1)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-1-1)/x4 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-1-1)/x1 repeat/x4 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-1-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x4 read(1-1-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-1-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-1-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x4 read(1-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-2-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-2-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef READ_2_2_2
|
||||
Case("qspi write(2-2-2)/x1 read(2-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x4 read(2-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(2-2-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(2-2-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#endif
|
||||
Case("qspi write(2-2-2)/x1 read(1-1-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x4 read(1-1-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-1-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-1-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x4 read(1-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-4-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(1-4-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef READ_4_4_4
|
||||
Case("qspi write(2-2-2)/x1 read(4-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x4 read(4-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(4-4-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(2-2-2)/x1 read(4-4-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WRITE_1_4_4
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-1)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x4 read(1-1-1)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-1)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-1)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-1)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x4 read(1-1-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-2)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x4 read(1-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-2-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-2-2)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-2-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef READ_2_2_2
|
||||
Case("qspi write(1-4-4)/x1 read(2-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x4 read(2-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(2-2-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(2-2-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#endif
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x4 read(1-1-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-4)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-1-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x4 read(1-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-4-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-4-4)/x1 repeat/x16 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(1-4-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef READ_4_4_4
|
||||
Case("qspi write(1-4-4)/x1 read(4-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x4 read(4-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(4-4-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(1-4-4)/x1 read(4-4-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WRITE_4_4_4
|
||||
Case("qspi write(4-4-4)/x1 read(1-1-1)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x4 read(1-1-1)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-1-1)/x4 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-1-1)/x1 repeat/x4 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_1, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-1-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x4 read(1-1-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-1-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-1-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x4 read(1-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-2-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-2-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef READ_2_2_2
|
||||
Case("qspi write(4-4-4)/x1 read(2-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x4 read(2-2-2)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(2-2-2)/x4 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(2-2-2)/x1 repeat/x4 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_2_2_2, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#endif
|
||||
Case("qspi write(4-4-4)/x1 read(1-1-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x4 read(1-1-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-1-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-1-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_1_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x4 read(1-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-4-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(1-4-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_1_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#ifdef READ_4_4_4
|
||||
Case("qspi write(4-4-4)/x1 read(4-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x4 read(4-4-4)/x1 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_MULTIPLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_SINGLE, DATA_SIZE_1024, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(4-4-4)/x4 repeat/x1 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_MULTIPLE, TEST_REPEAT_SINGLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
Case("qspi write(4-4-4)/x1 read(4-4-4)/x1 repeat/x4 test", qspi_write_read_test<WRITE_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, WRITE_SINGLE, READ_4_4_4, ADDR_SIZE_24, ALT_SIZE_8, QSPI_COMMON_MAX_FREQUENCY, READ_SINGLE, TEST_REPEAT_MULTIPLE, DATA_SIZE_256, TEST_FLASH_ADDRESS>),
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -26,6 +26,12 @@
|
|||
#include "flash_configs/flash_configs.h"
|
||||
#include "mbed.h"
|
||||
|
||||
static qspi_status_t extended_enable(Qspi &qspi);
|
||||
static qspi_status_t extended_disable(Qspi &qspi);
|
||||
static qspi_status_t dual_enable(Qspi &qspi);
|
||||
static qspi_status_t dual_disable(Qspi &qspi);
|
||||
static qspi_status_t quad_enable(Qspi &qspi);
|
||||
static qspi_status_t quad_disable(Qspi &qspi);
|
||||
|
||||
void QspiCommand::configure(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width,
|
||||
qspi_bus_width_t data_width, qspi_bus_width_t alt_width,
|
||||
|
@ -44,6 +50,11 @@ void QspiCommand::configure(qspi_bus_width_t inst_width, qspi_bus_width_t addr_w
|
|||
_cmd.dummy_count = dummy_cycles;
|
||||
}
|
||||
|
||||
void QspiCommand::set_dummy_cycles(int dummy_cycles)
|
||||
{
|
||||
_cmd.dummy_count = dummy_cycles;
|
||||
}
|
||||
|
||||
void QspiCommand::build(int instruction, int address, int alt)
|
||||
{
|
||||
_cmd.instruction.disabled = (instruction == QSPI_NONE);
|
||||
|
@ -188,46 +199,116 @@ qspi_status_t erase(uint32_t erase_cmd, uint32_t flash_addr, Qspi &qspi)
|
|||
return qspi_command_transfer(&qspi.handle, qspi.cmd.get(), NULL, 0, NULL, 0);
|
||||
}
|
||||
|
||||
qspi_status_t dual_enable(Qspi &qspi)
|
||||
qspi_status_t mode_enable(Qspi &qspi, qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width)
|
||||
{
|
||||
if(is_extended_mode(inst_width, addr_width, data_width)) {
|
||||
return extended_enable(qspi);
|
||||
} else if(is_dual_mode(inst_width, addr_width, data_width)) {
|
||||
return dual_enable(qspi);
|
||||
} else if(is_quad_mode(inst_width, addr_width, data_width)) {
|
||||
return quad_enable(qspi);
|
||||
} else {
|
||||
return QSPI_STATUS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
qspi_status_t mode_disable(Qspi &qspi, qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width)
|
||||
{
|
||||
if(is_extended_mode(inst_width, addr_width, data_width)) {
|
||||
return extended_disable(qspi);
|
||||
} else if(is_dual_mode(inst_width, addr_width, data_width)) {
|
||||
return dual_disable(qspi);
|
||||
} else if(is_quad_mode(inst_width, addr_width, data_width)) {
|
||||
return quad_disable(qspi);
|
||||
} else {
|
||||
return QSPI_STATUS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
static qspi_status_t extended_enable(Qspi &qspi)
|
||||
{
|
||||
#ifdef EXTENDED_SPI_ENABLE
|
||||
EXTENDED_SPI_ENABLE();
|
||||
#else
|
||||
return QSPI_STATUS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
static qspi_status_t extended_disable(Qspi &qspi)
|
||||
{
|
||||
#ifdef EXTENDED_SPI_DISABLE
|
||||
EXTENDED_SPI_DISABLE();
|
||||
#else
|
||||
return QSPI_STATUS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
static qspi_status_t dual_enable(Qspi &qspi)
|
||||
{
|
||||
#ifdef DUAL_ENABLE
|
||||
DUAL_ENABLE();
|
||||
#else
|
||||
QUAD_ENABLE();
|
||||
return QSPI_STATUS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
qspi_status_t dual_disable(Qspi &qspi)
|
||||
static qspi_status_t dual_disable(Qspi &qspi)
|
||||
{
|
||||
#ifdef DUAL_DISABLE
|
||||
DUAL_DISABLE();
|
||||
#else
|
||||
QUAD_DISABLE();
|
||||
return QSPI_STATUS_OK;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
qspi_status_t quad_enable(Qspi &qspi)
|
||||
static qspi_status_t quad_enable(Qspi &qspi)
|
||||
{
|
||||
#ifdef QUAD_ENABLE
|
||||
QUAD_ENABLE();
|
||||
#else
|
||||
return QSPI_STATUS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
qspi_status_t quad_disable(Qspi &qspi)
|
||||
static qspi_status_t quad_disable(Qspi &qspi)
|
||||
{
|
||||
#ifdef QUAD_DISABLE
|
||||
QUAD_DISABLE();
|
||||
#else
|
||||
return QSPI_STATUS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
qspi_status_t fast_mode_enable(Qspi &qspi)
|
||||
{
|
||||
#ifdef FAST_MODE_ENABLE
|
||||
FAST_MODE_ENABLE();
|
||||
#else
|
||||
return QSPI_STATUS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool is_dual_cmd(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width)
|
||||
qspi_status_t fast_mode_disable(Qspi &qspi)
|
||||
{
|
||||
return (inst_width == QSPI_CFG_BUS_DUAL) || (addr_width == QSPI_CFG_BUS_DUAL) || (data_width == QSPI_CFG_BUS_DUAL);
|
||||
#ifdef FAST_MODE_DISABLE
|
||||
FAST_MODE_DISABLE();
|
||||
#else
|
||||
return QSPI_STATUS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool is_quad_cmd(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width)
|
||||
bool is_extended_mode(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width)
|
||||
{
|
||||
return (inst_width == QSPI_CFG_BUS_QUAD) || (addr_width == QSPI_CFG_BUS_QUAD) || (data_width == QSPI_CFG_BUS_QUAD);
|
||||
return (inst_width == QSPI_CFG_BUS_SINGLE) && ((addr_width != QSPI_CFG_BUS_SINGLE) || (data_width != QSPI_CFG_BUS_SINGLE));
|
||||
}
|
||||
|
||||
bool is_dual_mode(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width)
|
||||
{
|
||||
return (inst_width == QSPI_CFG_BUS_DUAL) && (addr_width == QSPI_CFG_BUS_DUAL) && (data_width == QSPI_CFG_BUS_DUAL);
|
||||
}
|
||||
|
||||
bool is_quad_mode(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width)
|
||||
{
|
||||
return (inst_width == QSPI_CFG_BUS_QUAD) && (addr_width == QSPI_CFG_BUS_QUAD) && (data_width == QSPI_CFG_BUS_QUAD);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
qspi_bus_width_t alt_width, qspi_address_size_t addr_size, qspi_alt_size_t alt_size,
|
||||
int dummy_cycles = 0);
|
||||
|
||||
void set_dummy_cycles(int dummy_cycles);
|
||||
|
||||
void build(int instruction, int address = QSPI_NONE, int alt = QSPI_NONE);
|
||||
|
||||
qspi_command_t *get();
|
||||
|
@ -51,8 +53,10 @@ struct Qspi {
|
|||
#define MODE_1_1_1 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE
|
||||
#define MODE_1_1_2 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL
|
||||
#define MODE_1_2_2 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL
|
||||
#define MODE_1_1_4 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_SINGLE
|
||||
#define MODE_2_2_2 QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL, QSPI_CFG_BUS_DUAL
|
||||
#define MODE_1_1_4 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD
|
||||
#define MODE_1_4_4 QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD
|
||||
#define MODE_4_4_4 QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD, QSPI_CFG_BUS_QUAD
|
||||
|
||||
#define WRITE_1_1_1 MODE_1_1_1, QSPI_CMD_WRITE_1IO
|
||||
#ifdef QSPI_CMD_WRITE_2IO
|
||||
|
@ -61,6 +65,12 @@ struct Qspi {
|
|||
#ifdef QSPI_CMD_WRITE_4IO
|
||||
#define WRITE_1_4_4 MODE_1_4_4, QSPI_CMD_WRITE_4IO
|
||||
#endif
|
||||
#ifdef QSPI_CMD_WRITE_DPI
|
||||
#define WRITE_2_2_2 MODE_2_2_2, QSPI_CMD_WRITE_DPI
|
||||
#endif
|
||||
#ifdef QSPI_CMD_WRITE_QPI
|
||||
#define WRITE_4_4_4 MODE_4_4_4, QSPI_CMD_WRITE_QPI
|
||||
#endif
|
||||
|
||||
|
||||
#define READ_1_1_1 MODE_1_1_1, QSPI_CMD_READ_1IO, QSPI_READ_1IO_DUMMY_CYCLE
|
||||
|
@ -68,7 +78,12 @@ struct Qspi {
|
|||
#define READ_1_2_2 MODE_1_2_2, QSPI_CMD_READ_2IO, QSPI_READ_2IO_DUMMY_CYCLE
|
||||
#define READ_1_1_4 MODE_1_1_4, QSPI_CMD_READ_1I4O, QSPI_READ_1I4O_DUMMY_CYCLE
|
||||
#define READ_1_4_4 MODE_1_4_4, QSPI_CMD_READ_4IO, QSPI_READ_4IO_DUMMY_CYCLE
|
||||
|
||||
#ifdef QSPI_CMD_READ_DPI
|
||||
#define READ_2_2_2 MODE_2_2_2, QSPI_CMD_READ_DPI, QSPI_READ_2IO_DUMMY_CYCLE
|
||||
#endif
|
||||
#ifdef QSPI_CMD_READ_QPI
|
||||
#define READ_4_4_4 MODE_4_4_4, QSPI_CMD_READ_QPI, QSPI_READ_4IO_DUMMY_CYCLE
|
||||
#endif
|
||||
|
||||
#define ADDR_SIZE_8 QSPI_CFG_ADDR_SIZE_8
|
||||
#define ADDR_SIZE_16 QSPI_CFG_ADDR_SIZE_16
|
||||
|
@ -120,26 +135,21 @@ QspiStatus flash_wait_for(uint32_t time_us, Qspi &qspi);
|
|||
void flash_init(Qspi &qspi);
|
||||
|
||||
qspi_status_t write_enable(Qspi &qspi);
|
||||
|
||||
qspi_status_t write_disable(Qspi &qspi);
|
||||
|
||||
void log_register(uint32_t cmd, uint32_t reg_size, Qspi &qspi, const char *str = NULL);
|
||||
|
||||
qspi_status_t dual_enable(Qspi &qspi);
|
||||
|
||||
qspi_status_t dual_disable(Qspi &qspi);
|
||||
|
||||
qspi_status_t quad_enable(Qspi &qspi);
|
||||
|
||||
qspi_status_t quad_disable(Qspi &qspi);
|
||||
qspi_status_t mode_enable(Qspi &qspi, qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
|
||||
qspi_status_t mode_disable(Qspi &qspi, qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
|
||||
|
||||
qspi_status_t fast_mode_enable(Qspi &qspi);
|
||||
qspi_status_t fast_mode_disable(Qspi &qspi);
|
||||
|
||||
qspi_status_t erase(uint32_t erase_cmd, uint32_t flash_addr, Qspi &qspi);
|
||||
|
||||
bool is_dual_cmd(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
|
||||
|
||||
bool is_quad_cmd(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
|
||||
bool is_extended_mode(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
|
||||
bool is_dual_mode(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
|
||||
bool is_quad_mode(qspi_bus_width_t inst_width, qspi_bus_width_t addr_width, qspi_bus_width_t data_width);
|
||||
|
||||
#define WAIT_FOR(timeout, q) TEST_ASSERT_EQUAL_MESSAGE(sOK, flash_wait_for(timeout, q), "flash_wait_for failed!!!")
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
static char info[512] = {0};
|
||||
|
||||
/* The following ticker frequencies are possible:
|
||||
* high frequency ticker: 250 KHz (1 tick per 4 us) - 8 Mhz (1 tick per 1/8 us)
|
||||
* low power ticker: 8 KHz (1 tick per 125 us) - 64 KHz (1 tick per ~15.6 us)
|
||||
|
@ -140,6 +142,11 @@ void sleep_usticker_test()
|
|||
|
||||
const ticker_irq_handler_type us_ticker_irq_handler_org = set_us_ticker_irq_handler(us_ticker_isr);
|
||||
|
||||
/* Give some time Green Tea to finish UART transmission before entering
|
||||
* sleep mode.
|
||||
*/
|
||||
busy_wait_ms(SERIAL_FLUSH_TIME_MS);
|
||||
|
||||
/* Test only sleep functionality. */
|
||||
sleep_manager_lock_deep_sleep();
|
||||
TEST_ASSERT_FALSE_MESSAGE(sleep_manager_can_deep_sleep(), "deep sleep should be locked");
|
||||
|
@ -147,7 +154,8 @@ void sleep_usticker_test()
|
|||
/* Testing wake-up time 10 us. */
|
||||
for (timestamp_t i = 100; i < 1000; i += 100) {
|
||||
/* note: us_ticker_read() operates on ticks. */
|
||||
const timestamp_t next_match_timestamp = overflow_protect(us_ticker_read() + us_to_ticks(i, ticker_freq),
|
||||
const timestamp_t start_timestamp = us_ticker_read();
|
||||
const timestamp_t next_match_timestamp = overflow_protect(start_timestamp + us_to_ticks(i, ticker_freq),
|
||||
ticker_width);
|
||||
|
||||
us_ticker_set_interrupt(next_match_timestamp);
|
||||
|
@ -156,9 +164,11 @@ void sleep_usticker_test()
|
|||
|
||||
const unsigned int wakeup_timestamp = us_ticker_read();
|
||||
|
||||
TEST_ASSERT(
|
||||
compare_timestamps(us_to_ticks(sleep_mode_delta_us, ticker_freq), ticker_width, next_match_timestamp,
|
||||
wakeup_timestamp));
|
||||
sprintf(info, "Delta ticks: %u, Ticker width: %u, Expected wake up tick: %d, Actual wake up tick: %d, delay ticks: %d, wake up after ticks: %d",
|
||||
us_to_ticks(sleep_mode_delta_us, ticker_freq), ticker_width, next_match_timestamp, wakeup_timestamp, us_to_ticks(i, ticker_freq) , wakeup_timestamp - start_timestamp);
|
||||
|
||||
TEST_ASSERT_MESSAGE(compare_timestamps(us_to_ticks(sleep_mode_delta_us, ticker_freq),
|
||||
ticker_width, next_match_timestamp, wakeup_timestamp), info);
|
||||
}
|
||||
|
||||
set_us_ticker_irq_handler(us_ticker_irq_handler_org);
|
||||
|
@ -189,7 +199,8 @@ void deepsleep_lpticker_test()
|
|||
/* Testing wake-up time 10 ms. */
|
||||
for (timestamp_t i = 20000; i < 200000; i += 20000) {
|
||||
/* note: lp_ticker_read() operates on ticks. */
|
||||
const timestamp_t next_match_timestamp = overflow_protect(lp_ticker_read() + us_to_ticks(i, ticker_freq), ticker_width);
|
||||
const timestamp_t start_timestamp = lp_ticker_read();
|
||||
const timestamp_t next_match_timestamp = overflow_protect(start_timestamp + us_to_ticks(i, ticker_freq), ticker_width);
|
||||
|
||||
lp_ticker_set_interrupt(next_match_timestamp);
|
||||
|
||||
|
@ -197,7 +208,11 @@ void deepsleep_lpticker_test()
|
|||
|
||||
const timestamp_t wakeup_timestamp = lp_ticker_read();
|
||||
|
||||
TEST_ASSERT(compare_timestamps(us_to_ticks(deepsleep_mode_delta_us, ticker_freq), ticker_width, next_match_timestamp, wakeup_timestamp));
|
||||
sprintf(info, "Delta ticks: %u, Ticker width: %u, Expected wake up tick: %d, Actual wake up tick: %d, delay ticks: %d, wake up after ticks: %d",
|
||||
us_to_ticks(deepsleep_mode_delta_us, ticker_freq), ticker_width, next_match_timestamp, wakeup_timestamp, us_to_ticks(i, ticker_freq) , wakeup_timestamp - start_timestamp);
|
||||
|
||||
TEST_ASSERT_MESSAGE(compare_timestamps(us_to_ticks(deepsleep_mode_delta_us, ticker_freq), ticker_width,
|
||||
next_match_timestamp, wakeup_timestamp), info);
|
||||
}
|
||||
|
||||
set_lp_ticker_irq_handler(lp_ticker_irq_handler_org);
|
||||
|
@ -240,8 +255,12 @@ void deepsleep_high_speed_clocks_turned_off_test()
|
|||
|
||||
TEST_ASSERT_UINT32_WITHIN(1000, 0, ticks_to_us(us_ticks_diff, us_ticker_freq));
|
||||
|
||||
sprintf(info, "Delta ticks: %u, Ticker width: %u, Expected wake up tick: %d, Actual wake up tick: %d",
|
||||
us_to_ticks(deepsleep_mode_delta_us, lp_ticker_freq), lp_ticker_width, wakeup_time, lp_ticks_after_sleep);
|
||||
|
||||
/* Check if we have woken-up after expected time. */
|
||||
TEST_ASSERT(compare_timestamps(us_to_ticks(deepsleep_mode_delta_us, lp_ticker_freq), lp_ticker_width, wakeup_time, lp_ticks_after_sleep));
|
||||
TEST_ASSERT_MESSAGE(compare_timestamps(us_to_ticks(deepsleep_mode_delta_us, lp_ticker_freq), lp_ticker_width,
|
||||
wakeup_time, lp_ticks_after_sleep), info);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
* Copyright (c) 2018 ARM Limited. All rights reserved.
|
||||
* 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 "base64b.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static char IntToBase64Char(uint8_t intVal)
|
||||
{
|
||||
const char *base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
return base64Digits[intVal & 0x3F];
|
||||
}
|
||||
|
||||
#define BASE_64_PAD 0xFF
|
||||
static base64_result_e Base64CharToInt(char base64, uint8_t *intVal)
|
||||
{
|
||||
if (NULL == intVal) {
|
||||
return BASE64_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if ((base64 >= 'A') && (base64 <= 'Z')) {
|
||||
*intVal = base64 - 'A' ;
|
||||
} else if ((base64 >= 'a') && (base64 <= 'z')) {
|
||||
*intVal = base64 - 'a' + 26;
|
||||
} else if ((base64 >= '0') && (base64 <= '9')) {
|
||||
*intVal = base64 - '0' + 52;
|
||||
} else if (base64 == '+') {
|
||||
*intVal = 62;
|
||||
} else if (base64 == '/') {
|
||||
*intVal = 63;
|
||||
} else if (base64 == '=') {
|
||||
*intVal = BASE_64_PAD;
|
||||
} else {
|
||||
return BASE64_ERROR;
|
||||
}
|
||||
|
||||
return BASE64_SUCCESS;
|
||||
}
|
||||
|
||||
base64_result_e trng_DecodeNBase64(const char *string,
|
||||
uint32_t stringMaxSize,
|
||||
void *buffer,
|
||||
uint32_t bufferSize,
|
||||
uint32_t *lengthWritten,
|
||||
uint32_t *charsProcessed)
|
||||
{
|
||||
base64_result_e result = BASE64_SUCCESS;
|
||||
uint32_t bitOffset = 0;
|
||||
uint8_t *writePtr = (uint8_t *)buffer;
|
||||
uint8_t *bufferEnd = (uint8_t *)buffer + bufferSize;
|
||||
uint8_t tempVal = 0;
|
||||
uint32_t currPos = 0;
|
||||
uint32_t localBytesWritten = 0;
|
||||
uint32_t localCharsProcessed = 0;
|
||||
bool isEndOfString = false;
|
||||
|
||||
if ((NULL == string) || (NULL == buffer) || (bufferSize == 0)) {
|
||||
return BASE64_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*writePtr = 0;
|
||||
while (( currPos < stringMaxSize ) &&
|
||||
( string[currPos] != 0 ) &&
|
||||
( writePtr < bufferEnd ) &&
|
||||
( !isEndOfString )) {
|
||||
uint8_t val;
|
||||
|
||||
if (string[currPos] == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
result = Base64CharToInt(string[currPos++], &val);
|
||||
if (result != BASE64_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (val != BASE_64_PAD) {
|
||||
if (bitOffset <= 2) {
|
||||
tempVal |= val << (2 - bitOffset);
|
||||
if (bitOffset == 2) {
|
||||
*writePtr++ = tempVal;
|
||||
tempVal = 0;
|
||||
}
|
||||
} else {
|
||||
*writePtr++ = (uint8_t)(tempVal | (val >> (bitOffset - 2)));
|
||||
tempVal = (uint8_t)(val << (10 - bitOffset));
|
||||
}
|
||||
} else { // found BASE_64_PAD
|
||||
// At most two pad characters may occur at the end of the encoded stream
|
||||
if (bitOffset == 2) {
|
||||
isEndOfString = true; // The last padding byte has been processed.
|
||||
} else if (bitOffset != 4) {
|
||||
return BASE64_ERROR; // Incorrect padding
|
||||
}
|
||||
}
|
||||
|
||||
bitOffset = (bitOffset + 6) & 0x7;
|
||||
if (bitOffset == 0) {
|
||||
localBytesWritten = (uint32_t)(writePtr - (uint8_t *)buffer);
|
||||
localCharsProcessed = currPos;
|
||||
}
|
||||
}
|
||||
if (charsProcessed == NULL) {
|
||||
localBytesWritten = (uint32_t)(writePtr - (uint8_t *)buffer);
|
||||
} else {
|
||||
*charsProcessed = localCharsProcessed;
|
||||
}
|
||||
if (lengthWritten != NULL) {
|
||||
*lengthWritten = localBytesWritten;
|
||||
} else if (bufferSize != localBytesWritten) {
|
||||
return BASE64_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
// Check if additional bytes should have been processed but buffer isn't sufficient.
|
||||
if (( result == BASE64_SUCCESS ) &&
|
||||
( !isEndOfString ) &&
|
||||
( currPos < stringMaxSize ) &&
|
||||
( string[currPos] != 0 ) &&
|
||||
( string[currPos] != '=' ) ) {
|
||||
return BASE64_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (result != BASE64_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return BASE64_SUCCESS;
|
||||
}
|
||||
|
||||
base64_result_e trng_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize)
|
||||
{
|
||||
uint32_t bitOffset = 0;
|
||||
|
||||
const uint8_t *readPtr = (const uint8_t *)buffer;
|
||||
const uint8_t *bufferEnd = (const uint8_t *)buffer + bufferSize;
|
||||
|
||||
char *writePtr = string;
|
||||
char *stringEnd = string + stringSize - 1;
|
||||
|
||||
if ((NULL == string) || (NULL == buffer) || (stringSize == 0)) {
|
||||
return BASE64_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
stringSize--;
|
||||
while (readPtr < bufferEnd && writePtr < stringEnd) {
|
||||
uint8_t tempVal = 0;
|
||||
switch (bitOffset) {
|
||||
case 0:
|
||||
*writePtr++ = IntToBase64Char(*readPtr >> 2); // take upper 6 bits
|
||||
break;
|
||||
case 6:
|
||||
tempVal = *readPtr++ << 4;
|
||||
if (readPtr < bufferEnd) {
|
||||
tempVal |= *readPtr >> 4;
|
||||
}
|
||||
*writePtr++ = IntToBase64Char(tempVal);
|
||||
break;
|
||||
case 4:
|
||||
tempVal = *readPtr++ << 2;
|
||||
if (readPtr < bufferEnd) {
|
||||
tempVal |= *readPtr >> 6;
|
||||
}
|
||||
*writePtr++ = IntToBase64Char(tempVal);
|
||||
break;
|
||||
case 2:
|
||||
*writePtr++ = IntToBase64Char(*readPtr++);
|
||||
break;
|
||||
default:
|
||||
return BASE64_ERROR; // we should never reach this code.
|
||||
}
|
||||
bitOffset = (bitOffset + 6) & 0x7;
|
||||
}
|
||||
while (bitOffset > 0 && writePtr < stringEnd) {
|
||||
*writePtr++ = '=';
|
||||
bitOffset = (bitOffset + 6) & 0x7;
|
||||
}
|
||||
*writePtr = 0;
|
||||
|
||||
if ((readPtr < bufferEnd) || (bitOffset != 0)) {
|
||||
return (BASE64_BUFFER_TOO_SMALL);
|
||||
}
|
||||
|
||||
return (BASE64_SUCCESS);
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2018 ARM Limited. All rights reserved.
|
||||
* 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 <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
typedef enum {
|
||||
BASE64_SUCCESS = 0,
|
||||
BASE64_INVALID_PARAMETER = 1,
|
||||
BASE64_BUFFER_TOO_SMALL = 2,
|
||||
BASE64_ERROR = 3,
|
||||
} base64_result_e;
|
||||
|
||||
base64_result_e trng_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize);
|
||||
base64_result_e trng_DecodeNBase64(const char *string, uint32_t stringMaxSize, void *buffer, uint32_t bufferSize,
|
||||
uint32_t *lengthWritten, uint32_t *charsProcessed);
|
||||
|
||||
|
|
@ -0,0 +1,247 @@
|
|||
/*
|
||||
* Copyright (c) 2018 ARM Limited. All rights reserved.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The test is based on the assumption that trng will generate random data, random so
|
||||
* there will not be any similar patterns in it, that kind of data will be impossible to
|
||||
* compress, if compression will occur the test will result in failure.
|
||||
*
|
||||
* The test is composed out of three parts:
|
||||
* the first, generate a trng buffer and try to compress it, at the end of first part
|
||||
* we will reset the device.
|
||||
* In second part we will generate a trng buffer with a different buffer size and try to
|
||||
* compress it.
|
||||
* In the third part we will again generate a trng buffer to see that the same trng output
|
||||
* is not generated as the stored trng buffer from part one (before reseting), the new trng data will
|
||||
* be concatenated to the trng data from the first part and then try to compress it
|
||||
* together, if there are similar patterns the compression will succeed.
|
||||
*
|
||||
* We need to store and load the first part data before and after reset, the mechanism
|
||||
* we will use is the mbed greentea platform for sending and receving the data from the device
|
||||
* to the host running the test and back, the problem with this mechanism is that it doesn't
|
||||
* handle well certain characters, especially non ASCII ones, so we use the base64 algorithm
|
||||
* to ensure all characters will be transmitted correctly.
|
||||
*/
|
||||
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest/utest.h"
|
||||
#include "hal/trng_api.h"
|
||||
#include "base64b.h"
|
||||
#include "pithy.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if !DEVICE_TRNG
|
||||
#error [NOT_SUPPORTED] TRNG API not supported for this target
|
||||
#endif
|
||||
|
||||
#define MSG_VALUE_DUMMY "0"
|
||||
#define MSG_VALUE_LEN 64
|
||||
#define MSG_KEY_LEN 32
|
||||
|
||||
#define BUFFER_LEN (MSG_VALUE_LEN/2)
|
||||
|
||||
#define MSG_TRNG_READY "ready"
|
||||
#define MSG_TRNG_BUFFER "buffer"
|
||||
#define MSG_TRNG_EXIT "exit"
|
||||
|
||||
#define MSG_TRNG_TEST_STEP1 "check_step1"
|
||||
#define MSG_TRNG_TEST_STEP2 "check_step2"
|
||||
#define MSG_TRNG_TEST_SUITE_ENDED "Test_suite_ended"
|
||||
|
||||
#define RESULT_SUCCESS 0
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
static int fill_buffer_trng(uint8_t *buffer, trng_t *trng_obj, size_t trng_len)
|
||||
{
|
||||
size_t temp_size = 0, output_length = 0;
|
||||
int trng_res = 0;
|
||||
uint8_t *temp_in_buf = buffer;
|
||||
|
||||
trng_init(trng_obj);
|
||||
memset(buffer, 0, BUFFER_LEN);
|
||||
|
||||
while (true) {
|
||||
trng_res = trng_get_bytes(trng_obj, temp_in_buf, trng_len - temp_size, &output_length);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(0, trng_res, "trng_get_bytes error!");
|
||||
temp_size += output_length;
|
||||
temp_in_buf += output_length;
|
||||
if (temp_size >= trng_len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
temp_in_buf = NULL;
|
||||
trng_free(trng_obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_array(uint8_t *buffer, size_t size)
|
||||
{
|
||||
for (size_t i=0; i < size; i++) {
|
||||
utest_printf("%02x", buffer[i]);
|
||||
}
|
||||
utest_printf("\n");
|
||||
}
|
||||
|
||||
static void compress_and_compare(char *key, char *value)
|
||||
{
|
||||
trng_t trng_obj;
|
||||
uint8_t *out_comp_buf, *buffer;
|
||||
uint8_t *input_buf, *temp_buf;
|
||||
size_t comp_sz = 0;
|
||||
unsigned int result = 0;
|
||||
|
||||
#define OUT_COMP_BUF_SIZE ((BUFFER_LEN * 5) + 32)
|
||||
#define TEMP_BUF_SIZE (BUFFER_LEN * 2)
|
||||
|
||||
out_comp_buf = new uint8_t[OUT_COMP_BUF_SIZE];
|
||||
buffer = new uint8_t[BUFFER_LEN];
|
||||
temp_buf = new uint8_t[BUFFER_LEN * 2];
|
||||
input_buf = new uint8_t[BUFFER_LEN * 4];
|
||||
|
||||
/*At the begining of step 2 load trng buffer from step 1*/
|
||||
if (strcmp(key, MSG_TRNG_TEST_STEP2) == 0) {
|
||||
/*Using base64 to decode data sent from host*/
|
||||
uint32_t lengthWritten = 0;
|
||||
uint32_t charsProcessed = 0;
|
||||
result = trng_DecodeNBase64((const char *)value,
|
||||
MSG_VALUE_LEN,
|
||||
buffer,
|
||||
BUFFER_LEN,
|
||||
&lengthWritten,
|
||||
&charsProcessed);
|
||||
TEST_ASSERT_EQUAL(0, result);
|
||||
memcpy(input_buf, buffer, BUFFER_LEN);
|
||||
}
|
||||
|
||||
if (strcmp(key, MSG_TRNG_TEST_STEP1) == 0) {
|
||||
/*Fill buffer with trng values*/
|
||||
result = fill_buffer_trng(buffer, &trng_obj, BUFFER_LEN);
|
||||
TEST_ASSERT_EQUAL(0, result);
|
||||
memcpy(input_buf, buffer, BUFFER_LEN);
|
||||
}
|
||||
/*pithy_Compress will try to compress the random data, if it succeeded it means the data is not really random*/
|
||||
else if (strcmp(key, MSG_TRNG_TEST_STEP2) == 0) {
|
||||
|
||||
comp_sz = pithy_Compress((char *)buffer,
|
||||
BUFFER_LEN,
|
||||
(char *)out_comp_buf,
|
||||
OUT_COMP_BUF_SIZE,
|
||||
9);
|
||||
if (comp_sz <= BUFFER_LEN){
|
||||
print_array(buffer, BUFFER_LEN);
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(comp_sz > BUFFER_LEN,
|
||||
"TRNG_TEST_STEP1: trng_get_bytes was able to compress thus not random");
|
||||
|
||||
/*pithy_Compress will try to compress the random data with a different buffer size*/
|
||||
result = fill_buffer_trng(temp_buf, &trng_obj, TEMP_BUF_SIZE);
|
||||
TEST_ASSERT_EQUAL(0, result);
|
||||
|
||||
comp_sz = pithy_Compress((char *)temp_buf,
|
||||
TEMP_BUF_SIZE,
|
||||
(char *)out_comp_buf,
|
||||
OUT_COMP_BUF_SIZE,
|
||||
9);
|
||||
if (comp_sz <= TEMP_BUF_SIZE){
|
||||
print_array(temp_buf, TEMP_BUF_SIZE);
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(comp_sz > TEMP_BUF_SIZE,
|
||||
"TRNG_TEST_STEP2: trng_get_bytes was able to compress thus not random");
|
||||
|
||||
memcpy(input_buf + BUFFER_LEN, temp_buf, TEMP_BUF_SIZE);
|
||||
/*pithy_Compress will try to compress the random data from before reset concatenated with new random data*/
|
||||
comp_sz = pithy_Compress((char *)input_buf,
|
||||
TEMP_BUF_SIZE + BUFFER_LEN,
|
||||
(char *)out_comp_buf,
|
||||
OUT_COMP_BUF_SIZE,
|
||||
9);
|
||||
if (comp_sz <= TEMP_BUF_SIZE + BUFFER_LEN){
|
||||
print_array(input_buf, TEMP_BUF_SIZE + BUFFER_LEN);
|
||||
}
|
||||
TEST_ASSERT_MESSAGE(comp_sz > TEMP_BUF_SIZE + BUFFER_LEN,
|
||||
"TRNG_TEST_STEP3: concatenated buffer after reset was able to compress thus not random");
|
||||
|
||||
greentea_send_kv(MSG_TRNG_TEST_SUITE_ENDED, MSG_VALUE_DUMMY);
|
||||
}
|
||||
|
||||
/*At the end of step 1 store trng buffer and reset the device*/
|
||||
if (strcmp(key, MSG_TRNG_TEST_STEP1) == 0) {
|
||||
int result = 0;
|
||||
/*Using base64 to encode data sending from host*/
|
||||
result = trng_EncodeBase64(buffer,
|
||||
BUFFER_LEN,
|
||||
(char *)out_comp_buf,
|
||||
OUT_COMP_BUF_SIZE);
|
||||
TEST_ASSERT_EQUAL(RESULT_SUCCESS, result);
|
||||
|
||||
greentea_send_kv(MSG_TRNG_BUFFER, (const char *)out_comp_buf);
|
||||
}
|
||||
|
||||
delete[] out_comp_buf;
|
||||
delete[] buffer;
|
||||
delete[] input_buf;
|
||||
delete[] temp_buf;
|
||||
}
|
||||
|
||||
/*This method call first and second steps, it directs by the key received from the host*/
|
||||
void trng_test()
|
||||
{
|
||||
greentea_send_kv(MSG_TRNG_READY, MSG_VALUE_DUMMY);
|
||||
|
||||
char key[MSG_KEY_LEN + 1] = { };
|
||||
char *value = new char[MSG_VALUE_LEN + 1];
|
||||
do {
|
||||
memset(key, 0, MSG_KEY_LEN + 1);
|
||||
memset(value, 0, MSG_VALUE_LEN + 1);
|
||||
|
||||
greentea_parse_kv(key, value, MSG_KEY_LEN, MSG_VALUE_LEN);
|
||||
|
||||
if (strcmp(key, MSG_TRNG_TEST_STEP1) == 0) {
|
||||
/*create trng data buffer and try to compress it, store it for later checks*/
|
||||
compress_and_compare(key, value);
|
||||
}
|
||||
|
||||
if (strcmp(key, MSG_TRNG_TEST_STEP2) == 0) {
|
||||
/*create another trng data buffer and concatenate it to the stored trng data buffer
|
||||
try to compress them both*/
|
||||
compress_and_compare(key, value);
|
||||
}
|
||||
} while (strcmp(key, MSG_TRNG_EXIT) != 0);
|
||||
|
||||
delete[] value;
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("TRNG: trng_test", trng_test),
|
||||
};
|
||||
|
||||
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(100, "trng_reset");
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
|
||||
|
||||
int main()
|
||||
{
|
||||
bool ret = !Harness::run(specification);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -0,0 +1,795 @@
|
|||
//
|
||||
// pithy.c
|
||||
// http://github.com/johnezang/pithy
|
||||
// Licensed under the terms of the BSD License, as specified below.
|
||||
//
|
||||
|
||||
/*
|
||||
Copyright (c) 2011, John Engelhart
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the Zang Industries nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__arm__) && defined(__ARM_NEON__)
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
#include "pithy.h"
|
||||
|
||||
#define kBlockLog 20ul
|
||||
#define kBlockSize ((size_t)(1 << kBlockLog))
|
||||
|
||||
// The maximum size that can be compressed while still allowing for the worst case compression expansion.
|
||||
#define PITHY_UNCOMPRESSED_MAX_LENGTH 0xdb6db6bfu // 0xdb6db6bf == 3681400511, or 3510.857 Mbytes.
|
||||
|
||||
typedef const char *pithy_hashOffset_t;
|
||||
|
||||
enum {
|
||||
PITHY_LITERAL = 0,
|
||||
PITHY_COPY_1_BYTE_OFFSET = 1,
|
||||
PITHY_COPY_2_BYTE_OFFSET = 2,
|
||||
PITHY_COPY_3_BYTE_OFFSET = 3
|
||||
};
|
||||
|
||||
|
||||
#if defined (__GNUC__) && (__GNUC__ >= 3)
|
||||
#define PITHY_ATTRIBUTES(attr, ...) __attribute__((attr, ##__VA_ARGS__))
|
||||
#define PITHY_EXPECTED(cond, expect) __builtin_expect((long)(cond), (expect))
|
||||
#define PITHY_EXPECT_T(cond) PITHY_EXPECTED(cond, 1u)
|
||||
#define PITHY_EXPECT_F(cond) PITHY_EXPECTED(cond, 0u)
|
||||
#define PITHY_PREFETCH(ptr) __builtin_prefetch(ptr)
|
||||
#else // defined (__GNUC__) && (__GNUC__ >= 3)
|
||||
#define PITHY_ATTRIBUTES(attr, ...)
|
||||
#define PITHY_EXPECTED(cond, expect) (cond)
|
||||
#define PITHY_EXPECT_T(cond) (cond)
|
||||
#define PITHY_EXPECT_F(cond) (cond)
|
||||
#define PITHY_PREFETCH(ptr)
|
||||
#endif // defined (__GNUC__) && (__GNUC__ >= 3)
|
||||
|
||||
#define PITHY_STATIC_INLINE static inline PITHY_ATTRIBUTES(always_inline)
|
||||
#define PITHY_ALIGNED(x) PITHY_ATTRIBUTES(aligned(x))
|
||||
|
||||
#if defined(NS_BLOCK_ASSERTIONS) && !defined(NDEBUG)
|
||||
#define NDEBUG
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define DCHECK(condition)
|
||||
#else
|
||||
#define DCHECK(condition) do { \
|
||||
if(PITHY_EXPECT_F(!(condition))) { \
|
||||
fprintf(stderr, "%s / %s @ %ld: Invalid parameter not satisfying: %s", \
|
||||
__FILE__, __PRETTY_FUNCTION__, (long)__LINE__, #condition); fflush(stderr); \
|
||||
abort(); \
|
||||
} \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
PITHY_STATIC_INLINE const char *pithy_Parse32WithLimit(const char *p, const char *l, size_t *OUTPUT);
|
||||
PITHY_STATIC_INLINE char *pithy_Encode32(char *ptr, uint32_t v);
|
||||
|
||||
PITHY_STATIC_INLINE uint32_t pithy_GetUint32AtOffset(uint64_t v, uint32_t offset);
|
||||
PITHY_STATIC_INLINE uint32_t pithy_HashBytes(uint32_t bytes, uint32_t shift);
|
||||
PITHY_STATIC_INLINE size_t pithy_FindMatchLength(const char *s1, const char *s2, const char *s2_limit);
|
||||
PITHY_STATIC_INLINE char *pithy_EmitLiteral(char *op, const char *literal, size_t len, int allow_fast_path);
|
||||
PITHY_STATIC_INLINE char *pithy_EmitCopyGreaterThan63(char *op, size_t offset, size_t len);
|
||||
PITHY_STATIC_INLINE char *pithy_EmitCopyLessThan63(char *op, size_t offset, size_t len);
|
||||
PITHY_STATIC_INLINE char *pithy_EmitCopy(char *op, size_t offset, size_t len);
|
||||
|
||||
PITHY_STATIC_INLINE uint16_t pithy_Load16(const void *p) { uint16_t t; memcpy(&t, p, sizeof(t)); return (t); }
|
||||
PITHY_STATIC_INLINE uint32_t pithy_Load32(const void *p) { uint32_t t; memcpy(&t, p, sizeof(t)); return (t); }
|
||||
PITHY_STATIC_INLINE uint64_t pithy_Load64(const void *p) { uint64_t t; memcpy(&t, p, sizeof(t)); return (t); }
|
||||
PITHY_STATIC_INLINE void pithy_Store16(void *p, uint16_t v) { memcpy(p, &v, sizeof(v)); }
|
||||
PITHY_STATIC_INLINE void pithy_Store32(void *p, uint32_t v) { memcpy(p, &v, sizeof(v)); }
|
||||
PITHY_STATIC_INLINE void pithy_Store64(void *p, uint64_t v) { memcpy(p, &v, sizeof(v)); }
|
||||
|
||||
#define pithy_Move64(dst,src) pithy_Store64(dst, pithy_Load64(src));
|
||||
#define pithy_Move128(dst,src) pithy_Move64(dst, src); pithy_Move64(dst + 8ul, src + 8ul);
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <stdlib.h>
|
||||
#define pithy_bswap_16(x) _byteswap_ushort(x)
|
||||
#define pithy_bswap_32(x) _byteswap_ulong(x)
|
||||
#define pithy_bswap_64(x) _byteswap_uint64(x)
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
// Mac OS X / Darwin features
|
||||
#include <libkern/OSByteOrder.h>
|
||||
#define pithy_bswap_16(x) OSSwapInt16(x)
|
||||
#define pithy_bswap_32(x) OSSwapInt32(x)
|
||||
#define pithy_bswap_64(x) OSSwapInt64(x)
|
||||
#else
|
||||
#include <byteswap.h>
|
||||
#endif
|
||||
|
||||
#endif // __BIG_ENDIAN__
|
||||
|
||||
// Conversion functions.
|
||||
#ifdef __BIG_ENDIAN__
|
||||
#define pithy_FromHost16(x) ((uint16_t)pithy_bswap_16(x))
|
||||
#define pithy_ToHost16(x) ((uint16_t)pithy_bswap_16(x))
|
||||
#define pithy_FromHost32(x) ((uint32_t)pithy_bswap_32(x))
|
||||
#define pithy_ToHost32(x) ((uint32_t)pithy_bswap_32(x))
|
||||
#define pithy_IsLittleEndian() (0)
|
||||
|
||||
#else // !defined(__BIG_ENDIAN__)
|
||||
#define pithy_FromHost16(x) ((uint16_t)(x))
|
||||
#define pithy_ToHost16(x) ((uint16_t)(x))
|
||||
#define pithy_FromHost32(x) ((uint32_t)(x))
|
||||
#define pithy_ToHost32(x) ((uint32_t)(x))
|
||||
#define pithy_IsLittleEndian() (1)
|
||||
|
||||
#endif // !defined(__BIG_ENDIAN__)
|
||||
|
||||
#define pithy_LoadHost16(p) pithy_ToHost16(pithy_Load16((const void *)(p)))
|
||||
#define pithy_StoreHost16(p, v) pithy_Store16((void *)(p), pithy_FromHost16(v))
|
||||
#define pithy_LoadHost32(p) pithy_ToHost32(pithy_Load32((p)))
|
||||
#define pithy_StoreHost32(p, v) pithy_Store32((p), pithy_FromHost32(v))
|
||||
|
||||
PITHY_STATIC_INLINE void pithy_StoreHost24(char *p, uint32_t v)
|
||||
{
|
||||
*p++ = (v & 0xffu);
|
||||
*p++ = ((v >> 8) & 0xffu);
|
||||
*p++ = ((v >> 16) & 0xffu);
|
||||
}
|
||||
|
||||
#if defined (__GNUC__) && (__GNUC__ >= 3)
|
||||
|
||||
#define pithy_Log2Floor(n) ({typeof(n) _n = (n); _n == 0 ? (int)-1 : (int)(31 ^ __builtin_clz(_n));})
|
||||
#define pithy_FindLSBSetNonZero32(n) ((int)__builtin_ctz((uint32_t)(n)))
|
||||
#define pithy_FindLSBSetNonZero64(n) ((int)__builtin_ctzll((uint64_t)(n)))
|
||||
#define pithy_FindMSBSetNonZero32(n) ((int)__builtin_clz((uint32_t)(n)))
|
||||
#define pithy_FindMSBSetNonZero64(n) ((int)__builtin_clzll((uint64_t)(n)))
|
||||
|
||||
#else // Portable versions, !GNUC || GNUC < 3
|
||||
|
||||
PITHY_STATIC_INLINE int pithy_Log2Floor(uint32_t n)
|
||||
{
|
||||
if (n == 0u) {
|
||||
return (-1);
|
||||
}
|
||||
int i = 0, log = 0;
|
||||
uint32_t value = n;
|
||||
for (i = 4; i >= 0; --i) {
|
||||
int shift = (1 << i);
|
||||
uint32_t x = value >> shift;
|
||||
if (x != 0u) {
|
||||
value = x;
|
||||
log += shift;
|
||||
}
|
||||
}
|
||||
DCHECK(value == 1);
|
||||
return (log);
|
||||
}
|
||||
|
||||
PITHY_STATIC_INLINE int pithy_FindLSBSetNonZero32(uint32_t n)
|
||||
{
|
||||
int i = 0, rc = 31, shift = 0;
|
||||
for (i = 4, shift = 1 << 4; i >= 0; --i) {
|
||||
const uint32_t x = n << shift;
|
||||
if (x != 0u) {
|
||||
n = x;
|
||||
rc -= shift;
|
||||
}
|
||||
shift >>= 1;
|
||||
}
|
||||
return (rc);
|
||||
}
|
||||
|
||||
PITHY_STATIC_INLINE int pithy_FindLSBSetNonZero64(uint64_t n)
|
||||
{
|
||||
const uint32_t bottomBits = n;
|
||||
if (bottomBits == 0u) {
|
||||
return (32 + pithy_FindLSBSetNonZero32((n >> 32)));
|
||||
} else {
|
||||
return (pithy_FindLSBSetNonZero32(bottomBits));
|
||||
}
|
||||
}
|
||||
|
||||
PITHY_STATIC_INLINE int pithy_FindMSBSetNonZero32(uint32_t n)
|
||||
{
|
||||
int i;
|
||||
uint32_t x, rc = 32, shift = 1 << 4;
|
||||
for (i = 3; i >= 0; --i) {
|
||||
x = n >> shift;
|
||||
if (x != 0) {
|
||||
rc -= shift;
|
||||
n = x;
|
||||
}
|
||||
shift >>= 1;
|
||||
}
|
||||
x = n >> shift;
|
||||
return (rc - ((x != 0) ? 2 : n));
|
||||
}
|
||||
|
||||
PITHY_STATIC_INLINE int pithy_FindMSBSetNonZero64(uint64_t n)
|
||||
{
|
||||
const uint32_t upperBits = n >> 32;
|
||||
if (upperBits == 0u) {
|
||||
return (32 + pithy_FindMSBSetNonZero32((n)));
|
||||
} else {
|
||||
return (pithy_FindMSBSetNonZero32(upperBits));
|
||||
}
|
||||
}
|
||||
|
||||
#endif // End portable versions.
|
||||
|
||||
PITHY_STATIC_INLINE const char *pithy_Parse32WithLimit(const char *p, const char *l, size_t *resultOut)
|
||||
{
|
||||
const unsigned char *ptr = (const unsigned char *)p, *limit = (const unsigned char *)l;
|
||||
size_t resultShift = 0ul, result = 0ul;
|
||||
uint32_t encodedByte = 0u;
|
||||
|
||||
for (resultShift = 0ul; resultShift <= 28ul; resultShift += 7ul) {
|
||||
if (ptr >= limit) {
|
||||
return (NULL);
|
||||
}
|
||||
encodedByte = *(ptr++);
|
||||
result |= (encodedByte & 127u) << resultShift;
|
||||
if (encodedByte < ((resultShift == 28ul) ? 16u : 128u)) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
done:
|
||||
*resultOut = result;
|
||||
return ((const char *)ptr);
|
||||
}
|
||||
|
||||
PITHY_STATIC_INLINE char *pithy_Encode32(char *sptr, uint32_t v)
|
||||
{
|
||||
unsigned char *ptr = (unsigned char *)sptr;
|
||||
if (v < (1u << 7)) {
|
||||
*(ptr++) = v;
|
||||
} else if (v < (1u << 14)) {
|
||||
*(ptr++) = v | 0x80u;
|
||||
*(ptr++) = (v >> 7);
|
||||
} else if (v < (1u << 21)) {
|
||||
*(ptr++) = v | 0x80u;
|
||||
*(ptr++) = (v >> 7) | 0x80u;
|
||||
*(ptr++) = (v >> 14);
|
||||
} else if (v < (1u << 28)) {
|
||||
*(ptr++) = v | 0x80u;
|
||||
*(ptr++) = (v >> 7) | 0x80u;
|
||||
*(ptr++) = (v >> 14) | 0x80u;
|
||||
*(ptr++) = (v >> 21);
|
||||
} else {
|
||||
*(ptr++) = v | 0x80u;
|
||||
*(ptr++) = (v >> 7) | 0x80u;
|
||||
*(ptr++) = (v >> 14) | 0x80u;
|
||||
*(ptr++) = (v >> 21) | 0x80u;
|
||||
*(ptr++) = (v >> 28);
|
||||
}
|
||||
return ((char *)ptr);
|
||||
}
|
||||
|
||||
|
||||
PITHY_STATIC_INLINE uint32_t pithy_GetUint32AtOffset(uint64_t v, uint32_t offset)
|
||||
{
|
||||
DCHECK(offset <= 4);
|
||||
return (v >> (pithy_IsLittleEndian() ? (8u * offset) : (32u - (8u * offset))));
|
||||
}
|
||||
|
||||
|
||||
PITHY_STATIC_INLINE uint32_t pithy_HashBytes(uint32_t bytes, uint32_t shift)
|
||||
{
|
||||
uint32_t kMul = 0x1e35a7bdU;
|
||||
return ((bytes * kMul) >> shift);
|
||||
}
|
||||
|
||||
|
||||
PITHY_STATIC_INLINE size_t pithy_FindMatchLength(const char *s1, const char *s2, const char *s2_limit)
|
||||
{
|
||||
DCHECK(s2_limit >= s2);
|
||||
const char *ms1 = s1, *ms2 = s2;
|
||||
|
||||
#if defined(__LP64__)
|
||||
while (PITHY_EXPECT_T(ms2 < (s2_limit - 8ul))) {
|
||||
uint64_t x = pithy_Load64(ms1) ^ pithy_Load64(ms2);
|
||||
if (PITHY_EXPECT_F(x == 0ul)) {
|
||||
ms1 += 8ul;
|
||||
ms2 += 8ul;
|
||||
} else {
|
||||
return ((ms1 - s1) + ((unsigned int)(pithy_IsLittleEndian() ? (pithy_FindLSBSetNonZero64(x) >> 3) :
|
||||
(pithy_FindMSBSetNonZero64(x) >> 3))));
|
||||
}
|
||||
}
|
||||
#else
|
||||
while (PITHY_EXPECT_T(ms2 < (s2_limit - 4u ))) {
|
||||
uint32_t x = pithy_Load32(ms1) ^ pithy_Load32(ms2);
|
||||
if (PITHY_EXPECT_F(x == 0u)) {
|
||||
ms1 += 4u;
|
||||
ms2 += 4u;
|
||||
} else {
|
||||
return ((ms1 - s1) + ((unsigned int)(pithy_IsLittleEndian() ?
|
||||
(pithy_FindLSBSetNonZero32(x) >> 3) : (pithy_FindMSBSetNonZero32(x) >> 3))));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
while (PITHY_EXPECT_T(ms2 < s2_limit)) {
|
||||
if (PITHY_EXPECT_T(*ms1 == *ms2)) {
|
||||
ms1++;
|
||||
ms2++;
|
||||
} else {
|
||||
return (ms1 - s1);
|
||||
}
|
||||
}
|
||||
return (ms1 - s1);
|
||||
}
|
||||
|
||||
|
||||
PITHY_STATIC_INLINE char *pithy_EmitLiteral(char *op, const char *literal, size_t len, int allow_fast_path)
|
||||
{
|
||||
int n = len - 1l;
|
||||
if (PITHY_EXPECT_T(n < 60l)) {
|
||||
*op++ = PITHY_LITERAL | (n << 2);
|
||||
if (PITHY_EXPECT_T(allow_fast_path) && PITHY_EXPECT_T(len <= 16ul)) {
|
||||
pithy_Move128(op, literal);
|
||||
return (op + len);
|
||||
}
|
||||
} else {
|
||||
char *base = op;
|
||||
int count = 0;
|
||||
op++;
|
||||
while (n > 0l) {
|
||||
*op++ = n & 0xff;
|
||||
n >>= 8;
|
||||
count++;
|
||||
}
|
||||
DCHECK((count >= 1) && (count <= 4));
|
||||
*base = PITHY_LITERAL | ((59 + count) << 2);
|
||||
}
|
||||
memcpy(op, literal, len);
|
||||
return (op + len);
|
||||
}
|
||||
|
||||
PITHY_STATIC_INLINE char *pithy_EmitCopyGreaterThan63(char *op, size_t offset, size_t len)
|
||||
{
|
||||
DCHECK((len < 65536ul) && (len >= 63ul) && (offset < kBlockSize));
|
||||
if (PITHY_EXPECT_T(offset < 65536ul)) {
|
||||
if (PITHY_EXPECT_T(len < (256ul + 63ul))) {
|
||||
*op++ = PITHY_COPY_2_BYTE_OFFSET | (62 << 2);
|
||||
pithy_StoreHost16(op, offset);
|
||||
op += 2ul;
|
||||
*op++ = (len - 63ul);
|
||||
} else {
|
||||
*op++ = PITHY_COPY_2_BYTE_OFFSET | (63 << 2);
|
||||
pithy_StoreHost16(op, offset);
|
||||
op += 2ul;
|
||||
pithy_StoreHost16(op, len);
|
||||
op += 2ul;
|
||||
}
|
||||
} else {
|
||||
if (PITHY_EXPECT_T(len < (256ul + 63ul))) {
|
||||
*op++ = PITHY_COPY_3_BYTE_OFFSET | (62 << 2);
|
||||
pithy_StoreHost24(op, offset);
|
||||
op += 3ul;
|
||||
*op++ = (len - 63ul);
|
||||
} else {
|
||||
*op++ = PITHY_COPY_3_BYTE_OFFSET | (63 << 2);
|
||||
pithy_StoreHost24(op, offset);
|
||||
op += 3ul;
|
||||
pithy_StoreHost16(op, len);
|
||||
op += 2ul;
|
||||
}
|
||||
}
|
||||
return (op);
|
||||
}
|
||||
|
||||
PITHY_STATIC_INLINE char *pithy_EmitCopyLessThan63(char *op, size_t offset, size_t len)
|
||||
{
|
||||
DCHECK((len < 63ul) && (len >= 4ul) && (offset < kBlockSize));
|
||||
if (PITHY_EXPECT_T(len < 12ul) && PITHY_EXPECT_T(offset < 2048ul)) {
|
||||
int lenMinus4 = len - 4l;
|
||||
DCHECK(lenMinus4 < 8l);
|
||||
*op++ = PITHY_COPY_1_BYTE_OFFSET | (lenMinus4 << 2) | ((offset >> 8) << 5);
|
||||
*op++ = offset & 0xff;
|
||||
} else {
|
||||
if (PITHY_EXPECT_T(offset < 65536ul)) {
|
||||
*op++ = PITHY_COPY_2_BYTE_OFFSET | ((len - 1ul) << 2);
|
||||
pithy_StoreHost16(op, offset);
|
||||
op += 2ul;
|
||||
} else {
|
||||
*op++ = PITHY_COPY_3_BYTE_OFFSET | ((len - 1ul) << 2);
|
||||
pithy_StoreHost24(op, offset);
|
||||
op += 3ul;
|
||||
}
|
||||
}
|
||||
return (op);
|
||||
}
|
||||
|
||||
PITHY_STATIC_INLINE char *pithy_EmitCopy(char *op, size_t offset, size_t len)
|
||||
{
|
||||
while (PITHY_EXPECT_F(len >= 63ul)) {
|
||||
op = pithy_EmitCopyGreaterThan63(op, offset, (len >= 65539ul) ? 65535ul : len);
|
||||
len -= (len >= 65539ul) ? 65535ul : len;
|
||||
}
|
||||
DCHECK((len > 0ul) ? ((len >= 4ul) && (len < 63ul)) : 1);
|
||||
if ( PITHY_EXPECT_T(len > 0ul)) {
|
||||
op = pithy_EmitCopyLessThan63(op, offset, len);
|
||||
len -= len;
|
||||
}
|
||||
return (op);
|
||||
}
|
||||
|
||||
size_t pithy_MaxCompressedLength(size_t inputLength)
|
||||
{
|
||||
return ((inputLength >= PITHY_UNCOMPRESSED_MAX_LENGTH) ? 0ul : 32ul + inputLength + (inputLength / 6ul));
|
||||
}
|
||||
|
||||
size_t pithy_Compress(const char *uncompressed,
|
||||
size_t uncompressedLength,
|
||||
char *compressedOut,
|
||||
size_t compressedOutLength,
|
||||
int compressionLevel)
|
||||
{
|
||||
|
||||
if ((pithy_MaxCompressedLength(uncompressedLength) > compressedOutLength) ||
|
||||
(uncompressedLength >= PITHY_UNCOMPRESSED_MAX_LENGTH) ||
|
||||
(uncompressedLength == 0ul)) {
|
||||
return (0ul);
|
||||
}
|
||||
|
||||
char *compressedPtr = compressedOut;
|
||||
|
||||
size_t hashTableSize = 0x100ul, maxHashTableSize = 1 << (12ul + (((compressionLevel < 0) ? 0 :
|
||||
(compressionLevel > 9) ? 9 : compressionLevel) / 2ul));
|
||||
while ((hashTableSize < maxHashTableSize) && (hashTableSize < uncompressedLength)) {
|
||||
hashTableSize <<= 1;
|
||||
}
|
||||
pithy_hashOffset_t stackHashTable[hashTableSize], *heapHashTable = NULL, *hashTable = stackHashTable;
|
||||
if ((sizeof(pithy_hashOffset_t) * hashTableSize) >= (1024ul * 128ul)) {
|
||||
if ((heapHashTable = malloc(sizeof(pithy_hashOffset_t) * hashTableSize)) == NULL) {
|
||||
return (0ul);
|
||||
}
|
||||
hashTable = heapHashTable;
|
||||
}
|
||||
size_t x = 0ul;
|
||||
for (x = 0ul; x < hashTableSize; x++) {
|
||||
hashTable[x] = uncompressed;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
char *const compressedOutEnd = compressedOut + compressedOutLength;
|
||||
#endif
|
||||
compressedPtr = pithy_Encode32(compressedPtr, uncompressedLength);
|
||||
DCHECK(compressedPtr <= compressedOutEnd);
|
||||
{
|
||||
const char *uncompressedPtr = uncompressed;
|
||||
const char *uncompressedEnd = uncompressed + uncompressedLength;
|
||||
const char *nextEmitUncompressedPtr = uncompressedPtr;
|
||||
DCHECK((hashTableSize & (hashTableSize - 1l)) == 0);
|
||||
const int shift = 32 - pithy_Log2Floor(hashTableSize);
|
||||
DCHECK((UINT32_MAX >> shift) == (hashTableSize - 1l));
|
||||
size_t skip = 32ul;
|
||||
|
||||
if (PITHY_EXPECT_T(uncompressedLength >= 15ul)) {
|
||||
const char *uncompressedEndLimit = uncompressed + uncompressedLength - 15ul;
|
||||
uint32_t uncompressedBytes;
|
||||
uint32_t nextUncompressedBytes = pithy_Load32(++uncompressedPtr);
|
||||
uint32_t nextUncompressedBytesHash = pithy_HashBytes(nextUncompressedBytes, shift);
|
||||
|
||||
while (1) {
|
||||
DCHECK(nextEmitUncompressedPtr < uncompressedPtr);
|
||||
const char *nextUncompressedPtr = uncompressedPtr, *matchCandidatePtr = NULL;
|
||||
|
||||
skip = (((skip - 32ul) * 184ul) >> 8) + 32ul;
|
||||
|
||||
do {
|
||||
uncompressedPtr = nextUncompressedPtr;
|
||||
uncompressedBytes = nextUncompressedBytes;
|
||||
uint32_t uncompressedBytesHash = nextUncompressedBytesHash;
|
||||
DCHECK(uncompressedBytesHash == pithy_HashBytes(uncompressedBytes, shift));
|
||||
size_t skipBytesBetweenHashLookups = skip >> 5;
|
||||
skip += ((skip * 7ul) >> 11) + 1ul;
|
||||
nextUncompressedPtr = uncompressedPtr + skipBytesBetweenHashLookups;
|
||||
if (PITHY_EXPECT_F(nextUncompressedPtr > uncompressedEndLimit)) {
|
||||
goto emit_remainder;
|
||||
}
|
||||
nextUncompressedBytes = pithy_Load32(nextUncompressedPtr);
|
||||
nextUncompressedBytesHash = pithy_HashBytes(nextUncompressedBytes, shift);
|
||||
matchCandidatePtr = hashTable[uncompressedBytesHash];
|
||||
DCHECK((matchCandidatePtr >= uncompressed) && (matchCandidatePtr < uncompressedPtr));
|
||||
hashTable[uncompressedBytesHash] = uncompressedPtr;
|
||||
} while ((PITHY_EXPECT_T(uncompressedBytes != pithy_Load32(matchCandidatePtr))) ||
|
||||
PITHY_EXPECT_F((uncompressedPtr - matchCandidatePtr) >= ((int)(kBlockSize - 2ul))));
|
||||
|
||||
DCHECK((nextEmitUncompressedPtr + 16ul) <= uncompressedEnd);
|
||||
compressedPtr = pithy_EmitLiteral(compressedPtr,
|
||||
nextEmitUncompressedPtr,
|
||||
uncompressedPtr - nextEmitUncompressedPtr,
|
||||
1);
|
||||
DCHECK(compressedPtr <= compressedOutEnd);
|
||||
uint64_t uncompressedBytes64 = 0ul;
|
||||
|
||||
do {
|
||||
if (compressionLevel > 2) {
|
||||
DCHECK((uncompressedPtr + 5ul) <= uncompressedEnd);
|
||||
uncompressedBytes64 = pithy_Load64((uint64_t*)uncompressedPtr + 1ul);
|
||||
hashTable[pithy_HashBytes(pithy_GetUint32AtOffset(uncompressedBytes64, 0u), shift)] =
|
||||
uncompressedPtr + 1ul;
|
||||
if (compressionLevel > 4) {
|
||||
hashTable[pithy_HashBytes(pithy_GetUint32AtOffset(uncompressedBytes64, 1u), shift)] =
|
||||
uncompressedPtr + 2ul;
|
||||
}
|
||||
}
|
||||
|
||||
DCHECK((matchCandidatePtr >= uncompressed) &&
|
||||
(matchCandidatePtr <= uncompressedPtr) &&
|
||||
((matchCandidatePtr + 4ul) <= uncompressedEnd) &&
|
||||
((uncompressedPtr + 4ul) <= uncompressedEnd));
|
||||
|
||||
size_t matchCandidateLength = 4ul + pithy_FindMatchLength(matchCandidatePtr + 4ul,
|
||||
uncompressedPtr + 4ul,
|
||||
uncompressedEnd);
|
||||
DCHECK(((matchCandidatePtr + matchCandidateLength) >= uncompressed) &&
|
||||
((matchCandidatePtr + matchCandidateLength) <= uncompressedEnd));
|
||||
DCHECK(0 == memcmp(uncompressedPtr, matchCandidatePtr, matchCandidateLength));
|
||||
compressedPtr = pithy_EmitCopy(compressedPtr,
|
||||
uncompressedPtr - matchCandidatePtr,
|
||||
matchCandidateLength);
|
||||
DCHECK(compressedPtr <= compressedOutEnd);
|
||||
uncompressedPtr += matchCandidateLength;
|
||||
DCHECK(uncompressedPtr <= uncompressedEnd);
|
||||
nextEmitUncompressedPtr = uncompressedPtr;
|
||||
if (PITHY_EXPECT_F(uncompressedPtr >= uncompressedEndLimit)) {
|
||||
goto emit_remainder;
|
||||
}
|
||||
|
||||
DCHECK(((uncompressedPtr - 3ul) >= uncompressed) && (uncompressedPtr <= uncompressedEnd));
|
||||
|
||||
uncompressedBytes64 = pithy_Load64((uint64_t*)uncompressedPtr - 3ul);
|
||||
|
||||
if (compressionLevel > 0) {
|
||||
if (compressionLevel > 8) {
|
||||
hashTable[pithy_HashBytes(pithy_GetUint32AtOffset(uncompressedBytes64, 0u), shift)] =
|
||||
uncompressedPtr - 3ul;
|
||||
}
|
||||
if (compressionLevel > 6) {
|
||||
hashTable[pithy_HashBytes(pithy_GetUint32AtOffset(uncompressedBytes64, 1u), shift)] =
|
||||
uncompressedPtr - 2ul;
|
||||
}
|
||||
hashTable[pithy_HashBytes(pithy_GetUint32AtOffset(uncompressedBytes64, 2u), shift)] =
|
||||
uncompressedPtr - 1ul;
|
||||
}
|
||||
|
||||
uncompressedBytes = pithy_GetUint32AtOffset(uncompressedBytes64, 3u);
|
||||
uint32_t uncompressedBytesHash = pithy_HashBytes(uncompressedBytes, shift);
|
||||
matchCandidatePtr = hashTable[uncompressedBytesHash];
|
||||
DCHECK((matchCandidatePtr >= uncompressed) && (matchCandidatePtr < uncompressedPtr));
|
||||
hashTable[uncompressedBytesHash] = uncompressedPtr;
|
||||
} while (PITHY_EXPECT_F(uncompressedBytes == pithy_Load32(matchCandidatePtr)) &&
|
||||
PITHY_EXPECT_T((uncompressedPtr - matchCandidatePtr) < ((int)(kBlockSize - 2ul))));
|
||||
|
||||
nextUncompressedBytes = pithy_GetUint32AtOffset(uncompressedBytes64, 4u);
|
||||
nextUncompressedBytesHash = pithy_HashBytes(nextUncompressedBytes, shift);
|
||||
uncompressedPtr++;
|
||||
}
|
||||
}
|
||||
|
||||
emit_remainder:
|
||||
if (nextEmitUncompressedPtr < uncompressedEnd) {
|
||||
compressedPtr = pithy_EmitLiteral(compressedPtr,
|
||||
nextEmitUncompressedPtr,
|
||||
uncompressedEnd - nextEmitUncompressedPtr,
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
pithy_Store32(compressedPtr, 0);
|
||||
compressedPtr += 4;
|
||||
|
||||
DCHECK((size_t)(compressedPtr - compressedOut) <= compressedOutLength);
|
||||
if (heapHashTable != NULL) {
|
||||
free(heapHashTable);
|
||||
heapHashTable = NULL;
|
||||
hashTable = NULL;
|
||||
}
|
||||
return (compressedPtr - compressedOut);
|
||||
}
|
||||
|
||||
|
||||
static const uint32_t pithy_wordmask[] = {
|
||||
0u, 0xffu, 0xffffu, 0xffffffu, 0xffffffffu
|
||||
};
|
||||
|
||||
|
||||
static const uint16_t pithy_charTable[256] = {
|
||||
0x0001, 0x0804, 0x1001, 0x1801, 0x0002, 0x0805, 0x1002, 0x1802,
|
||||
0x0003, 0x0806, 0x1003, 0x1803, 0x0004, 0x0807, 0x1004, 0x1804,
|
||||
0x0005, 0x0808, 0x1005, 0x1805, 0x0006, 0x0809, 0x1006, 0x1806,
|
||||
0x0007, 0x080a, 0x1007, 0x1807, 0x0008, 0x080b, 0x1008, 0x1808,
|
||||
0x0009, 0x0904, 0x1009, 0x1809, 0x000a, 0x0905, 0x100a, 0x180a,
|
||||
0x000b, 0x0906, 0x100b, 0x180b, 0x000c, 0x0907, 0x100c, 0x180c,
|
||||
0x000d, 0x0908, 0x100d, 0x180d, 0x000e, 0x0909, 0x100e, 0x180e,
|
||||
0x000f, 0x090a, 0x100f, 0x180f, 0x0010, 0x090b, 0x1010, 0x1810,
|
||||
0x0011, 0x0a04, 0x1011, 0x1811, 0x0012, 0x0a05, 0x1012, 0x1812,
|
||||
0x0013, 0x0a06, 0x1013, 0x1813, 0x0014, 0x0a07, 0x1014, 0x1814,
|
||||
0x0015, 0x0a08, 0x1015, 0x1815, 0x0016, 0x0a09, 0x1016, 0x1816,
|
||||
0x0017, 0x0a0a, 0x1017, 0x1817, 0x0018, 0x0a0b, 0x1018, 0x1818,
|
||||
0x0019, 0x0b04, 0x1019, 0x1819, 0x001a, 0x0b05, 0x101a, 0x181a,
|
||||
0x001b, 0x0b06, 0x101b, 0x181b, 0x001c, 0x0b07, 0x101c, 0x181c,
|
||||
0x001d, 0x0b08, 0x101d, 0x181d, 0x001e, 0x0b09, 0x101e, 0x181e,
|
||||
0x001f, 0x0b0a, 0x101f, 0x181f, 0x0020, 0x0b0b, 0x1020, 0x1820,
|
||||
0x0021, 0x0c04, 0x1021, 0x1821, 0x0022, 0x0c05, 0x1022, 0x1822,
|
||||
0x0023, 0x0c06, 0x1023, 0x1823, 0x0024, 0x0c07, 0x1024, 0x1824,
|
||||
0x0025, 0x0c08, 0x1025, 0x1825, 0x0026, 0x0c09, 0x1026, 0x1826,
|
||||
0x0027, 0x0c0a, 0x1027, 0x1827, 0x0028, 0x0c0b, 0x1028, 0x1828,
|
||||
0x0029, 0x0d04, 0x1029, 0x1829, 0x002a, 0x0d05, 0x102a, 0x182a,
|
||||
0x002b, 0x0d06, 0x102b, 0x182b, 0x002c, 0x0d07, 0x102c, 0x182c,
|
||||
0x002d, 0x0d08, 0x102d, 0x182d, 0x002e, 0x0d09, 0x102e, 0x182e,
|
||||
0x002f, 0x0d0a, 0x102f, 0x182f, 0x0030, 0x0d0b, 0x1030, 0x1830,
|
||||
0x0031, 0x0e04, 0x1031, 0x1831, 0x0032, 0x0e05, 0x1032, 0x1832,
|
||||
0x0033, 0x0e06, 0x1033, 0x1833, 0x0034, 0x0e07, 0x1034, 0x1834,
|
||||
0x0035, 0x0e08, 0x1035, 0x1835, 0x0036, 0x0e09, 0x1036, 0x1836,
|
||||
0x0037, 0x0e0a, 0x1037, 0x1837, 0x0038, 0x0e0b, 0x1038, 0x1838,
|
||||
0x0039, 0x0f04, 0x1039, 0x1839, 0x003a, 0x0f05, 0x103a, 0x183a,
|
||||
0x003b, 0x0f06, 0x103b, 0x183b, 0x003c, 0x0f07, 0x103c, 0x183c,
|
||||
0x0801, 0x0f08, 0x103d, 0x183d, 0x1001, 0x0f09, 0x103e, 0x183e,
|
||||
0x1801, 0x0f0a, 0x103f, 0x183f, 0x2001, 0x0f0b, 0x1040, 0x1840
|
||||
};
|
||||
|
||||
|
||||
int pithy_GetDecompressedLength(const char *compressed, size_t compressedLength, size_t *decompressedOutLengthResult)
|
||||
{
|
||||
const char *compressedEnd = compressed + compressedLength;
|
||||
size_t decompressedLength = 0ul;
|
||||
if (pithy_Parse32WithLimit(compressed, compressedEnd, &decompressedLength) != NULL) {
|
||||
*decompressedOutLengthResult = decompressedLength;
|
||||
return (1);
|
||||
} else {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int pithy_Decompress(const char *compressed, size_t compressedLength, char *decompressedOut,
|
||||
size_t decompressedOutLength)
|
||||
{
|
||||
const char *nextCompressedPtr = NULL, *compressedEnd = (compressed + compressedLength);
|
||||
size_t parsedDecompressedLength = 0ul;
|
||||
if (((nextCompressedPtr = pithy_Parse32WithLimit(compressed, compressedEnd, &parsedDecompressedLength)) == NULL) ||
|
||||
(parsedDecompressedLength > decompressedOutLength)) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *decompressedPtr = decompressedOut, *decompressedEnd = decompressedOut + parsedDecompressedLength;
|
||||
|
||||
while (1) {
|
||||
const char *compressedPtr = nextCompressedPtr;
|
||||
DCHECK(compressedPtr <= compressedEnd);
|
||||
if (PITHY_EXPECT_F(compressedPtr >= compressedEnd)) {
|
||||
break;
|
||||
}
|
||||
|
||||
const unsigned char c = *((const unsigned char *)(compressedPtr++));
|
||||
const unsigned char cLowerBits = (c & 0x3u);
|
||||
const int spaceLeft = (decompressedEnd - decompressedPtr);
|
||||
|
||||
if ((cLowerBits == PITHY_LITERAL)) {
|
||||
size_t literalLength = (c >> 2) + 1;
|
||||
if (PITHY_EXPECT_T(literalLength <= 16ul) && PITHY_EXPECT_T((compressedEnd - compressedPtr) >= 16l) &&
|
||||
PITHY_EXPECT_T(spaceLeft >= 16l)) {
|
||||
pithy_Move128(decompressedPtr, compressedPtr);
|
||||
} else {
|
||||
if (PITHY_EXPECT_F(literalLength > 60)) {
|
||||
if (PITHY_EXPECT_F((compressedPtr + 4) > compressedEnd)) {
|
||||
break;
|
||||
}
|
||||
size_t literalLengthBytes = literalLength - 60;
|
||||
literalLength = (pithy_LoadHost32(compressedPtr) & pithy_wordmask[literalLengthBytes]) + 1;
|
||||
compressedPtr += literalLengthBytes;
|
||||
}
|
||||
if (PITHY_EXPECT_F(spaceLeft < (int)literalLength) ||
|
||||
PITHY_EXPECT_F((compressedPtr + literalLength) > compressedEnd)) {
|
||||
break;
|
||||
}
|
||||
memcpy(decompressedPtr, compressedPtr, literalLength);
|
||||
}
|
||||
nextCompressedPtr = compressedPtr + literalLength;
|
||||
decompressedPtr += literalLength;
|
||||
} else {
|
||||
const uint32_t entry = pithy_charTable[c];
|
||||
const size_t trailer = pithy_LoadHost32(compressedPtr) & pithy_wordmask[cLowerBits];
|
||||
size_t length = entry & 0xffu;
|
||||
const size_t copyOffset = ((entry & 0x700u) + trailer);
|
||||
|
||||
compressedPtr += cLowerBits;
|
||||
|
||||
DCHECK((compressedPtr <= compressedEnd) && (copyOffset > 0ul) && (spaceLeft > 0l) && (length > 0ul));
|
||||
|
||||
if (PITHY_EXPECT_F((decompressedPtr - decompressedOut) <= ((int)copyOffset - 1l))) {
|
||||
break;
|
||||
}
|
||||
if (PITHY_EXPECT_T(length <= 16ul) &&
|
||||
PITHY_EXPECT_T(copyOffset >= 16ul) &&
|
||||
PITHY_EXPECT_T(spaceLeft >= 16l)) {
|
||||
pithy_Move128(decompressedPtr, decompressedPtr - copyOffset);
|
||||
} else {
|
||||
if (PITHY_EXPECT_F(length >= 63ul)) {
|
||||
if (PITHY_EXPECT_T(length == 63ul)) {
|
||||
if (PITHY_EXPECT_F((compressedPtr + 1) > compressedEnd)) {
|
||||
break;
|
||||
}
|
||||
length = (*((unsigned char *)compressedPtr++)) + 63ul;
|
||||
} else {
|
||||
if (PITHY_EXPECT_F((compressedPtr + 2) > compressedEnd)) {
|
||||
break;
|
||||
}
|
||||
length = pithy_LoadHost16(compressedPtr);
|
||||
compressedPtr += 2ul;
|
||||
}
|
||||
}
|
||||
|
||||
char *copyFrom = decompressedPtr - copyOffset, *copyTo = decompressedPtr;
|
||||
int copyLength = (int)length;
|
||||
|
||||
if (PITHY_EXPECT_F(copyLength > 256l) && PITHY_EXPECT_T(copyOffset > (size_t)copyLength)) {
|
||||
if (PITHY_EXPECT_F(spaceLeft < copyLength)) {
|
||||
break;
|
||||
}
|
||||
memcpy(copyTo, copyFrom, copyLength);
|
||||
} else {
|
||||
if (PITHY_EXPECT_T(spaceLeft >= (copyLength + 24)) && PITHY_EXPECT_T(copyLength > 0l)) {
|
||||
while ((copyTo - copyFrom) < 16l) {
|
||||
pithy_Move128(copyTo, copyFrom);
|
||||
copyLength -= copyTo - copyFrom;
|
||||
copyTo += copyTo - copyFrom;
|
||||
}
|
||||
while (copyLength > 0l) {
|
||||
pithy_Move128(copyTo, copyFrom);
|
||||
copyFrom += 16l;
|
||||
copyTo += 16l;
|
||||
copyLength -= 16l;
|
||||
}
|
||||
} else {
|
||||
if (PITHY_EXPECT_F(spaceLeft < copyLength) || PITHY_EXPECT_F(copyLength <= 0l)) {
|
||||
break;
|
||||
}
|
||||
do {
|
||||
*copyTo++ = *copyFrom++;
|
||||
} while (--copyLength > 0l);
|
||||
}
|
||||
}
|
||||
}
|
||||
nextCompressedPtr = compressedPtr;
|
||||
decompressedPtr += length;
|
||||
}
|
||||
}
|
||||
|
||||
return (decompressedPtr == decompressedEnd);
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
//
|
||||
// pithy.h
|
||||
// http://github.com/johnezang/pithy
|
||||
// Licensed under the terms of the BSD License, as specified below.
|
||||
//
|
||||
|
||||
/*
|
||||
Copyright (c) 2011, John Engelhart
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the Zang Industries nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _PITHY_H_
|
||||
#define _PITHY_H_
|
||||
|
||||
// compressionLevel >= 0 && compressionLevel <= 9. Values out side this range will be clamped to this range.
|
||||
size_t pithy_Compress (const char *uncompressed, size_t uncompressedLength, char *compressedOut,
|
||||
size_t compressedOutLength, int compressionLevel);
|
||||
int pithy_Decompress(const char *compressed, size_t compressedLength, char *decompressedOut,
|
||||
size_t decompressedOutLength);
|
||||
|
||||
size_t pithy_MaxCompressedLength(size_t inputLength);
|
||||
int pithy_GetDecompressedLength(const char *compressed, size_t compressedLength,
|
||||
size_t *decompressedOutLengthResult);
|
||||
|
||||
#endif // _PITHY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
|
@ -66,11 +66,13 @@ void test_case_malloc_free_size()
|
|||
TEST_ASSERT_EQUAL_UINT32(stats_start.total_size + ALLOCATION_SIZE_DEFAULT * (i + 1), stats_current.total_size);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.alloc_cnt + 1, stats_current.alloc_cnt);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.alloc_fail_cnt, stats_current.alloc_fail_cnt);
|
||||
|
||||
// Library header 0x4-0x8, stats header 0x8 and alignment addition 0x4
|
||||
TEST_ASSERT_INT_WITHIN(0x8, stats_start.overhead_size + 0xC , stats_current.overhead_size);
|
||||
// Free memory and assert back to starting size
|
||||
free(data);
|
||||
mbed_stats_heap_get(&stats_current);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.current_size, stats_current.current_size);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.overhead_size, stats_current.overhead_size);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.alloc_cnt, stats_current.alloc_cnt);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.alloc_fail_cnt, stats_current.alloc_fail_cnt);
|
||||
}
|
||||
|
@ -93,10 +95,14 @@ void test_case_allocate_zero()
|
|||
TEST_ASSERT_EQUAL_UINT32(stats_start.current_size, stats_current.current_size);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.total_size, stats_current.total_size);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.alloc_fail_cnt, stats_current.alloc_fail_cnt);
|
||||
|
||||
// Library header 0x4-0x8, stats header 0x8 and alignment addition 0x4
|
||||
if (NULL != data) {
|
||||
TEST_ASSERT_INT_WITHIN(0x8, stats_start.overhead_size + 0xC , stats_current.overhead_size);
|
||||
}
|
||||
// Free memory and assert back to starting size
|
||||
free(data);
|
||||
mbed_stats_heap_get(&stats_current);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.overhead_size, stats_current.overhead_size);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.current_size, stats_current.current_size);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.alloc_cnt, stats_current.alloc_cnt);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.alloc_fail_cnt, stats_current.alloc_fail_cnt);
|
||||
|
@ -121,6 +127,7 @@ void test_case_allocate_fail()
|
|||
TEST_ASSERT_EQUAL_UINT32(stats_start.total_size, stats_current.total_size);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.alloc_cnt, stats_current.alloc_cnt);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.alloc_fail_cnt + i + 1, stats_current.alloc_fail_cnt);
|
||||
TEST_ASSERT_EQUAL_UINT32(stats_start.overhead_size, stats_current.overhead_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ void test_system_reset()
|
|||
|
||||
int main(void)
|
||||
{
|
||||
GREENTEA_SETUP(2, "system_reset");
|
||||
GREENTEA_SETUP(30, "system_reset");
|
||||
test_system_reset();
|
||||
GREENTEA_TESTSUITE_RESULT(0); // Fail on any error.
|
||||
|
||||
|
|
|
@ -188,15 +188,14 @@ int main()
|
|||
{
|
||||
int ret = 0;
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
mbedtls_platform_context platform_ctx;
|
||||
if ((ret = mbedtls_platform_setup(&platform_ctx)) != 0) {
|
||||
if ((ret = mbedtls_platform_setup(NULL)) != 0) {
|
||||
mbedtls_printf("Mbed TLS multitest failed! mbedtls_platform_setup returned %d\n", ret);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
ret = (Harness::run(specification) ? 0 : 1);
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
mbedtls_platform_teardown(&platform_ctx);
|
||||
mbedtls_platform_teardown(NULL);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -96,15 +96,14 @@ int main()
|
|||
{
|
||||
int ret = 0;
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
mbedtls_platform_context platform_ctx;
|
||||
if ((ret = mbedtls_platform_setup(&platform_ctx)) != 0) {
|
||||
if ((ret = mbedtls_platform_setup(NULL)) != 0) {
|
||||
mbedtls_printf("Mbed TLS selftest failed! mbedtls_platform_setup returned %d\n", ret);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
ret = (Harness::run(specification) ? 0 : 1);
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
mbedtls_platform_teardown(&platform_ctx);
|
||||
mbedtls_platform_teardown(NULL);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -234,6 +234,16 @@ content at minimum:
|
|||
|
||||
```
|
||||
{
|
||||
"config": {
|
||||
"echo-server-addr" : {
|
||||
"help" : "IP address of echo server",
|
||||
"value" : "\"echo.mbedcloudtesting.com\""
|
||||
},
|
||||
"echo-server-port" : {
|
||||
"help" : "Port of echo server",
|
||||
"value" : "7"
|
||||
}
|
||||
},
|
||||
"macros": ["MBED_EXTENDED_TESTS"]
|
||||
}
|
||||
```
|
||||
|
@ -257,7 +267,7 @@ the `mbed_app.json` might look like this:
|
|||
"value": "\"password\""
|
||||
},
|
||||
"wifi-secure-protocol": {
|
||||
"help": "WiFi security protocol, valid values are WEP, WPA, WPA2, WPA/WPA2",
|
||||
"help": "WiFi security protocol, valid values are WEP, WPA, WPA2, WPA_WPA2",
|
||||
"value": "\"WPA2\""
|
||||
},
|
||||
"wifi-ch-secure": {
|
||||
|
@ -280,17 +290,6 @@ the `mbed_app.json` might look like this:
|
|||
"help": "How many networks may appear in Wifi scan result",
|
||||
"value": 30
|
||||
},
|
||||
"header-file": {
|
||||
"help" : "String for including your driver header file",
|
||||
"value" : "\"MyWifiInterface.h\""
|
||||
},
|
||||
"object-construction" : {
|
||||
"value" : "new MyWifiInterface()"
|
||||
},
|
||||
"connect-statement" : {
|
||||
"help" : "Must use 'net' variable name",
|
||||
"value" : "net->wifiInterface()->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, NSAPI_SECURITY_WPA_WPA2)"
|
||||
},
|
||||
"echo-server-addr" : {
|
||||
"help" : "IP address of echo server",
|
||||
"value" : "\"echo.mbedcloudtesting.com\""
|
||||
|
@ -300,9 +299,18 @@ the `mbed_app.json` might look like this:
|
|||
"value" : "7"
|
||||
}
|
||||
},
|
||||
"macros": ["MBED_EXTENDED_TESTS"]
|
||||
"macros": ["MBED_EXTENDED_TESTS"],
|
||||
"target_overrides": {
|
||||
"*": {
|
||||
"target.network-default-interface-type": "WIFI",
|
||||
"nsapi.default-wifi-ssid": "\"WIFI_SSID\"",
|
||||
"nsapi.default-wifi-password": "\"WIFI_PASSWORD\"",
|
||||
"nsapi.default-wifi-security": "WPA_WPA2"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
See `mbed-os/tools/test_configs` folder for examples.
|
||||
|
||||
Now build test binaries:
|
||||
|
||||
|
|
|
@ -178,9 +178,6 @@ Case cases[] = {
|
|||
#endif
|
||||
Case("SYNCHRONOUS_DNS", SYNCHRONOUS_DNS),
|
||||
Case("SYNCHRONOUS_DNS_MULTIPLE", SYNCHRONOUS_DNS_MULTIPLE),
|
||||
#ifdef MBED_EXTENDED_TESTS
|
||||
Case("SYNCHRONOUS_DNS_CACHE", SYNCHRONOUS_DNS_CACHE),
|
||||
#endif
|
||||
Case("SYNCHRONOUS_DNS_INVALID", SYNCHRONOUS_DNS_INVALID),
|
||||
};
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock);
|
|||
int split2half_rmng_tcp_test_time(); // [s]
|
||||
|
||||
namespace tcp_global {
|
||||
static const int TESTS_TIMEOUT = 480;
|
||||
static const int TCP_OS_STACK_SIZE = 1024;
|
||||
static const int TESTS_TIMEOUT = 960;
|
||||
static const int TCP_OS_STACK_SIZE = 2048;
|
||||
|
||||
static const int RX_BUFF_SIZE = 1220;
|
||||
static const int TX_BUFF_SIZE = 1220;
|
||||
|
|
|
@ -29,7 +29,7 @@ static const int SIGNAL_SIGIO1 = 0x1;
|
|||
static const int SIGNAL_SIGIO2 = 0x2;
|
||||
static const int SIGIO_TIMEOUT = 5000; //[ms]
|
||||
|
||||
Thread thread;
|
||||
Thread thread(osPriorityNormal, tcp_global::TCP_OS_STACK_SIZE);
|
||||
volatile bool running = true;
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,8 @@ static void check_const_len_rand_sequence()
|
|||
sock.sigio(callback(_sigio_handler1, Thread::gettid()));
|
||||
|
||||
static const int BUFF_SIZE = 10;
|
||||
char rx_buff[BUFF_SIZE] = {0};
|
||||
char tx_buff[BUFF_SIZE] = {0};
|
||||
static char rx_buff[BUFF_SIZE] = {0};
|
||||
static char tx_buff[BUFF_SIZE] = {0};
|
||||
|
||||
|
||||
int bytes2process;
|
||||
|
@ -107,8 +107,8 @@ static void check_var_len_rand_sequence()
|
|||
sock.sigio(callback(_sigio_handler2, Thread::gettid()));
|
||||
|
||||
static const int BUFF_SIZE = 1001;
|
||||
char rx_buff[BUFF_SIZE];
|
||||
char tx_buff[BUFF_SIZE];
|
||||
static char rx_buff[BUFF_SIZE];
|
||||
static char tx_buff[BUFF_SIZE];
|
||||
static const int pkt_size_diff = 100;
|
||||
|
||||
int bytes2process;
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define WIFI 2
|
||||
#if !defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE) || \
|
||||
(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == WIFI && !defined(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID))
|
||||
#error [NOT_SUPPORTED] No network configuration found for this target.
|
||||
#endif
|
||||
|
||||
#include "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
#include "utest/utest_stack_trace.h"
|
||||
#include "networkinterface_tests.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(480, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("NETWORKINTERFACE_STATUS", NETWORKINTERFACE_STATUS),
|
||||
Case("NETWORKINTERFACE_STATUS_NONBLOCK", NETWORKINTERFACE_STATUS_NONBLOCK),
|
||||
Case("NETWORKINTERFACE_STATUS_GET", NETWORKINTERFACE_STATUS_GET),
|
||||
Case("NETWORKINTERFACE_CONN_DISC_REPEAT", NETWORKINTERFACE_CONN_DISC_REPEAT),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main()
|
||||
{
|
||||
return !Harness::run(specification);
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* 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 "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "networkinterface_tests.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
namespace
|
||||
{
|
||||
NetworkInterface* net;
|
||||
const int repeats = 5;
|
||||
}
|
||||
|
||||
void NETWORKINTERFACE_CONN_DISC_REPEAT()
|
||||
{
|
||||
net = NetworkInterface::get_default_instance();
|
||||
|
||||
for (int i = 0; i < repeats; i++) {
|
||||
nsapi_error_t err = net->connect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
|
||||
err = net->disconnect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* 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 "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "networkinterface_tests.h"
|
||||
#include "unity/unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
namespace
|
||||
{
|
||||
NetworkInterface* net;
|
||||
rtos::Semaphore status_semaphore;
|
||||
int status_write_counter = 0;
|
||||
int status_read_counter = 0;
|
||||
const int repeats = 5;
|
||||
const int status_buffer_size = 100;
|
||||
nsapi_connection_status_t current_status = NSAPI_STATUS_ERROR_UNSUPPORTED;
|
||||
nsapi_connection_status_t statuses[status_buffer_size];
|
||||
}
|
||||
|
||||
void status_cb(nsapi_event_t event, intptr_t value)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, event);
|
||||
|
||||
statuses[status_write_counter] = static_cast<nsapi_connection_status_t>(value);
|
||||
status_write_counter++;
|
||||
if (status_write_counter >= status_buffer_size) {
|
||||
TEST_ASSERT(0);
|
||||
}
|
||||
|
||||
status_semaphore.release();
|
||||
}
|
||||
|
||||
nsapi_connection_status_t wait_status_callback()
|
||||
{
|
||||
nsapi_connection_status_t status;
|
||||
|
||||
while (true) {
|
||||
status_semaphore.wait();
|
||||
|
||||
status = statuses[status_read_counter];
|
||||
status_read_counter++;
|
||||
|
||||
if (status != current_status) {
|
||||
current_status = status;
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NETWORKINTERFACE_STATUS()
|
||||
{
|
||||
nsapi_connection_status_t status;
|
||||
|
||||
status_write_counter = 0;
|
||||
status_read_counter = 0;
|
||||
current_status = NSAPI_STATUS_ERROR_UNSUPPORTED;
|
||||
|
||||
net = NetworkInterface::get_default_instance();
|
||||
net->attach(status_cb);
|
||||
net->set_blocking(true);
|
||||
|
||||
for (int i = 0; i < repeats; i++) {
|
||||
nsapi_error_t err = net->connect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
|
||||
status = wait_status_callback();
|
||||
TEST_ASSERT_EQUAL(NSAPI_STATUS_CONNECTING, status);
|
||||
|
||||
status = wait_status_callback();
|
||||
if (status == NSAPI_STATUS_LOCAL_UP) {
|
||||
status = wait_status_callback();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_STATUS_GLOBAL_UP, status);
|
||||
|
||||
net->disconnect();
|
||||
|
||||
status = wait_status_callback();
|
||||
TEST_ASSERT_EQUAL(NSAPI_STATUS_DISCONNECTED, status);
|
||||
}
|
||||
|
||||
net->attach(NULL);
|
||||
}
|
||||
|
||||
void NETWORKINTERFACE_STATUS_NONBLOCK()
|
||||
{
|
||||
nsapi_connection_status_t status;
|
||||
|
||||
status_write_counter = 0;
|
||||
status_read_counter = 0;
|
||||
current_status = NSAPI_STATUS_ERROR_UNSUPPORTED;
|
||||
|
||||
net = NetworkInterface::get_default_instance();
|
||||
net->attach(status_cb);
|
||||
net->set_blocking(false);
|
||||
|
||||
for (int i = 0; i < repeats; i++) {
|
||||
nsapi_error_t err = net->connect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
|
||||
status = wait_status_callback();
|
||||
TEST_ASSERT_EQUAL(NSAPI_STATUS_CONNECTING, status);
|
||||
|
||||
status = wait_status_callback();
|
||||
if (status == NSAPI_STATUS_LOCAL_UP) {
|
||||
status = wait_status_callback();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_STATUS_GLOBAL_UP, status);
|
||||
|
||||
net->disconnect();
|
||||
|
||||
status = wait_status_callback();
|
||||
TEST_ASSERT_EQUAL(NSAPI_STATUS_DISCONNECTED, status);
|
||||
}
|
||||
|
||||
net->attach(NULL);
|
||||
net->set_blocking(true);
|
||||
}
|
||||
|
||||
void NETWORKINTERFACE_STATUS_GET()
|
||||
{
|
||||
nsapi_connection_status_t status;
|
||||
|
||||
net = NetworkInterface::get_default_instance();
|
||||
net->set_blocking(true);
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_STATUS_DISCONNECTED, net->get_connection_status());
|
||||
|
||||
for (int i = 0; i < repeats; i++) {
|
||||
nsapi_error_t err = net->connect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
|
||||
while (net->get_connection_status() != NSAPI_STATUS_GLOBAL_UP) {
|
||||
wait(0.5);
|
||||
}
|
||||
|
||||
net->disconnect();
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_STATUS_DISCONNECTED, net->get_connection_status());
|
||||
}
|
||||
|
||||
net->attach(NULL);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* 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 NETWORKINTERFACE_TESTS_H
|
||||
#define NETWORKINTERFACE_TESTS_H
|
||||
|
||||
/*
|
||||
* Test cases
|
||||
*/
|
||||
void NETWORKINTERFACE_STATUS();
|
||||
void NETWORKINTERFACE_STATUS_NONBLOCK();
|
||||
void NETWORKINTERFACE_STATUS_GET();
|
||||
void NETWORKINTERFACE_CONN_DISC_REPEAT();
|
||||
|
||||
#endif //NETWORKINTERFACE_TESTS_H
|
|
@ -0,0 +1,88 @@
|
|||
# Nanostack MAC test application
|
||||
|
||||
You can use this application to test the Nanostack RF driver implementations that follow the [Nanostack RF driver porting instructions](https://os.mbed.com/docs/v5.6/reference/contributing-connectivity.html#porting-new-rf-driver-for-6lowpan-stack). The application has a command-line interface that is used to send commands to Nanostack's MAC layer, for example starting PANs, scanning or sending data. The provided tests do not test performance or stability and only indirectly test RF functionalities.
|
||||
|
||||
## Table of contents
|
||||
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Setting up the application](#setting-up-the-application)
|
||||
* [Application usage](#application-usage)
|
||||
* [Interactive mode](#interactive-mode)
|
||||
* [Automated mode](#automated-mode)
|
||||
* [Testcases](#testcases)
|
||||
* [Considerations](#considerations)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* [Mbed CLI](https://github.com/ARMmbed/mbed-cli).
|
||||
* Mbed OS target board with build in radio, OR RF shield with Mbed OS driver
|
||||
|
||||
## Setting up the application
|
||||
|
||||
### Add your RF driver
|
||||
|
||||
When using RF shield, you need to configure it to be a default RF driver and instruct Mbed OS that RF driver is present. For example, configuring Atmel RF driver to provide default driver:
|
||||
|
||||
```
|
||||
"target_overrides": {
|
||||
"*": {
|
||||
"target.device_has_add": ["802_15_4_RF_PHY"],
|
||||
"atmel-rf.provide-default": true
|
||||
```
|
||||
|
||||
### Checking platform support
|
||||
|
||||
Check that your choice of platform is supported by your choice of toolchain:
|
||||
|
||||
```
|
||||
mbed compile --supported
|
||||
```
|
||||
|
||||
<span class="notes">**Note:** Targets are often abbreviated from the full model names. In the case of `FRDM-K64F` the target is `K64F`.</span>
|
||||
|
||||
## Run tests
|
||||
|
||||
You can use this application in interactive or automated mode.
|
||||
|
||||
### Interactive mode
|
||||
|
||||
To set the application to interactive mode:
|
||||
|
||||
1. Build the application.
|
||||
```
|
||||
mbed test --compile --icetea -t TOOLCHAIN -m TARGET_PLATFORM -DICETEA_MAC_TESTER_ENABLED --test-config NANOSTACK_MAC_TESTER -n address_read_and_write,send_data,send_data_indirect,send_large_payloads,create_and_join_PAN,ED_scan
|
||||
```
|
||||
2. Connect your board and copy the compiled application binary from the `BUILD/tests/TARGET_PLATFORM/TOOLCHAIN/TEST_APPS/device/nanostack_mac_tester/` folder to the board.
|
||||
3. Wait for the device to flash the binary.
|
||||
4. Open a serial connection with a program such as PuTTY, screen or minicom. The default baudrate is 115200.
|
||||
5. Press the reset button on the board. The Arm Mbed logo and trace appears in the terminal window.
|
||||
|
||||
If the driver registration and SW MAC creation was successful, the application is ready to receive commands.
|
||||
|
||||
To start off, type `help` to list all commands available and furthermore `help <command>` to print detailed information about a specific command.
|
||||
|
||||
### Automated mode
|
||||
|
||||
```
|
||||
mbed test --clean --compile --run --icetea -t TOOLCHAIN -m TARGET_PLATFORM -DICETEA_MAC_TESTER_ENABLED --test-config NANOSTACK_MAC_TESTER -n address_read_and_write,send_data,send_data_indirect,send_large_payloads,create_and_join_PAN,ED_scan
|
||||
```
|
||||
|
||||
Many of the provided testcases have a `self.channel` variable in the `setUp()` function for setting the RF channel. The default channel is 11. If you wish to run a test on another channel, you will need to change it manually in TEST_APPS/testcases/nanostack_mac_tester/.
|
||||
|
||||
Some testcases also use a secondary channel for transmitting and will use the next higher channel for that purpose. If the given channel is 26, the secondary channel will default to 25.
|
||||
|
||||
### Test cases
|
||||
|
||||
The automated test set runs the following testcases included in the repository under `TEST_APPS/testcases/nanostack_mac_tester/`.
|
||||
* Create and join PAN
|
||||
* Direct data transmission(Transmission between two devices)
|
||||
* Indirect data transmission(Transmission between two devices with one device acting as intermediary)
|
||||
* ED scan(Energy Density scanning)
|
||||
* Address read and write
|
||||
* Large data transmission
|
||||
|
||||
### Considerations
|
||||
|
||||
* Devices need to be power cycled if they are unresponsive to test framework commands even after resetting.
|
||||
* Devices can be enclosed in an RF isolation box to improve the consistency of test results.
|
||||
* Some boards and radio modules come with a PCB trace antenna, instead of an SMD antenna, and need to be spaced further apart to decrease interference.
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 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 "mbed.h"
|
||||
#include "rtos.h"
|
||||
#include "sw_mac.h"
|
||||
#include "ns_hal_init.h"
|
||||
#define MBED_CMDLINE_MAX_LINE_LENGTH 250
|
||||
#include "ns_cmdline.h"
|
||||
|
||||
#include "mac_commands.h"
|
||||
|
||||
#define HEAP_FOR_MAC_TESTER_SIZE 10000
|
||||
#define RX_BUFFER_SIZE 512
|
||||
|
||||
#define ATMEL 1
|
||||
#define MCR20 2
|
||||
#define OTHER 3
|
||||
|
||||
#define TRACE_GROUP "Main"
|
||||
#include "mbed-trace/mbed_trace.h"
|
||||
|
||||
#include "NanostackRfPhy.h"
|
||||
|
||||
#if !DEVICE_802_15_4_PHY
|
||||
#error [NOT_SUPPORTED] No 802.15.4 RF driver found for this target
|
||||
#endif
|
||||
|
||||
#ifndef ICETEA_MAC_TESTER_ENABLED
|
||||
#error [NOT_SUPPORTED] Skipping Nanostack MAC tester application.
|
||||
#endif
|
||||
|
||||
extern mac_api_s *mac_interface;
|
||||
RawSerial pc(USBTX, USBRX);
|
||||
osThreadId main_thread;
|
||||
static CircularBuffer<uint8_t, RX_BUFFER_SIZE> rx_buffer;
|
||||
static uint8_t ns_heap[HEAP_FOR_MAC_TESTER_SIZE];
|
||||
|
||||
static void app_heap_error_handler(heap_fail_t event)
|
||||
{
|
||||
tr_error("Heap error (%d), app_heap_error_handler()", event);
|
||||
switch (event) {
|
||||
case NS_DYN_MEM_NULL_FREE:
|
||||
case NS_DYN_MEM_DOUBLE_FREE:
|
||||
case NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID:
|
||||
case NS_DYN_MEM_POINTER_NOT_VALID:
|
||||
case NS_DYN_MEM_HEAP_SECTOR_CORRUPTED:
|
||||
case NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
while (1);
|
||||
}
|
||||
|
||||
static void rx_interrupt(void)
|
||||
{
|
||||
uint8_t c = pc.getc();
|
||||
rx_buffer.push(c);
|
||||
if (main_thread != NULL) {
|
||||
osSignalSet(main_thread, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_rx_data(void)
|
||||
{
|
||||
bool exit = false;
|
||||
uint8_t data;
|
||||
|
||||
while (1) {
|
||||
exit = !rx_buffer.pop(data);
|
||||
if (exit) {
|
||||
break;
|
||||
}
|
||||
cmd_char_input(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int mac_prepare(void)
|
||||
{
|
||||
NanostackRfPhy &rf_phy = NanostackRfPhy::get_default_instance();
|
||||
int8_t rf_driver_id = rf_phy.rf_register();
|
||||
uint8_t rf_eui64[8];
|
||||
|
||||
if (rf_driver_id < 0) {
|
||||
tr_error("Failed to register RF driver.");
|
||||
return -1;
|
||||
}
|
||||
rf_phy.get_mac_address(rf_eui64);
|
||||
mac_description_storage_size_t mac_description;
|
||||
mac_description.device_decription_table_size = DEVICE_DESCRIPTOR_TABLE_SIZE; /** MAC Device description list size */
|
||||
mac_description.key_description_table_size = KEY_DESCRIPTOR_TABLE_SIZE; /** MAC Key description list size */
|
||||
mac_description.key_lookup_size = LOOKUP_DESCRIPTOR_TABLE_SIZE; /** Key description key lookup list size */
|
||||
mac_description.key_usage_size = USAGE_DESCRIPTOR_TABLE_SIZE; /** Key description key usage list size */
|
||||
tr_info("Registered RF driver with id: %hhu, EUI64: %s", rf_driver_id, mbed_trace_array(rf_eui64, 8));
|
||||
mac_interface = ns_sw_mac_create(rf_driver_id, &mac_description);
|
||||
if (!mac_interface) {
|
||||
tr_error("Failed to create SW MAC.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
return mac_interface->mac_initialize(mac_interface, mac_data_confirm_handler,
|
||||
mac_data_indication_handler, mac_purge_confirm_handler, mac_mlme_confirm_handler,
|
||||
mac_mlme_indication_handler, rf_driver_id);
|
||||
}
|
||||
|
||||
static void cmd_ready_cb(int retcode)
|
||||
{
|
||||
cmd_next(retcode);
|
||||
}
|
||||
|
||||
static void trace_printer(const char *str)
|
||||
{
|
||||
printf("%s\n", str);
|
||||
cmd_output();
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
main_thread = osThreadGetId();
|
||||
pc.baud(MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
|
||||
pc.attach(rx_interrupt);
|
||||
ns_hal_init(ns_heap, HEAP_FOR_MAC_TESTER_SIZE, app_heap_error_handler, NULL);
|
||||
mbed_trace_init();
|
||||
mbed_trace_print_function_set(trace_printer);
|
||||
cmd_init(&default_cmd_response_out);
|
||||
cmd_set_ready_cb(cmd_ready_cb);
|
||||
mac_commands_init();
|
||||
|
||||
if (mac_prepare() != 0) {
|
||||
return -1;
|
||||
}
|
||||
tr_info("Created driver & SW MAC");
|
||||
|
||||
while (true) {
|
||||
osEvent os_event = Thread::signal_wait(1);
|
||||
if (os_event.status != osEventSignal) {
|
||||
osThreadYield();
|
||||
} else {
|
||||
handle_rx_data();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"macros": ["MBED_TRACE_LINE_LENGTH=200", "OS_TASKCNT=4", "OS_IDLESTKSIZE=32"],
|
||||
"target_overrides": {
|
||||
"*": {
|
||||
"nanostack.configuration": "lowpan_host",
|
||||
"platform.stdio-convert-newlines": true,
|
||||
"platform.stdio-baud-rate": 115200,
|
||||
"mbed-mesh-api.heap-size": 6000,
|
||||
"nanostack-hal.event_loop_thread_stack_size": 2000,
|
||||
"mbed-trace.enable": true,
|
||||
"nsapi.default-stack": "LWIP",
|
||||
"target.device_has_add": ["802_15_4_PHY"],
|
||||
"atmel-rf.provide-default": true
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 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 MAC_COMMANDS_H_
|
||||
#define MAC_COMMANDS_H_
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "ns_cmdline.h"
|
||||
#include "nsdynmemLIB.h"
|
||||
#include "mbed_trace.h"
|
||||
#include "mac_api.h"
|
||||
#include "mlme.h"
|
||||
#include "mac_mcps.h"
|
||||
#include "mac_common_defines.h"
|
||||
#include "mac_filter_api.h"
|
||||
#include "util.h"
|
||||
|
||||
#define LOOKUP_DESCRIPTOR_TABLE_SIZE 2
|
||||
#define DEVICE_DESCRIPTOR_TABLE_SIZE 2
|
||||
#define USAGE_DESCRIPTOR_TABLE_SIZE 2
|
||||
#define KEY_DESCRIPTOR_TABLE_SIZE 2
|
||||
|
||||
void mac_commands_init(void);
|
||||
|
||||
void mac_data_confirm_handler(const mac_api_t *api, const mcps_data_conf_t *data);
|
||||
void mac_data_indication_handler(const mac_api_t *api, const mcps_data_ind_t *data);
|
||||
void mac_purge_confirm_handler(const mac_api_t *api, mcps_purge_conf_t *data);
|
||||
void mac_mlme_confirm_handler(const mac_api_t *api, mlme_primitive id, const void *data);
|
||||
void mac_mlme_indication_handler(const mac_api_t *api, mlme_primitive id, const void *data);
|
||||
|
||||
int mac_start_command(int argc, char *argv[]);
|
||||
int mac_scan_command(int argc, char *argv[]);
|
||||
int mac_data_command(int argc, char *argv[]);
|
||||
int mac_poll_command(int argc, char *argv[]);
|
||||
int mac_purge_command(int argc, char *argv[]);
|
||||
int mac_set_command(int argc, char *argv[]);
|
||||
int mac_get_command(int argc, char *argv[]);
|
||||
int mac_reset_command(int argc, char *argv[]);
|
||||
int mac_address_command(int argc, char *argv[]);
|
||||
int mac_key_command(int argc, char *argv[]);
|
||||
int mac_add_neighbour_command(int argc, char *argv[]);
|
||||
int mac_filter_command(int argc, char *argv[]);
|
||||
int mac_config_status_command(int argc, char *argv[]);
|
||||
int mac_find_beacon_command(int argc, char *argv[]);
|
||||
int mac_wait_command(int argc, char *argv[]);
|
||||
int mac_analyze_ed_command(int argc, char *argv[]);
|
||||
int reset_command(int argc, char *argv[]);
|
||||
int silent_mode_command(int argc, char *argv[]);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 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 "util.h"
|
||||
|
||||
int string_to_bytes(const char *str, uint8_t *buf, int bytes)
|
||||
{
|
||||
int len = strlen(str);
|
||||
|
||||
if (len <= (3 * bytes - 1)) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < bytes; ++i) {
|
||||
if (i * 3 < len) {
|
||||
buf[i] = (uint8_t)strtoul(str + i * 3, NULL, 16);
|
||||
} else {
|
||||
buf[i] = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *mlme_status_string(uint8_t status)
|
||||
{
|
||||
switch (status) {
|
||||
case MLME_SUCCESS: return "MLME_SUCCESS";
|
||||
case MLME_BUSY_CHAN: return "MLME_BUSY_CHAN";
|
||||
case MLME_BUSY_RX: return "MLME_BUSY_RX";
|
||||
case MLME_BUSY_TX: return "MLME_BUSY_TX";
|
||||
case MLME_FORCE_TRX_OFF: return "MLME_FORCE_TRX_OFF";
|
||||
case MLME_IDLE: return "MLME_IDLE";
|
||||
case MLME_RX_ON: return "MLME_RX_ON";
|
||||
case MLME_TRX_OFF: return "MLME_TRX_OFF";
|
||||
case MLME_TX_ON: return "MLME_TX_ON";
|
||||
case MLME_COUNTER_ERROR: return "MLME_COUNTER_ERROR";
|
||||
case MLME_IMPROPER_KEY_TYPE: return "MLME_IMPROPER_KEY_TYPE";
|
||||
case MLME_IMPROPER_SECURITY_LEVEL: return "MLME_IMPROPER_SECURITY_LEVEL";
|
||||
case MLME_UNSUPPORTED_LEGACY: return "MLME_UNSUPPORTED_LEGACY";
|
||||
case MLME_UNSUPPORTED_SECURITY: return "MLME_UNSUPPORTED_SECURITY";
|
||||
case MLME_SECURITY_FAIL: return "MLME_SECURITY_FAIL";
|
||||
case MLME_FRAME_TOO_LONG: return "MLME_FRAME_TOO_LONG";
|
||||
case MLME_INVALID_HANDLE: return "MLME_INVALID_HANDLE";
|
||||
case MLME_INVALID_PARAMETER: return "MLME_INVALID_PARAMETER";
|
||||
case MLME_TX_NO_ACK: return "MLME_TX_NO_ACK";
|
||||
case MLME_NO_BEACON: return "MLME_NO_BEACON";
|
||||
case MLME_NO_DATA: return "MLME_NO_DATA";
|
||||
case MLME_NO_SHORT_ADDRESS: return "MLME_NO_SHORT_ADDRESS";
|
||||
case MLME_PAN_ID_CONFLICT: return "MLME_PAN_ID_CONFLICT";
|
||||
case MLME_TRANSACTION_EXPIRED: return "MLME_TRANSACTION_EXPIRED";
|
||||
case MLME_TRANSACTION_OVERFLOW: return "MLME_TRANSACTION_OVERFLOW";
|
||||
case MLME_UNAVAILABLE_KEY: return "MLME_UNAVAILABLE_KEY";
|
||||
case MLME_UNSUPPORTED_ATTRIBUTE: return "MLME_UNSUPPORTED_ATTRIBUTE";
|
||||
case MLME_INVALID_ADDRESS: return "MLME_INVALID_ADDRESS";
|
||||
case MLME_INVALID_INDEX: return "MLME_INVALID_INDEX";
|
||||
case MLME_LIMIT_REACHED: return "MLME_LIMIT_REACHED";
|
||||
case MLME_READ_ONLY: return "MLME_READ_ONLY";
|
||||
case MLME_SCAN_IN_PROGRESS: return "MLME_SCAN_IN_PROGRESS";
|
||||
case MLME_DATA_POLL_NOTIFICATION: return "MLME_DATA_POLL_NOTIFICATION";
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int channel_from_mask(uint32_t channel_mask, int index)
|
||||
{
|
||||
int expected_index = 0;
|
||||
for (int i = 0; i < 27; ++i) {
|
||||
if ((channel_mask >> i) & 1) {
|
||||
if (expected_index == index) {
|
||||
return i;
|
||||
}
|
||||
++expected_index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 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 UTIL_H_
|
||||
#define UTIL_H_
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "mbed.h"
|
||||
#include "mlme.h"
|
||||
|
||||
int string_to_bytes(const char *str, uint8_t *buf, int bytes);
|
||||
const char *mlme_status_string(uint8_t status);
|
||||
int channel_from_mask(uint32_t channel_mask, int index);
|
||||
|
||||
#endif
|
|
@ -2,57 +2,66 @@
|
|||
|
||||
### Structure
|
||||
|
||||
mbed-os has a folder called TEST_APPS that contains everything related to Icetea testing.
|
||||
There are currently 3 folders:
|
||||
Mbed OS has a folder called `TEST_APPS` that contains everything related to Icetea testing.
|
||||
|
||||
- device - contains all the different test applications you can flash to your board
|
||||
- icetea-plugins - contains plugins that are being used by some of the testcases, needed for the test execution
|
||||
- testcases - contains Icetea testcases written in Python
|
||||
There are currently three folders:
|
||||
|
||||
The testcases depends on test applications
|
||||
- `device` - contains all the different test applications you can flash to your board.
|
||||
- `icetea_plugins` - contains plugins that are being used by some of the testcases, needed for the test execution.
|
||||
- `testcases` - contains Icetea testcases written in Python.
|
||||
|
||||
The testcases depend on test applications.
|
||||
|
||||
### Preparing your work environment
|
||||
|
||||
#### Prerequisities
|
||||
#### Prerequisites
|
||||
|
||||
You need Icetea and mbed-cli that supports Icetea, installed.
|
||||
You need Icetea and version 1.8.0 or higher of Mbed CLI installed.
|
||||
|
||||
#### Selecting the network interface to use
|
||||
|
||||
Depending on a device, there might be a default network interface type defined in the mbed-os/targets/targets.json, which is used to locate a test-config file by default.
|
||||
If there is not, or you want to use a different interface than the default, you need to provide a relevant test-config -file to the mbed test with --test-config option.
|
||||
The test-config file contains the necessary information for the test application, there are some test-config files located under mbed-os/tools/test_configs.
|
||||
Devices which have their network drivers residing inside mbed-os can use generic test_configs like HeapBlockDeviceAndEthernetInterface.json and HeapBlockDeviceAndWifiInterface.json. Otherwise you need to use a device specific test-config.
|
||||
Depending on the device, there might be a default network interface type defined in `mbed-os/targets/targets.json`, which you can use to locate a default test-config file.
|
||||
|
||||
If the default network interface type is not defined or you want to use a different interface than the default, you need to provide a test-config file to the mbed test with `--test-config` option.
|
||||
|
||||
The test-config file contains the necessary information for the test application. There are some test-config files located under `mbed-os/tools/test_configs`.
|
||||
|
||||
Devices that have their network drivers residing inside `mbed-os` can use generic `test_configs`, such as `HeapBlockDeviceAndEthernetInterface.json` and `HeapBlockDeviceAndWifiInterface.json`. Otherwise, you need to use a device-specific test-config.
|
||||
|
||||
### Running the tests
|
||||
|
||||
Now that the interface has been selected you can run the icetea tests from the mbed-os root on your command line by
|
||||
Now that you have selected the interface, you can run the Icetea tests from the `mbed-os` root on your command-line by running the following command:
|
||||
|
||||
`>mbed test -m <target> -t <toolchain> --icetea`
|
||||
`mbed test -m <target> -t <toolchain> --icetea`
|
||||
|
||||
This command will compile the mbed-os, then compiles the test applications, creates a test suite and then starts running the tests.
|
||||
This command compiles the OS, compiles the test applications, creates a test suite and then starts running the tests.
|
||||
|
||||
If you want only to run some specific tests, you can use the -n -option. You can list multiple tests by separating them by comma (,).
|
||||
If you only want to run some specific tests, you can use the `-n` option. You can choose multiple tests by separating them with a comma (`,`):
|
||||
|
||||
`>mbed test -m <target> -t <toolchain> --icetea -n test1,test2`
|
||||
`mbed test -m <target> -t <toolchain> --icetea -n test1,test2`
|
||||
|
||||
#### Running the tests with specifig test-config
|
||||
#### Running the tests with a specific test-config
|
||||
|
||||
Some devices may offer multiple network interfaces to operate with. For example, `UBLOX_EVK_ODIN_W2` offers ethernet and Wi-Fi capabilities.
|
||||
|
||||
Some devices may offer multiple network interfaces to operate with. For example, UBLOX_EVK_ODIN_W2 offers ethernet and Wi-Fi capabilities.
|
||||
The tests can be run for either one of those using already existing test-config -files.
|
||||
|
||||
To run the tests with Wi-Fi interface:
|
||||
`>mbed test -m UBLOX_EVK_ODIN_W2 -t <toolchain> --icetea --test-config tools/test_configs/HeapBlockDeviceAndWifiInterface.json`
|
||||
To run the tests with the Wi-Fi interface:
|
||||
|
||||
To run the tests with ethernet interface:
|
||||
`>mbed test -m UBLOX_EVK_ODIN_W2 -t <toolchain> --icetea --test-config tools/test_configs/HeapBlockDeviceAndEthernetInterface.json`
|
||||
`mbed test -m UBLOX_EVK_ODIN_W2 -t <toolchain> --icetea --test-config tools/test_configs/HeapBlockDeviceAndWifiInterface.json`
|
||||
|
||||
To run the tests with the ethernet interface:
|
||||
|
||||
`mbed test -m UBLOX_EVK_ODIN_W2 -t <toolchain> --icetea --test-config tools/test_configs/HeapBlockDeviceAndEthernetInterface.json`
|
||||
|
||||
#### Providing Wi-Fi access point information
|
||||
|
||||
If you are using Wi-Fi interface for running the tests, you need to provide also information about the used access point.
|
||||
If you are using the Wi-Fi interface for running the tests, you need to also provide information about the used access point.
|
||||
|
||||
The information can be provided in the used test-config file.
|
||||
|
||||
Example of access point information:
|
||||
|
||||
```
|
||||
"target_overrides": {
|
||||
"*": {
|
||||
|
@ -66,7 +75,7 @@ Example of access point information:
|
|||
|
||||
### Test results
|
||||
|
||||
Icetea prints the results from the test run to the command line, and the final result looks similar to this.
|
||||
Icetea prints the results from the test run to the command-line, and the final result looks similar to this:
|
||||
|
||||
```
|
||||
+--------------------------------+---------+-------------+-------------+-----------+----------+
|
||||
|
@ -89,5 +98,6 @@ Icetea prints the results from the test run to the command line, and the final r
|
|||
+---------------+----------------+
|
||||
```
|
||||
|
||||
The results from the tests can also be found in the mbed-os/log folder.
|
||||
You probably want to add the log folder to your .mbedignore file to prevent issues with build commands becoming too long over the time.
|
||||
You can also find the results from the tests in the `mbed-os/log` folder.
|
||||
|
||||
You probably want to add the log folder to your `.mbedignore` file to prevent issues with build commands becoming too long over the time.
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
Icetea tests
|
||||
============
|
||||
|
||||
This folder contains all the test cases done with Icetea residing in `mbed-os`.
|
||||
The tests are divided in to subfolders and each subfolder contains a set of testcases.
|
||||
The subfolder has a description of all the testcases it contains.
|
||||
|
||||
Testcases
|
||||
---------
|
||||
|
||||
Current testcases:
|
||||
|
||||
- [netsocket](https://github.com/ARMmbed/mbed-os/blob/master/TEST_APPS/testcases/netsocket)
|
||||
- [example](https://github.com/ARMmbed/mbed-os/blob/master/TEST_APPS/testcases/example)
|
|
@ -0,0 +1,24 @@
|
|||
Example tests
|
||||
=============
|
||||
|
||||
This folder contains example tests for Icetea
|
||||
The test located under this folder is dependent of the application [exampleapp](https://github.com/ARMmbed/mbed-os/blob/master/TEST_APPS/device/exampleapp)
|
||||
The exampleapp is disabled by default, to be able to run the test_cmdline with the exampleapp, either remove the preprocessor macro from exampleapp.cpp or add `-DICETEA_EXAMPLE_ENABLED` to the mbed test command
|
||||
|
||||
Testcases
|
||||
---------
|
||||
|
||||
### test_cmdline
|
||||
|
||||
**Description:**
|
||||
Send command line commands to target over serial interface.
|
||||
This test introduces the Icetea testcase structure to the user.
|
||||
|
||||
**Test steps:**
|
||||
Send "echo hello world" to the target.
|
||||
Target sends "hello world" back to the host machine.
|
||||
Send help to the target.
|
||||
Target prints out the command line commands the application supports.
|
||||
|
||||
**Expected result:**
|
||||
The test exits without timeouts.
|
|
@ -0,0 +1,107 @@
|
|||
"""
|
||||
Copyright (c) 2017, 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.
|
||||
"""
|
||||
|
||||
import threading
|
||||
import os,sys
|
||||
from icetea_lib.bench import Bench
|
||||
|
||||
class Testcase(Bench):
|
||||
def __init__(self):
|
||||
Bench.__init__(self, name = "ED_scan",
|
||||
title = "ED scan test",
|
||||
status = "development",
|
||||
type = "smoke",
|
||||
subtype = "",
|
||||
execution = {
|
||||
"skip": {
|
||||
"value": False,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
author = "Valtteri Erkkila",
|
||||
purpose = "Tests reading the ED values from channels 11-16",
|
||||
feature = ["MLME-SCAN (ED)"],
|
||||
component = ["MAC"],
|
||||
requirements = {
|
||||
"duts": {
|
||||
'*': {
|
||||
"count":3,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
},
|
||||
"1":{"nick": "First"},
|
||||
"2":{"nick": "Second"},
|
||||
"3":{"nick": "Third"}
|
||||
}}
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
self.channel = 11
|
||||
self.command("First", "addr --64-bit 01:02:03:00:00:00:00:01")
|
||||
self.command("Second", "addr --64-bit 01:02:03:00:00:00:00:02")
|
||||
self.command("Third", "addr --64-bit 01:02:03:00:00:00:00:03")
|
||||
|
||||
def spam_channel(self, event):
|
||||
while not event.wait(0.1):
|
||||
self.lock_th.acquire()
|
||||
self.command("First", "data --dst_addr 01:02:03:00:00:00:00:03 --msdu {} --msdu_length {} --wait_for_confirm false".format(self.payload, len(self.payload)))
|
||||
self.command("Third", "data --dst_addr 01:02:03:00:00:00:00:01 --msdu {} --msdu_length {} --wait_for_confirm false".format(self.payload, len(self.payload)))
|
||||
self.lock_th.release()
|
||||
|
||||
def mask_from_channel_list(self, channels):
|
||||
res = 0
|
||||
for ch in channels:
|
||||
res = res | ( 1 << ch)
|
||||
return hex(res)
|
||||
|
||||
def case(self):
|
||||
self.lock_th = threading.Lock()
|
||||
self.payload = "01234567890123456789012345678901234567890123456789"
|
||||
|
||||
self.command("First", "start --pan_coordinator true --logical_channel {}".format(self.channel))
|
||||
self.command("Second", "start --pan_coordinator false --logical_channel {}".format(self.channel))
|
||||
self.command("Third", "start --pan_coordinator false --logical_channel {}".format(self.channel))
|
||||
|
||||
#No reason to print their spamming
|
||||
self.command("First", "silent-mode on")
|
||||
self.command("Third", "silent-mode on")
|
||||
|
||||
self.stop_event = threading.Event()
|
||||
self.th = threading.Thread(target=self.spam_channel, args=(self.stop_event,))
|
||||
self.th.start()
|
||||
self.stopped = True
|
||||
channels = range(11,27)
|
||||
for i in range(0, 3):
|
||||
self.lock_th.acquire()
|
||||
self.command("First", "mlme-reset")
|
||||
self.command("First", "start --pan_coordinator true --logical_channel {}".format(self.channel))
|
||||
self.command("Third", "mlme-reset")
|
||||
self.command("Third", "start --pan_coordinator false --logical_channel {}".format(self.channel))
|
||||
self.lock_th.release()
|
||||
self.command("Second", "scan --scan_type 0 --scan_duration 7 --channel_mask {}".format(self.mask_from_channel_list(channels)))
|
||||
self.command("Second", "analyze-ed --channel {} --above 100".format(self.channel))
|
||||
|
||||
def tearDown(self):
|
||||
self.command("First", "silent-mode off")
|
||||
self.command("Third", "silent-mode off")
|
||||
self.stop_event.set()
|
||||
self.th.join()
|
||||
del self.th
|
||||
self.reset_dut()
|
|
@ -0,0 +1 @@
|
|||
#!/usr/bin/env python
|
|
@ -0,0 +1,65 @@
|
|||
"""
|
||||
Copyright (c) 2017, 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.
|
||||
"""
|
||||
|
||||
import os,sys
|
||||
from icetea_lib.bench import Bench
|
||||
|
||||
class Testcase(Bench):
|
||||
def __init__(self):
|
||||
Bench.__init__(self, name = "address_read_and_write",
|
||||
title = "MAC address and PAN id read/write test",
|
||||
status = "development",
|
||||
type = "smoke",
|
||||
subtype = "",
|
||||
execution = {
|
||||
"skip": {
|
||||
"value": False,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
author = "Valtteri Erkkila",
|
||||
purpose = "Tests reading a MAC address from the driver, and writing to the modifiable MAC address",
|
||||
feature = ["MLME-SET"],
|
||||
component = ["MAC"],
|
||||
requirements = {
|
||||
"duts": {
|
||||
'*': {
|
||||
"count":1,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
},
|
||||
"1":{"nick": "First"}
|
||||
}}
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def case(self):
|
||||
self.command("First", "addr")
|
||||
self.command("First", "addr --64-bit 01:02:03:00:00:00:00:01")
|
||||
self.command("First", "addr --16-bit 0xABCD")
|
||||
#macPANId
|
||||
self.command("First", "mlme-set --attr 0x50 --value_bytes CD:CD --value_size 2")
|
||||
self.command("First", "addr")
|
||||
self.verify_trace(1, "MAC64: 01:02:03:00:00:00:00:01")
|
||||
|
||||
def tearDown(self):
|
||||
self.reset_dut()
|
|
@ -0,0 +1,86 @@
|
|||
"""
|
||||
Copyright (c) 2017, 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.
|
||||
"""
|
||||
|
||||
import os,sys
|
||||
from icetea_lib.bench import Bench
|
||||
|
||||
class Testcase(Bench):
|
||||
def __init__(self):
|
||||
Bench.__init__(self, name = "create_and_join_PAN",
|
||||
title = "Create a PAN and have a device join it",
|
||||
status = "development",
|
||||
type = "smoke",
|
||||
subtype = "",
|
||||
execution = {
|
||||
"skip": {
|
||||
"value": False,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
author = "Valtteri Erkkila",
|
||||
purpose = "",
|
||||
feature = ["MLME-START", "MLME-SCAN (active)"],
|
||||
component = ["MAC"],
|
||||
requirements = {
|
||||
"duts": {
|
||||
'*': {
|
||||
"count":3,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
},
|
||||
"1":{"nick": "First"},
|
||||
"2":{"nick": "Second"},
|
||||
"3":{"nick": "Third"}
|
||||
}}
|
||||
)
|
||||
|
||||
def mask_from_channel_list(self, channels):
|
||||
res = 0
|
||||
for ch in channels:
|
||||
res = res | ( 1 << ch)
|
||||
return hex(res)
|
||||
|
||||
def setUp(self):
|
||||
self.channel = 11
|
||||
|
||||
def case(self):
|
||||
#Beacon payload & length
|
||||
self.command("First", "mlme-set --attr 0x45 --value_ascii mac-tester --value_size 10")
|
||||
self.command("First", "mlme-set --attr 0x46 --value_uint8 10 --value_size 1")
|
||||
|
||||
self.command("Second", "mlme-set --attr 0x45 --value_ascii second-mac-tester --value_size 17")
|
||||
self.command("Second", "mlme-set --attr 0x46 --value_uint8 17 --value_size 1")
|
||||
|
||||
self.command("First", "start --pan_coordinator true --logical_channel {}".format(self.channel))
|
||||
self.command("Second", "start --pan_coordinator true --logical_channel {}".format(int(self.channel)+1))
|
||||
self.delay(3)
|
||||
if self.channel == 11:
|
||||
channels = [11,12]
|
||||
elif self.channel == 26:
|
||||
channels = [25,26]
|
||||
else:
|
||||
channels = [self.channel, self.channel+1]
|
||||
self.command("Third", "scan --channel_mask {}".format(self.mask_from_channel_list(channels)))
|
||||
self.delay(0.2)
|
||||
self.command("Third", "find-beacon --data mac-tester")
|
||||
self.command("Third", "find-beacon --data second-mac-tester")
|
||||
|
||||
def tearDown(self):
|
||||
self.reset_dut()
|
|
@ -0,0 +1,66 @@
|
|||
"""
|
||||
Copyright (c) 2017, 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.
|
||||
"""
|
||||
|
||||
import os,sys
|
||||
from icetea_lib.bench import Bench
|
||||
|
||||
class Testcase(Bench):
|
||||
def __init__(self):
|
||||
Bench.__init__(self, name = "send_data",
|
||||
title = "Simple data transmission test",
|
||||
status = "development",
|
||||
type = "smoke",
|
||||
subtype = "",
|
||||
execution = {
|
||||
"skip": {
|
||||
"value": False,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
author = "Valtteri Erkkila",
|
||||
purpose = "Tests that sending data works",
|
||||
feature = ["MCPS-DATA"],
|
||||
component = ["MAC"],
|
||||
requirements = {
|
||||
"duts": {
|
||||
'*': {
|
||||
"count":2,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
},
|
||||
"1":{"nick": "First"},
|
||||
"2":{"nick": "Second"}
|
||||
}}
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
self.channel = 11
|
||||
self.command("First", "addr --64-bit 01:02:03:00:00:00:00:01")
|
||||
self.command("Second", "addr --64-bit 01:02:03:00:00:00:00:02")
|
||||
|
||||
def case(self):
|
||||
self.command("First", "start --pan_coordinator true --logical_channel {}".format(self.channel))
|
||||
self.command("Second", "start --pan_coordinator false --logical_channel {}".format(self.channel))
|
||||
|
||||
self.command("First", "data --dst_addr 01:02:03:00:00:00:00:02 --msdu_length 5 --msdu abcde")
|
||||
self.command("Second", "data --dst_addr 01:02:03:00:00:00:00:01 --msdu_length 5 --msdu 12345")
|
||||
|
||||
def tearDown(self):
|
||||
self.reset_dut()
|
|
@ -0,0 +1,96 @@
|
|||
"""
|
||||
Copyright (c) 2017, 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.
|
||||
"""
|
||||
|
||||
import os,sys
|
||||
from icetea_lib.bench import Bench
|
||||
|
||||
class Testcase(Bench):
|
||||
def __init__(self):
|
||||
Bench.__init__(self, name = "send_data_indirect",
|
||||
title = "Indirect data transmission test",
|
||||
status = "development",
|
||||
type = "smoke",
|
||||
subtype = "",
|
||||
execution = {
|
||||
"skip": {
|
||||
"value": False,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
author = "Valtteri Erkkila",
|
||||
purpose = "Tests sending data indirectly, i.e polling the coordinator for data",
|
||||
feature = ["MCPS-DATA", "MLME-POLL"],
|
||||
component = ["MAC"],
|
||||
requirements = {
|
||||
"duts": {
|
||||
'*': {
|
||||
"count":3,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
},
|
||||
"1":{"nick": "First"},
|
||||
"2":{"nick": "Second"},
|
||||
"3":{"nick": "Third"}
|
||||
}}
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
self.channel = 11
|
||||
self.command("First", "addr --64-bit 01:02:03:00:00:00:00:01")
|
||||
self.command("Second", "addr --64-bit 01:02:03:00:00:00:00:02")
|
||||
self.command("Third", "addr --64-bit 01:02:03:00:00:00:00:03")
|
||||
|
||||
def case(self):
|
||||
self.command("First", "start --pan_coordinator true --logical_channel {}".format(self.channel))
|
||||
self.command("Second", "start --pan_coordinator false --logical_channel {}".format(self.channel))
|
||||
self.command("Third", "start --pan_coordinator false --logical_channel {}".format(self.channel))
|
||||
|
||||
#macRxOnWhenIdle
|
||||
self.command("Second", "mlme-set --attr 0x52 --value_uint8 0 --value_size 1")
|
||||
self.command("Third", "mlme-set --attr 0x52 --value_uint8 0 --value_size 1")
|
||||
|
||||
self.command("First", "add-neigh --frame_ctr 0 --mac16 0xFFFF --mac64 01:02:03:00:00:00:00:02 --pan_id 0x1234 --index 0")
|
||||
self.command("First", "add-neigh --frame_ctr 0 --mac16 0xFFFF --mac64 01:02:03:00:00:00:00:03 --pan_id 0x1234 --index 1")
|
||||
self.command("Second", "add-neigh --frame_ctr 0 --mac16 0xFFFF --mac64 01:02:03:00:00:00:00:01 --pan_id 0x1234 --index 0")
|
||||
self.command("Third", "add-neigh --frame_ctr 0 --mac16 0xFFFF --mac64 01:02:03:00:00:00:00:01 --pan_id 0x1234 --index 0")
|
||||
|
||||
self.command("Second", "config-status --data_ind abcde")
|
||||
self.command("Third", "config-status --data_ind 12345")
|
||||
|
||||
#Runs into timing issues if extensive printing is enabled
|
||||
self.command("*", "silent-mode on")
|
||||
self.command("First", "data --dst_addr 01:02:03:00:00:00:00:02 --msdu_length 5 --msdu abcde --indirect_tx true --wait_for_confirm false")
|
||||
self.command("Second", "poll --coord_address 01:02:03:00:00:00:00:01")
|
||||
|
||||
self.command("First", "data")
|
||||
self.command("First", "data")
|
||||
self.command("Second", "poll")
|
||||
self.command("Second", "poll")
|
||||
self.command("Second", "config-status --poll 235")
|
||||
self.command("Second", "poll")
|
||||
|
||||
self.command("Second", "config-status --poll 235")
|
||||
self.command("First", "data --dst_addr 01:02:03:00:00:00:00:03 --msdu 12345")
|
||||
self.command("Second", "poll")
|
||||
self.command("Third", "poll --coord_address 01:02:03:00:00:00:00:01")
|
||||
self.command("*", "silent-mode off")
|
||||
|
||||
def tearDown(self):
|
||||
self.reset_dut()
|
|
@ -0,0 +1,79 @@
|
|||
"""
|
||||
Copyright (c) 2017, 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.
|
||||
"""
|
||||
|
||||
import os,sys
|
||||
from icetea_lib.bench import Bench
|
||||
|
||||
class Testcase(Bench):
|
||||
def __init__(self):
|
||||
Bench.__init__(self, name = "send_large_payloads",
|
||||
title = "Data transmission test with large packets",
|
||||
status = "development",
|
||||
type = "reliability",
|
||||
subtype = "",
|
||||
execution = {
|
||||
"skip": {
|
||||
"value": False,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
author = "Valtteri Erkkila",
|
||||
purpose = "Repeatedly sends long packets, checking that the payload is correct in each one",
|
||||
feature = ["MCPS-DATA"],
|
||||
component = ["MAC"],
|
||||
requirements = {
|
||||
"duts": {
|
||||
'*': {
|
||||
"count":2,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
},
|
||||
"1":{"nick": "First"},
|
||||
"2":{"nick": "Second"}
|
||||
}}
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
self.channel = 11
|
||||
self.command("First", "addr --64-bit 01:02:03:00:00:00:00:01")
|
||||
self.command("Second", "addr --64-bit 01:02:03:00:00:00:00:02")
|
||||
|
||||
def case(self):
|
||||
#104 characters, headers are 2+1+2+8+8+2=23 bytes, resulting in a packet size of 127 (max)
|
||||
large_payload = "0123456789abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZZZZZZZZZ0123456789012345678901234567891234"
|
||||
self.command("First", "start --pan_coordinator true --logical_channel {}".format(self.channel))
|
||||
self.command("Second", "start --pan_coordinator false --logical_channel {}".format(self.channel))
|
||||
|
||||
self.command("First", "config-status --data_ind {}".format(large_payload))
|
||||
self.command("Second", "config-status --data_ind {}".format(large_payload))
|
||||
|
||||
self.command("First", "data --dst_addr 01:02:03:00:00:00:00:02 --msdu_length {} --msdu {}".format(len(large_payload), large_payload))
|
||||
self.command("Second", "wait --timeout 500")
|
||||
|
||||
self.command("Second", "data --dst_addr 01:02:03:00:00:00:00:01 --msdu_length {} --msdu {}".format(len(large_payload), large_payload))
|
||||
self.command("First", "wait --timeout 500")
|
||||
for i in range(0, 25):
|
||||
self.command("First", "data")
|
||||
self.command("Second", "wait")
|
||||
self.command("Second", "data")
|
||||
self.command("First", "wait")
|
||||
|
||||
def tearDown(self):
|
||||
self.reset_dut()
|
|
@ -0,0 +1,65 @@
|
|||
"""
|
||||
Copyright (c) 2017, 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.
|
||||
"""
|
||||
import os,sys
|
||||
# ensure that test/ directory is first choice for imports
|
||||
test_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
if not test_dir in sys.path:
|
||||
sys.path.insert(0, test_dir)
|
||||
from GenericTestcase import Bench
|
||||
from Error import TestStepFail
|
||||
|
||||
class Testcase(Bench):
|
||||
def __init__(self):
|
||||
Bench.__init__(self, name = "template", # Name should be the same as the filename
|
||||
title = "TITLE",
|
||||
status = "development",
|
||||
type = "TYPE",
|
||||
subtype = "",
|
||||
execution = {
|
||||
"skip": {
|
||||
"value": False,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
author = "Valtteri Erkkila",
|
||||
purpose = "",
|
||||
feature = [""],
|
||||
component = ["MAC"],
|
||||
requirements = {
|
||||
"duts": {
|
||||
'*': {
|
||||
"count":2, # Count must reflect the amount of specified devices below
|
||||
"type": "hardware",
|
||||
"application":{ "name":"generalTestApplication", "version": "1.0"},
|
||||
"rf_channel": 11
|
||||
},
|
||||
"1":{"nick": "First"},
|
||||
"2":{"nick": "Second"}
|
||||
}}
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def case(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
if __name__=='__main__':
|
||||
sys.exit( Testcase().run() )
|
|
@ -0,0 +1,7 @@
|
|||
Netsocket tests
|
||||
===============
|
||||
|
||||
This folder contains netsocket tests for Icetea
|
||||
The tests located under this folder are dependent of the application [socket_app](https://github.com/ARMmbed/mbed-os/blob/master/TEST_APPS/device/socket_app)
|
||||
|
||||
The test cases under this folder are defined in [Network Socket test plan](https://github.com/ARMmbed/mbed-os/blob/master/TESTS/netsocket/README.md)
|
|
@ -90,17 +90,42 @@ endif(COVERAGE)
|
|||
set(unittest-includes-base
|
||||
"${PROJECT_SOURCE_DIR}/target_h"
|
||||
"${PROJECT_SOURCE_DIR}/target_h/events"
|
||||
"${PROJECT_SOURCE_DIR}/target_h/events/equeue"
|
||||
"${PROJECT_SOURCE_DIR}/target_h/platform"
|
||||
"${PROJECT_SOURCE_DIR}/stubs"
|
||||
"${PROJECT_SOURCE_DIR}/.."
|
||||
"${PROJECT_SOURCE_DIR}/../features"
|
||||
"${PROJECT_SOURCE_DIR}/../features/netsocket"
|
||||
"${PROJECT_SOURCE_DIR}/../platform"
|
||||
"${PROJECT_SOURCE_DIR}/../drivers"
|
||||
"${PROJECT_SOURCE_DIR}/../hal"
|
||||
"${PROJECT_SOURCE_DIR}/../events"
|
||||
"${PROJECT_SOURCE_DIR}/../events/equeue"
|
||||
"${PROJECT_SOURCE_DIR}/../rtos"
|
||||
"${PROJECT_SOURCE_DIR}/../rtos/TARGET_CORTEX"
|
||||
"${PROJECT_SOURCE_DIR}/../rtos/TARGET_CORTEX/rtx5/Include"
|
||||
"${PROJECT_SOURCE_DIR}/../cmsis"
|
||||
"${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice/mbed-client-libservice/"
|
||||
"${PROJECT_SOURCE_DIR}/../features/frameworks"
|
||||
"${PROJECT_SOURCE_DIR}/../features/frameworks/mbed-trace"
|
||||
"${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice"
|
||||
"${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice/mbed-client-libservice"
|
||||
"${PROJECT_SOURCE_DIR}/../features/filesystem/fat"
|
||||
"${PROJECT_SOURCE_DIR}/../features/filesystem/fat/ChaN"
|
||||
"${PROJECT_SOURCE_DIR}/../features/filesystem/bd"
|
||||
"${PROJECT_SOURCE_DIR}/../features/filesystem/"
|
||||
"${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs"
|
||||
"${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs/littlefs"
|
||||
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/API"
|
||||
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/AT"
|
||||
"${PROJECT_SOURCE_DIR}/../features/cellular/framework"
|
||||
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/common"
|
||||
"${PROJECT_SOURCE_DIR}/../features/lorawan"
|
||||
"${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack"
|
||||
"${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack/mac"
|
||||
"${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack/phy"
|
||||
"${PROJECT_SOURCE_DIR}/../features/lorawan/system"
|
||||
"${PROJECT_SOURCE_DIR}/../features/mbedtls"
|
||||
"${PROJECT_SOURCE_DIR}/../features/mbedtls/inc"
|
||||
)
|
||||
|
||||
# Create a list for test suites.
|
||||
|
@ -129,11 +154,17 @@ foreach(testfile ${unittest-file-list})
|
|||
# Get source files
|
||||
include("${testfile}")
|
||||
|
||||
if(TEST_SUITE_NAME)
|
||||
set(TEST_SUITES ${TEST_SUITES} ${TEST_SUITE_NAME})
|
||||
else()
|
||||
message(FATAL_ERROR "No TEST_SUITE_NAME found in test file. Add it to ${testfile}.")
|
||||
endif()
|
||||
get_filename_component(TEST_SUITE_DIR ${testfile} DIRECTORY)
|
||||
|
||||
file(RELATIVE_PATH
|
||||
TEST_SUITE_NAME # output
|
||||
${PROJECT_SOURCE_DIR} # root
|
||||
${TEST_SUITE_DIR} #abs dirpath
|
||||
)
|
||||
|
||||
string(REGEX REPLACE "/|\\\\" "-" TEST_SUITE_NAME ${TEST_SUITE_NAME})
|
||||
|
||||
set(TEST_SUITES ${TEST_SUITES} ${TEST_SUITE_NAME})
|
||||
|
||||
set(LIBS_TO_BE_LINKED gmock_main)
|
||||
|
||||
|
@ -160,7 +191,7 @@ foreach(testfile ${unittest-file-list})
|
|||
# Link the executable with the libraries.
|
||||
target_link_libraries(${TEST_SUITE_NAME} ${LIBS_TO_BE_LINKED})
|
||||
|
||||
add_test(NAME "${TEST_SUITE_NAME}UnitTests" COMMAND ${TEST_SUITE_NAME})
|
||||
add_test(NAME "${TEST_SUITE_NAME}" COMMAND ${TEST_SUITE_NAME})
|
||||
|
||||
# Append test build directory to list
|
||||
list(APPEND BUILD_DIRECTORIES "./CMakeFiles/${TEST_SUITE_NAME}.dir")
|
||||
|
@ -168,3 +199,4 @@ foreach(testfile ${unittest-file-list})
|
|||
message(WARNING "No test source files found for ${TEST_SUITE_NAME}.\n")
|
||||
endif(unittest-test-sources)
|
||||
endforeach(testfile)
|
||||
|
||||
|
|
|
@ -1,242 +1,107 @@
|
|||
# Unit testing Mbed OS
|
||||
## Unit testing
|
||||
|
||||
This document describes how to run and write unit tests for Mbed OS.
|
||||
This document describes how to write and test unit tests for Mbed OS. To prevent and solve problems, please see the [troubleshooting](#troubleshooting) section.
|
||||
|
||||
## Prerequisites
|
||||
### Introduction
|
||||
|
||||
* GNU toolchains installed.
|
||||
* GCC 6 or later
|
||||
* MinGW-W64 GCC-6.4.0 or MinGW-W64 GCC-7.3.0 (Windows)
|
||||
* CMake 3.0+ installed.
|
||||
* Python 2.7.x or >3.5 and pip 10.0 (or newer) installed.
|
||||
* gcovr >=4.1
|
||||
Unit tests test code in small sections on a host machine. Unlike other testing tools, unit testing doesn't require embedded hardware, and it doesn't need to build the full operating system. Because of this, unit testing can result in faster tests than other testing tools. Unit testing takes place in a build environment where we test each C or C++ class or module in isolation. This means we build test suites into separate test binaries and stub all access outside to remove dependencies on any specific embedded hardware or software combination. This allows us to complete the testing using native compilers on the build machine.
|
||||
|
||||
### Installing dependencies on Debian/Ubuntu
|
||||
### Prerequisites
|
||||
|
||||
Please install the following dependencies to use Mbed OS unit testing.
|
||||
|
||||
- GNU toolchains.
|
||||
- GCC 6 or later. We recommend you use MinGW-W64 on Windows, but any Windows port of the above GCC versions works.
|
||||
- CMake 3.0 or newer.
|
||||
- Python 2.7.x, 3.5 or newer.
|
||||
- Pip 10.0 or newer.
|
||||
- Gcovr 4.1 or newer.
|
||||
- Mbed CLI 1.8.0 or newer.
|
||||
|
||||
Detailed instructions for supported operating systems are below.
|
||||
|
||||
#### Installing dependencies on Debian or Ubuntu
|
||||
|
||||
1. `sudo apt-get -y install build-essential cmake`
|
||||
2. Install python and pip:
|
||||
```
|
||||
sudo apt-get -y install python python-setuptools
|
||||
sudo easy_install pip
|
||||
```
|
||||
3. Install [gcovr](#installing-covr).
|
||||
4. (Optional) Install [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html).
|
||||
1. Install Python and Pip with:
|
||||
|
||||
### Installing dependencies on Mac OS
|
||||
```
|
||||
sudo apt-get -y install python python-setuptools
|
||||
sudo easy_install pip
|
||||
```
|
||||
|
||||
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
|
||||
|
||||
#### Installing dependencies on macOS
|
||||
|
||||
1. Install [Homebrew](https://brew.sh/).
|
||||
2. Install gcc compilers and cmake with: `brew install gcc cmake`
|
||||
3. Install python and pip:
|
||||
```
|
||||
brew install python
|
||||
sudo easy_install pip
|
||||
```
|
||||
3. Install [gcovr](#installing-covr).
|
||||
4. (Optional) Install [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html).
|
||||
1. Install GCC compilers and CMake with: `brew install gcc cmake`.
|
||||
1. Install Python and Pip:
|
||||
|
||||
### Installing dependencies on Windows
|
||||
```
|
||||
brew install python
|
||||
sudo easy_install pip
|
||||
```
|
||||
|
||||
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
|
||||
|
||||
#### Installing dependencies on Windows
|
||||
|
||||
1. Download and install [MinGW-W64](http://mingw-w64.org/).
|
||||
2. Download CMake binaries from https://cmake.org/download/ and run the installer.
|
||||
3. Download Python2.7 or Python3 from https://www.python.org/getit/ and run the installer.
|
||||
4. Add MinGW, CMake and Python into PATH.
|
||||
5. Install [gcovr](#installing-covr).
|
||||
6. (Optional) Install [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html).
|
||||
1. Download CMake binaries from https://cmake.org/download/, and run the installer.
|
||||
1. Download Python 2.7 or Python 3 from https://www.python.org/getit/, and run the installer.
|
||||
1. Add MinGW, CMake and Python into system PATH.
|
||||
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
|
||||
|
||||
### Installing covr
|
||||
### Test code structure
|
||||
|
||||
Install gcovr code coverage tool globally with `pip install "gcovr>=4.1"` or using virtualenv:
|
||||
Unit tests are located in the Mbed OS repository under the `UNITTESTS` folder. We recommend unit test files use an identical directory path to the file under test. This makes it easier to find unit tests for a particular class or a module. For example, if the file under test is `some/example/path/ClassName.cpp`, then all the test files are in the `UNITTESTS/some/example/path/ClassName` directory. Each test suite needs to have its own `unittest.cmake` file for test configuration.
|
||||
|
||||
#### virtualenv
|
||||
#### Test discovery
|
||||
|
||||
1. Install virtualenv if not installed with `pip install virtualenv`
|
||||
2. Install gcovr with:
|
||||
Registering unit tests for running is automatic, and the test runner handles registration. However, test files are not automatically assigned to be built. We build unit tests by using a separate build system, which searches for unit tests under the `UNITTESTS` directory.
|
||||
|
||||
**[Debian/Linux/Mac OS]**
|
||||
```
|
||||
virtualenv pyenv
|
||||
. pyenv/bin/activate
|
||||
pip install 'gcovr>=4.1'
|
||||
```
|
||||
**[Windows]**
|
||||
```
|
||||
virtualenv pyenv
|
||||
pyenv\\Scripts\\activate
|
||||
pip install "gcovr>=4.1"
|
||||
```
|
||||
For the build system to find and build any test suite automatically, you must include a unit test configuration file named `unittest.cmake` for each unit test suite. This configuration file contains all the source files required for the build.
|
||||
|
||||
## Building and running unit tests
|
||||
#### Test names
|
||||
|
||||
> In case of running into problems see [troubleshooting](#troubleshooting) section.
|
||||
The build system automatically generates names of test suites. The name is constructed by taking a relative file path from the UNITTESTS directory to the test directory and replacing path separators with dashes. For example, the test suite name for `some/example/path/ClassName.cpp` is `some-example-path-ClassName`. Suite names are used when deciding which test suites to run.
|
||||
|
||||
`UNITTESTS/mbed_unittest.py` contains testing scripts for Mbed OS unit testing. Mbed CLI supports unit testing through `mbed test --unittests` command with the same arguments.
|
||||
### Unit testing with Mbed CLI
|
||||
|
||||
### Testing with Mbed CLI
|
||||
Mbed CLI supports unit tests through `mbed test --unittests` command. For information on using Mbed CLI, please see the [CLI documentation in handbook](https://os.mbed.com/docs/latest/tools/arm-mbed-cli.html).
|
||||
|
||||
```
|
||||
mbed test --unittests
|
||||
```
|
||||
### Writing unit tests
|
||||
|
||||
A subset of tests can be run by providing `-r` flag for the tool which runs tests matching a regular expression.
|
||||
Create two files in the test directory for each test suite:
|
||||
|
||||
e.g. `mbed test --unittests --run -r features-netsocket`
|
||||
- Unit test source file (`test_ClassName.cpp`).
|
||||
- Unit test configuration file (`unittest.cmake`).
|
||||
|
||||
### Build manually without Python tools
|
||||
List all the files required for the build in the `unittest.cmake` file. We recommend you list the file paths relative to the `UNITTESTS` folder. Use the following variables to list the source files and include paths:
|
||||
|
||||
1. Create a build directory e.g. `mkdir UNITTESTS/build`.
|
||||
2. Move to the build directory `cd UNITTESTS/build`.
|
||||
3. Run CMake with `cmake [RELATIVE PATH TO UNITTESTS DIR] [OPTIONAL ARGUMENTS]` e.g. `cmake ..`:
|
||||
* Add `-g [generator]` argument if target other than Unix Makefiles e.g. MinGW `-g "MinGW Makefiles"`
|
||||
4. Run make program (make, gmake, mingw32-make, etc).
|
||||
- **unittest-includes** - List of header include paths. You can use this to extend or overwrite default paths listed in CMakeLists.txt.
|
||||
- **unittest-sources** - List of files under test.
|
||||
- **unittest-test-sources** - List of test sources and stubs.
|
||||
|
||||
##### Run CMake and build Unix Makefiles (GNU make)
|
||||
|
||||
```
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
##### Run CMake and build MinGW Makefiles (mingw32-make)
|
||||
|
||||
```
|
||||
cmake -G "MinGW Makefiles" ..
|
||||
mingw32-make
|
||||
```
|
||||
|
||||
#### Custom CMake variables
|
||||
|
||||
Usage:
|
||||
`cmake [RELATIVE PATH TO UNITTESTS DIR] [OPTIONS]`
|
||||
|
||||
Keyword variables (usage `cmake -D<VARIABLE>(:<TYPE>)=<value>`:
|
||||
|
||||
| Variable | Type | Accepted values | Description |
|
||||
| -------- | ---- | --------------- | ----------- |
|
||||
| COVERAGE | STRING | merged<br>separate | Generate merged or individual reports |
|
||||
|
||||
### Run in terminal
|
||||
|
||||
Unit tests can be run separately from each executable or by using ctest test runner. Run ctest with make program using target test. Options can be passed to ctest using ARGS argument. See [ctest manual](https://cmake.org/cmake/help/v3.0/manual/ctest.1.html) for more information.
|
||||
|
||||
Run ctest on test suite level:
|
||||
```
|
||||
{MAKE_PROGRAM} test -C [RELATIVE PATH TO BUILD DIRECTORY]
|
||||
```
|
||||
e.g. `make test -C UNITTESTS/build` or `mingw32-make test -C UNITTESTS/build`
|
||||
|
||||
Run ctest verbose (show each test case):
|
||||
```
|
||||
{MAKE_PROGRAM} test -C UNITTESTS/build ARGS="-V"
|
||||
```
|
||||
|
||||
Run ctest dashboard test and create test results:
|
||||
```
|
||||
{MAKE_PROGRAM} test --C UNITTESTS/build ARGS="-D ExperimentalTest"
|
||||
```
|
||||
|
||||
### Run with GUI test runner
|
||||
|
||||
1. Build and/or install *gtest-runner* using the documentation: https://github.com/nholthaus/gtest-runner
|
||||
|
||||
2. Run the application, add built test executables into the list and run it.
|
||||
|
||||
### Get code coverage
|
||||
|
||||
Python tools use gcovr to build code coverage reports. Generate html report `UNITTESTS/build/coverage/index.html` with:
|
||||
```
|
||||
mbed test --unittests --coverage html
|
||||
```
|
||||
|
||||
To get coverage for a single test suite, run gcovr separately for suite coverage data directory. See [gcovr documentation](https://gcovr.com/guide.html#filter-options) for more information.
|
||||
|
||||
e.g. for features/netsocket/InternetSocket coverage:
|
||||
|
||||
Debian/Ubuntu/Mac OS:
|
||||
```
|
||||
mkdir UNITTESTS/build
|
||||
cd UNITTESTS/build
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE:STRING=html ..
|
||||
make
|
||||
./features-netsocket-InternetSocket
|
||||
gcovr -r ../.. --html --html-detail -o ./index.html ./CMakeFiles/features-netsocket-InternetSocket.MbedOS.dir/
|
||||
```
|
||||
Windows:
|
||||
```
|
||||
mkdir UNITTESTS/build
|
||||
cd UNITTESTS/build
|
||||
cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE:STRING=html -g "MinGW Makefiles" ..
|
||||
mingw32-make
|
||||
features-netsocket-InternetSocket.exe
|
||||
gcovr -r ..\.. --html --html-detail -o .\index.html .\CMakeFiles\features-netsocket-InternetSocket.MbedOS.dir\
|
||||
```
|
||||
|
||||
## The structure of unit tests
|
||||
|
||||
The structure of the unit tests directory looks like this:
|
||||
```
|
||||
UNITTESTS
|
||||
├── mbed_unittest.py Python tool for unit testing
|
||||
├── unit_test Python tool modules
|
||||
├── CMakeLists.txt CMake project definition file
|
||||
├── CMakeSettings.json CMake configurations for Visual Studio 2017
|
||||
├── README.md
|
||||
├── googletest-CMakeLists.txt.in CMake project definition file for Google Test
|
||||
│
|
||||
├── features
|
||||
│ └── netsocket Directory tree that mirrors Mbed OS root
|
||||
│ ├── NetworkInterface Name of the class to be tested
|
||||
│ │ ├── test_NetworkInterface.cpp
|
||||
│ │ └── unittest.cmake CMake module for unit test
|
||||
│ └── Socket
|
||||
│
|
||||
├── stubs Shared stubs which can be used for tests.
|
||||
├── target_h Shared headers which can be used for tests.
|
||||
└── template Templates for creating new unittests
|
||||
```
|
||||
Each unit test has an identical directory tree as seen in the Mbed OS root folder. This is not a mandatory requirement but helps to maintain tests. Each class to be tested have their own `unittest.cmake` which is found by `CMakeLists.txt`.
|
||||
|
||||
## Creating a unit test
|
||||
|
||||
Each class to be tested requires two files for unit testing:
|
||||
1. C++ unit test source file (e.g. `test_NetworkInterface.cpp`)
|
||||
2. CMake module file for unit test definition (`unittest.cmake`)
|
||||
|
||||
A unit test definition file `unittest.cmake` requires variables to be set for a test to be configured. File source paths in `unittest.cmake` files need to be relative to the unit test folder and `CMakeLists.txt`.
|
||||
|
||||
* **TEST_SUITE_NAME** - Identifier for the test suite. Use naming convention *PATH_TO_THE_TESTABLE_FILE* e.g. *features-netsocket-InternetSocket*
|
||||
* **unittest-includes** - Include paths for headers needed to build the tests in addition to the base include paths listed in [CMakeLists.txt](CMakeLists.txt). Optional.
|
||||
* **unittest-sources** - Mbed OS source files and stubs included for the build.
|
||||
* **unittest-test-sources** - Unit test source files.
|
||||
|
||||
#### Creating unit tests files with Mbed CLI
|
||||
|
||||
```
|
||||
mbed test --unittests --new <FILEPATH>
|
||||
```
|
||||
|
||||
E.g. `mbed test --unittests --new rtos/Semaphore.cpp`
|
||||
|
||||
The generator script only creates the files required for a unit test. It does not write unit tests automatically nor does it handle source dependencies.
|
||||
|
||||
#### Create files manually
|
||||
|
||||
For example to create a unit test for `rtos/Semaphore.cpp`:
|
||||
With the following steps, you can write a simple unit test. In this example, `rtos/Semaphore.cpp` is a class under test.
|
||||
|
||||
1. Create a directory for unit test files in `UNITTESTS/rtos/Semaphore`.
|
||||
2. Create a test definition file `UNITTESTS/rtos/Semaphore/unittest.cmake` with the following content:
|
||||
```
|
||||
set(TEST_SUITE_NAME "rtos-Semaphore")
|
||||
1. Create a test configuration file `UNITTESTS/rtos/Semaphore/unittest.cmake` with the following content:
|
||||
|
||||
set(unittest-sources
|
||||
stubs/mbed_assert.c
|
||||
../rtos/Semaphore.cpp
|
||||
)
|
||||
```
|
||||
set(unittest-sources
|
||||
../rtos/Semaphore.cpp
|
||||
)
|
||||
|
||||
set(unittest-test-sources
|
||||
stubs/mbed_assert.c
|
||||
rtos/Semaphore/test_Semaphore.cpp
|
||||
)
|
||||
```
|
||||
|
||||
1. Create a test source file `UNITTESTS/rtos/Semaphore/test_Semaphore.cpp` with the following content:
|
||||
|
||||
set(unittest-test-sources
|
||||
rtos/Semaphore/test_Semaphore.cpp
|
||||
)
|
||||
```
|
||||
3. Create a test source file `UNITTESTS/rtos/Semaphore/test_Semaphore.cpp` with the following content:
|
||||
```
|
||||
#include "gtest/gtest.h"
|
||||
#include "rtos/Semaphore.h"
|
||||
|
@ -287,8 +152,39 @@ TEST_F(TestSemaphore, constructor)
|
|||
}
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
### Building and running unit tests
|
||||
|
||||
**Problem:** virus protection identifies files generated by CMake as malicious and quarantines the files on Windows.
|
||||
Use Mbed CLI to build and run unit tests. For advanced use, you can run CMake and a make program directly.
|
||||
|
||||
* **Solution**: restore the false positive files from the quarantine.
|
||||
#### Build tests directly with CMake
|
||||
|
||||
1. Create a build directory `mkdir UNITTESTS/build`.
|
||||
1. Move to the build directory `cd UNITTESTS/build`.
|
||||
1. Run CMake using a relative path to `UNITTESTS` folder as the argument. So from `UNITTESTS/build` use `cmake ..`:
|
||||
- Add `-g [generator]` if generating other than Unix Makefiles such in case of MinGW use `-g "MinGW Makefiles"`.
|
||||
- Add `-DCOVERAGE:True` to add coverage compiler flags.
|
||||
- See the [CMake manual](https://cmake.org/cmake/help/v3.0/manual/cmake.1.html) for more information.
|
||||
1. Run a make program (Make, Gmake, Mingw32-make and so on) to build the tests.
|
||||
|
||||
#### Run tests directly with CTest
|
||||
|
||||
Run a test binary in the build directory to run a unit test suite. To run multiple test suites at once, use CTest test runner. Run CTest with `ctest`. Add `-v` to get results for each test case. See the [CTest manual](https://cmake.org/cmake/help/v3.0/manual/ctest.1.html) for more information.
|
||||
|
||||
#### Run tests with GUI test runner
|
||||
|
||||
1. Install *gtest-runner* using the [documentation](https://github.com/nholthaus/gtest-runner).
|
||||
1. Run *gtest-runner*
|
||||
1. Add test executables into the list.
|
||||
1. Run them.
|
||||
|
||||
### Get code coverage
|
||||
|
||||
Use Mbed CLI to generate code coverage reports. For advanced use, you can run Gcovr or any other code coverage tool directly in the build directory.
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
**Problem:** Generic problems with CMake or with the build process.
|
||||
* **Solution**: Delete the build directory. Make sure that CMake, g++, gcc and a make program can be found in the path and are correct versions.
|
||||
|
||||
**Problem:** Virus protection identifies files generated by CMake as malicious and quarantines the files on Windows.
|
||||
* **Solution**: Restore the false positive files from the quarantine.
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "test_at_cellularbase.h"
|
||||
#include "EventQueue.h"
|
||||
#include "AT_CellularBase.h"
|
||||
#include "ATHandler_stub.h"
|
||||
#include "FileHandle_stub.h"
|
||||
#include <string.h>
|
||||
|
||||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
||||
Test_AT_CellularBase::Test_AT_CellularBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Test_AT_CellularBase::~Test_AT_CellularBase()
|
||||
{
|
||||
}
|
||||
|
||||
void Test_AT_CellularBase::test_AT_CellularBase_get_at_handler()
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
ATHandler ah(&fh, eq, 100, ",");
|
||||
AT_CellularBase at(ah);
|
||||
|
||||
EXPECT_EQ(&ah, &at.get_at_handler());
|
||||
}
|
||||
|
||||
void Test_AT_CellularBase::test_AT_CellularBase_get_device_error()
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
ATHandler ah(&fh, eq, 0, ",");
|
||||
AT_CellularBase at(ah);
|
||||
|
||||
ATHandler_stub::device_err_value.errCode = 8;
|
||||
|
||||
EXPECT_EQ(8, at.get_device_error().errCode);
|
||||
|
||||
ATHandler_stub::device_err_value.errCode = 0;
|
||||
}
|
|
@ -14,8 +14,9 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "test_at_cellularbase.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "AT_CellularBase.h"
|
||||
#include "EventQueue.h"
|
||||
#include "AT_CellularBase.h"
|
||||
#include "ATHandler_stub.h"
|
||||
|
@ -57,26 +58,44 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
Test_AT_CellularBase::Test_AT_CellularBase()
|
||||
{
|
||||
// AStyle ignored as the definition is not clear due to preprocessor usage
|
||||
// *INDENT-OFF*
|
||||
class TestAT_CellularBase : public testing::Test {
|
||||
protected:
|
||||
|
||||
void SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void TearDown()
|
||||
{
|
||||
}
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
TEST_F(TestAT_CellularBase, Create)
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
ATHandler ah(&fh, eq, 100, ",");
|
||||
AT_CellularBase *unit = new AT_CellularBase(ah);
|
||||
|
||||
EXPECT_TRUE(unit != NULL);
|
||||
|
||||
delete unit;
|
||||
}
|
||||
|
||||
Test_AT_CellularBase::~Test_AT_CellularBase()
|
||||
{
|
||||
}
|
||||
|
||||
void Test_AT_CellularBase::test_AT_CellularBase_get_at_handler()
|
||||
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_at_handler)
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
ATHandler ah(&fh, eq, 100, ",");
|
||||
AT_CellularBase at(ah);
|
||||
|
||||
CHECK(&ah == &at.get_at_handler());
|
||||
EXPECT_TRUE(&ah == &at.get_at_handler());
|
||||
}
|
||||
|
||||
void Test_AT_CellularBase::test_AT_CellularBase_get_device_error()
|
||||
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_device_error)
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
|
@ -85,12 +104,12 @@ void Test_AT_CellularBase::test_AT_CellularBase_get_device_error()
|
|||
|
||||
ATHandler_stub::device_err_value.errCode = 8;
|
||||
|
||||
CHECK_EQUAL(8, at.get_device_error().errCode);
|
||||
EXPECT_EQ(8, at.get_device_error().errCode);
|
||||
|
||||
ATHandler_stub::device_err_value.errCode = 0;
|
||||
}
|
||||
|
||||
void Test_AT_CellularBase::test_AT_CellularBase_set_unsupported_features()
|
||||
TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_unsupported_features)
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
|
@ -105,15 +124,14 @@ void Test_AT_CellularBase::test_AT_CellularBase_set_unsupported_features()
|
|||
at.set_unsupported_features(unsupported_features);
|
||||
}
|
||||
|
||||
void Test_AT_CellularBase::test_AT_CellularBase_is_supported()
|
||||
TEST_F(TestAT_CellularBase, test_AT_CellularBase_is_supported)
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
ATHandler ah(&fh, eq, 0, ",");
|
||||
my_base my_at(ah);
|
||||
|
||||
CHECK(true == my_at.check_supported());
|
||||
CHECK(true == my_at.check_supported_not_found());
|
||||
CHECK(false == my_at.check_not_supported());
|
||||
|
||||
EXPECT_TRUE(true == my_at.check_supported());
|
||||
EXPECT_TRUE(true == my_at.check_supported_not_found());
|
||||
EXPECT_TRUE(false == my_at.check_not_supported());
|
||||
}
|
|
@ -3,9 +3,6 @@
|
|||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "cellular-framework-AT-AT_CellularBase")
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
features/cellular/framework/AT/AT_CellularBase
|
||||
|
@ -23,10 +20,9 @@ set(unittest-sources
|
|||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
stubs/ATHandler_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.cpp
|
||||
features/cellular/framework/AT/AT_CellularBase/at_cellularbasetest.cpp
|
||||
)
|
|
@ -0,0 +1,277 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "AT_CellularDevice.h"
|
||||
#include "ATHandler_stub.h"
|
||||
#include "AT_CellularBase_stub.h"
|
||||
#include <string.h>
|
||||
|
||||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
||||
class TestAT_CellularDevice : public testing::Test {
|
||||
protected:
|
||||
|
||||
void SetUp() {
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TestAT_CellularDevice, Create)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
|
||||
CellularDevice *dev2 = new AT_CellularDevice(que);
|
||||
|
||||
EXPECT_TRUE(dev2 != NULL);
|
||||
delete dev2;
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
FileHandle_stub fh2;
|
||||
FileHandle_stub fh3;
|
||||
|
||||
EXPECT_TRUE(dev.open_network(&fh1));
|
||||
EXPECT_TRUE(dev.open_sms(&fh2));
|
||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
||||
EXPECT_TRUE(dev.open_sim(&fh3));
|
||||
ATHandler_stub::fh_value = &fh1;
|
||||
EXPECT_TRUE(dev.open_power(&fh1));
|
||||
|
||||
ATHandler_stub::fh_value = NULL;
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
|
||||
EXPECT_TRUE(!dev.open_network(NULL));
|
||||
EXPECT_TRUE(dev.open_network(&fh1));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
|
||||
EXPECT_TRUE(!dev.open_sms(NULL));
|
||||
EXPECT_TRUE(dev.open_sms(&fh1));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
|
||||
EXPECT_TRUE(!dev.open_power(NULL));
|
||||
EXPECT_TRUE(dev.open_power(&fh1));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
|
||||
EXPECT_TRUE(! dev.open_sim(NULL));
|
||||
EXPECT_TRUE(dev.open_sim(&fh1));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
|
||||
EXPECT_TRUE(!dev.open_information(NULL));
|
||||
EXPECT_TRUE(dev.open_information(&fh1));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::ref_count = 0;
|
||||
|
||||
EXPECT_TRUE(dev.open_network(&fh1));
|
||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.close_network();
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount);
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::ref_count = 0;
|
||||
|
||||
EXPECT_TRUE(dev.open_sms(&fh1));
|
||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.close_sms();
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount);
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::ref_count = 0;
|
||||
|
||||
EXPECT_TRUE(dev.open_power(&fh1));
|
||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.close_power();
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount);
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::ref_count = 0;
|
||||
int ana = 0;
|
||||
|
||||
EXPECT_TRUE(dev.open_sim(&fh1));
|
||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
||||
|
||||
ana = ATHandler_stub::ref_count;
|
||||
|
||||
dev.close_sms(); // this should not affect to refcount as it's not opened
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
|
||||
ana = ATHandler_stub::ref_count;
|
||||
|
||||
dev.close_sim();
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount);
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::int_value = 0;
|
||||
|
||||
EXPECT_TRUE(dev.open_information(&fh1));
|
||||
|
||||
ATHandler_stub::fh_value = NULL;
|
||||
AT_CellularBase_stub::handler_value = NULL;
|
||||
dev.close_information();
|
||||
|
||||
ATHandler_stub::fh_value = &fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
AT_CellularBase_stub::handler_value = &at;
|
||||
|
||||
EXPECT_TRUE(dev.open_information(&fh1));
|
||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
||||
|
||||
dev.close_information();
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
|
||||
|
||||
ATHandler_stub::fh_value = NULL;
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::timeout = 0;
|
||||
ATHandler_stub::default_timeout = false;
|
||||
|
||||
// no interfaces open so settings timeout should not change anything
|
||||
dev.set_timeout(5000);
|
||||
EXPECT_TRUE(ATHandler_stub::timeout == 0);
|
||||
EXPECT_TRUE(ATHandler_stub::default_timeout == false);
|
||||
|
||||
EXPECT_TRUE(dev.open_sim(&fh1));
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.set_timeout(5000);
|
||||
EXPECT_TRUE(ATHandler_stub::timeout == 5000);
|
||||
EXPECT_TRUE(ATHandler_stub::default_timeout == true);
|
||||
|
||||
dev.close_sim();
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
ATHandler_stub::debug_on = false;
|
||||
|
||||
// no interfaces open so debug toggling should not affect
|
||||
dev.modem_debug_on(true);
|
||||
EXPECT_TRUE(ATHandler_stub::debug_on == false);
|
||||
|
||||
EXPECT_TRUE(dev.open_sim(&fh1));
|
||||
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
|
||||
|
||||
dev.modem_debug_on(true);
|
||||
EXPECT_TRUE(ATHandler_stub::debug_on == true);
|
||||
|
||||
dev.close_sim();
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_stack)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
FileHandle_stub fh1;
|
||||
|
||||
NetworkStack *stack = dev.get_stack();
|
||||
EXPECT_TRUE(stack == NULL);
|
||||
|
||||
EXPECT_TRUE(dev.open_network(&fh1));
|
||||
|
||||
stack = dev.get_stack();
|
||||
EXPECT_TRUE(stack == NULL); // Not in PPP so also null but this is got from the network class
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
EXPECT_TRUE(0 == dev.get_send_delay());
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module)
|
||||
{
|
||||
EventQueue que;
|
||||
AT_CellularDevice dev(que);
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module(NULL));
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
####################
|
||||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
features/cellular/framework/common/util
|
||||
../features/cellular/framework/common
|
||||
../features/cellular/framework/AT
|
||||
../features/frameworks/mbed-client-randlib/mbed-client-randlib
|
||||
)
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
stubs/randLIB_stub.c
|
||||
../features/cellular/framework/AT/AT_CellularDevice.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp
|
||||
stubs/AT_CellularNetwork_stub.cpp
|
||||
stubs/ATHandler_stub.cpp
|
||||
stubs/AT_CellularSMS_stub.cpp
|
||||
stubs/AT_CellularSIM_stub.cpp
|
||||
stubs/AT_CellularPower_stub.cpp
|
||||
stubs/AT_CellularInformation_stub.cpp
|
||||
stubs/CellularUtil_stub.cpp
|
||||
stubs/AT_CellularBase_stub.cpp
|
||||
stubs/NetworkInterface_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
)
|
|
@ -14,8 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "test_at_cellularinformation.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <string.h>
|
||||
#include "ATHandler_stub.h"
|
||||
#include "EventQueue.h"
|
||||
|
@ -28,16 +27,32 @@
|
|||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
||||
Test_AT_CellularInformation::Test_AT_CellularInformation()
|
||||
{
|
||||
// AStyle ignored as the definition is not clear due to preprocessor usage
|
||||
// *INDENT-OFF*
|
||||
class TestAT_CellularInformation : public testing::Test {
|
||||
protected:
|
||||
|
||||
void SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void TearDown()
|
||||
{
|
||||
}
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
TEST_F(TestAT_CellularInformation, Create)
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
ATHandler ah(&fh, eq, 0, ",");
|
||||
AT_CellularInformation *unit = new AT_CellularInformation(ah);
|
||||
EXPECT_TRUE(unit != NULL);
|
||||
delete unit;
|
||||
}
|
||||
|
||||
Test_AT_CellularInformation::~Test_AT_CellularInformation()
|
||||
{
|
||||
}
|
||||
|
||||
void Test_AT_CellularInformation::test_AT_CellularInformation_get_manufacturer()
|
||||
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_manufacturer)
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
|
@ -45,21 +60,21 @@ void Test_AT_CellularInformation::test_AT_CellularInformation_get_manufacturer()
|
|||
AT_CellularInformation aci(ah);
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::read_string_value = "some";
|
||||
ATHandler_stub::read_string_value = (char *)"some";
|
||||
ATHandler_stub::ssize_value = 4;
|
||||
|
||||
char buf[8];
|
||||
CHECK(NSAPI_ERROR_OK == aci.get_manufacturer(buf, 8));
|
||||
CHECK(strcmp("some", buf) == 0);
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_manufacturer(buf, 8));
|
||||
EXPECT_TRUE(strcmp("some", buf) == 0);
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
ATHandler_stub::ssize_value = -1;
|
||||
buf[0] = 0;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == aci.get_manufacturer(buf, 8));
|
||||
CHECK(strlen(buf) == 0);
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_manufacturer(buf, 8));
|
||||
EXPECT_TRUE(strlen(buf) == 0);
|
||||
}
|
||||
|
||||
void Test_AT_CellularInformation::test_AT_CellularInformation_get_model()
|
||||
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_model)
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
|
@ -67,20 +82,20 @@ void Test_AT_CellularInformation::test_AT_CellularInformation_get_model()
|
|||
AT_CellularInformation aci(ah);
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::read_string_value = "model";
|
||||
ATHandler_stub::read_string_value = (char *)"model";
|
||||
ATHandler_stub::ssize_value = 5;
|
||||
char buf[8];
|
||||
CHECK(NSAPI_ERROR_OK == aci.get_model(buf, 8));
|
||||
CHECK(strcmp("model", buf) == 0);
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_model(buf, 8));
|
||||
EXPECT_TRUE(strcmp("model", buf) == 0);
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
ATHandler_stub::ssize_value = -1;
|
||||
buf[0] = 0;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == aci.get_model(buf, 8));
|
||||
CHECK(strlen(buf) == 0);
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_model(buf, 8));
|
||||
EXPECT_TRUE(strlen(buf) == 0);
|
||||
}
|
||||
|
||||
void Test_AT_CellularInformation::test_AT_CellularInformation_get_revision()
|
||||
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_revision)
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
|
@ -90,23 +105,23 @@ void Test_AT_CellularInformation::test_AT_CellularInformation_get_revision()
|
|||
AT_CellularInformation *aci = new AT_CellularInformation(ah);
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::read_string_value = "revision";
|
||||
ATHandler_stub::read_string_value = (char *)"revision";
|
||||
ATHandler_stub::ssize_value = 8;
|
||||
|
||||
char buf[9];
|
||||
CHECK(NSAPI_ERROR_OK == aci->get_revision(buf, 9));
|
||||
CHECK(strcmp("revision", buf) == 0);
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == aci->get_revision(buf, 9));
|
||||
EXPECT_TRUE(strcmp("revision", buf) == 0);
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
ATHandler_stub::ssize_value = -1;
|
||||
buf[0] = 0;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == aci->get_revision(buf, 8));
|
||||
CHECK(strlen(buf) == 0);
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci->get_revision(buf, 8));
|
||||
EXPECT_TRUE(strlen(buf) == 0);
|
||||
|
||||
delete aci;
|
||||
}
|
||||
|
||||
void Test_AT_CellularInformation::test_AT_CellularInformation_get_serial_number()
|
||||
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_serial_number)
|
||||
{
|
||||
EventQueue eq;
|
||||
FileHandle_stub fh;
|
||||
|
@ -114,28 +129,27 @@ void Test_AT_CellularInformation::test_AT_CellularInformation_get_serial_number(
|
|||
AT_CellularInformation aci(ah);
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::read_string_value = "1234567";
|
||||
ATHandler_stub::read_string_value = (char *)"1234567";
|
||||
ATHandler_stub::ssize_value = 7;
|
||||
char buf[8];
|
||||
|
||||
CHECK(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::SN));
|
||||
CHECK(strcmp("1234567", buf) == 0);
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::SN));
|
||||
EXPECT_TRUE(strcmp("1234567", buf) == 0);
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
ATHandler_stub::ssize_value = -1;
|
||||
buf[0] = 0;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == aci.get_serial_number(buf, 8, CellularInformation::SN));
|
||||
CHECK(strlen(buf) == 0);
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_serial_number(buf, 8, CellularInformation::SN));
|
||||
EXPECT_TRUE(strlen(buf) == 0);
|
||||
|
||||
AT_CellularBase_stub::supported_bool = false;
|
||||
CHECK(NSAPI_ERROR_UNSUPPORTED == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
|
||||
CHECK(strlen(buf) == 0);
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
|
||||
EXPECT_TRUE(strlen(buf) == 0);
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::read_string_value = "1234567";
|
||||
ATHandler_stub::read_string_value = (char *)"1234567";
|
||||
ATHandler_stub::ssize_value = 7;
|
||||
AT_CellularBase_stub::supported_bool = true;
|
||||
CHECK(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
|
||||
CHECK(strcmp("1234567", buf) == 0);
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
|
||||
EXPECT_TRUE(strcmp("1234567", buf) == 0);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
####################
|
||||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
features/cellular/framework/common/util
|
||||
../features/cellular/framework/common
|
||||
../features/cellular/framework/AT
|
||||
../features/frameworks/mbed-client-randlib/mbed-client-randlib
|
||||
)
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
stubs/randLIB_stub.c
|
||||
../features/cellular/framework/AT/AT_CellularInformation.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
features/cellular/framework/AT//at_cellularinformation/at_cellularinformationtest.cpp
|
||||
stubs/ATHandler_stub.cpp
|
||||
stubs/AT_CellularBase_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
)
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,34 @@
|
|||
|
||||
####################
|
||||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
features/cellular/framework/common/util
|
||||
../features/cellular/framework/common
|
||||
../features/cellular/framework/AT
|
||||
../features/frameworks/mbed-client-randlib/mbed-client-randlib
|
||||
)
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/cellular/framework/AT/AT_CellularNetwork.cpp
|
||||
../features/cellular/framework/AT/AT_CellularStack.cpp
|
||||
../features/cellular/framework/common/CellularUtil.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp
|
||||
stubs/ATHandler_stub.cpp
|
||||
stubs/AT_CellularBase_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
stubs/NetworkInterface_stub.cpp
|
||||
stubs/NetworkStack_stub.cpp
|
||||
stubs/us_ticker_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
stubs/SocketAddress_stub.cpp
|
||||
stubs/randLIB_stub.cpp
|
||||
)
|
|
@ -14,8 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "test_at_cellularpower.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <string.h>
|
||||
#include "AT_CellularNetwork.h"
|
||||
#include "EventQueue.h"
|
||||
|
@ -27,47 +26,60 @@
|
|||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
||||
Test_AT_CellularPower::Test_AT_CellularPower()
|
||||
{
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
}
|
||||
// AStyle ignored as the definition is not clear due to preprocessor usage
|
||||
// *INDENT-OFF*
|
||||
class TestAT_CellularPower : public testing::Test {
|
||||
protected:
|
||||
|
||||
Test_AT_CellularPower::~Test_AT_CellularPower()
|
||||
void SetUp() {
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
void TearDown() {
|
||||
}
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
|
||||
static void device_ready_cb()
|
||||
{
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_constructor()
|
||||
TEST_F(TestAT_CellularPower, Create)
|
||||
{
|
||||
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularPower *pow = new AT_CellularPower(at);
|
||||
|
||||
EXPECT_TRUE(pow != NULL);
|
||||
|
||||
delete pow;
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_on()
|
||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_on)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularPower pow(at);
|
||||
CHECK(NSAPI_ERROR_UNSUPPORTED == pow.on());
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.on());
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_off()
|
||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_off)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularPower pow(at);
|
||||
CHECK(NSAPI_ERROR_UNSUPPORTED == pow.off());
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.off());
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_set_at_mode()
|
||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_at_mode)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -75,13 +87,13 @@ void Test_AT_CellularPower::test_AT_CellularPower_set_at_mode()
|
|||
|
||||
AT_CellularPower pow(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
CHECK(NSAPI_ERROR_OK == pow.set_at_mode());
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_at_mode());
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.set_at_mode());
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_at_mode());
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_set_power_level()
|
||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_power_level)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -89,15 +101,15 @@ void Test_AT_CellularPower::test_AT_CellularPower_set_power_level()
|
|||
|
||||
AT_CellularPower pow(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
CHECK(NSAPI_ERROR_OK == pow.set_power_level(6));
|
||||
CHECK(NSAPI_ERROR_OK == pow.set_power_level(1, 1));
|
||||
CHECK(NSAPI_ERROR_OK == pow.set_power_level(1, 0));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(6));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(1, 1));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(1, 0));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.set_power_level(6));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_power_level(6));
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_reset()
|
||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -105,13 +117,13 @@ void Test_AT_CellularPower::test_AT_CellularPower_reset()
|
|||
|
||||
AT_CellularPower pow(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
CHECK(NSAPI_ERROR_OK == pow.reset());
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.reset());
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.reset());
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset());
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_opt_power_save_mode()
|
||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_power_save_mode)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -119,27 +131,27 @@ void Test_AT_CellularPower::test_AT_CellularPower_opt_power_save_mode()
|
|||
|
||||
AT_CellularPower pow(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(0, 0));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(0, 0));
|
||||
|
||||
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(10, 0));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(10, 0));
|
||||
|
||||
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(912, 0));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(912, 0));
|
||||
|
||||
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(1834, 1834));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(1834, 1834));
|
||||
|
||||
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(18345, 18345));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(18345, 18345));
|
||||
|
||||
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(101234, 101234));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(101234, 101234));
|
||||
|
||||
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(1012345, 1012345));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(1012345, 1012345));
|
||||
|
||||
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(39612345, 39612345));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(39612345, 39612345));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.opt_power_save_mode(0, 0));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_power_save_mode(0, 0));
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_opt_receive_period()
|
||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_receive_period)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -147,13 +159,13 @@ void Test_AT_CellularPower::test_AT_CellularPower_opt_receive_period()
|
|||
|
||||
AT_CellularPower pow(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
CHECK(NSAPI_ERROR_OK == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3));
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_is_device_ready()
|
||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_is_device_ready)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -161,32 +173,28 @@ void Test_AT_CellularPower::test_AT_CellularPower_is_device_ready()
|
|||
|
||||
AT_CellularPower pow(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
|
||||
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.is_device_ready());
|
||||
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == pow.is_device_ready());
|
||||
}
|
||||
|
||||
static void device_ready_cb()
|
||||
{
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_set_device_ready_urc_cb()
|
||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularPower pow(at);
|
||||
CHECK(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
|
||||
CHECK(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(NULL));
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(NULL));
|
||||
}
|
||||
|
||||
void Test_AT_CellularPower::test_AT_CellularPower_remove_device_ready_urc_cb()
|
||||
TEST_F(TestAT_CellularPower, test_AT_CellularPower_remove_device_ready_urc_cb)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularPower pow(at);
|
||||
CHECK(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
|
||||
|
||||
pow.remove_device_ready_urc_cb(NULL);
|
||||
pow.remove_device_ready_urc_cb(&device_ready_cb);
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
####################
|
||||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
features/cellular/framework/common/util
|
||||
../features/cellular/framework/common
|
||||
../features/cellular/framework/AT
|
||||
../features/frameworks/mbed-client-randlib/mbed-client-randlib
|
||||
)
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/cellular/framework/AT/AT_CellularPower.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp
|
||||
stubs/ATHandler_stub.cpp
|
||||
stubs/AT_CellularBase_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
stubs/CellularUtil_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
)
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "ATHandler_stub.h"
|
||||
#include <string.h>
|
||||
#include "AT_CellularNetwork.h"
|
||||
#include "EventQueue.h"
|
||||
#include "ATHandler.h"
|
||||
#include "AT_CellularSIM.h"
|
||||
#include "FileHandle_stub.h"
|
||||
#include "CellularLog.h"
|
||||
#include "ATHandler_stub.h"
|
||||
|
||||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
||||
// AStyle ignored as the definition is not clear due to preprocessor usage
|
||||
// *INDENT-OFF*
|
||||
class TestAT_CellularSIM : public testing::Test {
|
||||
protected:
|
||||
|
||||
void SetUp()
|
||||
{
|
||||
ATHandler_stub::read_string_index = kRead_string_table_size;
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::read_string_value = NULL;
|
||||
ATHandler_stub::ssize_value = 0;
|
||||
}
|
||||
|
||||
void TearDown()
|
||||
{
|
||||
}
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
TEST_F(TestAT_CellularSIM, Create)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularSIM *sim = new AT_CellularSIM(at);
|
||||
|
||||
EXPECT_TRUE(sim != NULL);
|
||||
delete sim;
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularSIM sim(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12"));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin("12"));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::read_string_value = (char *)"READY";
|
||||
ATHandler_stub::ssize_value = 5;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12"));
|
||||
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin(NULL));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_change_pin)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularSIM sim(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin("12", "34"));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin(NULL, "34"));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin("12", NULL));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin(NULL, NULL));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.change_pin("12", "34"));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin_query)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularSIM sim(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query("12", true));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query(NULL, true));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query("12", false));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query(NULL, false));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", false));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", true));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_sim_state)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularSIM sim(at);
|
||||
CellularSIM::SimState state;
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::ssize_value = -1;
|
||||
ATHandler_stub::read_string_value = NULL;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
|
||||
EXPECT_TRUE(CellularSIM::SimStateUnknown == state);
|
||||
|
||||
ATHandler_stub::read_string_value = (char *)"READY";
|
||||
ATHandler_stub::ssize_value = 5;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
|
||||
EXPECT_TRUE(CellularSIM::SimStateReady == state);
|
||||
|
||||
ATHandler_stub::read_string_value = (char *)"SIM PIN";
|
||||
ATHandler_stub::ssize_value = 7;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
|
||||
EXPECT_TRUE(CellularSIM::SimStatePinNeeded == state);
|
||||
|
||||
ATHandler_stub::read_string_value = (char *)"SIM PUK";
|
||||
ATHandler_stub::ssize_value = 7;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
|
||||
EXPECT_TRUE(CellularSIM::SimStatePukNeeded == state);
|
||||
|
||||
ATHandler_stub::read_string_value = (char *)"SOME CRAP";
|
||||
ATHandler_stub::ssize_value = 9;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
|
||||
EXPECT_TRUE(CellularSIM::SimStateUnknown == state);
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_imsi)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
char imsi[16];
|
||||
AT_CellularSIM sim(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::read_string_value = (char *)"123456789012345";
|
||||
ATHandler_stub::ssize_value = 15;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_imsi(imsi));
|
||||
EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, imsi) == 0);
|
||||
|
||||
ATHandler_stub::read_string_value = NULL;
|
||||
ATHandler_stub::ssize_value = -1;
|
||||
ATHandler_stub::read_string_index = -1;
|
||||
imsi[0] = 0;
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_imsi(imsi));
|
||||
EXPECT_TRUE(strlen(imsi) == 0);
|
||||
|
||||
EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(NULL));
|
||||
|
||||
// this would fail as get_imsi should take another param which is the size of the buffer which we could use for validation.
|
||||
// Now we have improved documentation that that the given imsi buffer size must be over 15.
|
||||
//char imsi2[5];
|
||||
//EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(imsi2));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_iccid)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
char buf[16];
|
||||
AT_CellularSIM sim(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::read_string_value = (char *)"123456789012345";
|
||||
ATHandler_stub::ssize_value = 15;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_iccid(buf, 16));
|
||||
EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, buf) == 0);
|
||||
|
||||
buf[0] = 0;
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
|
||||
ATHandler_stub::read_string_value = NULL;
|
||||
ATHandler_stub::ssize_value = -1;
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_iccid(buf, 16));
|
||||
EXPECT_TRUE(strlen(buf) == 0);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
####################
|
||||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
features/cellular/framework/common/util
|
||||
../features/cellular/framework/common
|
||||
../features/cellular/framework/AT
|
||||
../features/frameworks/mbed-client-randlib/mbed-client-randlib
|
||||
)
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/cellular/framework/AT/AT_CellularSIM.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp
|
||||
stubs/ATHandler_stub.cpp
|
||||
stubs/AT_CellularBase_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
stubs/CellularUtil_stub.cpp
|
||||
stubs/us_ticker_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
)
|
|
@ -14,8 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "test_at_cellularsms.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <string.h>
|
||||
#include "AT_CellularNetwork.h"
|
||||
#include "EventQueue.h"
|
||||
|
@ -28,17 +27,24 @@
|
|||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
||||
Test_AT_CellularSMS::Test_AT_CellularSMS()
|
||||
{
|
||||
ATHandler_stub::return_given_size = false;
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
}
|
||||
// AStyle ignored as the definition is not clear due to preprocessor usage
|
||||
// *INDENT-OFF*
|
||||
class TestAT_CellularSMS : public testing::Test {
|
||||
protected:
|
||||
|
||||
Test_AT_CellularSMS::~Test_AT_CellularSMS()
|
||||
{
|
||||
}
|
||||
void SetUp()
|
||||
{
|
||||
ATHandler_stub::return_given_size = false;
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
void Test_AT_CellularSMS::test_AT_CellularSMS_constructor()
|
||||
void TearDown()
|
||||
{
|
||||
}
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
TEST_F(TestAT_CellularSMS, Create)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -46,50 +52,66 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_constructor()
|
|||
|
||||
AT_CellularSMS *sms = new AT_CellularSMS(at);
|
||||
|
||||
EXPECT_TRUE(sms != NULL);
|
||||
delete sms;
|
||||
}
|
||||
|
||||
void Test_AT_CellularSMS::test_AT_CellularSMS_initialize()
|
||||
void my_callback()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_initialize)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
ATHandler_stub::call_immediately = true;
|
||||
|
||||
AT_CellularSMS sms(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
|
||||
CHECK(NSAPI_ERROR_NO_MEMORY == sms.initialize(CellularSMS::CellularSMSMmodeText));
|
||||
EXPECT_TRUE(NSAPI_ERROR_NO_MEMORY == sms.initialize(CellularSMS::CellularSMSMmodeText));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sms.initialize(CellularSMS::CellularSMSMmodeText));
|
||||
|
||||
sms.set_sms_callback(&my_callback);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == sms.initialize(CellularSMS::CellularSMSMmodeText));
|
||||
|
||||
ATHandler_stub::call_immediately = false;
|
||||
}
|
||||
|
||||
|
||||
void Test_AT_CellularSMS::test_AT_CellularSMS_send_sms()
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_send_sms)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
AT_CellularSMS sms(at);
|
||||
LONGS_EQUAL(NSAPI_ERROR_PARAMETER, sms.send_sms(NULL, "2", 1));
|
||||
EXPECT_EQ(NSAPI_ERROR_PARAMETER, sms.send_sms(NULL, "2", 1));
|
||||
|
||||
sms.initialize(CellularSMS::CellularSMSMmodeText);
|
||||
ATHandler_stub::size_value = 1;
|
||||
LONGS_EQUAL(1, sms.send_sms("1", "22", 2));
|
||||
EXPECT_EQ(1, sms.send_sms("1", "22", 2));
|
||||
|
||||
ATHandler_stub::size_value = 2;
|
||||
LONGS_EQUAL(2, sms.send_sms("1", "22", 2));
|
||||
EXPECT_EQ(2, sms.send_sms("1", "22", 2));
|
||||
|
||||
ATHandler_stub::return_given_size = true; // PDU mode write is much longer than than msg len
|
||||
sms.initialize(CellularSMS::CellularSMSMmodePDU);
|
||||
LONGS_EQUAL(2, sms.send_sms("1", "23", 2));;
|
||||
EXPECT_EQ(2, sms.send_sms("1", "23", 2));;
|
||||
|
||||
ATHandler_stub::nsapi_error_ok_counter = 1;
|
||||
ATHandler_stub::size_value = 32;
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
|
||||
LONGS_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8));
|
||||
EXPECT_EQ(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8));
|
||||
|
||||
ATHandler_stub::nsapi_error_ok_counter = 2;
|
||||
ATHandler_stub::size_value = 32;
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
|
||||
LONGS_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8));
|
||||
EXPECT_EQ(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
char table[] = "232323232323232323232323232323232323232323232323232323\
|
||||
|
@ -97,12 +119,11 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_send_sms()
|
|||
232323232323232323232323232323232323232323232323232323\
|
||||
23232323232323232323232323232323232323\0";
|
||||
|
||||
LONGS_EQUAL(strlen(table), sms.send_sms("1", table, strlen(table)));
|
||||
LONGS_EQUAL(strlen(table), sms.send_sms("12", table, strlen(table)));
|
||||
EXPECT_EQ(strlen(table), sms.send_sms("1", table, strlen(table)));
|
||||
EXPECT_EQ(strlen(table), sms.send_sms("12", table, strlen(table)));
|
||||
}
|
||||
|
||||
|
||||
void Test_AT_CellularSMS::test_AT_CellularSMS_get_sms()
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_get_sms)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -113,28 +134,27 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_get_sms()
|
|||
char phone[21];
|
||||
char stamp[21];
|
||||
int size;
|
||||
CHECK(NSAPI_ERROR_PARAMETER == sms.get_sms(NULL, 16, phone, 21, stamp, 21, &size));
|
||||
EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sms.get_sms(NULL, 16, phone, 21, stamp, 21, &size));
|
||||
|
||||
ATHandler_stub::resp_info_true_counter = 1;
|
||||
ATHandler_stub::int_value = 0;
|
||||
CHECK(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
|
||||
EXPECT_TRUE(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
|
||||
|
||||
ATHandler_stub::resp_info_true_counter = 2;
|
||||
ATHandler_stub::int_value = 11;
|
||||
CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
|
||||
EXPECT_TRUE(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
|
||||
//TODO: Should make add_info to happen, before calling get_sms!
|
||||
|
||||
ATHandler_stub::resp_info_true_counter = 2;
|
||||
ATHandler_stub::int_value = 11;
|
||||
sms.initialize(CellularSMS::CellularSMSMmodePDU);
|
||||
CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
|
||||
EXPECT_TRUE(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
|
||||
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
|
||||
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
|
||||
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
|
||||
}
|
||||
|
||||
|
||||
void Test_AT_CellularSMS::test_AT_CellularSMS_set_sms_callback()
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_sms_callback)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -144,8 +164,7 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_set_sms_callback()
|
|||
sms.set_sms_callback(NULL);
|
||||
}
|
||||
|
||||
|
||||
void Test_AT_CellularSMS::test_AT_CellularSMS_set_cpms()
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_cpms)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -153,11 +172,10 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_set_cpms()
|
|||
|
||||
AT_CellularSMS sms(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
|
||||
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_cpms("2", "3", "4"));
|
||||
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_cpms("2", "3", "4"));
|
||||
}
|
||||
|
||||
|
||||
void Test_AT_CellularSMS::test_AT_CellularSMS_set_csca()
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_csca)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -165,11 +183,10 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_set_csca()
|
|||
|
||||
AT_CellularSMS sms(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
|
||||
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_csca("2", 1));
|
||||
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_csca("2", 1));
|
||||
}
|
||||
|
||||
|
||||
void Test_AT_CellularSMS::test_AT_CellularSMS_set_cscs()
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_cscs)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -177,11 +194,10 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_set_cscs()
|
|||
|
||||
AT_CellularSMS sms(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
|
||||
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_cscs("2"));
|
||||
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_cscs("2"));
|
||||
}
|
||||
|
||||
|
||||
void Test_AT_CellularSMS::test_AT_CellularSMS_delete_all_messages()
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_delete_all_messages)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -189,11 +205,10 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_delete_all_messages()
|
|||
|
||||
AT_CellularSMS sms(at);
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
|
||||
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.delete_all_messages());
|
||||
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.delete_all_messages());
|
||||
}
|
||||
|
||||
|
||||
void Test_AT_CellularSMS::test_AT_CellularSMS_set_extra_sim_wait_time()
|
||||
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_extra_sim_wait_time)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -201,6 +216,4 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_set_extra_sim_wait_time()
|
|||
|
||||
AT_CellularSMS sms(at);
|
||||
sms.set_extra_sim_wait_time(56);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
####################
|
||||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
features/cellular/framework/common/util
|
||||
../features/cellular/framework/common
|
||||
../features/cellular/framework/AT
|
||||
../features/frameworks/mbed-client-randlib/mbed-client-randlib
|
||||
)
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/cellular/framework/AT/AT_CellularSMS.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp
|
||||
stubs/ATHandler_stub.cpp
|
||||
stubs/AT_CellularBase_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
stubs/CellularUtil_stub.cpp
|
||||
stubs/us_ticker_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
stubs/mbed_wait_api_stub.cpp
|
||||
)
|
|
@ -14,8 +14,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "test_at_cellularstack.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "AT_CellularStack.h"
|
||||
#include <string.h>
|
||||
#include "AT_CellularNetwork.h"
|
||||
#include "EventQueue.h"
|
||||
|
@ -136,18 +136,27 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
Test_AT_CellularStack::Test_AT_CellularStack()
|
||||
{
|
||||
ATHandler_stub::ssize_value = 0;
|
||||
ATHandler_stub::bool_value = false;
|
||||
ATHandler_stub::read_string_value = NULL;
|
||||
}
|
||||
// AStyle ignored as the definition is not clear due to preprocessor usage
|
||||
// *INDENT-OFF*
|
||||
class TestAT_CellularStack : public testing::Test {
|
||||
protected:
|
||||
|
||||
Test_AT_CellularStack::~Test_AT_CellularStack()
|
||||
{
|
||||
}
|
||||
void SetUp()
|
||||
{
|
||||
ATHandler_stub::return_given_size = false;
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ATHandler_stub::ssize_value = 0;
|
||||
ATHandler_stub::bool_value = false;
|
||||
ATHandler_stub::read_string_value = NULL;
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_constructor()
|
||||
void TearDown()
|
||||
{
|
||||
}
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
TEST_F(TestAT_CellularStack, Create)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -155,31 +164,32 @@ void Test_AT_CellularStack::test_AT_CellularStack_constructor()
|
|||
|
||||
MyStack *st = new MyStack(at, 0, IPV4_STACK);
|
||||
|
||||
EXPECT_TRUE(st != NULL);
|
||||
delete st;
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_get_ip_address()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_get_ip_address)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
CHECK(0 == strlen(st.get_ip_address()));
|
||||
EXPECT_TRUE(0 == strlen(st.get_ip_address()));
|
||||
|
||||
char table[] = "1.2.3.4.5.65.7.8.9.10.11\0";
|
||||
ATHandler_stub::ssize_value = -1;
|
||||
ATHandler_stub::bool_value = true;
|
||||
ATHandler_stub::read_string_value = table;
|
||||
CHECK(NULL == st.get_ip_address());
|
||||
EXPECT_TRUE(NULL == st.get_ip_address());
|
||||
|
||||
ATHandler_stub::ssize_value = strlen(table);
|
||||
ATHandler_stub::bool_value = true;
|
||||
ATHandler_stub::read_string_value = table;
|
||||
CHECK(st.get_ip_address());
|
||||
EXPECT_TRUE(st.get_ip_address());
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_open()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -187,45 +197,45 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_open()
|
|||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
st.bool_value = false;
|
||||
CHECK(NSAPI_ERROR_UNSUPPORTED == st.socket_open(NULL, NSAPI_TCP));
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_open(NULL, NSAPI_TCP));
|
||||
|
||||
st.bool_value = true;
|
||||
st.max_sock_value = 0;
|
||||
nsapi_socket_t sock = &st.socket;
|
||||
CHECK(NSAPI_ERROR_NO_SOCKET == st.socket_open(&sock, NSAPI_TCP));
|
||||
EXPECT_TRUE(NSAPI_ERROR_NO_SOCKET == st.socket_open(&sock, NSAPI_TCP));
|
||||
|
||||
MyStack st2(at, 0, IPV6_STACK);
|
||||
st2.bool_value = true;
|
||||
st2.max_sock_value = 1;
|
||||
sock = &st2.socket;
|
||||
CHECK(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP));
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_close()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_close)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(&st.socket));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(&st.socket));
|
||||
|
||||
nsapi_socket_t sock = &st.socket;
|
||||
st.bool_value = true;
|
||||
st.max_sock_value = 1;
|
||||
CHECK(NSAPI_ERROR_OK == st.socket_open(&sock, NSAPI_TCP));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_open(&sock, NSAPI_TCP));
|
||||
st.max_sock_value = 0;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(sock));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(sock));
|
||||
|
||||
MyStack st2(at, 0, IPV6_STACK);
|
||||
st2.max_sock_value = 1;
|
||||
st2.bool_value = true;
|
||||
sock = &st2.socket;
|
||||
CHECK(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP));
|
||||
CHECK(NSAPI_ERROR_OK == st2.socket_close(sock));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_close(sock));
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_bind()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_bind)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -234,22 +244,22 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_bind()
|
|||
MyStack st(at, 0, IPV6_STACK);
|
||||
SocketAddress addr;
|
||||
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_ALREADY;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_bind(NULL, addr));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_bind(NULL, addr));
|
||||
|
||||
CHECK(NSAPI_ERROR_ALREADY == st.socket_bind(&st.socket, addr));
|
||||
EXPECT_TRUE(NSAPI_ERROR_ALREADY == st.socket_bind(&st.socket, addr));
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_listen()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_listen)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
CHECK(NSAPI_ERROR_UNSUPPORTED == st.socket_listen(&st.socket, 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_listen(&st.socket, 4));
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_connect()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_connect)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -257,12 +267,12 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_connect()
|
|||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
SocketAddress addr;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_connect(NULL, addr));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_connect(NULL, addr));
|
||||
|
||||
CHECK(NSAPI_ERROR_OK == st.socket_connect(&st.socket, addr));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_connect(&st.socket, addr));
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_accept()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_accept)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -270,19 +280,19 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_accept()
|
|||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
nsapi_socket_t sock = &st.socket;
|
||||
CHECK(NSAPI_ERROR_UNSUPPORTED == st.socket_accept(NULL, &sock));
|
||||
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_accept(NULL, &sock));
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_send()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_send)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(NULL, "addr", 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(NULL, "addr", 4));
|
||||
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(&st.socket, "addr", 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(&st.socket, "addr", 4));
|
||||
|
||||
SocketAddress addr;
|
||||
st.max_sock_value = 1;
|
||||
|
@ -290,10 +300,10 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_send()
|
|||
nsapi_socket_t sock = &st.socket;
|
||||
st.socket_open(&sock, NSAPI_TCP);
|
||||
st.socket_connect(sock, addr);
|
||||
CHECK(NSAPI_ERROR_OK == st.socket_send(sock, "addr", 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_send(sock, "addr", 4));
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_sendto()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_sendto)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -302,7 +312,7 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_sendto()
|
|||
MyStack st(at, 0, IPV6_STACK);
|
||||
|
||||
SocketAddress addr;
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_sendto(NULL, addr, "addr", 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_sendto(NULL, addr, "addr", 4));
|
||||
|
||||
st.max_sock_value = 1;
|
||||
st.bool_value = true;
|
||||
|
@ -310,13 +320,13 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_sendto()
|
|||
st.socket_open(&sock, NSAPI_TCP);
|
||||
st.socket_connect(sock, addr);
|
||||
st.create_error = NSAPI_ERROR_CONNECTION_LOST;
|
||||
CHECK(NSAPI_ERROR_CONNECTION_LOST == st.socket_sendto(sock, addr, "addr", 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_CONNECTION_LOST == st.socket_sendto(sock, addr, "addr", 4));
|
||||
|
||||
st.create_error = NSAPI_ERROR_OK;
|
||||
CHECK(NSAPI_ERROR_OK == st.socket_sendto(sock, addr, "addr", 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_sendto(sock, addr, "addr", 4));
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_recv()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recv)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -324,10 +334,10 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_recv()
|
|||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
char table[4];
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_recv(NULL, table, 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_recv(NULL, table, 4));
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_recvfrom()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recvfrom)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -335,7 +345,7 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_recvfrom()
|
|||
|
||||
MyStack st(at, 0, IPV6_STACK);
|
||||
char table[4];
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_recvfrom(NULL, NULL, table, 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_recvfrom(NULL, NULL, table, 4));
|
||||
|
||||
SocketAddress addr;
|
||||
st.max_sock_value = 1;
|
||||
|
@ -344,13 +354,13 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_recvfrom()
|
|||
st.socket_open(&sock, NSAPI_TCP);
|
||||
st.socket_connect(sock, addr);
|
||||
st.create_error = NSAPI_ERROR_CONNECTION_LOST;
|
||||
CHECK(NSAPI_ERROR_CONNECTION_LOST == st.socket_recvfrom(sock, &addr, table, 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_CONNECTION_LOST == st.socket_recvfrom(sock, &addr, table, 4));
|
||||
|
||||
st.create_error = NSAPI_ERROR_OK;
|
||||
CHECK(NSAPI_ERROR_OK == st.socket_recvfrom(sock, &addr, table, 4));
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_recvfrom(sock, &addr, table, 4));
|
||||
}
|
||||
|
||||
void Test_AT_CellularStack::test_AT_CellularStack_socket_attach()
|
||||
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_attach)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
####################
|
||||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
features/cellular/framework/common/util
|
||||
../features/cellular/framework/common
|
||||
../features/cellular/framework/AT
|
||||
../features/frameworks/mbed-client-randlib/mbed-client-randlib
|
||||
)
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/cellular/framework/AT/AT_CellularStack.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
features/cellular/framework/AT/at_cellularstack/at_cellularstacktest.cpp
|
||||
stubs/ATHandler_stub.cpp
|
||||
stubs/AT_CellularBase_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
stubs/CellularUtil_stub.cpp
|
||||
stubs/us_ticker_stub.cpp
|
||||
stubs/NetworkStack_stub.cpp
|
||||
stubs/SocketAddress_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
)
|
|
@ -14,8 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "test_athandler.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <string.h>
|
||||
#include "AT_CellularNetwork.h"
|
||||
#include "EventQueue.h"
|
||||
|
@ -34,16 +33,26 @@ void urc_callback()
|
|||
{
|
||||
}
|
||||
|
||||
Test_ATHandler::Test_ATHandler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Test_ATHandler::~Test_ATHandler()
|
||||
void urc2_callback()
|
||||
{
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_constructor()
|
||||
// AStyle ignored as the definition is not clear due to preprocessor usage
|
||||
// *INDENT-OFF*
|
||||
class TestATHandler : public testing::Test {
|
||||
protected:
|
||||
|
||||
void SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void TearDown()
|
||||
{
|
||||
}
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
TEST_F(TestATHandler, Create)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -54,19 +63,20 @@ void Test_ATHandler::test_ATHandler_constructor()
|
|||
|
||||
at = new ATHandler(&fh1, que, 0, NULL);
|
||||
|
||||
EXPECT_TRUE(at != NULL);
|
||||
delete at;
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_get_file_handle()
|
||||
TEST_F(TestATHandler, test_ATHandler_get_file_handle)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
CHECK_EQUAL(&fh1, at.get_file_handle());
|
||||
EXPECT_EQ(&fh1, at.get_file_handle());
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_set_file_handle()
|
||||
TEST_F(TestATHandler, test_ATHandler_set_file_handle)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1, fh2;
|
||||
|
@ -76,7 +86,7 @@ void Test_ATHandler::test_ATHandler_set_file_handle()
|
|||
at.set_file_handle(&fh2);
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_lock()
|
||||
TEST_F(TestATHandler, test_ATHandler_lock)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -86,7 +96,7 @@ void Test_ATHandler::test_ATHandler_lock()
|
|||
at.lock();
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_unlock()
|
||||
TEST_F(TestATHandler, test_ATHandler_unlock)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -97,44 +107,64 @@ void Test_ATHandler::test_ATHandler_unlock()
|
|||
at.unlock();
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_unlock_return_error()
|
||||
TEST_F(TestATHandler, test_ATHandler_unlock_return_error)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
CHECK(NSAPI_ERROR_OK == at.unlock_return_error());
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == at.unlock_return_error());
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_set_urc_handler()
|
||||
TEST_F(TestATHandler, test_ATHandler_set_urc_handler)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
const char ch[] = "testtesttesttest";
|
||||
at.set_urc_handler(ch, &urc_callback);
|
||||
|
||||
mbed::Callback<void()> cb(&urc_callback);
|
||||
at.set_urc_handler(ch, cb);
|
||||
|
||||
//THIS IS NOT same callback in find_urc_handler???
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == at.set_urc_handler(ch, cb));
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_get_last_error()
|
||||
TEST_F(TestATHandler, test_ATHandler_remove_urc_handler)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
CHECK(NSAPI_ERROR_OK == at.get_last_error());
|
||||
const char ch[] = "testtesttesttest";
|
||||
|
||||
mbed::Callback<void()> cb(&urc_callback);
|
||||
at.set_urc_handler(ch, cb);
|
||||
|
||||
//This does nothing!!!
|
||||
at.remove_urc_handler(ch, cb);
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_get_last_device_error()
|
||||
TEST_F(TestATHandler, test_ATHandler_get_last_error)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
CHECK(0 == at.get_last_device_error().errCode);
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == at.get_last_error());
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_inc_ref_count()
|
||||
TEST_F(TestATHandler, test_ATHandler_get_last_device_error)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
EXPECT_TRUE(0 == at.get_last_device_error().errCode);
|
||||
}
|
||||
|
||||
TEST_F(TestATHandler, test_ATHandler_inc_ref_count)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -143,7 +173,7 @@ void Test_ATHandler::test_ATHandler_inc_ref_count()
|
|||
at.inc_ref_count();
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_dec_ref_count()
|
||||
TEST_F(TestATHandler, test_ATHandler_dec_ref_count)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -152,26 +182,26 @@ void Test_ATHandler::test_ATHandler_dec_ref_count()
|
|||
at.dec_ref_count();
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_get_ref_count()
|
||||
TEST_F(TestATHandler, test_ATHandler_get_ref_count)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
CHECK(1 == at.get_ref_count());
|
||||
EXPECT_TRUE(1 == at.get_ref_count());
|
||||
|
||||
at.inc_ref_count();
|
||||
CHECK(2 == at.get_ref_count());
|
||||
EXPECT_TRUE(2 == at.get_ref_count());
|
||||
|
||||
at.inc_ref_count();
|
||||
CHECK(3 == at.get_ref_count());
|
||||
EXPECT_TRUE(3 == at.get_ref_count());
|
||||
|
||||
at.dec_ref_count();
|
||||
at.dec_ref_count();
|
||||
CHECK(1 == at.get_ref_count());
|
||||
EXPECT_TRUE(1 == at.get_ref_count());
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_set_at_timeout()
|
||||
TEST_F(TestATHandler, test_ATHandler_set_at_timeout)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -182,7 +212,7 @@ void Test_ATHandler::test_ATHandler_set_at_timeout()
|
|||
at.set_at_timeout(80, true);
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_restore_at_timeout()
|
||||
TEST_F(TestATHandler, test_ATHandler_restore_at_timeout)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -193,7 +223,7 @@ void Test_ATHandler::test_ATHandler_restore_at_timeout()
|
|||
at.restore_at_timeout();
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_clear_error()
|
||||
TEST_F(TestATHandler, test_ATHandler_clear_error)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -202,12 +232,18 @@ void Test_ATHandler::test_ATHandler_clear_error()
|
|||
at.clear_error();
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_process_oob()
|
||||
TEST_F(TestATHandler, test_ATHandler_process_oob)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
at.set_at_timeout(10);
|
||||
|
||||
at.set_is_filehandle_usable(false);
|
||||
at.process_oob();
|
||||
at.set_is_filehandle_usable(true);
|
||||
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
fh1.short_value = POLLIN;
|
||||
at.set_urc_handler("s", &urc_callback);
|
||||
|
@ -222,6 +258,8 @@ void Test_ATHandler::test_ATHandler_process_oob()
|
|||
char table[] = "ssssssssssssssssssssssssssssssss\0";
|
||||
filehandle_stub_table = table;
|
||||
filehandle_stub_table_pos = 0;
|
||||
mbed_poll_stub::revents_value = POLLIN;
|
||||
mbed_poll_stub::int_value = 1;
|
||||
at.read_bytes(buf, 5);
|
||||
|
||||
filehandle_stub_short_value_counter = 2;
|
||||
|
@ -235,31 +273,32 @@ void Test_ATHandler::test_ATHandler_process_oob()
|
|||
filehandle_stub_short_value_counter = 1;
|
||||
at.process_oob();
|
||||
|
||||
char table2[4];
|
||||
char table2[5];
|
||||
table2[0] = '\r';
|
||||
table2[1] = '\r';
|
||||
table2[2] = '\n';
|
||||
table2[3] = 0;
|
||||
table2[3] = '\n';
|
||||
table2[4] = 0;
|
||||
filehandle_stub_table = table2;
|
||||
|
||||
at.clear_error();
|
||||
timer_stub_value = 0;
|
||||
filehandle_stub_table_pos = 0;
|
||||
mbed_poll_stub::revents_value = POLLIN;
|
||||
mbed_poll_stub::int_value = 1;
|
||||
at.read_bytes(buf, 1);
|
||||
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
at.process_oob();
|
||||
|
||||
|
||||
filehandle_stub_table = table;
|
||||
|
||||
|
||||
filehandle_stub_short_value_counter = 0;
|
||||
filehandle_stub_table_pos = 0;
|
||||
filehandle_stub_table = NULL;
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_set_filehandle_sigio()
|
||||
TEST_F(TestATHandler, test_ATHandler_set_filehandle_sigio)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -268,7 +307,7 @@ void Test_ATHandler::test_ATHandler_set_filehandle_sigio()
|
|||
at.set_filehandle_sigio();
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_flush()
|
||||
TEST_F(TestATHandler, test_ATHandler_flush)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -279,7 +318,7 @@ void Test_ATHandler::test_ATHandler_flush()
|
|||
at.flush();
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_cmd_start()
|
||||
TEST_F(TestATHandler, test_ATHandler_cmd_start)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -297,7 +336,7 @@ void Test_ATHandler::test_ATHandler_cmd_start()
|
|||
at.cmd_start("s");
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_write_int()
|
||||
TEST_F(TestATHandler, test_ATHandler_write_int)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -320,14 +359,15 @@ void Test_ATHandler::test_ATHandler_write_int()
|
|||
// at.write_int(4);
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_write_string()
|
||||
TEST_F(TestATHandler, test_ATHandler_write_string)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
fh1.size_value = -1;
|
||||
at.write_string("help");
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
|
||||
at.clear_error();
|
||||
mbed_poll_stub::revents_value = POLLOUT;
|
||||
|
@ -335,24 +375,24 @@ void Test_ATHandler::test_ATHandler_write_string()
|
|||
fh1.size_value = -1;
|
||||
at.cmd_start("s");
|
||||
at.write_string("help", true);
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
|
||||
at.clear_error();
|
||||
mbed_poll_stub::revents_value = POLLOUT;
|
||||
mbed_poll_stub::int_value = 1;
|
||||
fh1.size_value = -1;
|
||||
at.write_string("help", true);
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
|
||||
at.clear_error();
|
||||
mbed_poll_stub::revents_value = POLLOUT;
|
||||
mbed_poll_stub::int_value = 1;
|
||||
fh1.size_value = 7;
|
||||
at.write_string("help", true);
|
||||
CHECK(NSAPI_ERROR_OK == at.get_last_error());
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == at.get_last_error());
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_cmd_stop()
|
||||
TEST_F(TestATHandler, test_ATHandler_cmd_stop)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -364,10 +404,10 @@ void Test_ATHandler::test_ATHandler_cmd_stop()
|
|||
at.write_string("help", true);
|
||||
|
||||
at.cmd_stop();
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_write_bytes()
|
||||
TEST_F(TestATHandler, test_ATHandler_write_bytes)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -378,10 +418,10 @@ void Test_ATHandler::test_ATHandler_write_bytes()
|
|||
at.write_bytes(data, 4);
|
||||
|
||||
at.write_bytes(data, 4);
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_set_stop_tag()
|
||||
TEST_F(TestATHandler, test_ATHandler_set_stop_tag)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -390,7 +430,7 @@ void Test_ATHandler::test_ATHandler_set_stop_tag()
|
|||
at.set_stop_tag("s");
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_set_delimiter()
|
||||
TEST_F(TestATHandler, test_ATHandler_set_delimiter)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -399,73 +439,83 @@ void Test_ATHandler::test_ATHandler_set_delimiter()
|
|||
at.set_delimiter('+');
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_skip_param()
|
||||
TEST_F(TestATHandler, test_ATHandler_skip_param)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
at.set_stop_tag("OK\r\n");
|
||||
at.skip_param();
|
||||
|
||||
char table[] = "ssssssssssssssssssssssssssssOK\r\n\0";
|
||||
filehandle_stub_table = table;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
mbed_poll_stub::revents_value = POLLIN;
|
||||
mbed_poll_stub::int_value = 1;
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
fh1.short_value = POLLIN;
|
||||
at.resp_start();
|
||||
at.skip_param();
|
||||
CHECK(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
|
||||
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
|
||||
|
||||
char table1[] = "ss,sssssssssssss,sssssssssssOK\r\n\0";
|
||||
filehandle_stub_table = table1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
at.skip_param();
|
||||
|
||||
char table2[] = "sssOK\r\n\0";
|
||||
filehandle_stub_table = table2;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
at.skip_param();
|
||||
|
||||
char table3[] = "sssssssOK\nssss\0";
|
||||
filehandle_stub_table = table3;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
//Need to create a new instance because stop tag already found
|
||||
ATHandler at2(&fh1, que, 0, ",");
|
||||
at2.flush();
|
||||
at2.clear_error();
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
at2.resp_start();
|
||||
at2.skip_param();
|
||||
|
||||
at2.skip_param(4, 3);
|
||||
|
||||
filehandle_stub_table = table3;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at2.flush();
|
||||
at2.clear_error();
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
at2.resp_start();
|
||||
at2.skip_param(4, 3);
|
||||
|
||||
filehandle_stub_table = table3;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at2.flush();
|
||||
at2.clear_error();
|
||||
filehandle_stub_short_value_counter = 1;
|
||||
filehandle_stub_table_pos = 0;
|
||||
at2.resp_start();
|
||||
at2.skip_param(24, 17);
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_read_bytes()
|
||||
TEST_F(TestATHandler, test_ATHandler_read_bytes)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -477,10 +527,10 @@ void Test_ATHandler::test_ATHandler_read_bytes()
|
|||
|
||||
// TEST EMPTY BUFFER
|
||||
// Shouldn't read any byte since buffer is empty
|
||||
CHECK(-1 == at.read_bytes(buf, 1));
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(-1 == at.read_bytes(buf, 1));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
// Return error due to error set to at handler by the above call on empty buffer
|
||||
CHECK(-1 == at.read_bytes(buf, 1));
|
||||
EXPECT_TRUE(-1 == at.read_bytes(buf, 1));
|
||||
|
||||
// TEST DATA IN BUFFER
|
||||
at.clear_error();
|
||||
|
@ -491,18 +541,18 @@ void Test_ATHandler::test_ATHandler_read_bytes()
|
|||
mbed_poll_stub::int_value = 1;;
|
||||
|
||||
// Read 5 bytes
|
||||
CHECK(5 == at.read_bytes(buf, 5));
|
||||
CHECK(!memcmp(buf, table1, 5));
|
||||
EXPECT_TRUE(5 == at.read_bytes(buf, 5));
|
||||
EXPECT_TRUE(!memcmp(buf, table1, 5));
|
||||
// get_char triggered above should have filled in the whole reading buffer(fill_buffer())
|
||||
CHECK(filehandle_stub_table_pos == (strlen(table1) - 1));
|
||||
EXPECT_TRUE(filehandle_stub_table_pos == (strlen(table1) - 1));
|
||||
// Read another 8 bytes
|
||||
CHECK(8 == at.read_bytes(buf, 8) && !memcmp(buf, table1 + 5, 8));
|
||||
EXPECT_TRUE(8 == at.read_bytes(buf, 8) && !memcmp(buf, table1 + 5, 8));
|
||||
// Reading more than the 4 bytes left -> ERROR
|
||||
CHECK(-1 == at.read_bytes(buf, 5));
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(-1 == at.read_bytes(buf, 5));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_read_string()
|
||||
TEST_F(TestATHandler, test_ATHandler_read_string)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -521,15 +571,15 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
mbed_poll_stub::int_value = 1;
|
||||
char buf1[1];
|
||||
// No _stop_tag set without resp_start
|
||||
CHECK(-1 == at.read_string(buf1, 1));
|
||||
EXPECT_TRUE(-1 == at.read_string(buf1, 1));
|
||||
at.clear_error();
|
||||
// Set _stop_tag to resp_stop(OKCRLF)
|
||||
at.resp_start();
|
||||
// Device error because buffer is empty
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
at.clear_error();
|
||||
// Device error because empty buffer and attempt to fill_buffer by consume_char('\"')
|
||||
CHECK(-1 == at.read_string(buf1, 1));
|
||||
EXPECT_TRUE(-1 == at.read_string(buf1, 1));
|
||||
|
||||
// *** 1 BYTE ***
|
||||
at.clear_error();
|
||||
|
@ -543,9 +593,9 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
// Set _stop_tag to resp_stop(OKCRLF)
|
||||
at.resp_start();
|
||||
// Device error because no CRLF and no more data to read
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
at.clear_error();
|
||||
CHECK(0 == at.read_string(buf2, 1));
|
||||
EXPECT_TRUE(0 == at.read_string(buf2, 1));
|
||||
|
||||
// *** CRLF ***
|
||||
at.clear_error();
|
||||
|
@ -559,15 +609,16 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
// Set _stop_tag to resp_stop(OKCRLF)
|
||||
at.resp_start();
|
||||
// OK because after CRLF matched there is more data to read ending in CRLF
|
||||
CHECK(NSAPI_ERROR_OK == at.get_last_error());
|
||||
EXPECT_TRUE(NSAPI_ERROR_OK == at.get_last_error());
|
||||
// To read 0 bytes from: s\r\n
|
||||
CHECK(0 == at.read_string(buf3, 0 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(0 == at.read_string(buf3, 0 + 1/*for NULL*/));
|
||||
// To read 1 byte from: s\r\n -> read s
|
||||
CHECK(1 == at.read_string(buf3, 1 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(1 == at.read_string(buf3, 1 + 1/*for NULL*/));
|
||||
|
||||
// *** Reading more than available in buffer ***
|
||||
at.clear_error();
|
||||
char table4[] = "\"s,\"OK\r\n\0";
|
||||
mbed_poll_stub::int_value = 0;
|
||||
at.flush();
|
||||
filehandle_stub_table = table4;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
@ -580,8 +631,8 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
// TO read 5 bytes from: "s,"OK\r\n -> read "s,"O
|
||||
at.read_bytes(buf5, 5);
|
||||
// K\r\n left to be read -> reading more than 3 + 1(for NULL) -> ERROR
|
||||
CHECK(-1 == at.read_string(buf4, 4 + 1/*for NULL*/));
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(-1 == at.read_string(buf4, 4 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
|
||||
// *** Encountering delimiter after reading 1 byte ***
|
||||
at.clear_error();
|
||||
|
@ -593,7 +644,7 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
// TO read 1 byte from: "s,"OK\r\n -> read "
|
||||
at.read_bytes(buf5, 1);
|
||||
// TO read max 4 from: s,"OK\r\n -> read s and stop on ,
|
||||
CHECK(1 == at.read_string(buf4, 4 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(1 == at.read_string(buf4, 4 + 1/*for NULL*/));
|
||||
|
||||
// *** Encountering delimiter as first char in buffer ***
|
||||
at.clear_error();
|
||||
|
@ -605,7 +656,7 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
// TO read 2 bytes from: "s,"OK\r\n -> read "s
|
||||
at.read_bytes(buf5, 2);
|
||||
// TO read max 4 bytes from: ,"OK\r\n -> stop on ,
|
||||
CHECK(0 == at.read_string(buf4, 4 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(0 == at.read_string(buf4, 4 + 1/*for NULL*/));
|
||||
|
||||
// *** Read as much as buffer size is without encountering any delimiter " or OKCRLF ***
|
||||
at.clear_error();
|
||||
|
@ -620,19 +671,19 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
// TO read 1 byte from: "s"OK\r\n -> read "
|
||||
at.read_bytes(buf5, 1);
|
||||
// TO read max 1 byte from: s"OK\r\n -> read s
|
||||
CHECK(1 == at.read_string(buf4, 1 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(1 == at.read_string(buf4, 1 + 1/*for NULL*/));
|
||||
|
||||
// *** Consume " and run into OKCRLF ***
|
||||
// TO read max 1 byte from: "OK\r\n -> consume " and find stop tag OKCRLF
|
||||
CHECK(0 == at.read_string(buf4, 1 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(0 == at.read_string(buf4, 1 + 1/*for NULL*/));
|
||||
|
||||
// *** Try to read after stop tag was found ***
|
||||
// stop tag found do not read further
|
||||
CHECK(-1 == at.read_string(buf4, 1 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(-1 == at.read_string(buf4, 1 + 1/*for NULL*/));
|
||||
|
||||
// *** Try to read after stop tag was found when parameter allows it ***
|
||||
// stop tag found but flag indicates to read despite stop_tag found
|
||||
CHECK(4 == at.read_string(buf4, 4 + 1/*for NULL*/, true));
|
||||
EXPECT_TRUE(4 == at.read_string(buf4, 4 + 1/*for NULL*/, true));
|
||||
|
||||
// *** Read as much as buffer size is without encountering any delimiter " or OKCRLF ***
|
||||
at.clear_error();
|
||||
|
@ -644,7 +695,7 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
mbed_poll_stub::int_value = 1;
|
||||
at.resp_start("s");
|
||||
// TO read from: ss\rsss -> read all 6 chars ss\rsss
|
||||
CHECK(6 == at.read_string(buf4, 6 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(6 == at.read_string(buf4, 6 + 1/*for NULL*/));
|
||||
|
||||
// *** Reading when buffer only has " ***
|
||||
at.clear_error();
|
||||
|
@ -656,8 +707,8 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
mbed_poll_stub::int_value = 1;
|
||||
at.resp_start("s");
|
||||
// TO read from buffer having only " -> consume " -> trying to read when nothing in buffer
|
||||
CHECK(-1 == at.read_string(buf4, 5));
|
||||
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
EXPECT_TRUE(-1 == at.read_string(buf4, 5));
|
||||
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
|
||||
|
||||
// *** Reading through partially matching stop tag ***
|
||||
at.clear_error();
|
||||
|
@ -671,7 +722,7 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
// NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read
|
||||
at.resp_start();
|
||||
// TO read from
|
||||
CHECK(8 == at.read_string(buf8, 8 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(8 == at.read_string(buf8, 8 + 1/*for NULL*/));
|
||||
|
||||
// *** Reading through partially matching stop tag ***
|
||||
at.clear_error();
|
||||
|
@ -686,11 +737,12 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
// NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read
|
||||
at.resp_start();
|
||||
// TO read from
|
||||
CHECK(6 == at.read_string(buf9, 6 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(6 == at.read_string(buf9, 6 + 1/*for NULL*/));
|
||||
|
||||
// *** CRLF part of the string ***
|
||||
at.clear_error();
|
||||
char table10[] = "\"s\"\r\nOK\r\n\0";
|
||||
mbed_poll_stub::int_value = 0;
|
||||
at.flush();
|
||||
filehandle_stub_table = table10;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
@ -701,10 +753,10 @@ void Test_ATHandler::test_ATHandler_read_string()
|
|||
// NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read
|
||||
at.resp_start();
|
||||
// TO read from
|
||||
CHECK(3 == at.read_string(buf10, 9 + 1/*for NULL*/));
|
||||
EXPECT_TRUE(3 == at.read_string(buf10, 9 + 1/*for NULL*/));
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_read_hex_string()
|
||||
TEST_F(TestATHandler, test_ATHandler_read_hex_string)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -724,8 +776,8 @@ void Test_ATHandler::test_ATHandler_read_hex_string()
|
|||
char buf1[10];
|
||||
// Set _stop_tag to resp_stop(OKCRLF)
|
||||
at.resp_start();
|
||||
CHECK(5 == at.read_hex_string(buf1, 5));
|
||||
CHECK(!strncmp(buf1, "hello", 5));
|
||||
EXPECT_TRUE(5 == at.read_hex_string(buf1, 5));
|
||||
EXPECT_TRUE(!strncmp(buf1, "hello", 5));
|
||||
|
||||
// *** Read up to delimiter, odd length ***
|
||||
at.clear_error();
|
||||
|
@ -738,8 +790,8 @@ void Test_ATHandler::test_ATHandler_read_hex_string()
|
|||
char buf2[10];
|
||||
// Set _stop_tag to resp_stop(OKCRLF)
|
||||
at.resp_start();
|
||||
CHECK(5 == at.read_hex_string(buf2, 6));
|
||||
CHECK(!strncmp(buf2, "hello", 5));
|
||||
EXPECT_TRUE(5 == at.read_hex_string(buf2, 6));
|
||||
EXPECT_TRUE(!strncmp(buf2, "hello", 5));
|
||||
|
||||
// *** Read with stop tag, even length ***
|
||||
at.clear_error();
|
||||
|
@ -752,8 +804,8 @@ void Test_ATHandler::test_ATHandler_read_hex_string()
|
|||
char buf3[6];
|
||||
// Set _stop_tag to resp_stop(OKCRLF)
|
||||
at.resp_start();
|
||||
CHECK(2 == at.read_hex_string(buf3, 2 + 1/*get to stop tag match*/));
|
||||
CHECK(!strncmp(buf3, "he", 2));
|
||||
EXPECT_TRUE(2 == at.read_hex_string(buf3, 2 + 1/*get to stop tag match*/));
|
||||
EXPECT_TRUE(!strncmp(buf3, "he", 2));
|
||||
at.resp_stop();
|
||||
|
||||
// *** Read with stop tag, odd length ***
|
||||
|
@ -767,11 +819,11 @@ void Test_ATHandler::test_ATHandler_read_hex_string()
|
|||
char buf4[6];
|
||||
// Set _stop_tag to resp_stop(OKCRLF)
|
||||
at.resp_start();
|
||||
CHECK(1 == at.read_hex_string(buf4, 2 + 1/*get to stop tag match*/));
|
||||
CHECK(!strncmp(buf4, "h", 1));
|
||||
EXPECT_TRUE(1 == at.read_hex_string(buf4, 2 + 1/*get to stop tag match*/));
|
||||
EXPECT_TRUE(!strncmp(buf4, "h", 1));
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_read_int()
|
||||
TEST_F(TestATHandler, test_ATHandler_read_int)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -781,7 +833,7 @@ void Test_ATHandler::test_ATHandler_read_int()
|
|||
ATHandler at(&fh1, que, 0, ",");
|
||||
|
||||
int32_t ret = at.read_int();
|
||||
CHECK(-1 == ret);
|
||||
EXPECT_TRUE(-1 == ret);
|
||||
at.clear_error();
|
||||
|
||||
char table[] = "\",\"OK\r\n\0";
|
||||
|
@ -793,7 +845,7 @@ void Test_ATHandler::test_ATHandler_read_int()
|
|||
at.resp_start();
|
||||
|
||||
ret = at.read_int();
|
||||
CHECK(-1 == ret);
|
||||
EXPECT_TRUE(-1 == ret);
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
|
||||
|
@ -806,11 +858,10 @@ void Test_ATHandler::test_ATHandler_read_int()
|
|||
at.resp_start();
|
||||
|
||||
ret = at.read_int();
|
||||
CHECK(2 == ret);
|
||||
|
||||
EXPECT_TRUE(2 == ret);
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_resp_start()
|
||||
TEST_F(TestATHandler, test_ATHandler_resp_start)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -828,6 +879,7 @@ void Test_ATHandler::test_ATHandler_resp_start()
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start("ssssaaaassssaaaassss"); //too long prefix
|
||||
|
||||
char table3[] = "+CME ERROR: 108\0";
|
||||
|
@ -836,20 +888,22 @@ void Test_ATHandler::test_ATHandler_resp_start()
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
char table4[] = "+CMS ERROR: 6\0";
|
||||
filehandle_stub_table = table4;
|
||||
filehandle_stub_table_pos = 0;
|
||||
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
char table5[] = "ERROR\r\n\0";
|
||||
|
@ -858,6 +912,7 @@ void Test_ATHandler::test_ATHandler_resp_start()
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
char table6[] = "OK\r\n\0";
|
||||
|
@ -866,6 +921,7 @@ void Test_ATHandler::test_ATHandler_resp_start()
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
char table7[] = "ssssss\0";
|
||||
|
@ -875,10 +931,11 @@ void Test_ATHandler::test_ATHandler_resp_start()
|
|||
at.flush();
|
||||
at.clear_error();
|
||||
at.set_urc_handler("ss", NULL);
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_resp_stop()
|
||||
TEST_F(TestATHandler, test_ATHandler_resp_stop)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -899,6 +956,7 @@ void Test_ATHandler::test_ATHandler_resp_stop()
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start();
|
||||
|
||||
at.resp_stop();
|
||||
|
@ -909,11 +967,12 @@ void Test_ATHandler::test_ATHandler_resp_stop()
|
|||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
filehandle_stub_table_pos = 0;
|
||||
at.resp_start("ss", false);
|
||||
at.resp_stop();
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_info_resp()
|
||||
TEST_F(TestATHandler, test_ATHandler_info_resp)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -921,10 +980,10 @@ void Test_ATHandler::test_ATHandler_info_resp()
|
|||
filehandle_stub_table = NULL;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
CHECK(at.info_resp());
|
||||
EXPECT_TRUE(at.info_resp());
|
||||
|
||||
at.resp_start();
|
||||
CHECK(!at.info_resp());
|
||||
EXPECT_TRUE(!at.info_resp());
|
||||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
|
@ -936,9 +995,9 @@ void Test_ATHandler::test_ATHandler_info_resp()
|
|||
mbed_poll_stub::int_value = strlen(table2);
|
||||
|
||||
at.resp_start("21");
|
||||
CHECK(at.info_resp());
|
||||
EXPECT_TRUE(at.info_resp());
|
||||
|
||||
CHECK(!at.info_resp());
|
||||
EXPECT_TRUE(!at.info_resp());
|
||||
|
||||
at.flush();
|
||||
at.clear_error();
|
||||
|
@ -949,10 +1008,10 @@ void Test_ATHandler::test_ATHandler_info_resp()
|
|||
mbed_poll_stub::revents_value = POLLIN;
|
||||
mbed_poll_stub::int_value = strlen(table3);
|
||||
|
||||
CHECK(at.info_resp());
|
||||
EXPECT_TRUE(at.info_resp());
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_info_elem()
|
||||
TEST_F(TestATHandler, test_ATHandler_info_elem)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -964,7 +1023,7 @@ void Test_ATHandler::test_ATHandler_info_elem()
|
|||
mbed_poll_stub::int_value = strlen(table);
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
CHECK(!at.info_elem('O'));
|
||||
EXPECT_TRUE(!at.info_elem('O'));
|
||||
at.flush();
|
||||
|
||||
char table2[] = "21 OK\r\n\0";
|
||||
|
@ -975,7 +1034,7 @@ void Test_ATHandler::test_ATHandler_info_elem()
|
|||
|
||||
at.clear_error();
|
||||
at.resp_start("21");
|
||||
CHECK(at.info_elem('O'));
|
||||
EXPECT_TRUE(at.info_elem('O'));
|
||||
at.flush();
|
||||
|
||||
filehandle_stub_table = NULL;
|
||||
|
@ -983,19 +1042,19 @@ void Test_ATHandler::test_ATHandler_info_elem()
|
|||
|
||||
at.clear_error();
|
||||
at.resp_start("21");
|
||||
CHECK(!at.info_elem('2'));
|
||||
EXPECT_TRUE(!at.info_elem('2'));
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_consume_to_stop_tag()
|
||||
TEST_F(TestATHandler, test_ATHandler_consume_to_stop_tag)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
CHECK(at.consume_to_stop_tag());
|
||||
EXPECT_TRUE(at.consume_to_stop_tag());
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_set_debug()
|
||||
TEST_F(TestATHandler, test_ATHandler_set_debug)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
@ -1006,11 +1065,12 @@ void Test_ATHandler::test_ATHandler_set_debug()
|
|||
at.set_debug(false);
|
||||
}
|
||||
|
||||
void Test_ATHandler::test_ATHandler_get_3gpp_error()
|
||||
TEST_F(TestATHandler, test_ATHandler_get_3gpp_error)
|
||||
{
|
||||
EventQueue que;
|
||||
FileHandle_stub fh1;
|
||||
|
||||
ATHandler at(&fh1, que, 0, ",");
|
||||
int ret = at.get_3gpp_error();
|
||||
at.get_3gpp_error();
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
####################
|
||||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
features/cellular/framework/common/util
|
||||
../features/cellular/framework/common
|
||||
../features/cellular/framework/AT
|
||||
../features/frameworks/mbed-client-randlib/mbed-client-randlib
|
||||
)
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/cellular/framework/AT/ATHandler.cpp
|
||||
../features/cellular/framework/common/CellularUtil.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
features/cellular/framework/AT/athandler/athandlertest.cpp
|
||||
stubs/AT_CellularBase_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
stubs/us_ticker_stub.cpp
|
||||
stubs/mbed_wait_api_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
stubs/mbed_poll_stub.cpp
|
||||
stubs/Timer_stub.cpp
|
||||
stubs/equeue_stub.c
|
||||
stubs/Kernel_stub.cpp
|
||||
stubs/Thread_stub.cpp
|
||||
stubs/randLIB_stub.cpp
|
||||
)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048")
|
|
@ -1,179 +0,0 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "test_util.h"
|
||||
#include <string.h>
|
||||
#include "CellularUtil.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace mbed_cellular_util;
|
||||
|
||||
Test_util::Test_util()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Test_util::~Test_util()
|
||||
{
|
||||
}
|
||||
|
||||
void Test_util::test_util_uint_to_binary_string()
|
||||
{
|
||||
char str[33];
|
||||
uint_to_binary_str(15, str, 33, 32);
|
||||
str[32] = '\0';
|
||||
// 15 is "1111" in binary but we ask all 32 bits so it should return "00000000000000000000000000001111"
|
||||
EXPECT_STREQ("00000000000000000000000000001111", str);
|
||||
|
||||
// test NULL pointer
|
||||
uint_to_binary_str(15, NULL, 0, 32);
|
||||
|
||||
// test give too small buffer
|
||||
char too_small[5];
|
||||
uint_to_binary_str(15, too_small, 5, 6);
|
||||
}
|
||||
|
||||
void Test_util::test_util_char_str_to_hex()
|
||||
{
|
||||
// basic conversion test, happy days
|
||||
char hex_buf[50];
|
||||
uint16_t number_of_hex_chars = char_str_to_hex_str("1234", 4, hex_buf);
|
||||
hex_buf[number_of_hex_chars] = '\0';
|
||||
EXPECT_STREQ("31323334", hex_buf);
|
||||
EXPECT_EQ(8, number_of_hex_chars);
|
||||
|
||||
number_of_hex_chars = char_str_to_hex_str("wuhuu", 5, hex_buf);
|
||||
hex_buf[number_of_hex_chars] = '\0';
|
||||
EXPECT_STREQ("7775687575", hex_buf);
|
||||
EXPECT_EQ(10, number_of_hex_chars);
|
||||
|
||||
// First don't omit the leading zero and then omit and check that leading zero is missing
|
||||
number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf);
|
||||
hex_buf[number_of_hex_chars] = '\0';
|
||||
EXPECT_STREQ("0A7775687575", hex_buf);
|
||||
EXPECT_EQ(12, number_of_hex_chars);
|
||||
|
||||
number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf, true);
|
||||
hex_buf[number_of_hex_chars] = '\0';
|
||||
EXPECT_STREQ("A7775687575", hex_buf);
|
||||
EXPECT_EQ(11, number_of_hex_chars);
|
||||
|
||||
// test giving a null pointer
|
||||
number_of_hex_chars = char_str_to_hex_str(NULL, 4, hex_buf);
|
||||
EXPECT_EQ(0, number_of_hex_chars);
|
||||
number_of_hex_chars = char_str_to_hex_str("1234", 4, NULL);
|
||||
EXPECT_EQ(0, number_of_hex_chars);
|
||||
}
|
||||
|
||||
void Test_util::test_util_convert_ipv6()
|
||||
{
|
||||
// leading zeros omitted
|
||||
char ipv6[64];
|
||||
strncpy(ipv6, "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1", 64);
|
||||
convert_ipv6(ipv6);
|
||||
EXPECT_STREQ("101:101:101:101:101:101:101:101", ipv6);
|
||||
EXPECT_EQ(31, strlen(ipv6));
|
||||
|
||||
// some omitted and some not so much
|
||||
strncpy(ipv6, "255.1.120.2.244.12.55.45.201.110.11.2.233.154.85.96", 64);
|
||||
convert_ipv6(ipv6);
|
||||
EXPECT_STREQ("FF01:7802:F40C:372D:C96E:B02:E99A:5560", ipv6);
|
||||
EXPECT_EQ(38, strlen(ipv6));
|
||||
|
||||
// test giving a null pointer
|
||||
convert_ipv6(NULL);
|
||||
}
|
||||
|
||||
void Test_util::test_util_prefer_ipv6()
|
||||
{
|
||||
char tt[20] = "62.241.198.246";
|
||||
char temp[64] = "2001:14B8:1000:000:000:000:000:002";
|
||||
|
||||
// not enough space to swap, arrays should stay the same
|
||||
prefer_ipv6(tt, sizeof(tt), temp, sizeof(temp));
|
||||
EXPECT_STREQ("62.241.198.246", tt);
|
||||
EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", temp);
|
||||
|
||||
// should swap as first one was ip4 and later was ipv6 and enough space
|
||||
char tt2[64] = "62.241.198.246";
|
||||
prefer_ipv6(tt2, sizeof(tt2), temp, sizeof(temp));
|
||||
EXPECT_STREQ("62.241.198.246", temp);
|
||||
EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", tt2);
|
||||
}
|
||||
|
||||
void Test_util::test_util_separate_ip_addresses()
|
||||
{
|
||||
char *s = (char *)calloc(128, 1);
|
||||
|
||||
char ip[64] = {0};
|
||||
char subnet[64] = {0};
|
||||
|
||||
strncpy(s, "32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15", 94);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip);
|
||||
EXPECT_STREQ("001:203:405:607:809:A0B:C0D:E0F", subnet);
|
||||
|
||||
strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", 94);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip);
|
||||
EXPECT_STREQ("0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "1.2.3.4\0", 8);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("1.2.3.4", ip);
|
||||
EXPECT_STREQ("", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "1.2.3.4.5.6.7.8\0", 16);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("1.2.3.4", ip);
|
||||
EXPECT_STREQ("5.6.7.8", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16\0", 39);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("102:304:506:708:90A:B0C:D0E:F10", ip);
|
||||
EXPECT_STREQ("", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 57);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip);
|
||||
EXPECT_STREQ("", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "1.2.3.4 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 65);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("1.2.3.4", ip);
|
||||
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20\0", 51);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("1.2.3.4", ip);
|
||||
EXPECT_STREQ("506:708:90A:B0C:D0E:F10:1112:1314", subnet);
|
||||
EXPECT_STREQ("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s);
|
||||
|
||||
free(s);
|
||||
}
|
|
@ -3,9 +3,6 @@
|
|||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "cellular-framework-common-util")
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
features/cellular/framework/common/util
|
||||
|
@ -20,7 +17,6 @@ set(unittest-sources
|
|||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
stubs/randLIB_stub.c
|
||||
features/cellular/framework/common/util/test_util.cpp
|
||||
features/cellular/framework/common/util/utiltest.cpp
|
||||
stubs/randLIB_stub.cpp
|
||||
)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Arm Limited and affiliates
|
||||
* Copyright (c) 2018, Arm Limited and affiliates.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,49 +15,187 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "gtest/gtest.h"
|
||||
#include "test_util.h"
|
||||
#include <string.h>
|
||||
#include "CellularUtil.h"
|
||||
|
||||
class TestUtil : public testing::Test {
|
||||
using namespace mbed_cellular_util;
|
||||
|
||||
// AStyle ignored as the definition is not clear due to preprocessor usage
|
||||
// *INDENT-OFF*
|
||||
class Testutil : public testing::Test {
|
||||
protected:
|
||||
Test_util *unit;
|
||||
|
||||
virtual void SetUp()
|
||||
void SetUp()
|
||||
{
|
||||
unit = new Test_util();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
void TearDown()
|
||||
{
|
||||
delete unit;
|
||||
}
|
||||
};
|
||||
// *INDENT-ON*
|
||||
|
||||
TEST_F(TestUtil, Create)
|
||||
TEST_F(Testutil, test_util_uint_to_binary_string)
|
||||
{
|
||||
EXPECT_TRUE(unit);
|
||||
char str[33];
|
||||
uint_to_binary_str(15, str, 33, 32);
|
||||
str[32] = '\0';
|
||||
// 15 is "1111" in binary but we ask all 32 bits so it should return "00000000000000000000000000001111"
|
||||
EXPECT_STREQ("00000000000000000000000000001111", str);
|
||||
|
||||
// test NULL pointer
|
||||
uint_to_binary_str(15, NULL, 0, 32);
|
||||
|
||||
// test give too small buffer
|
||||
char too_small[5];
|
||||
uint_to_binary_str(15, too_small, 5, 6);
|
||||
}
|
||||
|
||||
TEST_F(TestUtil, test_util_uint_to_binary_string)
|
||||
TEST_F(Testutil, char_str_to_hex)
|
||||
{
|
||||
unit->test_util_uint_to_binary_string();
|
||||
// basic conversion test, happy days
|
||||
char hex_buf[50];
|
||||
uint16_t number_of_hex_chars = char_str_to_hex_str("1234", 4, hex_buf);
|
||||
hex_buf[number_of_hex_chars] = '\0';
|
||||
EXPECT_STREQ("31323334", hex_buf);
|
||||
EXPECT_EQ(8, number_of_hex_chars);
|
||||
|
||||
number_of_hex_chars = char_str_to_hex_str("wuhuu", 5, hex_buf);
|
||||
hex_buf[number_of_hex_chars] = '\0';
|
||||
EXPECT_STREQ("7775687575", hex_buf);
|
||||
EXPECT_EQ(10, number_of_hex_chars);
|
||||
|
||||
// First don't omit the leading zero and then omit and check that leading zero is missing
|
||||
number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf);
|
||||
hex_buf[number_of_hex_chars] = '\0';
|
||||
EXPECT_STREQ("0A7775687575", hex_buf);
|
||||
EXPECT_EQ(12, number_of_hex_chars);
|
||||
|
||||
number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf, true);
|
||||
hex_buf[number_of_hex_chars] = '\0';
|
||||
EXPECT_STREQ("A7775687575", hex_buf);
|
||||
EXPECT_EQ(11, number_of_hex_chars);
|
||||
|
||||
// test giving a null pointer
|
||||
number_of_hex_chars = char_str_to_hex_str(NULL, 4, hex_buf);
|
||||
EXPECT_EQ(0, number_of_hex_chars);
|
||||
number_of_hex_chars = char_str_to_hex_str("1234", 4, NULL);
|
||||
EXPECT_EQ(0, number_of_hex_chars);
|
||||
}
|
||||
|
||||
TEST_F(TestUtil, char_str_to_hex)
|
||||
TEST_F(Testutil, convert_ipv6)
|
||||
{
|
||||
unit->test_util_char_str_to_hex();
|
||||
// leading zeros omitted
|
||||
char ipv6[64];
|
||||
strncpy(ipv6, "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1", 64);
|
||||
convert_ipv6(ipv6);
|
||||
EXPECT_STREQ("101:101:101:101:101:101:101:101", ipv6);
|
||||
EXPECT_EQ(31, strlen(ipv6));
|
||||
|
||||
// some omitted and some not so much
|
||||
strncpy(ipv6, "255.1.120.2.244.12.55.45.201.110.11.2.233.154.85.96", 64);
|
||||
convert_ipv6(ipv6);
|
||||
EXPECT_STREQ("FF01:7802:F40C:372D:C96E:B02:E99A:5560", ipv6);
|
||||
EXPECT_EQ(38, strlen(ipv6));
|
||||
|
||||
// test giving a null pointer
|
||||
convert_ipv6(NULL);
|
||||
}
|
||||
|
||||
TEST_F(TestUtil, convert_ipv6)
|
||||
TEST_F(Testutil, prefer_ipv6)
|
||||
{
|
||||
unit->test_util_convert_ipv6();
|
||||
char tt[20] = "62.241.198.246";
|
||||
char temp[64] = "2001:14B8:1000:000:000:000:000:002";
|
||||
|
||||
// not enough space to swap, arrays should stay the same
|
||||
prefer_ipv6(tt, sizeof(tt), temp, sizeof(temp));
|
||||
EXPECT_STREQ("62.241.198.246", tt);
|
||||
EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", temp);
|
||||
|
||||
// should swap as first one was ip4 and later was ipv6 and enough space
|
||||
char tt2[64] = "62.241.198.246";
|
||||
prefer_ipv6(tt2, sizeof(tt2), temp, sizeof(temp));
|
||||
EXPECT_STREQ("62.241.198.246", temp);
|
||||
EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", tt2);
|
||||
}
|
||||
|
||||
TEST_F(TestUtil, prefer_ipv6)
|
||||
TEST_F(Testutil, separate_ip_addresses)
|
||||
{
|
||||
unit->test_util_prefer_ipv6();
|
||||
char *s = (char *)malloc(128);
|
||||
|
||||
char ip[64] = {0};
|
||||
char subnet[64] = {0};
|
||||
|
||||
strncpy(s, "32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15\0", 95);
|
||||
separate_ip_addresses(NULL, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip);
|
||||
EXPECT_STREQ("001:203:405:607:809:A0B:C0D:E0F", subnet);
|
||||
|
||||
strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15\0", 95);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip);
|
||||
EXPECT_STREQ("0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "1.2.3.4\0", 8);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("1.2.3.4", ip);
|
||||
EXPECT_STREQ("", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "1.2.3.4.5.6.7.8\0", 16);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("1.2.3.4", ip);
|
||||
EXPECT_STREQ("5.6.7.8", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16\0", 39);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("102:304:506:708:90A:B0C:D0E:F10", ip);
|
||||
EXPECT_STREQ("", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 57);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip);
|
||||
EXPECT_STREQ("", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "1.2.3.4 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 65);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("1.2.3.4", ip);
|
||||
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", subnet);
|
||||
|
||||
ip[0] = '\0';
|
||||
subnet[0] = '\0';
|
||||
strncpy(s, "1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20\0", 51);
|
||||
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
|
||||
EXPECT_STREQ("1.2.3.4", ip);
|
||||
EXPECT_STREQ("506:708:90A:B0C:D0E:F10:1112:1314", subnet);
|
||||
EXPECT_STREQ("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s);
|
||||
}
|
||||
|
||||
TEST_F(TestUtil, separate_ip_addresses)
|
||||
TEST_F(Testutil, get_dynamic_ip_port)
|
||||
{
|
||||
unit->test_util_separate_ip_addresses();
|
||||
uint16_t port = get_dynamic_ip_port();
|
||||
uint16_t port2 = get_dynamic_ip_port();
|
||||
|
||||
EXPECT_TRUE(port != port2);
|
||||
}
|
||||
|
||||
TEST_F(Testutil, int_to_hex_str)
|
||||
{
|
||||
char buf[2];
|
||||
int_to_hex_str(100, (char*)buf);
|
||||
|
||||
EXPECT_TRUE(buf[0] == '6');
|
||||
EXPECT_TRUE(buf[1] == '4');
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,560 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "LoRaMac.h"
|
||||
#include "LoRaPHY_stub.h"
|
||||
#include "LoRaMacCrypto_stub.h"
|
||||
#include "LoRaMacCommand_stub.h"
|
||||
#include "LoRaWANTimer_stub.h"
|
||||
#include "EventQueue_stub.h"
|
||||
|
||||
using namespace events;
|
||||
|
||||
class my_phy : public LoRaPHY
|
||||
{
|
||||
public:
|
||||
my_phy(){};
|
||||
|
||||
virtual ~my_phy(){};
|
||||
};
|
||||
|
||||
class Test_LoRaMac : public testing::Test {
|
||||
protected:
|
||||
LoRaMac *object;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
object = new LoRaMac();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Test_LoRaMac, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
||||
void my_cb()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, initialize)
|
||||
{
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
|
||||
lorawan_connect_t conn;
|
||||
uint8_t key[16];
|
||||
conn.connection_u.otaa.app_key = key;
|
||||
conn.connection_u.otaa.app_eui = key;
|
||||
conn.connection_u.otaa.dev_eui = key;
|
||||
conn.connection_u.otaa.nb_trials = 2;
|
||||
object->prepare_join(&conn, true);
|
||||
|
||||
LoRaWANTimer_stub::call_cb_immediately = true;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize(NULL, my_cb));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, disconnect)
|
||||
{
|
||||
object->disconnect();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, nwk_joined)
|
||||
{
|
||||
EXPECT_EQ(false, object->nwk_joined());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, add_channel_plan)
|
||||
{
|
||||
lorawan_channelplan_t plan;
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->add_channel_plan(plan));
|
||||
|
||||
object->set_tx_ongoing(true);
|
||||
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->add_channel_plan(plan));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, remove_channel_plan)
|
||||
{
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->remove_channel_plan());
|
||||
|
||||
object->set_tx_ongoing(true);
|
||||
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->remove_channel_plan());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_channel_plan)
|
||||
{
|
||||
lorawan_channelplan_t plan;
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->get_channel_plan(plan));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, remove_single_channel)
|
||||
{
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->remove_single_channel(1));
|
||||
|
||||
object->set_tx_ongoing(true);
|
||||
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->remove_single_channel(1));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, multicast_channel_link)
|
||||
{
|
||||
multicast_params_t p;
|
||||
|
||||
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->multicast_channel_link(NULL));
|
||||
|
||||
object->set_tx_ongoing(true);
|
||||
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->multicast_channel_link(&p));
|
||||
|
||||
object->set_tx_ongoing(false);
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->multicast_channel_link(&p));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, multicast_channel_unlink)
|
||||
{
|
||||
multicast_params_t p;
|
||||
|
||||
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->multicast_channel_unlink(NULL));
|
||||
|
||||
object->set_tx_ongoing(true);
|
||||
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->multicast_channel_unlink(&p));
|
||||
|
||||
object->set_tx_ongoing(false);
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->multicast_channel_unlink(&p));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, send)
|
||||
{
|
||||
loramac_mhdr_t mac_hdr;
|
||||
uint8_t buf[15];
|
||||
mac_hdr.bits.mtype = FRAME_TYPE_DATA_CONFIRMED_UP;
|
||||
object->send(&mac_hdr, 1, buf, 15);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_default_tx_datarate)
|
||||
{
|
||||
object->get_default_tx_datarate();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, enable_adaptive_datarate)
|
||||
{
|
||||
object->enable_adaptive_datarate(true);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, set_channel_data_rate)
|
||||
{
|
||||
object->set_channel_data_rate(8);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, tx_ongoing)
|
||||
{
|
||||
object->tx_ongoing();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, set_tx_ongoing)
|
||||
{
|
||||
object->set_tx_ongoing(true);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, reset_ongoing_tx)
|
||||
{
|
||||
object->reset_ongoing_tx(true);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, prepare_ongoing_tx)
|
||||
{
|
||||
uint8_t buf[16];
|
||||
object->prepare_ongoing_tx(1, buf, 16, 1, 0);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, send_ongoing_tx)
|
||||
{
|
||||
object->send_ongoing_tx();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_device_class)
|
||||
{
|
||||
object->get_device_class();
|
||||
}
|
||||
|
||||
void exp_cb()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, set_device_class)
|
||||
{
|
||||
object->set_device_class(CLASS_B, exp_cb);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, setup_link_check_request)
|
||||
{
|
||||
object->setup_link_check_request();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, prepare_join)
|
||||
{
|
||||
lorawan_connect_t conn;
|
||||
object->prepare_join(&conn, false);
|
||||
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->join(false));
|
||||
|
||||
uint8_t key[16];
|
||||
conn.connection_u.otaa.app_key = NULL;
|
||||
conn.connection_u.otaa.app_eui = NULL;
|
||||
conn.connection_u.otaa.dev_eui = NULL;
|
||||
conn.connection_u.otaa.nb_trials = 0;
|
||||
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, true));
|
||||
|
||||
conn.connection_u.otaa.app_key = key;
|
||||
conn.connection_u.otaa.app_eui = NULL;
|
||||
conn.connection_u.otaa.dev_eui = NULL;
|
||||
conn.connection_u.otaa.nb_trials = 0;
|
||||
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, true));
|
||||
|
||||
conn.connection_u.otaa.app_key = key;
|
||||
conn.connection_u.otaa.app_eui = key;
|
||||
conn.connection_u.otaa.dev_eui = NULL;
|
||||
conn.connection_u.otaa.nb_trials = 0;
|
||||
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, true));
|
||||
|
||||
conn.connection_u.otaa.app_key = key;
|
||||
conn.connection_u.otaa.app_eui = key;
|
||||
conn.connection_u.otaa.dev_eui = key;
|
||||
conn.connection_u.otaa.nb_trials = 0;
|
||||
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, true));
|
||||
|
||||
LoRaPHY_stub::bool_table[0] = false;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
conn.connection_u.otaa.app_key = key;
|
||||
conn.connection_u.otaa.app_eui = key;
|
||||
conn.connection_u.otaa.dev_eui = key;
|
||||
conn.connection_u.otaa.nb_trials = 2;
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->prepare_join(&conn, true));
|
||||
|
||||
conn.connection_u.abp.dev_addr = 0;
|
||||
conn.connection_u.abp.nwk_id = 0;
|
||||
conn.connection_u.abp.nwk_skey = NULL;
|
||||
conn.connection_u.abp.app_skey = NULL;
|
||||
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, false));
|
||||
|
||||
conn.connection_u.abp.dev_addr = 1;
|
||||
conn.connection_u.abp.nwk_id = 0;
|
||||
conn.connection_u.abp.nwk_skey = NULL;
|
||||
conn.connection_u.abp.app_skey = NULL;
|
||||
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, false));
|
||||
|
||||
conn.connection_u.abp.dev_addr = 1;
|
||||
conn.connection_u.abp.nwk_id = 2;
|
||||
conn.connection_u.abp.nwk_skey = NULL;
|
||||
conn.connection_u.abp.app_skey = NULL;
|
||||
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, false));
|
||||
|
||||
conn.connection_u.abp.dev_addr = 1;
|
||||
conn.connection_u.abp.nwk_id = 2;
|
||||
conn.connection_u.abp.nwk_skey = key;
|
||||
conn.connection_u.abp.app_skey = NULL;
|
||||
EXPECT_EQ(LORAWAN_STATUS_PARAMETER_INVALID, object->prepare_join(&conn, false));
|
||||
|
||||
conn.connection_u.abp.dev_addr = 1;
|
||||
conn.connection_u.abp.nwk_id = 2;
|
||||
conn.connection_u.abp.nwk_skey = key;
|
||||
conn.connection_u.abp.app_skey = key;
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->prepare_join(&conn, false));
|
||||
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->prepare_join(NULL, false));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, join)
|
||||
{
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->join(false));
|
||||
|
||||
lorawan_connect_t conn;
|
||||
uint8_t key[16];
|
||||
conn.connection_u.otaa.app_key = key;
|
||||
conn.connection_u.otaa.app_eui = key;
|
||||
conn.connection_u.otaa.dev_eui = key;
|
||||
conn.connection_u.otaa.nb_trials = 2;
|
||||
object->prepare_join(&conn, true);
|
||||
EXPECT_EQ(LORAWAN_STATUS_CONNECT_IN_PROGRESS, object->join(true));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, on_radio_tx_done)
|
||||
{
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
object->on_radio_tx_done(100);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, on_radio_rx_done)
|
||||
{
|
||||
uint8_t buf[16];
|
||||
object->on_radio_rx_done(buf, 16, 0, 0);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, on_radio_tx_timeout)
|
||||
{
|
||||
object->on_radio_tx_timeout();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, on_radio_rx_timeout)
|
||||
{
|
||||
object->on_radio_rx_timeout(true);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, continue_joining_process)
|
||||
{
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
lorawan_connect_t conn;
|
||||
uint8_t key[16];
|
||||
conn.connection_u.otaa.app_key = key;
|
||||
conn.connection_u.otaa.app_eui = key;
|
||||
conn.connection_u.otaa.dev_eui = key;
|
||||
conn.connection_u.otaa.nb_trials = 2;
|
||||
object->prepare_join(&conn, true);
|
||||
object->continue_joining_process();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, continue_sending_process)
|
||||
{
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
object->continue_sending_process();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_mcps_confirmation)
|
||||
{
|
||||
object->get_mcps_confirmation();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_mcps_indication)
|
||||
{
|
||||
object->get_mcps_indication();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_mlme_confirmation)
|
||||
{
|
||||
object->get_mlme_confirmation();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_mlme_indication)
|
||||
{
|
||||
object->get_mlme_indication();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, post_process_mcps_req)
|
||||
{
|
||||
uint8_t data[16];
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
object->join(false);
|
||||
|
||||
object->prepare_ongoing_tx(1, data, 15, 0x01, 2);
|
||||
object->send_ongoing_tx();
|
||||
object->post_process_mcps_req();
|
||||
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
object->prepare_ongoing_tx(1, data, 15, 0x02, 2);
|
||||
object->send_ongoing_tx();
|
||||
object->post_process_mcps_req();
|
||||
|
||||
//_mcps_confirmation.ack_received missing here
|
||||
uint8_t payload[16] = {};
|
||||
LoRaPHY_stub::uint16_value = 5;
|
||||
payload[0] = FRAME_TYPE_DATA_CONFIRMED_DOWN << 5;
|
||||
payload[5] = 1 << 5;
|
||||
|
||||
//address != _params.dev_addr
|
||||
payload[2] = 2;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
object->post_process_mcps_req();
|
||||
|
||||
payload[2] = 0;
|
||||
//mic failure
|
||||
payload[13] = 2;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
object->post_process_mcps_req();
|
||||
|
||||
payload[13] = 0;
|
||||
//crypto failure
|
||||
LoRaMacCrypto_stub::int_table_idx_value = 0;
|
||||
LoRaMacCrypto_stub::int_table[0] = 4;
|
||||
LoRaMacCrypto_stub::int_table[1] = 4;
|
||||
// LoRaPHY_stub::uint16_value = 0;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
object->post_process_mcps_req();
|
||||
|
||||
//process_mac_commands failure
|
||||
LoRaMacCommand_stub::status_value = LORAWAN_STATUS_BUSY;
|
||||
LoRaMacCrypto_stub::int_table[0] = 0;
|
||||
LoRaMacCrypto_stub::int_table[1] = 0;
|
||||
payload[7] = 1;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
object->post_process_mcps_req();
|
||||
|
||||
//FOpts_len != 0
|
||||
payload[5] = (1 << 5) + 1;
|
||||
payload[7] = 0;
|
||||
LoRaMacCommand_stub::status_value = LORAWAN_STATUS_OK;
|
||||
payload[0] = FRAME_TYPE_DATA_UNCONFIRMED_DOWN << 5;
|
||||
|
||||
object->on_radio_rx_done(payload, 13, 0, 0);
|
||||
|
||||
//_mac_commands.process_mac_commands fails
|
||||
LoRaMacCommand_stub::status_value = LORAWAN_STATUS_DATARATE_INVALID;
|
||||
object->on_radio_rx_done(payload, 13, 0, 0);
|
||||
|
||||
object->post_process_mcps_req();
|
||||
|
||||
payload[9] = 1;
|
||||
LoRaMacCommand_stub::status_value = LORAWAN_STATUS_OK;
|
||||
payload[0] = FRAME_TYPE_PROPRIETARY << 5;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
object->post_process_mcps_req();
|
||||
|
||||
payload[9] = 0;
|
||||
payload[5] = 1 << 5;
|
||||
LoRaMacCommand_stub::status_value = LORAWAN_STATUS_OK;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
object->post_process_mcps_req();
|
||||
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
object->prepare_ongoing_tx(1, data, 15, 0x04, 2);
|
||||
object->send_ongoing_tx();
|
||||
object->post_process_mcps_req();
|
||||
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
object->prepare_ongoing_tx(1, data, 15, 0x08, 2);
|
||||
object->send_ongoing_tx();
|
||||
object->post_process_mcps_req();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, handle_join_accept_frame)
|
||||
{
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
|
||||
uint8_t payload[16] = {};
|
||||
LoRaPHY_stub::uint16_value = 5;
|
||||
payload[0] = FRAME_TYPE_JOIN_ACCEPT << 5;
|
||||
payload[5] = 1 << 5;
|
||||
|
||||
LoRaMacCrypto_stub::int_table_idx_value = 0;
|
||||
LoRaMacCrypto_stub::int_table[0] = 4;
|
||||
LoRaMacCrypto_stub::int_table[1] = 4;
|
||||
LoRaMacCrypto_stub::int_table[2] = 4;
|
||||
LoRaMacCrypto_stub::int_table[3] = 4;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
|
||||
LoRaMacCrypto_stub::int_table_idx_value = 0;
|
||||
LoRaMacCrypto_stub::int_table[0] = 0;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
|
||||
LoRaMacCrypto_stub::int_table_idx_value = 0;
|
||||
LoRaMacCrypto_stub::int_table[1] = 0;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
|
||||
//mic failure case
|
||||
payload[13] = 17;
|
||||
LoRaMacCrypto_stub::int_table_idx_value = 0;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
|
||||
payload[13] = 0;
|
||||
LoRaMacCrypto_stub::int_table_idx_value = 0;
|
||||
LoRaMacCrypto_stub::int_table[2] = 0;
|
||||
object->on_radio_rx_done(payload, 16, 0, 0);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, post_process_mcps_ind)
|
||||
{
|
||||
object->post_process_mcps_ind();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, post_process_mlme_request)
|
||||
{
|
||||
object->post_process_mlme_request();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, post_process_mlme_ind)
|
||||
{
|
||||
object->post_process_mlme_ind();
|
||||
}
|
||||
|
||||
uint8_t batt_cb()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, set_batterylevel_callback)
|
||||
{
|
||||
object->set_batterylevel_callback(batt_cb);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_backoff_timer_event_id)
|
||||
{
|
||||
object->get_backoff_timer_event_id();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, clear_tx_pipe)
|
||||
{
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->clear_tx_pipe()); //timer id == 0
|
||||
|
||||
my_phy phy;
|
||||
object->bind_phy(phy);
|
||||
|
||||
lorawan_connect_t conn;
|
||||
uint8_t key[16];
|
||||
conn.connection_u.otaa.app_key = key;
|
||||
conn.connection_u.otaa.app_eui = key;
|
||||
conn.connection_u.otaa.dev_eui = key;
|
||||
conn.connection_u.otaa.nb_trials = 2;
|
||||
object->prepare_join(&conn, true);
|
||||
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize(NULL, my_cb));
|
||||
EventQueue_stub::int_value = 0;
|
||||
EXPECT_EQ(LORAWAN_STATUS_BUSY, object->clear_tx_pipe());
|
||||
|
||||
EventQueue_stub::int_value = 1;
|
||||
EXPECT_EQ(LORAWAN_STATUS_OK, object->clear_tx_pipe());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_current_time)
|
||||
{
|
||||
object->get_current_time();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMac, get_current_slot)
|
||||
{
|
||||
object->get_current_slot();
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
#[[
|
||||
* 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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaMac")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/mac/LoRaMac.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/mac
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loramac/Test_LoRaMac.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANStack_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
stubs/LoRaMacCrypto_stub.cpp
|
||||
stubs/LoRaMacChannelPlan_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/LoRaMacCommand_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
|
||||
)
|
||||
|
||||
# defines
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_ADR_ON=true -DMBED_CONF_LORA_PUBLIC_NETWORK=true -DMBED_CONF_LORA_NB_TRIALS=2 -DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_ADR_ON=true -DMBED_CONF_LORA_PUBLIC_NETWORK=true -DMBED_CONF_LORA_NB_TRIALS=2 -DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_DUTY_CYCLE_ON=true -DMBED_CONF_LORA_MAX_SYS_RX_ERROR=10 -DMBED_CONF_LORA_NWKSKEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_DUTY_CYCLE_ON=true -DMBED_CONF_LORA_MAX_SYS_RX_ERROR=10 -DMBED_CONF_LORA_NWKSKEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_APPSKEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_APPSKEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_DEVICE_ADDRESS=\"0x00000000\"")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_DEVICE_ADDRESS=\"0x00000000\"")
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "LoRaMacChannelPlan.h"
|
||||
#include "LoRaPHY_stub.h"
|
||||
#include "LoRaPHY.h"
|
||||
|
||||
class my_LoRaPHY : public LoRaPHY
|
||||
{
|
||||
public:
|
||||
my_LoRaPHY(){};
|
||||
|
||||
virtual ~my_LoRaPHY(){};
|
||||
};
|
||||
|
||||
|
||||
class Test_LoRaMacChannelPlan : public testing::Test {
|
||||
protected:
|
||||
LoRaMacChannelPlan *object;
|
||||
my_LoRaPHY phy;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
object = new LoRaMacChannelPlan();
|
||||
object->activate_channelplan_subsystem(&phy);
|
||||
|
||||
LoRaPHY_stub::uint8_value = 0;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_OK;
|
||||
LoRaPHY_stub::uint16_value = 0;
|
||||
memcpy(LoRaPHY_stub::bool_table, "0", 20);
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Test_LoRaMacChannelPlan, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacChannelPlan, set_plan)
|
||||
{
|
||||
lorawan_channelplan_t plan;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = false;
|
||||
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_SERVICE_UNKNOWN);
|
||||
|
||||
plan.nb_channels = 1;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
LoRaPHY_stub::uint8_value = 0;
|
||||
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_PARAMETER_INVALID);
|
||||
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
LoRaPHY_stub::uint8_value = 10;
|
||||
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_PARAMETER_INVALID;
|
||||
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_PARAMETER_INVALID);
|
||||
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
plan.nb_channels = 2;
|
||||
LoRaPHY_stub::lorawan_status_value = LORAWAN_STATUS_OK;
|
||||
EXPECT_TRUE(object->set_plan(plan) == LORAWAN_STATUS_OK);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacChannelPlan, get_plan)
|
||||
{
|
||||
lorawan_channelplan_t plan;
|
||||
channel_params_t params;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = false;
|
||||
EXPECT_TRUE(object->get_plan(plan, ¶ms) == LORAWAN_STATUS_SERVICE_UNKNOWN);
|
||||
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
LoRaPHY_stub::bool_table[1] = false;
|
||||
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
LoRaPHY_stub::uint16_value = 0xABCD;
|
||||
EXPECT_TRUE(object->get_plan(plan, ¶ms) == LORAWAN_STATUS_OK);
|
||||
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
LoRaPHY_stub::bool_table[1] = true;
|
||||
LoRaPHY_stub::bool_table[2] = false;
|
||||
loramac_channel_t ch;
|
||||
plan.channels = &ch;
|
||||
EXPECT_TRUE(object->get_plan(plan, ¶ms) == LORAWAN_STATUS_OK);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacChannelPlan, remove_plan)
|
||||
{
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = false;
|
||||
EXPECT_TRUE(object->remove_plan() == LORAWAN_STATUS_SERVICE_UNKNOWN);
|
||||
|
||||
LoRaPHY_stub::uint8_value = 4;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
LoRaPHY_stub::bool_table[1] = true; //first continue
|
||||
LoRaPHY_stub::bool_table[2] = false;
|
||||
LoRaPHY_stub::bool_table[3] = false;//second continue
|
||||
LoRaPHY_stub::bool_table[4] = false;
|
||||
LoRaPHY_stub::bool_table[5] = true;
|
||||
LoRaPHY_stub::bool_table[6] = false;//false for remove_single_channel(i)
|
||||
|
||||
EXPECT_TRUE(object->remove_plan() == LORAWAN_STATUS_SERVICE_UNKNOWN);
|
||||
|
||||
LoRaPHY_stub::uint8_value = 3;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
LoRaPHY_stub::bool_table[1] = false;
|
||||
LoRaPHY_stub::bool_table[2] = true;
|
||||
LoRaPHY_stub::bool_table[3] = true;
|
||||
LoRaPHY_stub::bool_table[4] = true;
|
||||
LoRaPHY_stub::bool_table[5] = true;
|
||||
LoRaPHY_stub::bool_table[7] = true;
|
||||
LoRaPHY_stub::bool_table[8] = true;
|
||||
LoRaPHY_stub::bool_table[9] = true;
|
||||
LoRaPHY_stub::bool_table[10] = true;
|
||||
|
||||
EXPECT_TRUE(object->remove_plan() == LORAWAN_STATUS_OK);
|
||||
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacChannelPlan, remove_single_channel)
|
||||
{
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = false;
|
||||
EXPECT_TRUE(object->remove_single_channel(4) == LORAWAN_STATUS_SERVICE_UNKNOWN);
|
||||
|
||||
LoRaPHY_stub::uint8_value = 2;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
|
||||
EXPECT_TRUE(object->remove_single_channel(4) == LORAWAN_STATUS_PARAMETER_INVALID);
|
||||
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
LoRaPHY_stub::bool_table[1] = false;
|
||||
EXPECT_TRUE(object->remove_single_channel(1) == LORAWAN_STATUS_PARAMETER_INVALID);
|
||||
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
LoRaPHY_stub::bool_table[1] = true;
|
||||
EXPECT_TRUE(object->remove_single_channel(1) == LORAWAN_STATUS_OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#[[
|
||||
* 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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaMacChannelPlan")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/mac/LoRaMacChannelPlan.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/mac
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loramacchannelplan/Test_LoRaMacChannelPlan.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_TX_MAX_SIZE=255")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_TX_MAX_SIZE=255")
|
|
@ -0,0 +1,353 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "LoRaMacCommand.h"
|
||||
|
||||
#include "LoRaPHY_stub.h"
|
||||
|
||||
class my_LoRaPHY : public LoRaPHY
|
||||
{
|
||||
public:
|
||||
my_LoRaPHY(){};
|
||||
|
||||
virtual ~my_LoRaPHY(){};
|
||||
};
|
||||
|
||||
uint8_t my_cb()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
class Test_LoRaMacCommand : public testing::Test {
|
||||
protected:
|
||||
LoRaMacCommand *object;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
object = new LoRaMacCommand();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, get_mac_cmd_length)
|
||||
{
|
||||
object->add_link_check_req();
|
||||
EXPECT_TRUE(object->get_mac_cmd_length() == 1);
|
||||
object->clear_command_buffer();
|
||||
EXPECT_TRUE(object->get_mac_cmd_length() == 0);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, parse_mac_commands_to_repeat)
|
||||
{
|
||||
loramac_mlme_confirm_t mlme;
|
||||
lora_mac_system_params_t params;
|
||||
my_LoRaPHY phy;
|
||||
uint8_t buf[20];
|
||||
|
||||
object->parse_mac_commands_to_repeat();
|
||||
|
||||
buf[0] = 2;
|
||||
buf[1] = 16;
|
||||
buf[2] = 32;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 3, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
buf[0] = 3;
|
||||
LoRaPHY_stub::uint8_value = 7;
|
||||
LoRaPHY_stub::linkAdrNbBytesParsed = 5;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
buf[0] = 4;
|
||||
buf[1] = 2;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
buf[0] = 5;
|
||||
buf[1] = 2;
|
||||
buf[2] = 2;
|
||||
buf[3] = 2;
|
||||
buf[4] = 2;
|
||||
buf[5] = 2;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
buf[0] = 6;
|
||||
object->set_batterylevel_callback(my_cb);
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
buf[0] = 7;
|
||||
buf[1] = 2;
|
||||
buf[2] = 2;
|
||||
buf[3] = 2;
|
||||
buf[4] = 2;
|
||||
buf[5] = 2;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 6, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
buf[0] = 8;
|
||||
buf[1] = 0;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
buf[0] = 9;
|
||||
buf[1] = 48;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
buf[0] = 10;
|
||||
buf[1] = 2;
|
||||
buf[1] = 3;
|
||||
buf[1] = 4;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
object->parse_mac_commands_to_repeat();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, clear_repeat_buffer)
|
||||
{
|
||||
object->clear_repeat_buffer();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, copy_repeat_commands_to_buffer)
|
||||
{
|
||||
loramac_mlme_confirm_t mlme;
|
||||
lora_mac_system_params_t params;
|
||||
my_LoRaPHY phy;
|
||||
uint8_t buf[20];
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 5;
|
||||
buf[1] = 2;
|
||||
buf[2] = 2;
|
||||
buf[3] = 2;
|
||||
buf[4] = 2;
|
||||
buf[5] = 2;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
object->parse_mac_commands_to_repeat();
|
||||
|
||||
object->clear_command_buffer();
|
||||
EXPECT_TRUE(object->get_mac_cmd_length() == 0);
|
||||
|
||||
object->copy_repeat_commands_to_buffer();
|
||||
|
||||
EXPECT_TRUE(object->get_mac_cmd_length() != 0);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, get_repeat_commands_length)
|
||||
{
|
||||
EXPECT_TRUE(object->get_repeat_commands_length() == 0 );
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, clear_sticky_mac_cmd)
|
||||
{
|
||||
loramac_mlme_confirm_t mlme;
|
||||
lora_mac_system_params_t params;
|
||||
my_LoRaPHY phy;
|
||||
uint8_t buf[20];
|
||||
|
||||
EXPECT_TRUE(object->has_sticky_mac_cmd() == false);
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 5;
|
||||
buf[1] = 2;
|
||||
buf[2] = 2;
|
||||
buf[3] = 2;
|
||||
buf[4] = 2;
|
||||
buf[5] = 2;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
EXPECT_TRUE(object->has_sticky_mac_cmd() == true);
|
||||
|
||||
object->clear_sticky_mac_cmd();
|
||||
EXPECT_TRUE(object->has_sticky_mac_cmd() == false);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, has_sticky_mac_cmd)
|
||||
{
|
||||
loramac_mlme_confirm_t mlme;
|
||||
lora_mac_system_params_t params;
|
||||
my_LoRaPHY phy;
|
||||
uint8_t buf[20];
|
||||
|
||||
EXPECT_TRUE(object->has_sticky_mac_cmd() == false);
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 5;
|
||||
buf[1] = 2;
|
||||
buf[2] = 2;
|
||||
buf[3] = 2;
|
||||
buf[4] = 2;
|
||||
buf[5] = 2;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
EXPECT_TRUE(object->has_sticky_mac_cmd() == true);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, process_mac_commands)
|
||||
{
|
||||
loramac_mlme_confirm_t mlme;
|
||||
lora_mac_system_params_t params;
|
||||
my_LoRaPHY phy;
|
||||
uint8_t buf[20];
|
||||
EXPECT_TRUE(object->process_mac_commands(NULL, 0, 0, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
buf[0] = 2;
|
||||
buf[1] = 16;
|
||||
buf[2] = 32;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 3, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
buf[0] = 3;
|
||||
LoRaPHY_stub::uint8_value = 7;
|
||||
LoRaPHY_stub::linkAdrNbBytesParsed = 5;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
//Overflow add_link_adr_ans function here
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 3;
|
||||
for (int i=0; i < 64; i++) {
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
}
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 4;
|
||||
buf[1] = 2;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
//Overflow add_duty_cycle_ans()
|
||||
object->clear_command_buffer();
|
||||
for (int i=0; i < 128; i++) {
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
}
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 5;
|
||||
buf[1] = 2;
|
||||
buf[2] = 2;
|
||||
buf[3] = 2;
|
||||
buf[4] = 2;
|
||||
buf[5] = 2;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
//Overflow add_rx_param_setup_ans
|
||||
object->clear_command_buffer();
|
||||
LoRaPHY_stub::uint8_value = 7;
|
||||
for (int i=0; i < 64; i++) {
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
}
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 6;
|
||||
object->set_batterylevel_callback(my_cb);
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
//overflow add_dev_status_ans
|
||||
object->clear_command_buffer();
|
||||
for (int i=0; i < 42; i++) {
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
}
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 7;
|
||||
buf[1] = 2;
|
||||
buf[2] = 2;
|
||||
buf[3] = 2;
|
||||
buf[4] = 2;
|
||||
buf[5] = 2;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 6, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
//Overflow add_new_channel_ans
|
||||
object->clear_command_buffer();
|
||||
LoRaPHY_stub::uint8_value = 7;
|
||||
for (int i=0; i < 64; i++) {
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 6, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
}
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 6, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 8;
|
||||
buf[1] = 0;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
//Overflow add_rx_timing_setup_ans
|
||||
object->clear_command_buffer();
|
||||
LoRaPHY_stub::uint8_value = 7;
|
||||
for (int i=0; i < 128; i++) {
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
}
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 9;
|
||||
buf[1] = 48;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
//Overflow add_tx_param_setup_ans
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
object->clear_command_buffer();
|
||||
LoRaPHY_stub::uint8_value = 7;
|
||||
for (int i=0; i < 128; i++) {
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
}
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 2, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 10;
|
||||
buf[1] = 2;
|
||||
buf[1] = 3;
|
||||
buf[1] = 4;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
|
||||
//Overflow add_tx_param_setup_ans
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
object->clear_command_buffer();
|
||||
LoRaPHY_stub::uint8_value = 7;
|
||||
for (int i=0; i < 64; i++) {
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
}
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_LENGTH_ERROR);
|
||||
|
||||
object->clear_command_buffer();
|
||||
buf[0] = 80;
|
||||
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_UNSUPPORTED);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, add_link_check_req)
|
||||
{
|
||||
object->add_link_check_req();
|
||||
EXPECT_TRUE(object->get_mac_commands_buffer()[0] == 2);
|
||||
EXPECT_TRUE(object->get_mac_cmd_length() == 1);
|
||||
object->clear_command_buffer();
|
||||
EXPECT_TRUE(object->get_mac_cmd_length() == 0);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCommand, set_batterylevel_callback)
|
||||
{
|
||||
object->set_batterylevel_callback(my_cb);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
#[[
|
||||
* 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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaMacCommand")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/mac/LoRaMacCommand.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/mac
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loramaccommand/Test_LoRaMacCommand.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
)
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "LoRaMacCrypto.h"
|
||||
|
||||
#include "cipher_stub.h"
|
||||
#include "cmac_stub.h"
|
||||
#include "aes_stub.h"
|
||||
|
||||
class Test_LoRaMacCrypto : public testing::Test {
|
||||
protected:
|
||||
LoRaMacCrypto *object;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
cipher_stub.info_value = NULL;
|
||||
cipher_stub.int_zero_counter = 0;
|
||||
cipher_stub.int_value = 0;
|
||||
cmac_stub.int_zero_counter = 0;
|
||||
cmac_stub.int_value = 0;
|
||||
aes_stub.int_zero_counter = 0;
|
||||
aes_stub.int_value = 0;
|
||||
object = new LoRaMacCrypto();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Test_LoRaMacCrypto, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
LoRaMacCrypto obj;
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCrypto, compute_mic)
|
||||
{
|
||||
EXPECT_TRUE(MBEDTLS_ERR_CIPHER_ALLOC_FAILED == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
|
||||
|
||||
mbedtls_cipher_info_t info;
|
||||
cipher_stub.info_value = &info;
|
||||
cipher_stub.int_zero_counter = 0;
|
||||
cipher_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
|
||||
|
||||
cipher_stub.int_value = 0;
|
||||
cmac_stub.int_zero_counter = 0;
|
||||
cmac_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
|
||||
|
||||
cmac_stub.int_zero_counter = 1;
|
||||
cmac_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
|
||||
|
||||
cmac_stub.int_zero_counter = 2;
|
||||
cmac_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
|
||||
|
||||
cmac_stub.int_zero_counter = 3;
|
||||
cmac_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, NULL));
|
||||
|
||||
uint32_t mic[16];
|
||||
cmac_stub.int_zero_counter = 3;
|
||||
cmac_stub.int_value = 0;
|
||||
EXPECT_TRUE(0 == object->compute_mic(NULL, 0, NULL, 0, 0, 0, 0, mic));
|
||||
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCrypto, encrypt_payload)
|
||||
{
|
||||
aes_stub.int_zero_counter = 0;
|
||||
aes_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->encrypt_payload(NULL, 0, NULL, 0, 0, 0, 0, NULL));
|
||||
|
||||
aes_stub.int_zero_counter = 1;
|
||||
aes_stub.int_value = -2;
|
||||
uint8_t buf[60];
|
||||
uint8_t enc[60];
|
||||
EXPECT_TRUE(-2 == object->encrypt_payload(buf, 20, NULL, 0, 0, 0, 0, enc));
|
||||
|
||||
aes_stub.int_zero_counter = 2;
|
||||
aes_stub.int_value = -3;
|
||||
EXPECT_TRUE(-3 == object->encrypt_payload(buf, 20, NULL, 0, 0, 0, 0, enc));
|
||||
|
||||
aes_stub.int_value = 0;
|
||||
EXPECT_TRUE(0 == object->encrypt_payload(buf, 20, NULL, 0, 0, 0, 0, enc));
|
||||
|
||||
EXPECT_TRUE(0 == object->encrypt_payload(buf, 60, NULL, 0, 0, 0, 0, enc));
|
||||
|
||||
aes_stub.int_zero_counter = 0;
|
||||
EXPECT_TRUE(0 == object->encrypt_payload(NULL, 0, NULL, 0, 0, 0, 0, NULL));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCrypto, decrypt_payload)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->decrypt_payload(NULL, 0, NULL, 0, 0, 0, 0, NULL));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCrypto, compute_join_frame_mic)
|
||||
{
|
||||
uint32_t mic[16];
|
||||
EXPECT_TRUE(MBEDTLS_ERR_CIPHER_ALLOC_FAILED == object->compute_join_frame_mic(NULL, 0, NULL, 0, NULL));
|
||||
mbedtls_cipher_info_t info;
|
||||
cipher_stub.info_value = &info;
|
||||
cipher_stub.int_zero_counter = 0;
|
||||
cipher_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->compute_join_frame_mic(NULL, 0, NULL, 0, NULL));
|
||||
|
||||
cipher_stub.int_value = 0;
|
||||
cmac_stub.int_zero_counter = 0;
|
||||
cmac_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->compute_join_frame_mic(NULL, 0, NULL, 0, NULL));
|
||||
|
||||
cmac_stub.int_zero_counter = 1;
|
||||
cmac_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->compute_join_frame_mic(NULL, 0, NULL, 0, NULL));
|
||||
|
||||
cmac_stub.int_zero_counter = 2;
|
||||
cmac_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->compute_join_frame_mic(NULL, 0, NULL, 0, NULL));
|
||||
|
||||
cmac_stub.int_zero_counter = 3;
|
||||
cmac_stub.int_value = 0;
|
||||
EXPECT_TRUE(0 == object->compute_join_frame_mic(NULL, 0, NULL, 0, mic));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCrypto, decrypt_join_frame)
|
||||
{
|
||||
aes_stub.int_zero_counter = 0;
|
||||
aes_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->decrypt_join_frame(NULL, 0, NULL, 0, NULL));
|
||||
|
||||
aes_stub.int_zero_counter = 1;
|
||||
aes_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->decrypt_join_frame(NULL, 0, NULL, 0, NULL));
|
||||
|
||||
aes_stub.int_value = 0;
|
||||
uint8_t buf[60];
|
||||
uint8_t enc[60];
|
||||
EXPECT_TRUE(0 == object->decrypt_join_frame(buf, 60, NULL, 0, enc));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaMacCrypto, compute_skeys_for_join_frame)
|
||||
{
|
||||
uint8_t nwk_key[16];
|
||||
uint8_t app_key[16];
|
||||
uint8_t nonce[16];
|
||||
|
||||
aes_stub.int_zero_counter = 0;
|
||||
aes_stub.int_value = -1;
|
||||
EXPECT_TRUE(-1 == object->compute_skeys_for_join_frame(NULL, 0, nonce, 0, nwk_key, app_key));
|
||||
|
||||
aes_stub.int_zero_counter = 1;
|
||||
aes_stub.int_value = -2;
|
||||
EXPECT_TRUE(-2 == object->compute_skeys_for_join_frame(NULL, 0, nonce, 0, nwk_key, app_key));
|
||||
|
||||
aes_stub.int_zero_counter = 0;
|
||||
aes_stub.int_value = 0;
|
||||
EXPECT_TRUE(0 == object->compute_skeys_for_join_frame(NULL, 0, nonce, 0, nwk_key, app_key));
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
#[[
|
||||
* 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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaMacCrypto")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/mac/LoRaMacCrypto.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/mac
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loramaccrypto/Test_LoRaMacCrypto.cpp
|
||||
stubs/cipher_stub.c
|
||||
stubs/aes_stub.c
|
||||
stubs/cmac_stub.c
|
||||
|
||||
)
|
||||
|
|
@ -0,0 +1,814 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "LoRaPHY.h"
|
||||
|
||||
#include "LoRaWANTimer_stub.h"
|
||||
|
||||
class my_LoRaPHY : public LoRaPHY
|
||||
{
|
||||
public:
|
||||
my_LoRaPHY(){phy_params.adr_ack_delay = 1;}
|
||||
|
||||
virtual ~my_LoRaPHY(){}
|
||||
|
||||
loraphy_params_t &get_phy_params() {
|
||||
return phy_params;
|
||||
}
|
||||
};
|
||||
|
||||
class my_radio : public LoRaRadio
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void init_radio(radio_events_t *events){};
|
||||
|
||||
virtual void radio_reset(){};
|
||||
|
||||
virtual void sleep(void){};
|
||||
|
||||
virtual void standby(void){};
|
||||
|
||||
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
|
||||
uint32_t datarate, uint8_t coderate,
|
||||
uint32_t bandwidth_afc, uint16_t preamble_len,
|
||||
uint16_t symb_timeout, bool fix_len,
|
||||
uint8_t payload_len,
|
||||
bool crc_on, bool freq_hop_on, uint8_t hop_period,
|
||||
bool iq_inverted, bool rx_continuous){};
|
||||
|
||||
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
|
||||
uint32_t bandwidth, uint32_t datarate,
|
||||
uint8_t coderate, uint16_t preamble_len,
|
||||
bool fix_len, bool crc_on, bool freq_hop_on,
|
||||
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
|
||||
|
||||
virtual void send(uint8_t *buffer, uint8_t size){};
|
||||
|
||||
virtual void receive(void){};
|
||||
|
||||
virtual void set_channel(uint32_t freq){};
|
||||
|
||||
virtual uint32_t random(void){};
|
||||
|
||||
virtual uint8_t get_status(void){return uint8_value;};
|
||||
|
||||
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
|
||||
|
||||
virtual void set_public_network(bool enable){};
|
||||
|
||||
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
|
||||
|
||||
virtual bool perform_carrier_sense(radio_modems_t modem,
|
||||
uint32_t freq,
|
||||
int16_t rssi_threshold,
|
||||
uint32_t max_carrier_sense_time){ return bool_value;};
|
||||
|
||||
virtual void start_cad(void){};
|
||||
|
||||
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
|
||||
|
||||
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
|
||||
|
||||
virtual void lock(void){};
|
||||
|
||||
virtual void unlock(void){};
|
||||
|
||||
bool bool_value;
|
||||
uint8_t uint8_value;
|
||||
};
|
||||
|
||||
class Test_LoRaPHY : public testing::Test {
|
||||
protected:
|
||||
my_LoRaPHY *object;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
object = new my_LoRaPHY();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Test_LoRaPHY, initialize)
|
||||
{
|
||||
object->initialize(NULL);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, set_radio_instance)
|
||||
{
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, put_radio_to_sleep)
|
||||
{
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
object->put_radio_to_sleep();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, put_radio_to_standby)
|
||||
{
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
object->put_radio_to_standby();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, handle_receive)
|
||||
{
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
object->handle_receive();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, handle_send)
|
||||
{
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
object->handle_send(NULL, 0);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, setup_public_network_mode)
|
||||
{
|
||||
my_radio radio;
|
||||
channel_params_t p;
|
||||
object->get_phy_params().channels.channel_list = &p;
|
||||
object->set_radio_instance(radio);
|
||||
object->setup_public_network_mode(false);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_radio_rng)
|
||||
{
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
EXPECT_TRUE(0 != object->get_radio_rng());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, calculate_backoff)
|
||||
{
|
||||
channel_params_t p[1];
|
||||
p[0].band = 0;
|
||||
object->get_phy_params().channels.channel_list = p;
|
||||
band_t b[1];
|
||||
object->get_phy_params().bands.table = b;
|
||||
object->calculate_backoff(false, false, false, 0, 10, 12);
|
||||
|
||||
object->calculate_backoff(false, true, false, 0, 3600000 + 10, 12);
|
||||
|
||||
object->calculate_backoff(false, false, true, 0, 3600000 + 36000000 + 10, 12);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, mask_bit_test)
|
||||
{
|
||||
uint16_t buf;
|
||||
EXPECT_TRUE(!object->mask_bit_test(&buf, 0));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, mask_bit_set)
|
||||
{
|
||||
uint16_t buf;
|
||||
object->mask_bit_set(&buf, 3);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, mask_bit_clear)
|
||||
{
|
||||
uint16_t buf;
|
||||
object->mask_bit_clear(&buf, 0);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, request_new_channel)
|
||||
{
|
||||
channel_params_t p;
|
||||
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
|
||||
|
||||
p.frequency = 0;
|
||||
object->get_phy_params().custom_channelplans_supported = true;
|
||||
uint16_t list;
|
||||
object->get_phy_params().channels.default_mask = &list;
|
||||
channel_params_t pp;
|
||||
object->get_phy_params().channels.channel_list = &pp;
|
||||
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
|
||||
|
||||
//Default
|
||||
p.frequency = 2;
|
||||
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
|
||||
|
||||
//Freq & DR invalid
|
||||
object->get_phy_params().max_channel_cnt = 2;
|
||||
EXPECT_TRUE(0 == object->request_new_channel(1, &p));
|
||||
|
||||
//Freq invalid
|
||||
pp.frequency = 0;
|
||||
object->get_phy_params().default_max_datarate = 1;
|
||||
object->get_phy_params().max_tx_datarate = 8;
|
||||
p.dr_range.fields.max = 2;
|
||||
p.dr_range.fields.min = 0;
|
||||
object->get_phy_params().default_channel_cnt = 3;
|
||||
EXPECT_TRUE(2 == object->request_new_channel(0, &p));
|
||||
|
||||
//DR invalid
|
||||
pp.frequency = 2;
|
||||
p.band = 0;
|
||||
object->get_phy_params().bands.size = 1;
|
||||
band_t b;
|
||||
object->get_phy_params().bands.table = &b;
|
||||
b.higher_band_freq = 5;
|
||||
b.lower_band_freq = 1;
|
||||
p.dr_range.fields.max = 12;
|
||||
p.dr_range.fields.min = 1;
|
||||
EXPECT_TRUE(1 == object->request_new_channel(0, &p));
|
||||
|
||||
//STATUS_OK
|
||||
p.dr_range.fields.max = 2;
|
||||
uint16_t list2[16];
|
||||
p.dr_range.fields.min = 0;
|
||||
object->get_phy_params().channels.mask = list2;
|
||||
EXPECT_TRUE(3 == object->request_new_channel(0, &p));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, set_last_tx_done)
|
||||
{
|
||||
channel_params_t p[1];
|
||||
p[0].band = 0;
|
||||
object->get_phy_params().channels.channel_list = p;
|
||||
band_t b[1];
|
||||
object->get_phy_params().bands.table = b;
|
||||
object->set_last_tx_done(0, false, 0);
|
||||
|
||||
object->set_last_tx_done(0, true, 0);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, restore_default_channels)
|
||||
{
|
||||
channel_params_t p[1];
|
||||
p[0].band = 0;
|
||||
object->get_phy_params().channels.channel_list = p;
|
||||
uint16_t m, dm;
|
||||
object->get_phy_params().channels.mask_size = 1;
|
||||
object->get_phy_params().channels.default_mask = &dm;
|
||||
object->get_phy_params().channels.mask = &m;
|
||||
object->restore_default_channels();
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, apply_cf_list)
|
||||
{
|
||||
uint8_t list[16];
|
||||
object->apply_cf_list(list, 0);
|
||||
|
||||
object->get_phy_params().cflist_supported = true;
|
||||
object->apply_cf_list(list, 0);
|
||||
|
||||
object->get_phy_params().default_channel_cnt = 2;
|
||||
object->get_phy_params().cflist_channel_cnt = 0;
|
||||
object->get_phy_params().max_channel_cnt = 3;
|
||||
|
||||
uint16_t mask[8];
|
||||
channel_params_t p[8];
|
||||
object->get_phy_params().channels.default_mask = mask;
|
||||
object->get_phy_params().channels.mask = mask;
|
||||
object->get_phy_params().channels.channel_list = p;
|
||||
object->apply_cf_list(list, 16);
|
||||
|
||||
list[1] = 15;
|
||||
object->get_phy_params().cflist_channel_cnt = 1;
|
||||
object->apply_cf_list(list, 16);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_next_ADR)
|
||||
{
|
||||
int8_t i = 0;
|
||||
int8_t j = 0;
|
||||
uint32_t ctr = 0;
|
||||
object->get_phy_params().min_tx_datarate = 0;
|
||||
EXPECT_TRUE(!object->get_next_ADR(false, i, j, ctr));
|
||||
|
||||
i = 1;
|
||||
object->get_phy_params().adr_ack_limit = 3;
|
||||
EXPECT_TRUE(!object->get_next_ADR(false, i, j, ctr));
|
||||
|
||||
object->get_phy_params().adr_ack_limit = 3;
|
||||
ctr = 4;
|
||||
object->get_phy_params().max_tx_power = 2;
|
||||
object->get_phy_params().adr_ack_delay = 1;
|
||||
EXPECT_TRUE(object->get_next_ADR(true, i, j, ctr));
|
||||
|
||||
ctr = 5;
|
||||
object->get_phy_params().adr_ack_delay = 2;
|
||||
EXPECT_TRUE(!object->get_next_ADR(true, i, j, ctr));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, rx_config)
|
||||
{
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
uint8_t list;
|
||||
object->get_phy_params().datarates.table = &list;
|
||||
uint8_t list2;
|
||||
object->get_phy_params().payloads_with_repeater.table = &list2;
|
||||
rx_config_params_t p;
|
||||
p.datarate = 0;
|
||||
p.rx_slot = RX_SLOT_WIN_1;
|
||||
channel_params_t pp[1];
|
||||
object->get_phy_params().channels.channel_list = pp;
|
||||
pp[0].rx1_frequency = 2;
|
||||
p.channel = 0;
|
||||
uint8_t tab[8];
|
||||
object->get_phy_params().payloads.table = tab;
|
||||
object->get_phy_params().payloads_with_repeater.table = tab;
|
||||
EXPECT_TRUE(object->rx_config(&p));
|
||||
|
||||
p.datarate = DR_7;
|
||||
p.is_repeater_supported = true;
|
||||
object->get_phy_params().fsk_supported = true;
|
||||
EXPECT_TRUE(object->rx_config(&p));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, compute_rx_win_params)
|
||||
{
|
||||
uint32_t list[1];
|
||||
list[0] = 0;
|
||||
object->get_phy_params().bandwidths.table = list;
|
||||
uint8_t list2;
|
||||
object->get_phy_params().datarates.table = &list2;
|
||||
rx_config_params_t p;
|
||||
object->compute_rx_win_params(0, 0, 0, &p);
|
||||
|
||||
p.datarate = 0;
|
||||
list[0] = 125000;
|
||||
object->compute_rx_win_params(0, 0, 0, &p);
|
||||
|
||||
list[0] = 250000;
|
||||
object->compute_rx_win_params(0, 0, 0, &p);
|
||||
|
||||
list[0] = 500000;
|
||||
object->get_phy_params().fsk_supported = true;
|
||||
object->get_phy_params().max_rx_datarate = 0;
|
||||
object->compute_rx_win_params(0, 0, 0, &p);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, tx_config)
|
||||
{
|
||||
band_t b;
|
||||
object->get_phy_params().bands.table = &b;
|
||||
channel_params_t pp;
|
||||
pp.band=0;
|
||||
object->get_phy_params().channels.channel_list = &pp;
|
||||
uint32_t list = 0;
|
||||
object->get_phy_params().bandwidths.table = &list;
|
||||
uint8_t list2;
|
||||
object->get_phy_params().datarates.table = &list2;
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
tx_config_params_t p;
|
||||
p.channel=0;
|
||||
int8_t i;
|
||||
lorawan_time_t t;
|
||||
object->tx_config(&p, &i, &t);
|
||||
|
||||
p.datarate = 8;
|
||||
object->get_phy_params().max_tx_datarate = 8;
|
||||
object->tx_config(&p, &i, &t);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, link_ADR_request)
|
||||
{
|
||||
adr_req_params_t p;
|
||||
uint8_t b[100];
|
||||
p.payload = b;
|
||||
b[0] = 0x03;
|
||||
b[1] = 1;
|
||||
b[2] = 0;
|
||||
b[3] = 0;
|
||||
b[4] = 1 << 4;
|
||||
b[5] = 0x03;
|
||||
b[6] = 1;
|
||||
b[7] = 1;
|
||||
b[8] = 1;
|
||||
b[9] = 6 << 4;
|
||||
b[10] = 0x03;
|
||||
b[11] = 1;
|
||||
b[12] = 0xff;
|
||||
b[13] = 0xff;
|
||||
b[14] = 0;
|
||||
b[15] = 0;
|
||||
p.payload_size = 16;
|
||||
int8_t i, j;
|
||||
uint8_t k, l;
|
||||
uint8_t t[5];
|
||||
t[0] = 0;
|
||||
object->get_phy_params().datarates.size = 1;
|
||||
object->get_phy_params().datarates.table = t;
|
||||
//Test without ADR payload does not make sense here.
|
||||
|
||||
object->get_phy_params().max_channel_cnt = 2;
|
||||
channel_params_t li[4];
|
||||
object->get_phy_params().channels.channel_list = li;
|
||||
li[0].frequency = 0;
|
||||
li[1].frequency = 5;
|
||||
EXPECT_TRUE(4 == object->link_ADR_request(&p, &i, &j, &k, &l));
|
||||
|
||||
t[0] = 3;
|
||||
//verify adr with p.adr_enabled = false
|
||||
EXPECT_TRUE(0 == object->link_ADR_request(&p, &i, &j, &k, &l));
|
||||
|
||||
p.current_nb_rep = 0;
|
||||
EXPECT_TRUE(0 == object->link_ADR_request(&p, &i, &j, &k, &l));
|
||||
|
||||
p.adr_enabled = true;
|
||||
li[0].dr_range.value = 0xff;
|
||||
object->get_phy_params().min_tx_datarate = DR_3;
|
||||
object->get_phy_params().max_tx_datarate = DR_8;
|
||||
|
||||
//verify adr with status != 0
|
||||
EXPECT_TRUE(0 == object->link_ADR_request(&p, &i, &j, &k, &l));
|
||||
|
||||
object->get_phy_params().max_tx_power = 2;
|
||||
object->get_phy_params().min_tx_power = 6;
|
||||
//verify adr with status != 0
|
||||
EXPECT_TRUE(4 == object->link_ADR_request(&p, &i, &j, &k, &l));
|
||||
|
||||
object->get_phy_params().min_tx_datarate = DR_0;
|
||||
li[0].dr_range.value = 0xf0;
|
||||
EXPECT_TRUE(6 == object->link_ADR_request(&p, &i, &j, &k, &l));
|
||||
|
||||
li[1].dr_range.fields.min = DR_0;
|
||||
li[1].dr_range.fields.max = DR_13;
|
||||
b[4] = 6 << 4;
|
||||
p.payload_size = 5;
|
||||
EXPECT_TRUE(7 == object->link_ADR_request(&p, &i, &j, &k, &l));
|
||||
|
||||
uint16_t mask[2];
|
||||
object->get_phy_params().channels.mask = mask;
|
||||
object->get_phy_params().channels.mask_size = 2;
|
||||
EXPECT_TRUE(7 == object->link_ADR_request(&p, &i, &j, &k, &l));
|
||||
|
||||
li[0].dr_range.value = 0xff;
|
||||
object->get_phy_params().max_channel_cnt = 0;
|
||||
EXPECT_TRUE(5 == object->link_ADR_request(&p, &i, &j, &k, &l));
|
||||
|
||||
b[0] = 0x03;
|
||||
b[1] = 1;
|
||||
b[2] = 0;
|
||||
b[3] = 0;
|
||||
b[4] = 0;
|
||||
t[0] = 0;
|
||||
object->get_phy_params().datarates.size = 1;
|
||||
object->get_phy_params().datarates.table = t;
|
||||
//Test without ADR payload does not make sense here.
|
||||
|
||||
object->get_phy_params().max_channel_cnt = 2;
|
||||
li[0].frequency = 0;
|
||||
li[1].frequency = 5;
|
||||
EXPECT_TRUE(4 == object->link_ADR_request(&p, &i, &j, &k, &l));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, accept_rx_param_setup_req)
|
||||
{
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
rx_param_setup_req_t req;
|
||||
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&req));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, accept_tx_param_setup_req)
|
||||
{
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
object->get_phy_params().accept_tx_param_setup_req = true;
|
||||
EXPECT_TRUE(object->accept_tx_param_setup_req(0, 0));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, dl_channel_request)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->dl_channel_request(0, 0));
|
||||
|
||||
object->get_phy_params().dl_channel_req_supported = true;
|
||||
object->get_phy_params().bands.size = 1;
|
||||
band_t t[1];
|
||||
object->get_phy_params().bands.table = t;
|
||||
channel_params_t p[4];
|
||||
object->get_phy_params().channels.channel_list = p;
|
||||
|
||||
p[0].frequency = 0;
|
||||
EXPECT_TRUE(0 == object->dl_channel_request(0, 1));
|
||||
|
||||
t[0].higher_band_freq = 19;
|
||||
t[0].lower_band_freq = 0;
|
||||
p[0].frequency = 1;
|
||||
EXPECT_TRUE(3 == object->dl_channel_request(0, 1));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_alternate_DR)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_alternate_DR(0));
|
||||
|
||||
object->get_phy_params().default_max_datarate = 5;
|
||||
object->get_phy_params().min_tx_datarate = 4;
|
||||
EXPECT_TRUE(5 == object->get_alternate_DR(1));
|
||||
|
||||
object->get_phy_params().default_max_datarate = 6;
|
||||
object->get_phy_params().min_tx_datarate = 4;
|
||||
EXPECT_TRUE(5 == object->get_alternate_DR(2));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, set_next_channel)
|
||||
{
|
||||
channel_selection_params_t p;
|
||||
uint8_t ch;
|
||||
lorawan_time_t t1;
|
||||
lorawan_time_t t2;
|
||||
p.aggregate_timeoff = 10000;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&p, &ch, &t1, &t2));
|
||||
|
||||
uint16_t list[16];
|
||||
list[4] = 1;
|
||||
memcpy(list, "\0", 16);
|
||||
object->get_phy_params().channels.mask = list;
|
||||
object->get_phy_params().channels.mask_size = 1;
|
||||
p.aggregate_timeoff = 10000;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&p, &ch, &t1, &t2));
|
||||
|
||||
LoRaWANTimer_stub::time_value = 20000;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&p, &ch, &t1, &t2));
|
||||
|
||||
p.joined = false;
|
||||
p.dc_enabled = false;
|
||||
band_t b[4];
|
||||
object->get_phy_params().bands.size = 2;
|
||||
object->get_phy_params().bands.table = &b;
|
||||
b[0].off_time = 0;
|
||||
b[1].off_time = 9999999;
|
||||
list[4] = 0;
|
||||
object->get_phy_params().channels.mask_size = 128;
|
||||
p.current_datarate = DR_1;
|
||||
object->get_phy_params().max_channel_cnt = 4;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&p, &ch, &t1, &t2));
|
||||
|
||||
p.dc_enabled = true;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&p, &ch, &t1, &t2));
|
||||
|
||||
list[4] = 1;
|
||||
p.joined = true;
|
||||
p.dc_enabled = false;
|
||||
channel_params_t l[4];
|
||||
l[0].dr_range.value = 0xff;
|
||||
l[1].dr_range.value = 0xff;
|
||||
l[2].dr_range.value = 0xf0;
|
||||
l[3].dr_range.value = 0xf0;
|
||||
l[2].band = 2;
|
||||
l[3].band = 3;
|
||||
object->get_phy_params().channels.channel_list = l;
|
||||
list[0] = 0xFF;
|
||||
b[2].off_time = 9999999;
|
||||
b[3].off_time = 0;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&p, &ch, &t1, &t2));
|
||||
|
||||
b[0].off_time = 10000;
|
||||
LoRaWANTimer_stub::time_value = 2000;
|
||||
p.aggregate_timeoff = 1000;
|
||||
p.dc_enabled = true;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&p, &ch, &t1, &t2));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, add_channel)
|
||||
{
|
||||
uint16_t list[16];
|
||||
object->get_phy_params().channels.mask = list;
|
||||
object->get_phy_params().channels.default_mask = list;
|
||||
channel_params_t p;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->add_channel(&p, 0));
|
||||
|
||||
object->get_phy_params().custom_channelplans_supported = true;
|
||||
object->get_phy_params().max_channel_cnt = 2;
|
||||
object->get_phy_params().min_tx_datarate = 0;
|
||||
object->get_phy_params().max_tx_datarate = 13;
|
||||
p.dr_range.fields.min = 6;
|
||||
p.dr_range.fields.max = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_FREQ_AND_DR_INVALID == object->add_channel(&p, 0));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, remove_channel)
|
||||
{
|
||||
channel_params_t pp;
|
||||
pp.band=0;
|
||||
object->get_phy_params().channels.channel_list = &pp;
|
||||
uint16_t list[16];
|
||||
list[0] = 1;
|
||||
object->get_phy_params().channels.mask = list;
|
||||
object->get_phy_params().channels.default_mask = list;
|
||||
EXPECT_TRUE(false == object->remove_channel(0));
|
||||
|
||||
list[0] = 0;
|
||||
EXPECT_TRUE(false == object->remove_channel(0));
|
||||
|
||||
object->get_phy_params().channels.mask_size = 1;
|
||||
object->get_phy_params().max_channel_cnt = 0;
|
||||
EXPECT_TRUE(false == object->remove_channel(0));
|
||||
|
||||
object->get_phy_params().max_channel_cnt = 1;
|
||||
EXPECT_TRUE(true == object->remove_channel(0));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, set_tx_cont_mode)
|
||||
{
|
||||
channel_params_t pp;
|
||||
pp.band=0;
|
||||
object->get_phy_params().channels.channel_list = &pp;
|
||||
band_t b;
|
||||
object->get_phy_params().bands.table = &b;
|
||||
my_radio radio;
|
||||
object->set_radio_instance(radio);
|
||||
|
||||
cw_mode_params_t p;
|
||||
p.max_eirp = 0;
|
||||
p.channel=0;
|
||||
object->set_tx_cont_mode(&p);
|
||||
|
||||
p.max_eirp = 1;
|
||||
p.antenna_gain = 1;
|
||||
object->set_tx_cont_mode(&p, 1);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, apply_DR_offset)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->apply_DR_offset(0, 0));
|
||||
|
||||
object->get_phy_params().min_tx_datarate = 1;
|
||||
EXPECT_TRUE(1 == object->apply_DR_offset(0, 2));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, reset_to_default_values)
|
||||
{
|
||||
loramac_protocol_params p;
|
||||
object->reset_to_default_values(&p);
|
||||
|
||||
object->reset_to_default_values(&p, true);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_next_lower_tx_datarate)
|
||||
{
|
||||
EXPECT_TRUE(DR_0 == object->get_next_lower_tx_datarate(DR_2));
|
||||
|
||||
object->get_phy_params().ul_dwell_time_setting = 1;
|
||||
object->get_phy_params().dwell_limit_datarate = DR_1;
|
||||
EXPECT_TRUE(DR_1 == object->get_next_lower_tx_datarate(DR_2));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_minimum_rx_datarate)
|
||||
{
|
||||
EXPECT_TRUE(DR_0 == object->get_minimum_rx_datarate());
|
||||
|
||||
object->get_phy_params().dl_dwell_time_setting = 1;
|
||||
object->get_phy_params().dwell_limit_datarate = DR_1;
|
||||
EXPECT_TRUE(DR_1 == object->get_minimum_rx_datarate());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_minimum_tx_datarate)
|
||||
{
|
||||
EXPECT_TRUE(DR_0 == object->get_minimum_tx_datarate());
|
||||
|
||||
object->get_phy_params().ul_dwell_time_setting = 1;
|
||||
object->get_phy_params().dwell_limit_datarate = DR_1;
|
||||
EXPECT_TRUE(DR_1 == object->get_minimum_tx_datarate());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_default_tx_datarate)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_default_tx_datarate());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_default_max_tx_datarate)
|
||||
{
|
||||
EXPECT_TRUE(DR_0 == object->get_default_max_tx_datarate());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_default_tx_power)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_default_tx_power());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_max_payload)
|
||||
{
|
||||
uint8_t list=8;
|
||||
object->get_phy_params().payloads.table = &list;
|
||||
object->get_phy_params().payloads_with_repeater.table = &list;
|
||||
EXPECT_TRUE(8 == object->get_max_payload(0));
|
||||
|
||||
EXPECT_TRUE(8 == object->get_max_payload(0, true));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_maximum_frame_counter_gap)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_maximum_frame_counter_gap());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_ack_timeout)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_ack_timeout());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_default_rx2_frequency)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_default_rx2_frequency());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_default_rx2_datarate)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_default_rx2_datarate());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_channel_mask)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_channel_mask());
|
||||
EXPECT_TRUE(0 == object->get_channel_mask(true));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_max_nb_channels)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_max_nb_channels());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, get_phy_channels)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_phy_channels());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, is_custom_channel_plan_supported)
|
||||
{
|
||||
EXPECT_TRUE(false == object->is_custom_channel_plan_supported());
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, verify_rx_datarate)
|
||||
{
|
||||
EXPECT_TRUE(false == object->verify_rx_datarate(0));
|
||||
|
||||
object->get_phy_params().datarates.size = 1;
|
||||
uint8_t t[1];
|
||||
t[0] = 2;
|
||||
object->get_phy_params().datarates.table = t;
|
||||
object->get_phy_params().dl_dwell_time_setting = 0;
|
||||
|
||||
EXPECT_TRUE(true == object->verify_rx_datarate(0));
|
||||
|
||||
object->get_phy_params().dl_dwell_time_setting = 1;
|
||||
object->get_phy_params().min_rx_datarate = 0;
|
||||
|
||||
EXPECT_TRUE(true == object->verify_rx_datarate(0));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, verify_tx_datarate)
|
||||
{
|
||||
EXPECT_TRUE(false == object->verify_tx_datarate(0));
|
||||
|
||||
object->get_phy_params().datarates.size = 1;
|
||||
uint8_t t[1];
|
||||
t[0] = 2;
|
||||
object->get_phy_params().datarates.table = t;
|
||||
object->get_phy_params().ul_dwell_time_setting = 0;
|
||||
EXPECT_TRUE(true == object->verify_tx_datarate(0));
|
||||
|
||||
object->get_phy_params().ul_dwell_time_setting = 1;
|
||||
EXPECT_TRUE(true == object->verify_tx_datarate(0));
|
||||
|
||||
object->get_phy_params().ul_dwell_time_setting = 1;
|
||||
EXPECT_TRUE(true == object->verify_tx_datarate(0, true));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, verify_tx_power)
|
||||
{
|
||||
EXPECT_TRUE(true == object->verify_tx_power(0));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, verify_duty_cycle)
|
||||
{
|
||||
EXPECT_TRUE(true == object->verify_duty_cycle(false));
|
||||
|
||||
EXPECT_TRUE(false == object->verify_duty_cycle(true));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHY, verify_nb_join_trials)
|
||||
{
|
||||
EXPECT_TRUE(false == object->verify_nb_join_trials(0));
|
||||
EXPECT_TRUE(true == object->verify_nb_join_trials(100));
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#[[
|
||||
* 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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaPHY")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/phy/LoRaPHY.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loraphy/Test_LoRaPHY.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
)
|
||||
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 -DMBED_CONF_LORA_DUTY_CYCLE_ON_JOIN=true")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH=8 -DMBED_CONF_LORA_DUTY_CYCLE_ON_JOIN=true")
|
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "LoRaPHYAS923.h"
|
||||
|
||||
#include "LoRaPHY_stub.h"
|
||||
|
||||
class my_radio : public LoRaRadio
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void init_radio(radio_events_t *events){};
|
||||
|
||||
virtual void radio_reset(){};
|
||||
|
||||
virtual void sleep(void){};
|
||||
|
||||
virtual void standby(void){};
|
||||
|
||||
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
|
||||
uint32_t datarate, uint8_t coderate,
|
||||
uint32_t bandwidth_afc, uint16_t preamble_len,
|
||||
uint16_t symb_timeout, bool fix_len,
|
||||
uint8_t payload_len,
|
||||
bool crc_on, bool freq_hop_on, uint8_t hop_period,
|
||||
bool iq_inverted, bool rx_continuous){};
|
||||
|
||||
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
|
||||
uint32_t bandwidth, uint32_t datarate,
|
||||
uint8_t coderate, uint16_t preamble_len,
|
||||
bool fix_len, bool crc_on, bool freq_hop_on,
|
||||
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
|
||||
|
||||
virtual void send(uint8_t *buffer, uint8_t size){};
|
||||
|
||||
virtual void receive(void){};
|
||||
|
||||
virtual void set_channel(uint32_t freq){};
|
||||
|
||||
virtual uint32_t random(void){};
|
||||
|
||||
virtual uint8_t get_status(void){return uint8_value;};
|
||||
|
||||
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
|
||||
|
||||
virtual void set_public_network(bool enable){};
|
||||
|
||||
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
|
||||
|
||||
virtual bool perform_carrier_sense(radio_modems_t modem,
|
||||
uint32_t freq,
|
||||
int16_t rssi_threshold,
|
||||
uint32_t max_carrier_sense_time){ return bool_value;};
|
||||
|
||||
virtual void start_cad(void){};
|
||||
|
||||
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
|
||||
|
||||
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
|
||||
|
||||
virtual void lock(void){};
|
||||
|
||||
virtual void unlock(void){};
|
||||
|
||||
bool bool_value;
|
||||
uint8_t uint8_value;
|
||||
};
|
||||
|
||||
class Test_LoRaPHYAS923 : public testing::Test {
|
||||
protected:
|
||||
LoRaPHYAS923 *object;
|
||||
my_radio radio;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
LoRaPHY_stub::radio = &radio;
|
||||
object = new LoRaPHYAS923();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
LoRaPHY_stub::radio = NULL;
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Test_LoRaPHYAS923, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYAS923, get_alternate_DR)
|
||||
{
|
||||
EXPECT_TRUE(2 == object->get_alternate_DR(1));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYAS923, set_next_channel)
|
||||
{
|
||||
channel_selection_params_t next_channel;
|
||||
lorawan_time_t backoff_time = 0;
|
||||
lorawan_time_t time = 0;
|
||||
uint8_t ch = 1;
|
||||
|
||||
next_channel.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 0;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
|
||||
|
||||
next_channel.aggregate_timeoff = 1;
|
||||
radio.bool_value = false;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
|
||||
|
||||
next_channel.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
|
||||
|
||||
radio.bool_value = true;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYAS923, apply_DR_offset)
|
||||
{
|
||||
//0, 1, 2, 3, 4, 5, -1, -2
|
||||
for (int i=0; i < 8; i++) {
|
||||
uint8_t val = i>5?5:2;
|
||||
EXPECT_TRUE(object->apply_DR_offset(0, i));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Arm Limited and affiliates.
|
||||
#[[
|
||||
* Copyright (c) 2018, Arm Limited and affiliates
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -13,24 +13,28 @@
|
|||
* 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_AT_CELLULARINFORMATION_H
|
||||
#define TEST_AT_CELLULARINFORMATION_H
|
||||
]]
|
||||
|
||||
class Test_AT_CellularInformation {
|
||||
public:
|
||||
Test_AT_CellularInformation();
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaPHYAS923")
|
||||
|
||||
virtual ~Test_AT_CellularInformation();
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/phy/LoRaPHYAS923.cpp
|
||||
)
|
||||
|
||||
void test_AT_CellularInformation_get_manufacturer();
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
void test_AT_CellularInformation_get_model();
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loraphyas923/Test_LoRaPHYAS923.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
|
||||
void test_AT_CellularInformation_get_revision();
|
||||
|
||||
void test_AT_CellularInformation_get_serial_number();
|
||||
};
|
||||
|
||||
#endif // TEST_AT_CELLULARINFORMATION_H
|
||||
)
|
||||
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "LoRaPHYAU915.h"
|
||||
|
||||
#include "LoRaPHY_stub.h"
|
||||
|
||||
class my_radio : public LoRaRadio
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void init_radio(radio_events_t *events){};
|
||||
|
||||
virtual void radio_reset(){};
|
||||
|
||||
virtual void sleep(void){};
|
||||
|
||||
virtual void standby(void){};
|
||||
|
||||
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
|
||||
uint32_t datarate, uint8_t coderate,
|
||||
uint32_t bandwidth_afc, uint16_t preamble_len,
|
||||
uint16_t symb_timeout, bool fix_len,
|
||||
uint8_t payload_len,
|
||||
bool crc_on, bool freq_hop_on, uint8_t hop_period,
|
||||
bool iq_inverted, bool rx_continuous){};
|
||||
|
||||
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
|
||||
uint32_t bandwidth, uint32_t datarate,
|
||||
uint8_t coderate, uint16_t preamble_len,
|
||||
bool fix_len, bool crc_on, bool freq_hop_on,
|
||||
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
|
||||
|
||||
virtual void send(uint8_t *buffer, uint8_t size){};
|
||||
|
||||
virtual void receive(void){};
|
||||
|
||||
virtual void set_channel(uint32_t freq){};
|
||||
|
||||
virtual uint32_t random(void){};
|
||||
|
||||
virtual uint8_t get_status(void){return uint8_value;};
|
||||
|
||||
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
|
||||
|
||||
virtual void set_public_network(bool enable){};
|
||||
|
||||
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
|
||||
|
||||
virtual bool perform_carrier_sense(radio_modems_t modem,
|
||||
uint32_t freq,
|
||||
int16_t rssi_threshold,
|
||||
uint32_t max_carrier_sense_time){ return bool_value;};
|
||||
|
||||
virtual void start_cad(void){};
|
||||
|
||||
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
|
||||
|
||||
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
|
||||
|
||||
virtual void lock(void){};
|
||||
|
||||
virtual void unlock(void){};
|
||||
|
||||
bool bool_value;
|
||||
uint8_t uint8_value;
|
||||
};
|
||||
|
||||
class Test_LoRaPHYAU915 : public testing::Test {
|
||||
protected:
|
||||
LoRaPHYAU915 *object;
|
||||
my_radio radio;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
LoRaPHY_stub::radio = &radio;
|
||||
object = new LoRaPHYAU915();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
LoRaPHY_stub::radio = NULL;
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Test_LoRaPHYAU915, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYAU915, rx_config)
|
||||
{
|
||||
rx_config_params_t p;
|
||||
|
||||
radio.uint8_value = 1;
|
||||
EXPECT_TRUE(!object->rx_config(&p));
|
||||
|
||||
radio.uint8_value = 0;
|
||||
p.is_repeater_supported = true;
|
||||
EXPECT_TRUE(object->rx_config(&p));
|
||||
|
||||
p.is_repeater_supported = false;
|
||||
EXPECT_TRUE(object->rx_config(&p));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYAU915, tx_config)
|
||||
{
|
||||
tx_config_params_t p;
|
||||
int8_t tx;
|
||||
lorawan_time_t time;
|
||||
p.tx_power = 9;
|
||||
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYAU915, link_ADR_request)
|
||||
{
|
||||
adr_req_params_t params;
|
||||
int8_t dr_out;
|
||||
int8_t tx_power_out;
|
||||
uint8_t nb_rep_out;
|
||||
uint8_t nb_bytes_parsed;
|
||||
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
LoRaPHY_stub::ch_mask_value = 6;
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
|
||||
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
LoRaPHY_stub::ch_mask_value = 7;
|
||||
EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
|
||||
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
LoRaPHY_stub::ch_mask_value = 5;
|
||||
LoRaPHY_stub::uint8_value = 6;
|
||||
EXPECT_TRUE(6 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
|
||||
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
LoRaPHY_stub::ch_mask_value = 66;
|
||||
LoRaPHY_stub::uint8_value = 7;
|
||||
EXPECT_TRUE(7 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYAU915, accept_rx_param_setup_req)
|
||||
{
|
||||
rx_param_setup_req_t p;
|
||||
radio.bool_value = false;
|
||||
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
|
||||
|
||||
radio.bool_value = true;
|
||||
p.frequency = 923300000 - 1;
|
||||
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
|
||||
|
||||
radio.bool_value = true;
|
||||
p.frequency = 927500000 + 1;
|
||||
p.datarate = 6;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
EXPECT_TRUE(2 == object->accept_rx_param_setup_req(&p));
|
||||
|
||||
radio.bool_value = true;
|
||||
p.frequency = 923300000 + 600000;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
LoRaPHY_stub::bool_table[1] = true;
|
||||
EXPECT_TRUE(7 == object->accept_rx_param_setup_req(&p));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYAU915, get_alternate_DR)
|
||||
{
|
||||
EXPECT_TRUE(0 == object->get_alternate_DR(0));
|
||||
|
||||
EXPECT_TRUE(6 == object->get_alternate_DR(1));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYAU915, set_next_channel)
|
||||
{
|
||||
channel_selection_params_t params;
|
||||
uint8_t channel;
|
||||
lorawan_time_t time;
|
||||
lorawan_time_t timeoff;
|
||||
|
||||
params.current_datarate = 6;
|
||||
params.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 0;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
|
||||
radio.bool_value = false;
|
||||
params.aggregate_timeoff = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
|
||||
params.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYAU915, apply_DR_offset)
|
||||
{
|
||||
// { DR_8, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_0
|
||||
// { DR_9, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_1
|
||||
// { DR_10, DR_9, DR_8, DR_8, DR_8, DR_8 }, // DR_2
|
||||
// { DR_11, DR_10, DR_9, DR_8, DR_8, DR_8 }, // DR_3
|
||||
// { DR_12, DR_11, DR_10, DR_9, DR_8, DR_8 }, // DR_4
|
||||
// { DR_13, DR_12, DR_11, DR_10, DR_9, DR_8 }, // DR_5
|
||||
// { DR_13, DR_13, DR_12, DR_11, DR_10, DR_9 }, // DR_6
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int j=0; j < 6; j++ ) {
|
||||
uint8_t val = 8 + i;
|
||||
val -= j;
|
||||
if (val > 13) val = 13;
|
||||
if (val < 8) val = 8;
|
||||
EXPECT_TRUE(val == object->apply_DR_offset(i, j));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
#[[
|
||||
* 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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaPHYAU915")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/phy/LoRaPHYAU915.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loraphyau915/Test_LoRaPHYAU915.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
|
||||
)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_FSB_MASK=\"{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}\"")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_FSB_MASK=\"{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}\"")
|
||||
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "LoRaPHYCN470.h"
|
||||
|
||||
#include "LoRaPHY_stub.h"
|
||||
|
||||
class my_radio : public LoRaRadio
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void init_radio(radio_events_t *events){};
|
||||
|
||||
virtual void radio_reset(){};
|
||||
|
||||
virtual void sleep(void){};
|
||||
|
||||
virtual void standby(void){};
|
||||
|
||||
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
|
||||
uint32_t datarate, uint8_t coderate,
|
||||
uint32_t bandwidth_afc, uint16_t preamble_len,
|
||||
uint16_t symb_timeout, bool fix_len,
|
||||
uint8_t payload_len,
|
||||
bool crc_on, bool freq_hop_on, uint8_t hop_period,
|
||||
bool iq_inverted, bool rx_continuous){};
|
||||
|
||||
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
|
||||
uint32_t bandwidth, uint32_t datarate,
|
||||
uint8_t coderate, uint16_t preamble_len,
|
||||
bool fix_len, bool crc_on, bool freq_hop_on,
|
||||
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
|
||||
|
||||
virtual void send(uint8_t *buffer, uint8_t size){};
|
||||
|
||||
virtual void receive(void){};
|
||||
|
||||
virtual void set_channel(uint32_t freq){};
|
||||
|
||||
virtual uint32_t random(void){};
|
||||
|
||||
virtual uint8_t get_status(void){return uint8_value;};
|
||||
|
||||
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
|
||||
|
||||
virtual void set_public_network(bool enable){};
|
||||
|
||||
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
|
||||
|
||||
virtual bool perform_carrier_sense(radio_modems_t modem,
|
||||
uint32_t freq,
|
||||
int16_t rssi_threshold,
|
||||
uint32_t max_carrier_sense_time){ return bool_value;};
|
||||
|
||||
virtual void start_cad(void){};
|
||||
|
||||
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
|
||||
|
||||
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
|
||||
|
||||
virtual void lock(void){};
|
||||
|
||||
virtual void unlock(void){};
|
||||
|
||||
bool bool_value;
|
||||
uint8_t uint8_value;
|
||||
};
|
||||
|
||||
class Test_LoRaPHYCN470 : public testing::Test {
|
||||
protected:
|
||||
LoRaPHYCN470 *object;
|
||||
my_radio radio;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
|
||||
LoRaPHY_stub::radio = &radio;
|
||||
object = new LoRaPHYCN470();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
|
||||
LoRaPHY_stub::radio = NULL;
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Test_LoRaPHYCN470, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYCN470, set_next_channel)
|
||||
{
|
||||
channel_selection_params_t params;
|
||||
uint8_t channel;
|
||||
lorawan_time_t time;
|
||||
lorawan_time_t timeoff;
|
||||
|
||||
params.current_datarate = 4;
|
||||
params.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 0;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
|
||||
radio.bool_value = false;
|
||||
params.aggregate_timeoff = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
|
||||
params.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(¶ms, &channel, &time, &timeoff));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYCN470, rx_config)
|
||||
{
|
||||
rx_config_params_t p;
|
||||
|
||||
radio.uint8_value = 1;
|
||||
EXPECT_TRUE(!object->rx_config(&p));
|
||||
|
||||
radio.uint8_value = 0;
|
||||
p.is_repeater_supported = true;
|
||||
EXPECT_TRUE(object->rx_config(&p));
|
||||
|
||||
p.is_repeater_supported = false;
|
||||
EXPECT_TRUE(object->rx_config(&p));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYCN470, tx_config)
|
||||
{
|
||||
tx_config_params_t p;
|
||||
int8_t tx;
|
||||
lorawan_time_t time;
|
||||
p.tx_power = 9;
|
||||
EXPECT_TRUE(object->tx_config(&p, &tx, &time));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYCN470, link_ADR_request)
|
||||
{
|
||||
adr_req_params_t params;
|
||||
int8_t dr_out;
|
||||
int8_t tx_power_out;
|
||||
uint8_t nb_rep_out;
|
||||
uint8_t nb_bytes_parsed;
|
||||
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
LoRaPHY_stub::ch_mask_value = 6;
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
|
||||
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
LoRaPHY_stub::ch_mask_value = 7;
|
||||
EXPECT_TRUE(1 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
|
||||
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
LoRaPHY_stub::ch_mask_value = 5;
|
||||
LoRaPHY_stub::uint8_value = 6;
|
||||
EXPECT_TRUE(6 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
|
||||
|
||||
LoRaPHY_stub::adr_parse_count = 2;
|
||||
LoRaPHY_stub::ch_mask_value = 66;
|
||||
LoRaPHY_stub::uint8_value = 7;
|
||||
EXPECT_TRUE(7 == object->link_ADR_request(¶ms, &dr_out, &tx_power_out, &nb_rep_out, &nb_bytes_parsed));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYCN470, accept_rx_param_setup_req)
|
||||
{
|
||||
rx_param_setup_req_t p;
|
||||
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
|
||||
|
||||
radio.bool_value = true;
|
||||
p.frequency = 923300000 - 1;
|
||||
EXPECT_TRUE(0 == object->accept_rx_param_setup_req(&p));
|
||||
|
||||
radio.bool_value = true;
|
||||
p.frequency = 927500000 + 1;
|
||||
p.datarate = 6;
|
||||
LoRaPHY_stub::bool_counter = 0;
|
||||
LoRaPHY_stub::bool_table[0] = true;
|
||||
EXPECT_TRUE(2 == object->accept_rx_param_setup_req(&p));
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#[[
|
||||
* 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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaPHYCN470")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/phy/LoRaPHYCN470.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loraphycn470/Test_LoRaPHYCN470.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/LoRaWANTimer_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
|
||||
)
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Arm Limited and affiliates.
|
||||
* Copyright (c) 2018, Arm Limited and affiliates
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -14,24 +14,27 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef TEST_UTIL_H
|
||||
#define TEST_UTIL_H
|
||||
|
||||
class Test_util {
|
||||
public:
|
||||
Test_util();
|
||||
#include "gtest/gtest.h"
|
||||
#include "LoRaPHYCN779.h"
|
||||
|
||||
virtual ~Test_util();
|
||||
class Test_LoRaPHYCN779 : public testing::Test {
|
||||
protected:
|
||||
LoRaPHYCN779 *object;
|
||||
|
||||
void test_util_uint_to_binary_string();
|
||||
virtual void SetUp()
|
||||
{
|
||||
object = new LoRaPHYCN779();
|
||||
}
|
||||
|
||||
void test_util_char_str_to_hex();
|
||||
|
||||
void test_util_convert_ipv6();
|
||||
|
||||
void test_util_prefer_ipv6();
|
||||
|
||||
void test_util_separate_ip_addresses();
|
||||
virtual void TearDown()
|
||||
{
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TEST_UTIL_H
|
||||
TEST_F(Test_LoRaPHYCN779, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#[[
|
||||
* 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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaPHYCN779")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/phy/LoRaPHYCN779.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loraphycn779/Test_LoRaPHYCN779.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
|
||||
)
|
||||
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_FSB_MASK_CHINA=\"{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}\"")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_FSB_MASK_CHINA=\"{0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00FF}\"")
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Arm Limited and affiliates.
|
||||
* Copyright (c) 2018, Arm Limited and affiliates
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -14,25 +14,27 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef TEST_UTIL_H
|
||||
#define TEST_UTIL_H
|
||||
|
||||
class Test_util {
|
||||
public:
|
||||
Test_util();
|
||||
#include "gtest/gtest.h"
|
||||
#include "LoRaPHYEU433.h"
|
||||
|
||||
virtual ~Test_util();
|
||||
class Test_LoRaPHYEU433 : public testing::Test {
|
||||
protected:
|
||||
LoRaPHYEU433 *object;
|
||||
|
||||
void test_util_uint_to_binary_string();
|
||||
virtual void SetUp()
|
||||
{
|
||||
object = new LoRaPHYEU433();
|
||||
}
|
||||
|
||||
void test_util_char_str_to_hex();
|
||||
|
||||
void test_util_convert_ipv6();
|
||||
|
||||
void test_util_prefer_ipv6();
|
||||
|
||||
void test_util_separate_ip_addresses();
|
||||
virtual void TearDown()
|
||||
{
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TEST_UTIL_H
|
||||
TEST_F(Test_LoRaPHYEU433, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Arm Limited and affiliates.
|
||||
#[[
|
||||
* Copyright (c) 2018, Arm Limited and affiliates
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -13,24 +13,27 @@
|
|||
* 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_AT_CELLULARBASE_H
|
||||
#define TEST_AT_CELLULARBASE_H
|
||||
]]
|
||||
|
||||
class Test_AT_CellularBase {
|
||||
public:
|
||||
Test_AT_CellularBase();
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaPHYEU433")
|
||||
|
||||
virtual ~Test_AT_CellularBase();
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/phy/LoRaPHYEU433.cpp
|
||||
)
|
||||
|
||||
void test_AT_CellularBase_get_at_handler();
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
void test_AT_CellularBase_get_device_error();
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loraphyeu433/Test_LoRaPHYEU433.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
|
||||
void test_AT_CellularBase_set_unsupported_features();
|
||||
|
||||
void test_AT_CellularBase_is_supported();
|
||||
};
|
||||
|
||||
#endif // TEST_AT_CELLULARBASE_H
|
||||
)
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Arm Limited and affiliates.
|
||||
* Copyright (c) 2018, Arm Limited and affiliates
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -14,18 +14,27 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef TEST_AT_CELLULARBASE_H
|
||||
#define TEST_AT_CELLULARBASE_H
|
||||
|
||||
class Test_AT_CellularBase {
|
||||
public:
|
||||
Test_AT_CellularBase();
|
||||
#include "gtest/gtest.h"
|
||||
#include "LoRaPHYEU868.h"
|
||||
|
||||
virtual ~Test_AT_CellularBase();
|
||||
class Test_LoRaPHYEU868 : public testing::Test {
|
||||
protected:
|
||||
LoRaPHYEU868 *object;
|
||||
|
||||
void test_AT_CellularBase_get_at_handler();
|
||||
virtual void SetUp()
|
||||
{
|
||||
object = new LoRaPHYEU868();
|
||||
}
|
||||
|
||||
void test_AT_CellularBase_get_device_error();
|
||||
virtual void TearDown()
|
||||
{
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TEST_AT_CELLULARBASE_H
|
||||
TEST_F(Test_LoRaPHYEU868, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#[[
|
||||
* 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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaPHYEU868")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/phy/LoRaPHYEU868.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loraphyeu868/Test_LoRaPHYEU868.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
|
||||
)
|
||||
|
|
@ -14,36 +14,34 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "gtest/gtest.h"
|
||||
#include "test_at_cellularbase.h"
|
||||
#include "AT_CellularBase.h"
|
||||
|
||||
class TestAT_CellularBase : public testing::Test {
|
||||
#include "gtest/gtest.h"
|
||||
#include "LoRaPHYIN865.h"
|
||||
|
||||
class Test_LoRaPHYIN865 : public testing::Test {
|
||||
protected:
|
||||
Test_AT_CellularBase *unit;
|
||||
LoRaPHYIN865 *object;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
unit = new Test_AT_CellularBase();
|
||||
object = new LoRaPHYIN865();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
delete unit;
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TestAT_CellularBase, Create)
|
||||
TEST_F(Test_LoRaPHYIN865, constructor)
|
||||
{
|
||||
EXPECT_TRUE(unit);
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_at_handler)
|
||||
TEST_F(Test_LoRaPHYIN865, apply_DR_offset)
|
||||
{
|
||||
unit->test_AT_CellularBase_get_at_handler();
|
||||
EXPECT_TRUE(0 == object->apply_DR_offset(0, 0));
|
||||
}
|
||||
|
||||
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_device_error)
|
||||
{
|
||||
unit->test_AT_CellularBase_get_device_error();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#[[
|
||||
* 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.
|
||||
]]
|
||||
|
||||
# Unit test suite name
|
||||
set(TEST_SUITE_NAME "lorawan_LoRaPHYIN865")
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../features/lorawan/lorastack/phy/LoRaPHYIN865.cpp
|
||||
)
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
target_h
|
||||
../features/lorawan/lorastack/phy
|
||||
)
|
||||
|
||||
# Test & stub files
|
||||
set(unittest-test-sources
|
||||
features/lorawan/loraphyin865/Test_LoRaPHYIN865.cpp
|
||||
stubs/LoRaPHY_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
|
||||
)
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "LoRaPHYKR920.h"
|
||||
#include "LoRaPHY_stub.h"
|
||||
#include "LoRaRadio.h"
|
||||
|
||||
class my_radio : public LoRaRadio
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void init_radio(radio_events_t *events){};
|
||||
|
||||
virtual void radio_reset(){};
|
||||
|
||||
virtual void sleep(void){};
|
||||
|
||||
virtual void standby(void){};
|
||||
|
||||
virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
|
||||
uint32_t datarate, uint8_t coderate,
|
||||
uint32_t bandwidth_afc, uint16_t preamble_len,
|
||||
uint16_t symb_timeout, bool fix_len,
|
||||
uint8_t payload_len,
|
||||
bool crc_on, bool freq_hop_on, uint8_t hop_period,
|
||||
bool iq_inverted, bool rx_continuous){};
|
||||
|
||||
virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
|
||||
uint32_t bandwidth, uint32_t datarate,
|
||||
uint8_t coderate, uint16_t preamble_len,
|
||||
bool fix_len, bool crc_on, bool freq_hop_on,
|
||||
uint8_t hop_period, bool iq_inverted, uint32_t timeout){};
|
||||
|
||||
virtual void send(uint8_t *buffer, uint8_t size){};
|
||||
|
||||
virtual void receive(void){};
|
||||
|
||||
virtual void set_channel(uint32_t freq){};
|
||||
|
||||
virtual uint32_t random(void){};
|
||||
|
||||
virtual uint8_t get_status(void){};
|
||||
|
||||
virtual void set_max_payload_length(radio_modems_t modem, uint8_t max){};
|
||||
|
||||
virtual void set_public_network(bool enable){};
|
||||
|
||||
virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len){};
|
||||
|
||||
virtual bool perform_carrier_sense(radio_modems_t modem,
|
||||
uint32_t freq,
|
||||
int16_t rssi_threshold,
|
||||
uint32_t max_carrier_sense_time){ return bool_value;};
|
||||
|
||||
virtual void start_cad(void){};
|
||||
|
||||
virtual bool check_rf_frequency(uint32_t frequency){ return bool_value; };
|
||||
|
||||
virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time){};
|
||||
|
||||
virtual void lock(void){};
|
||||
|
||||
virtual void unlock(void){};
|
||||
|
||||
bool bool_value;
|
||||
};
|
||||
|
||||
class Test_LoRaPHYKR920 : public testing::Test {
|
||||
protected:
|
||||
LoRaPHYKR920 *object;
|
||||
my_radio radio;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
LoRaPHY_stub::radio = &radio;
|
||||
object = new LoRaPHYKR920();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
LoRaPHY_stub::radio = NULL;
|
||||
delete object;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(Test_LoRaPHYKR920, constructor)
|
||||
{
|
||||
EXPECT_TRUE(object);
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYKR920, verify_frequency_for_band)
|
||||
{
|
||||
radio.bool_value = false;
|
||||
EXPECT_TRUE(false == object->verify_frequency_for_band(0, 0));
|
||||
|
||||
radio.bool_value = true;
|
||||
EXPECT_TRUE(false == object->verify_frequency_for_band(0, 0));
|
||||
|
||||
EXPECT_TRUE(true == object->verify_frequency_for_band(921100000, 0));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYKR920, tx_config)
|
||||
{
|
||||
tx_config_params_t tx_config;
|
||||
int8_t tx_power = 0;
|
||||
lorawan_time_t time;
|
||||
|
||||
tx_config.tx_power = 9;
|
||||
EXPECT_TRUE(true == object->tx_config(&tx_config, &tx_power, &time));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYKR920, set_next_channel)
|
||||
{
|
||||
channel_selection_params_t next_channel;
|
||||
lorawan_time_t backoff_time = 0;
|
||||
lorawan_time_t time = 0;
|
||||
uint8_t ch = 1;
|
||||
|
||||
next_channel.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 0;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
|
||||
|
||||
next_channel.aggregate_timeoff = 1;
|
||||
radio.bool_value = false;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_DUTYCYCLE_RESTRICTED == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
|
||||
|
||||
next_channel.aggregate_timeoff = 0;
|
||||
LoRaPHY_stub::uint8_value = 1;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
|
||||
|
||||
radio.bool_value = true;
|
||||
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_next_channel(&next_channel, &ch, &backoff_time, &time));
|
||||
}
|
||||
|
||||
TEST_F(Test_LoRaPHYKR920, set_tx_cont_mode)
|
||||
{
|
||||
cw_mode_params_t params;
|
||||
params.tx_power = 9;
|
||||
object->set_tx_cont_mode(¶ms, 0);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue