Added MBED_26 Integer constant division test to test suite

pull/258/head
Przemek Wirkus 2014-04-08 12:09:22 +01:00
parent 38f84aa194
commit 5804ee610b
2 changed files with 29 additions and 14 deletions

View File

@ -1,4 +1,6 @@
#include <utility> // std::pair
#include "mbed.h"
#include "test_env.h"
uint32_t test_64(uint64_t ticks) {
ticks >>= 3; // divide by 8
@ -10,18 +12,30 @@ uint32_t test_64(uint64_t ticks) {
return (uint32_t)(0xFFFFFFFF & ticks);
}
int main() {
// 0xFFFFFFFF * 8 = 0x7fffffff8
printf("expected : 55555555\n");
printf("64: 0x7fffffff8: %x\n", test_64(0x7fffffff8));
// 0xFFFFFFFF * 24 = 0x17ffffffe8
printf("expected : ffffffff\n");
printf("64: 0x17ffffffe8: %x\n", test_64(0x17FFFFFFE8));
DigitalOut led(LED1);
while (1) {
led = !led;
wait(0.5);
}
const char *result_str(bool result) {
return result ? "[OK]" : "[FAIL]";
}
int main() {
DigitalOut led(LED1);
bool result = true;
{ // 0xFFFFFFFF * 8 = 0x7fffffff8
std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
uint32_t test_ret = test_64(values.second);
bool test_res = values.first == test_ret;
result = result && test_res;
printf("64bit: 0x7FFFFFFF8: expected 0x%X got 0x%X ... %s\r\n", values.first, test_ret, result_str(test_res));
}
{ // 0xFFFFFFFF * 24 = 0x17ffffffe8
std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
uint32_t test_ret = test_64(values.second);
bool test_res = values.first == test_ret;
result = result && test_res;
printf("64bit: 0x17FFFFFFE8: expected 0x%X got 0x%X ... %s\r\n", values.first, test_ret, result_str(test_res));
}
notify_completion(result);
return 0;
}

View File

@ -423,6 +423,7 @@ TESTS = [
"id": "MBED_26", "description": "Integer constant division",
"source_dir": join(TEST_DIR, "mbed", "div"),
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
"automated": True,
},
{
"id": "MBED_27", "description": "SPI ADXL345",