Skip to content

Commit c85b76a

Browse files
authored
Merge pull request #13298 from ashok-rao/platform-refactor
Refactoring \platform directory
2 parents 1d362c8 + a78554e commit c85b76a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+156
-3
lines changed

.astyleignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
^features/unsupported/
2020
^hal/storage_abstraction
2121
^platform/cxxsupport
22+
^platform/tests/UNITTESTS
2223
^events/tests/UNITTESTS
2324
^rtos/source/TARGET_CORTEX/rtx4
2425
^rtos/source/TARGET_CORTEX/rtx5

UNITTESTS/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ set(unittest-includes-base
112112
"${PROJECT_SOURCE_DIR}/stubs"
113113
"${PROJECT_SOURCE_DIR}/.."
114114
"${PROJECT_SOURCE_DIR}/../features"
115-
"${PROJECT_SOURCE_DIR}/../platform"
115+
"${PROJECT_SOURCE_DIR}/../platform/include"
116+
"${PROJECT_SOURCE_DIR}/../platform/include/platform"
116117
"${PROJECT_SOURCE_DIR}/../storage/filesystem/littlefs/include"
117118
"${PROJECT_SOURCE_DIR}/../storage/filesystem/fat/include"
118119
"${PROJECT_SOURCE_DIR}/../storage/blockdevice/include"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

platform/tests/.mbedignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UNITTESTS/*
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""
2+
Copyright (c) 2018 ARM Limited
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+
import time
18+
from mbed_host_tests import BaseHostTest
19+
from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector
20+
21+
DEFAULT_CYCLE_PERIOD = 10.0
22+
23+
MSG_VALUE_DUMMY = '0'
24+
25+
MSG_KEY_DEVICE_READY = 'crash_reporting_ready'
26+
MSG_KEY_DEVICE_ERROR = 'crash_reporting_inject_error'
27+
MSG_KEY_SYNC = '__sync'
28+
29+
class CrashReportingTest(BaseHostTest):
30+
"""Test for the crash reporting feature.
31+
"""
32+
33+
def __init__(self):
34+
super(CrashReportingTest, self).__init__()
35+
self.reset = False
36+
self.test_steps_sequence = self.test_steps()
37+
# Advance the coroutine to it's first yield statement.
38+
self.test_steps_sequence.send(None)
39+
40+
def setup(self):
41+
self.register_callback(MSG_KEY_DEVICE_READY, self.cb_device_ready)
42+
43+
def cb_device_ready(self, key, value, timestamp):
44+
"""Acknowledge device rebooted correctly and feed the test execution
45+
"""
46+
self.reset = True
47+
48+
try:
49+
if self.test_steps_sequence.send(value):
50+
self.notify_complete(True)
51+
except (StopIteration, RuntimeError) as exc:
52+
self.notify_complete(False)
53+
54+
def test_steps(self):
55+
"""Reset the device and check the status
56+
"""
57+
system_reset = yield
58+
self.reset = False
59+
60+
wait_after_reset = self.get_config_item('forced_reset_timeout')
61+
wait_after_reset = wait_after_reset if wait_after_reset is not None else DEFAULT_CYCLE_PERIOD
62+
63+
#Wait 2 seconds for system to init
64+
time.sleep(7.0)
65+
#self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
66+
self.send_kv(MSG_KEY_DEVICE_ERROR, MSG_VALUE_DUMMY)
67+
time.sleep(5.0)
68+
69+
system_reset = yield
70+
if self.reset == False:
71+
raise RuntimeError('Platform did not auto-reboot as expected.')
72+
73+
# The sequence is correct -- test passed.
74+
yield True
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
Copyright (c) 2018 ARM Limited
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+
import time
18+
from mbed_host_tests import BaseHostTest
19+
from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector
20+
21+
DEFAULT_CYCLE_PERIOD = 1.0
22+
23+
MSG_VALUE_DUMMY = '0'
24+
25+
MSG_KEY_DEVICE_READY = 'ready'
26+
MSG_KEY_DEVICE_RESET = 'reset'
27+
MSG_KEY_SYNC = '__sync'
28+
29+
class SystemResetTest(BaseHostTest):
30+
"""Test for the system_reset API.
31+
32+
Given a device running code
33+
When the device is restarted using @a system_reset()
34+
Then the device is restarted
35+
"""
36+
37+
def __init__(self):
38+
super(SystemResetTest, self).__init__()
39+
self.reset = False
40+
self.test_steps_sequence = self.test_steps()
41+
# Advance the coroutine to it's first yield statement.
42+
self.test_steps_sequence.send(None)
43+
44+
def setup(self):
45+
self.register_callback(MSG_KEY_DEVICE_READY, self.cb_device_ready)
46+
47+
def cb_device_ready(self, key, value, timestamp):
48+
"""Acknowledge device rebooted correctly and feed the test execution
49+
"""
50+
self.reset = True
51+
52+
try:
53+
if self.test_steps_sequence.send(value):
54+
self.notify_complete(True)
55+
except (StopIteration, RuntimeError) as exc:
56+
self.notify_complete(False)
57+
58+
def test_steps(self):
59+
"""Reset the device and check the status
60+
"""
61+
system_reset = yield
62+
self.reset = False
63+
64+
wait_after_reset = self.get_config_item('forced_reset_timeout')
65+
wait_after_reset = wait_after_reset if wait_after_reset is not None else DEFAULT_CYCLE_PERIOD
66+
67+
self.send_kv(MSG_KEY_DEVICE_RESET, MSG_VALUE_DUMMY)
68+
time.sleep(wait_after_reset)
69+
self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
70+
71+
system_reset = yield
72+
if self.reset == False:
73+
raise RuntimeError('Platform did not reset as expected.')
74+
75+
# The sequence is correct -- test passed.
76+
yield True

UNITTESTS/platform/ATCmdParser/unittest.cmake renamed to platform/tests/UNITTESTS/ATCmdParser/unittest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set(unittest-sources
99

1010
# Test files
1111
set(unittest-test-sources
12-
platform/ATCmdParser/test_ATCmdParser.cpp
12+
../platform/tests/UNITTESTS/ATCmdParser/test_ATCmdParser.cpp
1313
stubs/FileHandle_stub.cpp
1414
stubs/mbed_assert_stub.cpp
1515
stubs/mbed_poll_stub.cpp

UNITTESTS/platform/CircularBuffer/unittest.cmake renamed to platform/tests/UNITTESTS/CircularBuffer/unittest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ set(unittest-sources
77
)
88

99
set(unittest-test-sources
10-
platform/CircularBuffer/test_CircularBuffer.cpp
10+
../platform/tests/UNITTESTS/CircularBuffer/test_CircularBuffer.cpp
1111
)

0 commit comments

Comments
 (0)