Skip to content

Commit

Permalink
tests/build_system/xfa: improve test coverage
Browse files Browse the repository at this point in the history
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
  • Loading branch information
maribu committed Nov 6, 2024
1 parent 06aaf64 commit 2839224
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
7 changes: 4 additions & 3 deletions tests/build_system/xfa/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

#include <stdio.h>
#include <stdint.h>

#include "xfa.h"

Expand All @@ -35,12 +34,14 @@ int main(void)
unsigned n = XFA_LEN(xfatest_t, xfatest);
printf("xfatest[%u]:\n", n);
for (unsigned i = 0; i < n; i++) {
printf("[%u] = %u, \"%s\"\n", i, xfatest[i].val, xfatest[i].text);
printf("[%u] = %u, \"%s\", '%c'\n",
i, xfatest[i].val, xfatest[i].text, xfatest[i].letter);
}
n = XFA_LEN(xfatest_t, xfatest_const);
printf("xfatest_const[%u]:\n", n);
for (unsigned i = 0; i < n; i++) {
printf("[%u] = %u, \"%s\"\n", i, xfatest_const[i].val, xfatest_const[i].text);
printf("[%u] = %u, \"%s\", '%c'\n",
i, xfatest_const[i].val, xfatest_const[i].text, xfatest_const[i].letter);
}

return 0;
Expand Down
16 changes: 10 additions & 6 deletions tests/build_system/xfa/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

def testfunc(child):
child.expect_exact('Cross file array test')
child.expect_exact('xfatest[2]:')
child.expect_exact('[0] = 1, "xfatest1"')
child.expect_exact('[1] = 2, "xfatest2"')
child.expect_exact('xfatest_const[2]:')
child.expect_exact('[0] = 123, "xfatest_const1"')
child.expect_exact('[1] = 45, "xfatest_const2"')
child.expect_exact('xfatest[4]:')
child.expect_exact("[0] = 1, \"xfatest1\", 'a'")
child.expect_exact("[1] = 2, \"xfatest2\", 'b'")
child.expect_exact("[2] = 3, \"xfatest3\", 'c'")
child.expect_exact("[3] = 4, \"xfatest4\", 'd'")
child.expect_exact('xfatest_const[4]:')
child.expect_exact("[0] = 123, \"xfatest_const1\", 'a'")
child.expect_exact("[1] = 45, \"xfatest_const2\", 'b'")
child.expect_exact("[2] = 42, \"xfatest_const3\", 'c'")
child.expect_exact("[3] = 44, \"xfatest_const4\", 'd'")


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions tests/build_system/xfa/xfatest.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern "C" {
typedef struct {
unsigned val;
const char *text;
char letter;
} xfatest_t;

#endif /* DOXYGEN */
Expand Down
4 changes: 2 additions & 2 deletions tests/build_system/xfa/xfatest1.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "xfa.h"

Check warning on line 1 in tests/build_system/xfa/xfatest1.c

View workflow job for this annotation

GitHub Actions / static-tests

no copyright notice found
#include "xfatest.h"

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

Check warning on line 5 in tests/build_system/xfa/xfatest1.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
9 changes: 7 additions & 2 deletions tests/build_system/xfa/xfatest2.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "xfa.h"

Check warning on line 1 in tests/build_system/xfa/xfatest2.c

View workflow job for this annotation

GitHub Actions / static-tests

no copyright notice found
#include "xfatest.h"

XFA(xfatest, 0) xfatest_t _xfatest2 = { .val = 2, .text = "xfatest2" };
XFA_CONST(xfatest_const, 0) xfatest_t _xfatest_const2 = { .val = 45, .text = "xfatest_const2" };
XFA(xfatest, 1) xfatest_t _xfatest2 = { .val = 2, .text = "xfatest2", .letter = 'b' };
XFA(xfatest, 3) xfatest_t _xfatest4 = { .val = 4, .text = "xfatest4", .letter = 'd' };
XFA(xfatest, 2) xfatest_t _xfatest3 = { .val = 3, .text = "xfatest3", .letter = 'c' };

XFA_CONST(xfatest_const, 1) xfatest_t _xfatest_const2 = { .val = 45, .text = "xfatest_const2", .letter = 'b' };

Check warning on line 8 in tests/build_system/xfa/xfatest2.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
XFA_CONST(xfatest_const, 3) xfatest_t _xfatest_const4 = { .val = 44, .text = "xfatest_const4", .letter = 'd' };

Check warning on line 9 in tests/build_system/xfa/xfatest2.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
XFA_CONST(xfatest_const, 2) xfatest_t _xfatest_const3 = { .val = 42, .text = "xfatest_const3", .letter = 'c' };

Check warning on line 10 in tests/build_system/xfa/xfatest2.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters

0 comments on commit 2839224

Please sign in to comment.