Skip to content

Commit 4ec30e3

Browse files
committed
Added greentea test
1 parent 9ac31db commit 4ec30e3

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

TESTS/host_tests/crash_reporting.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""
2+
Copyright (c) 2018 ARM Limited
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
"""
16+
import time
17+
from mbed_host_tests import BaseHostTest
18+
from mbed_host_tests.host_tests_runner.host_test_default import DefaultTestSelector
19+
20+
DEFAULT_CYCLE_PERIOD = 10.0
21+
22+
MSG_VALUE_DUMMY = '0'
23+
24+
MSG_KEY_DEVICE_READY = 'crash_reporting_ready'
25+
MSG_KEY_DEVICE_ERROR = 'crash_reporting_inject_error'
26+
MSG_KEY_SYNC = '__sync'
27+
28+
class CrashReportingTest(BaseHostTest):
29+
"""Test for the crash reporting feature.
30+
"""
31+
32+
def __init__(self):
33+
super(CrashReportingTest, self).__init__()
34+
self.reset = False
35+
self.test_steps_sequence = self.test_steps()
36+
# Advance the coroutine to it's first yield statement.
37+
self.test_steps_sequence.send(None)
38+
39+
def setup(self):
40+
self.register_callback(MSG_KEY_DEVICE_READY, self.cb_device_ready)
41+
42+
def cb_device_ready(self, key, value, timestamp):
43+
"""Acknowledge device rebooted correctly and feed the test execution
44+
"""
45+
self.reset = True
46+
47+
try:
48+
if self.test_steps_sequence.send(value):
49+
self.notify_complete(True)
50+
except (StopIteration, RuntimeError) as exc:
51+
self.notify_complete(False)
52+
53+
def test_steps(self):
54+
"""Reset the device and check the status
55+
"""
56+
system_reset = yield
57+
self.reset = False
58+
59+
wait_after_reset = self.get_config_item('forced_reset_timeout')
60+
wait_after_reset = wait_after_reset if wait_after_reset is not None else DEFAULT_CYCLE_PERIOD
61+
62+
#self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
63+
self.send_kv(MSG_KEY_DEVICE_ERROR, MSG_VALUE_DUMMY)
64+
time.sleep(5.0)
65+
66+
system_reset = yield
67+
if self.reset == False:
68+
raise RuntimeError('Platform did not auto-reboot as expected.')
69+
70+
# The sequence is correct -- test passed.
71+
yield True
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "mbed.h"
17+
#include "mbed_error.h"
18+
#include "greentea-client/test_env.h"
19+
#include "unity/unity.h"
20+
21+
#if !MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
22+
#error [NOT_SUPPORTED] crash_reporting test not supported
23+
#endif
24+
25+
#define MSG_VALUE_DUMMY "0"
26+
#define MSG_VALUE_LEN 32
27+
#define MSG_KEY_LEN 64
28+
29+
#define MSG_KEY_DEVICE_READY "crash_reporting_ready"
30+
#define MSG_KEY_DEVICE_ERROR "crash_reporting_inject_error"
31+
32+
void mbed_error_reboot_callback(mbed_error_ctx *error_context) {
33+
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_OUT_OF_MEMORY, error_context->error_status);
34+
TEST_ASSERT_EQUAL_UINT(1, error_context->error_reboot_count);
35+
mbed_reset_reboot_error_info();
36+
37+
//Send the ready msg to host to indicate test pass
38+
greentea_send_kv(MSG_KEY_DEVICE_READY, MSG_VALUE_DUMMY);
39+
}
40+
41+
void test_crash_reporting()
42+
{
43+
// Report readiness
44+
greentea_send_kv(MSG_KEY_DEVICE_READY, MSG_VALUE_DUMMY);
45+
46+
static char _key[MSG_KEY_LEN + 1] = { };
47+
static char _value[MSG_VALUE_LEN + 1] = { };
48+
49+
greentea_parse_kv(_key, _value, MSG_KEY_LEN, MSG_VALUE_LEN);
50+
if (strcmp(_key, MSG_KEY_DEVICE_ERROR) == 0) {
51+
MBED_ERROR1(MBED_ERROR_OUT_OF_MEMORY, "Executing crash reporting test.", 0xDEADBAD);
52+
TEST_ASSERT_MESSAGE(0, "crash_reporting() error call failed.");
53+
}
54+
55+
TEST_ASSERT_MESSAGE(0, "Unexpected message received.");
56+
}
57+
58+
int main(void)
59+
{
60+
GREENTEA_SETUP(30, "crash_reporting");
61+
test_crash_reporting();
62+
GREENTEA_TESTSUITE_RESULT(0);
63+
64+
return 0;
65+
}

0 commit comments

Comments
 (0)