tools/testing/selftests/damon/sysfs.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/damon/sysfs.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/damon/sysfs.sh
Extension
.sh
Size
10602 bytes
Lines
433
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

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

source _common.sh

# Kselftest frmework requirement - SKIP code is 4.
ksft_skip=4

ensure_write_succ()
{
	file=$1
	content=$2
	reason=$3

	if ! echo "$content" > "$file"
	then
		echo "writing $content to $file failed"
		echo "expected success because $reason"
		exit 1
	fi
}

ensure_write_fail()
{
	file=$1
	content=$2
	reason=$3

	if (echo "$content" > "$file") 2> /dev/null
	then
		echo "writing $content to $file succeed ($fail_reason)"
		echo "expected failure because $reason"
		exit 1
	fi
}

ensure_dir()
{
	dir=$1
	to_ensure=$2
	if [ "$to_ensure" = "exist" ] && [ ! -d "$dir" ]
	then
		echo "$dir dir is expected but not found"
		exit 1
	elif [ "$to_ensure" = "not_exist" ] && [ -d "$dir" ]
	then
		echo "$dir dir is not expected but found"
		exit 1
	fi
}

ensure_file()
{
	file=$1
	to_ensure=$2
	permission=$3
	if [ "$to_ensure" = "exist" ]
	then
		if [ ! -f "$file" ]
		then
			echo "$file is expected but not found"
			exit 1
		fi
		perm=$(stat -c "%a" "$file")
		if [ ! "$perm" = "$permission" ]
		then
			echo "$file permission: expected $permission but $perm"
			exit 1
		fi
	elif [ "$to_ensure" = "not_exist" ] && [ -f "$dir" ]

Annotation

Implementation Notes