1
+ #include < utility> // std::pair
1
2
#include " mbed.h"
3
+ #include " test_env.h"
2
4
3
5
uint32_t test_64 (uint64_t ticks) {
4
6
ticks >>= 3 ; // divide by 8
@@ -10,18 +12,30 @@ uint32_t test_64(uint64_t ticks) {
10
12
return (uint32_t )(0xFFFFFFFF & ticks);
11
13
}
12
14
15
+ const char *result_str (bool result) {
16
+ return result ? " [OK]" : " [FAIL]" ;
17
+ }
18
+
13
19
int main () {
14
- // 0xFFFFFFFF * 8 = 0x7fffffff8
15
- printf (" expected : 55555555\n " );
16
- printf (" 64: 0x7fffffff8: %x\n " , test_64 (0x7fffffff8 ));
17
-
18
- // 0xFFFFFFFF * 24 = 0x17ffffffe8
19
- printf (" expected : ffffffff\n " );
20
- printf (" 64: 0x17ffffffe8: %x\n " , test_64 (0x17FFFFFFE8 ));
21
-
22
20
DigitalOut led (LED1);
23
- while (1 ) {
24
- led = !led;
25
- wait (0.5 );
21
+ bool result = true ;
22
+
23
+ { // 0xFFFFFFFF * 8 = 0x7fffffff8
24
+ std::pair<uint32_t , uint64_t > values = std::make_pair (0x55555555 , 0x7FFFFFFF8 );
25
+ uint32_t test_ret = test_64 (values.second );
26
+ bool test_res = values.first == test_ret;
27
+ result = result && test_res;
28
+ printf (" 64bit: 0x7FFFFFFF8: expected 0x%X got 0x%X ... %s\r\n " , values.first , test_ret, result_str (test_res));
26
29
}
30
+
31
+ { // 0xFFFFFFFF * 24 = 0x17ffffffe8
32
+ std::pair<uint32_t , uint64_t > values = std::make_pair (0xFFFFFFFF , 0x17FFFFFFE8 );
33
+ uint32_t test_ret = test_64 (values.second );
34
+ bool test_res = values.first == test_ret;
35
+ result = result && test_res;
36
+ printf (" 64bit: 0x17FFFFFFE8: expected 0x%X got 0x%X ... %s\r\n " , values.first , test_ret, result_str (test_res));
37
+ }
38
+
39
+ notify_completion (result);
40
+ return 0 ;
27
41
}
0 commit comments