Bug 453055 - shared_timed_mutex drd test fails with "Lock shared failed" message
Summary: shared_timed_mutex drd test fails with "Lock shared failed" message
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: drd (show other bugs)
Version: 3.19.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Paul Floyd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-26 14:51 UTC by Jesus Checa
Modified: 2022-04-27 19:14 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Proposed fix for drd/tests/shared_timed_mutex (380 bytes, patch)
2022-04-26 14:51 UTC, Jesus Checa
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jesus Checa 2022-04-26 14:51:56 UTC
Created attachment 148388 [details]
Proposed fix for drd/tests/shared_timed_mutex

SUMMARY
drd/tests/shared_timed_mutex test fails in 3.19.0 during `make regtest`. This is also reproducible in 3.20.0.GIT:
=================================================
drd/tests/shared_timed_mutex.stderr.diff
=================================================
--- shared_timed_mutex.stderr.exp	2022-04-11 10:27:12.000000000 -0400
+++ shared_timed_mutex.stderr.out	2022-04-26 03:53:54.116981437 -0400
@@ -1,3 +1,4 @@
 
+Lock shared failed
 
 ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Running the test without valgrind seems to fail always as well. The problem seems to come from this code from the test itself:
```
    for (i = 0; i < 3 && std::chrono::steady_clock::now() < then; ++i)
    {
        if (test_mutex.try_lock_shared_until(then))
        {
            test_mutex.unlock_shared();
        }
    }
    if (i == 3)
    {
        std::cerr << "Lock shared failed\n";
    }
```

IIUIC, variable `i` will always be 3 in this code, hence the test will always print "Lock shared failed" and will mismatch the expected output.  Adding a break as in the proposed patch fixes the issue. Tested in rhel-8 in x86_64, aarch64 and s390x.

STEPS TO REPRODUCE
1. git clone git://sourceware.org/git/valgrind.git
2. cd valgrind && ./autogen.sh && ./configure
3. make -j$(nproc) regtest
Comment 1 Paul Floyd 2022-04-26 20:15:39 UTC
LGTM

This was my badly written testcase.
Comment 2 Paul Floyd 2022-04-27 19:14:56 UTC
To ssh://sourceware.org/git/valgrind.git
   6af21da95..184e3ba05  master -> master