162306a36Sopenharmony_ci#!/bin/sh
262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci# Without the -hw argument, runs a herd7 test and outputs verification
562306a36Sopenharmony_ci# results to a file whose name is that of the specified litmus test,
662306a36Sopenharmony_ci# but with ".out" appended.
762306a36Sopenharmony_ci#
862306a36Sopenharmony_ci# If the --hw argument is specified, this script translates the .litmus
962306a36Sopenharmony_ci# C-language file to the specified type of assembly and verifies that.
1062306a36Sopenharmony_ci# But in this case, litmus tests using complex synchronization (such as
1162306a36Sopenharmony_ci# locking, RCU, and SRCU) are cheerfully ignored.
1262306a36Sopenharmony_ci#
1362306a36Sopenharmony_ci# Either way, return the status of the herd7 command.
1462306a36Sopenharmony_ci#
1562306a36Sopenharmony_ci# Usage:
1662306a36Sopenharmony_ci#	runlitmus.sh file.litmus
1762306a36Sopenharmony_ci#
1862306a36Sopenharmony_ci# Run this in the directory containing the memory model, specifying the
1962306a36Sopenharmony_ci# pathname of the litmus test to check.  The caller is expected to have
2062306a36Sopenharmony_ci# properly set up the LKMM environment variables.
2162306a36Sopenharmony_ci#
2262306a36Sopenharmony_ci# Copyright IBM Corporation, 2019
2362306a36Sopenharmony_ci#
2462306a36Sopenharmony_ci# Author: Paul E. McKenney <paulmck@linux.ibm.com>
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_cilitmus=$1
2762306a36Sopenharmony_ciif test -f "$litmus" -a -r "$litmus"
2862306a36Sopenharmony_cithen
2962306a36Sopenharmony_ci	:
3062306a36Sopenharmony_cielse
3162306a36Sopenharmony_ci	echo ' !!! ' error: \"$litmus\" is not a readable file
3262306a36Sopenharmony_ci	exit 255
3362306a36Sopenharmony_cifi
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciif test -z "$LKMM_HW_MAP_FILE" -o ! -e $LKMM_DESTDIR/$litmus.out
3662306a36Sopenharmony_cithen
3762306a36Sopenharmony_ci	# LKMM run
3862306a36Sopenharmony_ci	herdoptions=${LKMM_HERD_OPTIONS--conf linux-kernel.cfg}
3962306a36Sopenharmony_ci	echo Herd options: $herdoptions > $LKMM_DESTDIR/$litmus.out
4062306a36Sopenharmony_ci	/usr/bin/time $LKMM_TIMEOUT_CMD herd7 $herdoptions $litmus >> $LKMM_DESTDIR/$litmus.out 2>&1
4162306a36Sopenharmony_ci	ret=$?
4262306a36Sopenharmony_ci	if test -z "$LKMM_HW_MAP_FILE"
4362306a36Sopenharmony_ci	then
4462306a36Sopenharmony_ci		exit $ret
4562306a36Sopenharmony_ci	fi
4662306a36Sopenharmony_ci	echo " --- " Automatically generated LKMM output for '"'--hw $LKMM_HW_MAP_FILE'"' run
4762306a36Sopenharmony_cifi
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci# Hardware run
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ciT=/tmp/checklitmushw.sh.$$
5262306a36Sopenharmony_citrap 'rm -rf $T' 0 2
5362306a36Sopenharmony_cimkdir $T
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci# Generate filenames
5662306a36Sopenharmony_cimapfile="Linux2${LKMM_HW_MAP_FILE}.map"
5762306a36Sopenharmony_cithemefile="$T/${LKMM_HW_MAP_FILE}.theme"
5862306a36Sopenharmony_ciherdoptions="-model $LKMM_HW_CAT_FILE"
5962306a36Sopenharmony_cihwlitmus=`echo $litmus | sed -e 's/\.litmus$/.litmus.'${LKMM_HW_MAP_FILE}'/'`
6062306a36Sopenharmony_cihwlitmusfile=`echo $hwlitmus | sed -e 's,^.*/,,'`
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci# Don't run on litmus tests with complex synchronization
6362306a36Sopenharmony_ciif ! scripts/simpletest.sh $litmus
6462306a36Sopenharmony_cithen
6562306a36Sopenharmony_ci	echo ' --- ' error: \"$litmus\" contains locking, RCU, or SRCU
6662306a36Sopenharmony_ci	exit 254
6762306a36Sopenharmony_cifi
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci# Generate the assembly code and run herd7 on it.
7062306a36Sopenharmony_cigen_theme7 -n 10 -map $mapfile -call Linux.call > $themefile
7162306a36Sopenharmony_cijingle7 -v -theme $themefile $litmus > $LKMM_DESTDIR/$hwlitmus 2> $T/$hwlitmusfile.jingle7.out
7262306a36Sopenharmony_ciif grep -q "Generated 0 tests" $T/$hwlitmusfile.jingle7.out
7362306a36Sopenharmony_cithen
7462306a36Sopenharmony_ci	echo ' !!! ' jingle7 failed, errors in $hwlitmus.err
7562306a36Sopenharmony_ci	cp $T/$hwlitmusfile.jingle7.out $LKMM_DESTDIR/$hwlitmus.err
7662306a36Sopenharmony_ci	exit 253
7762306a36Sopenharmony_cifi
7862306a36Sopenharmony_ci/usr/bin/time $LKMM_TIMEOUT_CMD herd7 -unroll 0 $LKMM_DESTDIR/$hwlitmus > $LKMM_DESTDIR/$hwlitmus.out 2>&1
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ciexit $?
81