#!/bin/sh
#
# Check tracing of looping threads.
#
# Copyright (c) 2009-2018 The strace developers.
# All rights reserved.
#
# SPDX-License-Identifier: GPL-2.0-or-later

. "./init.sh"
. "./PTRACE_SEIZE.sh"

run_prog ../orphaned_process_group > /dev/null

run_prog_skip_if_failed date +%s > /dev/null
s0="$(date +%s)"

check_prog nproc
inc="$(nproc)"
[ "$inc" -ge 1 ] || inc=1

timeout_2="$(($TIMEOUT_DURATION/2))"
timeout_8="$(($TIMEOUT_DURATION/8))"
nproc=1

run_prog "../$NAME" "$timeout_8" "$nproc"

while :; do
	run_strace -f -qq -enone -esignal=none "../$NAME" "$timeout_2" "$nproc"

	s1="$(date +%s)"
	[ "$(($s1-$s0))" -lt "$timeout_8" ] ||
		break

	nproc="$(($nproc+$inc))"
done

warn_ "$ME_: nproc=$nproc elapsed=$(($s1-$s0))"
