162306a36Sopenharmony_ci#!/bin/bash
262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci# Run herd7 tests on all .litmus files in the litmus-tests directory
562306a36Sopenharmony_ci# and check each file's result against a "Result:" comment within that
662306a36Sopenharmony_ci# litmus test.  If the verification result does not match that specified
762306a36Sopenharmony_ci# in the litmus test, this script prints an error message prefixed with
862306a36Sopenharmony_ci# "^^^".  It also outputs verification results to a file whose name is
962306a36Sopenharmony_ci# that of the specified litmus test, but with ".out" appended.
1062306a36Sopenharmony_ci#
1162306a36Sopenharmony_ci# If the --hw argument is specified, this script translates the .litmus
1262306a36Sopenharmony_ci# C-language file to the specified type of assembly and verifies that.
1362306a36Sopenharmony_ci# But in this case, litmus tests using complex synchronization (such as
1462306a36Sopenharmony_ci# locking, RCU, and SRCU) are cheerfully ignored.
1562306a36Sopenharmony_ci#
1662306a36Sopenharmony_ci# Usage:
1762306a36Sopenharmony_ci#	checkalllitmus.sh
1862306a36Sopenharmony_ci#
1962306a36Sopenharmony_ci# Run this in the directory containing the memory model.
2062306a36Sopenharmony_ci#
2162306a36Sopenharmony_ci# This script makes no attempt to run the litmus tests concurrently.
2262306a36Sopenharmony_ci#
2362306a36Sopenharmony_ci# Copyright IBM Corporation, 2018
2462306a36Sopenharmony_ci#
2562306a36Sopenharmony_ci# Author: Paul E. McKenney <paulmck@linux.ibm.com>
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci. scripts/parseargs.sh
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cilitmusdir=litmus-tests
3062306a36Sopenharmony_ciif test -d "$litmusdir" -a -r "$litmusdir" -a -x "$litmusdir"
3162306a36Sopenharmony_cithen
3262306a36Sopenharmony_ci	:
3362306a36Sopenharmony_cielse
3462306a36Sopenharmony_ci	echo ' --- ' error: $litmusdir is not an accessible directory
3562306a36Sopenharmony_ci	exit 255
3662306a36Sopenharmony_cifi
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci# Create any new directories that have appeared in the litmus-tests
3962306a36Sopenharmony_ci# directory since the last run.
4062306a36Sopenharmony_ciif test "$LKMM_DESTDIR" != "."
4162306a36Sopenharmony_cithen
4262306a36Sopenharmony_ci	find $litmusdir -type d -print |
4362306a36Sopenharmony_ci	( cd "$LKMM_DESTDIR"; sed -e 's/^/mkdir -p /' | sh )
4462306a36Sopenharmony_cifi
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci# Run the script on all the litmus tests in the specified directory
4762306a36Sopenharmony_ciret=0
4862306a36Sopenharmony_cifor i in $litmusdir/*.litmus
4962306a36Sopenharmony_cido
5062306a36Sopenharmony_ci	if test -n "$LKMM_HW_MAP_FILE" && ! scripts/simpletest.sh $i
5162306a36Sopenharmony_ci	then
5262306a36Sopenharmony_ci		continue
5362306a36Sopenharmony_ci	fi
5462306a36Sopenharmony_ci	if ! scripts/checklitmus.sh $i
5562306a36Sopenharmony_ci	then
5662306a36Sopenharmony_ci		ret=1
5762306a36Sopenharmony_ci	fi
5862306a36Sopenharmony_cidone
5962306a36Sopenharmony_ciif test "$ret" -ne 0
6062306a36Sopenharmony_cithen
6162306a36Sopenharmony_ci	echo " ^^^ VERIFICATION MISMATCHES" 1>&2
6262306a36Sopenharmony_cielse
6362306a36Sopenharmony_ci	echo All litmus tests verified as was expected. 1>&2
6462306a36Sopenharmony_cifi
6562306a36Sopenharmony_ciexit $ret
66