Mercurial > hg
comparison tests/run-tests.py @ 32717:e5680cb1414f
run-tests: write test times to output dir
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Wed, 07 Jun 2017 20:32:11 -0700 |
parents | 2146f01a2577 |
children | 232875623c27 |
comparison
equal
deleted
inserted
replaced
32716:2146f01a2577 | 32717:e5680cb1414f |
---|---|
1864 # Save the most recent 5 wall-clock runtimes of each test to a | 1864 # Save the most recent 5 wall-clock runtimes of each test to a |
1865 # human-readable text file named .testtimes. Tests are sorted | 1865 # human-readable text file named .testtimes. Tests are sorted |
1866 # alphabetically, while times for each test are listed from oldest to | 1866 # alphabetically, while times for each test are listed from oldest to |
1867 # newest. | 1867 # newest. |
1868 | 1868 |
1869 def loadtimes(testdir): | 1869 def loadtimes(outputdir): |
1870 times = [] | 1870 times = [] |
1871 try: | 1871 try: |
1872 with open(os.path.join(testdir, b'.testtimes-')) as fp: | 1872 with open(os.path.join(outputdir, b'.testtimes-')) as fp: |
1873 for line in fp: | 1873 for line in fp: |
1874 ts = line.split() | 1874 ts = line.split() |
1875 times.append((ts[0], [float(t) for t in ts[1:]])) | 1875 times.append((ts[0], [float(t) for t in ts[1:]])) |
1876 except IOError as err: | 1876 except IOError as err: |
1877 if err.errno != errno.ENOENT: | 1877 if err.errno != errno.ENOENT: |
1878 raise | 1878 raise |
1879 return times | 1879 return times |
1880 | 1880 |
1881 def savetimes(testdir, result): | 1881 def savetimes(outputdir, result): |
1882 saved = dict(loadtimes(testdir)) | 1882 saved = dict(loadtimes(outputdir)) |
1883 maxruns = 5 | 1883 maxruns = 5 |
1884 skipped = set([str(t[0]) for t in result.skipped]) | 1884 skipped = set([str(t[0]) for t in result.skipped]) |
1885 for tdata in result.times: | 1885 for tdata in result.times: |
1886 test, real = tdata[0], tdata[3] | 1886 test, real = tdata[0], tdata[3] |
1887 if test not in skipped: | 1887 if test not in skipped: |
1888 ts = saved.setdefault(test, []) | 1888 ts = saved.setdefault(test, []) |
1889 ts.append(real) | 1889 ts.append(real) |
1890 ts[:] = ts[-maxruns:] | 1890 ts[:] = ts[-maxruns:] |
1891 | 1891 |
1892 fd, tmpname = tempfile.mkstemp(prefix=b'.testtimes', | 1892 fd, tmpname = tempfile.mkstemp(prefix=b'.testtimes', |
1893 dir=testdir, text=True) | 1893 dir=outputdir, text=True) |
1894 with os.fdopen(fd, 'w') as fp: | 1894 with os.fdopen(fd, 'w') as fp: |
1895 for name, ts in sorted(saved.items()): | 1895 for name, ts in sorted(saved.items()): |
1896 fp.write('%s %s\n' % (name, ' '.join(['%.3f' % (t,) for t in ts]))) | 1896 fp.write('%s %s\n' % (name, ' '.join(['%.3f' % (t,) for t in ts]))) |
1897 timepath = os.path.join(testdir, b'.testtimes') | 1897 timepath = os.path.join(outputdir, b'.testtimes') |
1898 try: | 1898 try: |
1899 os.unlink(timepath) | 1899 os.unlink(timepath) |
1900 except OSError: | 1900 except OSError: |
1901 pass | 1901 pass |
1902 try: | 1902 try: |
1964 with open(jsonpath, 'w') as fp: | 1964 with open(jsonpath, 'w') as fp: |
1965 self._writejson(result, fp) | 1965 self._writejson(result, fp) |
1966 | 1966 |
1967 self._runner._checkhglib('Tested') | 1967 self._runner._checkhglib('Tested') |
1968 | 1968 |
1969 savetimes(self._runner._testdir, result) | 1969 savetimes(self._runner._outputdir, result) |
1970 | 1970 |
1971 if failed and self._runner.options.known_good_rev: | 1971 if failed and self._runner.options.known_good_rev: |
1972 def nooutput(args): | 1972 def nooutput(args): |
1973 p = subprocess.Popen(args, stderr=subprocess.STDOUT, | 1973 p = subprocess.Popen(args, stderr=subprocess.STDOUT, |
1974 stdout=subprocess.PIPE) | 1974 stdout=subprocess.PIPE) |