|
| 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