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

. "./init.sh"
. "./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=8
# 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
