4
Copyright (C) International Business Machines Corp., 2005
5
Author: Dan Smith <danms@us.ibm.com>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; under version 2 of the License.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
## These are utility functions for test cases
41
# We currently advise waiting this many seconds for the ramdisk to
43
TEST_DOMU_BOOT_DELAY = 20
45
if os.environ.get("TEST_VERBOSE"):
50
class TimeoutError(Exception):
51
def __init__(self, msg, outputSoFar):
53
self.output = outputSoFar
58
def runWithTimeout(cmd, timeout):
63
startTime = time.time()
66
os.execvp(args[0], args)
70
while time.time() - startTime < timeout:
71
i, o, e = select.select([fd], [], [], timeout)
78
exitPid, status = os.waitpid(pid, os.WNOHANG)
82
print "Child exited with %i" % status
86
print "Command timed out: killing pid %i" % pid
88
os.kill(pid, signal.SIGINT)
89
raise TimeoutError("Command execution time exceeded %i seconds" % timeout,
92
def traceCommand(command, timeout=None, logOutput=True):
94
print "[dom0] Running `%s'" % command
97
status, output = runWithTimeout(command, timeout)
99
status, output = commands.getstatusoutput(command)
101
if logOutput and verbose:
104
return status, output
108
fname = os.path.basename(script)
109
match = re.match("([^\.]+)\.[a-z]+", fname)
111
tname = match.group(1)
118
"""Become a non-root user, or FAIL if this is not possible. This call
119
succeeds if we are already running as a non-root user.
122
if os.geteuid() == 0:
123
# Try and become "nobody". This user is commonly in place, but this
124
# could be extended to consider any number of users to be acceptable,
125
# if there are systems where "nobody" is not present.
126
allusers = pwd.getpwall()
129
os.setreuid(u[2], u[2])
131
if os.geteuid() == 0:
132
FAIL("Could not become a non-root user")
134
def FAIL(format, *args):
135
print "\nREASON:", (format % args)
138
def SKIP(format, *args):
139
print "\nREASON:", (format % args)
142
def saveLog(logText, filename=None):
145
logfile = open(filename, 'w');
146
date = commands.getoutput("date");
147
logfile.write("-- BEGIN XmTest Log @" + date + "\n");
148
logfile.write(logText);
149
logfile.write("\n-- END XmTest Log\n");
154
print "[dom0] Waiting %i seconds for domU boot..." % TEST_DOMU_BOOT_DELAY
155
time.sleep(TEST_DOMU_BOOT_DELAY)
160
t = time.asctime(time.localtime())
162
print "*** Test %s started at %s %s" % (name, t,
163
time.tzname[time.daylight])
166
# Try to start a domain and attach a console to it to see if
167
# the console system is working
171
from XmTestLib import XmTestDomain, DomainError, XmConsole, ConsoleError
173
domain = XmTestDomain()
176
console = domain.start()
178
except DomainError, e:
180
except ConsoleError, e:
189
# We currently can only load as many concurrent HVM domains as loop
190
# devices, need to find how many devices the system has.
191
def getMaxHVMDomains():
192
nodes = glob.glob("/dev/loop*")
198
if __name__ == "__main__":