Contents:
We have included regression tests for most of the Ptolemy II code. Usually,
wherever there is Java file, the tests are in the test
directory.
test/
directories
as *.tcl
files
test/auto/
directories as
*.xml
files .
test/junit
directories.
cd $PTII/ptolemy/actor/lib/test make tests
cd $PTII ant test.single -Dtest.name=ptolemy.actor.lib.test.junit.JUnitTclTest -Djunit.formatter=plainTo get usage for the test.single rule, try
ant test.single
and
look at the first few lines of output.
test/
directorycd $PTII/ptolemy/actor/lib/test $PTII/bin/ptjunit
test/
directory and ant under Eclipse runs from
$PTII
.Resources:
http://www.tcl.tk/scripting/primer.html
java::
man page We ship Jacl as a jar file called $PTII/lib/ptjacl.jar
.
make tests
will run the tests in the current directory
and any subdirectories.
There are two ways to write tests:
The testing infrastructure will automatically run any MoML models
located in test/auto
directories. (Nowhere do the names
of these MoML files need to be listed in order for them to be run.)
However, said infrastructure has to be re-built in each new directory containing tests.
Note that MoML models used for testing should follow the following conventions:
domains/yourdomain/kernel/test/auto
should not use actors in
domains/yourdomain/lib
.
kernel
directories before running
in the lib
directories, so the actors in lib
will not yet be built.domains/yourdomain/test/auto
.
lib/test/auto
or kernel/test/auto
.
test/auto
directories)
in ptolemy/kernel
and its subdirectories.
The tests in ptolemy/kernel
and subdirectories should
not use code from ptolemy/domains
ptolemy/moml
and the domains
is not yet built. Again, we want unit tests of the kernel, not
tests of moml and the domains here.ptolemy.actor.lib.gui
because these gui actors
will not work during the nightly build when the models are run
without a display.test/
directory
that contains an auto/
directory.
$PTII/ptolemy/actor/lib/test
.test/
and
test/auto/
directories.
mkdir test test/auto
test/
directory.
cd test
testDefs.tcl
and the makefile
file from the example directory chosen in step 1 above.
cp $PTII/ptolemy/actor/lib/test/testDefs.tcl cp $PTII/ptolemy/actor/lib/test/makefile .
testDefs.tcl
PTII
.
if {![info exist PTII]} { # If we are here, then we are probably running jacl and we can't # read environment variables set PTII [file join [pwd] .. .. .. .. ] }The
.. .. .. ..
is the relative path
to the top of the Ptolemy II tree.
makefile
ME =
and ROOT =
auto
directory is listed in the
MISC_FILES
section:
MISC_FILES = alljtests.tcl \ auto
test/makefile
should include a line that
invokes test_auto
when the test_jsimple
rule
is invoked:
test_jsimple: $(EXTRA_SRCS) jclass $(KERNEL_TESTDEFS) alljtests.tcl test_auto
dummy.tcl
may appear in the makefile
,
which some people find confusing. The test makefile structure supports
running graphical and non-graphical Tcl tests. If a particular directory
does not have graphical or non-graphical Tcl tests, then we
set the value of JGRAPHICAL_TESTS
or
JSIMPLE_TESTS
to include dummy.tcl
so
that when the makefile expands JGRAPHICAL_TESTS
or JSIMPLE_TESTS
there will be a value there instead
of an empty value. However, if either JGRAPHICAL_TESTS
or JSIMPLE_TESTS
are set to dummy.tcl
and not referred to as a dependency, then you need not have
a dummy.tcl
file.
# Graphical Java tests that use Tcl. # If there are no tests, we use a dummy file so that the script that builds # alljtests.tcl works. If you add a test, be sure to add # $(JGRAPHICAL_TESTS) to EXTRA_SRCS JGRAPHICAL_TESTS = \ dummy.tcl EXTRA_SRCS = $(TCL_SRCS) $(JSRCS) $(JSIMPLE_TESTS) #$(JGRAPHICAL_TESTS)
$PTII/build.xml
file
includes targets that run all the tests in **/junit/*.java
. So we need to create a test/junit/JUnitTclTest.java
file.
That file is mostly empty, but it needs to have at least the package adjusted
mkdir junit cd junit cp $PTII/ptolemy/actor/lib/test/junit/JUnitTclTest.java . cp $PTII/ptolemy/actor/lib/test/junit/makefile .
JUnitTclTest.java
package ptolemy.actor.lib.test.junit;
* (cd $PTII/ptolemy/actor/lib/test/junit; java -classpath ${PTII}:${PTII}/lib/ptjacl.jar:${PTII}/lib/junit-4.8.2.jar:${PTII}/lib/JUnitParams-0.3.0.jar org.junit.runner.JUnitCore ptolemy.actor.lib.test.junit.JUnitTclTest)
makefile
and adjust the paths:
ME
and ROOT
# Location of this directory, relative to the Ptolemy II directory ME = ptolemy/actor/lib/test/junit # Root of the Ptolemy II directory ROOT = ../../../../..
tests:: $(EXTRA_SRCS) jclass test_java #test_jsimple (cd ..; CLASSPATH="$(PTII)$(CLASSPATHSEPARATOR)$(CLASSPATH)" "$(JAVA)" $(JUNIT_JAVA_ARGS) org.junit.runner.JUnitCore ptolemy.actor.lib.test.junit.JUnitTclTest)
cd ..There needs to be a makefile here too. It needs to name the
test/
directory you created. If there already is a
makefile, edit it. If there is not a makefile, then
copy the makefile from a similar directory elsewhere in the tree.
test
directory was
added, the add test
to the DIRS
and
MISC_FILES
lines:
DIRS = kernel lib demo doc test ... MISC_FILES = kernel lib doc test
When you have done all this, the tests in your new test/auto directory ought to run in the nightly build.
The test passes if it does not throw an exception
The Test actor (located under "more libraries") can be used to compare the first few results of a simulation with a known good results. If the comparison fails, then the test fails.
If a test is in the optional test/auto/knownFailedTests
directory, then it will be marked as a known failure if it fails.
(For more information, see
Checking Known Failed Test Results
below).
Using Vergil to write tests is quite a bit easier than writing Tcl code, but it is much more difficult to handle corner cases and test for erroneous conditions by writing models. Tcl tests are unit tests, whereas tests that use models are system tests and may mask unit test bugs.
The test suite infrastructure is based on the Tcl test suite code.
The file $PTII/util/testsuite/testDefs.tcl
defines the Tcl proc test
.
test
takes five arguments:
foo-1.0
-
'1
, though if
you are
doing setup, you can start with 0
.foo-1
and foo-2
, you can always call
your new test foo-1.1
NORMAL
, which means that
the test should pass under normal conditions. If the value is
KNOWN_FAILED
, then the test is expected to fail, but
eventually will be fixed. By using KNOWN_FAILED
, developers
can mark tests that they know are failing, which will save other
developers from attempting to debug known problems.
testDefs.tcl
file and then runs one test. The code below
has the incorrect value return results to be compared against, so the
test suite properly indicates that the test failed.
if {[string compare test [info procs test]] == 1} then { source [file join $PTII util testsuite testDefs.tcl] } {} test testExample-1.1 {This is the first test example, it does very little} { catch {this is an error} errMsg1 set a "this is the value of a" list $errMsg1 $a } {{invalid command name "this"} {this is NOT the value of a}}
test
directory.
It is better to have many small test files as opposed to a few
large test files so that other developers can quickly find the tests
for the class they are working with. Usually tests for the class
Foo
are found in the file test/Foo.tcl
Each test file should have the following parts:
if {[string compare test [info procs test]] == 1} then { source testDefs.tcl }Each directory contains a
testDefs.tcl
file which
in turn sources $PTII/util/testsuite/testDefs.tcl
. The idea here is that
if the test framework changes, each test file need not be updated.
#set VERBOSE 1
############################################################################ #### Foo test Foo-1.1 {Test out Foo} { } {}
It is up to the author of the tests as to whether each individual test does all the set up necessary. If each test is atomic, then it makes it easy to highlight the text of an individual test and run it. If lots of tests are sharing common setup, then using a separate procedure to do setup might help. On the negative side, atomic tests usually are longer and have more complicated return results.
cd $PTII; make tests
If you run make
in a test directory that contains
tests written in Tcl for testing Java classes, then the 'right thing'
should just happen.
If you are running in Eclipse:
tcl.lang.Shell
.alljtests.tcl
or any individual test tcl file.
(E.g. SimpleDelay.tcl
).
Or, leave the "Program arguments" field blank and when ptjacl is running (see below), enter text in to the Eclipse console.
-Dptolemy.ptII.dir=your PtII directory
-Dptolemy.ptII.dir=c:/hyzheng/ptII
).-Dptolemy.ptII.dir="c:/my workspace/ptII"
).
C:\hyzheng\ptII\ptolemy\domains\de\lib\test
)
The nice thing of using Eclipse is that you can very easily locate where the exception is thrown by clicking the classes listed in the stack trace. You may further register a breakpoint to do more diagnosis.
Below we discuss some of the details of writing tests in Tcl that test Java classes.
Jacl allows us to instantiate objects in a class and call public
methods. We use Jacl and the standard Tcl test bed to create tests.
In the example below, we call java::new
to create an
instance of the Java NamedObj
class. We can then
call public methods of NamedObj
by referring to the
Java object handle $n
:
test NamedObj-2.1 {Create a NamedObj, set the name, change it} { set n [java::new pt.kernel.NamedObj] set result1 [$n getName] $n setName "A Named Obj" set result2 [$n getName] list $result1 $result2 } {{} {A Named Obj}}
createAndExecute
. Even better, you
can test for specific error messages with:
test SDFSchedulerErrors-1.0 {} { catch {createAndExecute "rateConsistency.xml"} errorMessage list $errorMessage } {{ptolemy.kernel.util.IllegalActionException: Failed to compute schedule: in .rateConsistency.SDF Director Because: No solution exists for the balance equations. Graph is not consistent under the SDF domain detected on external port .rateConsistency.actor.port2}}
It is best if each Java class has a separate Tcl file that contains tests.
The base of the name of the Tcl test file should be the same of the Java
class being tested. The Tcl test file should be located in the
test
subdirectory of the directory where the Java class
is defined.
For example, if we are testing NamedObj.java
, then
the Tcl test file should be at test/NamedObj.tcl
.
We use ant and Cobertura for code coverage. See $PTII/doc/coding/ant.htm for information about ant.
For code coverage, see http://chess.eecs.berkeley.edu/ptexternal.
wget
program can be used to craw the html pages
of the release when it is on a website.
$PTII/index.htm
that includes a link to doc/index.htm
wget
wget -np -m https://ptolemy.berkeley.edu/ptolemyII/release/index.htm >& wget.outThis will generate lots of files in a
ptolemy.eecs.berkeley.edu
directory. This directory can be removed:
rm -rf ptolemy.eecs.berkeley.eduLook for "
Not Found
"
awk '{ if ($0 ~ /Not Found/) { print lineTwo} else {lineTwo = lineOne; lineOne=$0}}' wget.out | uniq | awk '{print $NF}'| grep -v '%5C' | sort
ftp://ftp.cre.canon.co.uk/pub/weblint/weblint.tar.gz
but has since moved, try
using google.
weblint
:
cd $PTII make weblint
htmlchek
also checks for bad links. The
htmlchek
output is a little hard to read, so we tend to
use weblint
for checking individual files.
htmlchek
was once available at
ftp://ftp.cs.buffalo.edu/pub/htmlchek/
but has since moved, try using google.
The best way to run htmlchek
is to create a sample
distribution, create the files in the codeDoc
directory
and then run htmlchek
cd /users/ptII/adm/gen-latest; make htmlchek
PTII
to point to the test distribution:
setenv PTII /users/ptII/adm/dists/ptII-latest cd PTII
make install
. This will make the Itcl HTML docs
twice, which will populate the doc/codeDoc
directories.
You need to make the Itcl HTML docs twice so that the cross references are
correct.
make htmlchek
htmlchekout.ERR
- HTML usage errorshtmlchekout.NAME
- Locations in the specified files
that ware not referenced by any of those files
htmlchekout.HREF
- References from the specified files
that are not found in the files. This file is by far the most important
file to look at.
htmlchekout.SRC
- References to online images.htmlchekout.MAP
- Cross dependency information. All of the references in htmlchekout.HREF
that point
to .html
files should be checked. References to non-HTML
files appear in htmlchekout.HREF
because the non-HTML
files were not included in the list of files that
htmlchek
ran on. One quick way to search all the the *.html
files is
cd $PTII grep mystring `find . -name "*.html" -print`
$PTII/util/testsuite/ptspell
is a Ptolemy II specific spelling checker.
ptspell
has the following features:
$PTII/util/testsuite/ptlocaldict
as a local dictionary of acceptable words that are not in the
regular system dictionary. ptlocaldict
is kept in ASCII sort order.
ptspell
splits words up that contain embedded
capital letters and then runs spell again. Thus, ptspell
can report spelling problems in variable, method and class names.
This mechanism also reduces the number of words that are reported as
misspelled because the word consists of two words stuck together.
/usr/local/bin/ispell
is present, then
it will use it. If you are running under Windows with Cygwin, you can
download a prebuilt version of ispell
from
https://ptolemy.berkeley.edu/tycho/tychoTools.htm
Checking the spelling in all the HTML files can be done with:
cd $PTII ptspell `find . -name "*.html" -print`
Spell check the comments in the demos
cd $PTII adm/bin/ptIItxtfiles > /tmp/f grep demo /tmp/f | grep .xml > /tmp/m ptspell `cat /tmp/m
make realclean
tclIndex
files and the files in
doc/codeDoc
. The reason to remove the
codeDoc
files is so that we don't ship HTML files for any
classes that have been removed.
make install
tclIndex
files and the
doc/codeDoc
files.
make checkjunk
adm/bin/chkgifs
$PTII/com/microstar
is a non validating parser.
If you are writing MoML code, you might want to run your
file through a validating parser, below are a few references:
http://webster.commnet.edu/writing/symbols.htm
cd $PTII;./configure
cd $PTII make install jnlp_allInvoke Webstart by pointing your browser at
$PTII/vergil.jnlp
about::copyright
facility to test
for missing files and models that are the wrong size.
cd c:/Ptolemy/ptII5.1 export PTII=c:/Ptolemy/ptII5.1 ./configure make fast install tests >& make.out &
Last Updated: $Date: 2014-10-23 21:17:40 -0700 (Thu, 23 Oct 2014) $