tracefw/tracecompiler/test/src/TraceHeadersLicenceTest.java
branchRCL_3
changeset 21 52e343bb8f80
parent 20 ca8a1b6995f6
child 22 e26895079d7c
equal deleted inserted replaced
20:ca8a1b6995f6 21:52e343bb8f80
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 import static org.junit.Assert.fail;
       
    19 
       
    20 import java.io.BufferedReader;
       
    21 import java.io.File;
       
    22 import java.io.FileReader;
       
    23 import java.io.IOException;
       
    24 import java.io.InputStream;
       
    25 import java.util.Arrays;
       
    26 import java.util.HashMap;
       
    27 import java.util.List;
       
    28 import java.util.regex.Matcher;
       
    29 import java.util.regex.Pattern;
       
    30 
       
    31 import org.junit.BeforeClass;
       
    32 import org.junit.Test;
       
    33 
       
    34 import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
       
    35 import com.nokia.tracecompiler.model.TraceCompilerException;
       
    36 
       
    37 
       
    38 public class TraceHeadersLicenceTest {
       
    39 	
       
    40 	public static void main(String args[]) {		
       
    41 	      	org.junit.runner.JUnitCore.main(TraceHeadersLicenceTest.class.getName());
       
    42 	    }
       
    43 	
       
    44 	/****************************************************UTILITY FUNCTIONS FOR TESTS************************************************************/
       
    45 	
       
    46 	private static String epocroot = null; 
       
    47 	private static String projectdir = "testdata\\MultipleMmpTestCases\\"; //$NON-NLS-1$
       
    48 	private static Pattern versionPattern = Pattern.compile("^.*(\\d+\\.\\d+\\.\\d+).*$"); //$NON-NLS-1$
       
    49 	private static Pattern oldversionPat = Pattern.compile("^(1\\..*)|(2\\.1.*)"); //$NON-NLS-1$
       
    50 	//old TC version should be up to 2.12.5 as new functionality was submitted to 2.12.6 (we hope)
       
    51 	private static Pattern sbsoldversionPat = Pattern.compile("^(1\\..*)|(2\\.[01]\\..*)|(2\\.1[0-2]\\.[0-3].*)"); //$NON-NLS-1$
       
    52 	private static String TCversion = ""; //$NON-NLS-1$
       
    53 	private static String SBSversion = ""; //$NON-NLS-1$
       
    54 	private static File compilerpath;
       
    55 	private static boolean oldTC = false;
       
    56 	private static boolean oldBuilder = false; 
       
    57 	private static HashMap<String, List<File>> headers = new HashMap<String, List<File>>();
       
    58 	private static HashMap<String, List<File>> sources = new HashMap<String, List<File>>();
       
    59 	private static ProcessBuilder sbs_build = new ProcessBuilder("sbs.bat","-k","-c","winscw_udeb.tracecompiler");
       
    60 	private static ProcessBuilder sbs_reallyclean = new ProcessBuilder("sbs.bat","-k","-c","winscw_udeb.tracecompiler", "reallyclean");
       
    61 	
       
    62 
       
    63 	@BeforeClass
       
    64 	static public void setEnvVariables() {
       
    65 		epocroot = System.getenv("EPOCROOT"); //$NON-NLS-1$
       
    66 		if(epocroot == null || (epocroot.length()==0)){
       
    67 			fail();
       
    68 		}
       
    69 		
       
    70 		// need to check that the path ends in a backslash
       
    71 		if(!epocroot.endsWith("\\")){ 
       
    72 			epocroot += "\\"; 
       
    73 		}
       
    74 
       
    75 		compilerpath = new File (epocroot + "epoc32" + File.separator + "tools" + File.separator +"tracecompiler" + File.separator); //default value to remove warnings. //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
       
    76 
       
    77 		ProcessBuilder tc = new ProcessBuilder("java", "-classpath", compilerpath.getPath(), //$NON-NLS-1$//$NON-NLS-2$
       
    78 				"com.nokia.tracecompiler.TraceCompiler", "-v"); //$NON-NLS-1$//$NON-NLS-2$
       
    79 		System.out.println("compilerPath= " + compilerpath); //$NON-NLS-1$
       
    80 		tc.directory(compilerpath);
       
    81 		tc.redirectErrorStream(true);
       
    82 		try {
       
    83 		Process p = tc.start();
       
    84 		p.waitFor();	
       
    85 
       
    86 		
       
    87 		String str = readProcessOutput(p);
       
    88 		System.out.println("TC version = " + str); //$NON-NLS-1$
       
    89 		Matcher m = versionPattern.matcher(str.trim());
       
    90 		if (m.matches()) {
       
    91 			TCversion = m.group(1);
       
    92 			System.out.println("TC Version = " + TCversion); //$NON-NLS-1$
       
    93 		}
       
    94 		
       
    95 		m = oldversionPat.matcher(TCversion);
       
    96 		if (m.matches()){
       
    97 			oldTC=true;
       
    98 		}
       
    99 
       
   100 		System.out.println("TC version = " + TCversion); //$NON-NLS-1$ 
       
   101 		System.out.println("OLD TC version = " + oldTC); //$NON-NLS-1$
       
   102 
       
   103 		ProcessBuilder sbs = new ProcessBuilder("sbs.bat","-v"); //$NON-NLS-1$ //$NON-NLS-2$
       
   104 		sbs.directory(compilerpath);
       
   105 		sbs.redirectErrorStream(true);
       
   106 			
       
   107 		//start the compiler
       
   108 		p = sbs.start();
       
   109 		p.waitFor();
       
   110 			
       
   111 		InputStream inp = p.getInputStream();
       
   112 			
       
   113 	        str = ""; //$NON-NLS-1$
       
   114 	        int c;
       
   115 	        //read the output from the compiler into the input stream
       
   116 	        while ((c = inp.read()) != -1) {
       
   117 	           	 str= str +((char)c);
       
   118 	        }
       
   119 
       
   120 		System.out.println("SBS version = " + str); //$NON-NLS-1$
       
   121 		m = versionPattern.matcher(str.trim());
       
   122 		if (m.matches()) {
       
   123 			SBSversion = m.group(1);
       
   124 		}
       
   125 		
       
   126 		m = sbsoldversionPat.matcher(SBSversion);
       
   127 		if (m.matches()){
       
   128 			oldBuilder=true;
       
   129 		}
       
   130 		
       
   131 		} catch (Exception e) {// Catch exception if any
       
   132 			System.err.println(e.getMessage());
       
   133 		}
       
   134 	}
       
   135 	
       
   136 	
       
   137 	public void createListHeadersDicts(String builder)
       
   138 	{
       
   139 		//The whole logic of what is expected is built here whether we build with sbs 
       
   140 		//new TC or old, The structure is re-built for each case.
       
   141 		
       
   142 		
       
   143 		Matcher m = sbsoldversionPat.matcher(SBSversion);
       
   144 		if (m.matches()){
       
   145 			oldBuilder=true;
       
   146 		} else {
       
   147 			oldBuilder=false;
       
   148 		}
       
   149 		
       
   150 		
       
   151 		System.out.println("OLD Builder :" + builder + ": = " + oldBuilder); //$NON-NLS-1$
       
   152 		
       
   153 		File tracesHeader1;
       
   154 		File tracesHeader2;
       
   155 		File tracesHeader3;
       
   156 		File tracesHeader4;
       
   157 		File source1;
       
   158 		File source2;
       
   159 		File source3;
       
   160 		File source4;
       
   161 		File ostTraceDefinitions;
       
   162 		File fixedidDefinitions;
       
   163 		String loc = "traces\\"; //$NON-NLS-1$
       
   164 		
       
   165 		source1 = new File (epocroot+projectdir+"mmp_traces\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$
       
   166 		source2 = new File (epocroot+projectdir+"mmp_traces\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$
       
   167 		source3 = new File (epocroot+projectdir+"mmp_traces\\src\\MultipleMmpApp2.cpp"); //$NON-NLS-1$
       
   168 		source4 = new File (epocroot+projectdir+"mmp_traces\\src\\ExtraCppFile2.cpp"); //$NON-NLS-1$
       
   169 		sources.put("_traces", Arrays.asList(source1, source2, source3, source4));
       
   170 		
       
   171 		tracesHeader1 = new File (epocroot+projectdir+"mmp_traces\\traces\\MultipleMmpApp1Traces.h"); //$NON-NLS-1$
       
   172 		tracesHeader2 = new File (epocroot+projectdir+"mmp_traces\\traces\\ExtraCppFile1Traces.h"); //$NON-NLS-1$
       
   173 		tracesHeader3 = new File (epocroot+projectdir+"mmp_traces\\traces\\MultipleMmpApp2Traces.h"); //$NON-NLS-1$
       
   174 		tracesHeader4 = new File (epocroot+projectdir+"mmp_traces\\traces\\ExtraCppFile2Traces.h"); //$NON-NLS-1$
       
   175 		
       
   176 		ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces\\traces\\OstTraceDefinitions.h"); //$NON-NLS-1$
       
   177 		fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces\\traces\\fixed_id.definitions"); //$NON-NLS-1$)
       
   178 		headers.put("_traces", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$
       
   179 		
       
   180 		
       
   181 		//=============================
       
   182 		
       
   183 		if (!oldBuilder && !oldTC) {
       
   184 			loc = "traces_mmp_traces_mmpname1\\"; //$NON-NLS-1$
       
   185 		}
       
   186 		tracesHeader1 = new File (epocroot+projectdir+"mmp_traces_mmpname\\"+ loc + "MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   187 		tracesHeader2 = new File (epocroot+projectdir+"mmp_traces_mmpname\\" + loc + "ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   188 		if (!oldBuilder && !oldTC) {
       
   189 			loc = "traces_mmp_traces_mmpname2\\"; //$NON-NLS-1$
       
   190 		}
       
   191 		tracesHeader3 = new File (epocroot+projectdir+"mmp_traces_mmpname\\" + loc + "MultipleMmpApp2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   192 		tracesHeader4 = new File (epocroot+projectdir+"mmp_traces_mmpname\\" + loc + "ExtraCppFile2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   193 		ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces_mmpname\\" + loc + "OstTraceDefinitions.h"); //$NON-NLS-1$
       
   194 		fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces_mmpname\\" + loc + "fixed_id.definitions"); //$NON-NLS-1$)
       
   195 
       
   196 		headers.put("_traces_mmpname", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$
       
   197 		
       
   198 		source1 = new File (epocroot+projectdir+"mmp_traces_mmpname\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$
       
   199 		source2 = new File (epocroot+projectdir+"mmp_traces_mmpname\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$
       
   200 		source3 = new File (epocroot+projectdir+"mmp_traces_mmpname\\src\\MultipleMmpApp2.cpp"); //$NON-NLS-1$
       
   201 		source4 = new File (epocroot+projectdir+"mmp_traces_mmpname\\src\\ExtraCppFile2.cpp"); //$NON-NLS-1$
       
   202 		sources.put("_traces_mmpname", Arrays.asList(source1, source2, source3, source4));
       
   203 		
       
   204 	    //=============================
       
   205 	    
       
   206 	    loc = "traces\\"; //$NON-NLS-1$
       
   207 		if (!oldTC) {
       
   208 			loc = "traces\\target7_dll\\"; //$NON-NLS-1$
       
   209 		}
       
   210 		tracesHeader1 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   211 		tracesHeader2 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   212 		if (!oldTC) {
       
   213 			loc = "traces\\target8_dll\\"; //$NON-NLS-1$
       
   214 		}
       
   215 		tracesHeader3 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "MultipleMmpApp2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   216 		tracesHeader4 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "ExtraCppFile2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   217 		ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "OstTraceDefinitions.h"); //$NON-NLS-1$
       
   218 		fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "fixed_id.definitions"); //$NON-NLS-1$)
       
   219 
       
   220 		headers.put("_traces_slash_target_ext", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$
       
   221 		
       
   222 		source1 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$
       
   223 		source2 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$
       
   224 		source3 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\src\\MultipleMmpApp2.cpp"); //$NON-NLS-1$
       
   225 		source4 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\src\\ExtraCppFile2.cpp"); //$NON-NLS-1$
       
   226 		sources.put("_traces_slash_target_ext", Arrays.asList(source1, source2, source3, source4));
       
   227 				
       
   228 	    //================================
       
   229 	    loc = "traces\\"; //$NON-NLS-1$
       
   230 		if (!oldTC) {
       
   231 			loc = "traces\\target9_dll\\"; //$NON-NLS-1$
       
   232 		}
       
   233 		tracesHeader1 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   234 		tracesHeader2 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   235 		if (!oldTC) {
       
   236 			loc = "traces\\target10_dll\\"; //$NON-NLS-1$
       
   237 		}
       
   238 		tracesHeader3 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   239 		tracesHeader4 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   240 		ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "OstTraceDefinitions.h"); //$NON-NLS-1$
       
   241 		fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "fixed_id.definitions"); //$NON-NLS-1$)
       
   242 
       
   243 		headers.put("_traces_slash_target_ext_commonsource", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$
       
   244 		
       
   245 		source1 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$
       
   246 		source2 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$
       
   247 		source3 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$
       
   248 		source4 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$
       
   249 		sources.put("_traces_slash_target_ext_commonsource", Arrays.asList(source1, source2, source3, source4));
       
   250 		
       
   251 		//==================================
       
   252 		loc = "traces\\"; //$NON-NLS-1$
       
   253 		if (!oldTC && !oldBuilder) {
       
   254 			loc = "traces_target11_exe\\"; //$NON-NLS-1$
       
   255 		}
       
   256 		tracesHeader1 = new File (epocroot+projectdir+"mmp_traces_target_type\\" + loc +"MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   257 		tracesHeader2 = new File (epocroot+projectdir+"mmp_traces_target_type\\" + loc +"ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   258 		if (!oldTC && !oldBuilder) {
       
   259 			loc = "traces_target12_exe\\"; //$NON-NLS-1$
       
   260 		}
       
   261 		tracesHeader3 = new File (epocroot+projectdir+"mmp_traces_target_type\\" + loc + "MultipleMmpApp2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   262 		tracesHeader4 = new File (epocroot+projectdir+"mmp_traces_target_type\\" + loc + "ExtraCppFile2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   263 		ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces_target_type\\" + loc + "OstTraceDefinitions.h"); //$NON-NLS-1$
       
   264 		fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces_target_type\\" + loc + "fixed_id.definitions"); //$NON-NLS-1$)
       
   265 
       
   266 		headers.put("_traces_target_type", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$
       
   267 		
       
   268 		
       
   269 		source1 = new File (epocroot+projectdir+"mmp_traces_target_type\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$
       
   270 		source2 = new File (epocroot+projectdir+"mmp_traces_target_type\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$
       
   271 		source3 = new File (epocroot+projectdir+"mmp_traces_target_type\\src\\MultipleMmpApp2.cpp"); //$NON-NLS-1$
       
   272 		source4 = new File (epocroot+projectdir+"mmp_traces_target_type\\src\\ExtraCppFile2.cpp"); //$NON-NLS-1$
       
   273 		sources.put("_traces_target_type", Arrays.asList(source1, source2, source3, source4));
       
   274 
       
   275 		
       
   276 		//==================================
       
   277 		
       
   278 		loc = "traces\\"; //$NON-NLS-1$
       
   279 		if (!oldTC && !oldBuilder) {
       
   280 			loc = "traces\\target3_dll\\"; //$NON-NLS-1$
       
   281 		}
       
   282 		tracesHeader1 = new File (epocroot+projectdir+"mmp_traces_mixed\\" + loc + "MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   283 		tracesHeader2 = new File (epocroot+projectdir+"mmp_traces_mixed\\" + loc + "ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   284 		if (!oldTC && !oldBuilder) {
       
   285 			loc = "traces_target4_kext\\"; //$NON-NLS-1$ 
       
   286 		}
       
   287 		tracesHeader3 = new File (epocroot+projectdir+"mmp_traces_mixed\\" + loc + "MultipleMmpApp2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$
       
   288 		tracesHeader4 = new File (epocroot+projectdir+"mmp_traces_mixed\\" + loc + "ExtraCppFile2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$		
       
   289 		ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces_mixed\\" + loc + "OstTraceDefinitions.h"); //$NON-NLS-1$
       
   290 		fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces_mixed\\" + loc + "fixed_id.definitions"); //$NON-NLS-1$)
       
   291 
       
   292 		headers.put("_traces_mixed", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$		
       
   293 		
       
   294 		source1 = new File (epocroot+projectdir+"mmp_traces_mixed\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$
       
   295 		source2 = new File (epocroot+projectdir+"mmp_traces_mixed\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$
       
   296 		source3 = new File (epocroot+projectdir+"mmp_traces_mixed\\src\\MultipleMmpApp2.cpp"); //$NON-NLS-1$
       
   297 		source4 = new File (epocroot+projectdir+"mmp_traces_mixed\\src\\ExtraCppFile2.cpp"); //$NON-NLS-1$
       
   298 		sources.put("_traces_mixed", Arrays.asList(source1, source2, source3, source4));
       
   299 	}
       
   300 	
       
   301 	
       
   302 	/**
       
   303 	 * This function invokes raptor on the desired test c++ project
       
   304 	 * 
       
   305 	 * @param path String specifying the path the compiler needs
       
   306 	 * 				  to run from
       
   307 	 */
       
   308 	public void InvokeCompiler(String path, String builder) {
       
   309 		System.out.println ("InvokeCompiler() for : " + builder);
       
   310 		
       
   311 		List<File> headersList;
       
   312 		try{
       
   313 			
       
   314 			//set up the directory from which the process will be called
       
   315 			if (path.compareTo("_traces")==0){ //$NON-NLS-1$
       
   316 				headersList = headers.get("_traces"); //$NON-NLS-1$
       
   317 				System.out.println("deleting file " + headersList.toString()); //$NON-NLS-1$
       
   318 				for (File header : headersList) {
       
   319 					if (header.exists()) header.delete();
       
   320 				}
       
   321 				
       
   322 				compilerpath = new File (epocroot+projectdir+"mmp_traces\\group\\"); //$NON-NLS-1$
       
   323 			}
       
   324 			else if (path.compareTo("_traces_mmpname")==0){ //$NON-NLS-1$
       
   325 				headersList = headers.get("_traces_mmpname"); //$NON-NLS-1$
       
   326 				System.out.println("deleting file " + headersList.toString()); //$NON-NLS-1$
       
   327 				for (File header : headersList) {
       
   328 					if (header.exists()) {
       
   329 						header.delete();
       
   330 					}
       
   331 				}
       
   332 				
       
   333 				compilerpath = new File (epocroot+projectdir+"mmp_traces_mmpname\\group\\");
       
   334 			}
       
   335 			else if (path.compareTo("_traces_slash_target_ext")==0){
       
   336 				headersList = headers.get("_traces_slash_target_ext");
       
   337 				System.out.println("deleting file " + headersList.toString());
       
   338 				for (File header : headersList) {
       
   339 					if (header.exists()) header.delete();
       
   340 				}
       
   341 				
       
   342 				compilerpath = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\group\\");
       
   343 			}
       
   344 			else if (path.compareTo("_traces_slash_target_ext_commonsource")==0){
       
   345 				headersList = headers.get("_traces_slash_target_ext_commonsource");
       
   346 				System.out.println("deleting file " + headersList.toString());
       
   347 				for (File header : headersList) {
       
   348 					if (header.exists()) header.delete();
       
   349 				}
       
   350 				
       
   351 				compilerpath = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\group\\");
       
   352 			}
       
   353 			else if (path.compareTo("_traces_target_type")==0){
       
   354 				headersList = headers.get("_traces_target_type");
       
   355 				System.out.println("deleting file " + headersList.toString());
       
   356 				for (File header : headersList) {
       
   357 					if (header.exists()) header.delete();
       
   358 				}
       
   359 				
       
   360 				compilerpath = new File (epocroot+projectdir+"mmp_traces_target_type\\group\\");
       
   361 			}
       
   362 			else if (path.compareTo("_traces_mixed")==0){
       
   363 				headersList = headers.get("_traces_mixed");
       
   364 				System.out.println("deleting file " + headersList.toString());
       
   365 				for (File header : headersList) {
       
   366 					if (header.exists()) header.delete();
       
   367 				}
       
   368 				
       
   369 				compilerpath = new File (epocroot+projectdir+"mmp_traces_mixed\\group\\");
       
   370 			}
       
   371 			else{
       
   372 			
       
   373 				System.out.println("Error: Unrecognised test case.");
       
   374 				fail();
       
   375 			}
       
   376 			
       
   377 			//set up the process builder object
       
   378 			sbs_build.directory(compilerpath);
       
   379 			sbs_reallyclean.directory(compilerpath);
       
   380 			sbs_build.redirectErrorStream(true);
       
   381 			
       
   382 			
       
   383 			
       
   384 			Process p;
       
   385 			String str = "";
       
   386 			//start the compiler
       
   387 			System.out.println("Starting build process ....");
       
   388 			
       
   389 				System.out.println("Running sbs reallyclean on : " + compilerpath + " command: " + sbs_reallyclean.command().toString());
       
   390 				p = sbs_reallyclean.start();
       
   391 				readProcessOutput(p);
       
   392 				System.out.println("Running sbs on : " + compilerpath + " command: " + sbs_build.command().toString());
       
   393 				p = sbs_build.start();
       
   394 				str = readProcessOutput(p);
       
   395 			
       
   396 			
       
   397 			int ret = p.exitValue();
       
   398 			System.out.println("build process ended....");
       
   399 			if (ret!=0){
       
   400 				System.out.println("build process failed:"+str);
       
   401 			}
       
   402 		}
       
   403 		
       
   404     	catch (Exception e){//Catch exception if any
       
   405     		System.err.println("Error: " + e.getMessage());
       
   406     		fail();
       
   407         }
       
   408 		
       
   409 	}
       
   410 
       
   411 
       
   412 	static private String readProcessOutput(Process p) throws IOException {
       
   413 		InputStream inp = p.getInputStream();
       
   414 		
       
   415 			int c;
       
   416 			String str = "";	        
       
   417 			//read the output from the compiler into the input stream
       
   418 			while ((c = inp.read()) != -1) {
       
   419 		   	 str= str +((char)c);
       
   420 			}
       
   421 		return str;
       
   422 	}
       
   423 	
       
   424 	/**
       
   425 	 * This function checks that the traces header files have been generated in the expected locations
       
   426 	 * 
       
   427 	 * @param path  String specifying where to look for the traces header file.  		   
       
   428 	 */
       
   429 	public void checkForTracesHeadersAndLicence(String path) {
       
   430 		System.out.println ("CheckForTracesHeaders()");
       
   431 		System.out.println("Old Builder : " + oldBuilder + "......Old TC : " + oldTC);
       
   432 		List<File> headersList = headers.get(path);
       
   433 		List<File> sourceList =  sources.get(path);
       
   434 		System.out.println("checking files " + headersList.toString());
       
   435 		boolean error = false;
       
   436 		if ((path.compareTo("_traces_slash_target_ext")==0 || path.compareTo("_traces_slash_target_ext_commonsource")==0) && oldBuilder && !oldTC){
       
   437 			System.out.println("No need to check for header files as old sbs cannot call TC");
       
   438 		} else {
       
   439 			try {
       
   440 				TraceCompilerEngineGlobals.start();
       
   441 			} catch (TraceCompilerException e) {
       
   442 				fail();
       
   443 			}
       
   444 			for (File header : headersList) {
       
   445 				if (!header.exists()) {
       
   446 					error = true;
       
   447 					System.out.println("Error: "+header+" does not exist/hasn't been generated by TraceCompiler");
       
   448 				} else {
       
   449 					String licenceInSource = null;
       
   450 					String licenceInHeader = null;
       
   451 					File source = null;
       
   452 					// read the licence from the header file
       
   453 					if (header.getName().trim().equalsIgnoreCase("OstTraceDefinitions.h")) {
       
   454 						licenceInSource = TraceCompilerEngineGlobals.getDefaultLicence(true);
       
   455 						System.out.println("Reading default licence for OstTraceDefinitions.h" + licenceInSource);
       
   456 					} else {
       
   457 						if (header.getName().trim().equalsIgnoreCase("fixed_id.definitions")) {
       
   458 							licenceInSource = TraceCompilerEngineGlobals.getDefaultLicence(false);
       
   459 							System.out.println("Reading default licence for fixed_id.definitions" + licenceInSource);
       
   460 						} else {
       
   461 							licenceInHeader = readFirstMultiLineComment(header.getAbsolutePath());
       
   462 							System.out.println("Reading licence from " + header.getAbsolutePath() + " == " + licenceInHeader);
       
   463 							if (licenceInHeader == null) {
       
   464 								System.out.println("No licence found in header file, so fail().");
       
   465 								fail();
       
   466 							}
       
   467 							source = sourceList.get(headersList.indexOf(header));
       
   468 
       
   469 							licenceInSource = readFirstMultiLineComment(source.getAbsolutePath());
       
   470 							System.out.println("Reading licence from " + source.getAbsolutePath() + " == " + licenceInSource);
       
   471 							if (licenceInSource == null) {
       
   472 								//licence should be EPL
       
   473 								System.out.println("No licence found in source file, so get default one.");
       
   474 								licenceInSource = TraceCompilerEngineGlobals.getDefaultLicence(true);
       
   475 								System.out.println("Reading default licence for " + header.getAbsolutePath() + " == " + licenceInSource);
       
   476 							}
       
   477 						}
       
   478 					}
       
   479 					if (licenceInHeader != licenceInHeader) {
       
   480 						System.out.println("Error: licence in header " + header + " is not the same in source." + source);
       
   481 						fail();
       
   482 					}
       
   483 				}
       
   484 			}
       
   485 		
       
   486 			if(!error){
       
   487 				System.out.println("All Traces Header files have been generated as expected");
       
   488 			}
       
   489 			else {
       
   490 				fail();
       
   491 				}
       
   492 		}
       
   493 	}
       
   494 
       
   495 
       
   496 	/**
       
   497 	 * @param path
       
   498 	 */
       
   499 	private String readFirstMultiLineComment(String path) {
       
   500 		StringBuffer sb = new StringBuffer();
       
   501 		try {
       
   502 			FileReader reader = new FileReader(new File(path));
       
   503 			BufferedReader br = new BufferedReader(reader);
       
   504 			String line;
       
   505 			boolean inComment = false;
       
   506 			
       
   507 			while ((line = br.readLine()) != null) {
       
   508 				if (line.trim().startsWith("/*")) {
       
   509 					inComment = true;
       
   510 				}
       
   511 				if (inComment) {
       
   512 					sb.append(line + System.getProperty("line.separator"));
       
   513 				}
       
   514 				if (line.trim().endsWith("*/") && inComment) {
       
   515 					break;
       
   516 				}
       
   517 			}
       
   518 			br.close();
       
   519 		} catch (Exception e) {
       
   520 			System.out.println("Failed to open/read file " + path + "  " + e.getMessage());
       
   521 			fail();
       
   522 		}
       
   523 		String licence = null;
       
   524 		if (sb.length()> 0) {
       
   525 			licence = sb.toString();
       
   526 			if (!licence.contains("Copyright")) {
       
   527 				licence = null;
       
   528 			}
       
   529 		}
       
   530 			
       
   531 		return licence;
       
   532 	}
       
   533 	
       
   534 
       
   535 	/****************************************************ACTUAL TESTS************************************************************/
       
   536 	@Test
       
   537 	public void MultipleMmpsTest1 (){
       
   538 		System.out.println ("*********************traces****************************");
       
   539 		createListHeadersDicts("sbs");
       
   540 		//Call Raptor
       
   541 		InvokeCompiler("_traces", "sbs");		
       
   542 		//Check for header files
       
   543 		checkForTracesHeadersAndLicence("_traces");		
       
   544 	
       
   545 	}
       
   546 	
       
   547 
       
   548 	@Test
       
   549 	public void MultipleMmpsTest2 (){
       
   550 		System.out.println ("****************traces_mmpname**********************");
       
   551 		createListHeadersDicts("sbs");
       
   552 		//Call Raptor
       
   553 		InvokeCompiler("_traces_mmpname", "sbs");
       
   554 		//Check for header files
       
   555 		checkForTracesHeadersAndLicence("_traces_mmpname");		
       
   556 		
       
   557 	}
       
   558 	
       
   559 
       
   560 	@Test
       
   561 	public void MultipleMmpsTest3 (){
       
   562 		System.out.println ("**********traces_slash_target_ext****************");
       
   563 		createListHeadersDicts("sbs");
       
   564 		//Call Raptor
       
   565 		InvokeCompiler("_traces_slash_target_ext", "sbs");
       
   566 		//Check for header files
       
   567 		checkForTracesHeadersAndLicence("_traces_slash_target_ext");		
       
   568 		
       
   569 	}
       
   570 
       
   571 	@Test
       
   572 	public void MultipleMmpsTest4 (){
       
   573 		System.out.println ("**********traces_slash_target_ext_commonsource****************");
       
   574 		createListHeadersDicts("sbs");
       
   575 		//Call Raptor
       
   576 		InvokeCompiler("_traces_slash_target_ext_commonsource", "sbs");
       
   577 		//Check for header files
       
   578 		checkForTracesHeadersAndLicence("_traces_slash_target_ext_commonsource");						
       
   579 	}
       
   580 
       
   581 	@Test
       
   582 	public void MultipleMmpsTest5 (){
       
   583 		System.out.println ("**********traces_target_type****************");
       
   584 		createListHeadersDicts("sbs");
       
   585 		//Call Raptor
       
   586 		InvokeCompiler("_traces_target_type", "sbs");
       
   587 		//Check for header files
       
   588 		checkForTracesHeadersAndLicence("_traces_target_type");
       
   589 	}
       
   590 
       
   591 	@Test
       
   592 	public void MultipleMmpsTest6 (){
       
   593 		System.out.println ("**********traces_mixed****************");
       
   594 		createListHeadersDicts("sbs");
       
   595 		//Call Raptor
       
   596 		InvokeCompiler("_traces_mixed", "sbs");
       
   597 		//Check for header files
       
   598 		checkForTracesHeadersAndLicence("_traces_mixed");
       
   599 	}
       
   600 }