Mercurial > hg
comparison tests/run-tests.py @ 39253:c496e8c14b9e
tests: add support for emitting trace events to run-tests
Right now this is pretty basic, but it's a start.
Differential Revision: https://phab.mercurial-scm.org/D4343
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 21 Aug 2018 15:23:01 -0400 |
parents | 1f987f7c832b |
children | a235ee4cfc1c |
comparison
equal
deleted
inserted
replaced
39252:9a81f126f9fa | 39253:c496e8c14b9e |
---|---|
62 import sysconfig | 62 import sysconfig |
63 import tempfile | 63 import tempfile |
64 import threading | 64 import threading |
65 import time | 65 import time |
66 import unittest | 66 import unittest |
67 import uuid | |
67 import xml.dom.minidom as minidom | 68 import xml.dom.minidom as minidom |
68 | 69 |
69 try: | 70 try: |
70 import Queue as queue | 71 import Queue as queue |
71 except ImportError: | 72 except ImportError: |
1068 env["HGUSER"] = "test" | 1069 env["HGUSER"] = "test" |
1069 env["HGENCODING"] = "ascii" | 1070 env["HGENCODING"] = "ascii" |
1070 env["HGENCODINGMODE"] = "strict" | 1071 env["HGENCODINGMODE"] = "strict" |
1071 env["HGHOSTNAME"] = "test-hostname" | 1072 env["HGHOSTNAME"] = "test-hostname" |
1072 env['HGIPV6'] = str(int(self._useipv6)) | 1073 env['HGIPV6'] = str(int(self._useipv6)) |
1074 if 'HGCATAPULTSERVERPIPE' not in env: | |
1075 env['HGCATAPULTSERVERPIPE'] = '/dev/null' | |
1073 | 1076 |
1074 extraextensions = [] | 1077 extraextensions = [] |
1075 for opt in self._extraconfigopts: | 1078 for opt in self._extraconfigopts: |
1076 section, key = opt.encode('utf-8').split(b'.', 1) | 1079 section, key = opt.encode('utf-8').split(b'.', 1) |
1077 if section != 'extensions': | 1080 if section != 'extensions': |
1342 def addsalt(line, inpython): | 1345 def addsalt(line, inpython): |
1343 if inpython: | 1346 if inpython: |
1344 script.append(b'%s %d 0\n' % (salt, line)) | 1347 script.append(b'%s %d 0\n' % (salt, line)) |
1345 else: | 1348 else: |
1346 script.append(b'echo %s %d $?\n' % (salt, line)) | 1349 script.append(b'echo %s %d $?\n' % (salt, line)) |
1350 active = [] | |
1351 session = str(uuid.uuid4()) | |
1352 if PYTHON3: | |
1353 session = session.encode('ascii') | |
1354 def toggletrace(cmd): | |
1355 quoted = shellquote(cmd.strip()).replace(b'\\', b'\\\\') | |
1356 if active: | |
1357 script.append( | |
1358 b'echo END %s %s >> "$HGCATAPULTSERVERPIPE"\n' % ( | |
1359 session, active[0])) | |
1360 script.append( | |
1361 b'echo START %s %s >> "$HGCATAPULTSERVERPIPE"\n' % ( | |
1362 session, quoted)) | |
1363 active[0:] = [quoted] | |
1347 | 1364 |
1348 script = [] | 1365 script = [] |
1349 | 1366 |
1350 # After we run the shell script, we re-unify the script output | 1367 # After we run the shell script, we re-unify the script output |
1351 # with non-active parts of the source, with synchronization by our | 1368 # with non-active parts of the source, with synchronization by our |
1369 script.append(b'set -x\n') | 1386 script.append(b'set -x\n') |
1370 if self._hgcommand != b'hg': | 1387 if self._hgcommand != b'hg': |
1371 script.append(b'alias hg="%s"\n' % self._hgcommand) | 1388 script.append(b'alias hg="%s"\n' % self._hgcommand) |
1372 if os.getenv('MSYSTEM'): | 1389 if os.getenv('MSYSTEM'): |
1373 script.append(b'alias pwd="pwd -W"\n') | 1390 script.append(b'alias pwd="pwd -W"\n') |
1391 | |
1392 if os.getenv('HGCATAPULTSERVERPIPE'): | |
1393 # Kludge: use a while loop to keep the pipe from getting | |
1394 # closed by our echo commands. The still-running file gets | |
1395 # reaped at the end of the script, which causes the while | |
1396 # loop to exit and closes the pipe. Sigh. | |
1397 script.append( | |
1398 b'rtendtracing() {\n' | |
1399 b' echo END %(session)s %(name)s >> $HGCATAPULTSERVERPIPE\n' | |
1400 b' rm -f "$TESTTMP/.still-running"\n' | |
1401 b'}\n' | |
1402 b'trap "rtendtracing" 0\n' | |
1403 b'touch "$TESTTMP/.still-running"\n' | |
1404 b'while [ -f "$TESTTMP/.still-running" ]; do sleep 1; done ' | |
1405 b'> $HGCATAPULTSERVERPIPE &\n' | |
1406 b'HGCATAPULTSESSION=%(session)s ; export HGCATAPULTSESSION\n' | |
1407 b'echo START %(session)s %(name)s >> $HGCATAPULTSERVERPIPE\n' | |
1408 % { | |
1409 'name': self.name, | |
1410 'session': session, | |
1411 } | |
1412 ) | |
1413 | |
1374 if self._case: | 1414 if self._case: |
1375 casestr = b'#'.join(self._case) | 1415 casestr = b'#'.join(self._case) |
1376 if isinstance(self._case, str): | 1416 if isinstance(self._case, str): |
1377 quoted = shellquote(casestr) | 1417 quoted = shellquote(casestr) |
1378 else: | 1418 else: |
1434 inpython = False | 1474 inpython = False |
1435 after.setdefault(pos, []).append(l) | 1475 after.setdefault(pos, []).append(l) |
1436 prepos = pos | 1476 prepos = pos |
1437 pos = n | 1477 pos = n |
1438 addsalt(n, False) | 1478 addsalt(n, False) |
1439 cmd = l[4:].split() | 1479 rawcmd = l[4:] |
1480 cmd = rawcmd.split() | |
1481 toggletrace(rawcmd) | |
1440 if len(cmd) == 2 and cmd[0] == b'cd': | 1482 if len(cmd) == 2 and cmd[0] == b'cd': |
1441 l = b' $ cd %s || exit 1\n' % cmd[1] | 1483 l = b' $ cd %s || exit 1\n' % cmd[1] |
1442 script.append(l[4:]) | 1484 script.append(rawcmd) |
1443 elif l.startswith(b' > '): # continuations | 1485 elif l.startswith(b' > '): # continuations |
1444 after.setdefault(prepos, []).append(l) | 1486 after.setdefault(prepos, []).append(l) |
1445 script.append(l[4:]) | 1487 script.append(l[4:]) |
1446 elif l.startswith(b' '): # results | 1488 elif l.startswith(b' '): # results |
1447 # Queue up a list of expected results. | 1489 # Queue up a list of expected results. |
1456 if inpython: | 1498 if inpython: |
1457 script.append(b'EOF\n') | 1499 script.append(b'EOF\n') |
1458 if skipping is not None: | 1500 if skipping is not None: |
1459 after.setdefault(pos, []).append(' !!! missing #endif\n') | 1501 after.setdefault(pos, []).append(' !!! missing #endif\n') |
1460 addsalt(n + 1, False) | 1502 addsalt(n + 1, False) |
1461 | |
1462 return salt, script, after, expected | 1503 return salt, script, after, expected |
1463 | 1504 |
1464 def _processoutput(self, exitcode, output, salt, after, expected): | 1505 def _processoutput(self, exitcode, output, salt, after, expected): |
1465 # Merge the script output back into a unified test. | 1506 # Merge the script output back into a unified test. |
1466 warnonly = 1 # 1: not yet; 2: yes; 3: for sure not | 1507 warnonly = 1 # 1: not yet; 2: yes; 3: for sure not |