• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4lib_dir=$(dirname $0)/../../../net/forwarding
5
6ALL_TESTS="fw_flash_test params_test regions_test"
7NUM_NETIFS=0
8source $lib_dir/lib.sh
9
10BUS_ADDR=10
11PORT_COUNT=4
12DEV_NAME=netdevsim$BUS_ADDR
13SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/
14DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_NAME/
15DL_HANDLE=netdevsim/$DEV_NAME
16
17fw_flash_test()
18{
19	RET=0
20
21	devlink dev flash $DL_HANDLE file dummy
22	check_err $? "Failed to flash with status updates on"
23
24	echo "n"> $DEBUGFS_DIR/fw_update_status
25	check_err $? "Failed to disable status updates"
26
27	devlink dev flash $DL_HANDLE file dummy
28	check_err $? "Failed to flash with status updates off"
29
30	log_test "fw flash test"
31}
32
33param_get()
34{
35	local name=$1
36
37	cmd_jq "devlink dev param show $DL_HANDLE name $name -j" \
38	       '.[][][].values[] | select(.cmode == "driverinit").value'
39}
40
41param_set()
42{
43	local name=$1
44	local value=$2
45
46	devlink dev param set $DL_HANDLE name $name cmode driverinit value $value
47}
48
49check_value()
50{
51	local name=$1
52	local phase_name=$2
53	local expected_param_value=$3
54	local expected_debugfs_value=$4
55	local value
56
57	value=$(param_get $name)
58	check_err $? "Failed to get $name param value"
59	[ "$value" == "$expected_param_value" ]
60	check_err $? "Unexpected $phase_name $name param value"
61	value=$(<$DEBUGFS_DIR/$name)
62	check_err $? "Failed to get $name debugfs value"
63	[ "$value" == "$expected_debugfs_value" ]
64	check_err $? "Unexpected $phase_name $name debugfs value"
65}
66
67params_test()
68{
69	RET=0
70
71	local max_macs
72	local test1
73
74	check_value max_macs initial 32 32
75	check_value test1 initial true Y
76
77	param_set max_macs 16
78	check_err $? "Failed to set max_macs param value"
79	param_set test1 false
80	check_err $? "Failed to set test1 param value"
81
82	check_value max_macs post-set 16 32
83	check_value test1 post-set false Y
84
85	devlink dev reload $DL_HANDLE
86
87	check_value max_macs post-reload 16 16
88	check_value test1 post-reload false N
89
90	log_test "params test"
91}
92
93check_region_size()
94{
95	local name=$1
96	local size
97
98	size=$(devlink region show $DL_HANDLE/$name -j | jq -e -r '.[][].size')
99	check_err $? "Failed to get $name region size"
100	[ $size -eq 32768 ]
101	check_err $? "Invalid $name region size"
102}
103
104check_region_snapshot_count()
105{
106	local name=$1
107	local phase_name=$2
108	local expected_count=$3
109	local count
110
111	count=$(devlink region show $DL_HANDLE/$name -j | jq -e -r '.[][].snapshot | length')
112	[ $count -eq $expected_count ]
113	check_err $? "Unexpected $phase_name snapshot count"
114}
115
116regions_test()
117{
118	RET=0
119
120	local count
121
122	check_region_size dummy
123	check_region_snapshot_count dummy initial 0
124
125	echo ""> $DEBUGFS_DIR/take_snapshot
126	check_err $? "Failed to take first dummy region snapshot"
127	check_region_snapshot_count dummy post-first-snapshot 1
128
129	echo ""> $DEBUGFS_DIR/take_snapshot
130	check_err $? "Failed to take second dummy region snapshot"
131	check_region_snapshot_count dummy post-second-snapshot 2
132
133	echo ""> $DEBUGFS_DIR/take_snapshot
134	check_err $? "Failed to take third dummy region snapshot"
135	check_region_snapshot_count dummy post-third-snapshot 3
136
137	devlink region del $DL_HANDLE/dummy snapshot 1
138	check_err $? "Failed to delete first dummy region snapshot"
139
140	check_region_snapshot_count dummy post-first-delete 2
141
142	log_test "regions test"
143}
144
145setup_prepare()
146{
147	modprobe netdevsim
148	echo "$BUS_ADDR $PORT_COUNT" > /sys/bus/netdevsim/new_device
149	while [ ! -d $SYSFS_NET_DIR ] ; do :; done
150}
151
152cleanup()
153{
154	pre_cleanup
155	echo "$BUS_ADDR" > /sys/bus/netdevsim/del_device
156	modprobe -r netdevsim
157}
158
159trap cleanup EXIT
160
161setup_prepare
162
163tests_run
164
165exit $EXIT_STATUS
166