From f05240b666ed71ecfa0e2bfcb4b3d12010bdcd4c Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 16 May 2016 14:27:54 -0500 Subject: [PATCH] Added attribute tests from compiler-polyfill from https://github.com/ARMmbed/compiler-polyfill/tree/master/test/attributes --- hal/TESTS/api/toolchain/attributes.c | 61 ++++++++++++++++++++++++++++ hal/TESTS/api/toolchain/main.cpp | 43 ++++++++++++++++++++ hal/TESTS/api/toolchain/weak.c | 10 +++++ 3 files changed, 114 insertions(+) create mode 100644 hal/TESTS/api/toolchain/attributes.c create mode 100644 hal/TESTS/api/toolchain/main.cpp create mode 100644 hal/TESTS/api/toolchain/weak.c diff --git a/hal/TESTS/api/toolchain/attributes.c b/hal/TESTS/api/toolchain/attributes.c new file mode 100644 index 0000000000..e235477744 --- /dev/null +++ b/hal/TESTS/api/toolchain/attributes.c @@ -0,0 +1,61 @@ +#include "toolchain.h" + +#include +#include + + +struct TestAttrPackedStruct { + char a; + int x; +} PACKED; + +int testPacked() { + int failed = 0; + + if (sizeof(struct TestAttrPackedStruct) != sizeof(int) + sizeof(char)) { + failed++; + } + + return failed; +} + + +int testUnused1(UNUSED int arg) { + return 0; +} + +int testUnused() { + return testUnused1(0); +} + + +DEPRECATED("this message should not be displayed") +void testDeprecatedUnused(); +void testDeprecatedUnused() { } + +DEPRECATED("this message should be displayed") +int testDeprecatedUsed(); +int testDeprecatedUsed() { + return 0; +} + +int testDeprecated() { + return testDeprecatedUsed(); +} + + +int testWeak1(); +int testWeak2(); + +WEAK int testWeak1() { + return 1; +} + +int testWeak2() { + return 0; +} + +int testWeak() { + return testWeak1() | testWeak2(); +} + diff --git a/hal/TESTS/api/toolchain/main.cpp b/hal/TESTS/api/toolchain/main.cpp new file mode 100644 index 0000000000..40ccacb3cd --- /dev/null +++ b/hal/TESTS/api/toolchain/main.cpp @@ -0,0 +1,43 @@ +#include +#include + +#include "toolchain.h" +#include "test_env.h" +#include "unity.h" +#include "utest.h" + +using namespace utest::v1; + + +// Test functions declared as C functions to avoid issues with name mangling +extern "C" { + int testPacked(); + int testUnused(); + int testDeprecated(); + int testWeak(); +} + + +// Test wrapper and test cases for utest +template +void test_wrapper() { + TEST_ASSERT_UNLESS(F()); +} + +status_t test_setup(const size_t number_of_cases) { + GREENTEA_SETUP(40, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +Case cases[] = { + Case("Testing PACKED attribute", test_wrapper), + Case("Testing UNUSED attribute", test_wrapper), + Case("Testing DEPRECATED attribute", test_wrapper), + Case("Testing WEAK attribute", test_wrapper), +}; + +Specification specification(test_setup, cases); + +int main() { + return !Harness::run(specification); +} diff --git a/hal/TESTS/api/toolchain/weak.c b/hal/TESTS/api/toolchain/weak.c new file mode 100644 index 0000000000..d81125573f --- /dev/null +++ b/hal/TESTS/api/toolchain/weak.c @@ -0,0 +1,10 @@ +#include "toolchain.h" + +int testWeak1() { + return 0; +} + +WEAK int testWeak2() { + return 1; +} +