• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  * Test cases for ethtool command-line parsing
3  * Copyright 2011 Solarflare Communications Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation, incorporated herein by reference.
8  */
9 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #define TEST_NO_WRAPPERS
13 #include "internal.h"
14 
15 static struct test_case {
16 	int rc;
17 	const char *args;
18 } test_cases[] = {
19 	{ 1, "" },
20 	{ 0, "devname" },
21 	{ 0, "15_char_devname" },
22 	{ 1, "16_char_devname!" },
23 	/* Argument parsing for -s is specialised */
24 	{ 0, "-s devname" },
25 	{ 0, "--change devname speed 100 duplex half mdix auto" },
26 	{ 1, "-s devname speed foo" },
27 	{ 1, "--change devname speed" },
28 	{ 0, "-s devname duplex half" },
29 	{ 1, "--change devname duplex foo" },
30 	{ 1, "-s devname duplex" },
31 	{ 1, "--change devname mdix foo" },
32 	{ 1, "-s devname mdix" },
33 	{ 0, "--change devname port tp" },
34 	{ 1, "-s devname port foo" },
35 	{ 1, "--change devname port" },
36 	{ 0, "-s devname autoneg on" },
37 	{ 1, "--change devname autoneg foo" },
38 	{ 1, "-s devname autoneg" },
39 	{ 0, "--change devname advertise 0x1" },
40 	{ 0, "--change devname advertise 0xf" },
41 	{ 0, "--change devname advertise 0Xf" },
42 	{ 0, "--change devname advertise 1" },
43 	{ 0, "--change devname advertise f" },
44 	{ 0, "--change devname advertise 01" },
45 	{ 0, "--change devname advertise 0f" },
46 	{ 0, "--change devname advertise 0xfffffffffffffffffffffffffffffffff" },
47 	{ 0, "--change devname advertise fffffffffffffffffffffffffffffffff" },
48 	{ 0, "--change devname advertise 0x0000fffffffffffffffffffffffffffff" },
49 	{ 0, "--change devname advertise 0000fffffffffffffffffffffffffffff" },
50 	{ 1, "-s devname advertise" },
51 	{ 1, "-s devname advertise 0x" },
52 	{ 1, "-s devname advertise foo" },
53 	{ 1, "-s devname advertise 0xfoo" },
54 	{ 1, "--change devname advertise" },
55 	{ 0, "-s devname phyad 1" },
56 	{ 1, "--change devname phyad foo" },
57 	{ 1, "-s devname phyad" },
58 	{ 0, "--change devname xcvr external" },
59 	{ 1, "-s devname xcvr foo" },
60 	{ 1, "--change devname xcvr" },
61 	{ 0, "-s devname wol p" },
62 	{ 1, "--change devname wol" },
63 	{ 0, "-s devname sopass 01:23:45:67:89:ab" },
64 	{ 1, "--change devname sopass 01:23:45:67:89:" },
65 	{ 1, "-s devname sopass 01:23:45:67:89" },
66 	{ 1, "--change devname sopass" },
67 	{ 0, "-s devname msglvl 1" },
68 	{ 1, "--change devname msglvl" },
69 	{ 0, "-s devname msglvl hw on rx_status off" },
70 	{ 1, "--change devname msglvl hw foo" },
71 	{ 1, "-s devname msglvl hw" },
72 	{ 0, "--change devname speed 100 duplex half port tp autoneg on advertise 0x1 phyad 1 xcvr external wol p sopass 01:23:45:67:89:ab msglvl 1" },
73 	{ 1, "-s devname foo" },
74 	{ 1, "-s" },
75 	{ 0, "-a devname" },
76 	{ 0, "--show-pause devname" },
77 	{ 1, "-a" },
78 	/* Many other sub-commands use parse_generic_cmdline() and
79 	 * don't need to be check in that much detail. */
80 	{ 0, "-A devname autoneg on" },
81 	{ 1, "--pause devname autoneg foo" },
82 	{ 1, "-A devname autoneg" },
83 	{ 0, "--pause devname rx off" },
84 	{ 0, "-A devname tx on rx on autoneg off" },
85 	{ 1, "--pause devname foo on" },
86 	{ 1, "-A" },
87 	{ 0, "-c devname" },
88 	{ 0, "--show-coalesce devname" },
89 	{ 0, "-C devname adaptive-rx on adaptive-tx off rx-usecs 1 rx-frames 2 rx-usecs-irq 3 rx-frames-irq 4 tx-usecs 5 tx-frames 6 tx-usecs-irq 7 tx-frames-irq 8 stats-block-usecs 9 pkt-rate-low 10" },
90 	{ 0, "--coalesce devname rx-usecs-low 11 rx-frames-low 12 tx-usecs-low 13 tx-frames-low 14 pkt-rate-high 15 rx-usecs-high 16 rx-frames-high 17 tx-usecs-high 18 tx-frames-high 19 sample-interval 20" },
91 	{ 1, "-C devname adaptive-rx foo" },
92 	{ 1, "--coalesce devname adaptive-rx" },
93 	{ 1, "-C devname foo on" },
94 	{ 1, "-C" },
95 	{ 0, "-g devname" },
96 	{ 0, "--show-ring devname" },
97 	{ 1, "-g" },
98 	{ 0, "-G devname rx 1 rx-mini 2 rx-jumbo 3 tx 4" },
99 	{ 0, "--set-ring devname rx 1 rx-mini 2 rx-jumbo 3 tx 4" },
100 	{ 1, "-G devname rx foo" },
101 	{ 1, "--set-ring devname rx" },
102 	{ 1, "-G devname foo 1" },
103 	{ 1, "-G" },
104 	{ 1, "-k" },
105 	{ 1, "-K" },
106 	{ 0, "-i devname" },
107 	{ 0, "--driver devname" },
108 	{ 1, "-i" },
109 	{ 0, "-d devname" },
110 	{ 0, "--register-dump devname raw on file foo" },
111 	{ 1, "-d devname raw foo" },
112 	{ 1, "--register-dump devname file" },
113 	{ 1, "-d devname foo" },
114 	{ 1, "-d" },
115 	{ 0, "-e devname" },
116 	{ 0, "--eeprom-dump devname raw on offset 1 length 2" },
117 	{ 1, "-e devname raw foo" },
118 	{ 1, "--eeprom-dump devname offset foo" },
119 	{ 1, "-e devname length" },
120 	{ 1, "--eeprom-dump devname foo" },
121 	{ 1, "-e" },
122 	{ 0, "-E devname" },
123 	{ 0, "--change-eeprom devname magic 0x87654321 offset 0 value 1" },
124 	{ 0, "-E devname magic 0x87654321 offset 0 length 2" },
125 	{ 1, "-E" },
126 	{ 0, "-r devname" },
127 	{ 0, "--negotiate devname" },
128 	{ 1, "-r" },
129 	{ 0, "-p devname" },
130 	{ 0, "--identify devname 1" },
131 	{ 1, "-p devname 1 foo" },
132 	{ 1, "--identify devname foo" },
133 	{ 1, "-p" },
134 	/* Argument parsing for -t is specialised */
135 	{ 0, "-t devname" },
136 	{ 0, "--test devname online" },
137 	{ 1, "-t devname foo" },
138 	{ 1, "--test devname online foo" },
139 	{ 0, "-S devname" },
140 	{ 0, "--statistics devname" },
141 	{ 1, "-S" },
142 	/* Argument parsing for -n/-u is specialised */
143 	{ 0, "-n devname rx-flow-hash tcp4" },
144 	{ 0, "-u devname rx-flow-hash sctp4" },
145 	{ 0, "--show-nfc devname rx-flow-hash udp6" },
146 	{ 0, "--show-ntuple devname rx-flow-hash esp6" },
147 	{ 1, "-n devname rx-flow-hash foo" },
148 	{ 1, "-u devname rx-flow-hash foo" },
149 	{ 1, "--show-nfc devname rx-flow-hash" },
150 	{ 1, "--show-ntuple devname rx-flow-hash" },
151 	{ 1, "-n" },
152 	/* Argument parsing for -f is specialised */
153 	{ 1, "-f devname" },
154 	{ 0, "--flash devname filename" },
155 	{ 0, "-f devname filename 1" },
156 	{ 1, "-f devname filename 1 foo" },
157 	{ 1, "-f" },
158 	/* Argument parsing for -N/-U is specialised */
159 	{ 0, "-N devname rx-flow-hash tcp4 mvtsdfn" },
160 	{ 0, "--config-ntuple devname rx-flow-hash tcp4 r" },
161 	{ 1, "-U devname rx-flow-hash tcp4" },
162 	{ 1, "--config-nfc devname rx-flow-hash foo" },
163 	{ 1, "-N devname rx-flow-hash" },
164 	{ 1, "--config-ntuple devname foo" },
165 	{ 0, "-U devname delete 1" },
166 	{ 1, "--config-nfc devname delete foo" },
167 	{ 1, "-N devname delete" },
168 	{ 0, "--config-ntuple devname flow-type ether src 01:23:45:67:89:ab m cd:ef:01:23:45:67 dst 89:ab:cd:ef:01:23 m 45:67:89:ab:cd:ef proto 0x0123 m 0x4567 vlan 0x89ab m 0xcdef action 0" },
169 	{ 0, "-U devname flow-type ether src 01:23:45:67:89:ab src-mask cd:ef:01:23:45:67 dst 89:ab:cd:ef:01:23 dst-mask 45:67:89:ab:cd:ef proto 0x0123 proto-mask 0x4567 vlan 0x89ab vlan-mask 0xcdef action 1" },
170 	{ 1, "--config-nfc devname flow-type ether src 01:23:45:67:89: action 3" },
171 	{ 1, "-N devname flow-type ether src 01:23:45:67:89 action 4" },
172 	{ 0, "--config-ntuple devname flow-type ip4 src-ip 0.123.45.67 m 89.0.123.45 dst-ip 67.89.0.123 m 45.67.89.0 tos 1 m 1 l4proto 0x23 m 0x45 l4data 0xfedcba98 m 76543210 vlan 0x89ab m 0xcdef action 6" },
173 	{ 0, "-U devname flow-type ip4 src-ip 0.123.45.67 src-ip-mask 89.0.123.45 dst-ip 67.89.0.123 dst-ip-mask 45.67.89.0 tos 1 tos-mask 1 l4proto 0x23 l4proto-mask 0x45 l4data 0xfedcba98 l4data-mask 76543210 vlan 0x89ab vlan-mask 0xcdef action 7" },
174 	{ 0, "--config-nfc devname flow-type tcp4 src-ip 0.123.45.67 m 89.0.123.45 dst-ip 67.89.0.123 m 45.67.89.0 tos 1 m 1 src-port 23456 m 7890 dst-port 12345 m 6789 vlan 0x89ab m 0xcdef action 8" },
175 	{ 0, "-N devname flow-type tcp4 src-ip 0.123.45.67 src-ip-mask 89.0.123.45 dst-ip 67.89.0.123 dst-ip-mask 45.67.89.0 tos 1 tos-mask 1 src-port 23456 src-port-mask 7890 dst-port 12345 dst-port-mask 6789 vlan 0x89ab vlan-mask 0xcdef action 9" },
176 	{ 0, "--config-ntuple devname flow-type ah4 src-ip 0.123.45.67 m 89.0.123.45 dst-ip 67.89.0.123 m 45.67.89.0 tos 1 m 1 spi 2 m 3 vlan 0x89ab m 0xcdef action 10" },
177 	{ 0, "-U devname flow-type ah4 src-ip 0.123.45.67 src-ip-mask 89.0.123.45 dst-ip 67.89.0.123 dst-ip-mask 45.67.89.0 tos 1 tos-mask 1 spi 2 spi-mask 3 vlan 0x89ab vlan-mask 0xcdef action 11" },
178 	{ 1, "--config-nfc devname flow-type tcp4 action foo" },
179 	{ 1, "-N devname flow-type foo" },
180 	{ 1, "--config-ntuple devname flow-type" },
181 	{ 1, "-U devname foo" },
182 	{ 1, "-N" },
183 	{ 1, "-U" },
184 	{ 0, "-T devname" },
185 	{ 0, "--show-time-stamping devname" },
186 	{ 1, "-T" },
187 	{ 0, "-x devname" },
188 	{ 0, "--show-rxfh-indir devname" },
189 	{ 0, "--show-rxfh devname" },
190 	{ 1, "-x" },
191 	/* Argument parsing for -X is specialised */
192 	{ 0, "-X devname equal 2" },
193 	{ 0, "--set-rxfh-indir devname equal 256" },
194 	{ 1, "-X devname equal 0" },
195 	{ 1, "--set-rxfh-indir devname equal foo" },
196 	{ 1, "-X devname equal" },
197 	{ 1, "-X devname start" },
198 	{ 1, "-X devname start 3" },
199 	{ 0, "-X devname start 4 equal 2" },
200 	{ 0, "--set-rxfh-indir devname weight 1 2 3 4" },
201 	{ 0, "--set-rxfh-indir devname start 4 weight 1 2 3 4" },
202 	{ 0, "--rxfh devname hkey 48:15:6e:bb:d8:bd:6f:b1:a4:c6:7a:c4:76:1c:29:98:da:e1:ae:6c:2e:12:2f:c0:b9:be:61:3d:00:54:35:9e:09:05:c7:d7:93:72:4a:ee" },
203 	{ 0, "-X devname hkey 48:15:6e:bb:d8:bd:6f:b1:a4:c6:7a:c4:76:1c:29:98:da:e1:ae:6c:2e:12:2f:c0:b9:be:61:3d:00:54:35:9e:09:05:c7:d7:93:72:4a:ee" },
204 #if 0
205 	/* XXX These won't fail as expected because we don't parse the
206 	 * hash key until after the first send_ioctl().  That needs to
207 	 * be changed before we enable them.
208 	 */
209 	{ 1, "--rxfh devname hkey foo" },
210 	{ 1, "-X devname hkey foo" },
211 #endif
212 	{ 0, "--rxfh devname hkey 48:15:6e:bb:d8:bd:6f:b1:a4:c6:7a:c4:76:1c:29:98:da:e1:ae:6c:2e:12:2f:c0:b9:be:61:3d:00:54:35:9e:09:05:c7:d7:93:72:4a:ee weight 1 2 3 4" },
213 	{ 0, "-X devname weight 1 2 3 4 hkey 48:15:6e:bb:d8:bd:6f:b1:a4:c6:7a:c4:76:1c:29:98:da:e1:ae:6c:2e:12:2f:c0:b9:be:61:3d:00:54:35:9e:09:05:c7:d7:93:72:4a:ee" },
214 	{ 0, "--rxfh devname hkey 48:15:6e:bb:d8:bd:6f:b1:a4:c6:7a:c4:76:1c:29:98:da:e1:ae:6c:2e:12:2f:c0:b9:be:61:3d:00:54:35:9e:09:05:c7:d7:93:72:4a:ee equal 2" },
215 	{ 0, "-X devname equal 2 hkey 48:15:6e:bb:d8:bd:6f:b1:a4:c6:7a:c4:76:1c:29:98:da:e1:ae:6c:2e:12:2f:c0:b9:be:61:3d:00:54:35:9e:09:05:c7:d7:93:72:4a:ee" },
216 	{ 1, "--rxfh devname weight 1 2 3 4 equal 8" },
217 	{ 1, "-X devname weight 1 2 3 4 equal 8" },
218 	{ 1, "-X devname foo" },
219 	{ 1, "-X" },
220 	{ 0, "-P devname" },
221 	{ 0, "--show-permaddr devname" },
222 	{ 1, "-P" },
223 	{ 0, "-w devname" },
224 	{ 0, "--get-dump devname data filename" },
225 	{ 0, "-w devname data filename" },
226 	{ 1, "--get-dump devname data" },
227 	{ 1, "-w devname foo" },
228 	{ 1, "-w" },
229 	{ 0, "-W devname 1" },
230 	{ 0, "--set-dump devname 2" },
231 	{ 1, "-W devname 1 foo" },
232 	{ 1, "-W devname foo" },
233 	{ 1, "-W" },
234 	{ 0, "-l devname" },
235 	{ 0, "--show-channels devname" },
236 	{ 1, "-l" },
237 	{ 0, "-L devname rx 1 tx 2 other 3 combined 4" },
238 	{ 0, "--set-channels devname rx 1 tx 2 other 3 combined 4" },
239 	{ 1, "-L devname rx foo" },
240 	{ 1, "--set-channels devname rx" },
241 	{ 0, "-L devname" },
242 	{ 1, "-L" },
243 	{ 0, "--show-priv-flags devname" },
244 	{ 1, "--show-priv-flags devname foo" },
245 	{ 1, "--show-priv-flags" },
246 	{ 1, "-m" },
247 	{ 0, "-m devname" },
248 	{ 1, "--dump-module-eeprom" },
249 	{ 0, "--dump-module-eeprom devname" },
250 	{ 1, "--module-info" },
251 	{ 0, "--module-info devname" },
252 	{ 0, "-m devname raw on" },
253 	{ 0, "-m devname raw off" },
254 	{ 0, "-m devname hex on" },
255 	{ 0, "-m devname hex off" },
256 	{ 1, "-m devname hex on raw on" },
257 	{ 0, "-m devname offset 4 length 6" },
258 	{ 1, "--show-eee" },
259 	{ 0, "--show-eee devname" },
260 	{ 1, "--show-eee devname foo" },
261 	{ 1, "--set-eee" },
262 	{ 1, "--set-eee devname" },
263 	{ 1, "--set-eee devname foo" },
264 	{ 0, "--set-eee devname eee on" },
265 	{ 0, "--set-eee devname eee off" },
266 	{ 1, "--set-eee devname eee foo" },
267 	{ 0, "--set-eee devname tx-lpi on" },
268 	{ 0, "--set-eee devname tx-lpi off" },
269 	{ 1, "--set-eee devname tx-lpi foo" },
270 	{ 0, "--set-eee devname tx-timer 42 advertise 0x4321" },
271 	{ 1, "--set-eee devname tx-timer foo" },
272 	{ 1, "--set-eee devname advertise foo" },
273 	{ 1, "--set-fec devname" },
274 	{ 0, "--set-fec devname encoding auto" },
275 	{ 0, "--set-fec devname encoding off" },
276 	{ 0, "--set-fec devname encoding baser rs" },
277 	{ 0, "--set-fec devname encoding auto auto" },
278 	{ 1, "--set-fec devname encoding foo" },
279 	{ 1, "--set-fec devname encoding auto foo" },
280 	{ 1, "--set-fec devname encoding none" },
281 	{ 1, "--set-fec devname auto" },
282 	/* can't test --set-priv-flags yet */
283 	{ 0, "-h" },
284 	{ 0, "--help" },
285 	{ 0, "--version" },
286 	{ 1, "--foo" },
287 	{ 1, "-foo" },
288 	{ 1, "-0" },
289 };
290 
send_ioctl(struct cmd_context * ctx,void * cmd)291 int send_ioctl(struct cmd_context *ctx, void *cmd)
292 {
293 	/* If we get this far then parsing succeeded */
294 	test_exit(0);
295 }
296 
main(void)297 int main(void)
298 {
299 	struct test_case *tc;
300 	int test_rc;
301 	int rc = 0;
302 
303 	for (tc = test_cases; tc < test_cases + ARRAY_SIZE(test_cases); tc++) {
304 		if (getenv("ETHTOOL_TEST_VERBOSE"))
305 			printf("I: Test command line: ethtool %s\n", tc->args);
306 		test_rc = test_cmdline(tc->args);
307 		if (test_rc != tc->rc) {
308 			fprintf(stderr, "E: ethtool %s returns %d\n",
309 				tc->args, test_rc);
310 			rc = 1;
311 		}
312 	}
313 
314 	return rc;
315 }
316