001/* Run the Ptolemy model tests in the auto/knownFailedTests/ directory using cg code generation under JUnit. 002 003 Copyright (c) 2011-2014 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.util.Arrays; 033import java.util.LinkedList; 034 035import ptolemy.util.FileUtilities; 036import ptolemy.util.StringUtilities; 037 038/////////////////////////////////////////////////////////////////// 039//// AutoCGKnownFailedTests 040 041/** 042 * Run the Ptolemy model tests in the auto/knownFailedTests/ directory using cg code generation 043 * under JUnit. 044 * 045 * <p> 046 * This class provides common facilities used by classes that generate 047 * C and Java code. 048 * 049 * @author Christopher Brooks 050 * @version $Id$ 051 * @since Ptolemy II 10.0 052 * @Pt.ProposedRating Red (cxh) 053 * @Pt.AcceptedRating Red (cxh) 054 */ 055public class AutoCGKnownFailedTests extends AutoCGTests { 056 057 /** 058 * Return a two dimensional array of arrays of strings that name 059 * the model to be executed. If auto/knownFailedTests/ does not 060 * exist, or does not contain files that end with .xml or .moml, 061 * return a list with one element that contains a special string. 062 * 063 * @return The List of model names in auto/ 064 * @exception IOException If there is a problem accessing the auto/ directory. 065 */ 066 @Override 067 public Object[] modelValues() throws IOException { 068 return modelValues("auto/knownFailedTests/", 069 THERE_ARE_NO_KNOWN_FAILED_TESTS); 070 } 071 072 /** 073 * Generate, compile and run code for a model known to fail. 074 * @param fullPath 075 * The full path to the model file to be executed. If the 076 * fullPath ends with the value of the 077 * {@link #THERE_ARE_NO_AUTO_TESTS}, then the method returns 078 * immediately. 079 * @param language Either "c" or "java". 080 * @param generateInSubdirectory If true, then generate the code in 081 * in a subdirectory of ~/cg/. 082 * @param inline If true, then generate inline code. 083 * @param maximumLinesPerBlock The maximum number of line of code generated 084 * per block 085 * @param variablesAsArrays If true, then try to save space by putting variables 086 * into arrays. 087 * @param generatorPackageList A semicolon or * separated list of 088 * Java packages to be searched for adapters. For example, 089 * generic.program.procedural.c.arduino means use the arduino 090 * @exception Throwable If thrown while generating, compiling or executing the compiled code. 091 */ 092 @Override 093 public void runModel(String fullPath, String language, 094 boolean generateInSubdirectory, boolean inline, 095 int maximumLinesPerBlock, boolean variablesAsArrays, 096 String generatorPackageList) throws Throwable { 097 if (fullPath.endsWith(THERE_ARE_NO_KNOWN_FAILED_TESTS)) { 098 System.out.println("No auto/*.xml tests in " 099 + StringUtilities.getProperty("user.dir")); 100 return; 101 } 102 103 // Delete the ~/cg directory each time so that if the user generates code for 104 // a model using -generateInSubdirectory, we can still have gcc generate an 105 // executable with that name. 106 if (!FileUtilities.deleteDirectory(_cgDirectory)) { 107 System.out.println("Warning, failed to delete " + _cgDirectory); 108 } 109 110 LinkedList<String> argumentsList = new LinkedList<String>(Arrays.asList( 111 "-language", language, "-generateInSubdirectory", 112 Boolean.toString(generateInSubdirectory), "-inline", 113 Boolean.toString(inline), "-maximumLinesPerBlock", 114 Integer.toString(maximumLinesPerBlock), "-variablesAsArrays", 115 Boolean.toString(variablesAsArrays))); 116 if (generatorPackageList != null && generatorPackageList.length() > 0) { 117 argumentsList.add("-generatorPackageList"); 118 argumentsList.add(generatorPackageList); 119 } 120 argumentsList.add(fullPath); 121 122 String[] args = argumentsList.toArray(new String[argumentsList.size()]); 123 124 System.out.print( 125 "----------------- (Known Failure) AutoCG $PTII/bin/ptcg"); 126 for (int i = 0; i < args.length; i++) { 127 System.out.print(" " + args[i]); 128 } 129 130 try { 131 int returnValue = ((Integer) _generateCodeMethod.invoke(null, 132 (Object) args)).intValue(); 133 if (returnValue != 0) { 134 System.out.println( 135 "Known Failure: Return value of the last command executed was not zero, it was: " 136 + returnValue); 137 } 138 } catch (Throwable throwable) { 139 System.out.println("Known Failure: " + throwable); 140 throwable.printStackTrace(); 141 } 142 } 143}