Debian Codegraph @

test/ping/meson.build

raw
1 # SPDX-License-Identifier: GPL-2.0-or-later
2 # Copyright (c) 2021 Petr Vorel <[email protected]>
3
4 # GitHub CI does not have working IPv6
5 # https://github.com/actions/virtual-environments/issues/668
6 ipv6_dst = []
7 ipv6_switch = []
8 ip = find_program('ip', required: false)
9 if ip.found() and run_command(ip, '-6', 'a').stdout().contains('::1')
10 message('IPv6 enabled')
11 ipv6_dst = [ '::1' ]
12 ipv6_switch = [ '-6' ]
13 elif not ip.found()
14 message('WARNING: ip binary not found => disable IPv6 tests')
15 else
16 message('WARNING: IPv6 disabled')
17 endif
18
19 run_as_root = false
20 r = run_command('id', '-u')
21 if r.stdout().strip().to_int() == 0
22 message('running as root')
23 run_as_root = true
24 else
25 message('running as normal user')
26 endif
27
28 cmd = ping
29 cmd_name = 'ping '
30 args = ['-V']
31
32 name = 'ping ' + ' '.join(args)
33 test(name, ping, args : args)
34
35 foreach dst : [ 'localhost', '127.0.0.1' ] + ipv6_dst
36 foreach switch : [ '', '-4' ] + ipv6_switch
37 args = [ '-c1', dst ]
38 should_fail = false
39
40 if switch != ''
41 args = [switch] + args
42 if (switch == '-4' and dst == '::1') or (switch == '-6' and dst == '127.0.0.1')
43 should_fail = true
44 endif
45 endif
46
47 name = cmd_name + ' '.join(args)
48 name = '_'.join(name.split(':'))
49 test(name, cmd, args : args, should_fail : should_fail)
50 endforeach
51 endforeach
52
53 ping_tests_opt = [
54 [ '-c1' ],
55 [ '-c5', '-i0.1' ],
56 [ '-c1', '-I', 'lo' ],
57 [ '-c1', '-w1' ],
58 [ '-c1', '-W1' ],
59 [ '-c1', '-W1.1' ],
60 ]
61 foreach dst : [ '127.0.0.1' ] + ipv6_dst
62 foreach args : ping_tests_opt
63 args += [ dst ]
64 name = cmd_name + ' '.join(args)
65 name = '_'.join(name.split(':'))
66 test(name, cmd, args : args)
67 endforeach
68 endforeach
69
70 ping_tests_opt_fail = [
71 [ '-c1.1' ],
72 [ '-I', 'nonexisting' ],
73 [ '-w0.1' ],
74 [ '-w0,1' ],
75 ]
76 foreach dst : [ '127.0.0.1' ] + ipv6_dst
77 foreach args : ping_tests_opt_fail
78 args += [ dst ]
79 name = cmd_name + ' '.join(args)
80 name = '_'.join(name.split(':'))
81 test(name, cmd, args : args, should_fail : true)
82 endforeach
83 endforeach
84
85 ping_tests_user_fail = [
86 [ '-c1', '-i0.001' ], # -c1 required to quit ping when running as root
87 ]
88 foreach dst : [ '127.0.0.1' ] + ipv6_dst
89 foreach args : ping_tests_user_fail
90 args += [ dst ]
91 name = cmd_name + ' '.join(args)
92 name = '_'.join(name.split(':'))
93 test(name, cmd, args : args, should_fail : not run_as_root)
94 endforeach
95 endforeach