18c2ecf20Sopenharmony_ci#!/bin/bash 28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0+ 38c2ecf20Sopenharmony_ci# 48c2ecf20Sopenharmony_ci# Runs the C-language litmus tests specified on standard input, using up 58c2ecf20Sopenharmony_ci# to the specified number of CPUs (defaulting to all of them) and placing 68c2ecf20Sopenharmony_ci# the results in the specified directory (defaulting to the same place 78c2ecf20Sopenharmony_ci# the litmus test came from). 88c2ecf20Sopenharmony_ci# 98c2ecf20Sopenharmony_ci# sh runlitmushist.sh 108c2ecf20Sopenharmony_ci# 118c2ecf20Sopenharmony_ci# Run from the Linux kernel tools/memory-model directory. 128c2ecf20Sopenharmony_ci# This script uses environment variables produced by parseargs.sh. 138c2ecf20Sopenharmony_ci# 148c2ecf20Sopenharmony_ci# Copyright IBM Corporation, 2018 158c2ecf20Sopenharmony_ci# 168c2ecf20Sopenharmony_ci# Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ciT=/tmp/runlitmushist.sh.$$ 198c2ecf20Sopenharmony_citrap 'rm -rf $T' 0 208c2ecf20Sopenharmony_cimkdir $T 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ciif test -d litmus 238c2ecf20Sopenharmony_cithen 248c2ecf20Sopenharmony_ci : 258c2ecf20Sopenharmony_cielse 268c2ecf20Sopenharmony_ci echo Directory \"litmus\" missing, aborting run. 278c2ecf20Sopenharmony_ci exit 1 288c2ecf20Sopenharmony_cifi 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci# Prefixes for per-CPU scripts 318c2ecf20Sopenharmony_cifor ((i=0;i<$LKMM_JOBS;i++)) 328c2ecf20Sopenharmony_cido 338c2ecf20Sopenharmony_ci echo dir="$LKMM_DESTDIR" > $T/$i.sh 348c2ecf20Sopenharmony_ci echo T=$T >> $T/$i.sh 358c2ecf20Sopenharmony_ci echo herdoptions=\"$LKMM_HERD_OPTIONS\" >> $T/$i.sh 368c2ecf20Sopenharmony_ci cat << '___EOF___' >> $T/$i.sh 378c2ecf20Sopenharmony_ci runtest () { 388c2ecf20Sopenharmony_ci echo ' ... ' /usr/bin/time $LKMM_TIMEOUT_CMD herd7 $herdoptions $1 '>' $dir/$1.out '2>&1' 398c2ecf20Sopenharmony_ci if /usr/bin/time $LKMM_TIMEOUT_CMD herd7 $herdoptions $1 > $dir/$1.out 2>&1 408c2ecf20Sopenharmony_ci then 418c2ecf20Sopenharmony_ci if ! grep -q '^Observation ' $dir/$1.out 428c2ecf20Sopenharmony_ci then 438c2ecf20Sopenharmony_ci echo ' !!! Herd failed, no Observation:' $1 448c2ecf20Sopenharmony_ci fi 458c2ecf20Sopenharmony_ci else 468c2ecf20Sopenharmony_ci exitcode=$? 478c2ecf20Sopenharmony_ci if test "$exitcode" -eq 124 488c2ecf20Sopenharmony_ci then 498c2ecf20Sopenharmony_ci exitmsg="timed out" 508c2ecf20Sopenharmony_ci else 518c2ecf20Sopenharmony_ci exitmsg="failed, exit code $exitcode" 528c2ecf20Sopenharmony_ci fi 538c2ecf20Sopenharmony_ci echo ' !!! Herd' ${exitmsg}: $1 548c2ecf20Sopenharmony_ci fi 558c2ecf20Sopenharmony_ci } 568c2ecf20Sopenharmony_ci___EOF___ 578c2ecf20Sopenharmony_cidone 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciawk -v q="'" -v b='\\' ' 608c2ecf20Sopenharmony_ci{ 618c2ecf20Sopenharmony_ci print "echo `grep " q "^P[0-9]" b "+(" q " " $0 " | tail -1 | sed -e " q "s/^P" b "([0-9]" b "+" b ")(.*$/" b "1/" q "` " $0 628c2ecf20Sopenharmony_ci}' | bash | 638c2ecf20Sopenharmony_cisort -k1n | 648c2ecf20Sopenharmony_ciawk -v ncpu=$LKMM_JOBS -v t=$T ' 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci print "runtest " $2 >> t "/" NR % ncpu ".sh"; 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciEND { 708c2ecf20Sopenharmony_ci for (i = 0; i < ncpu; i++) { 718c2ecf20Sopenharmony_ci print "sh " t "/" i ".sh > " t "/" i ".sh.out 2>&1 &"; 728c2ecf20Sopenharmony_ci close(t "/" i ".sh"); 738c2ecf20Sopenharmony_ci } 748c2ecf20Sopenharmony_ci print "wait"; 758c2ecf20Sopenharmony_ci}' | sh 768c2ecf20Sopenharmony_cicat $T/*.sh.out 778c2ecf20Sopenharmony_ciif grep -q '!!!' $T/*.sh.out 788c2ecf20Sopenharmony_cithen 798c2ecf20Sopenharmony_ci echo ' ---' Summary: 1>&2 808c2ecf20Sopenharmony_ci grep '!!!' $T/*.sh.out 1>&2 818c2ecf20Sopenharmony_ci nfail="`grep '!!!' $T/*.sh.out | wc -l`" 828c2ecf20Sopenharmony_ci echo 'Number of failed herd7 runs (e.g., timeout): ' $nfail 1>&2 838c2ecf20Sopenharmony_ci exit 1 848c2ecf20Sopenharmony_cielse 858c2ecf20Sopenharmony_ci echo All runs completed successfully. 1>&2 868c2ecf20Sopenharmony_ci exit 0 878c2ecf20Sopenharmony_cifi 88