mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 #include <utility> // std::pair
elessair 0:f269e3021894 2 #include "mbed.h"
elessair 0:f269e3021894 3 #include "test_env.h"
elessair 0:f269e3021894 4
elessair 0:f269e3021894 5 uint32_t test_64(uint64_t ticks) {
elessair 0:f269e3021894 6 ticks >>= 3; // divide by 8
elessair 0:f269e3021894 7 if (ticks > 0xFFFFFFFF) {
elessair 0:f269e3021894 8 ticks /= 3;
elessair 0:f269e3021894 9 } else {
elessair 0:f269e3021894 10 ticks = (ticks * 0x55555556) >> 32; // divide by 3
elessair 0:f269e3021894 11 }
elessair 0:f269e3021894 12 return (uint32_t)(0xFFFFFFFF & ticks);
elessair 0:f269e3021894 13 }
elessair 0:f269e3021894 14
elessair 0:f269e3021894 15 const char *result_str(bool result) {
elessair 0:f269e3021894 16 return result ? "[OK]" : "[FAIL]";
elessair 0:f269e3021894 17 }
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 int main() {
elessair 0:f269e3021894 20 MBED_HOSTTEST_TIMEOUT(20);
elessair 0:f269e3021894 21 MBED_HOSTTEST_SELECT(default_auto);
elessair 0:f269e3021894 22 MBED_HOSTTEST_DESCRIPTION(Integer constant division);
elessair 0:f269e3021894 23 MBED_HOSTTEST_START("MBED_26");
elessair 0:f269e3021894 24
elessair 0:f269e3021894 25 bool result = true;
elessair 0:f269e3021894 26
elessair 0:f269e3021894 27 { // 0xFFFFFFFF * 8 = 0x7fffffff8
elessair 0:f269e3021894 28 std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
elessair 0:f269e3021894 29 uint32_t test_ret = test_64(values.second);
elessair 0:f269e3021894 30 bool test_res = values.first == test_ret;
elessair 0:f269e3021894 31 result = result && test_res;
elessair 0:f269e3021894 32 printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
elessair 0:f269e3021894 33 }
elessair 0:f269e3021894 34
elessair 0:f269e3021894 35 { // 0xFFFFFFFF * 24 = 0x17ffffffe8
elessair 0:f269e3021894 36 std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
elessair 0:f269e3021894 37 uint32_t test_ret = test_64(values.second);
elessair 0:f269e3021894 38 bool test_res = values.first == test_ret;
elessair 0:f269e3021894 39 result = result && test_res;
elessair 0:f269e3021894 40 printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
elessair 0:f269e3021894 41 }
elessair 0:f269e3021894 42
elessair 0:f269e3021894 43 MBED_HOSTTEST_RESULT(result);
elessair 0:f269e3021894 44 }