Class Script
java.lang.Object
com.sun.javatest.Script
- Direct Known Subclasses:
APIScript, KeywordScript, ReportScript, StdTestScript
Script is the abstract base class providing the ability to control
how a test is to be compiled and executed. In addition to the primary method,
run, it has many methods that can be used by subtype classes
to assist them in performing a test.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for extended testTimeout control. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final TimerA timer that may be used to set up timeouts.protected BackupPolicyA backup policy object that specifies how files should be backed up, if a file is found to exist when a new one of the same name is to be written.protected StringThe default name for the TestResult section used to save the data written to the out1 stream for a command.protected StringThe default name for the TestResult section used to save the data written to the out2 stream for a command.protected TestEnvironmentThe test environment for the test being performed.protected static final StatusA status that may be used to indicate problems in the executeArgs field of a test description.protected static final StatusA status that may be used to indicate a problem with a test's class directory.protected static final StatusA status that may be used to indicate that a compilation failed unexpectedly.protected static final StatusA status that may be used to indicate that no action was specified.protected static final StatusA status that may be used to indicate that no execute class was specified in a test description.protected static final StatusA status that may be used to indicate that no extension was found in a source file.protected static final StatusA status that may be used to indicate that no rmi classes were specified in a test description.protected static final StatusA status that may be used to indicate that no sources were specified in a test description.protected String[]The set of test cases to be excluded for this test.protected static final StatusA status that may be used to indicate the a compilation failed unexpectedly.protected static final StatusA status that may be used to indicate that a compilation did not fail as was expected.protected static final StatusA status that may be used to indicate that a test execution step did not fail as wqas expected.protected ClassLoaderThe class loader to be used to load additional user-specified classes as required in the execution of the script.protected static final StatusA status that may be used to indicate that no extension was found in a source file.protected static final StatusA status that may be used to indicate that no source files were found in the test description.protected Harness.ObserverNotifier of starting/finishing tests.protected static final StatusA status that may be used to indicate that a compilation failed as expected.protected static final StatusA status that may be used to indicate that a compilation succeeded as expected.protected static final StatusA status that may be used to indicate that an execution step failed, as was expected.protected String[]The initialization args for the script.protected TestDescriptionThe test description for the test being performed.protected PrintWriterThe reporting channel for the test being performed.protected WorkDirectoryThe work directory for the test run. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StatuscompileIfNecessary(File[] srcs, String classDir) Compile those source files for which the corresponding class file appears to be out of date.protected StatuscompileIfNecessary(String[] srcs, String classDir) Compile those source files for which the corresponding class file appears to be out of date.protected StatuscompileIfNecessary(String command, File[] srcs, String classDir) Compile those source files for which the corresponding class file appears to be out of date.protected StatuscompileIfNecessary(String command, String[] srcs, String classDir) Compile those source files for which the corresponding class file appears to be out of date.protected StatuscompileIndividually(File... srcs) Compile the given source files individually.protected StatuscompileIndividually(String... srcs) Compile the given source files individually.protected StatuscompileIndividually(String command, File... srcs) Compile the given source files individually.protected StatuscompileIndividually(String command, String... srcs) Compile the given source files individually.protected StatuscompileOne(File src) Compiles the given source file.protected StatuscompileOne(String src) Compile the given source file.protected StatuscompileOne(String command, File src) Compiles the given source file.protected StatuscompileOne(String command, String src) Compile the given source file.protected StatuscompileTogether(File... srcs) Compile the given source files together.protected StatuscompileTogether(String... srcs) Compile the given source files together.protected StatuscompileTogether(String command, File... srcs) Compile the given source files together.protected StatuscompileTogether(String command, String[] srcs) Compile the given source files together.protected String[]Modify the args for a test to be executed, according to a set of test cases to be excluded.protected StatusExecute the given class with the given arguments, which need to be passed to the environment for $ substitution and for splitting into separate strings.protected StatusExecute the given class with the given arguments.protected StatusExecute the given class with the given arguments, which need to be passed to the environment for $ substitution and for splitting into separate strings.protected StatusExecute the given class with the given arguments.protected static String[]filesToStrings(File... files) Utility routine to convert an array of filenames to a corresponding array of strings.booleanGet the flag that indicates whether a result (.jtr) file should be written even if the test has passed.Get the test description for the test which this script will run.Get the test result object to be used for the results of the test run.protected intGet the timeout to be used for a test.Getter for TimeoutProvider.voidInitialize any custom args for the script.voidinitBackupPolicy(BackupPolicy backupPolicy) Initialize the backup policy to be used when creating a test result file in which to store the results of running this test.voidinitClassLoader(ClassLoader loader) Initialize the class loader for any commands to be loaded.protected voidinitDelegate(Script s, String... scriptArgs) Initialize a delegate script object.voidinitExcludedTestCases(String... excludedTestCases) Initialize the list of test cases to be excluded from the test.voidInitialize the test description to be run by the script.voidInitialize the environment to be used when running the test.protected voidInitialize the test result for the result of the script execution.voidinitWorkDir(WorkDirectory workDir) Initialize the work directory to be used to store the results obtained when running the test, and to store any temporary files that may be required by the test.protected StatusinvokeCommand(String key) Invoke a command in the environment identified by a given key.protected StatusrmiCompile(String... classes) RMI Compile the given class files.protected StatusrmiCompile(String command, String... classes) RMI Compile the given class files.voidrun()Run the script, to fill out the test results for the test description given toinit.abstract Statusrun(String[] args, TestDescription td, TestEnvironment env) The primary method to be provided by Scripts.protected voidsetAlarm(int timeout) Set an alarm that will interrupt the calling thread after a specified delay (in milliseconds), and repeatedly thereafter until cancelled.protected voidSet an alarm that will interrupt a given thread after a specified delay (in milliseconds), and repeatedly thereafter until cancelled.protected voidsetDefaultCommandStreamNames(String out1Name, String out2Name) Set the default names of the two default output streams used when executing a command.voidsetJTRIfPassed(boolean b) Set the flag that indicates whether a result (.jtr) file should be written even if the test has passed.voidsetNotifier(Harness.Observer notifier) Sets notifier to be used to inform listeners of events of a test starting/finishing.voidsetTimeoutProvider(Script.TimeoutProvider provider) Set TimeoutProvider used to control test timeouts.booleanReturns true if the Script uses own way of notifying the Harness of starting/finishing test, false otherwise (by default).
-
Field Details
-
alarmTimer
A timer that may be used to set up timeouts. -
error_badExecuteArgs
A status that may be used to indicate problems in the executeArgs field of a test description. -
error_badTestClassDir
A status that may be used to indicate a problem with a test's class directory. -
error_compFailUnexp
A status that may be used to indicate that a compilation failed unexpectedly. -
error_noActionSpecified
A status that may be used to indicate that no action was specified. -
error_noExecuteClass
A status that may be used to indicate that no execute class was specified in a test description. -
error_noExtnInSource
A status that may be used to indicate that no extension was found in a source file. -
error_noRMIClasses
A status that may be used to indicate that no rmi classes were specified in a test description. -
error_noSource
A status that may be used to indicate that no sources were specified in a test description. -
fail_compFailUnexp
A status that may be used to indicate the a compilation failed unexpectedly. -
fail_compSuccUnexp
A status that may be used to indicate that a compilation did not fail as was expected. -
fail_execSuccUnexp
A status that may be used to indicate that a test execution step did not fail as wqas expected. -
pass_compFailExp
A status that may be used to indicate that a compilation failed as expected. -
pass_compSuccExp
A status that may be used to indicate that a compilation succeeded as expected. -
noSource
A status that may be used to indicate that no source files were found in the test description. -
noExtnInSource
A status that may be used to indicate that no extension was found in a source file. -
pass_execFailExp
A status that may be used to indicate that an execution step failed, as was expected. -
td
The test description for the test being performed. -
excludedTestCases
The set of test cases to be excluded for this test. -
env
The test environment for the test being performed. -
scriptArgs
The initialization args for the script. -
workDir
The work directory for the test run. -
cmdOut1Name
The default name for the TestResult section used to save the data written to the out1 stream for a command.- See Also:
-
cmdOut2Name
The default name for the TestResult section used to save the data written to the out2 stream for a command.- See Also:
-
backupPolicy
A backup policy object that specifies how files should be backed up, if a file is found to exist when a new one of the same name is to be written. -
loader
The class loader to be used to load additional user-specified classes as required in the execution of the script. -
trOut
The reporting channel for the test being performed. -
notifier
Notifier of starting/finishing tests. Initialized only when useNotifier() returns true.- Since:
- 4.2.1
- See Also:
-
-
Constructor Details
-
Script
public Script()
-
-
Method Details
-
filesToStrings
-
initArgs
Initialize any custom args for the script.- Parameters:
args- custom args for the script
-
initTestDescription
Initialize the test description to be run by the script. In addition, a mutable test result is set up, in which the results of running the test can be recorded by the script.- Parameters:
td- the test description for the test to be run
-
initExcludedTestCases
Initialize the list of test cases to be excluded from the test. The script is responsible for determining how to instruct the test not to run these test cases. A recommended convention is to pass the list of test cases to the test using a -exclude option.- Parameters:
excludedTestCases- a list of test cases within the test that should not be run
-
initTestEnvironment
Initialize the environment to be used when running the test.- Parameters:
env- the environment to be used when running the test
-
initWorkDir
Initialize the work directory to be used to store the results obtained when running the test, and to store any temporary files that may be required by the test.- Parameters:
workDir- the work directory to be used to store the test's results.
-
initBackupPolicy
Initialize the backup policy to be used when creating a test result file in which to store the results of running this test.- Parameters:
backupPolicy- A backup policy object to be used when creating test result files.
-
initClassLoader
Initialize the class loader for any commands to be loaded.- Parameters:
loader- a class loader to be used to load any commands or other user-specified classes that may be required.
-
initDelegate
Initialize a delegate script object. This should only be used in exceptional circumstances, and is mostly provided for historical purposes.- Parameters:
s- The delegate to be initializedscriptArgs- the arguments to be passed to the delegate object
-
initTestResult
Initialize the test result for the result of the script execution. Normally, a test result is initialized as a side effect of calling initTestDescription. This method should only be called is special circumstances, and is mostly provided for historical purposes.- Parameters:
tr- The test result to set as the result of the script's execution.- Throws:
IllegalStateException- if the test result has already been set.- See Also:
-
run
public void run()Run the script, to fill out the test results for the test description given toinit. Most implementations will use the default implementation of this method, which delegates to a simpler (abstract) method @link(run(String[],TestDescription, TestEnvironment)). If you override this method, be aware that this method does insert many of the standard result properties into the TestResult object - harness info, start stop times, etc. -
run
The primary method to be provided by Scripts. It is responsible for compiling and executing the test appropriately. Normally, a script should call `init' and then decode any script-specific options it is given in `args'. It should then examine the test description it is given so that it can compile and execute the test as appropriate. Various convenience routines are provided to simplify the task of running the compiler, an interpreter or any other commands, which can be specified in a flexible manner by properties in the TestEnvironment.- Parameters:
args- Any script-specific options specified in the script propertytd- The test description for the test to be performedenv- The test environment giving the details of how to run the test- Returns:
- The result of running the script
- See Also:
-
getTestDescription
Get the test description for the test which this script will run.- Returns:
- the test description for the test which this script will run.
-
getTestResult
Get the test result object to be used for the results of the test run.- Returns:
- the test result object to be used for the results of the test run.
-
getJTRIfPassed
public boolean getJTRIfPassed()Get the flag that indicates whether a result (.jtr) file should be written even if the test has passed. By default, this is true.- Returns:
- the flag that indicates whether a result (.jtr) file should be written even if the test has passed.
- See Also:
-
setJTRIfPassed
public void setJTRIfPassed(boolean b) Set the flag that indicates whether a result (.jtr) file should be written even if the test has passed. By default, this is true.- Parameters:
b- the flag that indicates whether a result (.jtr) file should be written even if the test has passed.- See Also:
-
setAlarm
protected void setAlarm(int timeout) Set an alarm that will interrupt the calling thread after a specified delay (in milliseconds), and repeatedly thereafter until cancelled. Typical usage:try { setAlarm(delay); ... } finally { setAlarm(0); }- Parameters:
timeout- the interval (in milliseconds) after which the calling thread will be interrupted, if not cancelled in the meantime.
-
setAlarm
Set an alarm that will interrupt a given thread after a specified delay (in milliseconds), and repeatedly thereafter until cancelled. Typical usage:try { setAlarm(delay); ... } finally { setAlarm(0); }- Parameters:
timeout- the interval (in milliseconds) after which the calling thread will be interrupted, if not cancelled in the meantime.threadToInterrupt- which thread to interrupt
-
getTimeoutProvider
Getter for TimeoutProvider. Generates default (10*factor) provider in case no provider is set- Returns:
- TimeoutProvider set to Script. Returns default TimeoutProvider in case no TimeoutProvider is set (or it is set to null). The default implementation is 10 minutes scaled by a value found in the environment ("javatestTimeoutFactor").
- See Also:
-
setTimeoutProvider
Set TimeoutProvider used to control test timeouts.- Parameters:
provider- null to use default test timeout value (10 sec).- See Also:
-
getTestTimeout
protected int getTestTimeout()Get the timeout to be used for a test. Uses TimeoutProvider to get test timeout value. The default implementation of TimeoutProvider is 10 minutes scaled by a value found in the environment ("javatestTimeoutFactor"). This method can be overriden to provide different behaviors. A value of zero means no timeout.- Returns:
- the number of seconds in which the test is expected to complete its execution.
- See Also:
-
compileIndividually
Compile the given source files individually. One at a time, each source file is passed to compileTogether, until they have all been successfully compiled, or until one fails to compile.- Parameters:
srcs- The names of the file to be compiled.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileIndividually
Compile the given source files individually. One at a time, each source file is passed to compileTogether, until they have all been successfully compiled, or until one fails to compile.- Parameters:
command- the base name of the command entry in the environment to be used to compile any necessary sources. The complete entry name will becommand.command.extnsrcs- The names of the file to be compiled.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileIndividually
Compile the given source files individually. One at a time, each source file is passed to compileTogether, until they have all been successfully compiled, or until one fails to compile.- Parameters:
srcs- The names of the file to be compiled.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileIndividually
Compile the given source files individually. One at a time, each source file is passed to compileTogether, until they have all been successfully compiled, or until one fails to compile.- Parameters:
command- the base name of the command entry in the environment to be used to compile any necessary sources. The complete entry name will becommand.command.extnsrcs- The names of the file to be compiled.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileOne
-
compileOne
Compile the given source file. The file is treated as a singleton group and passed to compileTogether.- Parameters:
command- the base name of the command entry in the environment to be used to compile any necessary sources. The complete entry name will becommand.command.extnsrc- The name of the file to be compiled.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileOne
-
compileOne
Compiles the given source file.- Parameters:
command- the base name of the command entry in the environment to be used to compile any necessary sources. The complete entry name will becommand.command.extnsrc- The name of the file to be compiled.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileTogether
Compile the given source files together. The compiler and arguments to be used are identified by the `env.env.compile.extn.*' properties in the script's environment, where env is the name of the environment specified to the GUI, and extn is the extension of the first source file. The names of the files to be compiled are added to the end of the arguments retrieved from the environment.- Parameters:
srcs- The names of the file to be compiled.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileTogether
Compile the given source files together. The compiler and arguments to be used are identified by the `env.env.command.command.extn.*' properties in the script's environment, where env is the name of the environment specified to the GUI, and extn is the extension of the first source file. The names of the files to be compiled are added to the end of the arguments retrieved from the environment.- Parameters:
command- the base name of the command entry in the environment to be used to compile any necessary sources. The complete entry name will becommand.command.extnsrcs- The names of the file to be compiled.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileTogether
Compile the given source files together. The compiler and arguments to be used are identified by the `env.env.command.compile.extn.*' properties in the script's environment, where env is the name of the environment specified to the GUI, and extn is the extension of the first source file. The names of the files to be compiled are added to the end of the arguments retrieved from the environment.- Parameters:
srcs- The names of the file to be compiled.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileTogether
Compile the given source files together. The compiler and arguments to be used are identified by the `env.env.command.command.extn.*' properties in the script's environment, where env is the name of the environment specified to the GUI, and extn is the extension of the first source file. The names of the files to be compiled are added to the end of the arguments retrieved from the environment.- Parameters:
command- the base name of the command entry in the environment to be used to compile any necessary sources. The complete entry name will becommand.command.extnsrcs- The names of the file to be compiled.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileIfNecessary
Compile those source files for which the corresponding class file appears to be out of date. Each source file is scanned to find a package statement to help determine the main class defined in the source file -- the corresponding class file in the given class directory is then checked, and if the source file is newer, it is put on a list to be recompiled. After checking all the source files, if any need to be recompiled, they will be compiled together, using the default compile command ("command.compile.extn") entry in the the environment.- Parameters:
srcs- The names of the source files to be compiled if necessaryclassDir- The class directory in which the corresponding class files (if any) will be found.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileIfNecessary
Compile those source files for which the corresponding class file appears to be out of date. Each source file is scanned to find a package statement to help determine the main class defined in the source file -- the corresponding class file in the given class directory is then checked, and if the source file is newer, it is put on a list to be recompiled. After checking all the source files, if any need to be recompiled, they will be compiled together, using the specified compile command entry in the the environment.- Parameters:
command- the base name of the command entry in the environment to be used to compile any necessary sources. The complete entry name will becommand.command.extnsrcs- The names of the source files to be compiled if necessaryclassDir- The class directory in which the corresponding class files (if any) will be found.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileIfNecessary
Compile those source files for which the corresponding class file appears to be out of date. Each source file is scanned to find a package statement to help determine the main class defined in the source file -- the corresponding class file in the given class directory is then checked, and if the source file is newer, it is put on a list to be recompiled. After checking all the source files, if any need to be recompiled, they will be compiled together, using the default compile command ("command.compile.extn") entry in the the environment.- Parameters:
srcs- The names of the source files to be compiled if necessaryclassDir- The class directory in which the corresponding class files (if any) will be found.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
compileIfNecessary
Compile those source files for which the corresponding class file appears to be out of date. Each source file is scanned to find a package statement to help determine the main class defined in the source file -- the corresponding class file in the given class directory is then checked, and if the source file is newer, it is put on a list to be recompiled. After checking all the source files, if any need to be recompiled, they will be compiled together, using the specified compile command entry in the the environment.- Parameters:
command- the base name of the command entry in the environment to be used to compile any necessary sources. The complete entry name will becommand.command.extnsrcs- The names of the source files to be compiled if necessaryclassDir- The class directory in which the corresponding class files (if any) will be found.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
execute
Execute the given class with the given arguments, which need to be passed to the environment for $ substitution and for splitting into separate strings.- Parameters:
executeClass- The name of the class to be executedexecuteArgs- The arguments to be evaluated before passing to the class to be executed- Returns:
- The status of the execution
- See Also:
-
execute
Execute the given class with the given arguments, which need to be passed to the environment for $ substitution and for splitting into separate strings.- Parameters:
command- The name of the command containing the template to be executedexecuteClass- The name of the class to be executedexecuteArgs- The arguments to be evaluated before passing to the class to be executed- Returns:
- The status of the execution
-
execute
Execute the given class with the given arguments. The interpreter to be used and its arguments are identified by the `env.env.execute.*' properties in the script's environment, where env is the name of the environment specified to the GUI. The class to be executed and its arguments are added to the end of the arguments retrieved from the environment.- Parameters:
executeClass- The name of the class to be executed.executeArgs- Any arguments to be passed to the class to be executed.- Returns:
- The status of the execution
- See Also:
-
execute
Execute the given class with the given arguments. The interpreter to be used and its arguments are identified by the `env.env.command.*' properties in the script's environment, where env is the name of the environment specified to the GUI. The class to be executed and its arguments are added to the end of the arguments retrieved from the environment.- Parameters:
command- The name of the command containing the template to be executedexecuteClass- The name of the class to be executed.executeArgs- Any arguments to be passed to the class to be executed.- Returns:
- The status of the execution
- See Also:
-
rmiCompile
RMI Compile the given class files. The compiler and arguments to be used is identified by the `env.env.command.rmic' property in the script's environment, where env is the name of the environment specified to the GUI. The name of the classes to be compiled by rmic is obtained from the test description.- Parameters:
classes- The names of the classes to be compiled by rmic.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
rmiCompile
RMI Compile the given class files. The compiler and arguments to be used is identified by the `env.env.command.command' property in the script's environment, where env is the name of the environment specified to the GUI. The name of the classes to be compiled by rmic is obtained from the test description.- Parameters:
command- The name of the command containing the template to be compiledclasses- The names of the classes to be compiled by rmic.- Returns:
- The status of the compilation: passed or failed.
- See Also:
-
invokeCommand
Invoke a command in the environment identified by a given key. The command is identified by looking up `command.key' property in the environment. The first word of this property identifies the name of a class that should be an implementation ofCommand, and the subsequent words are the arguments to be passed to a fresh instance of that class, via itsrunmethod. Standard library implementations ofCommandare available, such as:- com.sun.javatest.lib.ProcessCommand
- Execute a command in a separate process
- com.sun.javatest.lib.ExecStdTestSameJVMCmd
- Execute a standard test in the same JVM as JT Harness
- com.sun.javatest.agent.PassiveAgentCommand
- Execute a command on a remote machine
The use of `
command.key' supersedes an earlier mechanism involving multiple properties. For backwards compatibility, if the `command.key' property is not found, the properties for the earlier mechanism are checked as well.- Parameters:
key- The tag for the command to be executed- Returns:
- A status giving the outcome of the command
- See Also:
-
setDefaultCommandStreamNames
Set the default names of the two default output streams used when executing a command. In many cases these may correspond to the UNIX-style standard-out and standard-error streams. This API does not define what they are used for though, and architects are encouraged to give descriptive names if possible.- Parameters:
out1Name- Name of the first stream.out2Name- Name of the second stream.
-
exclude
Modify the args for a test to be executed, according to a set of test cases to be excluded. If there are no test cases to be excluded, the result will be the original args unchanged; otherwise, the result will be the original args prefixed by "-exclude" and a comma-separated list of exclude test cases.- Parameters:
args- The basic list of args for the testtestCases- the set of test cases to be excluded, or null if none- Returns:
- The original list of args, possibly prefixed by "-exclude" and a comma-separated list of test cases that should not be executed by the test
-
useNotifier
public boolean useNotifier()Returns true if the Script uses own way of notifying the Harness of starting/finishing test, false otherwise (by default).Normally the Harness notifies all listeners of an event of starting a test when the method run() is invoked and an event of finishing the test when the method run() is completed. Those Scripts which need to take a control over notifying should override this method to return
true. In this case the notifier field will be initialized and the Harness will no longer notify the listeners when a test starts/stops.- Since:
- 4.2.1
-
setNotifier
Sets notifier to be used to inform listeners of events of a test starting/finishing. Invoked by the Harness iff useNotifier() returns true.- Since:
- 4.2.1
- See Also:
-