162306a36Sopenharmony_ci#!/bin/sh
262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+
362306a36Sopenharmony_ci#
462306a36Sopenharmony_ci# Runs the C-language litmus tests having a maximum number of processes
562306a36Sopenharmony_ci# to run, defaults to 6.
662306a36Sopenharmony_ci#
762306a36Sopenharmony_ci# sh checkghlitmus.sh
862306a36Sopenharmony_ci#
962306a36Sopenharmony_ci# Run from the Linux kernel tools/memory-model directory.  See the
1062306a36Sopenharmony_ci# parseargs.sh scripts for arguments.
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci. scripts/parseargs.sh
1362306a36Sopenharmony_ci. scripts/hwfnseg.sh
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciT=/tmp/checkghlitmus.sh.$$
1662306a36Sopenharmony_citrap 'rm -rf $T' 0
1762306a36Sopenharmony_cimkdir $T
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci# Clone the repository if it is not already present.
2062306a36Sopenharmony_ciif test -d litmus
2162306a36Sopenharmony_cithen
2262306a36Sopenharmony_ci	:
2362306a36Sopenharmony_cielse
2462306a36Sopenharmony_ci	git clone https://github.com/paulmckrcu/litmus
2562306a36Sopenharmony_ci	( cd litmus; git checkout origin/master )
2662306a36Sopenharmony_cifi
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci# Create any new directories that have appeared in the github litmus
2962306a36Sopenharmony_ci# repo since the last run.
3062306a36Sopenharmony_ciif test "$LKMM_DESTDIR" != "."
3162306a36Sopenharmony_cithen
3262306a36Sopenharmony_ci	find litmus -type d -print |
3362306a36Sopenharmony_ci	( cd "$LKMM_DESTDIR"; sed -e 's/^/mkdir -p /' | sh )
3462306a36Sopenharmony_cifi
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci# Create a list of the specified litmus tests previously run.
3762306a36Sopenharmony_ci( cd $LKMM_DESTDIR; find litmus -name "*.litmus${hwfnseg}.out" -print ) |
3862306a36Sopenharmony_ci	sed -e "s/${hwfnseg}"'\.out$//' |
3962306a36Sopenharmony_ci	xargs -r grep -E -l '^ \* Result: (Never|Sometimes|Always|DEADLOCK)' |
4062306a36Sopenharmony_ci	xargs -r grep -L "^P${LKMM_PROCS}"> $T/list-C-already
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci# Create a list of C-language litmus tests with "Result:" commands and
4362306a36Sopenharmony_ci# no more than the specified number of processes.
4462306a36Sopenharmony_cifind litmus -name '*.litmus' -print | mselect7 -arch C > $T/list-C
4562306a36Sopenharmony_cixargs < $T/list-C -r grep -E -l '^ \* Result: (Never|Sometimes|Always|DEADLOCK)' > $T/list-C-result
4662306a36Sopenharmony_cixargs < $T/list-C-result -r grep -L "^P${LKMM_PROCS}" > $T/list-C-result-short
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci# Form list of tests without corresponding .out files
4962306a36Sopenharmony_cisort $T/list-C-already $T/list-C-result-short | uniq -u > $T/list-C-needed
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci# Run any needed tests.
5262306a36Sopenharmony_ciif scripts/runlitmushist.sh < $T/list-C-needed > $T/run.stdout 2> $T/run.stderr
5362306a36Sopenharmony_cithen
5462306a36Sopenharmony_ci	errs=
5562306a36Sopenharmony_cielse
5662306a36Sopenharmony_ci	errs=1
5762306a36Sopenharmony_cifi
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_cised < $T/list-C-result-short -e 's,^,scripts/judgelitmus.sh ,' |
6062306a36Sopenharmony_ci	sh > $T/judge.stdout 2> $T/judge.stderr
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciif test -n "$errs"
6362306a36Sopenharmony_cithen
6462306a36Sopenharmony_ci	cat $T/run.stderr 1>&2
6562306a36Sopenharmony_cifi
6662306a36Sopenharmony_cigrep '!!!' $T/judge.stdout
67