001/* Run the Ptolemy model tests in the auto/os.name-os.arch directory using JUnit.
002
003   Copyright (c) 2016-2018 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;
032
033import org.junit.Test;
034import org.junit.runner.RunWith;
035
036import junitparams.JUnitParamsRunner;
037import junitparams.Parameters;
038
039///////////////////////////////////////////////////////////////////
040//// AutoNameArchTests
041/**
042 * Run the Ptolemy model tests in the auto/os.name-os.arch directory
043 * using JUnit.
044 *
045 * <p>The name is based on the value of the os.name Java property, but
046 * spaces have been removed and the results converted to lower case.
047 * The value of the os.arch property is not modified.  Valid directory
048 * names are macosx-x86_64 and linux-amd64.</p>
049 *
050 * <p>
051 * This test must be run from the directory that contains the auto/os.name directory,
052 * for example:
053 * </p>
054 *
055 * <pre>
056 * (cd ~/ptII/ptolemy/actor/lib/fmi/fmus/jmodelica/test; java -classpath ${PTII}:${PTII}/lib/jna-4.0.0-variadic.jar:${PTII}/lib/junit-4.8.2.jar:${PTII}/lib/JUnitParams-0.3.0.jar org.junit.runner.JUnitCore ptolemy.util.test.junit.AutoNameArchTests)
057 * </pre>
058 *
059 * <p>
060 * This test uses JUnitParams from <a
061 * href="http://code.google.com/p/junitparams/#in_browser"
062 * >http://code.google.com/p/junitparams/</a>, which is released under <a
063 * href="http://www.apache.org/licenses/LICENSE-2.0#in_browser">Apache License
064 * 2.0</a>.
065 * </p>
066 *
067 * @author Christopher Brooks
068 * @version $Id$
069 * @since Ptolemy II 11.0
070 * @Pt.ProposedRating Red (cxh)
071 * @Pt.AcceptedRating Red (cxh)
072 */
073@RunWith(JUnitParamsRunner.class)
074public class AutoNameArchTests extends AutoTests {
075    /**
076     * Execute a model and time out after 900000 ms.
077     *
078     * @param fullPath
079     *            The full path to the model file to be executed. If the
080     *            fullPath ends with the value of the
081     *            {@link #THERE_ARE_NO_AUTO_TESTS}, then the method returns
082     *            immediately.
083     * @exception Throwable
084     *                If thrown while executing the model.
085     */
086    @Override
087    @Test(timeout = 900000)
088    @Parameters(method = "modelValues")
089    public void RunModel(String fullPath) throws Throwable {
090        // This method is present so that we can run just these tests
091        // from the command line.  See the class comment for the command line.
092        super.RunModel(fullPath);
093    }
094
095    /**
096     * Return a two dimensional array of arrays of strings that name the model
097     * to be executed. If auto/ does not exist, or does not contain files that
098     * end with .xml or .moml, return a list with one element that contains
099     * the value of the THERE_ARE_NO_AUTO_TESTS variable.
100     *
101     * @return The List of model names in auto/
102     * @exception IOException If there is a problem accessing the auto/ directory.
103     */
104    @Override
105    public Object[] modelValues() throws IOException {
106
107        // Unfortunately, how architectures are specified under Java
108        // is a bit messed up.
109
110        //  Under Darwin, the os.arch property is ok, it is set to
111        //  x86_64
112
113        //  The os.name property is set to "Mac OS X", which is not a
114        //  good directory name.
115
116        //  We could use the ptolemy.ptII.jni.architecture property,
117        //  which is set by configure, but configure is not always
118        //  run.
119
120        //  So, why don't we use the name "auto/os.name-os.arch/"
121        //  where os.name is the value of the os.name property
122        //  downcased and with spaces removed and the os.arch is the
123        //  value of os.arch.
124
125        // Thus, for RHEL, we would use auto/linux-amd64/
126
127        // For Darwin: auto/macosx-x86_64/
128
129        // An alternative would be to use the fmi architecture names
130        // like linux64 and darwin64, but these names do not have much
131        // to do with Java and I'm guessing are going to change.
132
133        //  One problem is that RHEL has an old version of GLIBC,
134        //  which means that recent Ubuntu fmu binaries will not run
135        //  on the nightly build machine. The workaround for this is
136        //  to build the fmus on the nightly build machine. Upgrading
137        //  the nightly build machine to Ubuntu is out of scope.
138
139        // The FMI standard should have used with the GNU triplet
140        // architecture names or the Debian multiarch names
141        // (https://wiki.debian.org/Multiarch/Tuples)
142
143        // So, linux64 is not sufficient to differentiate between RHEL
144        // and Ubuntu. A better version number would include the
145        // version of GLIBC.
146
147        return modelValues(AutoNameArchTests.autoNameArch(),
148                THERE_ARE_NO_AUTO_ARCH_TESTS);
149    }
150
151    /** Return the auto directory for the current architecture, for example
152     *  "macosx-x86_64/".
153     *  @return the auto directory for the current architecture.
154     */
155    public static String autoNameArch() {
156        String osName = System.getProperty("os.name").replaceAll("\\s", "")
157                .toLowerCase();
158        String osArch = System.getProperty("os.arch");
159        return "auto/" + osName + "-" + osArch + "/";
160    }
161
162}