Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java216
1 files changed, 216 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java
new file mode 100644
index 00000000000..3950b534a8c
--- /dev/null
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/TortureTest.java
@@ -0,0 +1,216 @@
+/*******************************************************************************
+ * Copyright (c) 2001 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Corp. - Rational Software - initial implementation
+ ******************************************************************************/
+package org.eclipse.cdt.core.parser.tests;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+
+import org.eclipse.cdt.core.parser.IParser;
+import org.eclipse.cdt.internal.core.dom.DOMBuilder;
+import org.eclipse.cdt.internal.core.parser.Parser;
+import org.eclipse.core.runtime.Path;
+
+
+/**
+ * @author vmozgin
+ *
+ * Automated parser test framework, to use with GCC testsuites
+ */
+public class TortureTest extends FractionalAutomatedTest {
+
+ static protected boolean isEnabled = false;
+ static protected boolean quickParse = true;
+
+ public TortureTest () {
+ super();
+ }
+
+ public TortureTest (String name) {
+ super(name);
+ }
+
+ protected AutomatedFramework newTest (String name){
+ return new TortureTest (name);
+ }
+
+ protected void loadProperties() throws Exception{
+ String resourcePath = org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
+ resourcePath += "resources/parser/TortureTest";
+
+ try {
+ FileInputStream propertiesIn = new FileInputStream(resourcePath + "/TortureTest.properties");
+ properties.load (propertiesIn);
+
+ isEnabled = properties.getProperty("enabled", "false").equalsIgnoreCase("true");
+ quickParse = properties.getProperty("quickParse", "true").equalsIgnoreCase("true");
+
+ String sourceInfo = properties.getProperty("source", "");
+
+ stepSize = Integer.parseInt(properties.getProperty("stepSize", "25000"));
+ outputFile = properties.getProperty("outputFile", "");
+ timeOut = Integer.parseInt(properties.getProperty("timeOut", "60000"));
+ outputDir = properties.getProperty("outDir", "");
+
+ if (sourceInfo.equals(""))
+ throw new FileNotFoundException();
+ else {
+ StringTokenizer tokenizer = new StringTokenizer(sourceInfo, ",");
+ String str = null, val = null;
+ try {
+ while (tokenizer.hasMoreTokens()) {
+ str = tokenizer.nextToken().trim();
+ val = tokenizer.nextToken().trim();
+
+ testSources.put(str, val);
+ }
+ } catch (NoSuchElementException e){
+ //only way to get here is to have a missing val, assume cpp for that str
+ testSources.put(str, "cpp");
+ }
+
+ }
+ } catch (FileNotFoundException e){
+ testSources.put(resourcePath + "/default", "cpp");
+ }
+
+ if (!isEnabled) testSources.clear();
+ }
+
+
+ public static Test suite()
+ {
+ AutomatedFramework frame = new TortureTest();
+ return frame.createSuite();
+ }
+
+
+ static protected void reportException (Throwable e, String file, IParser parser){
+ String output = null;
+ int lineNumber = -1;
+
+ try {
+ lineNumber = parser.getLineNumberForOffset(parser.getLastErrorOffset());
+ } catch (Exception ex) {}
+
+ if (e instanceof AssertionFailedError) {
+ output = file + ": Parse failed on line ";
+ output += lineNumber + "\n";
+ } else {
+ output = file + ": " + e.getClass().toString();
+ output += " on line " + lineNumber + "\n";
+ }
+ try {
+ if (report != null) {
+ report.write(output.getBytes());
+ }
+ } catch (IOException ex) {}
+
+ fail(output);
+ }
+
+
+ static protected boolean isExpectedToPass (String testCode)
+ {
+ // Process some DejaGNU instructions
+ if (testCode.indexOf("{ dg-do run") >= 0) return true;
+ if (testCode.indexOf("{ dg-do link") >= 0) return true;
+ if (testCode.indexOf("{ dg-error") >= 0) return false;
+ if (testCode.indexOf("// ERROR") >= 0) return false;
+ if (testCode.indexOf("- ERROR") >= 0) return false;
+ if (testCode.indexOf("// XFAIL") >= 0) return false;
+ if (testCode.indexOf("{ xfail") >= 0) return false;
+ if (testCode.indexOf("{ dg-preprocess") >= 0) return false;
+
+ return true;
+ }
+
+
+ public void doFile() throws Throwable {
+ assertNotNull (fileList);
+
+ File file = (File)fileList.removeFirst();
+ FileInputStream stream = new FileInputStream(file);
+
+ String filePath = file.getCanonicalPath();
+ String nature = (String)natures.get(filePath);
+
+ StringWriter code = new StringWriter();
+
+ byte b[] = new byte[stepSize];
+ int n = stream.read(b);
+ while( n != -1 ){
+ code.write(new String(b));
+ n = stream.read(b);
+ }
+
+ String testCode = code.toString();
+
+ if (isExpectedToPass(testCode)) {
+ ParseThread thread = new ParseThread();
+
+ thread.quickParse = quickParse;
+ thread.code = testCode;
+ thread.cppNature = nature.equalsIgnoreCase("cpp");
+ thread.file = filePath;
+
+ thread.start();
+ thread.join(timeOut);
+
+ if (thread.isAlive()) {
+ thread.stop();
+ reportHang(testCode, filePath);
+ } else if (thread.result != null) {
+ reportException(thread.result, filePath, thread.parser);
+ }
+ } else {
+ // gcc probably didn't expect this test to pass.
+ // It doesn't mean that it should pass CDT parser,
+ // as it is more relaxed
+ // Result - 'inconclusive', but we report 'pass'
+ assertTrue(true);
+ }
+ }
+
+
+
+ static class ParseThread extends Thread {
+ public String code;
+ public boolean cppNature;
+ public String file;
+ public Throwable result = null;
+ public IParser parser = null;
+ public boolean quickParse = true;
+
+ public void run(){
+ try {
+ DOMBuilder domBuilder = new DOMBuilder();
+ parser = new Parser(code.toString(), domBuilder, quickParse);
+
+ parser.setCppNature(cppNature);
+ parser.mapLineNumbers(true);
+
+ assertTrue(parser.parse());
+ }
+ catch( Throwable e )
+ {
+ result = e;
+ }
+ }
+ }
+}

Back to the top