Skip to content

Commit 2839224

Browse files
committed
tests/build_system/xfa: improve test coverage
This increases the test coverage for XFA: - Multiple entries are added from a single file - Priorities are assigned to enforce a given order - The size of the `struct` to add is changed to no longer be a power of 2
1 parent 06aaf64 commit 2839224

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

tests/build_system/xfa/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020

2121
#include <stdio.h>
22-
#include <stdint.h>
2322

2423
#include "xfa.h"
2524

@@ -35,12 +34,14 @@ int main(void)
3534
unsigned n = XFA_LEN(xfatest_t, xfatest);
3635
printf("xfatest[%u]:\n", n);
3736
for (unsigned i = 0; i < n; i++) {
38-
printf("[%u] = %u, \"%s\"\n", i, xfatest[i].val, xfatest[i].text);
37+
printf("[%u] = %u, \"%s\", '%c'\n",
38+
i, xfatest[i].val, xfatest[i].text, xfatest[i].letter);
3939
}
4040
n = XFA_LEN(xfatest_t, xfatest_const);
4141
printf("xfatest_const[%u]:\n", n);
4242
for (unsigned i = 0; i < n; i++) {
43-
printf("[%u] = %u, \"%s\"\n", i, xfatest_const[i].val, xfatest_const[i].text);
43+
printf("[%u] = %u, \"%s\", '%c'\n",
44+
i, xfatest_const[i].val, xfatest_const[i].text, xfatest_const[i].letter);
4445
}
4546

4647
return 0;

tests/build_system/xfa/tests/01-run.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414

1515
def testfunc(child):
1616
child.expect_exact('Cross file array test')
17-
child.expect_exact('xfatest[2]:')
18-
child.expect_exact('[0] = 1, "xfatest1"')
19-
child.expect_exact('[1] = 2, "xfatest2"')
20-
child.expect_exact('xfatest_const[2]:')
21-
child.expect_exact('[0] = 123, "xfatest_const1"')
22-
child.expect_exact('[1] = 45, "xfatest_const2"')
17+
child.expect_exact('xfatest[4]:')
18+
child.expect_exact("[0] = 1, \"xfatest1\", 'a'")
19+
child.expect_exact("[1] = 2, \"xfatest2\", 'b'")
20+
child.expect_exact("[2] = 3, \"xfatest3\", 'c'")
21+
child.expect_exact("[3] = 4, \"xfatest4\", 'd'")
22+
child.expect_exact('xfatest_const[4]:')
23+
child.expect_exact("[0] = 123, \"xfatest_const1\", 'a'")
24+
child.expect_exact("[1] = 45, \"xfatest_const2\", 'b'")
25+
child.expect_exact("[2] = 42, \"xfatest_const3\", 'c'")
26+
child.expect_exact("[3] = 44, \"xfatest_const4\", 'd'")
2327

2428

2529
if __name__ == "__main__":

tests/build_system/xfa/xfatest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern "C" {
1818
typedef struct {
1919
unsigned val;
2020
const char *text;
21+
char letter;
2122
} xfatest_t;
2223

2324
#endif /* DOXYGEN */

tests/build_system/xfa/xfatest1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "xfa.h"
22
#include "xfatest.h"
33

4-
XFA(xfatest, 0) xfatest_t _xfatest1 = { .val = 1, .text = "xfatest1" };
5-
XFA_CONST(xfatest_const, 0) xfatest_t _xfatest_const1 = { .val = 123, .text = "xfatest_const1" };
4+
XFA(xfatest, 0) xfatest_t _xfatest1 = { .val = 1, .text = "xfatest1", .letter = 'a' };
5+
XFA_CONST(xfatest_const, 0) xfatest_t _xfatest_const1 = { .val = 123, .text = "xfatest_const1", .letter = 'a' };

tests/build_system/xfa/xfatest2.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#include "xfa.h"
22
#include "xfatest.h"
33

4-
XFA(xfatest, 0) xfatest_t _xfatest2 = { .val = 2, .text = "xfatest2" };
5-
XFA_CONST(xfatest_const, 0) xfatest_t _xfatest_const2 = { .val = 45, .text = "xfatest_const2" };
4+
XFA(xfatest, 1) xfatest_t _xfatest2 = { .val = 2, .text = "xfatest2", .letter = 'b' };
5+
XFA(xfatest, 3) xfatest_t _xfatest4 = { .val = 4, .text = "xfatest4", .letter = 'd' };
6+
XFA(xfatest, 2) xfatest_t _xfatest3 = { .val = 3, .text = "xfatest3", .letter = 'c' };
7+
8+
XFA_CONST(xfatest_const, 1) xfatest_t _xfatest_const2 = { .val = 45, .text = "xfatest_const2", .letter = 'b' };
9+
XFA_CONST(xfatest_const, 3) xfatest_t _xfatest_const4 = { .val = 44, .text = "xfatest_const4", .letter = 'd' };
10+
XFA_CONST(xfatest_const, 2) xfatest_t _xfatest_const3 = { .val = 42, .text = "xfatest_const3", .letter = 'c' };

0 commit comments

Comments
 (0)