001/* Run the Ptolemy model tests in the auto32/ directory using JUnit. 002 003 Copyright (c) 2013-2016 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028 029package ptolemy.util.test.junit; 030 031import java.io.IOException; 032import java.lang.reflect.Method; 033 034import org.junit.Test; 035import org.junit.runner.RunWith; 036 037import junitparams.JUnitParamsRunner; 038import junitparams.Parameters; 039import ptolemy.util.StringUtilities; 040 041/////////////////////////////////////////////////////////////////// 042//// Auto32Tests 043/** 044 * Run the Ptolemy model tests in the auto/ directory using JUnit. 045 * 046 * <p> 047 * This test must be run from the directory that contains the auto/ directory, 048 * for example: 049 * </p> 050 * 051 * <pre> 052 * (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) 053 * </pre> 054 * 055 * <p> 056 * This test uses JUnitParams from <a 057 * href="http://code.google.com/p/junitparams/#in_browser" 058 * >http://code.google.com/p/junitparams/</a>, which is released under <a 059 * href="http://www.apache.org/licenses/LICENSE-2.0#in_browser">Apache License 060 * 2.0</a>. 061 * </p> 062 * 063 * @author Christopher Brooks 064 * @version $Id$ 065 * @since Ptolemy II 10.0 066 * @Pt.ProposedRating Red (cxh) 067 * @Pt.AcceptedRating Red (cxh) 068 */ 069@RunWith(JUnitParamsRunner.class) 070public class Auto32Tests extends ModelTests { 071 072 /** 073 * Return a two dimensional array of arrays of strings that name the model 074 * to be executed. If auto/ does not exist, or does not contain files that 075 * end with .xml or .moml, return a list with one element that contains 076 * the value of the THERE_ARE_NO_AUTO_TESTS variable. 077 * 078 * @return The List of model names in auto/ 079 * @exception IOException If there is a problem accessing the auto/ directory. 080 */ 081 @Override 082 public Object[] modelValues() throws IOException { 083 return modelValues("auto32/", THERE_ARE_NO_AUTO_TESTS); 084 } 085 086 /** 087 * Execute a model. Timeout after 140000 ms. 088 * 089 * For information about how this class is used in the Travis build, 090 * see <a href="https://wiki.eecs.berkeley.edu/ptexternal/Main/Travis#in_browser target="_top">https://wiki.eecs.berkeley.edu/ptexternal/Main/Travis</a>. 091 * 092 * @param fullPath 093 * The full path to the model file to be executed. If the 094 * fullPath ends with the value of the 095 * {@link #THERE_ARE_NO_AUTO_TESTS}, then the method returns 096 * immediately. 097 * @exception Throwable 098 * If thrown while executing the model. 099 */ 100 @Test(timeout = 140000) 101 @Parameters(method = "modelValues") 102 public void RunModel(String fullPath) throws Throwable { 103 if (fullPath.endsWith(THERE_ARE_NO_AUTO_TESTS)) { 104 System.out.println("No auto32/*.xml tests in " 105 + System.getProperty("user.dir")); 106 return; 107 } 108 if (modelFileIsOK(fullPath)) { 109 System.out.println("----------------- testing " + fullPath); 110 System.out.flush(); 111 if (_applicationConstructor == null) { 112 // Delay instantiating MoMLSimpleApplication so that we 113 // can run the kernel tests without requiring moml 114 _applicationClass = Class 115 .forName("ptolemy.moml.MoMLSimpleApplication"); 116 _applicationConstructor = _applicationClass 117 .getConstructor(String.class); 118 119 } 120 Object instance = _applicationConstructor.newInstance(fullPath); 121 122 System.out.println("----------------- testing again " + fullPath); 123 System.out.flush(); 124 Method rerunMethod = _applicationClass.getMethod("rerun", 125 (Class<?>[]) null); 126 rerunMethod.invoke(instance, (Object[]) null); 127 } else { 128 System.err.println( 129 "----------------- *** Skipping testing of " + fullPath); 130 System.err.flush(); 131 132 } 133 } 134 135 /** Return true if the model should be run. 136 * This is a hack to avoid a problem where certain models 137 * interact badly with the Cobertura code coverage tool. 138 * @param fullPath The full path of the model to be executed 139 * @return true if the model should be run. 140 */ 141 public boolean modelFileIsOK(String fullPath) { 142 if (fullPath.endsWith("de/test/auto/ThreadedComposite.xml") 143 && !StringUtilities 144 .getProperty("net.sourceforge.cobertura.datafile") 145 .equals("")) { 146 System.err.println( 147 "ModelTests: Skipping de/test/auto/ThreadedComposite.xml because it interacts badly with Cobertura."); 148 return false; 149 } 150 return true; 151 } 152}