Skip to content

Commit f6ecb31

Browse files
author
Antti Kauppila
committed
LoRaMac unittested
1 parent bd90664 commit f6ecb31

File tree

20 files changed

+642
-41
lines changed

20 files changed

+642
-41
lines changed

UNITTESTS/features/lorawan/loramac/Test_LoRaMac.cpp

Lines changed: 507 additions & 0 deletions
Large diffs are not rendered by default.

UNITTESTS/features/lorawan/loraphy/unittest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ set(unittest-includes ${unittest-includes}
3333
set(unittest-test-sources
3434
../features/lorawan/loraphy/Test_LoRaPHY.cpp
3535
stubs/LoRaWANTimer_stub.cpp
36-
36+
stubs/mbed_assert_stub.c
3737
)
3838

3939

UNITTESTS/features/lorawan/loraphyas923/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ set(unittest-test-sources
3434
../features/lorawan/loraphyas923/Test_LoRaPHYAS923.cpp
3535
stubs/LoRaPHY_stub.cpp
3636
stubs/LoRaWANTimer_stub.cpp
37+
stubs/mbed_assert_stub.c
3738

3839
)
3940

UNITTESTS/features/lorawan/loraphyau915/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ set(unittest-test-sources
3434
../features/lorawan/loraphyau915/Test_LoRaPHYAU915.cpp
3535
stubs/LoRaPHY_stub.cpp
3636
stubs/LoRaWANTimer_stub.cpp
37+
stubs/mbed_assert_stub.c
3738

3839
)
3940

UNITTESTS/features/lorawan/loraphycn470/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ set(unittest-test-sources
3434
../features/lorawan/loraphycn470/Test_LoRaPHYCN470.cpp
3535
stubs/LoRaPHY_stub.cpp
3636
stubs/LoRaWANTimer_stub.cpp
37+
stubs/mbed_assert_stub.c
3738

3839
)
3940

UNITTESTS/features/lorawan/loraphycn779/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(unittest-includes ${unittest-includes}
3333
set(unittest-test-sources
3434
../features/lorawan/loraphycn779/Test_LoRaPHYCN779.cpp
3535
stubs/LoRaPHY_stub.cpp
36+
stubs/mbed_assert_stub.c
3637

3738
)
3839

UNITTESTS/features/lorawan/loraphyeu433/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(unittest-includes ${unittest-includes}
3333
set(unittest-test-sources
3434
../features/lorawan/loraphyeu433/Test_LoRaPHYEU433.cpp
3535
stubs/LoRaPHY_stub.cpp
36+
stubs/mbed_assert_stub.c
3637

3738
)
3839

UNITTESTS/features/lorawan/loraphyeu868/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(unittest-includes ${unittest-includes}
3333
set(unittest-test-sources
3434
../features/lorawan/loraphyeu868/Test_LoRaPHYEU868.cpp
3535
stubs/LoRaPHY_stub.cpp
36+
stubs/mbed_assert_stub.c
3637

3738
)
3839

UNITTESTS/features/lorawan/loraphyin865/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(unittest-includes ${unittest-includes}
3333
set(unittest-test-sources
3434
../features/lorawan/loraphyin865/Test_LoRaPHYIN865.cpp
3535
stubs/LoRaPHY_stub.cpp
36+
stubs/mbed_assert_stub.c
3637

3738
)
3839

UNITTESTS/features/lorawan/loraphykr920/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ set(unittest-test-sources
3434
../features/lorawan/loraphykr920/Test_LoRaPHYKR920.cpp
3535
stubs/LoRaPHY_stub.cpp
3636
stubs/LoRaWANTimer_stub.cpp
37+
stubs/mbed_assert_stub.c
3738

3839
)
3940

UNITTESTS/features/lorawan/loraphyus915/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ set(unittest-test-sources
3434
../features/lorawan/loraphyus915/Test_LoRaPHYUS915.cpp
3535
stubs/LoRaPHY_stub.cpp
3636
stubs/LoRaWANTimer_stub.cpp
37+
stubs/mbed_assert_stub.c
3738

3839
)
3940

UNITTESTS/stubs/EventQueue_stub.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
#include "EventQueue.h"
1919
#include "Callback.h"
20+
#include "EventQueue_stub.h"
2021

2122
using namespace mbed;
2223

24+
int EventQueue_stub::int_value = 0;
25+
unsigned EventQueue_stub::unsigned_value = 0;
26+
2327
namespace events {
2428

2529
EventQueue::EventQueue(unsigned event_size, unsigned char *event_pointer)
@@ -40,7 +44,7 @@ void EventQueue::break_dispatch()
4044

4145
unsigned EventQueue::tick()
4246
{
43-
return 0;
47+
return EventQueue_stub::unsigned_value;
4448
}
4549

4650
void EventQueue::cancel(int id)
@@ -49,7 +53,7 @@ void EventQueue::cancel(int id)
4953

5054
int EventQueue::time_left(int id)
5155
{
52-
return 0;
56+
return EventQueue_stub::int_value;
5357
}
5458

5559
void EventQueue::background(Callback<void(int)> update)

UNITTESTS/stubs/EventQueue_stub.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) , Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <inttypes.h>
19+
20+
namespace EventQueue_stub
21+
{
22+
extern int int_value;
23+
extern unsigned unsigned_value;
24+
}
25+

UNITTESTS/stubs/LoRaMacCommand_stub.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
#include "LoRaMacCommand.h"
1919
#include "LoRaMac.h"
2020

21+
#include "LoRaMacCommand_stub.h"
22+
23+
lorawan_status_t LoRaMacCommand_stub::status_value = LORAWAN_STATUS_OK;
24+
bool LoRaMacCommand_stub::bool_value = false;
25+
uint8_t LoRaMacCommand_stub::uint8_value = 0;
26+
int32_t LoRaMacCommand_stub::int32_value = 0;
2127

2228
LoRaMacCommand::LoRaMacCommand()
2329
{
@@ -29,12 +35,12 @@ void LoRaMacCommand::clear_command_buffer()
2935

3036
uint8_t LoRaMacCommand::get_mac_cmd_length() const
3137
{
32-
return 0;
38+
return LoRaMacCommand_stub::uint8_value;
3339
}
3440

3541
uint8_t *LoRaMacCommand::get_mac_commands_buffer()
3642
{
37-
return NULL;
43+
return &LoRaMacCommand_stub::uint8_value;
3844
}
3945

4046
void LoRaMacCommand::parse_mac_commands_to_repeat()
@@ -52,7 +58,7 @@ void LoRaMacCommand::copy_repeat_commands_to_buffer()
5258

5359
uint8_t LoRaMacCommand::get_repeat_commands_length() const
5460
{
55-
return 0;
61+
return LoRaMacCommand_stub::uint8_value;
5662
}
5763

5864
void LoRaMacCommand::clear_sticky_mac_cmd()
@@ -61,7 +67,7 @@ void LoRaMacCommand::clear_sticky_mac_cmd()
6167

6268
bool LoRaMacCommand::has_sticky_mac_cmd() const
6369
{
64-
return false;
70+
return LoRaMacCommand_stub::bool_value;
6571
}
6672

6773
lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, uint8_t mac_index,
@@ -70,12 +76,12 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, ui
7076
lora_mac_system_params_t &mac_sys_params,
7177
LoRaPHY &lora_phy)
7278
{
73-
return LORAWAN_STATUS_OK;
79+
return LoRaMacCommand_stub::status_value;
7480
}
7581

7682
int32_t LoRaMacCommand::cmd_buffer_remaining() const
7783
{
78-
return 0;
84+
return LoRaMacCommand_stub::int32_value;
7985
}
8086

8187
void LoRaMacCommand::set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_level)
@@ -84,45 +90,45 @@ void LoRaMacCommand::set_batterylevel_callback(mbed::Callback<uint8_t(void)> bat
8490

8591
lorawan_status_t LoRaMacCommand::add_link_check_req()
8692
{
87-
return LORAWAN_STATUS_OK;
93+
return LoRaMacCommand_stub::status_value;
8894
}
8995

9096
lorawan_status_t LoRaMacCommand::add_link_adr_ans(uint8_t status)
9197
{
92-
return LORAWAN_STATUS_OK;
98+
return LoRaMacCommand_stub::status_value;
9399
}
94100

95101
lorawan_status_t LoRaMacCommand::add_duty_cycle_ans()
96102
{
97-
return LORAWAN_STATUS_OK;
103+
return LoRaMacCommand_stub::status_value;
98104
}
99105

100106
lorawan_status_t LoRaMacCommand::add_rx_param_setup_ans(uint8_t status)
101107
{
102-
return LORAWAN_STATUS_OK;
108+
return LoRaMacCommand_stub::status_value;
103109
}
104110

105111
lorawan_status_t LoRaMacCommand::add_dev_status_ans(uint8_t battery, uint8_t margin)
106112
{
107-
return LORAWAN_STATUS_OK;
113+
return LoRaMacCommand_stub::status_value;
108114
}
109115

110116
lorawan_status_t LoRaMacCommand::add_new_channel_ans(uint8_t status)
111117
{
112-
return LORAWAN_STATUS_OK;
118+
return LoRaMacCommand_stub::status_value;
113119
}
114120

115121
lorawan_status_t LoRaMacCommand::add_rx_timing_setup_ans()
116122
{
117-
return LORAWAN_STATUS_OK;
123+
return LoRaMacCommand_stub::status_value;
118124
}
119125

120126
lorawan_status_t LoRaMacCommand::add_tx_param_setup_ans()
121127
{
122-
return LORAWAN_STATUS_OK;
128+
return LoRaMacCommand_stub::status_value;
123129
}
124130

125131
lorawan_status_t LoRaMacCommand::add_dl_channel_ans(uint8_t status)
126132
{
127-
return LORAWAN_STATUS_OK;
133+
return LoRaMacCommand_stub::status_value;
128134
}

UNITTESTS/stubs/LoRaMacCommand_stub.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) , Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
#include <inttypes.h>
20+
#include "lorawan_types.h"
21+
22+
namespace LoRaMacCommand_stub
23+
{
24+
extern lorawan_status_t status_value;
25+
extern bool bool_value;
26+
extern uint8_t uint8_value;
27+
extern int32_t int32_value;
28+
}

UNITTESTS/stubs/LoRaMacCrypto_stub.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include "LoRaMacCrypto.h"
2222
#include "system/lorawan_data_structures.h"
2323

24+
#include "LoRaMacCrypto_stub.h"
25+
26+
int LoRaMacCrypto_stub::int_table_idx_value = 0;
27+
int LoRaMacCrypto_stub::int_table[20] = {};
2428

2529
LoRaMacCrypto::LoRaMacCrypto()
2630
{
@@ -29,34 +33,34 @@ LoRaMacCrypto::LoRaMacCrypto()
2933
int LoRaMacCrypto::compute_mic(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
3034
uint8_t dir, uint32_t, uint32_t *)
3135
{
32-
return 0;
36+
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
3337
}
3438

3539
int LoRaMacCrypto::encrypt_payload(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
3640
uint8_t , uint32_t , uint8_t *)
3741
{
38-
return 0;
42+
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
3943
}
4044

4145
int LoRaMacCrypto::decrypt_payload(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t,
4246
uint8_t , uint32_t , uint8_t *)
4347
{
44-
return 0;
48+
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
4549
}
4650

4751
int LoRaMacCrypto::compute_join_frame_mic(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint32_t *)
4852
{
49-
return 0;
53+
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
5054
}
5155

52-
int LoRaMacCrypto::decrypt_join_frame(const uint8_t *, uint16_t , const uint8_t *, uint32_t, uint8_t *)
56+
int LoRaMacCrypto::decrypt_join_frame(const uint8_t *in, uint16_t size, const uint8_t *, uint32_t, uint8_t *out)
5357
{
54-
return 0;
58+
memcpy(out, in, size);
59+
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
5560
}
5661

5762
int LoRaMacCrypto::compute_skeys_for_join_frame(const uint8_t *, uint32_t, const uint8_t *, uint16_t ,
5863
uint8_t *, uint8_t *)
5964
{
60-
return 0;
65+
return LoRaMacCrypto_stub::int_table[LoRaMacCrypto_stub::int_table_idx_value++];
6166
}
62-

UNITTESTS/stubs/LoRaMacCrypto_stub.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) , Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
19+
#include <inttypes.h>
20+
21+
namespace LoRaMacCrypto_stub
22+
{
23+
extern int int_table_idx_value;
24+
extern int int_table[20];
25+
}

UNITTESTS/stubs/LoRaWANTimer_stub.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include "mbed_assert.h"
1819
#include "LoRaWANTimer.h"
1920

2021
#include "LoRaWANTimer_stub.h"
2122

2223
lorawan_time_t LoRaWANTimer_stub::time_value = 0;
24+
bool LoRaWANTimer_stub::call_cb_immediately = false;
2325

2426
LoRaWANTimeHandler::LoRaWANTimeHandler()
2527
: _queue(NULL)
@@ -46,6 +48,10 @@ lorawan_time_t LoRaWANTimeHandler::get_elapsed_time(lorawan_time_t saved_time)
4648

4749
void LoRaWANTimeHandler::init(timer_event_t &obj, mbed::Callback<void()> callback)
4850
{
51+
if (callback && LoRaWANTimer_stub::call_cb_immediately) {
52+
callback();
53+
}
54+
obj.timer_id = 1;
4955
}
5056

5157
void LoRaWANTimeHandler::start(timer_event_t &obj, const uint32_t timeout)
@@ -54,4 +60,5 @@ void LoRaWANTimeHandler::start(timer_event_t &obj, const uint32_t timeout)
5460

5561
void LoRaWANTimeHandler::stop(timer_event_t &obj)
5662
{
63+
obj.timer_id = 0;
5764
}

0 commit comments

Comments
 (0)