|
15 | 15 | */
|
16 | 16 |
|
17 | 17 | #if !DEVICE_LOWPOWERTIMER
|
18 |
| - #error [NOT_SUPPORTED] Low power timer not supported for this target |
| 18 | +#error [NOT_SUPPORTED] Low power timer not supported for this target |
19 | 19 | #endif
|
20 | 20 |
|
| 21 | +#include "mbed.h" |
| 22 | +#include "greentea-client/test_env.h" |
21 | 23 | #include "utest/utest.h"
|
22 | 24 | #include "unity/unity.h"
|
23 |
| -#include "greentea-client/test_env.h" |
24 |
| - |
25 |
| -#include "mbed.h" |
| 25 | +#include "../timeout/timeout_tests.h" |
26 | 26 |
|
27 | 27 | using namespace utest::v1;
|
28 | 28 |
|
29 |
| -volatile static bool complete; |
30 |
| -static LowPowerTimeout lpt; |
31 |
| - |
32 |
| -/* Timeouts are quite arbitrary due to large number of boards with varying level of accuracy */ |
33 |
| -#define LONG_TIMEOUT (100000) |
34 |
| -#define SHORT_TIMEOUT (600) |
35 |
| - |
36 |
| -void cb_done() { |
37 |
| - complete = true; |
38 |
| -} |
39 |
| - |
40 |
| -#if DEVICE_SLEEP |
41 |
| -void lp_timeout_1s_deepsleep(void) |
| 29 | +utest::v1::status_t greentea_failure_handler(const Case * const source, const failure_t reason) |
42 | 30 | {
|
43 |
| - complete = false; |
44 |
| - LowPowerTimer timer; |
45 |
| - |
46 |
| - /* |
47 |
| - * Since deepsleep() may shut down the UART peripheral, we wait for 10ms |
48 |
| - * to allow for hardware serial buffers to completely flush. |
49 |
| -
|
50 |
| - * This should be replaced with a better function that checks if the |
51 |
| - * hardware buffers are empty. However, such an API does not exist now, |
52 |
| - * so we'll use the wait_ms() function for now. |
53 |
| - */ |
54 |
| - wait_ms(10); |
55 |
| - |
56 |
| - /* |
57 |
| - * We use here the low power timer instead of microsecond timer for start and |
58 |
| - * end because the microseconds timer might be disable during deepsleep. |
59 |
| - */ |
60 |
| - timer.start(); |
61 |
| - lpt.attach(&cb_done, 1); |
62 |
| - /* Make sure deepsleep is allowed, to go to deepsleep */ |
63 |
| - bool deep_sleep_allowed = sleep_manager_can_deep_sleep(); |
64 |
| - TEST_ASSERT_TRUE_MESSAGE(deep_sleep_allowed, "Deep sleep should be allowed"); |
65 |
| - sleep(); |
66 |
| - while (!complete); |
67 |
| - |
68 |
| - /* It takes longer to wake up from deep sleep */ |
69 |
| - TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, timer.read_us()); |
70 |
| - TEST_ASSERT_TRUE(complete); |
| 31 | + greentea_case_failure_abort_handler(source, reason); |
| 32 | + return STATUS_CONTINUE; |
71 | 33 | }
|
72 | 34 |
|
73 |
| -void lp_timeout_1s_sleep(void) |
74 |
| -{ |
75 |
| - complete = false; |
76 |
| - Timer timer; |
77 |
| - timer.start(); |
78 |
| - |
79 |
| - sleep_manager_lock_deep_sleep(); |
80 |
| - lpt.attach(&cb_done, 1); |
81 |
| - bool deep_sleep_allowed = sleep_manager_can_deep_sleep(); |
82 |
| - TEST_ASSERT_FALSE_MESSAGE(deep_sleep_allowed, "Deep sleep should be disallowed"); |
83 |
| - sleep(); |
84 |
| - while (!complete); |
85 |
| - sleep_manager_unlock_deep_sleep(); |
86 |
| - |
87 |
| - TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, timer.read_us()); |
88 |
| - TEST_ASSERT_TRUE(complete); |
89 |
| -} |
90 |
| -#endif /* DEVICE_SLEEP */ |
| 35 | +Case cases[] = { |
| 36 | + Case("Callback called once (attach)", test_single_call<AttachTester<LowPowerTimeout> >), |
| 37 | + Case("Callback called once (attach_us)", test_single_call<AttachUSTester<LowPowerTimeout> >), |
91 | 38 |
|
92 |
| -void lp_timeout_us(uint32_t delay_us, uint32_t tolerance) |
93 |
| -{ |
94 |
| - complete = false; |
95 |
| - Timer timer; |
96 |
| - timer.start(); |
| 39 | + Case("Callback not called when cancelled (attach)", test_cancel<AttachTester<LowPowerTimeout> >), |
| 40 | + Case("Callback not called when cancelled (attach_us)", test_cancel<AttachUSTester<LowPowerTimeout> >), |
97 | 41 |
|
98 |
| - lpt.attach_us(&cb_done, delay_us); |
99 |
| - while (!complete); |
| 42 | + Case("Callback override (attach)", test_override<AttachTester<LowPowerTimeout> >), |
| 43 | + Case("Callback override (attach_us)", test_override<AttachUSTester<LowPowerTimeout> >), |
100 | 44 |
|
101 |
| - /* Using RTC which is less accurate */ |
102 |
| - TEST_ASSERT_UINT32_WITHIN(tolerance, delay_us, timer.read_us()); |
103 |
| - TEST_ASSERT_TRUE(complete); |
104 |
| -} |
| 45 | + Case("Multiple timeouts running in parallel (attach)", test_multiple<AttachTester<LowPowerTimeout> >), |
| 46 | + Case("Multiple timeouts running in parallel (attach_us)", test_multiple<AttachUSTester<LowPowerTimeout> >), |
105 | 47 |
|
106 |
| -void lp_timeout_5s(void) |
107 |
| -{ |
108 |
| - lp_timeout_us(5000000, LONG_TIMEOUT); |
109 |
| -} |
| 48 | + Case("Zero delay (attach)", test_no_wait<AttachTester<LowPowerTimeout> >), |
| 49 | + Case("Zero delay (attach_us)", test_no_wait<AttachUSTester<LowPowerTimeout> >), |
110 | 50 |
|
111 |
| -void lp_timeout_1s(void) |
112 |
| -{ |
113 |
| - lp_timeout_us(1000000, LONG_TIMEOUT); |
114 |
| -} |
| 51 | + Case("10 ms delay accuracy (attach)", test_delay_accuracy<AttachTester<LowPowerTimeout>, 10000, SHORT_DELTA_US>, |
| 52 | + greentea_failure_handler), |
| 53 | + Case("10 ms delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<LowPowerTimeout>, 10000, SHORT_DELTA_US>, |
| 54 | + greentea_failure_handler), |
115 | 55 |
|
116 |
| -void lp_timeout_1ms(void) |
117 |
| -{ |
118 |
| - lp_timeout_us(1000, SHORT_TIMEOUT); |
119 |
| -} |
| 56 | + Case("1 s delay accuracy (attach)", test_delay_accuracy<AttachTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>, |
| 57 | + greentea_failure_handler), |
| 58 | + Case("1 s delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>, |
| 59 | + greentea_failure_handler), |
120 | 60 |
|
121 |
| -void lp_timeout_500us(void) |
122 |
| -{ |
123 |
| - lp_timeout_us(500, SHORT_TIMEOUT); |
124 |
| - |
125 |
| -} |
| 61 | + Case("5 s delay accuracy (attach)", test_delay_accuracy<AttachTester<LowPowerTimeout>, 5000000, LONG_DELTA_US>, |
| 62 | + greentea_failure_handler), |
| 63 | + Case("5 s delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<LowPowerTimeout>, 5000000, LONG_DELTA_US>, |
| 64 | + greentea_failure_handler), |
126 | 65 |
|
127 |
| -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { |
128 |
| - greentea_case_failure_abort_handler(source, reason); |
129 |
| - return STATUS_CONTINUE; |
130 |
| -} |
131 |
| - |
132 |
| -Case cases[] = { |
133 |
| - Case("500us LowPowerTimeout", lp_timeout_500us, greentea_failure_handler), |
134 |
| - Case("1ms LowPowerTimeout", lp_timeout_1ms, greentea_failure_handler), |
135 |
| - Case("1sec LowPowerTimeout", lp_timeout_1s, greentea_failure_handler), |
136 |
| - Case("5sec LowPowerTimeout", lp_timeout_5s, greentea_failure_handler), |
137 | 66 | #if DEVICE_SLEEP
|
138 |
| - Case("1sec LowPowerTimeout from sleep", lp_timeout_1s_sleep, greentea_failure_handler), |
139 |
| - Case("1sec LowPowerTimeout from deepsleep", lp_timeout_1s_deepsleep, greentea_failure_handler), |
140 |
| -#endif /* DEVICE_SLEEP */ |
| 67 | + Case("1 s delay during sleep (attach)", test_sleep<AttachTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>, |
| 68 | + greentea_failure_handler), |
| 69 | + Case("1 s delay during sleep (attach_us)", test_sleep<AttachUSTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>, |
| 70 | + greentea_failure_handler), |
| 71 | + |
| 72 | + Case("1 s delay during deepsleep (attach)", test_deepsleep<AttachTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>, |
| 73 | + greentea_failure_handler), |
| 74 | + Case("1 s delay during deepsleep (attach_us)", test_deepsleep<AttachUSTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>, |
| 75 | + greentea_failure_handler), |
| 76 | +#endif |
| 77 | + |
| 78 | + Case("Timing drift (attach)", test_drift<AttachTester<LowPowerTimeout> >), |
| 79 | + Case("Timing drift (attach_us)", test_drift<AttachUSTester<LowPowerTimeout> >), |
141 | 80 | };
|
142 | 81 |
|
143 |
| -utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { |
144 |
| - GREENTEA_SETUP(20, "default_auto"); |
| 82 | +utest::v1::status_t greentea_test_setup(const size_t number_of_cases) |
| 83 | +{ |
| 84 | + GREENTEA_SETUP(240, "timing_drift_auto"); |
145 | 85 | return greentea_test_setup_handler(number_of_cases);
|
146 | 86 | }
|
147 | 87 |
|
148 | 88 | Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
|
149 | 89 |
|
150 |
| -int main() { |
| 90 | +int main() |
| 91 | +{ |
151 | 92 | Harness::run(specification);
|
152 | 93 | }
|
0 commit comments