|
| 1 | +/* |
| 2 | + * Copyright (c) 2017, ARM Limited, All Rights Reserved |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | + * 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, WITHOUT |
| 13 | + * 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 "mbed.h" |
| 19 | +#include "rtos.h" |
| 20 | +#include "greentea-client/test_env.h" |
| 21 | +#include "unity/unity.h" |
| 22 | +#include "utest/utest.h" |
| 23 | + |
| 24 | +#if !DEVICE_LOWPOWERTIMER |
| 25 | + #error [NOT_SUPPORTED] Low power timer not supported for this target |
| 26 | +#endif |
| 27 | + |
| 28 | +using namespace utest::v1; |
| 29 | + |
| 30 | +template<timestamp_t time_ms> |
| 31 | +void idle_loop_test_sleep_ms() |
| 32 | +{ |
| 33 | + LowPowerTimer timer; |
| 34 | + timer.start(); |
| 35 | + wait_ms(time_ms); |
| 36 | + const timestamp_t end = timer.read_ms(); |
| 37 | + |
| 38 | + // this does not test accurancy for waking up |
| 39 | + // just that we are with some margin awake (10ms) |
| 40 | + // sleep/low power ticker will test this |
| 41 | + TEST_ASSERT_UINT32_WITHIN(10, time_ms, end); |
| 42 | +} |
| 43 | + |
| 44 | +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) |
| 45 | +{ |
| 46 | + greentea_case_failure_abort_handler(source, reason); |
| 47 | + return STATUS_CONTINUE; |
| 48 | +} |
| 49 | + |
| 50 | +Case cases[] = { |
| 51 | + Case("Idle loop - sleep for 10 ms", idle_loop_test_sleep_ms<10>, greentea_failure_handler), |
| 52 | + Case("Idle loop - sleep for 100 ms", idle_loop_test_sleep_ms<100>, greentea_failure_handler), |
| 53 | + Case("Idle loop - sleep for 500 ms", idle_loop_test_sleep_ms<500>, greentea_failure_handler), |
| 54 | + Case("Idle loop - sleep for 5 s", idle_loop_test_sleep_ms<5000>, greentea_failure_handler), |
| 55 | +}; |
| 56 | + |
| 57 | +utest::v1::status_t greentea_test_setup(const size_t number_of_cases) |
| 58 | +{ |
| 59 | + GREENTEA_SETUP(25, "default_auto"); |
| 60 | + return greentea_test_setup_handler(number_of_cases); |
| 61 | +} |
| 62 | + |
| 63 | +Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); |
| 64 | + |
| 65 | +int main() |
| 66 | +{ |
| 67 | + Harness::run(specification); |
| 68 | +} |
| 69 | + |
0 commit comments