|
| 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 | +void idle_loop_test_sleep_ms_callback(timestamp_t *time_ms) |
| 31 | +{ |
| 32 | + LowPowerTimer timer; |
| 33 | + timer.start(); |
| 34 | + Thread::wait(*time_ms); |
| 35 | + const timestamp_t end = timer.read_ms(); |
| 36 | + |
| 37 | + // this does not test accurancy for waking up |
| 38 | + // just that we are with some margin awake (10ms) |
| 39 | + // sleep/low power ticker will test this |
| 40 | + // Note: if this does not work, we wake up with |
| 41 | + // default freq - 1ms |
| 42 | + TEST_ASSERT_UINT32_WITHIN(3, *time_ms, end); |
| 43 | +} |
| 44 | + |
| 45 | +template<timestamp_t time_ms> |
| 46 | +void idle_loop_test_sleep_ms() |
| 47 | +{ |
| 48 | + Thread t; |
| 49 | + timestamp_t delay = time_ms; |
| 50 | + t.start(callback(idle_loop_test_sleep_ms_callback, &delay)); |
| 51 | + |
| 52 | + Thread::yield(); |
| 53 | +} |
| 54 | + |
| 55 | +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) |
| 56 | +{ |
| 57 | + greentea_case_failure_abort_handler(source, reason); |
| 58 | + return STATUS_CONTINUE; |
| 59 | +} |
| 60 | + |
| 61 | +Case cases[] = { |
| 62 | + Case("Idle loop - sleep for 10 ms", idle_loop_test_sleep_ms<10>, greentea_failure_handler), |
| 63 | + Case("Idle loop - sleep for 100 ms", idle_loop_test_sleep_ms<100>, greentea_failure_handler), |
| 64 | + Case("Idle loop - sleep for 500 ms", idle_loop_test_sleep_ms<500>, greentea_failure_handler), |
| 65 | + Case("Idle loop - sleep for 1 s", idle_loop_test_sleep_ms<1000>, greentea_failure_handler), |
| 66 | + Case("Idle loop - sleep for 5 s", idle_loop_test_sleep_ms<5000>, greentea_failure_handler), |
| 67 | +}; |
| 68 | + |
| 69 | +utest::v1::status_t greentea_test_setup(const size_t number_of_cases) |
| 70 | +{ |
| 71 | + GREENTEA_SETUP(25, "default_auto"); |
| 72 | + return greentea_test_setup_handler(number_of_cases); |
| 73 | +} |
| 74 | + |
| 75 | +Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); |
| 76 | + |
| 77 | +int main() |
| 78 | +{ |
| 79 | + Harness::run(specification); |
| 80 | +} |
| 81 | + |
0 commit comments