Commit 0cb477dd authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

test/fuzz/llvm: Simplify parallel execution logic

parent 0f57273a
Loading
Loading
Loading
Loading
+15 −19
Original line number Diff line number Diff line
@@ -30,32 +30,28 @@ function start_llvm_fuzz_all() {
	local testn=$1    # Number of test to run in parallel
	local fuzz_num=$2 # Number of fuzzer tests
	local time=$3     # Time available for all fuzzers
	local testn_idx idx
	local core
	local pid

	# Calculate time for a single test and multiply it by number
	# of test execute in parallel and round it up to 1 sek per test
	timen=$(printf %d $(((time / fuzz_num) * testn)))
	timen=$((timen == 0 ? 1 : timen))

	for ((i = 0; i < fuzz_num; i++)); do
		core=$(printf "0x%x" $((0x1 << (i % testn))))
		start_llvm_fuzz $i $timen $core &> $output_dir/llvm/llvm_"$FUZZER"_$i.txt &
	for ((i = 0; i < fuzz_num; i += testn)); do
		idx=-1 pids=()
		# Run max up to $testn tests in parallel ...
		while ((testn_idx = i + ++idx, testn_idx < fuzz_num && idx < testn)); do
			core=$(printf "0x%x" $((0x1 << idx)))
			start_llvm_fuzz $testn_idx $timen $core &> "$output_dir/llvm/llvm_${FUZZER}_${testn_idx}.txt" &
			pids+=($!)

		# Wait for processes to finish
		if (((i + 1) % testn == 0 || fuzz_num - i - 1 == 0)); then
			(
				sleep $((timen * 10 + 100))
				echo "Timeout $time"
				exit 1
			) &
			timeout_pid=$!
		done
		# ... and now wait for them
		for pid in "${pids[@]}"; do
				wait $pid
			wait "$pid"
		done
			kill $timeout_pid || :
			pids=()
		fi
		# queue up another $testn bundle at next iteration
	done
}