Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d87e5edb authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller
Browse files

selftests: net: push jq workaround into separate helper



Push the jq return value workaround code into a separate helper so it
could be used by the rest of the code.

Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 873343e7
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -250,6 +250,25 @@ setup_wait()
	sleep $WAIT_TIME
}

cmd_jq()
{
	local cmd=$1
	local jq_exp=$2
	local ret
	local output

	output="$($cmd)"
	# it the command fails, return error right away
	ret=$?
	if [[ $ret -ne 0 ]]; then
		return $ret
	fi
	output=$(echo $output | jq -r "$jq_exp")
	echo $output
	# return success only in case of non-empty output
	[ ! -z "$output" ]
}

lldpad_app_wait_set()
{
	local dev=$1; shift
+4 −13
Original line number Diff line number Diff line
@@ -8,18 +8,9 @@ tc_check_packets()
	local id=$1
	local handle=$2
	local count=$3
	local ret

	output="$(tc -j -s filter show $id)"
	# workaround the jq bug which causes jq to return 0 in case input is ""
	ret=$?
	if [[ $ret -ne 0 ]]; then
		return $ret
	fi
	echo $output | \
		jq -e ".[] \
		| select(.options.handle == $handle) \
		| select(.options.actions[0].stats.packets == $count)" \
	cmd_jq "tc -j -s filter show $id" \
	       ".[] | select(.options.handle == $handle) | \
	              select(.options.actions[0].stats.packets == $count)" \
	       &> /dev/null
	return $?
}