-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
tests: ztest: provide test execution times per ztest testcase #33014
tests: ztest: provide test execution times per ztest testcase #33014
Conversation
01c55db
to
d047984
Compare
d047984
to
a2c51c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the implementation doesn't bring exactly what was required in the feature. Currently, the printed time per test case is not the execution time of the test case but the time from the start of the whole test suite till the test case finishes. E.g check calling test from /tests/kernel/sleep. Test case
test_usleep` shows that it took 2 seconds but in the calculated time it shows 4.420:
DEBUG - DEVICE: *** Booting Zephyr OS build zephyr-v2.5.0-887-ga2c51c22e6d2 ***
DEBUG - DEVICE: Running test suite sleep
DEBUG - DEVICE: ===================================================================
DEBUG - DEVICE: START - test_sleep
DEBUG - DEVICE: Kernel objects initialized
DEBUG - DEVICE: Test thread started: id = 0x20000138
DEBUG - DEVICE: Helper thread started: id = 0x20000080
DEBUG - DEVICE: Testing normal expiration of k_sleep()
DEBUG - DEVICE: Testing: test thread sleep + helper thread wakeup test
DEBUG - DEVICE: Testing: test thread sleep + isr offload wakeup test
DEBUG - DEVICE: Testing: test thread sleep + main wakeup test thread
DEBUG - DEVICE: Testing kernel k_sleep()
DEBUG - DEVICE: PASS - test_sleep in 2.408 seconds
DEBUG - DEVICE: ===================================================================
DEBUG - DEVICE: START - test_usleep
DEBUG - DEVICE: elapsed_ms = 2000
DEBUG - DEVICE: PASS - test_usleep in 4.420 seconds
DEBUG - DEVICE: ===================================================================
DEBUG - DEVICE: START - test_sleep_forever
DEBUG - DEVICE: Kernel objects initialized
DEBUG - DEVICE: PASS - test_sleep_forever in 4.435 seconds
DEBUG - DEVICE: ===================================================================
DEBUG - DEVICE: Test suite sleep succeeded
DEBUG - DEVICE: ===================================================================
DEBUG - DEVICE: PROJECT EXECUTION SUCCESSFUL
DEBUG - run status: nrf52840dk_nrf52840/tests/kernel/sleep/kernel.common.timing passed
INFO - 1/1 nrf52840dk_nrf52840 tests/kernel/sleep/kernel.common.timing PASSED (device 10.441s)
What about deleting everything from get_start_time_cyc(void)
and leaving there only
tc_start_time = k_cycle_get_32();
so that tc_start_time
is always updated for each test case. Then maybe you can get rid off the already_started
variable as it seems to be useless.
With the proposed changes I've got:
DEBUG - DEVICE: *** Booting Zephyr OS build zephyr-v2.5.0-887-ga2c51c22e6d2 ***
DEBUG - DEVICE: Running test suite sleep
DEBUG - DEVICE: ===================================================================
DEBUG - DEVICE: START - test_sleep
DEBUG - DEVICE: Kernel objects initialized
DEBUG - DEVICE: Test thread started: id = 0x20000138
DEBUG - DEVICE: Helper thread started: id = 0x20000080
DEBUG - DEVICE: Testing normal expiration of k_sleep()
DEBUG - DEVICE: Testing: test thread sleep + helper thread wakeup test
DEBUG - DEVICE: Testing: test thread sleep + isr offload wakeup test
DEBUG - DEVICE: Testing: test thread sleep + main wakeup test thread
DEBUG - DEVICE: Testing kernel k_sleep()
DEBUG - DEVICE: PASS - test_sleep in 2.32 seconds
DEBUG - DEVICE: ===================================================================
DEBUG - DEVICE: START - test_usleep
DEBUG - DEVICE: elapsed_ms = 2000
DEBUG - DEVICE: PASS - test_usleep in 2.2 seconds
DEBUG - DEVICE: ===================================================================
DEBUG - DEVICE: START - test_sleep_forever
DEBUG - DEVICE: Kernel objects initialized
DEBUG - DEVICE: PASS - test_sleep_forever in 0.3 seconds
DEBUG - DEVICE: ===================================================================
DEBUG - DEVICE: Test suite sleep succeeded
DEBUG - DEVICE: ===================================================================
DEBUG - DEVICE: PROJECT EXECUTION SUCCESSFUL
DEBUG - run status: nrf52840dk_nrf52840/tests/kernel/sleep/kernel.common.timing passed
INFO - 1/1 nrf52840dk_nrf52840 tests/kernel/sleep/kernel.common.timing PASSED (device 10.148s)
subsys/testsuite/include/tc_util.h
Outdated
if (!IS_ENABLED(CONFIG_ZTEST) && already_started) { | ||
tc_start_time = k_cycle_get_32(); | ||
already_started = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[please read the overall comment first. If the proposed solution doesn't make sense then consider this one] shouldn't it be ... && !already_started
on the condition? If already_started
is already true
, why setting it again to true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the logic for condition is wrong here, I shall correct it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove the already_started here, thanks!
I do appreciate your review, and understand what you concern is, let me explain it please:
Let me try if I can make this better, thank you so much for your example, it's so clear for me. |
I agree :)
I believe it is because the start time is not updated for each test case and not due to the uncertainty of measurement. Like you wrote: "The main goal of adding this is to understand roughly how much time each test case spends". But now it shows from the beginning of the first test case, not the current one. That's why usleep case, which should last for ~2 sec shows ~4 secs (+ extra 2sec from previous one). You can see this playing with the test itself. Add to the line https://github.com/zephyrproject-rtos/zephyr/blob/master/tests/kernel/sleep/src/usleep.c#L54
Without storing the start time for each test case you won't be able to calculate the run time for each individual test. You just need to update |
is it really like this? we call TC_START for each test and thats where it gets updated... I have been using this patch in my branch, it shows the following: <testsuite name="fifo_api" time="0.981" tests="8" failures="0" errors="0" skipped="0">
<properties>
<property name="version" value="v2.5.0"/>
<property name="platform" value="qemu_x86"/>
</properties>
<testcase classname="kernel.fifo" name="test_fifo_thread2thread" time="0.100"/>
<testcase classname="kernel.fifo" name="test_fifo_thread2isr" time="0.100"/>
<testcase classname="kernel.fifo" name="test_fifo_isr2thread" time="0.100"/>
<testcase classname="kernel.fifo" name="test_fifo_get_fail" time="0.107"/>
<testcase classname="kernel.fifo" name="test_fifo_loop" time="0.260"/>
<testcase classname="kernel.fifo" name="test_fifo_cancel_wait" time="0.114"/>
<testcase classname="kernel.fifo" name="test_fifo_is_empty_thread" time="0.100"/>
<testcase classname="kernel.fifo" name="test_fifo_is_empty_isr" time="0.100"/>
</testsuite> |
Now I am confused as I clearly see the issue as described above. Can you please check @nashif what would be the output of /tests/kernel/sleep in your case? |
<testsuite name="sleep" time="3.800" tests="3" failures="0" errors="0" skipped="0">
<properties>
<property name="version" value="zephyr-v2.5.0-549-g694aaf782f78"/>
<property name="platform" value="qemu_cortex_m3"/>
</properties>
<testcase classname="kernel.common.timing" name="test_sleep" time="2.700"/>
<testcase classname="kernel.common.timing" name="test_usleep" time="1.000"/>
<testcase classname="kernel.common.timing" name="test_sleep_forever" time="0.100"/>
</testsuite>
</testsuites> |
I am confused... Your times look correct. This is what I get for qemu_cortex_m3 PASS - test_sleep in 2.71 seconds I am on Ubuntu 18.04, zephyr sdk 0.12.2 and being checked out on this PR's head: zephyr-v2.5.0-887-ga2c51c22e6d2 |
i have an old version of this PR in my branch, this could be the reason |
@nashif By the content of your xml, I would guess you calculate the difference between reported times in console, and if it is 0 you set it to 0.1. Does the output in the console show the same times as in the report? |
I capture the values as is and put them in the report, no calculation done. The only calculation is the total per testsuite. |
I cherry picked the latest version of this PR, now I am getting: <testsuite name="sleep" time="10.130" tests="3" failures="0" errors="0" skipped="0">
<properties>
<property name="version" value="zephyr-v2.5.0-1001-g37406347c8b5"/>
<property name="platform" value="qemu_cortex_m3"/>
</properties>
<testcase classname="kernel.common.timing" name="test_sleep" time="2.710"/>
<testcase classname="kernel.common.timing" name="test_usleep" time="3.710"/>
<testcase classname="kernel.common.timing" name="test_sleep_forever" time="3.710"/>
</testsuite> |
1a7cda8
to
581ca9e
Compare
@PerMac I think I have addressed the comments you mentioned before. I removed the already_start flag, but a check for whether the caller of TC_START macro is in userspace is needed. The test result of time is correct now. Could you please help to review it again, thanks! |
Thanks, @enjiamai, looks good now. C is not my domain, but the logic with the nice and extended description looks correct. I tested this patch on qemu (qemu_cortex_m3) and physical board (nrf5340dk_nrf5340_cpuapp) with the kernel/sleep test, playing with the time to sleep, ad the reported values are correct. |
this should be fixed as part of this PR diff --git a/scripts/pylib/twister/harness.py b/scripts/pylib/twister/harness.py
index 2c30f9ab73..25bea110a3 100644
--- a/scripts/pylib/twister/harness.py
+++ b/scripts/pylib/twister/harness.py
@@ -2,7 +2,7 @@
import re
from collections import OrderedDict
-result_re = re.compile(".*(PASS|FAIL|SKIP) - (test_)?(.*)")
+result_re = re.compile(".*(PASS|FAIL|SKIP) - (test_)?(.*) in")
class Harness:
GCOV_START = "GCOV_COVERAGE_DUMP_START" |
Add execution time for testing result of each ztest testcase as: START - test_sem_multi_take_timeout_diff_sem PASS - test_sem_multi_take_timeout_diff_sem in 2.54 seconds Fix zephyrproject-rtos#32137. Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
581ca9e
to
3eb2c60
Compare
Add execution time for testing result of each ztest testcase as:
START - test_sem_multi_take_timeout_diff_sem
PASS - test_sem_multi_take_timeout_diff_sem in 2.54 seconds
Fix #32137.
Signed-off-by: Enjia Mai enjiax.mai@intel.com