• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2
3import common
4import sys, os, subprocess, fcntl
5
6
7bindir = os.path.dirname(__file__)
8autotest = os.path.join(bindir, 'autotest')
9
10logdir = sys.argv[1]
11
12
13# We want to simulate the behaviour of autotest_client, where fd3 would be
14# routed to stderr and fd1 & fd2 to stdout
15
16# HACK: grab fd3 for now
17os.dup2(2, 3)
18
19# open up log files to use for std*
20stdout = open(os.path.join(logdir, 'stdout'), 'a', 0)
21stderr = open(os.path.join(logdir, 'stderr'), 'a', 0)
22
23# set up the file descriptors now, simulating the old behaviour
24os.dup2(stdout.fileno(), 1)
25os.dup2(stdout.fileno(), 2)
26os.dup2(stderr.fileno(), 3)
27
28# we don't need the file objects any more
29stdout.close()
30stderr.close()
31
32
33args = [autotest] + sys.argv[2:]
34if '-H' not in args:
35    args[1:1] = ['-H', 'autoserv']
36cmd = ' '.join(args)
37
38# open up a log file for saving off the exit code
39exit_file = open(os.path.join(logdir, 'exit_code'), 'w', 0)
40fcntl.flock(exit_file, fcntl.LOCK_EX)
41
42# touch a 'started' file to indicate we've been initialized
43open(os.path.join(logdir, 'started'), 'w').close()
44
45# run the actual autotest client and write the exit code into the log file
46exit_code = subprocess.call(cmd, shell=True)
47exit_file.write('%+04d' % exit_code)
48exit_file.flush()
49fcntl.flock(exit_file, fcntl.LOCK_UN)
50exit_file.close()
51