From: Philippe Waroquiers Date: Thu, 29 Dec 2022 14:56:36 +0000 (+0100) Subject: Add a test for helgrind --history-backtrace-size X-Git-Tag: VALGRIND_3_21_0~253 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5b88a02d5750c464736ab1d4c66cedd4182c79e;p=thirdparty%2Fvalgrind.git Add a test for helgrind --history-backtrace-size Extend hg04_race to have more entries in the conflicting stacktrace, and make another test hg04_race_h9 to test with one more entry than the default of 8. --- diff --git a/helgrind/tests/Makefile.am b/helgrind/tests/Makefile.am index 2286e220f1..28f4c61912 100755 --- a/helgrind/tests/Makefile.am +++ b/helgrind/tests/Makefile.am @@ -34,6 +34,7 @@ EXTRA_DIST = \ hg02_deadlock.vgtest hg02_deadlock.stdout.exp hg02_deadlock.stderr.exp \ hg03_inherit.vgtest hg03_inherit.stdout.exp hg03_inherit.stderr.exp \ hg04_race.vgtest hg04_race.stdout.exp hg04_race.stderr.exp \ + hg04_race_h9.vgtest hg04_race_h9.stdout.exp hg04_race_h9.stderr.exp \ hg05_race2.vgtest hg05_race2.stdout.exp hg05_race2.stderr.exp \ hg06_readshared.vgtest hg06_readshared.stdout.exp \ hg06_readshared.stderr.exp \ diff --git a/helgrind/tests/hg04_race.c b/helgrind/tests/hg04_race.c index 111195bf90..760caf8860 100644 --- a/helgrind/tests/hg04_race.c +++ b/helgrind/tests/hg04_race.c @@ -5,18 +5,79 @@ static int shared; +__attribute__((noinline)) +static void th10(void) +{ + shared++; +} + +__attribute__((noinline)) +static void th9(void) +{ + th10(); +} + +__attribute__((noinline)) +static void th8(void) +{ + th9(); +} + +__attribute__((noinline)) +static void th7(void) +{ + th8(); +} + +__attribute__((noinline)) +static void th6(void) +{ + th7(); +} + +__attribute__((noinline)) +static void th5(void) +{ + th6(); +} + +__attribute__((noinline)) +static void th4(void) +{ + th5(); +} + +__attribute__((noinline)) +static void th3(void) +{ + th4(); +} + +__attribute__((noinline)) +static void th2(void) +{ + th3(); +} + + +__attribute__((noinline)) +static void th1(void) +{ + th2(); +} + static void *th(void *v) { - shared++; + th1(); - return 0; + return 0; } int main() { pthread_t a, b; - pthread_create(&a, NULL, th, NULL); + pthread_create(&a, NULL, th, NULL); sleep(1); /* force ordering */ pthread_create(&b, NULL, th, NULL); diff --git a/helgrind/tests/hg04_race.stderr.exp b/helgrind/tests/hg04_race.stderr.exp index 67f6573963..f66394bd13 100644 --- a/helgrind/tests/hg04_race.stderr.exp +++ b/helgrind/tests/hg04_race.stderr.exp @@ -4,28 +4,42 @@ Thread #x was created ... by 0x........: pthread_create@* (hg_intercepts.c:...) - by 0x........: main (hg04_race.c:21) + by 0x........: main (hg04_race.c:82) ---Thread-Announcement------------------------------------------ Thread #x was created ... by 0x........: pthread_create@* (hg_intercepts.c:...) - by 0x........: main (hg04_race.c:19) + by 0x........: main (hg04_race.c:80) ---------------------------------------------------------------- Possible data race during read of size 4 at 0x........ by thread #x Locks held: none - at 0x........: th (hg04_race.c:10) + at 0x........: th10 (hg04_race.c:11) + by 0x........: th9 (hg04_race.c:17) + by 0x........: th8 (hg04_race.c:23) + by 0x........: th7 (hg04_race.c:29) + by 0x........: th6 (hg04_race.c:35) + by 0x........: th5 (hg04_race.c:41) + by 0x........: th4 (hg04_race.c:47) + by 0x........: th3 (hg04_race.c:53) + by 0x........: th2 (hg04_race.c:59) + by 0x........: th1 (hg04_race.c:66) + by 0x........: th (hg04_race.c:71) by 0x........: mythread_wrapper (hg_intercepts.c:...) - ... This conflicts with a previous write of size 4 by thread #x Locks held: none - at 0x........: th (hg04_race.c:10) - by 0x........: mythread_wrapper (hg_intercepts.c:...) - ... + at 0x........: th10 (hg04_race.c:11) + by 0x........: th9 (hg04_race.c:17) + by 0x........: th8 (hg04_race.c:23) + by 0x........: th7 (hg04_race.c:29) + by 0x........: th6 (hg04_race.c:35) + by 0x........: th5 (hg04_race.c:41) + by 0x........: th4 (hg04_race.c:47) + by 0x........: th3 (hg04_race.c:53) Location 0x........ is 0 bytes inside global var "shared" declared at hg04_race.c:6 @@ -33,15 +47,29 @@ Locks held: none Possible data race during write of size 4 at 0x........ by thread #x Locks held: none - at 0x........: th (hg04_race.c:10) + at 0x........: th10 (hg04_race.c:11) + by 0x........: th9 (hg04_race.c:17) + by 0x........: th8 (hg04_race.c:23) + by 0x........: th7 (hg04_race.c:29) + by 0x........: th6 (hg04_race.c:35) + by 0x........: th5 (hg04_race.c:41) + by 0x........: th4 (hg04_race.c:47) + by 0x........: th3 (hg04_race.c:53) + by 0x........: th2 (hg04_race.c:59) + by 0x........: th1 (hg04_race.c:66) + by 0x........: th (hg04_race.c:71) by 0x........: mythread_wrapper (hg_intercepts.c:...) - ... This conflicts with a previous write of size 4 by thread #x Locks held: none - at 0x........: th (hg04_race.c:10) - by 0x........: mythread_wrapper (hg_intercepts.c:...) - ... + at 0x........: th10 (hg04_race.c:11) + by 0x........: th9 (hg04_race.c:17) + by 0x........: th8 (hg04_race.c:23) + by 0x........: th7 (hg04_race.c:29) + by 0x........: th6 (hg04_race.c:35) + by 0x........: th5 (hg04_race.c:41) + by 0x........: th4 (hg04_race.c:47) + by 0x........: th3 (hg04_race.c:53) Location 0x........ is 0 bytes inside global var "shared" declared at hg04_race.c:6 diff --git a/helgrind/tests/hg04_race_h9.stderr.exp b/helgrind/tests/hg04_race_h9.stderr.exp new file mode 100644 index 0000000000..6e692e749a --- /dev/null +++ b/helgrind/tests/hg04_race_h9.stderr.exp @@ -0,0 +1,79 @@ + +---Thread-Announcement------------------------------------------ + +Thread #x was created + ... + by 0x........: pthread_create@* (hg_intercepts.c:...) + by 0x........: main (hg04_race.c:82) + +---Thread-Announcement------------------------------------------ + +Thread #x was created + ... + by 0x........: pthread_create@* (hg_intercepts.c:...) + by 0x........: main (hg04_race.c:80) + +---------------------------------------------------------------- + +Possible data race during read of size 4 at 0x........ by thread #x +Locks held: none + at 0x........: th10 (hg04_race.c:11) + by 0x........: th9 (hg04_race.c:17) + by 0x........: th8 (hg04_race.c:23) + by 0x........: th7 (hg04_race.c:29) + by 0x........: th6 (hg04_race.c:35) + by 0x........: th5 (hg04_race.c:41) + by 0x........: th4 (hg04_race.c:47) + by 0x........: th3 (hg04_race.c:53) + by 0x........: th2 (hg04_race.c:59) + by 0x........: th1 (hg04_race.c:66) + by 0x........: th (hg04_race.c:71) + by 0x........: mythread_wrapper (hg_intercepts.c:...) + +This conflicts with a previous write of size 4 by thread #x +Locks held: none + at 0x........: th10 (hg04_race.c:11) + by 0x........: th9 (hg04_race.c:17) + by 0x........: th8 (hg04_race.c:23) + by 0x........: th7 (hg04_race.c:29) + by 0x........: th6 (hg04_race.c:35) + by 0x........: th5 (hg04_race.c:41) + by 0x........: th4 (hg04_race.c:47) + by 0x........: th3 (hg04_race.c:53) + by 0x........: th2 (hg04_race.c:59) + Location 0x........ is 0 bytes inside global var "shared" + declared at hg04_race.c:6 + +---------------------------------------------------------------- + +Possible data race during write of size 4 at 0x........ by thread #x +Locks held: none + at 0x........: th10 (hg04_race.c:11) + by 0x........: th9 (hg04_race.c:17) + by 0x........: th8 (hg04_race.c:23) + by 0x........: th7 (hg04_race.c:29) + by 0x........: th6 (hg04_race.c:35) + by 0x........: th5 (hg04_race.c:41) + by 0x........: th4 (hg04_race.c:47) + by 0x........: th3 (hg04_race.c:53) + by 0x........: th2 (hg04_race.c:59) + by 0x........: th1 (hg04_race.c:66) + by 0x........: th (hg04_race.c:71) + by 0x........: mythread_wrapper (hg_intercepts.c:...) + +This conflicts with a previous write of size 4 by thread #x +Locks held: none + at 0x........: th10 (hg04_race.c:11) + by 0x........: th9 (hg04_race.c:17) + by 0x........: th8 (hg04_race.c:23) + by 0x........: th7 (hg04_race.c:29) + by 0x........: th6 (hg04_race.c:35) + by 0x........: th5 (hg04_race.c:41) + by 0x........: th4 (hg04_race.c:47) + by 0x........: th3 (hg04_race.c:53) + by 0x........: th2 (hg04_race.c:59) + Location 0x........ is 0 bytes inside global var "shared" + declared at hg04_race.c:6 + + +ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0) diff --git a/helgrind/tests/hg04_race_h9.stdout.exp b/helgrind/tests/hg04_race_h9.stdout.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/helgrind/tests/hg04_race_h9.vgtest b/helgrind/tests/hg04_race_h9.vgtest new file mode 100644 index 0000000000..528d7a19ac --- /dev/null +++ b/helgrind/tests/hg04_race_h9.vgtest @@ -0,0 +1,3 @@ +prog: hg04_race +vgopts: --read-var-info=yes --history-backtrace-size=9 +stderr_filter_args: hg04_race.c