aboutsummaryrefslogtreecommitdiffstats
path: root/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest')
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/basic/basic.cpp13
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/bus/busout_ut.cpp87
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/general/general.cpp90
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/semihost_fs/semihost_fs.cpp63
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/testrunner/testrunner.cpp29
-rw-r--r--tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/testrunner/testrunner.h4
6 files changed, 286 insertions, 0 deletions
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/basic/basic.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/basic/basic.cpp
new file mode 100644
index 000000000..92d77cbc0
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/basic/basic.cpp
@@ -0,0 +1,13 @@
+#include "TestHarness.h"
+
+TEST_GROUP(FirstTestGroup)
+{
+};
+
+TEST(FirstTestGroup, FirstTest)
+{
+ /* These checks are here to make sure assertions outside test runs don't crash */
+ CHECK(true);
+ LONGS_EQUAL(1, 1);
+ STRCMP_EQUAL("mbed SDK!", "mbed SDK!");
+} \ No newline at end of file
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/bus/busout_ut.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/bus/busout_ut.cpp
new file mode 100644
index 000000000..d7f2a408d
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/bus/busout_ut.cpp
@@ -0,0 +1,87 @@
+#include "TestHarness.h"
+#include <utility>
+#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/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/general/general.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/general/general.cpp
new file mode 100644
index 000000000..ba56a0f18
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/general/general.cpp
@@ -0,0 +1,90 @@
+#include "TestHarness.h"
+#include <utility>
+#include "mbed.h"
+
+TEST_GROUP(Integer_Constant_Division)
+{
+ uint32_t test_64(uint64_t ticks) {
+ ticks >>= 3; // divide by 8
+ if (ticks > 0xFFFFFFFF) {
+ ticks /= 3;
+ } else {
+ ticks = (ticks * 0x55555556) >> 32; // divide by 3
+ }
+ return (uint32_t)(0xFFFFFFFF & ticks);
+ }
+};
+
+// 0xFFFFFFFF * 8 = 0x7fffffff8
+TEST(Integer_Constant_Division, Divide_By_8)
+{
+ std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
+ uint32_t test_ret = test_64(values.second);
+ CHECK_EQUAL(values.first, test_ret);
+}
+
+// 0xFFFFFFFF * 24 = 0x17ffffffe8
+TEST(Integer_Constant_Division, Divide_By_24)
+{
+ std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
+ uint32_t test_ret = test_64(values.second);
+ CHECK_EQUAL(values.first, test_ret);
+}
+
+TEST_GROUP(RTC_Test)
+{
+ char buffer[32];
+ const int CUSTOM_TIME = 1256729737;
+};
+
+TEST(RTC_Test, Check_Set_Time)
+{
+ set_time(CUSTOM_TIME); // Set RTC time to Wed, 28 Oct 2009 11:35:37
+ time_t seconds = time(NULL);
+ strftime(buffer, 32, "%Y-%m-%d %H:%M:%S %p", localtime(&seconds));
+ STRCMP_EQUAL(buffer, "2009-10-28 11:35:37 AM");
+}
+
+TEST_GROUP(C_String_Format)
+{
+ char buffer[256];
+};
+
+#define POSITIVE_INTEGERS 32768,3214,999,100,1,0,1,4231,999,4123,32760,99999
+TEST(C_String_Format, Sprintf_Positive_Integers)
+{
+ sprintf(buffer, "%u %d %u %d %u %d %u %d %u %d %u %d", POSITIVE_INTEGERS);
+ STRCMP_EQUAL(buffer, "32768 3214 999 100 1 0 1 4231 999 4123 32760 99999");
+}
+
+#define NEGATIVE_INTEGERS -32768,-3214,-999,-100,-1,0,-1,-4231,-999,-4123,-32760,-99999
+TEST(C_String_Format, Sprintf_Negative_Integers)
+{
+ sprintf(buffer, "%i %d %i %d %i %d %i %d %i %d %i %i", NEGATIVE_INTEGERS);
+ STRCMP_EQUAL(buffer, "-32768 -3214 -999 -100 -1 0 -1 -4231 -999 -4123 -32760 -99999");
+}
+
+#ifdef DEVICE_SEMIHOST
+#include "semihost_api.h"
+
+TEST_GROUP(Device_Semihost)
+{
+ char uid[48];
+};
+
+TEST(Device_Semihost, semihost_connected)
+{
+ CHECK(semihost_connected());
+}
+
+TEST(Device_Semihost, mbed_interface_connected)
+{
+ CHECK(mbed_interface_connected());
+}
+
+TEST(Device_Semihost, mbed_interface_uid)
+{
+ CHECK_EQUAL(mbed_interface_uid(uid), 0);
+}
+
+#endif
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/semihost_fs/semihost_fs.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/semihost_fs/semihost_fs.cpp
new file mode 100644
index 000000000..adb49025f
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/semihost_fs/semihost_fs.cpp
@@ -0,0 +1,63 @@
+#include "TestHarness.h"
+#include "mbed.h"
+#include "semihost_api.h"
+#include <stdio.h>
+
+#define FILENAME "/local/out.txt"
+#define TEST_STRING "Hello World!"
+
+TEST_GROUP(FirstTestGroup)
+{
+
+ FILE *test_open(const char *mode) {
+ FILE *f = fopen(FILENAME, mode);
+ return f;
+ }
+
+ bool test_write(FILE *f, char *str, int str_len) {
+ int n = fprintf(f, str);
+ return (n == str_len) ? true : false;
+ }
+
+ bool test_read(FILE *f, char *str, int str_len) {
+ int n = fread(str, sizeof(unsigned char), str_len, f);
+ return (n == str_len) ? true : false;
+ }
+
+ bool test_close(FILE *f) {
+ int rc = fclose(f);
+ return rc ? true : false;
+ }
+
+};
+
+TEST(FirstTestGroup, FirstTest)
+{
+ CHECK_TEXT(semihost_connected(), "Semihost not connected")
+
+ LocalFileSystem local("local");
+
+ char *str = TEST_STRING;
+ char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING));
+ int str_len = strlen(TEST_STRING);
+
+ CHECK_TEXT(buffer != NULL, "Buffer allocation failed");
+ CHECK_TEXT(str_len > 0, "Test string is empty (len <= 0)");
+
+ {
+ // Perform write / read tests
+ FILE *f = NULL;
+ // Write
+ f = test_open("w");
+ CHECK_TEXT(f != NULL, "Error opening file for writing")
+ CHECK_TEXT(test_write(f, str, str_len), "Error writing file");
+ CHECK_TEXT(test_close(f) != EOF, "Error closing file after write");
+
+ // Read
+ f = test_open("r");
+ CHECK_TEXT(f != NULL, "Error opening file for reading")
+ CHECK_TEXT(test_read(f, buffer, str_len), "Error reading file");
+ CHECK_TEXT(test_close(f) != EOF, "Error closing file after read");
+ }
+ CHECK(strncmp(buffer, str, str_len) == 0);
+}
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/testrunner/testrunner.cpp b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/testrunner/testrunner.cpp
new file mode 100644
index 000000000..2c1969ce0
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/testrunner/testrunner.cpp
@@ -0,0 +1,29 @@
+#include "CommandLineTestRunner.h"
+#include <stdio.h>
+#include "mbed.h"
+#include "testrunner.h"
+#include "test_env.h"
+
+/**
+Object 'mbed_cpputest_console' is used to show prints on console.
+It is declared in \cpputest\src\Platforms\armcc\UtestPlatform.cpp
+*/
+Serial mbed_cpputest_console(STDIO_UART_TX, STDIO_UART_RX);
+
+int main(int ac, char** av) {
+ MBED_HOSTTEST_TIMEOUT(20);
+ MBED_HOSTTEST_SELECT(default_auto);
+ MBED_HOSTTEST_DESCRIPTION(Unit test);
+ MBED_HOSTTEST_START("UT");
+
+ unsigned failureCount = 0;
+ {
+ // Some compilers may not pass ac, av so we need to supply them ourselves
+ int ac = 2;
+ char* av[] = {__FILE__, "-v"};
+ failureCount = CommandLineTestRunner::RunAllTests(ac, av);
+ }
+
+ MBED_HOSTTEST_RESULT(failureCount == 0);
+ return failureCount;
+}
diff --git a/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/testrunner/testrunner.h b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/testrunner/testrunner.h
new file mode 100644
index 000000000..b36c1bfc9
--- /dev/null
+++ b/tmk_core/tool/mbed/mbed-sdk/libraries/tests/utest/testrunner/testrunner.h
@@ -0,0 +1,4 @@
+#ifndef TEST_RUNNER_H_
+#define TEST_RUNNER_H_
+
+#endif