Christopher Haster 2016-05-16 14:27:54 -05:00
parent 8381fda624
commit f05240b666
3 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,61 @@
#include "toolchain.h"
#include <stdio.h>
#include <stdint.h>
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();
}

View File

@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdint.h>
#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 <int (*F)()>
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<testPacked>),
Case("Testing UNUSED attribute", test_wrapper<testUnused>),
Case("Testing DEPRECATED attribute", test_wrapper<testDeprecated>),
Case("Testing WEAK attribute", test_wrapper<testWeak>),
};
Specification specification(test_setup, cases);
int main() {
return !Harness::run(specification);
}

View File

@ -0,0 +1,10 @@
#include "toolchain.h"
int testWeak1() {
return 0;
}
WEAK int testWeak2() {
return 1;
}