tools/testing/selftests/exec/check-exec-tests.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/exec/check-exec-tests.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/exec/check-exec-tests.sh
Extension
.sh
Size
6534 bytes
Lines
206
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-2.0
#
# Test the "inc" interpreter.
#
# See include/uapi/linux/securebits.h, include/uapi/linux/fcntl.h and
# samples/check-exec/inc.c
#
# Copyright © 2024 Microsoft Corporation

set -u -e -o pipefail

EXPECTED_OUTPUT="1"
exec 2>/dev/null

DIR="$(dirname $(readlink -f "$0"))"
source "${DIR}"/../kselftest/ktap_helpers.sh

exec_direct() {
	local expect="$1"
	local script="$2"
	shift 2
	local ret=0
	local out

	# Updates PATH for `env` to execute the `inc` interpreter.
	out="$(PATH="." "$@" "${script}")" || ret=$?

	if [[ ${ret} -ne ${expect} ]]; then
		echo "ERROR: Wrong expectation for direct file execution: ${ret}"
		return 1
	fi
	if [[ ${ret} -eq 0 && "${out}" != "${EXPECTED_OUTPUT}" ]]; then
		echo "ERROR: Wrong output for direct file execution: ${out}"
		return 1
	fi
}

exec_indirect() {
	local expect="$1"
	local script="$2"
	shift 2
	local ret=0
	local out

	# Script passed as argument.
	out="$("$@" ./inc "${script}")" || ret=$?

	if [[ ${ret} -ne ${expect} ]]; then
		echo "ERROR: Wrong expectation for indirect file execution: ${ret}"
		return 1
	fi
	if [[ ${ret} -eq 0 && "${out}" != "${EXPECTED_OUTPUT}" ]]; then
		echo "ERROR: Wrong output for indirect file execution: ${out}"
		return 1
	fi
}

exec_stdin_reg() {
	local expect="$1"
	local script="$2"
	shift 2
	local ret=0
	local out

	# Executing stdin must be allowed if the related file is executable.
	out="$("$@" ./inc -i < "${script}")" || ret=$?

	if [[ ${ret} -ne ${expect} ]]; then
		echo "ERROR: Wrong expectation for stdin regular file execution: ${ret}"

Annotation

Implementation Notes