#!/bin/sh
#
# Check decoding of threads when a non-leader thread invokes execve.
#
# Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
# Copyright (c) 2016-2019 The strace developers.
# All rights reserved.
#
# SPDX-License-Identifier: GPL-2.0-or-later

. "./init.sh"

# Check that PTRACE_EVENT_EXEC support in kernel is good enough.
# The kernel before commit v3.1-rc1~308^2~7 reported 0 instead of old pid.
require_min_kernel_version_or_skip 3.1

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

run_prog > /dev/null

set -- -a21 -f -esignal=none -e trace=execve,exit,nanosleep,rt_sigsuspend $args

# Due to probabilistic nature of the test, try it several times.
while :; do
	run_strace "$@" > "$EXP"
	sed 1d < "$LOG" > "$OUT"
	diff -- "$EXP" "$OUT" && exit 0
	s1="$(date +%s)"
	if [ "$(($s1-$s0))" -gt "$(($TIMEOUT_DURATION/2))" ]; then
		fail_ "$STRACE $* output mismatch"
	fi
done
