11/* mbed Microcontroller Library
2- * Copyright (c) 2017 ARM Limited
2+ * Copyright (c) 2017-2020 ARM Limited
3+ *
4+ * SPDX-License-Identifier: Apache-2.0
35 *
46 * Licensed under the Apache License, Version 2.0 (the "License");
57 * you may not use this file except in compliance with the License.
1618#include < utility> // std::pair
1719#include " mbed.h"
1820#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 ;
1927
2028uint32_t test_64 (uint64_t ticks)
2129{
@@ -28,34 +36,42 @@ uint32_t test_64(uint64_t ticks)
2836 return (uint32_t )(0xFFFFFFFF & ticks);
2937}
3038
31- const char *result_str (bool result)
32- {
33- return result ? " [OK]" : " [FAIL]" ;
34- }
3539
36- int main ( )
40+ void test_division ( void )
3741{
38- GREENTEA_SETUP (5 , " default_auto" );
39-
40- bool result = true ;
4142
4243 {
4344 // 0xFFFFFFFF * 8 = 0x7fffffff8
4445 std::pair<uint32_t , uint64_t > values = std::make_pair (0x55555555 , 0x7FFFFFFF8 );
4546 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);
4949 }
5050
5151 {
5252 // 0xFFFFFFFF * 24 = 0x17ffffffe8
5353 std::pair<uint32_t , uint64_t > values = std::make_pair (0xFFFFFFFF , 0x17FFFFFFE8 );
5454 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);
5857 }
5958
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);
6177}
0 commit comments