18c2ecf20Sopenharmony_ci#!/bin/sh
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# Given a .litmus test and the corresponding .litmus.out file, check
58c2ecf20Sopenharmony_ci# the .litmus.out file against the "Result:" comment to judge whether
68c2ecf20Sopenharmony_ci# the test ran correctly.
78c2ecf20Sopenharmony_ci#
88c2ecf20Sopenharmony_ci# Usage:
98c2ecf20Sopenharmony_ci#	judgelitmus.sh file.litmus
108c2ecf20Sopenharmony_ci#
118c2ecf20Sopenharmony_ci# Run this in the directory containing the memory model, specifying the
128c2ecf20Sopenharmony_ci# pathname of the litmus test to check.
138c2ecf20Sopenharmony_ci#
148c2ecf20Sopenharmony_ci# Copyright IBM Corporation, 2018
158c2ecf20Sopenharmony_ci#
168c2ecf20Sopenharmony_ci# Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cilitmus=$1
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciif test -f "$litmus" -a -r "$litmus"
218c2ecf20Sopenharmony_cithen
228c2ecf20Sopenharmony_ci	:
238c2ecf20Sopenharmony_cielse
248c2ecf20Sopenharmony_ci	echo ' --- ' error: \"$litmus\" is not a readable file
258c2ecf20Sopenharmony_ci	exit 255
268c2ecf20Sopenharmony_cifi
278c2ecf20Sopenharmony_ciif test -f "$LKMM_DESTDIR/$litmus".out -a -r "$LKMM_DESTDIR/$litmus".out
288c2ecf20Sopenharmony_cithen
298c2ecf20Sopenharmony_ci	:
308c2ecf20Sopenharmony_cielse
318c2ecf20Sopenharmony_ci	echo ' --- ' error: \"$LKMM_DESTDIR/$litmus\".out is not a readable file
328c2ecf20Sopenharmony_ci	exit 255
338c2ecf20Sopenharmony_cifi
348c2ecf20Sopenharmony_ciif grep -q '^ \* Result: ' $litmus
358c2ecf20Sopenharmony_cithen
368c2ecf20Sopenharmony_ci	outcome=`grep -m 1 '^ \* Result: ' $litmus | awk '{ print $3 }'`
378c2ecf20Sopenharmony_cielse
388c2ecf20Sopenharmony_ci	outcome=specified
398c2ecf20Sopenharmony_cifi
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cigrep '^Observation' $LKMM_DESTDIR/$litmus.out
428c2ecf20Sopenharmony_ciif grep -q '^Observation' $LKMM_DESTDIR/$litmus.out
438c2ecf20Sopenharmony_cithen
448c2ecf20Sopenharmony_ci	:
458c2ecf20Sopenharmony_cielse
468c2ecf20Sopenharmony_ci	echo ' !!! Verification error' $litmus
478c2ecf20Sopenharmony_ci	if ! grep -q '!!!' $LKMM_DESTDIR/$litmus.out
488c2ecf20Sopenharmony_ci	then
498c2ecf20Sopenharmony_ci		echo ' !!! Verification error' >> $LKMM_DESTDIR/$litmus.out 2>&1
508c2ecf20Sopenharmony_ci	fi
518c2ecf20Sopenharmony_ci	exit 255
528c2ecf20Sopenharmony_cifi
538c2ecf20Sopenharmony_ciif test "$outcome" = DEADLOCK
548c2ecf20Sopenharmony_cithen
558c2ecf20Sopenharmony_ci	if grep '^Observation' $LKMM_DESTDIR/$litmus.out | grep -q 'Never 0 0$'
568c2ecf20Sopenharmony_ci	then
578c2ecf20Sopenharmony_ci		ret=0
588c2ecf20Sopenharmony_ci	else
598c2ecf20Sopenharmony_ci		echo " !!! Unexpected non-$outcome verification" $litmus
608c2ecf20Sopenharmony_ci		if ! grep -q '!!!' $LKMM_DESTDIR/$litmus.out
618c2ecf20Sopenharmony_ci		then
628c2ecf20Sopenharmony_ci			echo " !!! Unexpected non-$outcome verification" >> $LKMM_DESTDIR/$litmus.out 2>&1
638c2ecf20Sopenharmony_ci		fi
648c2ecf20Sopenharmony_ci		ret=1
658c2ecf20Sopenharmony_ci	fi
668c2ecf20Sopenharmony_cielif grep '^Observation' $LKMM_DESTDIR/$litmus.out | grep -q $outcome || test "$outcome" = Maybe
678c2ecf20Sopenharmony_cithen
688c2ecf20Sopenharmony_ci	ret=0
698c2ecf20Sopenharmony_cielse
708c2ecf20Sopenharmony_ci	echo " !!! Unexpected non-$outcome verification" $litmus
718c2ecf20Sopenharmony_ci	if ! grep -q '!!!' $LKMM_DESTDIR/$litmus.out
728c2ecf20Sopenharmony_ci	then
738c2ecf20Sopenharmony_ci		echo " !!! Unexpected non-$outcome verification" >> $LKMM_DESTDIR/$litmus.out 2>&1
748c2ecf20Sopenharmony_ci	fi
758c2ecf20Sopenharmony_ci	ret=1
768c2ecf20Sopenharmony_cifi
778c2ecf20Sopenharmony_citail -2 $LKMM_DESTDIR/$litmus.out | head -1
788c2ecf20Sopenharmony_ciexit $ret
79