1From 3163c49f9f4ad473a00d8a345ee334a028376011 Mon Sep 17 00:00:00 2001 2From: Heiko Becker <heirecka@exherbo.org> 3Date: Fri, 23 Jul 2021 16:32:46 +0200 4Subject: [PATCH] meson: Make tests optional 5 6Now can be disabled with -DSKIP_TESTS=true. 7 8It allows to avoid meson error during build when ip isn't installed. 9 10Closes: #359 11 12Reviewed-by: Petr Vorel <petr.vorel@gmail.com> 13Signed-off-by: Heiko Becker <heirecka@exherbo.org> 14[ pvorel: Rename variable TEST => SKIP_TESTS, default false, adjust 15the description ] 16Signed-off-by: Petr Vorel <petr.vorel@gmail.com> 17 18[Retrieved from: 19https://github.com/iputils/iputils/commit/3163c49f9f4ad473a00d8a345ee334a028376011] 20Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> 21--- 22 meson_options.txt | 3 ++ 23 ping/meson.build | 84 ++----------------------------------------- 24 ping/test/meson.build | 81 +++++++++++++++++++++++++++++++++++++++++ 25 3 files changed, 86 insertions(+), 82 deletions(-) 26 create mode 100644 ping/test/meson.build 27 28diff --git a/meson_options.txt b/meson_options.txt 29index ac5f5d98..517667f4 100644 30--- a/meson_options.txt 31+++ b/meson_options.txt 32@@ -72,3 +72,6 @@ option('INSTALL_SYSTEMD_UNITS', type: 'boolean', value: false, 33 34 option('USE_GETTEXT', type: 'boolean', value: true, 35 description: 'Enable I18N') 36+ 37+option('SKIP_TESTS', type: 'boolean', value: false, 38+ description: 'Skip tests during build') 39diff --git a/ping/meson.build b/ping/meson.build 40index 1e678ec8..83ea353c 100644 41--- a/ping/meson.build 42+++ b/ping/meson.build 43@@ -27,86 +27,6 @@ if (setcap_ping) 44 ) 45 endif 46 47-##### TESTS ##### 48- 49-# TODO: ::1 generates DEPRECATION: ":" is not allowed in test name "ping -c1 ::1", it has been replaced with "_" 50- 51-# GitHub CI does not have working IPv6 52-# https://github.com/actions/virtual-environments/issues/668 53-ipv6_dst = [] 54-ipv6_switch = [] 55-r = run_command('ip', '-6', 'a') 56-if r.stdout().strip().contains('::1') 57- message('IPv6 enabled') 58- ipv6_dst = [ '::1' ] 59- ipv6_switch = [ '-6' ] 60-else 61- message('WARNING: IPv6 disabled') 62+if not get_option('SKIP_TESTS') 63+ subdir('test') 64 endif 65- 66-run_as_root = false 67-r = run_command('id', '-u') 68-if r.stdout().strip().to_int() == 0 69- message('running as root') 70- run_as_root = true 71-else 72- message('running as normal user') 73-endif 74- 75-foreach dst : [ 'localhost', '127.0.0.1' ] + ipv6_dst 76- foreach switch : [ '', '-4' ] + ipv6_switch 77- args = [ '-c1', dst ] 78- should_fail = false 79- 80- if switch != '' 81- args = [switch] + args 82- if (switch == '-4' and dst == '::1') or (switch == '-6' and dst == '127.0.0.1') 83- should_fail = true 84- endif 85- endif 86- 87- name = 'ping ' + ' '.join(args) 88- test(name, ping, args : args, should_fail : should_fail) 89- endforeach 90-endforeach 91- 92-ping_tests_opt = [ 93- [ '-c1' ], 94- [ '-c5', '-i0.1' ], 95- [ '-c1', '-I', 'lo' ], 96- [ '-c1', '-w1' ], 97- [ '-c1', '-W1' ], 98- [ '-c1', '-W1.1' ], 99-] 100-foreach dst : [ '127.0.0.1' ] + ipv6_dst 101- foreach args : ping_tests_opt 102- args += [ dst ] 103- name = 'ping ' + ' '.join(args) 104- test(name, ping, args : args) 105- endforeach 106-endforeach 107- 108-ping_tests_opt_fail = [ 109- [ '-c1.1' ], 110- [ '-I', 'nonexisting' ], 111- [ '-w0.1' ], 112- [ '-w0,1' ], 113-] 114-foreach dst : [ '127.0.0.1' ] + ipv6_dst 115- foreach args : ping_tests_opt_fail 116- args += [ dst ] 117- name = 'ping ' + ' '.join(args) 118- test(name, ping, args : args, should_fail : true) 119- endforeach 120-endforeach 121- 122-ping_tests_user_fail = [ 123- [ '-c1', '-i0.001' ], # -c1 required to quit ping when running as root 124-] 125-foreach dst : [ '127.0.0.1' ] + ipv6_dst 126- foreach args : ping_tests_user_fail 127- args += [ dst ] 128- name = 'ping ' + ' '.join(args) 129- test(name, ping, args : args, should_fail : not run_as_root) 130- endforeach 131-endforeach 132diff --git a/ping/test/meson.build b/ping/test/meson.build 133new file mode 100644 134index 00000000..43aed758 135--- /dev/null 136+++ b/ping/test/meson.build 137@@ -0,0 +1,81 @@ 138+# TODO: ::1 generates DEPRECATION: ":" is not allowed in test name "ping -c1 ::1", it has been replaced with "_" 139+ 140+# GitHub CI does not have working IPv6 141+# https://github.com/actions/virtual-environments/issues/668 142+ipv6_dst = [] 143+ipv6_switch = [] 144+r = run_command('ip', '-6', 'a') 145+if r.stdout().strip().contains('::1') 146+ message('IPv6 enabled') 147+ ipv6_dst = [ '::1' ] 148+ ipv6_switch = [ '-6' ] 149+else 150+ message('WARNING: IPv6 disabled') 151+endif 152+ 153+run_as_root = false 154+r = run_command('id', '-u') 155+if r.stdout().strip().to_int() == 0 156+ message('running as root') 157+ run_as_root = true 158+else 159+ message('running as normal user') 160+endif 161+ 162+foreach dst : [ 'localhost', '127.0.0.1' ] + ipv6_dst 163+ foreach switch : [ '', '-4' ] + ipv6_switch 164+ args = [ '-c1', dst ] 165+ should_fail = false 166+ 167+ if switch != '' 168+ args = [switch] + args 169+ if (switch == '-4' and dst == '::1') or (switch == '-6' and dst == '127.0.0.1') 170+ should_fail = true 171+ endif 172+ endif 173+ 174+ name = 'ping ' + ' '.join(args) 175+ test(name, ping, args : args, should_fail : should_fail) 176+ endforeach 177+endforeach 178+ 179+ping_tests_opt = [ 180+ [ '-c1' ], 181+ [ '-c5', '-i0.1' ], 182+ [ '-c1', '-I', 'lo' ], 183+ [ '-c1', '-w1' ], 184+ [ '-c1', '-W1' ], 185+ [ '-c1', '-W1.1' ], 186+] 187+foreach dst : [ '127.0.0.1' ] + ipv6_dst 188+ foreach args : ping_tests_opt 189+ args += [ dst ] 190+ name = 'ping ' + ' '.join(args) 191+ test(name, ping, args : args) 192+ endforeach 193+endforeach 194+ 195+ping_tests_opt_fail = [ 196+ [ '-c1.1' ], 197+ [ '-I', 'nonexisting' ], 198+ [ '-w0.1' ], 199+ [ '-w0,1' ], 200+] 201+foreach dst : [ '127.0.0.1' ] + ipv6_dst 202+ foreach args : ping_tests_opt_fail 203+ args += [ dst ] 204+ name = 'ping ' + ' '.join(args) 205+ test(name, ping, args : args, should_fail : true) 206+ endforeach 207+endforeach 208+ 209+ping_tests_user_fail = [ 210+ [ '-c1', '-i0.001' ], # -c1 required to quit ping when running as root 211+] 212+foreach dst : [ '127.0.0.1' ] + ipv6_dst 213+ foreach args : ping_tests_user_fail 214+ args += [ dst ] 215+ name = 'ping ' + ' '.join(args) 216+ test(name, ping, args : args, should_fail : not run_as_root) 217+ endforeach 218+endforeach 219