1*5aa45cc5SMark Brown#!/bin/bash
2*5aa45cc5SMark Brown# SPDX-License-Identifier: GPL-2.0-only
3*5aa45cc5SMark Brown# Copyright (C) 2015-2019 ARM Limited.
4*5aa45cc5SMark Brown# Original author: Dave Martin <Dave.Martin@arm.com>
5*5aa45cc5SMark Brown
6*5aa45cc5SMark Brownset -ue
7*5aa45cc5SMark Brown
8*5aa45cc5SMark BrownNR_CPUS=`nproc`
9*5aa45cc5SMark Brown
10*5aa45cc5SMark Brownpids=
11*5aa45cc5SMark Brownlogs=
12*5aa45cc5SMark Brown
13*5aa45cc5SMark Browncleanup () {
14*5aa45cc5SMark Brown	trap - INT TERM CHLD
15*5aa45cc5SMark Brown	set +e
16*5aa45cc5SMark Brown
17*5aa45cc5SMark Brown	if [ -n "$pids" ]; then
18*5aa45cc5SMark Brown		kill $pids
19*5aa45cc5SMark Brown		wait $pids
20*5aa45cc5SMark Brown		pids=
21*5aa45cc5SMark Brown	fi
22*5aa45cc5SMark Brown
23*5aa45cc5SMark Brown	if [ -n "$logs" ]; then
24*5aa45cc5SMark Brown		cat $logs
25*5aa45cc5SMark Brown		rm $logs
26*5aa45cc5SMark Brown		logs=
27*5aa45cc5SMark Brown	fi
28*5aa45cc5SMark Brown}
29*5aa45cc5SMark Brown
30*5aa45cc5SMark Browninterrupt () {
31*5aa45cc5SMark Brown	cleanup
32*5aa45cc5SMark Brown	exit 0
33*5aa45cc5SMark Brown}
34*5aa45cc5SMark Brown
35*5aa45cc5SMark Brownchild_died () {
36*5aa45cc5SMark Brown	cleanup
37*5aa45cc5SMark Brown	exit 1
38*5aa45cc5SMark Brown}
39*5aa45cc5SMark Brown
40*5aa45cc5SMark Browntrap interrupt INT TERM EXIT
41*5aa45cc5SMark Brown
42*5aa45cc5SMark Brownfor x in `seq 0 $((NR_CPUS * 4))`; do
43*5aa45cc5SMark Brown	log=`mktemp`
44*5aa45cc5SMark Brown	logs=$logs\ $log
45*5aa45cc5SMark Brown	./za-test >$log &
46*5aa45cc5SMark Brown	pids=$pids\ $!
47*5aa45cc5SMark Browndone
48*5aa45cc5SMark Brown
49*5aa45cc5SMark Brown# Wait for all child processes to be created:
50*5aa45cc5SMark Brownsleep 10
51*5aa45cc5SMark Brown
52*5aa45cc5SMark Brownwhile :; do
53*5aa45cc5SMark Brown	kill -USR1 $pids
54*5aa45cc5SMark Browndone &
55*5aa45cc5SMark Brownpids=$pids\ $!
56*5aa45cc5SMark Brown
57*5aa45cc5SMark Brownwait
58*5aa45cc5SMark Brown
59*5aa45cc5SMark Brownexit 1
60