#!/bin/sh -efu # # Check -D option. # # Copyright (c) 2019 Dmitry V. Levin # All rights reserved. # # SPDX-License-Identifier: GPL-2.0-or-later . "${srcdir=.}/init.sh" check_prog sed get_parent_pid() { sed '/^PPid:[[:space:]]*/!d;s///' } get_tracer_pid() { sed '/^TracerPid:[[:space:]]*/!d;s///' } status_file=/proc/self/status [ -f "$status_file" ] || framework_skip_ "$status_file is not available" set -- sed -r -n '/^(P|Tracer)Pid:/p' "$status_file" "$@" > "$LOG" || framework_skip_ "$* does not work" # not traced: PPid > 0, TracerPid == 0 [ "$(get_parent_pid < "$LOG")" -gt 0 ] && [ "$(get_tracer_pid < "$LOG")" -eq 0 ] || dump_log_and_fail_with "$*: unexpected output" # !-D: PPid > 0, TracerPid > 0, PPid == TracerPid run_strace -q -enone "$@" > "$OUT" [ "$(get_parent_pid < "$OUT")" -gt 0 ] && [ "$(get_tracer_pid < "$OUT")" -gt 0 ] && [ "$(get_parent_pid < "$OUT")" = "$(get_tracer_pid < "$OUT")" ] || { cat < "$OUT" > "$LOG" dump_log_and_fail_with "$STRACE $args: unexpected output" } match_diff test_parent_tracer_pid() { local d d="$1"; shift # -D/-DD/-DDD: PPid > 0, TracerPid > 0, PPid != TracerPid run_strace $d -q -enone "$@" > "$OUT" [ "$(get_parent_pid < "$OUT")" -gt 0 ] && [ "$(get_tracer_pid < "$OUT")" -gt 0 ] && [ "$(get_parent_pid < "$OUT")" != "$(get_tracer_pid < "$OUT")" ] || { cat < "$OUT" > "$LOG" dump_log_and_fail_with "$STRACE $args: unexpected output" } match_diff } test_parent_tracer_pid -D "$@" test_parent_tracer_pid -DD "$@" test_parent_tracer_pid -DDD "$@"