/* Run the Ptolemy model tests in the auto32/ directory using JUnit. Copyright (c) 2013-2014 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY */ package ptolemy.util.test.junit; import java.io.IOException; import java.lang.reflect.Method; import junitparams.JUnitParamsRunner; import junitparams.Parameters; import org.junit.Test; import org.junit.runner.RunWith; import ptolemy.util.StringUtilities; /////////////////////////////////////////////////////////////////// //// Auto32Tests /** * Run the Ptolemy model tests in the auto/ directory using JUnit. * *

* This test must be run from the directory that contains the auto/ directory, * for example: *

* *
 * (cd ~/ptII/ptolemy/actor/lib/io/test; java -classpath ${PTII}:${PTII}/lib/junit-4.8.2.jar:${PTII}/lib/JUnitParams-0.3.0.jar org.junit.runner.JUnitCore ptolemy.util.test.junit.AutoTests)
 * 
* *

* This test uses JUnitParams from http://code.google.com/p/junitparams/, which is released under Apache License * 2.0. *

* * @author Christopher Brooks * @version $Id: Auto32Tests.java 70402 2014-10-23 00:52:20Z cxh $ * @since Ptolemy II 10.0 * @Pt.ProposedRating Red (cxh) * @Pt.AcceptedRating Red (cxh) */ @RunWith(JUnitParamsRunner.class) public class Auto32Tests extends ModelTests { /** * Return a two dimensional array of arrays of strings that name the model * to be executed. If auto/ does not exist, or does not contain files that * end with .xml or .moml, return a list with one element that contains * the value of the THERE_ARE_NO_AUTO_TESTS variable. * * @return The List of model names in auto/ * @exception IOException If there is a problem accessing the auto/ directory. */ @Override public Object[] modelValues() throws IOException { return modelValues("auto32/", THERE_ARE_NO_AUTO_TESTS); } /** * Execute a model. Timeout after 140000 ms. * *

To check the time, go to the list of tests for AutoTest, for example * http://sisyphus.eecs.berkeley.edu:8079/hudson/job/ptII/724/testReport/ptolemy.util.test.junit/AutoKnownFailedTests/, * where 724 is a recent run of the build. Look for thhe longest * passing test, typically OpenModelicaInteractive (15 sec.), and * round up by a factor of 10 because 15 sec. is so small, then * round down so that the time is different from * AutoKnownFailedTests.

* * @param fullPath * The full path to the model file to be executed. If the * fullPath ends with the value of the * {@link #THERE_ARE_NO_AUTO_TESTS}, then the method returns * immediately. * @exception Throwable * If thrown while executing the model. */ @Test(timeout = 140000) @Parameters(method = "modelValues") public void RunModel(String fullPath) throws Throwable { if (fullPath.endsWith(THERE_ARE_NO_AUTO_TESTS)) { System.out.println("No auto32/*.xml tests in " + System.getProperty("user.dir")); return; } if (modelFileIsOK(fullPath)) { System.out.println("----------------- testing " + fullPath); System.out.flush(); if (_applicationConstructor == null) { // Delay instantiating MoMLSimpleApplication so that we // can run the kernel tests without requiring moml _applicationClass = Class .forName("ptolemy.moml.MoMLSimpleApplication"); _applicationConstructor = _applicationClass .getConstructor(String.class); } Object instance = _applicationConstructor.newInstance(fullPath); System.out.println("----------------- testing again " + fullPath); System.out.flush(); Method rerunMethod = _applicationClass.getMethod("rerun", (Class[]) null); rerunMethod.invoke(instance, (Object[]) null); } else { System.err.println("----------------- *** Skipping testing of " + fullPath); System.err.flush(); } } /** Return true if the model should be run. * This is a hack to avoid a problem where certain models * interact badly with the Cobertura code coverage tool. * @param fullPath The full path of the model to be executed * @return true if the model should be run. */ public boolean modelFileIsOK(String fullPath) { if (fullPath.endsWith("de/test/auto/ThreadedComposite.xml") && !StringUtilities.getProperty( "net.sourceforge.cobertura.datafile").equals("")) { System.err .println("ModelTests: Skipping de/test/auto/ThreadedComposite.xml because it interacts badly with Cobertura."); return false; } return true; } }