• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2011 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import glob
6import os
7import re
8import sys
9import subprocess
10
11# TODO(timurrrr): we may use it on POSIX too to avoid code duplication once we
12# support layout_tests, remove Dr. Memory specific code and verify it works
13# on a "clean" Mac.
14
15testcase_name = None
16for arg in sys.argv:
17  m = re.match("\-\-gtest_filter=(.*)", arg)
18  if m:
19    assert testcase_name is None
20    testcase_name = m.groups()[0]
21
22# arg #0 is the path to this python script
23cmd_to_run = sys.argv[1:]
24
25# TODO(timurrrr): this is Dr. Memory-specific
26# Usually, we pass "-logdir" "foo\bar\spam path" args to Dr. Memory.
27# To group reports per UI test, we want to put the reports for each test into a
28# separate directory. This code can be simplified when we have
29# http://code.google.com/p/drmemory/issues/detail?id=684 fixed.
30logdir_idx = cmd_to_run.index("-logdir")
31old_logdir = cmd_to_run[logdir_idx + 1]
32
33wrapper_pid = str(os.getpid())
34
35# On Windows, there is a chance of PID collision. We avoid it by appending the
36# number of entries in the logdir at the end of wrapper_pid.
37# This number is monotonic and we can't have two simultaneously running wrappers
38# with the same PID.
39wrapper_pid += "_%d" % len(glob.glob(old_logdir + "\\*"))
40
41cmd_to_run[logdir_idx + 1] += "\\testcase.%s.logs" % wrapper_pid
42os.makedirs(cmd_to_run[logdir_idx + 1])
43
44if testcase_name:
45  f = open(old_logdir + "\\testcase.%s.name" % wrapper_pid, "w")
46  print >>f, testcase_name
47  f.close()
48
49exit(subprocess.call(cmd_to_run))
50