#!/usr/bin/python2.6
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
#
import radtest.fw as fw
import radtest.results as results
import radtest.main as main
import os
import os.path
import subprocess
import sys
_VP_DIR = "usr/lib/rad/java"
_JUNIT_JAR = "/usr/share/lib/java/junit.jar"
_SCF_JAR = "usr/share/vpanels/scf-common.jar"
class JavaExecutor(fw.ExtTestFinder):
""" Finds tests matching a particular pattern and executes them """
def __init__(self):
fw.ExtTestFinder.__init__(self, ".class")
def is_test(self, path, name):
return name.endswith("Test")
def make_classpath(self, root, dir):
vproot = os.path.join(root, _VP_DIR)
vpjars = [ "rad.jar", "adr.jar", "afunix.jar" ]
scfjar = os.path.join(root, _SCF_JAR)
classpathents = map(lambda x: os.path.join(vproot, x), vpjars)
classpathents.append(_JUNIT_JAR)
classpathents.append(scfjar)
classpathents.append(dir)
return ":".join(classpathents)
def run_common(self, dir, jargs, pargs):
root = os.getenv("ROOT")
classpath = self.make_classpath(root, dir)
javacmd = os.getenv("JAVA_HOME", "/usr") + "/bin/java"
args = [javacmd, "-classpath", classpath, "testutil.TestExec"]
args.extend(jargs)
args.extend(self.findtests(dir))
myenv = os.environ.copy()
proc = fw.with_proto_libs(myenv, root,
lambda: subprocess.Popen(args, env = myenv, **pargs))
return proc
def run(self, result, resultsdir = None, dir = ""):
if resultsdir:
args = ["-r", resultsdir]
else:
args = []
proc = self.run_common(dir, args,
{ "stdout" : subprocess.PIPE })
results.parse_raw(proc.stdout, result, resultsdir)
def run_raw(self, dir = ""):
proc = self.run_common(dir, [ "-v" ], {})
proc.wait()
if __name__ == "__main__":
# Without a results directory, python loses exception data
# main.main(JavaExecutor())
if len(sys.argv) > 1:
dir = sys.argv[1]
else:
dir = "build"
JavaExecutor().run_raw(dir)