runtests: add an IPv6 command line flag
authorJun Wu <quark@fb.com>
Fri, 17 Feb 2017 01:21:15 -0800
changeset 31011 01eebb65a61d
parent 31010 09ec648cd2a9
child 31012 88358446da16
runtests: add an IPv6 command line flag Now we have all IPv6 related issues fixed, add a command line flag so people could actually run tests with IPv6.
tests/run-tests.py
--- a/tests/run-tests.py	Thu Feb 16 08:43:59 2017 -0800
+++ b/tests/run-tests.py	Fri Feb 17 01:21:15 2017 -0800
@@ -137,8 +137,8 @@
     else:
         return False
 
-# IPv6 is used if IPv4 is not available and IPv6 is available.
-useipv6 = (not checksocketfamily('AF_INET')) and checksocketfamily('AF_INET6')
+# useipv6 will be set by parseargs
+useipv6 = None
 
 def checkportisavailable(port):
     """return true if a port seems free to bind on localhost"""
@@ -302,6 +302,8 @@
                       help="install and use chg wrapper in place of hg")
     parser.add_option("--with-chg", metavar="CHG",
                       help="use specified chg wrapper in place of hg")
+    parser.add_option("--ipv6", action="store_true",
+                      help="prefer IPv6 to IPv4 for network related tests")
     parser.add_option("-3", "--py3k-warnings", action="store_true",
         help="enable Py3k warnings on Python 2.6+")
     # This option should be deleted once test-check-py3-compat.t and other
@@ -371,6 +373,14 @@
         parser.error('--chg does not work when --with-hg is specified '
                      '(use --with-chg instead)')
 
+    global useipv6
+    if options.ipv6:
+        useipv6 = checksocketfamily('AF_INET6')
+    else:
+        # only use IPv6 if IPv4 is unavailable and IPv6 is available
+        useipv6 = ((not checksocketfamily('AF_INET'))
+                   and checksocketfamily('AF_INET6'))
+
     options.anycoverage = options.cover or options.annotate or options.htmlcov
     if options.anycoverage:
         try: