![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/TESTS/mbed_drivers/sleep_lock/main.cpp@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | |
kadonotakashi | 0:8fdf9a60065b | 2 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 3 | * Copyright (c) 2017 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 4 | * |
kadonotakashi | 0:8fdf9a60065b | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 6 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 7 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 8 | * |
kadonotakashi | 0:8fdf9a60065b | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 10 | * |
kadonotakashi | 0:8fdf9a60065b | 11 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 14 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 15 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 16 | */ |
kadonotakashi | 0:8fdf9a60065b | 17 | |
kadonotakashi | 0:8fdf9a60065b | 18 | #if !DEVICE_SLEEP |
kadonotakashi | 0:8fdf9a60065b | 19 | #error [NOT_SUPPORTED] Sleep not supported for this target |
kadonotakashi | 0:8fdf9a60065b | 20 | #endif |
kadonotakashi | 0:8fdf9a60065b | 21 | |
kadonotakashi | 0:8fdf9a60065b | 22 | #include "utest/utest.h" |
kadonotakashi | 0:8fdf9a60065b | 23 | #include "unity/unity.h" |
kadonotakashi | 0:8fdf9a60065b | 24 | #include "greentea-client/test_env.h" |
kadonotakashi | 0:8fdf9a60065b | 25 | |
kadonotakashi | 0:8fdf9a60065b | 26 | #include "mbed.h" |
kadonotakashi | 0:8fdf9a60065b | 27 | |
kadonotakashi | 0:8fdf9a60065b | 28 | using namespace utest::v1; |
kadonotakashi | 0:8fdf9a60065b | 29 | |
kadonotakashi | 0:8fdf9a60065b | 30 | void deep_sleep_lock_lock_test() |
kadonotakashi | 0:8fdf9a60065b | 31 | { |
kadonotakashi | 0:8fdf9a60065b | 32 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 33 | { |
kadonotakashi | 0:8fdf9a60065b | 34 | // Check basic usage works |
kadonotakashi | 0:8fdf9a60065b | 35 | DeepSleepLock lock; |
kadonotakashi | 0:8fdf9a60065b | 36 | TEST_ASSERT_EQUAL(false, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 37 | } |
kadonotakashi | 0:8fdf9a60065b | 38 | |
kadonotakashi | 0:8fdf9a60065b | 39 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 40 | { |
kadonotakashi | 0:8fdf9a60065b | 41 | // Check that unlock and lock change can deep sleep as expected |
kadonotakashi | 0:8fdf9a60065b | 42 | DeepSleepLock lock; |
kadonotakashi | 0:8fdf9a60065b | 43 | TEST_ASSERT_EQUAL(false, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 44 | lock.unlock(); |
kadonotakashi | 0:8fdf9a60065b | 45 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 46 | lock.lock(); |
kadonotakashi | 0:8fdf9a60065b | 47 | TEST_ASSERT_EQUAL(false, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 48 | } |
kadonotakashi | 0:8fdf9a60065b | 49 | |
kadonotakashi | 0:8fdf9a60065b | 50 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 51 | { |
kadonotakashi | 0:8fdf9a60065b | 52 | // Check that unlock releases sleep based on count |
kadonotakashi | 0:8fdf9a60065b | 53 | DeepSleepLock lock; |
kadonotakashi | 0:8fdf9a60065b | 54 | lock.lock(); |
kadonotakashi | 0:8fdf9a60065b | 55 | lock.lock(); |
kadonotakashi | 0:8fdf9a60065b | 56 | lock.unlock(); |
kadonotakashi | 0:8fdf9a60065b | 57 | TEST_ASSERT_EQUAL(false, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 58 | } |
kadonotakashi | 0:8fdf9a60065b | 59 | |
kadonotakashi | 0:8fdf9a60065b | 60 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 61 | { |
kadonotakashi | 0:8fdf9a60065b | 62 | // Check that unbalanced locks do not leave deep sleep locked |
kadonotakashi | 0:8fdf9a60065b | 63 | DeepSleepLock lock; |
kadonotakashi | 0:8fdf9a60065b | 64 | lock.lock(); |
kadonotakashi | 0:8fdf9a60065b | 65 | TEST_ASSERT_EQUAL(false, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 66 | } |
kadonotakashi | 0:8fdf9a60065b | 67 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 68 | |
kadonotakashi | 0:8fdf9a60065b | 69 | } |
kadonotakashi | 0:8fdf9a60065b | 70 | |
kadonotakashi | 0:8fdf9a60065b | 71 | void timer_lock_test() |
kadonotakashi | 0:8fdf9a60065b | 72 | { |
kadonotakashi | 0:8fdf9a60065b | 73 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 74 | { |
kadonotakashi | 0:8fdf9a60065b | 75 | // Just creating a timer object does not lock sleep |
kadonotakashi | 0:8fdf9a60065b | 76 | Timer timer; |
kadonotakashi | 0:8fdf9a60065b | 77 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 78 | } |
kadonotakashi | 0:8fdf9a60065b | 79 | |
kadonotakashi | 0:8fdf9a60065b | 80 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 81 | { |
kadonotakashi | 0:8fdf9a60065b | 82 | // Starting a timer does lock sleep |
kadonotakashi | 0:8fdf9a60065b | 83 | Timer timer; |
kadonotakashi | 0:8fdf9a60065b | 84 | timer.start(); |
kadonotakashi | 0:8fdf9a60065b | 85 | TEST_ASSERT_EQUAL(false, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 86 | } |
kadonotakashi | 0:8fdf9a60065b | 87 | |
kadonotakashi | 0:8fdf9a60065b | 88 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 89 | { |
kadonotakashi | 0:8fdf9a60065b | 90 | // Stopping a timer after starting it allows sleep |
kadonotakashi | 0:8fdf9a60065b | 91 | Timer timer; |
kadonotakashi | 0:8fdf9a60065b | 92 | timer.start(); |
kadonotakashi | 0:8fdf9a60065b | 93 | timer.stop(); |
kadonotakashi | 0:8fdf9a60065b | 94 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 95 | } |
kadonotakashi | 0:8fdf9a60065b | 96 | |
kadonotakashi | 0:8fdf9a60065b | 97 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 98 | { |
kadonotakashi | 0:8fdf9a60065b | 99 | // Starting a timer multiple times still lets you sleep |
kadonotakashi | 0:8fdf9a60065b | 100 | Timer timer; |
kadonotakashi | 0:8fdf9a60065b | 101 | timer.start(); |
kadonotakashi | 0:8fdf9a60065b | 102 | timer.start(); |
kadonotakashi | 0:8fdf9a60065b | 103 | } |
kadonotakashi | 0:8fdf9a60065b | 104 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 105 | |
kadonotakashi | 0:8fdf9a60065b | 106 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 107 | { |
kadonotakashi | 0:8fdf9a60065b | 108 | // Stopping a timer multiple times still lets you sleep |
kadonotakashi | 0:8fdf9a60065b | 109 | Timer timer; |
kadonotakashi | 0:8fdf9a60065b | 110 | timer.start(); |
kadonotakashi | 0:8fdf9a60065b | 111 | timer.stop(); |
kadonotakashi | 0:8fdf9a60065b | 112 | timer.stop(); |
kadonotakashi | 0:8fdf9a60065b | 113 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 114 | } |
kadonotakashi | 0:8fdf9a60065b | 115 | TEST_ASSERT_EQUAL(true, sleep_manager_can_deep_sleep_test_check()); |
kadonotakashi | 0:8fdf9a60065b | 116 | } |
kadonotakashi | 0:8fdf9a60065b | 117 | |
kadonotakashi | 0:8fdf9a60065b | 118 | Case cases[] = { |
kadonotakashi | 0:8fdf9a60065b | 119 | Case("DeepSleepLock lock test", deep_sleep_lock_lock_test), |
kadonotakashi | 0:8fdf9a60065b | 120 | Case("timer lock test", timer_lock_test), |
kadonotakashi | 0:8fdf9a60065b | 121 | }; |
kadonotakashi | 0:8fdf9a60065b | 122 | |
kadonotakashi | 0:8fdf9a60065b | 123 | utest::v1::status_t greentea_test_setup(const size_t number_of_cases) |
kadonotakashi | 0:8fdf9a60065b | 124 | { |
kadonotakashi | 0:8fdf9a60065b | 125 | GREENTEA_SETUP(20, "default_auto"); |
kadonotakashi | 0:8fdf9a60065b | 126 | return greentea_test_setup_handler(number_of_cases); |
kadonotakashi | 0:8fdf9a60065b | 127 | } |
kadonotakashi | 0:8fdf9a60065b | 128 | |
kadonotakashi | 0:8fdf9a60065b | 129 | Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); |
kadonotakashi | 0:8fdf9a60065b | 130 | |
kadonotakashi | 0:8fdf9a60065b | 131 | int main() |
kadonotakashi | 0:8fdf9a60065b | 132 | { |
kadonotakashi | 0:8fdf9a60065b | 133 | Harness::run(specification); |
kadonotakashi | 0:8fdf9a60065b | 134 | } |