001/* Run the Ptolemy model tests in the auto/knownFailedTests/ directory using JUnit.
002
003   Copyright (c) 2011-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 org.junit.Test;
032import org.junit.runner.RunWith;
033
034import junitparams.JUnitParamsRunner;
035import junitparams.Parameters;
036
037///////////////////////////////////////////////////////////////////
038//// AutoKnownFailedTests
039/**
040 * Run the Ptolemy model tests in the auto/knownFailedTest/ directory using
041 * JUnit.
042 *
043 * <p>
044 * This test must be run from the directory that contains the
045 * auto/knownFailedTests/ directory, for example:
046 * </p>
047 *
048 * <pre>
049 * (cd $PTII/ptolemy/actor/lib/net/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.AutoKnownFailedTests)
050 * </pre>
051 *
052 * <p>
053 * This test uses JUnitParams from <a
054 * href="http://code.google.com/p/junitparams/#in_browser"
055 * >http://code.google.com/p/junitparams/</a>, which is released under <a
056 * href="http://www.apache.org/licenses/LICENSE-2.0#in_browser">Apache License
057 * 2.0</a>.
058 * </p>
059 *
060 * @author Christopher Brooks
061 * @version $Id$
062 * @since Ptolemy II 10.0
063 * @Pt.ProposedRating Red (cxh)
064 * @Pt.AcceptedRating Red (cxh)
065 */
066@RunWith(JUnitParamsRunner.class)
067public class AutoKnownFailedTests extends ModelKnownFailedTests {
068
069    /**
070     * Execute a model.  Timeout after 150000 ms.
071     *
072     * For information about how this class is used in the Travis build,
073     * see <a href="https://wiki.eecs.berkeley.edu/ptexternal/Main/Travis#in_browser target="_top">https://wiki.eecs.berkeley.edu/ptexternal/Main/Travis</a>.
074     *
075     * @param fullPath
076     *            The full path to the model file to be executed. If the
077     *            fullPath ends with the value of the
078     *            {@link #THERE_ARE_NO_KNOWN_FAILED_TESTS}, then the method
079     *            returns immediately.
080     * @exception Throwable
081     *                If thrown while executing the model.
082     */
083    @Test(timeout = 150000)
084    @Parameters(method = "modelValues")
085    public void RunModel(String fullPath) throws Throwable {
086        if (fullPath.endsWith(THERE_ARE_NO_KNOWN_FAILED_TESTS)) {
087            System.out.println("No auto/knownFailedTests/*.xml tests in "
088                    + System.getProperty("user.dir"));
089            System.out.flush();
090            return;
091        }
092        System.out.println(
093                "----------------- testing (KnownFailure) " + fullPath);
094        System.out.flush();
095        try {
096            if (_applicationConstructor == null) {
097                // Delay instantiating MoMLSimpleApplication so that we
098                // can run the kernel tests without requiring moml
099                _applicationClass = Class
100                        .forName("ptolemy.moml.MoMLSimpleApplication");
101                _applicationConstructor = _applicationClass
102                        .getConstructor(String.class);
103
104            }
105            _applicationConstructor.newInstance(fullPath);
106        } catch (Throwable throwable) {
107            System.out.println("Known Failure: " + throwable);
108            throwable.printStackTrace();
109        }
110    }
111}