Hi Serhei,

On Fri, Sep 4, 2026 at 9:56 AM Serhei Makarov <[email protected]> wrote:
>
> On an idle embedded system, run-stackprof-system*.sh will fail due to
> lack of background activity yielding 0 samples. Fix this by imitating
> existing run-native-test.sh and launching a sh 'while true' loop in
> the background to guarantee that some samples are collected.
> (No time limit; we use trap+kill+wait to clean up the sh process when
> the testcase exits.)
>
> * tests/stackprof_subr.sh (testjob): New var, tracks job PID.
>   (testjob_launch): Launch a sh loop and assign to testjob.
>   (kill_testjob): On exit, kill+wait $testjob to clean up.
>   (testjob_cleanup): New helper, runs on abnormal exit (1,2,15).
>   (testjob_exit): New helper, runs on normal exit (0).
> * tests/run-stackprof-system.sh: Invoke testjob_launch to guarantee
>   some samples are collected.
> * tests/run-stackprof-system-gprof.sh: Invoke testjob_launch to
>   guarantee some samples are collected.

LGTM with a Signed-off-by tag added.

Aaron

> ---
>  tests/run-stackprof-system-gprof.sh |  3 +++
>  tests/run-stackprof-system.sh       |  3 +++
>  tests/stackprof-subr.sh             | 32 +++++++++++++++++++++++++++++
>  3 files changed, 38 insertions(+)
>
> diff --git a/tests/run-stackprof-system-gprof.sh 
> b/tests/run-stackprof-system-gprof.sh
> index c281167c..980a35be 100755
> --- a/tests/run-stackprof-system-gprof.sh
> +++ b/tests/run-stackprof-system-gprof.sh
> @@ -29,6 +29,9 @@ expr `whoami` = "root" || (echo "not running as root"; exit 
> 77)
>
>  tempfiles test.out
>
> +# guarantee background load on idle systems (cleaned up on exit)
> +testjob_launch
> +
>  # run systemwide scan, no gprof output
>  testrun timeout -p --kill-after=5 10 ${abs_top_builddir}/src/stackprof -v 
> 2>&1 | tee test.out
>  grep "^perf_event_attr configuration" test.out
> diff --git a/tests/run-stackprof-system.sh b/tests/run-stackprof-system.sh
> index cb796a71..af64e7f1 100755
> --- a/tests/run-stackprof-system.sh
> +++ b/tests/run-stackprof-system.sh
> @@ -28,6 +28,9 @@ expr `whoami` = "root" || (echo "not running as root"; exit 
> 77)
>
>  tempfiles test.out
>
> +# guarantee background load on idle systems (cleaned up on exit)
> +testjob_launch
> +
>  # run systemwide scan, no gprof output
>  testrun timeout -p --kill-after=5 10 ${abs_top_builddir}/src/stackprof -v 
> 2>&1 | tee test.out
>  grep "^perf_event_attr configuration" test.out
> diff --git a/tests/stackprof-subr.sh b/tests/stackprof-subr.sh
> index 67c30d47..896c2fe8 100644
> --- a/tests/stackprof-subr.sh
> +++ b/tests/stackprof-subr.sh
> @@ -18,6 +18,38 @@
>
>  . $srcdir/test-subr.sh
>
> +# to launch and cleanup a background process
> +testjob=0
> +
> +testjob_launch()
> +{
> +  trap testjob_cleanup 1 2 15
> +  trap testjob_exit 0
> +  { /bin/sh -c 'while true; do true; done' >/dev/null 2>&1 & testjob=$! ; } 
> &&
> +  sleep 0.1
> +}
> +
> +kill_testjob()
> +{
> +  test $testjob -eq 0 || {
> +    kill -9 $testjob 2> /dev/null || :
> +    wait $testjob 2> /dev/null || :
> +  }
> +  testjob=0
> +}
> +
> +testjob_cleanup()
> +{
> +  kill_testjob
> +  test_cleanup
> +}
> +
> +testjob_exit()
> +{
> +  testjob_cleanup
> +  exit_cleanup
> +}
> +
>  check_perf_event_open() {
>      tempfiles perf-test.out
>      if ! testrun timeout 2 ${abs_top_builddir}/src/stackprof -v -- /bin/true 
> > perf-test.out 2>&1; then
> --
> 2.54.0
>

Reply via email to