Bug 435160 - drd/tests/swapcontext.c: threads are interrupted in nanosleep
Summary: drd/tests/swapcontext.c: threads are interrupted in nanosleep
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: drd (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Bart Van Assche
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-30 18:22 UTC by Yi Fan Yu
Modified: 2021-04-20 19:50 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
proposed patch (2.02 KB, patch)
2021-03-30 21:13 UTC, Yi Fan Yu
Details
proposed patch v2 (1.87 KB, patch)
2021-04-05 19:16 UTC, Yi Fan Yu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yi Fan Yu 2021-03-30 18:22:44 UTC
SUMMARY
on yocto/oe-core qemux86-64 glibc 3.17.0 release:
swapcontext.c fails because the threads were killed inside of nanosleep



STEPS TO REPRODUCE
 

OBSERVED RESULT

``` runqemu kvm
valgrind --tool=drd --read-var-info=yes --check-stack-var=yes --show-confl-seg=no --num-callers=2 ./swapcontext
==277== drd, a thread error detector
==277== Copyright (C) 2006-2020, and GNU GPL'd, by Bart Van Assche.
==277== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==277== Command: ./swapcontext
==277==
==277==
==277== Process terminating with default action of signal 14 (SIGALRM)
==277==    at 0x36C74C3943: clock_nanosleep@@GLIBC_2.17 (clock_nanosleep.c:43)
==277==    by 0x36C74C8726: nanosleep (nanosleep.c:25)
==277==
==277== For lists of detected and suppressed errors, rerun with: -s
==277== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 26 from 2)
Alarm clock
```

EXPECTED RESULT

i think the test should pass because it generated 0 error.
the nanosleep is called inside of f
Comment 1 Yi Fan Yu 2021-03-30 19:09:44 UTC
If i remove the nanosleep statement, inside of `f`

the original bug report 432381 's error message appears

drd: drd_main.c:378 (drd_stop_using_mem): Assertion 'a1 <= a2' failed
Comment 2 Yi Fan Yu 2021-03-30 19:42:20 UTC
What is the purpose of nanosleep, can it be safely removed?

Is there a filter to allow both scenario (stopped in f and stopped in nanosleep) to be correct?
Comment 3 Yi Fan Yu 2021-03-30 21:13:08 UTC
Created attachment 137186 [details]
proposed patch

revert commit 719d23b7a9c3b02411dee7d5d4d3744938bb768c
Comment 4 Yi Fan Yu 2021-03-30 21:21:22 UTC
I do know that the commit I reverted mentioned portability.
Do you know which platform has problems with timerfd?
Comment 5 Bart Van Assche 2021-03-31 03:23:39 UTC
Reverting commit 719d23b7a9c3 ("drd/tests/swapcontext: Improve portability") is not an option. Valgrind source code must build and run on all supported operating systems. Not all supported operating systems support poll().
Comment 6 Yi Fan Yu 2021-03-31 03:35:48 UTC
(In reply to Bart Van Assche from comment #5)
> Reverting commit 719d23b7a9c3 ("drd/tests/swapcontext: Improve portability")
> is not an option. Valgrind source code must build and run on all supported
> operating systems. Not all supported operating systems support poll().

seems like Mac doesn't support poll, maybe select would be a better choice?
I tested the "proposed patch" and test passes.

any advice to solve this issue?
Comment 7 Yi Fan Yu 2021-03-31 03:57:05 UTC
maybe the root cause is just the stderr.exp being to sensitive...
Comment 8 Bart Van Assche 2021-04-02 20:04:42 UTC
Please provide a .stderr.exp file that makes the test pass on your test setup.
Comment 9 Yi Fan Yu 2021-04-05 16:34:58 UTC
stderr.exp that would pass the test.
```


Process terminating with default action of signal 14 (SIGALRM)
   at 0x........: clock_nanosleep@@GLIBC_2.17 (clock_nanosleep.c:?)
   by 0x........: nanosleep (nanosleep.c:?)

ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
```
Comment 10 Yi Fan Yu 2021-04-05 19:16:26 UTC
Created attachment 137357 [details]
proposed patch v2

basically to avoid printing the stacktrace with a handled signal.
Comment 11 Bart Van Assche 2021-04-09 23:48:51 UTC
"Patch v2" has been applied on the master branch. Thanks for the patch!
Comment 12 Yi Fan Yu 2021-04-20 19:50:06 UTC
thanks!

passes on yocto ptest