mbed-os
Fork of mbed-os by
features/unsupported/tests/utest/general/general.cpp@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | #include "TestHarness.h" |
elessair | 0:f269e3021894 | 2 | #include <utility> |
elessair | 0:f269e3021894 | 3 | #include "mbed.h" |
elessair | 0:f269e3021894 | 4 | |
elessair | 0:f269e3021894 | 5 | TEST_GROUP(Integer_Constant_Division) |
elessair | 0:f269e3021894 | 6 | { |
elessair | 0:f269e3021894 | 7 | uint32_t test_64(uint64_t ticks) { |
elessair | 0:f269e3021894 | 8 | ticks >>= 3; // divide by 8 |
elessair | 0:f269e3021894 | 9 | if (ticks > 0xFFFFFFFF) { |
elessair | 0:f269e3021894 | 10 | ticks /= 3; |
elessair | 0:f269e3021894 | 11 | } else { |
elessair | 0:f269e3021894 | 12 | ticks = (ticks * 0x55555556) >> 32; // divide by 3 |
elessair | 0:f269e3021894 | 13 | } |
elessair | 0:f269e3021894 | 14 | return (uint32_t)(0xFFFFFFFF & ticks); |
elessair | 0:f269e3021894 | 15 | } |
elessair | 0:f269e3021894 | 16 | }; |
elessair | 0:f269e3021894 | 17 | |
elessair | 0:f269e3021894 | 18 | // 0xFFFFFFFF * 8 = 0x7fffffff8 |
elessair | 0:f269e3021894 | 19 | TEST(Integer_Constant_Division, Divide_By_8) |
elessair | 0:f269e3021894 | 20 | { |
elessair | 0:f269e3021894 | 21 | std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8); |
elessair | 0:f269e3021894 | 22 | uint32_t test_ret = test_64(values.second); |
elessair | 0:f269e3021894 | 23 | CHECK_EQUAL(values.first, test_ret); |
elessair | 0:f269e3021894 | 24 | } |
elessair | 0:f269e3021894 | 25 | |
elessair | 0:f269e3021894 | 26 | // 0xFFFFFFFF * 24 = 0x17ffffffe8 |
elessair | 0:f269e3021894 | 27 | TEST(Integer_Constant_Division, Divide_By_24) |
elessair | 0:f269e3021894 | 28 | { |
elessair | 0:f269e3021894 | 29 | std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8); |
elessair | 0:f269e3021894 | 30 | uint32_t test_ret = test_64(values.second); |
elessair | 0:f269e3021894 | 31 | CHECK_EQUAL(values.first, test_ret); |
elessair | 0:f269e3021894 | 32 | } |
elessair | 0:f269e3021894 | 33 | |
elessair | 0:f269e3021894 | 34 | TEST_GROUP(RTC_Test) |
elessair | 0:f269e3021894 | 35 | { |
elessair | 0:f269e3021894 | 36 | char buffer[32]; |
elessair | 0:f269e3021894 | 37 | const int CUSTOM_TIME = 1256729737; |
elessair | 0:f269e3021894 | 38 | }; |
elessair | 0:f269e3021894 | 39 | |
elessair | 0:f269e3021894 | 40 | TEST(RTC_Test, Check_Set_Time) |
elessair | 0:f269e3021894 | 41 | { |
elessair | 0:f269e3021894 | 42 | set_time(CUSTOM_TIME); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
elessair | 0:f269e3021894 | 43 | time_t seconds = time(NULL); |
elessair | 0:f269e3021894 | 44 | strftime(buffer, 32, "%Y-%m-%d %H:%M:%S %p", localtime(&seconds)); |
elessair | 0:f269e3021894 | 45 | STRCMP_EQUAL(buffer, "2009-10-28 11:35:37 AM"); |
elessair | 0:f269e3021894 | 46 | } |
elessair | 0:f269e3021894 | 47 | |
elessair | 0:f269e3021894 | 48 | TEST_GROUP(C_String_Format) |
elessair | 0:f269e3021894 | 49 | { |
elessair | 0:f269e3021894 | 50 | char buffer[256]; |
elessair | 0:f269e3021894 | 51 | }; |
elessair | 0:f269e3021894 | 52 | |
elessair | 0:f269e3021894 | 53 | #define POSITIVE_INTEGERS 32768,3214,999,100,1,0,1,4231,999,4123,32760,99999 |
elessair | 0:f269e3021894 | 54 | TEST(C_String_Format, Sprintf_Positive_Integers) |
elessair | 0:f269e3021894 | 55 | { |
elessair | 0:f269e3021894 | 56 | sprintf(buffer, "%u %d %u %d %u %d %u %d %u %d %u %d", POSITIVE_INTEGERS); |
elessair | 0:f269e3021894 | 57 | STRCMP_EQUAL(buffer, "32768 3214 999 100 1 0 1 4231 999 4123 32760 99999"); |
elessair | 0:f269e3021894 | 58 | } |
elessair | 0:f269e3021894 | 59 | |
elessair | 0:f269e3021894 | 60 | #define NEGATIVE_INTEGERS -32768,-3214,-999,-100,-1,0,-1,-4231,-999,-4123,-32760,-99999 |
elessair | 0:f269e3021894 | 61 | TEST(C_String_Format, Sprintf_Negative_Integers) |
elessair | 0:f269e3021894 | 62 | { |
elessair | 0:f269e3021894 | 63 | sprintf(buffer, "%i %d %i %d %i %d %i %d %i %d %i %i", NEGATIVE_INTEGERS); |
elessair | 0:f269e3021894 | 64 | STRCMP_EQUAL(buffer, "-32768 -3214 -999 -100 -1 0 -1 -4231 -999 -4123 -32760 -99999"); |
elessair | 0:f269e3021894 | 65 | } |
elessair | 0:f269e3021894 | 66 | |
elessair | 0:f269e3021894 | 67 | #ifdef DEVICE_SEMIHOST |
elessair | 0:f269e3021894 | 68 | #include "semihost_api.h" |
elessair | 0:f269e3021894 | 69 | |
elessair | 0:f269e3021894 | 70 | TEST_GROUP(Device_Semihost) |
elessair | 0:f269e3021894 | 71 | { |
elessair | 0:f269e3021894 | 72 | char uid[48]; |
elessair | 0:f269e3021894 | 73 | }; |
elessair | 0:f269e3021894 | 74 | |
elessair | 0:f269e3021894 | 75 | TEST(Device_Semihost, semihost_connected) |
elessair | 0:f269e3021894 | 76 | { |
elessair | 0:f269e3021894 | 77 | CHECK(semihost_connected()); |
elessair | 0:f269e3021894 | 78 | } |
elessair | 0:f269e3021894 | 79 | |
elessair | 0:f269e3021894 | 80 | TEST(Device_Semihost, mbed_interface_connected) |
elessair | 0:f269e3021894 | 81 | { |
elessair | 0:f269e3021894 | 82 | CHECK(mbed_interface_connected()); |
elessair | 0:f269e3021894 | 83 | } |
elessair | 0:f269e3021894 | 84 | |
elessair | 0:f269e3021894 | 85 | TEST(Device_Semihost, mbed_interface_uid) |
elessair | 0:f269e3021894 | 86 | { |
elessair | 0:f269e3021894 | 87 | CHECK_EQUAL(mbed_interface_uid(uid), 0); |
elessair | 0:f269e3021894 | 88 | } |
elessair | 0:f269e3021894 | 89 | |
elessair | 0:f269e3021894 | 90 | #endif |