TESTS/mbedmicro-mbed/div/main.cpp@0:0e018d759a2a, 2016-11-08 (annotated)
- Committer:
- switches
- Date:
- Tue Nov 08 18:27:11 2016 +0000
- Revision:
- 0:0e018d759a2a
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:0e018d759a2a | 1 | #include <utility> // std::pair |
switches | 0:0e018d759a2a | 2 | #include "mbed.h" |
switches | 0:0e018d759a2a | 3 | #include "greentea-client/test_env.h" |
switches | 0:0e018d759a2a | 4 | |
switches | 0:0e018d759a2a | 5 | uint32_t test_64(uint64_t ticks) { |
switches | 0:0e018d759a2a | 6 | ticks >>= 3; // divide by 8 |
switches | 0:0e018d759a2a | 7 | if (ticks > 0xFFFFFFFF) { |
switches | 0:0e018d759a2a | 8 | ticks /= 3; |
switches | 0:0e018d759a2a | 9 | } else { |
switches | 0:0e018d759a2a | 10 | ticks = (ticks * 0x55555556) >> 32; // divide by 3 |
switches | 0:0e018d759a2a | 11 | } |
switches | 0:0e018d759a2a | 12 | return (uint32_t)(0xFFFFFFFF & ticks); |
switches | 0:0e018d759a2a | 13 | } |
switches | 0:0e018d759a2a | 14 | |
switches | 0:0e018d759a2a | 15 | const char *result_str(bool result) { |
switches | 0:0e018d759a2a | 16 | return result ? "[OK]" : "[FAIL]"; |
switches | 0:0e018d759a2a | 17 | } |
switches | 0:0e018d759a2a | 18 | |
switches | 0:0e018d759a2a | 19 | int main() { |
switches | 0:0e018d759a2a | 20 | GREENTEA_SETUP(5, "default_auto"); |
switches | 0:0e018d759a2a | 21 | |
switches | 0:0e018d759a2a | 22 | bool result = true; |
switches | 0:0e018d759a2a | 23 | |
switches | 0:0e018d759a2a | 24 | { // 0xFFFFFFFF * 8 = 0x7fffffff8 |
switches | 0:0e018d759a2a | 25 | std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8); |
switches | 0:0e018d759a2a | 26 | uint32_t test_ret = test_64(values.second); |
switches | 0:0e018d759a2a | 27 | bool test_res = values.first == test_ret; |
switches | 0:0e018d759a2a | 28 | result = result && test_res; |
switches | 0:0e018d759a2a | 29 | printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res)); |
switches | 0:0e018d759a2a | 30 | } |
switches | 0:0e018d759a2a | 31 | |
switches | 0:0e018d759a2a | 32 | { // 0xFFFFFFFF * 24 = 0x17ffffffe8 |
switches | 0:0e018d759a2a | 33 | std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8); |
switches | 0:0e018d759a2a | 34 | uint32_t test_ret = test_64(values.second); |
switches | 0:0e018d759a2a | 35 | bool test_res = values.first == test_ret; |
switches | 0:0e018d759a2a | 36 | result = result && test_res; |
switches | 0:0e018d759a2a | 37 | printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res)); |
switches | 0:0e018d759a2a | 38 | } |
switches | 0:0e018d759a2a | 39 | |
switches | 0:0e018d759a2a | 40 | GREENTEA_TESTSUITE_RESULT(result); |
switches | 0:0e018d759a2a | 41 | } |