1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Victor Mozgin.

This patch enables us to use extensive GCC C/C++ testsuites to test CDT parser.
This commit is contained in:
John Camelon 2003-06-11 19:14:01 +00:00
parent 00257fb5de
commit 415dff9a88
6 changed files with 270 additions and 11 deletions

View file

@ -1,11 +1,15 @@
2003-06-11 Victor Mozgin
Old Java TestCase.txt and TestCase2.txt for partioning testing have been replaced with C/C++ files.
Modified AutomatedIntegrationSuite.java so it doesn't produce JUnit warning anymore.
All tests in org.eclipse.cdt.ui.tests should pass now.
3003-06-11 Peter Graves 3003-06-11 Peter Graves
Update the test.xml to get the location of org.eclipse.test from a property Update the test.xml to get the location of org.eclipse.test from a property
if set. If the property is not set, it will default to the old value. if set. If the property is not set, it will default to the old value.
2003-06-11 Victor Mozgin 2003-06-11 Victor Mozgin
Old Java TestCase.txt and TestCase2.txt for partioning testing have been replaced with C/C++ files. Added TortureTest to test CDT C++ parser with GCC testsuites.
Modified AutomatedIntegrationSuite.java so it doesn't produce JUnit warning anymore. GCC testsuites are not included.
All tests in org.eclipse.cdt.ui.tests should pass now.
2003-06-10 Brent Nicolle 2003-06-10 Brent Nicolle
Added some Interface tests of (IInclude, IMacro, IStructure). Added some Interface tests of (IInclude, IMacro, IStructure).

View file

@ -1,2 +1,3 @@
AutomatedTest.properties AutomatedTest.properties
FractionalAutomatedTest.properties FractionalAutomatedTest.properties
TortureTest.properties

View file

@ -0,0 +1,31 @@
Usage:
By default, torture testing is disabled. To enable it, create a 'TortureTest.properties' in 'org.eclipse.cdt.ui.tests\parser\org\eclipse\cdt\core\parser\resources'.
If you don't have GCC testsuites, it does nothing. Then go and grab your latest version of GCC testsuites
(for instance, ftp://ftp.fu-berlin.de/unix/gnu/gcc/gcc-3.3/gcc-testsuite-3.3.tar.gz).
Unpack testsuites under
org.eclipse.cdt.ui.tests\parser\org\eclipse\cdt\core\parser\resources\torture
or elsewhere, but then you'll need to create a 'TortureTest.properties'.
That's it, you can run TortureTest in JUnit Plugin mode. Don't run all ui.tests with torture-test enabled, as apparently it is included several times (anyone knows why?)
, and it's A LOT of test cases.
You can copy the rest of the file to create a TortureTest.properties and uncomment out/edit the default values as specified here.
# By default, torture testing is disabled
# Uncomment to enable
#enabled=true
# Default location is org.eclipse.cdt.ui.tests/parser/org/eclipse/cdt/core/parser/resources/torture
#source=/your/gcc/testsuite/installation/directory
# Chunks for reading files
#stepSize=25000
# Timeout for individual cases, ms
# Need a large enough value, as some files are non-trivial
#timeOut=60000
# Quick parse, or not
#quickParse=true

View file

@ -73,6 +73,8 @@ public abstract class AutomatedFramework extends TestCase {
} }
if( filePath.endsWith(".cpp") || filePath.endsWith(".hpp") || if( filePath.endsWith(".cpp") || filePath.endsWith(".hpp") ||
filePath.endsWith(".cc") || filePath.endsWith(".CC") ||
filePath.endsWith(".C") ||
filePath.endsWith(".hxx") || filePath.endsWith(".hh") ) filePath.endsWith(".hxx") || filePath.endsWith(".hh") )
{ {
AutomatedTest.natures.put( filePath, "cpp" ); AutomatedTest.natures.put( filePath, "cpp" );
@ -171,8 +173,11 @@ public abstract class AutomatedFramework extends TestCase {
if( name.endsWith(".cpp") || if( name.endsWith(".cpp") ||
name.endsWith(".c") || name.endsWith(".c") ||
name.endsWith(".cc") || name.endsWith(".cc") ||
name.endsWith(".CC") ||
name.endsWith(".C") ||
name.endsWith(".h") || name.endsWith(".h") ||
name.endsWith(".hh") || name.endsWith(".hh") ||
name.endsWith(".hpp") ||
name.endsWith(".hxx")) name.endsWith(".hxx"))
{ {
return true; return true;

View file

@ -126,7 +126,7 @@ public class FractionalAutomatedTest extends AutomatedFramework {
return ""; return "";
} }
static private void reportHang( String code, String file ){ static public void reportHang( String code, String file ){
String output = outputFile( code.toString() ); String output = outputFile( code.toString() );
if( output.equals("") ) if( output.equals("") )
output = "Parser hang while parsing " + file + "\n"; output = "Parser hang while parsing " + file + "\n";
@ -142,7 +142,7 @@ public class FractionalAutomatedTest extends AutomatedFramework {
fail( output ); fail( output );
} }
static private void reportException( String code, String file, String exception ){ static public void reportException( String code, String file, String exception ){
String output = outputFile( code.toString() ); String output = outputFile( code.toString() );
if( output.equals("") ) if( output.equals("") )
@ -244,9 +244,9 @@ public class FractionalAutomatedTest extends AutomatedFramework {
} }
} }
static private int stepSize = 50; static protected int stepSize = 50;
static private int windowSize = 200; static protected int windowSize = 200;
static private int timeOut = 5000; static protected int timeOut = 5000;
static private String outputDir = null; static protected String outputDir = null;
static private int failures = 0; static protected int failures = 0;
} }

View file

@ -0,0 +1,218 @@
/*******************************************************************************
* 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.Test;
import org.eclipse.core.runtime.Path;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
import org.eclipse.cdt.internal.core.dom.DOMFactory;
import org.eclipse.cdt.internal.core.parser.IParser;
import org.eclipse.cdt.internal.core.parser.Parser;
import junit.framework.AssertionFailedError;
/**
* @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.ui.tests").find(new Path("/")).getFile();
resourcePath += "/parser/org/eclipse/cdt/core/parser/resources";
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 + "/torture", "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 = DOMFactory.createDOMBuilder(true);
parser = new Parser(code.toString(), domBuilder, quickParse);
parser.setCppNature(cppNature);
parser.mapLineNumbers(true);
assertTrue(parser.parse());
}
catch( Throwable e )
{
result = e;
}
}
}
}