From 28392245944655e72f7569ca1639d07ee234cb1f Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Wed, 6 Nov 2024 19:18:30 +0100 Subject: [PATCH] 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 --- tests/build_system/xfa/main.c | 7 ++++--- tests/build_system/xfa/tests/01-run.py | 16 ++++++++++------ tests/build_system/xfa/xfatest.h | 1 + tests/build_system/xfa/xfatest1.c | 4 ++-- tests/build_system/xfa/xfatest2.c | 9 +++++++-- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/build_system/xfa/main.c b/tests/build_system/xfa/main.c index 1bd38ce3810b..050e9fcc92d3 100644 --- a/tests/build_system/xfa/main.c +++ b/tests/build_system/xfa/main.c @@ -19,7 +19,6 @@ */ #include -#include #include "xfa.h" @@ -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; diff --git a/tests/build_system/xfa/tests/01-run.py b/tests/build_system/xfa/tests/01-run.py index 88a6425ca4f3..d5c3504fa038 100755 --- a/tests/build_system/xfa/tests/01-run.py +++ b/tests/build_system/xfa/tests/01-run.py @@ -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__": diff --git a/tests/build_system/xfa/xfatest.h b/tests/build_system/xfa/xfatest.h index 1645123c0e36..5935ce58fb02 100644 --- a/tests/build_system/xfa/xfatest.h +++ b/tests/build_system/xfa/xfatest.h @@ -18,6 +18,7 @@ extern "C" { typedef struct { unsigned val; const char *text; + char letter; } xfatest_t; #endif /* DOXYGEN */ diff --git a/tests/build_system/xfa/xfatest1.c b/tests/build_system/xfa/xfatest1.c index ace77dc27284..d16afd06b214 100644 --- a/tests/build_system/xfa/xfatest1.c +++ b/tests/build_system/xfa/xfatest1.c @@ -1,5 +1,5 @@ #include "xfa.h" #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' }; diff --git a/tests/build_system/xfa/xfatest2.c b/tests/build_system/xfa/xfatest2.c index ebf6db651c5e..84afcc6ca825 100644 --- a/tests/build_system/xfa/xfatest2.c +++ b/tests/build_system/xfa/xfatest2.c @@ -1,5 +1,10 @@ #include "xfa.h" #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' }; +XFA_CONST(xfatest_const, 3) xfatest_t _xfatest_const4 = { .val = 44, .text = "xfatest_const4", .letter = 'd' }; +XFA_CONST(xfatest_const, 2) xfatest_t _xfatest_const3 = { .val = 42, .text = "xfatest_const3", .letter = 'c' };