zephyr: it8xxx2_evb: tests/kernel/sched/schedule_api fail due to k_sleep(K_MSEC(100)) not correct

Describe the bug The daily test case tests/kernel/sched/schedule_api failed due to k_sleep(K_MSEC(100)) not correct, k_sleep is expected to wait 100ms, but actually it never ends.

Please also mention any information which could help others to understand the problem you’re facing:

  • What target platform are you using?: it8xxx2_evb
  • What have you tried to diagnose or workaround this issue? Add log before and after k_sleep(K_MSEC(100)), the log after it is never seen

To Reproduce Two ways to reproduce the behavior: Method 1

  1. twister -v -p it8xxx2_evb --device-testing --west-flash=“…/…/itetool/loader.sh” --device-serial=/dev/ttyUSB0 -T tests/kernel/sched/schedule_api Method 2
  2. west build -p always -b it8xxx2_evb tests/kernel/sched/schedule_api -DCONFIG_TIMESLICE_PER_THREAD=y -DCONFIG_TIMESLICING=y
  3. sudo -S ~/itetool/ite -f build/zephyr/zephyr.bin -s check

Expected behavior The test can pass

Impact Blocks all the daily tests under tests/kernel/sched/schedule_api

Logs and console output Logs for west:

*** Booting Zephyr OS build zephyr-v3.1.0-514-gf232db463078  (delayed boot 1ms) ***
Running TESTSUITE threads_scheduling
===================================================================
START - test_bad_priorities
 PASS - test_bad_priorities in 0.1 seconds
===================================================================
START - test_priority_cooperative

Environment (please complete the following information):

  • OS: (e.g. Linux, MacOS, Windows): ubuntu
  • Toolchain (e.g Zephyr SDK, …): 0.14.1
  • Commit SHA or Version used: f875d027a04374fcf07661809f81a42c2c646629

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (9 by maintainers)

Commits related to this issue

Most upvoted comments

z_tick_sleep->z_add_thread_timeout->z_add_timeout->next_timeout->_current_cpu->slice_ticks

The _current_cpu->slice_ticks is not initialized in the test of test_priority_cooperative(). So the swap of the thread got problem. I’ll provide a PR to fix it.

The test failed due to the k_sleep hang. The call stack of the k_sleep is:

  1. test_priority_cooperative -> k_sleep(K_MSEC(100)) -> z_impl_k_sleep -> z_tick_sleep -> z_swap -> do_swap -> arch_switch -> z_riscv_switch
  2. idle() -> k_cpu_idle -> arch_cpu_idle -> riscv_idle -> ite_intc_no_irq Adding some printk in the log:
START - test_priority_cooperative
@@@ z_reschedule
z_swap 1
new->name = test_priority_cooperative, old->name = main
do_swap done
@@@ z_reschedule
@@@ z_tick_sleep: ticks = 410
111 timeout.ticks = 410
222 expected_wakeup_ticks = 800
333
444
z_swap 1
new->name = , old->name = test_priority_cooperative
@@@ z_thread_abort, thread->name =
z_swap 1
new->name = main, old->name =
arch_switch done
do_swap done
z_swap 1 done, ret = -11
@@@ z_impl_k_thread_join thread->name = test_priority_cooperative, timeout.ticks = -1
z_swap 1
new->name = idle, old->name = main
arch_cpu_idle
riscv_idle before do

riscv_idle stuck at the do/while loop. It is waiting for an interrupt(function ite_intc_no_irq) which never come. @RuibinChang Could you please help to check? The function “riscv_idle” is in soc/riscv/riscv-ite/it8xxx2/soc.c. Thanks

OK, I’ll remove this test case on it8xxx2_evb. Thank you.

@RuibinChang can you investigate that why we can’t enable the CONFIG_TIMESLICE_PER_THREAD option on it8xxx2_evb?

@RuibinChang Sorry for late reply Twist and west are different. When using twister to do the test, it will test many different configurations, but for west, it conly contains 1 most common config. For example the test case of tests/kernel/sched/schedule_api, there are 8 test cases defined in tests/kernel/sched/schedule_api/testcase.yaml. There are 7 test cases suitable for it8xxx2_evb. Among these 7, only 1 is failed. I copy the failed test below

  kernel.scheduler.slice_perthread:
    filter: not CONFIG_SCHED_MULTIQ
    extra_configs:
      - CONFIG_TIMESLICING=y
      - CONFIG_TIMESLICE_PER_THREAD=y
    tags: kernel threads sched userspace ignore_faults

As you can see, this case defined two more macros, so if you want to test it in west you need to add these macros, like this:

west build -p always -b it8xxx2_evb tests/kernel/sched/schedule_api -DCONFIG_TIMESLICE_PER_THREAD=y -DCONFIG_TIMESLICING=y

If you think any of these macros does not fit for it8xxx2_evb, or we do not need to test these macros, we can skip this test for it8xxx2_evb.