annotate tests/run-tests.py @ 1106:cca56bbea143

tests: copy hg test infra from hg repo @5cfdf6137af8
author Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
date Tue, 06 Feb 2018 16:34:28 -0800
parents e085b381e8e2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2 #
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 # run-tests.py - Run a set of tests on Mercurial
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4 #
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 # Copyright 2006 Matt Mackall <mpm@selenic.com>
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6 #
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 # This software may be used and distributed according to the terms of the
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
8 # GNU General Public License version 2 or any later version.
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
10 # Modifying this script is tricky because it has many modes:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
11 # - serial (default) vs parallel (-jN, N > 1)
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
12 # - no coverage (default) vs coverage (-c, -C, -s)
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
13 # - temp install (default) vs specific hg script (--with-hg, --local)
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
14 # - tests are a mix of shell scripts and Python scripts
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
15 #
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
16 # If you change this script, it is recommended that you ensure you
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
17 # haven't broken it by running it in various modes with a representative
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
18 # sample of test scripts. For example:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
19 #
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
20 # 1) serial, no coverage, temp install:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
21 # ./run-tests.py test-s*
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
22 # 2) serial, no coverage, local hg:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
23 # ./run-tests.py --local test-s*
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
24 # 3) serial, coverage, temp install:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
25 # ./run-tests.py -c test-s*
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
26 # 4) serial, coverage, local hg:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
27 # ./run-tests.py -c --local test-s* # unsupported
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
28 # 5) parallel, no coverage, temp install:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
29 # ./run-tests.py -j2 test-s*
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
30 # 6) parallel, no coverage, local hg:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
31 # ./run-tests.py -j2 --local test-s*
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
32 # 7) parallel, coverage, temp install:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
33 # ./run-tests.py -j2 -c test-s* # currently broken
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
34 # 8) parallel, coverage, local install:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
35 # ./run-tests.py -j2 -c --local test-s* # unsupported (and broken)
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
36 # 9) parallel, custom tmp dir:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
37 # ./run-tests.py -j2 --tmpdir /tmp/myhgtests
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
38 # 10) parallel, pure, tests that call run-tests:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
39 # ./run-tests.py --pure `grep -l run-tests.py *.t`
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
40 #
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
41 # (You could use any subset of the tests: test-s* happens to match
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
42 # enough that it's worth doing parallel runs, few enough that it
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
43 # completes fairly quickly, includes both shell and Python scripts, and
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
44 # includes some scripts that run daemon processes.)
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
45
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
46 from __future__ import absolute_import, print_function
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
47
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
48 import argparse
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
49 import collections
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 import difflib
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
51 import distutils.version as version
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
52 import errno
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
53 import json
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
54 import os
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
55 import random
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
56 import re
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
57 import shutil
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
58 import signal
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
59 import socket
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
60 import subprocess
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
61 import sys
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
62 import sysconfig
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
63 import tempfile
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
64 import threading
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
65 import time
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
66 import unittest
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
67 import xml.dom.minidom as minidom
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
68
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
69 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
70 import Queue as queue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
71 except ImportError:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
72 import queue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
73
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
74 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
75 import shlex
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
76 shellquote = shlex.quote
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
77 except (ImportError, AttributeError):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
78 import pipes
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
79 shellquote = pipes.quote
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
80
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
81 if os.environ.get('RTUNICODEPEDANTRY', False):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
82 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
83 reload(sys)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
84 sys.setdefaultencoding("undefined")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
85 except NameError:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
86 pass
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
87
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
88 origenviron = os.environ.copy()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
89 osenvironb = getattr(os, 'environb', os.environ)
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
90 processlock = threading.Lock()
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
91
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
92 pygmentspresent = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
93 # ANSI color is unsupported prior to Windows 10
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
94 if os.name != 'nt':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
95 try: # is pygments installed
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
96 import pygments
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
97 import pygments.lexers as lexers
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
98 import pygments.lexer as lexer
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
99 import pygments.formatters as formatters
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
100 import pygments.token as token
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
101 import pygments.style as style
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
102 pygmentspresent = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
103 difflexer = lexers.DiffLexer()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
104 terminal256formatter = formatters.Terminal256Formatter()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
105 except ImportError:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
106 pass
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
107
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
108 if pygmentspresent:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
109 class TestRunnerStyle(style.Style):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
110 default_style = ""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
111 skipped = token.string_to_tokentype("Token.Generic.Skipped")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
112 failed = token.string_to_tokentype("Token.Generic.Failed")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
113 skippedname = token.string_to_tokentype("Token.Generic.SName")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
114 failedname = token.string_to_tokentype("Token.Generic.FName")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
115 styles = {
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
116 skipped: '#e5e5e5',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
117 skippedname: '#00ffff',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
118 failed: '#7f0000',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
119 failedname: '#ff0000',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
120 }
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
121
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
122 class TestRunnerLexer(lexer.RegexLexer):
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
123 testpattern = r'[\w-]+\.(t|py)( \(case [\w-]+\))?'
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
124 tokens = {
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
125 'root': [
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
126 (r'^Skipped', token.Generic.Skipped, 'skipped'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
127 (r'^Failed ', token.Generic.Failed, 'failed'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
128 (r'^ERROR: ', token.Generic.Failed, 'failed'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
129 ],
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
130 'skipped': [
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
131 (testpattern, token.Generic.SName),
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
132 (r':.*', token.Generic.Skipped),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
133 ],
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
134 'failed': [
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
135 (testpattern, token.Generic.FName),
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
136 (r'(:| ).*', token.Generic.Failed),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
137 ]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
138 }
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
139
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
140 runnerformatter = formatters.Terminal256Formatter(style=TestRunnerStyle)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
141 runnerlexer = TestRunnerLexer()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
142
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
143 if sys.version_info > (3, 5, 0):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
144 PYTHON3 = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
145 xrange = range # we use xrange in one place, and we'd rather not use range
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
146 def _bytespath(p):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
147 if p is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
148 return p
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
149 return p.encode('utf-8')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
150
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
151 def _strpath(p):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
152 if p is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
153 return p
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
154 return p.decode('utf-8')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
155
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
156 elif sys.version_info >= (3, 0, 0):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
157 print('%s is only supported on Python 3.5+ and 2.7, not %s' %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
158 (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3])))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
159 sys.exit(70) # EX_SOFTWARE from `man 3 sysexit`
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
160 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
161 PYTHON3 = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
162
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
163 # In python 2.x, path operations are generally done using
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
164 # bytestrings by default, so we don't have to do any extra
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
165 # fiddling there. We define the wrapper functions anyway just to
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
166 # help keep code consistent between platforms.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
167 def _bytespath(p):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
168 return p
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
169
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
170 _strpath = _bytespath
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
171
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
172 # For Windows support
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
173 wifexited = getattr(os, "WIFEXITED", lambda x: False)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
174
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
175 # Whether to use IPv6
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
176 def checksocketfamily(name, port=20058):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
177 """return true if we can listen on localhost using family=name
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
178
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
179 name should be either 'AF_INET', or 'AF_INET6'.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
180 port being used is okay - EADDRINUSE is considered as successful.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
181 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
182 family = getattr(socket, name, None)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
183 if family is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
184 return False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
185 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
186 s = socket.socket(family, socket.SOCK_STREAM)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
187 s.bind(('localhost', port))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
188 s.close()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
189 return True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
190 except socket.error as exc:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
191 if exc.errno == errno.EADDRINUSE:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
192 return True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
193 elif exc.errno in (errno.EADDRNOTAVAIL, errno.EPROTONOSUPPORT):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
194 return False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
195 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
196 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
197 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
198 return False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
199
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
200 # useipv6 will be set by parseargs
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
201 useipv6 = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
202
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
203 def checkportisavailable(port):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
204 """return true if a port seems free to bind on localhost"""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
205 if useipv6:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
206 family = socket.AF_INET6
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
207 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
208 family = socket.AF_INET
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
209 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
210 s = socket.socket(family, socket.SOCK_STREAM)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
211 s.bind(('localhost', port))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
212 s.close()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
213 return True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
214 except socket.error as exc:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
215 if exc.errno not in (errno.EADDRINUSE, errno.EADDRNOTAVAIL,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
216 errno.EPROTONOSUPPORT):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
217 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
218 return False
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
219
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
220 closefds = os.name == 'posix'
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
221 def Popen4(cmd, wd, timeout, env=None):
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
222 processlock.acquire()
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
223 p = subprocess.Popen(cmd, shell=True, bufsize=-1, cwd=wd, env=env,
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
224 close_fds=closefds,
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
225 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
226 stderr=subprocess.STDOUT)
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
227 processlock.release()
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
228
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
229 p.fromchild = p.stdout
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
230 p.tochild = p.stdin
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
231 p.childerr = p.stderr
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
232
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
233 p.timeout = False
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
234 if timeout:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
235 def t():
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
236 start = time.time()
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
237 while time.time() - start < timeout and p.returncode is None:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
238 time.sleep(.1)
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
239 p.timeout = True
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
240 if p.returncode is None:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
241 terminate(p)
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
242 threading.Thread(target=t).start()
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
243
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
244 return p
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
245
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
246 PYTHON = _bytespath(sys.executable.replace('\\', '/'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
247 IMPL_PATH = b'PYTHONPATH'
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
248 if 'java' in sys.platform:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
249 IMPL_PATH = b'JYTHONPATH'
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
250
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
251 defaults = {
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
252 'jobs': ('HGTEST_JOBS', 1),
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
253 'timeout': ('HGTEST_TIMEOUT', 180),
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
254 'slowtimeout': ('HGTEST_SLOWTIMEOUT', 500),
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
255 'port': ('HGTEST_PORT', 20059),
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
256 'shell': ('HGTEST_SHELL', 'sh'),
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
257 }
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
258
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
259 def canonpath(path):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
260 return os.path.realpath(os.path.expanduser(path))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
261
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
262 def parselistfiles(files, listtype, warn=True):
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
263 entries = dict()
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
264 for filename in files:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
265 try:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
266 path = os.path.expanduser(os.path.expandvars(filename))
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
267 f = open(path, "rb")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
268 except IOError as err:
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
269 if err.errno != errno.ENOENT:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
270 raise
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
271 if warn:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
272 print("warning: no such %s file: %s" % (listtype, filename))
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
273 continue
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
274
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
275 for line in f.readlines():
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
276 line = line.split(b'#', 1)[0].strip()
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
277 if line:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
278 entries[line] = filename
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
279
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
280 f.close()
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
281 return entries
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
282
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
283 def parsettestcases(path):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
284 """read a .t test file, return a set of test case names
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
285
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
286 If path does not exist, return an empty set.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
287 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
288 cases = set()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
289 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
290 with open(path, 'rb') as f:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
291 for l in f:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
292 if l.startswith(b'#testcases '):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
293 cases.update(l[11:].split())
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
294 except IOError as ex:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
295 if ex.errno != errno.ENOENT:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
296 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
297 return cases
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
298
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
299 def getparser():
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
300 """Obtain the OptionParser used by the CLI."""
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
301 parser = argparse.ArgumentParser(usage='%(prog)s [options] [tests]')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
302
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
303 selection = parser.add_argument_group('Test Selection')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
304 selection.add_argument('--allow-slow-tests', action='store_true',
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
305 help='allow extremely slow tests')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
306 selection.add_argument("--blacklist", action="append",
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
307 help="skip tests listed in the specified blacklist file")
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
308 selection.add_argument("--changed",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
309 help="run tests that are changed in parent rev or working directory")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
310 selection.add_argument("-k", "--keywords",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
311 help="run tests matching keywords")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
312 selection.add_argument("-r", "--retest", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
313 help = "retest failed tests")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
314 selection.add_argument("--test-list", action="append",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
315 help="read tests to run from the specified file")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
316 selection.add_argument("--whitelist", action="append",
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
317 help="always run tests listed in the specified whitelist file")
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
318 selection.add_argument('tests', metavar='TESTS', nargs='*',
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
319 help='Tests to run')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
320
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
321 harness = parser.add_argument_group('Test Harness Behavior')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
322 harness.add_argument('--bisect-repo',
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
323 metavar='bisect_repo',
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
324 help=("Path of a repo to bisect. Use together with "
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
325 "--known-good-rev"))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
326 harness.add_argument("-d", "--debug", action="store_true",
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
327 help="debug mode: write output of test scripts to console"
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
328 " rather than capturing and diffing it (disables timeout)")
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
329 harness.add_argument("-f", "--first", action="store_true",
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
330 help="exit on the first test failure")
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
331 harness.add_argument("-i", "--interactive", action="store_true",
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
332 help="prompt to accept changed output")
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
333 harness.add_argument("-j", "--jobs", type=int,
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
334 help="number of jobs to run in parallel"
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
335 " (default: $%s or %d)" % defaults['jobs'])
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
336 harness.add_argument("--keep-tmpdir", action="store_true",
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
337 help="keep temporary directory after running tests")
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
338 harness.add_argument('--known-good-rev',
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
339 metavar="known_good_rev",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
340 help=("Automatically bisect any failures using this "
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
341 "revision as a known-good revision."))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
342 harness.add_argument("--list-tests", action="store_true",
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
343 help="list tests instead of running them")
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
344 harness.add_argument("--loop", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
345 help="loop tests repeatedly")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
346 harness.add_argument('--random', action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
347 help='run tests in random order')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
348 harness.add_argument("-p", "--port", type=int,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
349 help="port on which servers should listen"
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
350 " (default: $%s or %d)" % defaults['port'])
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
351 harness.add_argument('--profile-runner', action='store_true',
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
352 help='run statprof on run-tests')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
353 harness.add_argument("-R", "--restart", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
354 help="restart at last error")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
355 harness.add_argument("--runs-per-test", type=int, dest="runs_per_test",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
356 help="run each test N times (default=1)", default=1)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
357 harness.add_argument("--shell",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
358 help="shell to use (default: $%s or %s)" % defaults['shell'])
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
359 harness.add_argument('--showchannels', action='store_true',
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
360 help='show scheduling channels')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
361 harness.add_argument("--slowtimeout", type=int,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
362 help="kill errant slow tests after SLOWTIMEOUT seconds"
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
363 " (default: $%s or %d)" % defaults['slowtimeout'])
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
364 harness.add_argument("-t", "--timeout", type=int,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
365 help="kill errant tests after TIMEOUT seconds"
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
366 " (default: $%s or %d)" % defaults['timeout'])
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
367 harness.add_argument("--tmpdir",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
368 help="run tests in the given temporary directory"
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
369 " (implies --keep-tmpdir)")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
370 harness.add_argument("-v", "--verbose", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
371 help="output verbose messages")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
372
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
373 hgconf = parser.add_argument_group('Mercurial Configuration')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
374 hgconf.add_argument("--chg", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
375 help="install and use chg wrapper in place of hg")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
376 hgconf.add_argument("--compiler",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
377 help="compiler to build with")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
378 hgconf.add_argument('--extra-config-opt', action="append", default=[],
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
379 help='set the given config opt in the test hgrc')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
380 hgconf.add_argument("-l", "--local", action="store_true",
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
381 help="shortcut for --with-hg=<testdir>/../hg, "
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
382 "and --with-chg=<testdir>/../contrib/chg/chg if --chg is set")
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
383 hgconf.add_argument("--ipv6", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
384 help="prefer IPv6 to IPv4 for network related tests")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
385 hgconf.add_argument("--pure", action="store_true",
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
386 help="use pure Python code instead of C extensions")
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
387 hgconf.add_argument("-3", "--py3k-warnings", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
388 help="enable Py3k warnings on Python 2.7+")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
389 hgconf.add_argument("--with-chg", metavar="CHG",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
390 help="use specified chg wrapper in place of hg")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
391 hgconf.add_argument("--with-hg",
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
392 metavar="HG",
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
393 help="test using specified hg script rather than a "
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
394 "temporary installation")
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
395 # This option should be deleted once test-check-py3-compat.t and other
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
396 # Python 3 tests run with Python 3.
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
397 hgconf.add_argument("--with-python3", metavar="PYTHON3",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
398 help="Python 3 interpreter (if running under Python 2)"
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
399 " (TEMPORARY)")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
400
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
401 reporting = parser.add_argument_group('Results Reporting')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
402 reporting.add_argument("-C", "--annotate", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
403 help="output files annotated with coverage")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
404 reporting.add_argument("--color", choices=["always", "auto", "never"],
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
405 default=os.environ.get('HGRUNTESTSCOLOR', 'auto'),
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
406 help="colorisation: always|auto|never (default: auto)")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
407 reporting.add_argument("-c", "--cover", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
408 help="print a test coverage report")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
409 reporting.add_argument('--exceptions', action='store_true',
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
410 help='log all exceptions and generate an exception report')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
411 reporting.add_argument("-H", "--htmlcov", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
412 help="create an HTML report of the coverage of the files")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
413 reporting.add_argument("--json", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
414 help="store test result data in 'report.json' file")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
415 reporting.add_argument("--outputdir",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
416 help="directory to write error logs to (default=test directory)")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
417 reporting.add_argument("-n", "--nodiff", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
418 help="skip showing test changes")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
419 reporting.add_argument("-S", "--noskips", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
420 help="don't report skip tests verbosely")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
421 reporting.add_argument("--time", action="store_true",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
422 help="time how long each test takes")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
423 reporting.add_argument("--view",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
424 help="external diff viewer")
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
425 reporting.add_argument("--xunit",
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
426 help="record xunit results at specified path")
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
427
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
428 for option, (envvar, default) in defaults.items():
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
429 defaults[option] = type(default)(os.environ.get(envvar, default))
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
430 parser.set_defaults(**defaults)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
431
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
432 return parser
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
433
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
434 def parseargs(args, parser):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
435 """Parse arguments with our OptionParser and validate results."""
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
436 options = parser.parse_args(args)
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
437
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
438 # jython is always pure
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
439 if 'java' in sys.platform or '__pypy__' in sys.modules:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
440 options.pure = True
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
441
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
442 if options.with_hg:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
443 options.with_hg = canonpath(_bytespath(options.with_hg))
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
444 if not (os.path.isfile(options.with_hg) and
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
445 os.access(options.with_hg, os.X_OK)):
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
446 parser.error('--with-hg must specify an executable hg script')
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
447 if os.path.basename(options.with_hg) not in [b'hg', b'hg.exe']:
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
448 sys.stderr.write('warning: --with-hg should specify an hg script\n')
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
449 if options.local:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
450 testdir = os.path.dirname(_bytespath(canonpath(sys.argv[0])))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
451 reporootdir = os.path.dirname(testdir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
452 pathandattrs = [(b'hg', 'with_hg')]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
453 if options.chg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
454 pathandattrs.append((b'contrib/chg/chg', 'with_chg'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
455 for relpath, attr in pathandattrs:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
456 binpath = os.path.join(reporootdir, relpath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
457 if os.name != 'nt' and not os.access(binpath, os.X_OK):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
458 parser.error('--local specified, but %r not found or '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
459 'not executable' % binpath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
460 setattr(options, attr, binpath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
461
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
462 if (options.chg or options.with_chg) and os.name == 'nt':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
463 parser.error('chg does not work on %s' % os.name)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
464 if options.with_chg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
465 options.chg = False # no installation to temporary location
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
466 options.with_chg = canonpath(_bytespath(options.with_chg))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
467 if not (os.path.isfile(options.with_chg) and
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
468 os.access(options.with_chg, os.X_OK)):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
469 parser.error('--with-chg must specify a chg executable')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
470 if options.chg and options.with_hg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
471 # chg shares installation location with hg
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
472 parser.error('--chg does not work when --with-hg is specified '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
473 '(use --with-chg instead)')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
474
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
475 if options.color == 'always' and not pygmentspresent:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
476 sys.stderr.write('warning: --color=always ignored because '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
477 'pygments is not installed\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
478
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
479 if options.bisect_repo and not options.known_good_rev:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
480 parser.error("--bisect-repo cannot be used without --known-good-rev")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
481
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
482 global useipv6
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
483 if options.ipv6:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
484 useipv6 = checksocketfamily('AF_INET6')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
485 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
486 # only use IPv6 if IPv4 is unavailable and IPv6 is available
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
487 useipv6 = ((not checksocketfamily('AF_INET'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
488 and checksocketfamily('AF_INET6'))
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
489
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
490 options.anycoverage = options.cover or options.annotate or options.htmlcov
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
491 if options.anycoverage:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
492 try:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
493 import coverage
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
494 covver = version.StrictVersion(coverage.__version__).version
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
495 if covver < (3, 3):
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
496 parser.error('coverage options require coverage 3.3 or later')
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
497 except ImportError:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
498 parser.error('coverage options now require the coverage package')
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
499
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
500 if options.anycoverage and options.local:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
501 # this needs some path mangling somewhere, I guess
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
502 parser.error("sorry, coverage options do not work when --local "
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
503 "is specified")
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
504
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
505 if options.anycoverage and options.with_hg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
506 parser.error("sorry, coverage options do not work when --with-hg "
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
507 "is specified")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
508
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
509 global verbose
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
510 if options.verbose:
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
511 verbose = ''
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
512
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
513 if options.tmpdir:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
514 options.tmpdir = canonpath(options.tmpdir)
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
515
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
516 if options.jobs < 1:
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
517 parser.error('--jobs must be positive')
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
518 if options.interactive and options.debug:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
519 parser.error("-i/--interactive and -d/--debug are incompatible")
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
520 if options.debug:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
521 if options.timeout != defaults['timeout']:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
522 sys.stderr.write(
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
523 'warning: --timeout option ignored with --debug\n')
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
524 if options.slowtimeout != defaults['slowtimeout']:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
525 sys.stderr.write(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
526 'warning: --slowtimeout option ignored with --debug\n')
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
527 options.timeout = 0
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
528 options.slowtimeout = 0
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
529 if options.py3k_warnings:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
530 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
531 parser.error(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
532 '--py3k-warnings can only be used on Python 2.7')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
533 if options.with_python3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
534 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
535 parser.error('--with-python3 cannot be used when executing with '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
536 'Python 3')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
537
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
538 options.with_python3 = canonpath(options.with_python3)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
539 # Verify Python3 executable is acceptable.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
540 proc = subprocess.Popen([options.with_python3, b'--version'],
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
541 stdout=subprocess.PIPE,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
542 stderr=subprocess.STDOUT)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
543 out, _err = proc.communicate()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
544 ret = proc.wait()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
545 if ret != 0:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
546 parser.error('could not determine version of python 3')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
547 if not out.startswith('Python '):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
548 parser.error('unexpected output from python3 --version: %s' %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
549 out)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
550 vers = version.LooseVersion(out[len('Python '):])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
551 if vers < version.LooseVersion('3.5.0'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
552 parser.error('--with-python3 version must be 3.5.0 or greater; '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
553 'got %s' % out)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
554
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
555 if options.blacklist:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
556 options.blacklist = parselistfiles(options.blacklist, 'blacklist')
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
557 if options.whitelist:
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
558 options.whitelisted = parselistfiles(options.whitelist, 'whitelist')
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
559 else:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
560 options.whitelisted = {}
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
561
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
562 if options.showchannels:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
563 options.nodiff = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
564
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
565 return options
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
566
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
567 def rename(src, dst):
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
568 """Like os.rename(), trade atomicity and opened files friendliness
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
569 for existing destination support.
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
570 """
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
571 shutil.copy(src, dst)
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
572 os.remove(src)
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
573
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
574 _unified_diff = difflib.unified_diff
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
575 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
576 import functools
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
577 _unified_diff = functools.partial(difflib.diff_bytes, difflib.unified_diff)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
578
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
579 def getdiff(expected, output, ref, err):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
580 servefail = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
581 lines = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
582 for line in _unified_diff(expected, output, ref, err):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
583 if line.startswith(b'+++') or line.startswith(b'---'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
584 line = line.replace(b'\\', b'/')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
585 if line.endswith(b' \n'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
586 line = line[:-2] + b'\n'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
587 lines.append(line)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
588 if not servefail and line.startswith(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
589 b'+ abort: child process failed to start'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
590 servefail = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
591
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
592 return servefail, lines
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
593
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
594 verbose = False
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
595 def vlog(*msg):
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
596 """Log only when in verbose mode."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
597 if verbose is False:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
598 return
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
599
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
600 return log(*msg)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
601
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
602 # Bytes that break XML even in a CDATA block: control characters 0-31
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
603 # sans \t, \n and \r
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
604 CDATA_EVIL = re.compile(br"[\000-\010\013\014\016-\037]")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
605
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
606 # Match feature conditionalized output lines in the form, capturing the feature
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
607 # list in group 2, and the preceeding line output in group 1:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
608 #
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
609 # output..output (feature !)\n
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
610 optline = re.compile(b'(.*) \((.+?) !\)\n$')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
611
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
612 def cdatasafe(data):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
613 """Make a string safe to include in a CDATA block.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
614
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
615 Certain control characters are illegal in a CDATA block, and
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
616 there's no way to include a ]]> in a CDATA either. This function
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
617 replaces illegal bytes with ? and adds a space between the ]] so
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
618 that it won't break the CDATA block.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
619 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
620 return CDATA_EVIL.sub(b'?', data).replace(b']]>', b'] ]>')
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
621
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
622 def log(*msg):
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
623 """Log something to stdout.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
624
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
625 Arguments are strings to print.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
626 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
627 with iolock:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
628 if verbose:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
629 print(verbose, end=' ')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
630 for m in msg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
631 print(m, end=' ')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
632 print()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
633 sys.stdout.flush()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
634
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
635 def highlightdiff(line, color):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
636 if not color:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
637 return line
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
638 assert pygmentspresent
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
639 return pygments.highlight(line.decode('latin1'), difflexer,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
640 terminal256formatter).encode('latin1')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
641
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
642 def highlightmsg(msg, color):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
643 if not color:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
644 return msg
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
645 assert pygmentspresent
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
646 return pygments.highlight(msg, runnerlexer, runnerformatter)
32
4ee030a94d79 Slightly modified run-tests.py so that tests can run self-contained.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
647
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
648 def terminate(proc):
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
649 """Terminate subprocess"""
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
650 vlog('# Terminating process %d' % proc.pid)
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
651 try:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
652 proc.terminate()
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
653 except OSError:
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
654 pass
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
655
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
656 def killdaemons(pidfile):
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
657 import killdaemons as killmod
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
658 return killmod.killdaemons(pidfile, tryhard=False, remove=True,
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
659 logfn=vlog)
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
660
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
661 class Test(unittest.TestCase):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
662 """Encapsulates a single, runnable test.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
663
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
664 While this class conforms to the unittest.TestCase API, it differs in that
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
665 instances need to be instantiated manually. (Typically, unittest.TestCase
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
666 classes are instantiated automatically by scanning modules.)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
667 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
668
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
669 # Status code reserved for skipped tests (used by hghave).
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
670 SKIPPED_STATUS = 80
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
671
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
672 def __init__(self, path, outputdir, tmpdir, keeptmpdir=False,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
673 debug=False,
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
674 first=False,
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
675 timeout=None,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
676 startport=None, extraconfigopts=None,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
677 py3kwarnings=False, shell=None, hgcommand=None,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
678 slowtimeout=None, usechg=False,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
679 useipv6=False):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
680 """Create a test from parameters.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
681
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
682 path is the full path to the file defining the test.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
683
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
684 tmpdir is the main temporary directory to use for this test.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
685
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
686 keeptmpdir determines whether to keep the test's temporary directory
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
687 after execution. It defaults to removal (False).
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
688
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
689 debug mode will make the test execute verbosely, with unfiltered
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
690 output.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
691
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
692 timeout controls the maximum run time of the test. It is ignored when
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
693 debug is True. See slowtimeout for tests with #require slow.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
694
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
695 slowtimeout overrides timeout if the test has #require slow.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
696
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
697 startport controls the starting port number to use for this test. Each
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
698 test will reserve 3 port numbers for execution. It is the caller's
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
699 responsibility to allocate a non-overlapping port range to Test
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
700 instances.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
701
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
702 extraconfigopts is an iterable of extra hgrc config options. Values
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
703 must have the form "key=value" (something understood by hgrc). Values
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
704 of the form "foo.key=value" will result in "[foo] key=value".
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
705
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
706 py3kwarnings enables Py3k warnings.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
707
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
708 shell is the shell to execute tests in.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
709 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
710 if timeout is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
711 timeout = defaults['timeout']
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
712 if startport is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
713 startport = defaults['port']
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
714 if slowtimeout is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
715 slowtimeout = defaults['slowtimeout']
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
716 self.path = path
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
717 self.bname = os.path.basename(path)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
718 self.name = _strpath(self.bname)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
719 self._testdir = os.path.dirname(path)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
720 self._outputdir = outputdir
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
721 self._tmpname = os.path.basename(path)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
722 self.errpath = os.path.join(self._outputdir, b'%s.err' % self.bname)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
723
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
724 self._threadtmp = tmpdir
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
725 self._keeptmpdir = keeptmpdir
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
726 self._debug = debug
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
727 self._first = first
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
728 self._timeout = timeout
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
729 self._slowtimeout = slowtimeout
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
730 self._startport = startport
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
731 self._extraconfigopts = extraconfigopts or []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
732 self._py3kwarnings = py3kwarnings
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
733 self._shell = _bytespath(shell)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
734 self._hgcommand = hgcommand or b'hg'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
735 self._usechg = usechg
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
736 self._useipv6 = useipv6
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
737
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
738 self._aborted = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
739 self._daemonpids = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
740 self._finished = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
741 self._ret = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
742 self._out = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
743 self._skipped = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
744 self._testtmp = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
745 self._chgsockdir = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
746
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
747 self._refout = self.readrefout()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
748
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
749 def readrefout(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
750 """read reference output"""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
751 # If we're not in --debug mode and reference output file exists,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
752 # check test output against it.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
753 if self._debug:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
754 return None # to match "out is None"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
755 elif os.path.exists(self.refpath):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
756 with open(self.refpath, 'rb') as f:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
757 return f.read().splitlines(True)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
758 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
759 return []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
760
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
761 # needed to get base class __repr__ running
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
762 @property
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
763 def _testMethodName(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
764 return self.name
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
765
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
766 def __str__(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
767 return self.name
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
768
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
769 def shortDescription(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
770 return self.name
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
771
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
772 def setUp(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
773 """Tasks to perform before run()."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
774 self._finished = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
775 self._ret = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
776 self._out = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
777 self._skipped = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
778
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
779 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
780 os.mkdir(self._threadtmp)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
781 except OSError as e:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
782 if e.errno != errno.EEXIST:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
783 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
784
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
785 name = self._tmpname
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
786 self._testtmp = os.path.join(self._threadtmp, name)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
787 os.mkdir(self._testtmp)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
788
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
789 # Remove any previous output files.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
790 if os.path.exists(self.errpath):
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
791 try:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
792 os.remove(self.errpath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
793 except OSError as e:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
794 # We might have raced another test to clean up a .err
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
795 # file, so ignore ENOENT when removing a previous .err
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
796 # file.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
797 if e.errno != errno.ENOENT:
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
798 raise
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
799
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
800 if self._usechg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
801 self._chgsockdir = os.path.join(self._threadtmp,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
802 b'%s.chgsock' % name)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
803 os.mkdir(self._chgsockdir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
804
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
805 def run(self, result):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
806 """Run this test and report results against a TestResult instance."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
807 # This function is extremely similar to unittest.TestCase.run(). Once
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
808 # we require Python 2.7 (or at least its version of unittest), this
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
809 # function can largely go away.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
810 self._result = result
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
811 result.startTest(self)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
812 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
813 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
814 self.setUp()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
815 except (KeyboardInterrupt, SystemExit):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
816 self._aborted = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
817 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
818 except Exception:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
819 result.addError(self, sys.exc_info())
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
820 return
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
821
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
822 success = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
823 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
824 self.runTest()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
825 except KeyboardInterrupt:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
826 self._aborted = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
827 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
828 except unittest.SkipTest as e:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
829 result.addSkip(self, str(e))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
830 # The base class will have already counted this as a
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
831 # test we "ran", but we want to exclude skipped tests
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
832 # from those we count towards those run.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
833 result.testsRun -= 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
834 except self.failureException as e:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
835 # This differs from unittest in that we don't capture
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
836 # the stack trace. This is for historical reasons and
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
837 # this decision could be revisited in the future,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
838 # especially for PythonTest instances.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
839 if result.addFailure(self, str(e)):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
840 success = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
841 except Exception:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
842 result.addError(self, sys.exc_info())
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
843 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
844 success = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
845
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
846 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
847 self.tearDown()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
848 except (KeyboardInterrupt, SystemExit):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
849 self._aborted = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
850 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
851 except Exception:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
852 result.addError(self, sys.exc_info())
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
853 success = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
854
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
855 if success:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
856 result.addSuccess(self)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
857 finally:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
858 result.stopTest(self, interrupted=self._aborted)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
859
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
860 def runTest(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
861 """Run this test instance.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
862
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
863 This will return a tuple describing the result of the test.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
864 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
865 env = self._getenv()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
866 self._genrestoreenv(env)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
867 self._daemonpids.append(env['DAEMON_PIDS'])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
868 self._createhgrc(env['HGRCPATH'])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
869
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
870 vlog('# Test', self.name)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
871
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
872 ret, out = self._run(env)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
873 self._finished = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
874 self._ret = ret
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
875 self._out = out
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
876
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
877 def describe(ret):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
878 if ret < 0:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
879 return 'killed by signal: %d' % -ret
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
880 return 'returned error code %d' % ret
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
881
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
882 self._skipped = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
883
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
884 if ret == self.SKIPPED_STATUS:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
885 if out is None: # Debug mode, nothing to parse.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
886 missing = ['unknown']
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
887 failed = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
888 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
889 missing, failed = TTest.parsehghaveoutput(out)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
890
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
891 if not missing:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
892 missing = ['skipped']
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
893
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
894 if failed:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
895 self.fail('hg have failed checking for %s' % failed[-1])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
896 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
897 self._skipped = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
898 raise unittest.SkipTest(missing[-1])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
899 elif ret == 'timeout':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
900 self.fail('timed out')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
901 elif ret is False:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
902 self.fail('no result code from test')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
903 elif out != self._refout:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
904 # Diff generation may rely on written .err file.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
905 if (ret != 0 or out != self._refout) and not self._skipped \
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
906 and not self._debug:
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
907 with open(self.errpath, 'wb') as f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
908 for line in out:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
909 f.write(line)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
910
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
911 # The result object handles diff calculation for us.
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
912 with firstlock:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
913 if self._result.addOutputMismatch(self, ret, out, self._refout):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
914 # change was accepted, skip failing
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
915 return
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
916 if self._first:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
917 global firsterror
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
918 firsterror = True
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
919
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
920 if ret:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
921 msg = 'output changed and ' + describe(ret)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
922 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
923 msg = 'output changed'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
924
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
925 self.fail(msg)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
926 elif ret:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
927 self.fail(describe(ret))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
928
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
929 def tearDown(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
930 """Tasks to perform after run()."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
931 for entry in self._daemonpids:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
932 killdaemons(entry)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
933 self._daemonpids = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
934
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
935 if self._keeptmpdir:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
936 log('\nKeeping testtmp dir: %s\nKeeping threadtmp dir: %s' %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
937 (self._testtmp.decode('utf-8'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
938 self._threadtmp.decode('utf-8')))
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
939 else:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
940 shutil.rmtree(self._testtmp, True)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
941 shutil.rmtree(self._threadtmp, True)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
942
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
943 if self._usechg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
944 # chgservers will stop automatically after they find the socket
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
945 # files are deleted
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
946 shutil.rmtree(self._chgsockdir, True)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
947
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
948 if (self._ret != 0 or self._out != self._refout) and not self._skipped \
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
949 and not self._debug and self._out:
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
950 with open(self.errpath, 'wb') as f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
951 for line in self._out:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
952 f.write(line)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
953
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
954 vlog("# Ret was:", self._ret, '(%s)' % self.name)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
955
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
956 def _run(self, env):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
957 # This should be implemented in child classes to run tests.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
958 raise unittest.SkipTest('unknown test type')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
959
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
960 def abort(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
961 """Terminate execution of this test."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
962 self._aborted = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
963
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
964 def _portmap(self, i):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
965 offset = b'' if i == 0 else b'%d' % i
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
966 return (br':%d\b' % (self._startport + i), b':$HGPORT%s' % offset)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
967
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
968 def _getreplacements(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
969 """Obtain a mapping of text replacements to apply to test output.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
970
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
971 Test output needs to be normalized so it can be compared to expected
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
972 output. This function defines how some of that normalization will
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
973 occur.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
974 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
975 r = [
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
976 # This list should be parallel to defineport in _getenv
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
977 self._portmap(0),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
978 self._portmap(1),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
979 self._portmap(2),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
980 (br'([^0-9])%s' % re.escape(self._localip()), br'\1$LOCALIP'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
981 (br'\bHG_TXNID=TXN:[a-f0-9]{40}\b', br'HG_TXNID=TXN:$ID$'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
982 ]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
983 r.append((self._escapepath(self._testtmp), b'$TESTTMP'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
984
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
985 replacementfile = os.path.join(self._testdir, b'common-pattern.py')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
986
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
987 if os.path.exists(replacementfile):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
988 data = {}
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
989 with open(replacementfile, mode='rb') as source:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
990 # the intermediate 'compile' step help with debugging
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
991 code = compile(source.read(), replacementfile, 'exec')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
992 exec(code, data)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
993 r.extend(data.get('substitutions', ()))
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
994 return r
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
995
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
996 def _escapepath(self, p):
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
997 if os.name == 'nt':
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
998 return (
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
999 (b''.join(c.isalpha() and b'[%s%s]' % (c.lower(), c.upper()) or
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1000 c in b'/\\' and br'[/\\]' or c.isdigit() and c or b'\\' + c
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1001 for c in p))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1002 )
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1003 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1004 return re.escape(p)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1005
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1006 def _localip(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1007 if self._useipv6:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1008 return b'::1'
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
1009 else:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1010 return b'127.0.0.1'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1011
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1012 def _genrestoreenv(self, testenv):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1013 """Generate a script that can be used by tests to restore the original
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1014 environment."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1015 # Put the restoreenv script inside self._threadtmp
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1016 scriptpath = os.path.join(self._threadtmp, b'restoreenv.sh')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1017 testenv['HGTEST_RESTOREENV'] = scriptpath
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1018
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1019 # Only restore environment variable names that the shell allows
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1020 # us to export.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1021 name_regex = re.compile('^[a-zA-Z][a-zA-Z0-9_]*$')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1022
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1023 # Do not restore these variables; otherwise tests would fail.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1024 reqnames = {'PYTHON', 'TESTDIR', 'TESTTMP'}
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1025
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1026 with open(scriptpath, 'w') as envf:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1027 for name, value in origenviron.items():
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1028 if not name_regex.match(name):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1029 # Skip environment variables with unusual names not
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1030 # allowed by most shells.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1031 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1032 if name in reqnames:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1033 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1034 envf.write('%s=%s\n' % (name, shellquote(value)))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1035
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1036 for name in testenv:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1037 if name in origenviron or name in reqnames:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1038 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1039 envf.write('unset %s\n' % (name,))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1040
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1041 def _getenv(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1042 """Obtain environment variables to use during test execution."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1043 def defineport(i):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1044 offset = '' if i == 0 else '%s' % i
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1045 env["HGPORT%s" % offset] = '%s' % (self._startport + i)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1046 env = os.environ.copy()
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1047 env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or ''
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1048 env['HGEMITWARNINGS'] = '1'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1049 env['TESTTMP'] = self._testtmp
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1050 env['HOME'] = self._testtmp
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1051 # This number should match portneeded in _getport
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1052 for port in xrange(3):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1053 # This list should be parallel to _portmap in _getreplacements
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1054 defineport(port)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1055 env["HGRCPATH"] = os.path.join(self._threadtmp, b'.hgrc')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1056 env["DAEMON_PIDS"] = os.path.join(self._threadtmp, b'daemon.pids')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1057 env["HGEDITOR"] = ('"' + sys.executable + '"'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1058 + ' -c "import sys; sys.exit(0)"')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1059 env["HGMERGE"] = "internal:merge"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1060 env["HGUSER"] = "test"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1061 env["HGENCODING"] = "ascii"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1062 env["HGENCODINGMODE"] = "strict"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1063 env['HGIPV6'] = str(int(self._useipv6))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1064
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1065 # LOCALIP could be ::1 or 127.0.0.1. Useful for tests that require raw
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1066 # IP addresses.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1067 env['LOCALIP'] = self._localip()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1068
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1069 # Reset some environment variables to well-known values so that
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1070 # the tests produce repeatable output.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1071 env['LANG'] = env['LC_ALL'] = env['LANGUAGE'] = 'C'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1072 env['TZ'] = 'GMT'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1073 env["EMAIL"] = "Foo Bar <foo.bar@example.com>"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1074 env['COLUMNS'] = '80'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1075 env['TERM'] = 'xterm'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1076
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1077 for k in ('HG HGPROF CDPATH GREP_OPTIONS http_proxy no_proxy ' +
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1078 'HGPLAIN HGPLAINEXCEPT EDITOR VISUAL PAGER ' +
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1079 'NO_PROXY CHGDEBUG').split():
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1080 if k in env:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1081 del env[k]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1082
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1083 # unset env related to hooks
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1084 for k in env.keys():
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1085 if k.startswith('HG_'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1086 del env[k]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1087
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1088 if self._usechg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1089 env['CHGSOCKNAME'] = os.path.join(self._chgsockdir, b'server')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1090
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1091 return env
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1092
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1093 def _createhgrc(self, path):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1094 """Create an hgrc file for this test."""
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1095 with open(path, 'wb') as hgrc:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1096 hgrc.write(b'[ui]\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1097 hgrc.write(b'slash = True\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1098 hgrc.write(b'interactive = False\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1099 hgrc.write(b'mergemarkers = detailed\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1100 hgrc.write(b'promptecho = True\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1101 hgrc.write(b'[defaults]\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1102 hgrc.write(b'[devel]\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1103 hgrc.write(b'all-warnings = true\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1104 hgrc.write(b'default-date = 0 0\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1105 hgrc.write(b'[largefiles]\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1106 hgrc.write(b'usercache = %s\n' %
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1107 (os.path.join(self._testtmp, b'.cache/largefiles')))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1108 hgrc.write(b'[lfs]\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1109 hgrc.write(b'usercache = %s\n' %
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1110 (os.path.join(self._testtmp, b'.cache/lfs')))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1111 hgrc.write(b'[web]\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1112 hgrc.write(b'address = localhost\n')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1113 hgrc.write(b'ipv6 = %s\n' % str(self._useipv6).encode('ascii'))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1114
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1115 for opt in self._extraconfigopts:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1116 section, key = opt.encode('utf-8').split(b'.', 1)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1117 assert b'=' in key, ('extra config opt %s must '
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1118 'have an = for assignment' % opt)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1119 hgrc.write(b'[%s]\n%s\n' % (section, key))
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1120
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1121 def fail(self, msg):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1122 # unittest differentiates between errored and failed.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1123 # Failed is denoted by AssertionError (by default at least).
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1124 raise AssertionError(msg)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1125
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1126 def _runcommand(self, cmd, env, normalizenewlines=False):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1127 """Run command in a sub-process, capturing the output (stdout and
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1128 stderr).
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1129
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1130 Return a tuple (exitcode, output). output is None in debug mode.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1131 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1132 if self._debug:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1133 proc = subprocess.Popen(cmd, shell=True, cwd=self._testtmp,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1134 env=env)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1135 ret = proc.wait()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1136 return (ret, None)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1137
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1138 proc = Popen4(cmd, self._testtmp, self._timeout, env)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1139 def cleanup():
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1140 terminate(proc)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1141 ret = proc.wait()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1142 if ret == 0:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1143 ret = signal.SIGTERM << 8
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1144 killdaemons(env['DAEMON_PIDS'])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1145 return ret
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1146
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1147 output = ''
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1148 proc.tochild.close()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1149
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1150 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1151 output = proc.fromchild.read()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1152 except KeyboardInterrupt:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1153 vlog('# Handling keyboard interrupt')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1154 cleanup()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1155 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1156
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1157 ret = proc.wait()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1158 if wifexited(ret):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1159 ret = os.WEXITSTATUS(ret)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1160
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1161 if proc.timeout:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1162 ret = 'timeout'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1163
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1164 if ret:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1165 killdaemons(env['DAEMON_PIDS'])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1166
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1167 for s, r in self._getreplacements():
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1168 output = re.sub(s, r, output)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1169
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1170 if normalizenewlines:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1171 output = output.replace('\r\n', '\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1172
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1173 return ret, output.splitlines(True)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1174
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1175 class PythonTest(Test):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1176 """A Python-based test."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1177
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1178 @property
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1179 def refpath(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1180 return os.path.join(self._testdir, b'%s.out' % self.bname)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1181
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1182 def _run(self, env):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1183 py3kswitch = self._py3kwarnings and b' -3' or b''
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1184 cmd = b'%s%s "%s"' % (PYTHON, py3kswitch, self.path)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1185 vlog("# Running", cmd)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1186 normalizenewlines = os.name == 'nt'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1187 result = self._runcommand(cmd, env,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1188 normalizenewlines=normalizenewlines)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1189 if self._aborted:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1190 raise KeyboardInterrupt()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1191
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1192 return result
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1193
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1194 # Some glob patterns apply only in some circumstances, so the script
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1195 # might want to remove (glob) annotations that otherwise should be
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1196 # retained.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1197 checkcodeglobpats = [
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1198 # On Windows it looks like \ doesn't require a (glob), but we know
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1199 # better.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1200 re.compile(br'^pushing to \$TESTTMP/.*[^)]$'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1201 re.compile(br'^moving \S+/.*[^)]$'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1202 re.compile(br'^pulling from \$TESTTMP/.*[^)]$'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1203 # Not all platforms have 127.0.0.1 as loopback (though most do),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1204 # so we always glob that too.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1205 re.compile(br'.*\$LOCALIP.*$'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1206 ]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1207
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1208 bchr = chr
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1209 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1210 bchr = lambda x: bytes([x])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1211
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1212 class TTest(Test):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1213 """A "t test" is a test backed by a .t file."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1214
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1215 SKIPPED_PREFIX = b'skipped: '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1216 FAILED_PREFIX = b'hghave check failed: '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1217 NEEDESCAPE = re.compile(br'[\x00-\x08\x0b-\x1f\x7f-\xff]').search
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1218
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1219 ESCAPESUB = re.compile(br'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1220 ESCAPEMAP = dict((bchr(i), br'\x%02x' % i) for i in range(256))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1221 ESCAPEMAP.update({b'\\': b'\\\\', b'\r': br'\r'})
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1222
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1223 def __init__(self, path, *args, **kwds):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1224 # accept an extra "case" parameter
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1225 case = kwds.pop('case', None)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1226 self._case = case
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1227 self._allcases = parsettestcases(path)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1228 super(TTest, self).__init__(path, *args, **kwds)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1229 if case:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1230 self.name = '%s (case %s)' % (self.name, _strpath(case))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1231 self.errpath = b'%s.%s.err' % (self.errpath[:-4], case)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1232 self._tmpname += b'-%s' % case
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1233
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1234 @property
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1235 def refpath(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1236 return os.path.join(self._testdir, self.bname)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1237
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1238 def _run(self, env):
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1239 with open(self.path, 'rb') as f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1240 lines = f.readlines()
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1241
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1242 # .t file is both reference output and the test input, keep reference
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1243 # output updated with the the test input. This avoids some race
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1244 # conditions where the reference output does not match the actual test.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1245 if self._refout is not None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1246 self._refout = lines
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1247
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1248 salt, script, after, expected = self._parsetest(lines)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1249
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1250 # Write out the generated script.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1251 fname = b'%s.sh' % self._testtmp
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1252 with open(fname, 'wb') as f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1253 for l in script:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1254 f.write(l)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1255
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1256 cmd = b'%s "%s"' % (self._shell, fname)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1257 vlog("# Running", cmd)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1258
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1259 exitcode, output = self._runcommand(cmd, env)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1260
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1261 if self._aborted:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1262 raise KeyboardInterrupt()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1263
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1264 # Do not merge output if skipped. Return hghave message instead.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1265 # Similarly, with --debug, output is None.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1266 if exitcode == self.SKIPPED_STATUS or output is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1267 return exitcode, output
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1268
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1269 return self._processoutput(exitcode, output, salt, after, expected)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1270
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1271 def _hghave(self, reqs):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1272 # TODO do something smarter when all other uses of hghave are gone.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1273 runtestdir = os.path.abspath(os.path.dirname(_bytespath(__file__)))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1274 tdir = runtestdir.replace(b'\\', b'/')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1275 proc = Popen4(b'%s -c "%s/hghave %s"' %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1276 (self._shell, tdir, b' '.join(reqs)),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1277 self._testtmp, 0, self._getenv())
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
1278 stdout, stderr = proc.communicate()
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
1279 ret = proc.wait()
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
1280 if wifexited(ret):
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
1281 ret = os.WEXITSTATUS(ret)
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
1282 if ret == 2:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1283 print(stdout.decode('utf-8'))
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
1284 sys.exit(1)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1285
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1286 if ret != 0:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1287 return False, stdout
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1288
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1289 if b'slow' in reqs:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1290 self._timeout = self._slowtimeout
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1291 return True, None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1292
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1293 def _iftest(self, args):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1294 # implements "#if"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1295 reqs = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1296 for arg in args:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1297 if arg.startswith(b'no-') and arg[3:] in self._allcases:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1298 if arg[3:] == self._case:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1299 return False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1300 elif arg in self._allcases:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1301 if arg != self._case:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1302 return False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1303 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1304 reqs.append(arg)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1305 return self._hghave(reqs)[0]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1306
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1307 def _parsetest(self, lines):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1308 # We generate a shell script which outputs unique markers to line
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1309 # up script results with our source. These markers include input
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1310 # line number and the last return code.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1311 salt = b"SALT%d" % time.time()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1312 def addsalt(line, inpython):
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
1313 if inpython:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1314 script.append(b'%s %d 0\n' % (salt, line))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1315 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1316 script.append(b'echo %s %d $?\n' % (salt, line))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1317
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1318 script = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1319
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1320 # After we run the shell script, we re-unify the script output
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1321 # with non-active parts of the source, with synchronization by our
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1322 # SALT line number markers. The after table contains the non-active
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1323 # components, ordered by line number.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1324 after = {}
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1325
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1326 # Expected shell script output.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1327 expected = {}
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1328
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1329 pos = prepos = -1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1330
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1331 # True or False when in a true or false conditional section
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1332 skipping = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1333
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1334 # We keep track of whether or not we're in a Python block so we
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1335 # can generate the surrounding doctest magic.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1336 inpython = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1337
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1338 if self._debug:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1339 script.append(b'set -x\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1340 if self._hgcommand != b'hg':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1341 script.append(b'alias hg="%s"\n' % self._hgcommand)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1342 if os.getenv('MSYSTEM'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1343 script.append(b'alias pwd="pwd -W"\n')
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1344 if self._case:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1345 if isinstance(self._case, str):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1346 quoted = shellquote(self._case)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1347 else:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1348 quoted = shellquote(self._case.decode('utf8')).encode('utf8')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1349 script.append(b'TESTCASE=%s\n' % quoted)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1350 script.append(b'export TESTCASE\n')
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1351
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1352 n = 0
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1353 for n, l in enumerate(lines):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1354 if not l.endswith(b'\n'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1355 l += b'\n'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1356 if l.startswith(b'#require'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1357 lsplit = l.split()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1358 if len(lsplit) < 2 or lsplit[0] != b'#require':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1359 after.setdefault(pos, []).append(' !!! invalid #require\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1360 haveresult, message = self._hghave(lsplit[1:])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1361 if not haveresult:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1362 script = [b'echo "%s"\nexit 80\n' % message]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1363 break
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1364 after.setdefault(pos, []).append(l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1365 elif l.startswith(b'#if'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1366 lsplit = l.split()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1367 if len(lsplit) < 2 or lsplit[0] != b'#if':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1368 after.setdefault(pos, []).append(' !!! invalid #if\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1369 if skipping is not None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1370 after.setdefault(pos, []).append(' !!! nested #if\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1371 skipping = not self._iftest(lsplit[1:])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1372 after.setdefault(pos, []).append(l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1373 elif l.startswith(b'#else'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1374 if skipping is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1375 after.setdefault(pos, []).append(' !!! missing #if\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1376 skipping = not skipping
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1377 after.setdefault(pos, []).append(l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1378 elif l.startswith(b'#endif'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1379 if skipping is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1380 after.setdefault(pos, []).append(' !!! missing #if\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1381 skipping = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1382 after.setdefault(pos, []).append(l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1383 elif skipping:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1384 after.setdefault(pos, []).append(l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1385 elif l.startswith(b' >>> '): # python inlines
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1386 after.setdefault(pos, []).append(l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1387 prepos = pos
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1388 pos = n
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1389 if not inpython:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1390 # We've just entered a Python block. Add the header.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1391 inpython = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1392 addsalt(prepos, False) # Make sure we report the exit code.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1393 script.append(b'%s -m heredoctest <<EOF\n' % PYTHON)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1394 addsalt(n, True)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1395 script.append(l[2:])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1396 elif l.startswith(b' ... '): # python inlines
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1397 after.setdefault(prepos, []).append(l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1398 script.append(l[2:])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1399 elif l.startswith(b' $ '): # commands
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1400 if inpython:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1401 script.append(b'EOF\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1402 inpython = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1403 after.setdefault(pos, []).append(l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1404 prepos = pos
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1405 pos = n
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1406 addsalt(n, False)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1407 cmd = l[4:].split()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1408 if len(cmd) == 2 and cmd[0] == b'cd':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1409 l = b' $ cd %s || exit 1\n' % cmd[1]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1410 script.append(l[4:])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1411 elif l.startswith(b' > '): # continuations
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1412 after.setdefault(prepos, []).append(l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1413 script.append(l[4:])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1414 elif l.startswith(b' '): # results
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1415 # Queue up a list of expected results.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1416 expected.setdefault(pos, []).append(l[2:])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1417 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1418 if inpython:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1419 script.append(b'EOF\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1420 inpython = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1421 # Non-command/result. Queue up for merged output.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1422 after.setdefault(pos, []).append(l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1423
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1424 if inpython:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1425 script.append(b'EOF\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1426 if skipping is not None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1427 after.setdefault(pos, []).append(' !!! missing #endif\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1428 addsalt(n + 1, False)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1429
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1430 return salt, script, after, expected
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1431
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1432 def _processoutput(self, exitcode, output, salt, after, expected):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1433 # Merge the script output back into a unified test.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1434 warnonly = 1 # 1: not yet; 2: yes; 3: for sure not
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1435 if exitcode != 0:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1436 warnonly = 3
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1437
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1438 pos = -1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1439 postout = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1440 for l in output:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1441 lout, lcmd = l, None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1442 if salt in l:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1443 lout, lcmd = l.split(salt, 1)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1444
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1445 while lout:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1446 if not lout.endswith(b'\n'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1447 lout += b' (no-eol)\n'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1448
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1449 # Find the expected output at the current position.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1450 els = [None]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1451 if expected.get(pos, None):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1452 els = expected[pos]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1453
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1454 i = 0
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1455 optional = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1456 while i < len(els):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1457 el = els[i]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1458
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1459 r = self.linematch(el, lout)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1460 if isinstance(r, str):
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1461 if r == '-glob':
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1462 lout = ''.join(el.rsplit(' (glob)', 1))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1463 r = '' # Warn only this line.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1464 elif r == "retry":
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1465 postout.append(b' ' + el)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1466 els.pop(i)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1467 break
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1468 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1469 log('\ninfo, unknown linematch result: %r\n' % r)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1470 r = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1471 if r:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1472 els.pop(i)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1473 break
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1474 if el:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1475 if el.endswith(b" (?)\n"):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1476 optional.append(i)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1477 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1478 m = optline.match(el)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1479 if m:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1480 conditions = [
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1481 c for c in m.group(2).split(b' ')]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1482
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1483 if not self._iftest(conditions):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1484 optional.append(i)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1485
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1486 i += 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1487
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1488 if r:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1489 if r == "retry":
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1490 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1491 # clean up any optional leftovers
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1492 for i in optional:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1493 postout.append(b' ' + els[i])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1494 for i in reversed(optional):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1495 del els[i]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1496 postout.append(b' ' + el)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1497 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1498 if self.NEEDESCAPE(lout):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1499 lout = TTest._stringescape(b'%s (esc)\n' %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1500 lout.rstrip(b'\n'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1501 postout.append(b' ' + lout) # Let diff deal with it.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1502 if r != '': # If line failed.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1503 warnonly = 3 # for sure not
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1504 elif warnonly == 1: # Is "not yet" and line is warn only.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1505 warnonly = 2 # Yes do warn.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1506 break
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1507 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1508 # clean up any optional leftovers
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1509 while expected.get(pos, None):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1510 el = expected[pos].pop(0)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1511 if el:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1512 if not el.endswith(b" (?)\n"):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1513 m = optline.match(el)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1514 if m:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1515 conditions = [c for c in m.group(2).split(b' ')]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1516
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1517 if self._iftest(conditions):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1518 # Don't append as optional line
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1519 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1520 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1521 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1522 postout.append(b' ' + el)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1523
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1524 if lcmd:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1525 # Add on last return code.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1526 ret = int(lcmd.split()[1])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1527 if ret != 0:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1528 postout.append(b' [%d]\n' % ret)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1529 if pos in after:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1530 # Merge in non-active test bits.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1531 postout += after.pop(pos)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1532 pos = int(lcmd.split()[0])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1533
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1534 if pos in after:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1535 postout += after.pop(pos)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1536
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1537 if warnonly == 2:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1538 exitcode = False # Set exitcode to warned.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1539
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1540 return exitcode, postout
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1541
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1542 @staticmethod
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1543 def rematch(el, l):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1544 try:
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1545 el = b'(?:' + el + b')'
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1546 # use \Z to ensure that the regex matches to the end of the string
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1547 if os.name == 'nt':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1548 return re.match(el + br'\r?\n\Z', l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1549 return re.match(el + br'\n\Z', l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1550 except re.error:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1551 # el is an invalid regex
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1552 return False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1553
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1554 @staticmethod
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1555 def globmatch(el, l):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1556 # The only supported special characters are * and ? plus / which also
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1557 # matches \ on windows. Escaping of these characters is supported.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1558 if el + b'\n' == l:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1559 if os.altsep:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1560 # matching on "/" is not needed for this line
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1561 for pat in checkcodeglobpats:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1562 if pat.match(el):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1563 return True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1564 return b'-glob'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1565 return True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1566 el = el.replace(b'$LOCALIP', b'*')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1567 i, n = 0, len(el)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1568 res = b''
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1569 while i < n:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1570 c = el[i:i + 1]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1571 i += 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1572 if c == b'\\' and i < n and el[i:i + 1] in b'*?\\/':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1573 res += el[i - 1:i + 1]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1574 i += 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1575 elif c == b'*':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1576 res += b'.*'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1577 elif c == b'?':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1578 res += b'.'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1579 elif c == b'/' and os.altsep:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1580 res += b'[/\\\\]'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1581 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1582 res += re.escape(c)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1583 return TTest.rematch(res, l)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1584
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1585 def linematch(self, el, l):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1586 retry = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1587 if el == l: # perfect match (fast)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1588 return True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1589 if el:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1590 if el.endswith(b" (?)\n"):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1591 retry = "retry"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1592 el = el[:-5] + b"\n"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1593 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1594 m = optline.match(el)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1595 if m:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1596 conditions = [c for c in m.group(2).split(b' ')]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1597
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1598 el = m.group(1) + b"\n"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1599 if not self._iftest(conditions):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1600 retry = "retry" # Not required by listed features
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1601
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1602 if el.endswith(b" (esc)\n"):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1603 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1604 el = el[:-7].decode('unicode_escape') + '\n'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1605 el = el.encode('utf-8')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1606 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1607 el = el[:-7].decode('string-escape') + '\n'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1608 if el == l or os.name == 'nt' and el[:-1] + b'\r\n' == l:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1609 return True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1610 if el.endswith(b" (re)\n"):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1611 return TTest.rematch(el[:-6], l) or retry
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1612 if el.endswith(b" (glob)\n"):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1613 # ignore '(glob)' added to l by 'replacements'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1614 if l.endswith(b" (glob)\n"):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1615 l = l[:-8] + b"\n"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1616 return TTest.globmatch(el[:-8], l) or retry
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1617 if os.altsep:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1618 _l = l.replace(b'\\', b'/')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1619 if el == _l or os.name == 'nt' and el[:-1] + b'\r\n' == _l:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1620 return True
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1621 return retry
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1622
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1623 @staticmethod
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1624 def parsehghaveoutput(lines):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1625 '''Parse hghave log lines.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1626
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1627 Return tuple of lists (missing, failed):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1628 * the missing/unknown features
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1629 * the features for which existence check failed'''
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1630 missing = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1631 failed = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1632 for line in lines:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1633 if line.startswith(TTest.SKIPPED_PREFIX):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1634 line = line.splitlines()[0]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1635 missing.append(line[len(TTest.SKIPPED_PREFIX):].decode('utf-8'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1636 elif line.startswith(TTest.FAILED_PREFIX):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1637 line = line.splitlines()[0]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1638 failed.append(line[len(TTest.FAILED_PREFIX):].decode('utf-8'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1639
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1640 return missing, failed
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1641
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1642 @staticmethod
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1643 def _escapef(m):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1644 return TTest.ESCAPEMAP[m.group(0)]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1645
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1646 @staticmethod
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1647 def _stringescape(s):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1648 return TTest.ESCAPESUB(TTest._escapef, s)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1649
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1650 iolock = threading.RLock()
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1651 firstlock = threading.RLock()
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1652 firsterror = False
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1653
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1654 class TestResult(unittest._TextTestResult):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1655 """Holds results when executing via unittest."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1656 # Don't worry too much about accessing the non-public _TextTestResult.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1657 # It is relatively common in Python testing tools.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1658 def __init__(self, options, *args, **kwargs):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1659 super(TestResult, self).__init__(*args, **kwargs)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1660
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1661 self._options = options
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1662
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1663 # unittest.TestResult didn't have skipped until 2.7. We need to
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1664 # polyfill it.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1665 self.skipped = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1666
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1667 # We have a custom "ignored" result that isn't present in any Python
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1668 # unittest implementation. It is very similar to skipped. It may make
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1669 # sense to map it into skip some day.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1670 self.ignored = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1671
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1672 self.times = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1673 self._firststarttime = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1674 # Data stored for the benefit of generating xunit reports.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1675 self.successes = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1676 self.faildata = {}
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1677
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1678 if options.color == 'auto':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1679 self.color = pygmentspresent and self.stream.isatty()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1680 elif options.color == 'never':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1681 self.color = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1682 else: # 'always', for testing purposes
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1683 self.color = pygmentspresent
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1684
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1685 def addFailure(self, test, reason):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1686 self.failures.append((test, reason))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1687
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1688 if self._options.first:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1689 self.stop()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1690 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1691 with iolock:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1692 if reason == "timed out":
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1693 self.stream.write('t')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1694 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1695 if not self._options.nodiff:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1696 self.stream.write('\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1697 # Exclude the '\n' from highlighting to lex correctly
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1698 formatted = 'ERROR: %s output changed\n' % test
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1699 self.stream.write(highlightmsg(formatted, self.color))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1700 self.stream.write('!')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1701
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1702 self.stream.flush()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1703
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1704 def addSuccess(self, test):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1705 with iolock:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1706 super(TestResult, self).addSuccess(test)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1707 self.successes.append(test)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1708
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1709 def addError(self, test, err):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1710 super(TestResult, self).addError(test, err)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1711 if self._options.first:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1712 self.stop()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1713
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1714 # Polyfill.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1715 def addSkip(self, test, reason):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1716 self.skipped.append((test, reason))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1717 with iolock:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1718 if self.showAll:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1719 self.stream.writeln('skipped %s' % reason)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1720 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1721 self.stream.write('s')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1722 self.stream.flush()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1723
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1724 def addIgnore(self, test, reason):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1725 self.ignored.append((test, reason))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1726 with iolock:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1727 if self.showAll:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1728 self.stream.writeln('ignored %s' % reason)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1729 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1730 if reason not in ('not retesting', "doesn't match keyword"):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1731 self.stream.write('i')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1732 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1733 self.testsRun += 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1734 self.stream.flush()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1735
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1736 def addOutputMismatch(self, test, ret, got, expected):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1737 """Record a mismatch in test output for a particular test."""
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1738 if self.shouldStop or firsterror:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1739 # don't print, some other test case already failed and
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1740 # printed, we're just stale and probably failed due to our
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1741 # temp dir getting cleaned up.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1742 return
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1743
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1744 accepted = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1745 lines = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1746
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1747 with iolock:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1748 if self._options.nodiff:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1749 pass
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1750 elif self._options.view:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1751 v = self._options.view
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1752 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1753 v = _bytespath(v)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1754 os.system(b"%s %s %s" %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1755 (v, test.refpath, test.errpath))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1756 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1757 servefail, lines = getdiff(expected, got,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1758 test.refpath, test.errpath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1759 if servefail:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1760 raise test.failureException(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1761 'server failed to start (HGPORT=%s)' % test._startport)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1762 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1763 self.stream.write('\n')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1764 for line in lines:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1765 line = highlightdiff(line, self.color)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1766 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1767 self.stream.flush()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1768 self.stream.buffer.write(line)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1769 self.stream.buffer.flush()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1770 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1771 self.stream.write(line)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1772 self.stream.flush()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1773
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1774 # handle interactive prompt without releasing iolock
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1775 if self._options.interactive:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1776 if test.readrefout() != expected:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1777 self.stream.write(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1778 'Reference output has changed (run again to prompt '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1779 'changes)')
673
0b33ab75e3cb tests: upgrade run-tests.py
Siddharth Agarwal <sid0@fb.com>
parents: 492
diff changeset
1780 else:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1781 self.stream.write('Accept this change? [n] ')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1782 answer = sys.stdin.readline().strip()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1783 if answer.lower() in ('y', 'yes'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1784 if test.path.endswith(b'.t'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1785 rename(test.errpath, test.path)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1786 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1787 rename(test.errpath, '%s.out' % test.path)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1788 accepted = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1789 if not accepted:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1790 self.faildata[test.name] = b''.join(lines)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1791
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1792 return accepted
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1793
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1794 def startTest(self, test):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1795 super(TestResult, self).startTest(test)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1796
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1797 # os.times module computes the user time and system time spent by
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1798 # child's processes along with real elapsed time taken by a process.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1799 # This module has one limitation. It can only work for Linux user
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1800 # and not for Windows.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1801 test.started = os.times()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1802 if self._firststarttime is None: # thread racy but irrelevant
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1803 self._firststarttime = test.started[4]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1804
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1805 def stopTest(self, test, interrupted=False):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1806 super(TestResult, self).stopTest(test)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1807
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1808 test.stopped = os.times()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1809
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1810 starttime = test.started
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1811 endtime = test.stopped
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1812 origin = self._firststarttime
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1813 self.times.append((test.name,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1814 endtime[2] - starttime[2], # user space CPU time
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1815 endtime[3] - starttime[3], # sys space CPU time
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1816 endtime[4] - starttime[4], # real time
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1817 starttime[4] - origin, # start date in run context
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1818 endtime[4] - origin, # end date in run context
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1819 ))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1820
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1821 if interrupted:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1822 with iolock:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1823 self.stream.writeln('INTERRUPTED: %s (after %d seconds)' % (
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1824 test.name, self.times[-1][3]))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1825
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1826 class TestSuite(unittest.TestSuite):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1827 """Custom unittest TestSuite that knows how to execute Mercurial tests."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1828
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1829 def __init__(self, testdir, jobs=1, whitelist=None, blacklist=None,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1830 retest=False, keywords=None, loop=False, runs_per_test=1,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1831 loadtest=None, showchannels=False,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1832 *args, **kwargs):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1833 """Create a new instance that can run tests with a configuration.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1834
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1835 testdir specifies the directory where tests are executed from. This
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1836 is typically the ``tests`` directory from Mercurial's source
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1837 repository.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1838
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1839 jobs specifies the number of jobs to run concurrently. Each test
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1840 executes on its own thread. Tests actually spawn new processes, so
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1841 state mutation should not be an issue.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1842
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1843 If there is only one job, it will use the main thread.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1844
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1845 whitelist and blacklist denote tests that have been whitelisted and
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1846 blacklisted, respectively. These arguments don't belong in TestSuite.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1847 Instead, whitelist and blacklist should be handled by the thing that
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1848 populates the TestSuite with tests. They are present to preserve
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1849 backwards compatible behavior which reports skipped tests as part
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1850 of the results.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1851
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1852 retest denotes whether to retest failed tests. This arguably belongs
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1853 outside of TestSuite.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1854
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1855 keywords denotes key words that will be used to filter which tests
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1856 to execute. This arguably belongs outside of TestSuite.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1857
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1858 loop denotes whether to loop over tests forever.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1859 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1860 super(TestSuite, self).__init__(*args, **kwargs)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1861
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1862 self._jobs = jobs
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1863 self._whitelist = whitelist
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1864 self._blacklist = blacklist
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1865 self._retest = retest
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1866 self._keywords = keywords
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1867 self._loop = loop
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1868 self._runs_per_test = runs_per_test
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1869 self._loadtest = loadtest
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1870 self._showchannels = showchannels
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1871
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1872 def run(self, result):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1873 # We have a number of filters that need to be applied. We do this
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1874 # here instead of inside Test because it makes the running logic for
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1875 # Test simpler.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1876 tests = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1877 num_tests = [0]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1878 for test in self._tests:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1879 def get():
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1880 num_tests[0] += 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1881 if getattr(test, 'should_reload', False):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1882 return self._loadtest(test, num_tests[0])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1883 return test
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1884 if not os.path.exists(test.path):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1885 result.addSkip(test, "Doesn't exist")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1886 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1887
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1888 if not (self._whitelist and test.bname in self._whitelist):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1889 if self._blacklist and test.bname in self._blacklist:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1890 result.addSkip(test, 'blacklisted')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1891 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1892
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1893 if self._retest and not os.path.exists(test.errpath):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1894 result.addIgnore(test, 'not retesting')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1895 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1896
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1897 if self._keywords:
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1898 with open(test.path, 'rb') as f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
1899 t = f.read().lower() + test.bname.lower()
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1900 ignored = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1901 for k in self._keywords.lower().split():
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1902 if k not in t:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1903 result.addIgnore(test, "doesn't match keyword")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1904 ignored = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1905 break
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1906
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1907 if ignored:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1908 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1909 for _ in xrange(self._runs_per_test):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1910 tests.append(get())
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1911
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1912 runtests = list(tests)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1913 done = queue.Queue()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1914 running = 0
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1915
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1916 channels = [""] * self._jobs
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1917
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1918 def job(test, result):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1919 for n, v in enumerate(channels):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1920 if not v:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1921 channel = n
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1922 break
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
1923 else:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1924 raise ValueError('Could not find output channel')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1925 channels[channel] = "=" + test.name[5:].split(".")[0]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1926 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1927 test(result)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1928 done.put(None)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1929 except KeyboardInterrupt:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1930 pass
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1931 except: # re-raises
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1932 done.put(('!', test, 'run-test raised an error, see traceback'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1933 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1934 finally:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1935 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1936 channels[channel] = ''
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1937 except IndexError:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1938 pass
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1939
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1940 def stat():
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1941 count = 0
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1942 while channels:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1943 d = '\n%03s ' % count
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1944 for n, v in enumerate(channels):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1945 if v:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1946 d += v[0]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1947 channels[n] = v[1:] or '.'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1948 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1949 d += ' '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1950 d += ' '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1951 with iolock:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1952 sys.stdout.write(d + ' ')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1953 sys.stdout.flush()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1954 for x in xrange(10):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1955 if channels:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1956 time.sleep(.1)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1957 count += 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1958
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1959 stoppedearly = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1960
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1961 if self._showchannels:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1962 statthread = threading.Thread(target=stat, name="stat")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1963 statthread.start()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1964
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1965 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1966 while tests or running:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1967 if not done.empty() or running == self._jobs or not tests:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1968 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1969 done.get(True, 1)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1970 running -= 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1971 if result and result.shouldStop:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1972 stoppedearly = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1973 break
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1974 except queue.Empty:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1975 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1976 if tests and not running == self._jobs:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1977 test = tests.pop(0)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1978 if self._loop:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1979 if getattr(test, 'should_reload', False):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1980 num_tests[0] += 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1981 tests.append(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1982 self._loadtest(test, num_tests[0]))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1983 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1984 tests.append(test)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1985 if self._jobs == 1:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1986 job(test, result)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1987 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1988 t = threading.Thread(target=job, name=test.name,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1989 args=(test, result))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1990 t.start()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1991 running += 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1992
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1993 # If we stop early we still need to wait on started tests to
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1994 # finish. Otherwise, there is a race between the test completing
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1995 # and the test's cleanup code running. This could result in the
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1996 # test reporting incorrect.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1997 if stoppedearly:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1998 while running:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
1999 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2000 done.get(True, 1)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2001 running -= 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2002 except queue.Empty:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2003 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2004 except KeyboardInterrupt:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2005 for test in runtests:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2006 test.abort()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2007
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2008 channels = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2009
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2010 return result
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2011
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2012 # Save the most recent 5 wall-clock runtimes of each test to a
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2013 # human-readable text file named .testtimes. Tests are sorted
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2014 # alphabetically, while times for each test are listed from oldest to
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2015 # newest.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2016
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2017 def loadtimes(outputdir):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2018 times = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2019 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2020 with open(os.path.join(outputdir, b'.testtimes-')) as fp:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2021 for line in fp:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2022 ts = line.split()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2023 times.append((ts[0], [float(t) for t in ts[1:]]))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2024 except IOError as err:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2025 if err.errno != errno.ENOENT:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2026 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2027 return times
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2028
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2029 def savetimes(outputdir, result):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2030 saved = dict(loadtimes(outputdir))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2031 maxruns = 5
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2032 skipped = set([str(t[0]) for t in result.skipped])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2033 for tdata in result.times:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2034 test, real = tdata[0], tdata[3]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2035 if test not in skipped:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2036 ts = saved.setdefault(test, [])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2037 ts.append(real)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2038 ts[:] = ts[-maxruns:]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2039
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2040 fd, tmpname = tempfile.mkstemp(prefix=b'.testtimes',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2041 dir=outputdir, text=True)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2042 with os.fdopen(fd, 'w') as fp:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2043 for name, ts in sorted(saved.items()):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2044 fp.write('%s %s\n' % (name, ' '.join(['%.3f' % (t,) for t in ts])))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2045 timepath = os.path.join(outputdir, b'.testtimes')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2046 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2047 os.unlink(timepath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2048 except OSError:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2049 pass
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2050 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2051 os.rename(tmpname, timepath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2052 except OSError:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2053 pass
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2055 class TextTestRunner(unittest.TextTestRunner):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2056 """Custom unittest test runner that uses appropriate settings."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2057
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2058 def __init__(self, runner, *args, **kwargs):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2059 super(TextTestRunner, self).__init__(*args, **kwargs)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2060
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2061 self._runner = runner
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2062
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2063 def listtests(self, test):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2064 result = TestResult(self._runner.options, self.stream,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2065 self.descriptions, 0)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2066 test = sorted(test, key=lambda t: t.name)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2067 for t in test:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2068 print(t.name)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2069 result.addSuccess(t)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2070
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2071 if self._runner.options.xunit:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2072 with open(self._runner.options.xunit, "wb") as xuf:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2073 self._writexunit(result, xuf)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2074
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2075 if self._runner.options.json:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2076 jsonpath = os.path.join(self._runner._outputdir, b'report.json')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2077 with open(jsonpath, 'w') as fp:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2078 self._writejson(result, fp)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2079
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2080 return result
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2081
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2082 def run(self, test):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2083 result = TestResult(self._runner.options, self.stream,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2084 self.descriptions, self.verbosity)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2085
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2086 test(result)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2087
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2088 failed = len(result.failures)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2089 skipped = len(result.skipped)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2090 ignored = len(result.ignored)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2091
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2092 with iolock:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2093 self.stream.writeln('')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2094
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2095 if not self._runner.options.noskips:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2096 for test, msg in result.skipped:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2097 formatted = 'Skipped %s: %s\n' % (test.name, msg)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2098 self.stream.write(highlightmsg(formatted, result.color))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2099 for test, msg in result.failures:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2100 formatted = 'Failed %s: %s\n' % (test.name, msg)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2101 self.stream.write(highlightmsg(formatted, result.color))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2102 for test, msg in result.errors:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2103 self.stream.writeln('Errored %s: %s' % (test.name, msg))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2104
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2105 if self._runner.options.xunit:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2106 with open(self._runner.options.xunit, "wb") as xuf:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2107 self._writexunit(result, xuf)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2108
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2109 if self._runner.options.json:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2110 jsonpath = os.path.join(self._runner._outputdir, b'report.json')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2111 with open(jsonpath, 'w') as fp:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2112 self._writejson(result, fp)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2113
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2114 self._runner._checkhglib('Tested')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2115
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2116 savetimes(self._runner._outputdir, result)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2117
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2118 if failed and self._runner.options.known_good_rev:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2119 self._bisecttests(t for t, m in result.failures)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2120 self.stream.writeln(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2121 '# Ran %d tests, %d skipped, %d failed.'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2122 % (result.testsRun, skipped + ignored, failed))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2123 if failed:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2124 self.stream.writeln('python hash seed: %s' %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2125 os.environ['PYTHONHASHSEED'])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2126 if self._runner.options.time:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2127 self.printtimes(result.times)
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2128
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2129 if self._runner.options.exceptions:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2130 exceptions = aggregateexceptions(
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2131 os.path.join(self._runner._outputdir, b'exceptions'))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2132 total = sum(exceptions.values())
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2133
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2134 self.stream.writeln('Exceptions Report:')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2135 self.stream.writeln('%d total from %d frames' %
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2136 (total, len(exceptions)))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2137 for (frame, line, exc), count in exceptions.most_common():
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2138 self.stream.writeln('%d\t%s: %s' % (count, frame, exc))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2139
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2140 self.stream.flush()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2141
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2142 return result
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2143
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2144 def _bisecttests(self, tests):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2145 bisectcmd = ['hg', 'bisect']
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2146 bisectrepo = self._runner.options.bisect_repo
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2147 if bisectrepo:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2148 bisectcmd.extend(['-R', os.path.abspath(bisectrepo)])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2149 def pread(args):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2150 env = os.environ.copy()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2151 env['HGPLAIN'] = '1'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2152 p = subprocess.Popen(args, stderr=subprocess.STDOUT,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2153 stdout=subprocess.PIPE, env=env)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2154 data = p.stdout.read()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2155 p.wait()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2156 return data
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2157 for test in tests:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2158 pread(bisectcmd + ['--reset']),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2159 pread(bisectcmd + ['--bad', '.'])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2160 pread(bisectcmd + ['--good', self._runner.options.known_good_rev])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2161 # TODO: we probably need to forward more options
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2162 # that alter hg's behavior inside the tests.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2163 opts = ''
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2164 withhg = self._runner.options.with_hg
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2165 if withhg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2166 opts += ' --with-hg=%s ' % shellquote(_strpath(withhg))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2167 rtc = '%s %s %s %s' % (sys.executable, sys.argv[0], opts,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2168 test)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2169 data = pread(bisectcmd + ['--command', rtc])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2170 m = re.search(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2171 (br'\nThe first (?P<goodbad>bad|good) revision '
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2172 br'is:\nchangeset: +\d+:(?P<node>[a-f0-9]+)\n.*\n'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2173 br'summary: +(?P<summary>[^\n]+)\n'),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2174 data, (re.MULTILINE | re.DOTALL))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2175 if m is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2176 self.stream.writeln(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2177 'Failed to identify failure point for %s' % test)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2178 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2179 dat = m.groupdict()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2180 verb = 'broken' if dat['goodbad'] == 'bad' else 'fixed'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2181 self.stream.writeln(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2182 '%s %s by %s (%s)' % (
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2183 test, verb, dat['node'], dat['summary']))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2184
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2185 def printtimes(self, times):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2186 # iolock held by run
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2187 self.stream.writeln('# Producing time report')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2188 times.sort(key=lambda t: (t[3]))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2189 cols = '%7.3f %7.3f %7.3f %7.3f %7.3f %s'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2190 self.stream.writeln('%-7s %-7s %-7s %-7s %-7s %s' %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2191 ('start', 'end', 'cuser', 'csys', 'real', 'Test'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2192 for tdata in times:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2193 test = tdata[0]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2194 cuser, csys, real, start, end = tdata[1:6]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2195 self.stream.writeln(cols % (start, end, cuser, csys, real, test))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2196
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2197 @staticmethod
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2198 def _writexunit(result, outf):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2199 # See http://llg.cubic.org/docs/junit/ for a reference.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2200 timesd = dict((t[0], t[3]) for t in result.times)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2201 doc = minidom.Document()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2202 s = doc.createElement('testsuite')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2203 s.setAttribute('name', 'run-tests')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2204 s.setAttribute('tests', str(result.testsRun))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2205 s.setAttribute('errors', "0") # TODO
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2206 s.setAttribute('failures', str(len(result.failures)))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2207 s.setAttribute('skipped', str(len(result.skipped) +
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2208 len(result.ignored)))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2209 doc.appendChild(s)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2210 for tc in result.successes:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2211 t = doc.createElement('testcase')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2212 t.setAttribute('name', tc.name)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2213 tctime = timesd.get(tc.name)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2214 if tctime is not None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2215 t.setAttribute('time', '%.3f' % tctime)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2216 s.appendChild(t)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2217 for tc, err in sorted(result.faildata.items()):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2218 t = doc.createElement('testcase')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2219 t.setAttribute('name', tc)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2220 tctime = timesd.get(tc)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2221 if tctime is not None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2222 t.setAttribute('time', '%.3f' % tctime)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2223 # createCDATASection expects a unicode or it will
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2224 # convert using default conversion rules, which will
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2225 # fail if string isn't ASCII.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2226 err = cdatasafe(err).decode('utf-8', 'replace')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2227 cd = doc.createCDATASection(err)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2228 # Use 'failure' here instead of 'error' to match errors = 0,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2229 # failures = len(result.failures) in the testsuite element.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2230 failelem = doc.createElement('failure')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2231 failelem.setAttribute('message', 'output changed')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2232 failelem.setAttribute('type', 'output-mismatch')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2233 failelem.appendChild(cd)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2234 t.appendChild(failelem)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2235 s.appendChild(t)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2236 for tc, message in result.skipped:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2237 # According to the schema, 'skipped' has no attributes. So store
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2238 # the skip message as a text node instead.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2239 t = doc.createElement('testcase')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2240 t.setAttribute('name', tc.name)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2241 binmessage = message.encode('utf-8')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2242 message = cdatasafe(binmessage).decode('utf-8', 'replace')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2243 cd = doc.createCDATASection(message)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2244 skipelem = doc.createElement('skipped')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2245 skipelem.appendChild(cd)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2246 t.appendChild(skipelem)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2247 s.appendChild(t)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2248 outf.write(doc.toprettyxml(indent=' ', encoding='utf-8'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2249
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2250 @staticmethod
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2251 def _writejson(result, outf):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2252 timesd = {}
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2253 for tdata in result.times:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2254 test = tdata[0]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2255 timesd[test] = tdata[1:]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2256
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2257 outcome = {}
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2258 groups = [('success', ((tc, None)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2259 for tc in result.successes)),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2260 ('failure', result.failures),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2261 ('skip', result.skipped)]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2262 for res, testcases in groups:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2263 for tc, __ in testcases:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2264 if tc.name in timesd:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2265 diff = result.faildata.get(tc.name, b'')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2266 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2267 diff = diff.decode('unicode_escape')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2268 except UnicodeDecodeError as e:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2269 diff = '%r decoding diff, sorry' % e
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2270 tres = {'result': res,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2271 'time': ('%0.3f' % timesd[tc.name][2]),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2272 'cuser': ('%0.3f' % timesd[tc.name][0]),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2273 'csys': ('%0.3f' % timesd[tc.name][1]),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2274 'start': ('%0.3f' % timesd[tc.name][3]),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2275 'end': ('%0.3f' % timesd[tc.name][4]),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2276 'diff': diff,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2277 }
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2278 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2279 # blacklisted test
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2280 tres = {'result': res}
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2281
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2282 outcome[tc.name] = tres
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2283 jsonout = json.dumps(outcome, sort_keys=True, indent=4,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2284 separators=(',', ': '))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2285 outf.writelines(("testreport =", jsonout))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2286
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2287 def sorttests(testdescs, shuffle=False):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2288 """Do an in-place sort of tests."""
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2289 if shuffle:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2290 random.shuffle(testdescs)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2291 return
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2292
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2293 # keywords for slow tests
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2294 slow = {b'svn': 10,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2295 b'cvs': 10,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2296 b'hghave': 10,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2297 b'largefiles-update': 10,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2298 b'run-tests': 10,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2299 b'corruption': 10,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2300 b'race': 10,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2301 b'i18n': 10,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2302 b'check': 100,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2303 b'gendoc': 100,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2304 b'contrib-perf': 200,
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2305 }
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2306 perf = {}
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2307
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2308 def sortkey(f):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2309 # run largest tests first, as they tend to take the longest
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2310 f = f['path']
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2311 try:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2312 return perf[f]
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2313 except KeyError:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2314 try:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2315 val = -os.stat(f).st_size
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2316 except OSError as e:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2317 if e.errno != errno.ENOENT:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2318 raise
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2319 perf[f] = -1e9 # file does not exist, tell early
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2320 return -1e9
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2321 for kw, mul in slow.items():
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2322 if kw in f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2323 val *= mul
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2324 if f.endswith(b'.py'):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2325 val /= 10.0
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2326 perf[f] = val / 1000.0
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2327 return perf[f]
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2328
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2329 testdescs.sort(key=sortkey)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2330
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2331 class TestRunner(object):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2332 """Holds context for executing tests.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2333
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2334 Tests rely on a lot of state. This object holds it for them.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2335 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2336
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2337 # Programs required to run tests.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2338 REQUIREDTOOLS = [
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2339 b'diff',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2340 b'grep',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2341 b'unzip',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2342 b'gunzip',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2343 b'bunzip2',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2344 b'sed',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2345 ]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2346
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2347 # Maps file extensions to test class.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2348 TESTTYPES = [
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2349 (b'.py', PythonTest),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2350 (b'.t', TTest),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2351 ]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2352
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2353 def __init__(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2354 self.options = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2355 self._hgroot = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2356 self._testdir = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2357 self._outputdir = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2358 self._hgtmp = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2359 self._installdir = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2360 self._bindir = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2361 self._tmpbinddir = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2362 self._pythondir = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2363 self._coveragefile = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2364 self._createdfiles = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2365 self._hgcommand = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2366 self._hgpath = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2367 self._portoffset = 0
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2368 self._ports = {}
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2369
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2370 def run(self, args, parser=None):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2371 """Run the test suite."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2372 oldmask = os.umask(0o22)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2373 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2374 parser = parser or getparser()
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2375 options = parseargs(args, parser)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2376 tests = [_bytespath(a) for a in options.tests]
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2377 if options.test_list is not None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2378 for listfile in options.test_list:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2379 with open(listfile, 'rb') as f:
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2380 tests.extend(t for t in f.read().splitlines() if t)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2381 self.options = options
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2382
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2383 self._checktools()
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2384 testdescs = self.findtests(tests)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2385 if options.profile_runner:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2386 import statprof
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2387 statprof.start()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2388 result = self._run(testdescs)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2389 if options.profile_runner:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2390 statprof.stop()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2391 statprof.display()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2392 return result
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2393
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2394 finally:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2395 os.umask(oldmask)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2396
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2397 def _run(self, testdescs):
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2398 sorttests(testdescs, shuffle=self.options.random)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2399
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2400 self._testdir = osenvironb[b'TESTDIR'] = getattr(
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2401 os, 'getcwdb', os.getcwd)()
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2402 # assume all tests in same folder for now
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2403 if testdescs:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2404 pathname = os.path.dirname(testdescs[0]['path'])
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2405 if pathname:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2406 osenvironb[b'TESTDIR'] = os.path.join(osenvironb[b'TESTDIR'],
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2407 pathname)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2408 if self.options.outputdir:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2409 self._outputdir = canonpath(_bytespath(self.options.outputdir))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2410 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2411 self._outputdir = self._testdir
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2412 if testdescs and pathname:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2413 self._outputdir = os.path.join(self._outputdir, pathname)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2414
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2415 if 'PYTHONHASHSEED' not in os.environ:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2416 # use a random python hash seed all the time
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2417 # we do the randomness ourself to know what seed is used
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2418 os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2419
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2420 if self.options.tmpdir:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2421 self.options.keep_tmpdir = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2422 tmpdir = _bytespath(self.options.tmpdir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2423 if os.path.exists(tmpdir):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2424 # Meaning of tmpdir has changed since 1.3: we used to create
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2425 # HGTMP inside tmpdir; now HGTMP is tmpdir. So fail if
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2426 # tmpdir already exists.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2427 print("error: temp dir %r already exists" % tmpdir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2428 return 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2429
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2430 os.makedirs(tmpdir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2431 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2432 d = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2433 if os.name == 'nt':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2434 # without this, we get the default temp dir location, but
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2435 # in all lowercase, which causes troubles with paths (issue3490)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2436 d = osenvironb.get(b'TMP', None)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2437 tmpdir = tempfile.mkdtemp(b'', b'hgtests.', d)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2438
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2439 self._hgtmp = osenvironb[b'HGTMP'] = (
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2440 os.path.realpath(tmpdir))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2441
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2442 if self.options.with_hg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2443 self._installdir = None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2444 whg = self.options.with_hg
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2445 self._bindir = os.path.dirname(os.path.realpath(whg))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2446 assert isinstance(self._bindir, bytes)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2447 self._hgcommand = os.path.basename(whg)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2448 self._tmpbindir = os.path.join(self._hgtmp, b'install', b'bin')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2449 os.makedirs(self._tmpbindir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2450
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2451 normbin = os.path.normpath(os.path.abspath(whg))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2452 normbin = normbin.replace(os.sep.encode('ascii'), b'/')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2453
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2454 # Other Python scripts in the test harness need to
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2455 # `import mercurial`. If `hg` is a Python script, we assume
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2456 # the Mercurial modules are relative to its path and tell the tests
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2457 # to load Python modules from its directory.
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2458 with open(whg, 'rb') as fh:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2459 initial = fh.read(1024)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2460
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2461 if re.match(b'#!.*python', initial):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2462 self._pythondir = self._bindir
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2463 # If it looks like our in-repo Rust binary, use the source root.
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2464 # This is a bit hacky. But rhg is still not supported outside the
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2465 # source directory. So until it is, do the simple thing.
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2466 elif re.search(b'/rust/target/[^/]+/hg', normbin):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2467 self._pythondir = os.path.dirname(self._testdir)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2468 # Fall back to the legacy behavior.
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2469 else:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2470 self._pythondir = self._bindir
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2471
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2472 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2473 self._installdir = os.path.join(self._hgtmp, b"install")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2474 self._bindir = os.path.join(self._installdir, b"bin")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2475 self._hgcommand = b'hg'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2476 self._tmpbindir = self._bindir
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2477 self._pythondir = os.path.join(self._installdir, b"lib", b"python")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2478
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2479 # set CHGHG, then replace "hg" command by "chg"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2480 chgbindir = self._bindir
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2481 if self.options.chg or self.options.with_chg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2482 osenvironb[b'CHGHG'] = os.path.join(self._bindir, self._hgcommand)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2483 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2484 osenvironb.pop(b'CHGHG', None) # drop flag for hghave
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2485 if self.options.chg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2486 self._hgcommand = b'chg'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2487 elif self.options.with_chg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2488 chgbindir = os.path.dirname(os.path.realpath(self.options.with_chg))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2489 self._hgcommand = os.path.basename(self.options.with_chg)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2490
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2491 osenvironb[b"BINDIR"] = self._bindir
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2492 osenvironb[b"PYTHON"] = PYTHON
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2493
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2494 if self.options.with_python3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2495 osenvironb[b'PYTHON3'] = self.options.with_python3
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2496
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2497 fileb = _bytespath(__file__)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2498 runtestdir = os.path.abspath(os.path.dirname(fileb))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2499 osenvironb[b'RUNTESTDIR'] = runtestdir
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2500 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2501 sepb = _bytespath(os.pathsep)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2502 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2503 sepb = os.pathsep
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2504 path = [self._bindir, runtestdir] + osenvironb[b"PATH"].split(sepb)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2505 if os.path.islink(__file__):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2506 # test helper will likely be at the end of the symlink
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2507 realfile = os.path.realpath(fileb)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2508 realdir = os.path.abspath(os.path.dirname(realfile))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2509 path.insert(2, realdir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2510 if chgbindir != self._bindir:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2511 path.insert(1, chgbindir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2512 if self._testdir != runtestdir:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2513 path = [self._testdir] + path
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2514 if self._tmpbindir != self._bindir:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2515 path = [self._tmpbindir] + path
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2516 osenvironb[b"PATH"] = sepb.join(path)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2517
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2518 # Include TESTDIR in PYTHONPATH so that out-of-tree extensions
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2519 # can run .../tests/run-tests.py test-foo where test-foo
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2520 # adds an extension to HGRC. Also include run-test.py directory to
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2521 # import modules like heredoctest.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2522 pypath = [self._pythondir, self._testdir, runtestdir]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2523 # We have to augment PYTHONPATH, rather than simply replacing
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2524 # it, in case external libraries are only available via current
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2525 # PYTHONPATH. (In particular, the Subversion bindings on OS X
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2526 # are in /opt/subversion.)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2527 oldpypath = osenvironb.get(IMPL_PATH)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2528 if oldpypath:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2529 pypath.append(oldpypath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2530 osenvironb[IMPL_PATH] = sepb.join(pypath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2531
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2532 if self.options.pure:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2533 os.environ["HGTEST_RUN_TESTS_PURE"] = "--pure"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2534 os.environ["HGMODULEPOLICY"] = "py"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2535
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2536 if self.options.allow_slow_tests:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2537 os.environ["HGTEST_SLOW"] = "slow"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2538 elif 'HGTEST_SLOW' in os.environ:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2539 del os.environ['HGTEST_SLOW']
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2540
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2541 self._coveragefile = os.path.join(self._testdir, b'.coverage')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2542
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2543 if self.options.exceptions:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2544 exceptionsdir = os.path.join(self._outputdir, b'exceptions')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2545 try:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2546 os.makedirs(exceptionsdir)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2547 except OSError as e:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2548 if e.errno != errno.EEXIST:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2549 raise
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2550
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2551 # Remove all existing exception reports.
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2552 for f in os.listdir(exceptionsdir):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2553 os.unlink(os.path.join(exceptionsdir, f))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2554
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2555 osenvironb[b'HGEXCEPTIONSDIR'] = exceptionsdir
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2556 logexceptions = os.path.join(self._testdir, b'logexceptions.py')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2557 self.options.extra_config_opt.append(
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2558 'extensions.logexceptions=%s' % logexceptions.decode('utf-8'))
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2559
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2560 vlog("# Using TESTDIR", self._testdir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2561 vlog("# Using RUNTESTDIR", osenvironb[b'RUNTESTDIR'])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2562 vlog("# Using HGTMP", self._hgtmp)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2563 vlog("# Using PATH", os.environ["PATH"])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2564 vlog("# Using", IMPL_PATH, osenvironb[IMPL_PATH])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2565 vlog("# Writing to directory", self._outputdir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2566
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2567 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2568 return self._runtests(testdescs) or 0
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2569 finally:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2570 time.sleep(.1)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2571 self._cleanup()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2572
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2573 def findtests(self, args):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2574 """Finds possible test files from arguments.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2575
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2576 If you wish to inject custom tests into the test harness, this would
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2577 be a good function to monkeypatch or override in a derived class.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2578 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2579 if not args:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2580 if self.options.changed:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2581 proc = Popen4('hg st --rev "%s" -man0 .' %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2582 self.options.changed, None, 0)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2583 stdout, stderr = proc.communicate()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2584 args = stdout.strip(b'\0').split(b'\0')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2585 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2586 args = os.listdir(b'.')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2587
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2588 expanded_args = []
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2589 for arg in args:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2590 if os.path.isdir(arg):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2591 if not arg.endswith(b'/'):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2592 arg += b'/'
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2593 expanded_args.extend([arg + a for a in os.listdir(arg)])
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2594 else:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2595 expanded_args.append(arg)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2596 args = expanded_args
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2597
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2598 tests = []
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2599 for t in args:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2600 if not (os.path.basename(t).startswith(b'test-')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2601 and (t.endswith(b'.py') or t.endswith(b'.t'))):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2602 continue
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2603 if t.endswith(b'.t'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2604 # .t file may contain multiple test cases
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2605 cases = sorted(parsettestcases(t))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2606 if cases:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2607 tests += [{'path': t, 'case': c} for c in sorted(cases)]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2608 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2609 tests.append({'path': t})
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2610 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2611 tests.append({'path': t})
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2612 return tests
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2613
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2614 def _runtests(self, testdescs):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2615 def _reloadtest(test, i):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2616 # convert a test back to its description dict
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2617 desc = {'path': test.path}
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2618 case = getattr(test, '_case', None)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2619 if case:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2620 desc['case'] = case
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2621 return self._gettest(desc, i)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2622
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2623 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2624 if self.options.restart:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2625 orig = list(testdescs)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2626 while testdescs:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2627 desc = testdescs[0]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2628 # desc['path'] is a relative path
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2629 if 'case' in desc:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2630 errpath = b'%s.%s.err' % (desc['path'], desc['case'])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2631 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2632 errpath = b'%s.err' % desc['path']
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2633 errpath = os.path.join(self._outputdir, errpath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2634 if os.path.exists(errpath):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2635 break
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2636 testdescs.pop(0)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2637 if not testdescs:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2638 print("running all tests")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2639 testdescs = orig
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2640
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2641 tests = [self._gettest(d, i) for i, d in enumerate(testdescs)]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2642
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2643 failed = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2644 kws = self.options.keywords
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2645 if kws is not None and PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2646 kws = kws.encode('utf-8')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2647
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2648 suite = TestSuite(self._testdir,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2649 jobs=self.options.jobs,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2650 whitelist=self.options.whitelisted,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2651 blacklist=self.options.blacklist,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2652 retest=self.options.retest,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2653 keywords=kws,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2654 loop=self.options.loop,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2655 runs_per_test=self.options.runs_per_test,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2656 showchannels=self.options.showchannels,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2657 tests=tests, loadtest=_reloadtest)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2658 verbosity = 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2659 if self.options.verbose:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2660 verbosity = 2
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2661 runner = TextTestRunner(self, verbosity=verbosity)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2662
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2663 if self.options.list_tests:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2664 result = runner.listtests(suite)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2665 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2666 if self._installdir:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2667 self._installhg()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2668 self._checkhglib("Testing")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2669 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2670 self._usecorrectpython()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2671 if self.options.chg:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2672 assert self._installdir
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2673 self._installchg()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2674
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2675 result = runner.run(suite)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2676
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2677 if result.failures:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2678 failed = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2679
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2680 if self.options.anycoverage:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2681 self._outputcoverage()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2682 except KeyboardInterrupt:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2683 failed = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2684 print("\ninterrupted!")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2685
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2686 if failed:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2687 return 1
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2688
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2689 def _getport(self, count):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2690 port = self._ports.get(count) # do we have a cached entry?
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2691 if port is None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2692 portneeded = 3
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2693 # above 100 tries we just give up and let test reports failure
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2694 for tries in xrange(100):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2695 allfree = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2696 port = self.options.port + self._portoffset
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2697 for idx in xrange(portneeded):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2698 if not checkportisavailable(port + idx):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2699 allfree = False
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2700 break
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2701 self._portoffset += portneeded
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2702 if allfree:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2703 break
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2704 self._ports[count] = port
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2705 return port
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2706
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2707 def _gettest(self, testdesc, count):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2708 """Obtain a Test by looking at its filename.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2709
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2710 Returns a Test instance. The Test may not be runnable if it doesn't
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2711 map to a known type.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2712 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2713 path = testdesc['path']
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2714 lctest = path.lower()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2715 testcls = Test
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2716
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2717 for ext, cls in self.TESTTYPES:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2718 if lctest.endswith(ext):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2719 testcls = cls
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2720 break
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2721
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2722 refpath = os.path.join(self._testdir, path)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2723 tmpdir = os.path.join(self._hgtmp, b'child%d' % count)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2724
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2725 # extra keyword parameters. 'case' is used by .t tests
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2726 kwds = dict((k, testdesc[k]) for k in ['case'] if k in testdesc)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2727
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2728 t = testcls(refpath, self._outputdir, tmpdir,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2729 keeptmpdir=self.options.keep_tmpdir,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2730 debug=self.options.debug,
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2731 first=self.options.first,
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2732 timeout=self.options.timeout,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2733 startport=self._getport(count),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2734 extraconfigopts=self.options.extra_config_opt,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2735 py3kwarnings=self.options.py3k_warnings,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2736 shell=self.options.shell,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2737 hgcommand=self._hgcommand,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2738 usechg=bool(self.options.with_chg or self.options.chg),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2739 useipv6=useipv6, **kwds)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2740 t.should_reload = True
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2741 return t
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2742
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2743 def _cleanup(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2744 """Clean up state from this test invocation."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2745 if self.options.keep_tmpdir:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2746 return
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2747
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2748 vlog("# Cleaning up HGTMP", self._hgtmp)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2749 shutil.rmtree(self._hgtmp, True)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2750 for f in self._createdfiles:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2751 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2752 os.remove(f)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2753 except OSError:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2754 pass
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2755
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2756 def _usecorrectpython(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2757 """Configure the environment to use the appropriate Python in tests."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2758 # Tests must use the same interpreter as us or bad things will happen.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2759 pyexename = sys.platform == 'win32' and b'python.exe' or b'python'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2760 if getattr(os, 'symlink', None):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2761 vlog("# Making python executable in test path a symlink to '%s'" %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2762 sys.executable)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2763 mypython = os.path.join(self._tmpbindir, pyexename)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2764 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2765 if os.readlink(mypython) == sys.executable:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2766 return
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2767 os.unlink(mypython)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2768 except OSError as err:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2769 if err.errno != errno.ENOENT:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2770 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2771 if self._findprogram(pyexename) != sys.executable:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2772 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2773 os.symlink(sys.executable, mypython)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2774 self._createdfiles.append(mypython)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2775 except OSError as err:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2776 # child processes may race, which is harmless
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2777 if err.errno != errno.EEXIST:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2778 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2779 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2780 exedir, exename = os.path.split(sys.executable)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2781 vlog("# Modifying search path to find %s as %s in '%s'" %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2782 (exename, pyexename, exedir))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2783 path = os.environ['PATH'].split(os.pathsep)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2784 while exedir in path:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2785 path.remove(exedir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2786 os.environ['PATH'] = os.pathsep.join([exedir] + path)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2787 if not self._findprogram(pyexename):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2788 print("WARNING: Cannot find %s in search path" % pyexename)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2789
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2790 def _installhg(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2791 """Install hg into the test environment.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2792
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2793 This will also configure hg with the appropriate testing settings.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2794 """
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2795 vlog("# Performing temporary installation of HG")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2796 installerrs = os.path.join(self._hgtmp, b"install.err")
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2797 compiler = ''
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2798 if self.options.compiler:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2799 compiler = '--compiler ' + self.options.compiler
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2800 if self.options.pure:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2801 pure = b"--pure"
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2802 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2803 pure = b""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2804
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2805 # Run installer in hg root
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2806 script = os.path.realpath(sys.argv[0])
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2807 exe = sys.executable
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2808 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2809 compiler = _bytespath(compiler)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2810 script = _bytespath(script)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2811 exe = _bytespath(exe)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2812 hgroot = os.path.dirname(os.path.dirname(script))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2813 self._hgroot = hgroot
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2814 os.chdir(hgroot)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2815 nohome = b'--home=""'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2816 if os.name == 'nt':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2817 # The --home="" trick works only on OS where os.sep == '/'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2818 # because of a distutils convert_path() fast-path. Avoid it at
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2819 # least on Windows for now, deal with .pydistutils.cfg bugs
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2820 # when they happen.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2821 nohome = b''
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2822 cmd = (b'%(exe)s setup.py %(pure)s clean --all'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2823 b' build %(compiler)s --build-base="%(base)s"'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2824 b' install --force --prefix="%(prefix)s"'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2825 b' --install-lib="%(libdir)s"'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2826 b' --install-scripts="%(bindir)s" %(nohome)s >%(logfile)s 2>&1'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2827 % {b'exe': exe, b'pure': pure,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2828 b'compiler': compiler,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2829 b'base': os.path.join(self._hgtmp, b"build"),
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2830 b'prefix': self._installdir, b'libdir': self._pythondir,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2831 b'bindir': self._bindir,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2832 b'nohome': nohome, b'logfile': installerrs})
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2833
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2834 # setuptools requires install directories to exist.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2835 def makedirs(p):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2836 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2837 os.makedirs(p)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2838 except OSError as e:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2839 if e.errno != errno.EEXIST:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2840 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2841 makedirs(self._pythondir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2842 makedirs(self._bindir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2843
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2844 vlog("# Running", cmd)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2845 if os.system(cmd) == 0:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2846 if not self.options.verbose:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2847 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2848 os.remove(installerrs)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2849 except OSError as e:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2850 if e.errno != errno.ENOENT:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2851 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2852 else:
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2853 with open(installerrs, 'rb') as f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2854 for line in f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2855 if PYTHON3:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2856 sys.stdout.buffer.write(line)
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2857 else:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2858 sys.stdout.write(line)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2859 sys.exit(1)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2860 os.chdir(self._testdir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2861
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2862 self._usecorrectpython()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2863
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2864 if self.options.py3k_warnings and not self.options.anycoverage:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2865 vlog("# Updating hg command to enable Py3k Warnings switch")
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2866 with open(os.path.join(self._bindir, 'hg'), 'rb') as f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2867 lines = [line.rstrip() for line in f]
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2868 lines[0] += ' -3'
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2869 with open(os.path.join(self._bindir, 'hg'), 'wb') as f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2870 for line in lines:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2871 f.write(line + '\n')
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2872
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2873 hgbat = os.path.join(self._bindir, b'hg.bat')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2874 if os.path.isfile(hgbat):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2875 # hg.bat expects to be put in bin/scripts while run-tests.py
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2876 # installation layout put it in bin/ directly. Fix it
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2877 with open(hgbat, 'rb') as f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2878 data = f.read()
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2879 if b'"%~dp0..\python" "%~dp0hg" %*' in data:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2880 data = data.replace(b'"%~dp0..\python" "%~dp0hg" %*',
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2881 b'"%~dp0python" "%~dp0hg" %*')
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2882 with open(hgbat, 'wb') as f:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
2883 f.write(data)
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2884 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2885 print('WARNING: cannot fix hg.bat reference to python.exe')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2886
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2887 if self.options.anycoverage:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2888 custom = os.path.join(self._testdir, 'sitecustomize.py')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2889 target = os.path.join(self._pythondir, 'sitecustomize.py')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2890 vlog('# Installing coverage trigger to %s' % target)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2891 shutil.copyfile(custom, target)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2892 rc = os.path.join(self._testdir, '.coveragerc')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2893 vlog('# Installing coverage rc to %s' % rc)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2894 os.environ['COVERAGE_PROCESS_START'] = rc
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2895 covdir = os.path.join(self._installdir, '..', 'coverage')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2896 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2897 os.mkdir(covdir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2898 except OSError as e:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2899 if e.errno != errno.EEXIST:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2900 raise
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2901
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2902 os.environ['COVERAGE_DIR'] = covdir
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2903
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2904 def _checkhglib(self, verb):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2905 """Ensure that the 'mercurial' package imported by python is
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2906 the one we expect it to be. If not, print a warning to stderr."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2907 if ((self._bindir == self._pythondir) and
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2908 (self._bindir != self._tmpbindir)):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2909 # The pythondir has been inferred from --with-hg flag.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2910 # We cannot expect anything sensible here.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2911 return
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2912 expecthg = os.path.join(self._pythondir, b'mercurial')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2913 actualhg = self._gethgpath()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2914 if os.path.abspath(actualhg) != os.path.abspath(expecthg):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2915 sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2916 ' (expected %s)\n'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2917 % (verb, actualhg, expecthg))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2918 def _gethgpath(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2919 """Return the path to the mercurial package that is actually found by
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2920 the current Python interpreter."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2921 if self._hgpath is not None:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2922 return self._hgpath
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2923
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2924 cmd = b'%s -c "import mercurial; print (mercurial.__path__[0])"'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2925 cmd = cmd % PYTHON
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2926 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2927 cmd = _strpath(cmd)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2928 pipe = os.popen(cmd)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2929 try:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2930 self._hgpath = _bytespath(pipe.read().strip())
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2931 finally:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2932 pipe.close()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2933
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2934 return self._hgpath
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2935
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2936 def _installchg(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2937 """Install chg into the test environment"""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2938 vlog('# Performing temporary installation of CHG')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2939 assert os.path.dirname(self._bindir) == self._installdir
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2940 assert self._hgroot, 'must be called after _installhg()'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2941 cmd = (b'"%(make)s" clean install PREFIX="%(prefix)s"'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2942 % {b'make': 'make', # TODO: switch by option or environment?
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2943 b'prefix': self._installdir})
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2944 cwd = os.path.join(self._hgroot, b'contrib', b'chg')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2945 vlog("# Running", cmd)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2946 proc = subprocess.Popen(cmd, shell=True, cwd=cwd,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2947 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2948 stderr=subprocess.STDOUT)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2949 out, _err = proc.communicate()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2950 if proc.returncode != 0:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2951 if PYTHON3:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2952 sys.stdout.buffer.write(out)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2953 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2954 sys.stdout.write(out)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2955 sys.exit(1)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2956
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2957 def _outputcoverage(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2958 """Produce code coverage output."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2959 import coverage
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2960 coverage = coverage.coverage
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2961
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2962 vlog('# Producing coverage report')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2963 # chdir is the easiest way to get short, relative paths in the
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2964 # output.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2965 os.chdir(self._hgroot)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2966 covdir = os.path.join(self._installdir, '..', 'coverage')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2967 cov = coverage(data_file=os.path.join(covdir, 'cov'))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2968
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2969 # Map install directory paths back to source directory.
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2970 cov.config.paths['srcdir'] = ['.', self._pythondir]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2971
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2972 cov.combine()
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2973
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2974 omit = [os.path.join(x, '*') for x in [self._bindir, self._testdir]]
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2975 cov.report(ignore_errors=True, omit=omit)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2976
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2977 if self.options.htmlcov:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2978 htmldir = os.path.join(self._outputdir, 'htmlcov')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2979 cov.html_report(directory=htmldir, omit=omit)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2980 if self.options.annotate:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2981 adir = os.path.join(self._outputdir, 'annotated')
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2982 if not os.path.isdir(adir):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2983 os.mkdir(adir)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2984 cov.annotate(directory=adir, omit=omit)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2985
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2986 def _findprogram(self, program):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2987 """Search PATH for a executable program"""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2988 dpb = _bytespath(os.defpath)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2989 sepb = _bytespath(os.pathsep)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2990 for p in osenvironb.get(b'PATH', dpb).split(sepb):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2991 name = os.path.join(p, program)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2992 if os.name == 'nt' or os.access(name, os.X_OK):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2993 return name
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2994 return None
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2995
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2996 def _checktools(self):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2997 """Ensure tools required to run tests are present."""
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2998 for p in self.REQUIREDTOOLS:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
2999 if os.name == 'nt' and not p.endswith('.exe'):
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3000 p += '.exe'
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3001 found = self._findprogram(p)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3002 if found:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3003 vlog("# Found prerequisite", p, "at", found)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3004 else:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3005 print("WARNING: Did not find prerequisite tool: %s " %
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3006 p.decode("utf-8"))
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3007
1106
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3008 def aggregateexceptions(path):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3009 exceptions = collections.Counter()
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3010
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3011 for f in os.listdir(path):
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3012 with open(os.path.join(path, f), 'rb') as fh:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3013 data = fh.read().split(b'\0')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3014 if len(data) != 4:
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3015 continue
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3016
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3017 exc, mainframe, hgframe, hgline = data
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3018 exc = exc.decode('utf-8')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3019 mainframe = mainframe.decode('utf-8')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3020 hgframe = hgframe.decode('utf-8')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3021 hgline = hgline.decode('utf-8')
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3022 exceptions[(hgframe, hgline, exc)] += 1
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3023
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3024 return exceptions
cca56bbea143 tests: copy hg test infra from hg repo @5cfdf6137af8
Tony Tung <ttung@chanzuckerberg.com <mailto:ttung@chanzuckerberg.com>>
parents: 1054
diff changeset
3025
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3026 if __name__ == '__main__':
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3027 runner = TestRunner()
492
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
3028
6d010ec28d7d tests: upgrade run-tests.py
David M. Carr <david@carrclan.us>
parents: 32
diff changeset
3029 try:
1054
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3030 import msvcrt
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3031 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3032 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3033 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3034 except ImportError:
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3035 pass
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3036
e085b381e8e2 tests: update run-tests.py
Kevin Bullock <kbullock@ringworld.org>
parents: 673
diff changeset
3037 sys.exit(runner.run(sys.argv[1:]))