Skip to content

Commit d87e5ed

Browse files
jpirkodavem330
authored andcommitted
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: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 873343e commit d87e5ed

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,25 @@ setup_wait()
250250
sleep $WAIT_TIME
251251
}
252252

253+
cmd_jq()
254+
{
255+
local cmd=$1
256+
local jq_exp=$2
257+
local ret
258+
local output
259+
260+
output="$($cmd)"
261+
# it the command fails, return error right away
262+
ret=$?
263+
if [[ $ret -ne 0 ]]; then
264+
return $ret
265+
fi
266+
output=$(echo $output | jq -r "$jq_exp")
267+
echo $output
268+
# return success only in case of non-empty output
269+
[ ! -z "$output" ]
270+
}
271+
253272
lldpad_app_wait_set()
254273
{
255274
local dev=$1; shift

tools/testing/selftests/net/forwarding/tc_common.sh

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@ tc_check_packets()
88
local id=$1
99
local handle=$2
1010
local count=$3
11-
local ret
1211

13-
output="$(tc -j -s filter show $id)"
14-
# workaround the jq bug which causes jq to return 0 in case input is ""
15-
ret=$?
16-
if [[ $ret -ne 0 ]]; then
17-
return $ret
18-
fi
19-
echo $output | \
20-
jq -e ".[] \
21-
| select(.options.handle == $handle) \
22-
| select(.options.actions[0].stats.packets == $count)" \
23-
&> /dev/null
24-
return $?
12+
cmd_jq "tc -j -s filter show $id" \
13+
".[] | select(.options.handle == $handle) | \
14+
select(.options.actions[0].stats.packets == $count)" \
15+
&> /dev/null
2516
}

0 commit comments

Comments
 (0)