From 32cea97577242466f4e4ccbf8860699c797c340d Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Fri, 19 Dec 2014 15:36:55 +0000 Subject: [PATCH] Added simple tests for BusOut component to check if we can use new features of BusOut::operator[] and DigitalOut::is_connected() --- libraries/tests/mbed/bus_out/main.cpp | 75 +++++++++++++++++++++ libraries/tests/utest/bus/busout_ut.cpp | 87 +++++++++++++++++++++++++ workspace_tools/tests.py | 16 ++++- 3 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 libraries/tests/mbed/bus_out/main.cpp create mode 100644 libraries/tests/utest/bus/busout_ut.cpp diff --git a/libraries/tests/mbed/bus_out/main.cpp b/libraries/tests/mbed/bus_out/main.cpp new file mode 100644 index 0000000000..4f14348604 --- /dev/null +++ b/libraries/tests/mbed/bus_out/main.cpp @@ -0,0 +1,75 @@ +#include "mbed.h" +#include "test_env.h" + +BusOut bus_out(LED1, LED2, LED3, LED4); + +int main() +{ + notify_start(); + + bool result = false; + + for (;;) { + const int mask = bus_out.mask(); + int led_mask = 0x00; + if (LED1 != NC) led_mask |= 0x01; + if (LED2 != NC) led_mask |= 0x02; + if (LED3 != NC) led_mask |= 0x04; + if (LED4 != NC) led_mask |= 0x08; + + printf("MBED: BusIn mask: 0x%X\r\n", mask); + printf("MBED: BusIn LED mask: 0x%X\r\n", led_mask); + + // Let's check bus's connected pins mask + if (mask != led_mask) { + break; + } + + // Checking if DigitalOut is correctly set as connected + for (int i=0; i<4; i++) { + printf("MBED: BusOut.bit[%d] is %s\r\n", i, bus_out[i].is_connected() ? "connected" : "not connected"); + } + + if (LED1 != NC && bus_out[0].is_connected() == 0) { + break; + } + if (LED1 != NC && bus_out[1].is_connected() == 0) { + break; + } + if (LED1 != NC && bus_out[2].is_connected() == 0) { + break; + } + if (LED1 != NC && bus_out[3].is_connected() == 0) { + break; + } + + // Write mask all LEDs + bus_out.write(mask); // Set all LED's pins in high state + if (bus_out.read() != mask) { + break; + } + // Zero all LEDs and see if mask is correctly cleared on all bits + bus_out.write(~mask); + if (bus_out.read() != 0x00) { + break; + } + + result = true; + break; + } + + printf("MBED: Blinking LEDs...\r\n"); + + // Just a quick LED blinking... + for (int i=0; i<4; i++) { + if (bus_out[i].is_connected()) { + bus_out[i] = 1; + } + wait(0.2); + if (bus_out[i].is_connected()) { + bus_out[i] = 0; + } + } + + notify_completion(result); +} diff --git a/libraries/tests/utest/bus/busout_ut.cpp b/libraries/tests/utest/bus/busout_ut.cpp new file mode 100644 index 0000000000..d7f2a408df --- /dev/null +++ b/libraries/tests/utest/bus/busout_ut.cpp @@ -0,0 +1,87 @@ +#include "TestHarness.h" +#include +#include "mbed.h" + +TEST_GROUP(BusOut_mask) +{ +}; + +TEST(BusOut_mask, led_1_2_3) +{ + BusOut bus_data(LED1, LED2, LED3); + CHECK_EQUAL(0x07, bus_data.mask()); +} + +TEST(BusOut_mask, led_nc_nc_nc_nc) +{ + BusOut bus_data(NC, NC, NC, NC); + CHECK_EQUAL(0x00, bus_data.mask()); +} + +TEST(BusOut_mask, led_1_2_3_nc_nc) +{ + BusOut bus_data(LED1, LED2, LED3, NC, NC); + CHECK_EQUAL(0x07, bus_data.mask()); +} + +TEST(BusOut_mask, led_1_nc_2_nc_nc_3) +{ + BusOut bus_data(LED1, NC, LED2, NC, NC, LED3); + CHECK_EQUAL(0x25, bus_data.mask()); +} + +/////////////////////////////////////////////////////////////////////////////// + +TEST_GROUP(BusOut_dummy) +{ +}; + +TEST(BusOut_dummy, dummy) +{ +} + +#ifdef MBED_OPERATORS +TEST_GROUP(BusOut_digitalout_write) +{ +}; + +TEST(BusOut_digitalout_write, led_nc) +{ + BusOut bus_data(NC); + CHECK_EQUAL(false, bus_data[0].is_connected()) +} + + +TEST(BusOut_digitalout_write, led_1_2_3) +{ + BusOut bus_data(LED1, LED2, LED3); + bus_data[0].write(1); + bus_data[1].write(1); + bus_data[2].write(1); + CHECK(bus_data[0].read()); + CHECK(bus_data[1].read()); + CHECK(bus_data[2].read()); +} + +TEST(BusOut_digitalout_write, led_1_2_3_nc_nc) +{ + BusOut bus_data(LED1, LED2, LED3, NC, NC); + bus_data[0].write(0); + bus_data[1].write(0); + bus_data[2].write(0); + CHECK(bus_data[0].read() == 0); + CHECK(bus_data[1].read() == 0); + CHECK(bus_data[2].read() == 0); +} + +TEST(BusOut_digitalout_write, led_1_nc_2_nc_nc_3) +{ + BusOut bus_data(LED1, NC, LED2, NC, NC, LED3); + bus_data[0].write(1); + bus_data[2].write(0); + bus_data[5].write(0); + CHECK(bus_data[0].read()); + CHECK(bus_data[2].read() == 0); + CHECK(bus_data[5].read() == 0); +} +#endif diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index dd8ed79c90..e6d27cbbda 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -262,6 +262,14 @@ TESTS = [ "duration": 15, }, + { + "id": "MBED_BUSOUT", "description": "BusOut", + "source_dir": join(TEST_DIR, "mbed", "bus_out"), + "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], + "automated": True, + "duration": 15, + }, + # Size benchmarks { "id": "BENCHMARK_1", "description": "Size (c environment)", @@ -527,7 +535,7 @@ TESTS = [ "automated": True, "host_test": "wait_us_auto" }, - + # CMSIS RTOS tests { @@ -899,6 +907,12 @@ TESTS = [ "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, CPPUTEST_LIBRARY], "automated": False, }, + { + "id": "UT_BUSIO", "description": "BusIn BusOut", + "source_dir": join(TEST_DIR, "utest", "bus"), + "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, CPPUTEST_LIBRARY], + "automated": False, + }, # Tests used for target information purposes {