tools/testing/selftests/net/hsr/link_faults.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/hsr/link_faults.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/hsr/link_faults.sh
Extension
.sh
Size
7889 bytes
Lines
379
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

if (echo "$nts" | grep -qE "^([0-9a-f]{2}:){5}") && \
		    ! (echo "$nts" | grep -q "00:00:00:00:00:00"); then
			return
		fi

		sleep 1
		((WAIT--))
	done
	check_err 1 "Failed to wait for merged node table entries"
}

setup_topo()
{
	local proto="$1"

	if [ "$proto" = "HSRv0" ]; then
		setup_hsr_topo 0
		wait_for_hsr_node_table
	elif [ "$proto" = "HSRv1" ]; then
		setup_hsr_topo 1
		wait_for_hsr_node_table
	elif [ "$proto" = "PRP" ]; then
		setup_prp_topo
	else
		check_err 1 "Unknown protocol (${proto})"
	fi
}

check_ping()
{
	local node="$1"
	local dst="$2"
	local accepted_dups="$3"
	local ping_args="-q -i 0.01 -c 400"

	log_info "Running ping $node -> $dst"
	# shellcheck disable=SC2086
	output=$(ip netns exec "$node" ping $ping_args "$dst" | \
		grep "packets transmitted")
	log_info "$output"

	dups=0
	loss=0

	if [[ "$output" =~ \+([0-9]+)" duplicates" ]]; then
		dups="${BASH_REMATCH[1]}"
	fi
	if [[ "$output" =~ ([0-9\.]+\%)" packet loss" ]]; then
		loss="${BASH_REMATCH[1]}"
	fi

	if [ "$dups" -gt "$accepted_dups" ]; then
		check_err 1 "Unexpected duplicate packets (${dups})"
	fi
	if [ "$loss" != "0%" ]; then
		check_err 1 "Unexpected packet loss (${loss})"
	fi
}

test_clean()
{
	local proto="$1"

	RET=0
	tname="${FUNCNAME[0]} - ${proto}"

	setup_topo "$proto"
	if ((RET != ksft_pass)); then
		log_test "${tname} setup"
		return

Annotation

Implementation Notes