21
21
22
22
#include " mbed.h"
23
23
24
- #if !defined(MBED_CPU_STATS_ENABLED)
24
+ #if !defined(MBED_CPU_STATS_ENABLED) || !defined(DEVICE_LOWPOWERTIMER) || !defined(DEVICE_SLEEP)
25
25
#error [NOT_SUPPORTED] test not supported
26
26
#endif
27
27
@@ -49,31 +49,35 @@ void get_cpu_usage()
49
49
{
50
50
static uint64_t prev_idle_time = 0 ;
51
51
mbed_stats_cpu_t stats;
52
- mbed_stats_cpu_get (&stats);
53
-
54
- uint64_t diff = (stats.idle_time - prev_idle_time);
55
- uint8_t usage = 100 - ((diff * 100 ) / (SAMPLE_TIME * 1000 ));
56
- prev_idle_time = stats.idle_time ;
57
52
58
- TEST_ASSERT_NOT_EQUAL (0 , usage);
53
+ while (1 ) {
54
+ mbed_stats_cpu_get (&stats);
55
+ uint64_t diff = (stats.idle_time - prev_idle_time);
56
+ uint8_t usage = 100 - ((diff * 100 ) / (SAMPLE_TIME * 1000 ));
57
+ prev_idle_time = stats.idle_time ;
58
+ TEST_ASSERT_NOT_EQUAL (0 , usage);
59
+ Thread::wait (SAMPLE_TIME);
60
+ }
59
61
}
60
62
61
63
void test_cpu_info (void )
62
64
{
63
65
mbed_stats_cpu_t stats;
64
- Thread::wait (0.1 );
66
+ Thread::wait (1 );
67
+ mbed_stats_cpu_get (&stats);
65
68
TEST_ASSERT_NOT_EQUAL (0 , stats.uptime );
66
69
TEST_ASSERT_NOT_EQUAL (0 , stats.idle_time );
67
70
return ;
68
71
}
69
72
70
73
void test_cpu_load (void )
71
74
{
72
- EventQueue *stats_queue = mbed_event_queue ();
73
- int id = stats_queue->call_every (SAMPLE_TIME, get_cpu_usage);
75
+
74
76
Thread thread (osPriorityNormal, MAX_THREAD_STACK);
77
+ Thread thread_stats (osPriorityNormal, MAX_THREAD_STACK);
75
78
76
79
thread.start (busy_thread);
80
+ thread_stats.start (get_cpu_usage);
77
81
78
82
// Steadily increase the system load
79
83
for (int count = 1 ; ; count++) {
@@ -84,7 +88,7 @@ void test_cpu_load(void)
84
88
wait_time -= 1000 ; // usec
85
89
}
86
90
thread.terminate ();
87
- stats_queue-> cancel (id );
91
+ thread_stats. terminate ( );
88
92
}
89
93
90
94
Case cases[] = {
0 commit comments