summaryrefslogtreecommitdiffstats
path: root/tools/purify/test_runner.py
blob: 78ab615266a12adf1ee7fee2a8c742c59e41fa4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/env python
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# test_runner

import optparse
import os
import re
import subprocess
import sys

import google.logging_utils
import google.path_utils

import common


def GetAllTests(exe):
  cmd = [exe, "--gtest_list_tests"]
  p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
  line = p.stdout.readline().rstrip()
  test = line
  tests = []
  while line:
    line = p.stdout.readline().rstrip()
    if line.startswith(' '):
      tests.append(test + line.lstrip())
    else:
      test = line
  return tests


def RunTestsSingly(exe, tests):
  for test in tests:
    filter = test
    if len(sys.argv) > 2:
      filter = filter + ":" + sys.argv[2]
    cmd = [exe, "--gtest_filter=" + filter]
    common.RunSubprocess(cmd)


def main():
  exe = sys.argv[1]
  all_tests = GetAllTests(exe)
  RunTestsSingly(exe, all_tests)


if __name__ == "__main__":
  main()