18c2ecf20Sopenharmony_ci#!/bin/sh
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# Runs the C-language litmus tests having a maximum number of processes
58c2ecf20Sopenharmony_ci# to run, defaults to 6.
68c2ecf20Sopenharmony_ci#
78c2ecf20Sopenharmony_ci# sh checkghlitmus.sh
88c2ecf20Sopenharmony_ci#
98c2ecf20Sopenharmony_ci# Run from the Linux kernel tools/memory-model directory.  See the
108c2ecf20Sopenharmony_ci# parseargs.sh scripts for arguments.
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci. scripts/parseargs.sh
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciT=/tmp/checkghlitmus.sh.$$
158c2ecf20Sopenharmony_citrap 'rm -rf $T' 0
168c2ecf20Sopenharmony_cimkdir $T
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci# Clone the repository if it is not already present.
198c2ecf20Sopenharmony_ciif test -d litmus
208c2ecf20Sopenharmony_cithen
218c2ecf20Sopenharmony_ci	:
228c2ecf20Sopenharmony_cielse
238c2ecf20Sopenharmony_ci	git clone https://github.com/paulmckrcu/litmus
248c2ecf20Sopenharmony_ci	( cd litmus; git checkout origin/master )
258c2ecf20Sopenharmony_cifi
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci# Create any new directories that have appeared in the github litmus
288c2ecf20Sopenharmony_ci# repo since the last run.
298c2ecf20Sopenharmony_ciif test "$LKMM_DESTDIR" != "."
308c2ecf20Sopenharmony_cithen
318c2ecf20Sopenharmony_ci	find litmus -type d -print |
328c2ecf20Sopenharmony_ci	( cd "$LKMM_DESTDIR"; sed -e 's/^/mkdir -p /' | sh )
338c2ecf20Sopenharmony_cifi
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci# Create a list of the C-language litmus tests previously run.
368c2ecf20Sopenharmony_ci( cd $LKMM_DESTDIR; find litmus -name '*.litmus.out' -print ) |
378c2ecf20Sopenharmony_ci	sed -e 's/\.out$//' |
388c2ecf20Sopenharmony_ci	xargs -r egrep -l '^ \* Result: (Never|Sometimes|Always|DEADLOCK)' |
398c2ecf20Sopenharmony_ci	xargs -r grep -L "^P${LKMM_PROCS}"> $T/list-C-already
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci# Create a list of C-language litmus tests with "Result:" commands and
428c2ecf20Sopenharmony_ci# no more than the specified number of processes.
438c2ecf20Sopenharmony_cifind litmus -name '*.litmus' -exec grep -l -m 1 "^C " {} \; > $T/list-C
448c2ecf20Sopenharmony_cixargs < $T/list-C -r egrep -l '^ \* Result: (Never|Sometimes|Always|DEADLOCK)' > $T/list-C-result
458c2ecf20Sopenharmony_cixargs < $T/list-C-result -r grep -L "^P${LKMM_PROCS}" > $T/list-C-result-short
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci# Form list of tests without corresponding .litmus.out files
488c2ecf20Sopenharmony_cisort $T/list-C-already $T/list-C-result-short | uniq -u > $T/list-C-needed
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci# Run any needed tests.
518c2ecf20Sopenharmony_ciif scripts/runlitmushist.sh < $T/list-C-needed > $T/run.stdout 2> $T/run.stderr
528c2ecf20Sopenharmony_cithen
538c2ecf20Sopenharmony_ci	errs=
548c2ecf20Sopenharmony_cielse
558c2ecf20Sopenharmony_ci	errs=1
568c2ecf20Sopenharmony_cifi
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cised < $T/list-C-result-short -e 's,^,scripts/judgelitmus.sh ,' |
598c2ecf20Sopenharmony_ci	sh > $T/judge.stdout 2> $T/judge.stderr
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciif test -n "$errs"
628c2ecf20Sopenharmony_cithen
638c2ecf20Sopenharmony_ci	cat $T/run.stderr 1>&2
648c2ecf20Sopenharmony_cifi
658c2ecf20Sopenharmony_cigrep '!!!' $T/judge.stdout
66