Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testcases fixes #60567

Merged
merged 3 commits into from
Aug 2, 2023
Merged

Conversation

povergoing
Copy link
Member

@povergoing povergoing commented Jul 19, 2023

  1. tests: posix: Fix the testcases by increasing the stack size
    Stack overflows on some arm64 platforms, so increase the stack as it's likely reaching the limit of the stack for most of the platforms.
    setting CONFIG_MAIN_STACK_SIZE=2048 because we observe the following platforms are reaching (some already exceeded) the stack limit (1152):

fvp_baser_aemv8r_smp:

I: Thread analyze:
I:  test_semaphore      : STACK: unused 2224 usage 848 / 3072 (27 %); CPU: 0 %
I:       : Total CPU cycles used: 2758
I:  thread_analyzer     : STACK: unused 3040 usage 1056 / 4096 (25 %); CPU: 0 %
I:       : Total CPU cycles used: 369577
I:  sysworkq            : STACK: unused 3632 usage 464 / 4096 (11 %); CPU: 0 %
I:       : Total CPU cycles used: 0
I:  idle                : STACK: unused 3680 usage 416 / 4096 (10 %); CPU: 98 %
I:       : Total CPU cycles used: 1973276289
I:  main                : STACK: unused 880 usage 1168 / 2048 (57 %); CPU: 0 %
I:       : Total CPU cycles used: 227536
I:  ISR0                : STACK: unused 2832 usage 1264 / 4096 (30 %)

qemu_cortex_a53:

I: Thread analyze:
I:  test_clock          : STACK: unused 2224 usage 848 / 3072 (27 %); CPU: 0 %
I:       : Total CPU cycles used: 2131
I:  thread_analyzer     : STACK: unused 3040 usage 1056 / 4096 (25 %); CPU: 3 %
I:       : Total CPU cycles used: 46296
I:  sysworkq            : STACK: unused 3632 usage 464 / 4096 (11 %); CPU: 0 %
I:       : Total CPU cycles used: 578
I:  idle                : STACK: unused 3888 usage 208 / 4096 (5 %); CPU: 0 %
I:       : Total CPU cycles used: 0
I:  main                : STACK: unused 880 usage 1168 / 2048 (57 %); CPU: 89 %
I:       : Total CPU cycles used: 1132838
I:  ISR0                : STACK: unused 2608 usage 1488 / 4096 (36 %)

qemu_riscv64_smp:

I:  idle 01             : STACK: unused 908 usage 116 / 1024 (11 %); CPU: 0 %
I:       : Total CPU cycles used: 0
START - test_clock
I:  thread_analyzer     : STACK: unused 3180 usage 916 / 4096 (22 %); CPU: 49 %
POSIX clock APIs
I:       : Total CPU cycles used: 24489
I:  sysworkq            : STACK: unused 636 usage 388 / 1024 (37 %); CPU: 4 %
I:       : Total CPU cycles used: 3391
I:  idle 00             : STACK: unused 780 usage 244 / 1024 (23 %); CPU: 0 %
I:       : Total CPU cycles used: 0
I:  main                : STACK: unused 1036 usage 1012 / 2048 (49 %); CPU: 58 %
I:       : Total CPU cycles used: 58270
I:  ISR0                : STACK: unused 1068 usage 980 / 2048 (47 %)
I:  ISR1                : STACK: unused 0 usage 2048 / 2048 (100 %)

qemu_x86_64:

I:  idle 01             : STACK: unused 4056 usage 40 / 4096 (0 %); CPU: 0 %
I:       : Total CPU cycles used: 0
I:  thread_analyzer     : STACK: unused 2976 usage 1120 / 4096 (27 %); CPU: 44 %
I:       : Total CPU cycles used: 168411
I:  sysworkq            : STACK: unused 7760 usage 432 / 8192 (5 %); CPU: 5 %
I:       : Total CPU cycles used: 24049
I:  idle 00             : STACK: unused 3936 usage 160 / 4096 (3 %); CPU: 0 %
I:       : Total CPU cycles used: 0
I:  main                : STACK: unused 1024 usage 1024 / 2048 (50 %); CPU: 238 %
I:       : Total CPU cycles used: 1337891
I:  ISR0                : STACK: unused 14776 usage 1608 / 16384 (9 %)
I:  ISR1                : STACK: unused 15184 usage 1200 / 16384 (7 %)
  1. tests: kernel: spinlock: Fix test_trylock thread reusable issue
    The test_trylock reuses the cpu1_thread, but there is no way for it to exit. This will cause the thread created twice, as a result, two CPU running the same thread simultaneously cause an unexpected crash.
    Analysis:

  2. tests: net: lib: lwm2m: Use 1 cpu only as a workaround
    These testcases are not SMP-safe, and will fail on all SMP boards. Simply turning them to 1cpu test can not fix the issue. So, setting CONFIG_MP_MAX_NUM_CPUS to 1 as a workaround.
    To reproduce:

