Skip to content

Commit f05240b

Browse files
committed
Added attribute tests from compiler-polyfill
from https://github.com/ARMmbed/compiler-polyfill/tree/master/test/attributes
1 parent 8381fda commit f05240b

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

hal/TESTS/api/toolchain/attributes.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "toolchain.h"
2+
3+
#include <stdio.h>
4+
#include <stdint.h>
5+
6+
7+
struct TestAttrPackedStruct {
8+
char a;
9+
int x;
10+
} PACKED;
11+
12+
int testPacked() {
13+
int failed = 0;
14+
15+
if (sizeof(struct TestAttrPackedStruct) != sizeof(int) + sizeof(char)) {
16+
failed++;
17+
}
18+
19+
return failed;
20+
}
21+
22+
23+
int testUnused1(UNUSED int arg) {
24+
return 0;
25+
}
26+
27+
int testUnused() {
28+
return testUnused1(0);
29+
}
30+
31+
32+
DEPRECATED("this message should not be displayed")
33+
void testDeprecatedUnused();
34+
void testDeprecatedUnused() { }
35+
36+
DEPRECATED("this message should be displayed")
37+
int testDeprecatedUsed();
38+
int testDeprecatedUsed() {
39+
return 0;
40+
}
41+
42+
int testDeprecated() {
43+
return testDeprecatedUsed();
44+
}
45+
46+
47+
int testWeak1();
48+
int testWeak2();
49+
50+
WEAK int testWeak1() {
51+
return 1;
52+
}
53+
54+
int testWeak2() {
55+
return 0;
56+
}
57+
58+
int testWeak() {
59+
return testWeak1() | testWeak2();
60+
}
61+

hal/TESTS/api/toolchain/main.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <stdio.h>
2+
#include <stdint.h>
3+
4+
#include "toolchain.h"
5+
#include "test_env.h"
6+
#include "unity.h"
7+
#include "utest.h"
8+
9+
using namespace utest::v1;
10+
11+
12+
// Test functions declared as C functions to avoid issues with name mangling
13+
extern "C" {
14+
int testPacked();
15+
int testUnused();
16+
int testDeprecated();
17+
int testWeak();
18+
}
19+
20+
21+
// Test wrapper and test cases for utest
22+
template <int (*F)()>
23+
void test_wrapper() {
24+
TEST_ASSERT_UNLESS(F());
25+
}
26+
27+
status_t test_setup(const size_t number_of_cases) {
28+
GREENTEA_SETUP(40, "default_auto");
29+
return verbose_test_setup_handler(number_of_cases);
30+
}
31+
32+
Case cases[] = {
33+
Case("Testing PACKED attribute", test_wrapper<testPacked>),
34+
Case("Testing UNUSED attribute", test_wrapper<testUnused>),
35+
Case("Testing DEPRECATED attribute", test_wrapper<testDeprecated>),
36+
Case("Testing WEAK attribute", test_wrapper<testWeak>),
37+
};
38+
39+
Specification specification(test_setup, cases);
40+
41+
int main() {
42+
return !Harness::run(specification);
43+
}

hal/TESTS/api/toolchain/weak.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "toolchain.h"
2+
3+
int testWeak1() {
4+
return 0;
5+
}
6+
7+
WEAK int testWeak2() {
8+
return 1;
9+
}
10+

0 commit comments

Comments
 (0)