#!/bin/sh
#
# Check seccomp filter performance.
#
# Copyright (c) 2019 Paul Chaignon <paul.chaignon@gmail.com>
# Copyright (c) 2018-2021 The strace developers.
# All rights reserved.
#
# SPDX-License-Identifier: GPL-2.0-or-later

. "${srcdir=.}/init.sh"
. "${srcdir=.}/filter_seccomp.sh"

args="-f -qq -e signal=none -e trace=fchdir ../$NAME"
num_regular="$(run_strace               $args)"
mv "$LOG" "$LOG.regular"
num_seccomp="$(run_strace --seccomp-bpf $args)"
mv "$LOG" "$LOG.seccomp"
match_diff "$LOG.regular" "$LOG.seccomp"

min_ratio=5
# With seccomp filter enabled, we should be able to complete
# at least $min_ratio times more chdir system calls.
ratio="$((num_seccomp / num_regular))"
if [ "$ratio" -lt "$min_ratio" ]; then
	fail_ "Only $ratio times more syscalls performed with seccomp filter enabled, expected at least $min_ratio times speedup"
fi
