Skip to content

Commit

Permalink
selftests: net: push jq workaround into separate helper
Browse files Browse the repository at this point in the history
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: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jiri Pirko authored and David S. Miller committed Aug 15, 2019
1 parent 873343e commit d87e5ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
19 changes: 19 additions & 0 deletions tools/testing/selftests/net/forwarding/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 4 additions & 13 deletions tools/testing/selftests/net/forwarding/tc_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)" \
&> /dev/null
return $?
cmd_jq "tc -j -s filter show $id" \
".[] | select(.options.handle == $handle) | \
select(.options.actions[0].stats.packets == $count)" \
&> /dev/null
}

0 comments on commit d87e5ed

Please sign in to comment.