Skip to content

Commit

Permalink
tools/memory-model: Add data-race capabilities to judgelitmus.sh
Browse files Browse the repository at this point in the history
This commit adds functionality to judgelitmus.sh to allow it to handle
both the "DATARACE" markers in the "Result:" comments in litmus tests
and the "Flag data-race" markers in LKMM output.  For C-language tests,
if either marker is present, the other must also be as well, at least for
litmus tests having a "Result:" comment.  If the LKMM output indicates
a data race, then failures of the Always/Sometimes/Never portion of the
"Result:" prediction are forgiven.

The reason for forgiving "Result:" mispredictions is that data races can
result in "interesting" compiler optimizations, so that all bets are off
in the data-race case.

[ paulmck: Apply Akira Yokosawa feedback. ]
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
  • Loading branch information
Paul E. McKenney committed Mar 24, 2023
1 parent df0f675 commit 68f7bca
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions tools/memory-model/scripts/judgelitmus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
# Given a .litmus test and the corresponding litmus output file, check
# the .litmus.out file against the "Result:" comment to judge whether the
# test ran correctly. If the --hw argument is omitted, check against the
# LKMM output, which is assumed to be in file.litmus.out. If this argument
# is provided, this is assumed to be a hardware test, and the output is
# assumed to be in file.litmus.HW.out, where "HW" is the --hw argument.
# In addition, non-Sometimes verification results will be noted, but
# forgiven. Furthermore, if there is no "Result:" comment but there is
# an LKMM .litmus.out file, the observation in that file will be used
# to judge the assembly-language verification.
# LKMM output, which is assumed to be in file.litmus.out. If either a
# "DATARACE" marker in the "Result:" comment or a "Flag data-race" marker
# in the LKMM output is present, the other must also be as well, at least
# for litmus tests having a "Result:" comment. In this case, a failure of
# the Always/Sometimes/Never portion of the "Result:" prediction will be
# noted, but forgiven.
#
# If the --hw argument is provided, this is assumed to be a hardware
# test, and the output is assumed to be in file.litmus.HW.out, where
# "HW" is the --hw argument. In addition, non-Sometimes verification
# results will be noted, but forgiven. Furthermore, if there is no
# "Result:" comment but there is an LKMM .litmus.out file, the observation
# in that file will be used to judge the assembly-language verification.
#
# Usage:
# judgelitmus.sh file.litmus
Expand Down Expand Up @@ -47,9 +53,27 @@ else
echo ' --- ' error: \"$LKMM_DESTDIR/$litmusout is not a readable file
exit 255
fi
if grep -q '^Flag data-race$' "$LKMM_DESTDIR/$litmusout"
then
datarace_modeled=1
fi
if grep -q '^ \* Result: ' $litmus
then
outcome=`grep -m 1 '^ \* Result: ' $litmus | awk '{ print $3 }'`
if grep -m1 '^ \* Result: .* DATARACE' $litmus
then
datarace_predicted=1
fi
if test -n "$datarace_predicted" -a -z "$datarace_modeled" -a -z "$LKMM_HW_MAP_FILE"
then
echo '!!! Predicted data race not modeled' $litmus
exit 252
elif test -z "$datarace_predicted" -a -n "$datarace_modeled"
then
# Note that hardware models currently don't model data races
echo '!!! Unexpected data race modeled' $litmus
exit 253
fi
elif test -n "$LKMM_HW_MAP_FILE" && grep -q '^Observation' $LKMM_DESTDIR/$lkmmout > /dev/null 2>&1
then
outcome=`grep -m 1 '^Observation ' $LKMM_DESTDIR/$lkmmout | awk '{ print $3 }'`
Expand Down Expand Up @@ -114,7 +138,7 @@ elif grep '^Observation' $LKMM_DESTDIR/$litmusout | grep -q $outcome || test "$o
then
ret=0
else
if test -n "$LKMM_HW_MAP_FILE" -a "$outcome" = Sometimes
if test \( -n "$LKMM_HW_MAP_FILE" -a "$outcome" = Sometimes \) -o -n "$datarace_modeled"
then
flag="--- Forgiven"
ret=0
Expand Down

0 comments on commit 68f7bca

Please sign in to comment.