Skip to content

Commit 5804ee6

Browse files
committed
Added MBED_26 Integer constant division test to test suite
1 parent 38f84aa commit 5804ee6

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

libraries/tests/mbed/div/main.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#include <utility> // std::pair
12
#include "mbed.h"
3+
#include "test_env.h"
24

35
uint32_t test_64(uint64_t ticks) {
46
ticks >>= 3; // divide by 8
@@ -10,18 +12,30 @@ uint32_t test_64(uint64_t ticks) {
1012
return (uint32_t)(0xFFFFFFFF & ticks);
1113
}
1214

15+
const char *result_str(bool result) {
16+
return result ? "[OK]" : "[FAIL]";
17+
}
18+
1319
int main() {
14-
// 0xFFFFFFFF * 8 = 0x7fffffff8
15-
printf("expected : 55555555\n");
16-
printf("64: 0x7fffffff8: %x\n", test_64(0x7fffffff8));
17-
18-
// 0xFFFFFFFF * 24 = 0x17ffffffe8
19-
printf("expected : ffffffff\n");
20-
printf("64: 0x17ffffffe8: %x\n", test_64(0x17FFFFFFE8));
21-
2220
DigitalOut led(LED1);
23-
while (1) {
24-
led = !led;
25-
wait(0.5);
21+
bool result = true;
22+
23+
{ // 0xFFFFFFFF * 8 = 0x7fffffff8
24+
std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
25+
uint32_t test_ret = test_64(values.second);
26+
bool test_res = values.first == test_ret;
27+
result = result && test_res;
28+
printf("64bit: 0x7FFFFFFF8: expected 0x%X got 0x%X ... %s\r\n", values.first, test_ret, result_str(test_res));
2629
}
30+
31+
{ // 0xFFFFFFFF * 24 = 0x17ffffffe8
32+
std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
33+
uint32_t test_ret = test_64(values.second);
34+
bool test_res = values.first == test_ret;
35+
result = result && test_res;
36+
printf("64bit: 0x17FFFFFFE8: expected 0x%X got 0x%X ... %s\r\n", values.first, test_ret, result_str(test_res));
37+
}
38+
39+
notify_completion(result);
40+
return 0;
2741
}

workspace_tools/tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@
423423
"id": "MBED_26", "description": "Integer constant division",
424424
"source_dir": join(TEST_DIR, "mbed", "div"),
425425
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
426+
"automated": True,
426427
},
427428
{
428429
"id": "MBED_27", "description": "SPI ADXL345",

0 commit comments

Comments
 (0)