west build -p always -b qemu_cortex_a53_smp -t run -T zephyr/tests/net/lib/lwm2m/lwm2m_engine/net.lwm2m.lwm2m_engine
west build -p always -b qemu_x86_smp -t run -T zephyr/tests/net/lib/lwm2m/lwm2m_engine/net.lwm2m.lwm2m_engine

carlocaione
carlocaione previously approved these changes Jul 19, 2023
@@ -1,6 +1,7 @@
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_POSIX_API=y
CONFIG_TEST_STACK_SIZE=2048
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide some evidence with reproducibility that the test thread stack overflows? Normally that would be part of a bug report.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might make a mistake about this CONFIG_TEST_STACK_SIZE, I cannot find out why I set it, now remove it.

Comment on lines 215 to 217
trylock_failures = 0;
trylock_successes = 0;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are already zero-initialized with bss. There is no need to do it explicitly here (since they are not shared between tests.

Arguably, the correct place to do this though would be in a setup function as part of the testsuite.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should do it

diff --git a/tests/kernel/spinlock/src/main.c b/tests/kernel/spinlock/src/main.c
index 4ad13373d1..0ab132bf2b 100644
--- a/tests/kernel/spinlock/src/main.c
+++ b/tests/kernel/spinlock/src/main.c
@@ -223,4 +223,11 @@ ZTEST(spinlock, test_trylock)
        zassert_true(trylock_successes > 0);
 }
 
-ZTEST_SUITE(spinlock, NULL, NULL, NULL, NULL, NULL);
+static void before(void *ctx)
+{
+       ARG_UNUSED(ctx);
+
+       bounce_done = 0;
+}
+
+ZTEST_SUITE(spinlock, NULL, NULL, before, NULL, NULL);

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a before() function in the testsuite for reinitializing bounce_done.

provide some evidence (e.g. via bug report, console output, etc).

Fix the testcases failures by increasing the stack size.

Signed-off-by: Jaxson Han <[email protected]>
The test_trylock reuses the cpu1_thread, but there is no way for it to
exit. This will cause the thread created twice, as a result, two cpu
running the same thread simultaneously cause an unexpected crash.

Fix this by adding initialization of resources and also the exit for the
cpu1_thread.

Signed-off-by: Jaxson Han <[email protected]>
These testcases are not SMP-safe, will fail on all SMP boards. Simply
turning them to 1cpu test  can not fix the issue.

So, setting CONFIG_MP_MAX_NUM_CPUS to 1 as a workaround.

Signed-off-by: Jaxson Han <[email protected]>
@povergoing
Copy link
Member Author

use a before() function in the testsuite for reinitializing bounce_done.

provide some evidence (e.g. via bug report, console output, etc).

Added more details in the description

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this one was not being joined properly at some point. Thanks!

@rlubos
Copy link
Contributor

rlubos commented Aug 2, 2023

tests: net: lib: lwm2m: Use 1 cpu only as a workaround
These testcases are not SMP-safe, and will fail on all SMP boards. Simply turning them to 1cpu test can not fix the issue. So, setting CONFIG_MP_MAX_NUM_CPUS to 1 as a workaround.

@povergoing Does executing ztest in SMP environment mean that several tests can run in parallel on different CPUs? If so, then indeed those test may not work in such environment.

@povergoing
Copy link
Member Author

tests: net: lib: lwm2m: Use 1 cpu only as a workaround
These testcases are not SMP-safe, and will fail on all SMP boards. Simply turning them to 1cpu test can not fix the issue. So, setting CONFIG_MP_MAX_NUM_CPUS to 1 as a workaround.

@povergoing Does executing ztest in SMP environment mean that several tests can run in parallel on different CPUs? If so, then indeed those test may not work in such environment.

@rlubos Yes it does. Creating 4 threads at a 4 CPU SMP platform means 4 threads running in parallel and even it does not care about the priority of the threads. So I just set it to one CPU to pass the tests.

@carlescufi carlescufi merged commit 3509f8b into zephyrproject-rtos:main Aug 2, 2023
@povergoing povergoing deleted the testcases_fixes branch August 17, 2023 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants