1
1
/* mbed Microcontroller Library
2
- * Copyright (c) 2017 ARM Limited
2
+ * Copyright (c) 2017-2020 ARM Limited
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
3
5
*
4
6
* Licensed under the Apache License, Version 2.0 (the "License");
5
7
* you may not use this file except in compliance with the License.
16
18
#include < utility> // std::pair
17
19
#include " mbed.h"
18
20
#include " greentea-client/test_env.h"
21
+ #include " utest/utest.h"
22
+ #include " unity/unity.h"
23
+
24
+ using utest::v1::Case;
25
+
26
+ static const int test_timeout = 5 ;
19
27
20
28
uint32_t test_64 (uint64_t ticks)
21
29
{
@@ -28,34 +36,42 @@ uint32_t test_64(uint64_t ticks)
28
36
return (uint32_t )(0xFFFFFFFF & ticks);
29
37
}
30
38
31
- const char *result_str (bool result)
32
- {
33
- return result ? " [OK]" : " [FAIL]" ;
34
- }
35
39
36
- int main ( )
40
+ void test_division ( void )
37
41
{
38
- GREENTEA_SETUP (5 , " default_auto" );
39
-
40
- bool result = true ;
41
42
42
43
{
43
44
// 0xFFFFFFFF * 8 = 0x7fffffff8
44
45
std::pair<uint32_t , uint64_t > values = std::make_pair (0x55555555 , 0x7FFFFFFF8 );
45
46
uint32_t test_ret = test_64 (values.second );
46
- bool test_res = values.first == test_ret;
47
- result = result && test_res;
48
- printf (" 64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n " , values.first , test_ret, result_str (test_res));
47
+ utest_printf (" 64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX \r\n " , values.first , test_ret);
48
+ TEST_ASSERT_EQUAL_UINT32 (values.first , test_ret);
49
49
}
50
50
51
51
{
52
52
// 0xFFFFFFFF * 24 = 0x17ffffffe8
53
53
std::pair<uint32_t , uint64_t > values = std::make_pair (0xFFFFFFFF , 0x17FFFFFFE8 );
54
54
uint32_t test_ret = test_64 (values.second );
55
- bool test_res = values.first == test_ret;
56
- result = result && test_res;
57
- printf (" 64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n " , values.first , test_ret, result_str (test_res));
55
+ utest_printf (" 64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX \r\n " , values.first , test_ret);
56
+ TEST_ASSERT_EQUAL_UINT32 (values.first , test_ret);
58
57
}
59
58
60
- GREENTEA_TESTSUITE_RESULT (result);
59
+ }
60
+
61
+ // Test cases
62
+ Case cases[] = {
63
+ Case (" Test division" , test_division),
64
+ };
65
+
66
+ utest::v1::status_t greentea_test_setup (const size_t number_of_cases)
67
+ {
68
+ GREENTEA_SETUP (test_timeout, " default_auto" );
69
+ return utest::v1::greentea_test_setup_handler (number_of_cases);
70
+ }
71
+
72
+ utest::v1::Specification specification (greentea_test_setup, cases);
73
+
74
+ int main ()
75
+ {
76
+ return !utest::v1::Harness::run (specification);
61
77
}
0 commit comments