summaryrefslogtreecommitdiffstats
path: root/tools/memory-model
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2018-05-14 19:33:47 -0400
committerIngo Molnar <mingo@kernel.org>2018-05-15 02:11:17 -0400
commit2fb6ae162f25a9c3bc45663c479a2b15fb69e768 (patch)
tree202d79d80b7564799b2aa574a808916f7fa70495 /tools/memory-model
parentd17013e0bac66bb4d1be44f061754c7e53292b64 (diff)
tools/memory-model: Add scripts to test memory model
This commit adds a pair of scripts that run the memory model on litmus tests, checking that the verification result of each litmus test matches the result flagged in the litmus test itself. These scripts permit easier checking of changes to the memory model against preconceived notions. To run the scripts, go to the tools/memory-model directory and type "scripts/checkalllitmus.sh". If all is well, the last line printed will be "All litmus tests verified as was expected." Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will.deacon@arm.com> Cc: akiyks@gmail.com Cc: boqun.feng@gmail.com Cc: dhowells@redhat.com Cc: j.alglave@ucl.ac.uk Cc: linux-arch@vger.kernel.org Cc: luc.maranget@inria.fr Cc: npiggin@gmail.com Cc: parri.andrea@gmail.com Cc: stern@rowland.harvard.edu Link: http://lkml.kernel.org/r/1526340837-12222-9-git-send-email-paulmck@linux.vnet.ibm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/memory-model')
-rw-r--r--tools/memory-model/litmus-tests/.gitignore1
-rw-r--r--tools/memory-model/scripts/checkalllitmus.sh73
-rw-r--r--tools/memory-model/scripts/checklitmus.sh86
3 files changed, 160 insertions, 0 deletions
diff --git a/tools/memory-model/litmus-tests/.gitignore b/tools/memory-model/litmus-tests/.gitignore
new file mode 100644
index 000000000000..6e2ddc54152f
--- /dev/null
+++ b/tools/memory-model/litmus-tests/.gitignore
@@ -0,0 +1 @@
*.litmus.out
diff --git a/tools/memory-model/scripts/checkalllitmus.sh b/tools/memory-model/scripts/checkalllitmus.sh
new file mode 100644
index 000000000000..af0aa15ab84e
--- /dev/null
+++ b/tools/memory-model/scripts/checkalllitmus.sh
@@ -0,0 +1,73 @@
1#!/bin/sh
2#
3# Run herd tests on all .litmus files in the specified directory (which
4# defaults to litmus-tests) and check each file's result against a "Result:"
5# comment within that litmus test. If the verification result does not
6# match that specified in the litmus test, this script prints an error
7# message prefixed with "^^^". It also outputs verification results to
8# a file whose name is that of the specified litmus test, but with ".out"
9# appended.
10#
11# Usage:
12# sh checkalllitmus.sh [ directory ]
13#
14# The LINUX_HERD_OPTIONS environment variable may be used to specify
15# arguments to herd, whose default is defined by the checklitmus.sh script.
16# Thus, one would normally run this in the directory containing the memory
17# model, specifying the pathname of the litmus test to check.
18#
19# This script makes no attempt to run the litmus tests concurrently.
20#
21# This program is free software; you can redistribute it and/or modify
22# it under the terms of the GNU General Public License as published by
23# the Free Software Foundation; either version 2 of the License, or
24# (at your option) any later version.
25#
26# This program is distributed in the hope that it will be useful,
27# but WITHOUT ANY WARRANTY; without even the implied warranty of
28# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29# GNU General Public License for more details.
30#
31# You should have received a copy of the GNU General Public License
32# along with this program; if not, you can access it online at
33# http://www.gnu.org/licenses/gpl-2.0.html.
34#
35# Copyright IBM Corporation, 2018
36#
37# Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
38
39litmusdir=${1-litmus-tests}
40if test -d "$litmusdir" -a -r "$litmusdir" -a -x "$litmusdir"
41then
42 :
43else
44 echo ' --- ' error: $litmusdir is not an accessible directory
45 exit 255
46fi
47
48# Find the checklitmus script. If it is not where we expect it, then
49# assume that the caller has the PATH environment variable set
50# appropriately.
51if test -x scripts/checklitmus.sh
52then
53 clscript=scripts/checklitmus.sh
54else
55 clscript=checklitmus.sh
56fi
57
58# Run the script on all the litmus tests in the specified directory
59ret=0
60for i in litmus-tests/*.litmus
61do
62 if ! $clscript $i
63 then
64 ret=1
65 fi
66done
67if test "$ret" -ne 0
68then
69 echo " ^^^ VERIFICATION MISMATCHES"
70else
71 echo All litmus tests verified as was expected.
72fi
73exit $ret
diff --git a/tools/memory-model/scripts/checklitmus.sh b/tools/memory-model/scripts/checklitmus.sh
new file mode 100644
index 000000000000..e2e477472844
--- /dev/null
+++ b/tools/memory-model/scripts/checklitmus.sh
@@ -0,0 +1,86 @@
1#!/bin/sh
2#
3# Run a herd test and check the result against a "Result:" comment within
4# the litmus test. If the verification result does not match that specified
5# in the litmus test, this script prints an error message prefixed with
6# "^^^" and exits with a non-zero status. It also outputs verification
7# results to a file whose name is that of the specified litmus test, but
8# with ".out" appended.
9#
10# Usage:
11# sh checklitmus.sh file.litmus
12#
13# The LINUX_HERD_OPTIONS environment variable may be used to specify
14# arguments to herd, which default to "-conf linux-kernel.cfg". Thus,
15# one would normally run this in the directory containing the memory model,
16# specifying the pathname of the litmus test to check.
17#
18# This program is free software; you can redistribute it and/or modify
19# it under the terms of the GNU General Public License as published by
20# the Free Software Foundation; either version 2 of the License, or
21# (at your option) any later version.
22#
23# This program is distributed in the hope that it will be useful,
24# but WITHOUT ANY WARRANTY; without even the implied warranty of
25# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26# GNU General Public License for more details.
27#
28# You should have received a copy of the GNU General Public License
29# along with this program; if not, you can access it online at
30# http://www.gnu.org/licenses/gpl-2.0.html.
31#
32# Copyright IBM Corporation, 2018
33#
34# Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
35
36litmus=$1
37herdoptions=${LINUX_HERD_OPTIONS--conf linux-kernel.cfg}
38
39if test -f "$litmus" -a -r "$litmus"
40then
41 :
42else
43 echo ' --- ' error: \"$litmus\" is not a readable file
44 exit 255
45fi
46if grep -q '^ \* Result: ' $litmus
47then
48 outcome=`grep -m 1 '^ \* Result: ' $litmus | awk '{ print $3 }'`
49else
50 outcome=specified
51fi
52
53echo Herd options: $herdoptions > $litmus.out
54/usr/bin/time herd7 -o ~/tmp $herdoptions $litmus >> $litmus.out 2>&1
55grep "Herd options:" $litmus.out
56grep '^Observation' $litmus.out
57if grep -q '^Observation' $litmus.out
58then
59 :
60else
61 cat $litmus.out
62 echo ' ^^^ Verification error'
63 echo ' ^^^ Verification error' >> $litmus.out 2>&1
64 exit 255
65fi
66if test "$outcome" = DEADLOCK
67then
68 echo grep 3 and 4
69 if grep '^Observation' $litmus.out | grep -q 'Never 0 0$'
70 then
71 ret=0
72 else
73 echo " ^^^ Unexpected non-$outcome verification"
74 echo " ^^^ Unexpected non-$outcome verification" >> $litmus.out 2>&1
75 ret=1
76 fi
77elif grep '^Observation' $litmus.out | grep -q $outcome || test "$outcome" = Maybe
78then
79 ret=0
80else
81 echo " ^^^ Unexpected non-$outcome verification"
82 echo " ^^^ Unexpected non-$outcome verification" >> $litmus.out 2>&1
83 ret=1
84fi
85tail -2 $litmus.out | head -1
86exit $ret