14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
16
16
*/
17
-
18
-
19
- /*
20
- * Tests is to measure the accuracy of Thread::wait() over a period of time
21
- *
22
- *
23
- * 1) DUT would start to update callback_trigger_count every milli sec
24
- * 2) Host would query what is current count base_time, Device responds by the callback_trigger_count
25
- * 3) Host after waiting for measurement stretch. It will query for device time again final_time.
26
- * 4) Host computes the drift considering base_time, final_time, transport delay and measurement stretch
27
- * 5) Finally host send the results back to device pass/fail based on tolerance.
28
- * 6) More details on tests can be found in timing_drift_auto.py
29
- *
30
- */
31
-
32
17
#include " mbed.h"
33
18
#include " greentea-client/test_env.h"
34
- #include " rtos .h"
19
+ #include " utest/utest .h"
35
20
#include " unity/unity.h"
36
21
37
22
#if defined(MBED_RTOS_SINGLE_THREAD)
38
23
#error [NOT_SUPPORTED] test not supported
39
24
#endif
40
25
41
- #define TEST_STACK_SIZE 1024
26
+ using utest::v1::Case;
27
+
28
+ #define TEST_STACK_SIZE 256
42
29
#define ONE_MILLI_SEC 1000
43
30
44
- volatile uint32_t callback_trigger_count = 0 ;
31
+ volatile uint32_t elapsed_time_ms = 0 ;
32
+ static const int test_timeout = 40 ;
45
33
46
- static const int test_timeout = 240 ;
47
- bool test_result = false ;
48
34
49
- void update_tick_thread () {
35
+ void update_tick_thread (Mutex *mutex)
36
+ {
50
37
while (true ) {
51
38
Thread::wait (1 );
52
- ++callback_trigger_count;
39
+ mutex->lock ();
40
+ ++elapsed_time_ms;
41
+ mutex->unlock ();
53
42
}
54
43
}
55
44
56
- void gt_comm_wait_thread () {
45
+
46
+ /* * Tests is to measure the accuracy of Thread::wait() over a period of time
47
+
48
+ Given
49
+ a thread updating elapsed_time_ms every milli sec
50
+ and host script for time measurement accuracy check (More details on tests can be found in timing_drift_auto.py)
51
+ When host query what is current count base_time
52
+ Then Device responds by the elapsed_time_ms
53
+ When host query what is current count final_time
54
+ Then Device responds by the elapsed_time_ms
55
+ When host computes the drift considering base_time, final_time, transport delay and measurement stretch
56
+ Then host send the results back to device pass/fail based on tolerance
57
+ */
58
+ void test (void )
59
+ {
57
60
char _key[11 ] = { };
58
61
char _value[128 ] = { };
59
62
int expected_key = 1 ;
63
+ Mutex mutex;
64
+ uint32_t elapsed_time;
65
+
66
+ Thread tick_thread (osPriorityHigh, TEST_STACK_SIZE);
67
+ tick_thread.start (callback (update_tick_thread, &mutex));
60
68
61
69
greentea_send_kv (" timing_drift_check_start" , 0 );
62
70
@@ -65,28 +73,41 @@ void gt_comm_wait_thread() {
65
73
greentea_parse_kv (_key, _value, sizeof (_key), sizeof (_value));
66
74
expected_key = strcmp (_key, " base_time" );
67
75
} while (expected_key);
68
- greentea_send_kv (_key, callback_trigger_count * ONE_MILLI_SEC);
76
+
77
+ mutex.lock ();
78
+ elapsed_time = elapsed_time_ms;
79
+ mutex.unlock ();
80
+ // send base_time
81
+ greentea_send_kv (_key, elapsed_time * ONE_MILLI_SEC);
69
82
70
83
// wait for 2nd signal from host
71
84
greentea_parse_kv (_key, _value, sizeof (_key), sizeof (_value));
72
- greentea_send_kv (_key, callback_trigger_count * ONE_MILLI_SEC);
85
+
86
+ mutex.lock ();
87
+ elapsed_time = elapsed_time_ms;
88
+ mutex.unlock ();
89
+ // send final_time
90
+ greentea_send_kv (_key, elapsed_time * ONE_MILLI_SEC);
73
91
74
92
// get the results from host
75
93
greentea_parse_kv (_key, _value, sizeof (_key), sizeof (_value));
76
94
77
- if (strcmp (" pass" , _key) == 0 ) {
78
- test_result = true ;
79
- }
95
+ TEST_ASSERT_EQUAL_STRING_MESSAGE (" pass" , _key," Host side script reported a fail..." );
80
96
}
81
97
82
- int main () {
98
+ Case cases[] = {
99
+ Case (" Test Thread::wait accuracy" , test)
100
+ };
101
+
102
+ utest::v1::status_t greentea_test_setup (const size_t number_of_cases)
103
+ {
83
104
GREENTEA_SETUP (test_timeout, " timing_drift_auto" );
84
- Thread tick_thread (osPriorityHigh, TEST_STACK_SIZE );
85
- Thread gt_conn_thread (osPriorityNormal, TEST_STACK_SIZE);
105
+ return utest::v1::greentea_test_setup_handler (number_of_cases );
106
+ }
86
107
87
- tick_thread.start (update_tick_thread);
88
- gt_conn_thread.start (gt_comm_wait_thread);
89
- gt_conn_thread.join ();
108
+ utest::v1::Specification specification (greentea_test_setup, cases);
90
109
91
- GREENTEA_TESTSUITE_RESULT (test_result);
110
+ int main ()
111
+ {
112
+ utest::v1::Harness::run (specification);
92
113
}
0 commit comments