From 31b7d84b2b4dc4ba29088947d8872027830e8fe4 Mon Sep 17 00:00:00 2001 From: wisberg Date: Mon, 16 Dec 2002 21:46:19 +0000 Subject: [PATCH] initial version --- testing-drivers/.classpath | 17 + testing-drivers/.project | 25 + testing-drivers/readme-testing-drivers.html | 8 + testing-drivers/src/.cvsignore | 1 + .../org/aspectj/testing/drivers/Harness.java | 1215 +++++++++++++++++ .../RFE-find-tests-for-resource.teamtask | 26 + .../org/aspectj/testing/drivers/package.html | 194 +++ testing-drivers/testdata/defaultSuite.xml | 58 + .../incremental/harness/TestNoTester.java | 5 + .../harness/classAdded/main/Main.20.java | 11 + .../harness/classAdded/main/Main.java | 7 + .../harness/classRemoved/main/Main.20.java | 8 + .../harness/classRemoved/main/Main.java | 11 + .../harness/classUnchanged/main/Main.20.java | 12 + .../harness/classUnchanged/main/Main.java | 11 + .../harness/classUpdated/main/Main.20.java | 8 + .../harness/classUpdated/main/Main.java | 7 + .../harness/defaultPackage/Main.30.java | 8 + .../harness/defaultPackage/Main.40.java | 7 + .../harness/defaultPackage/Main.java | 7 + .../harness/defaultPackage/Target.20.java | 9 + .../defaultPackage/Target.delete.40.java | 2 + .../incremental/harness/expClasses/Main.java | 7 + .../harness/expClasses/exp/Main.class | Bin 0 -> 355 bytes .../incremental/harness/selectionTest.xml | 145 ++ .../harness/sourceAdded/main/Main.30.java | 12 + .../harness/sourceAdded/main/Main.java | 7 + .../harness/sourceAdded/main/Target.20.java | 9 + .../delete/DeleteMe.delete.20.java | 2 + .../sourceDeleted/delete/DeleteMe.java | 7 + .../harness/sourceDeleted/delete/Main.java | 8 + .../sourceDeleted/delete/Target.30.java | 7 + .../harness/sourceDeleted/delete/Target.java | 8 + .../testdata/incremental/harness/suite.xml | 109 ++ .../incremental/harness/suiteFails.xml | 134 ++ .../testdata/incremental/inc-suite.xml | 58 + .../java/delete/DeleteMe.delete.20.java | 5 + .../incremental/java/delete/DeleteMe.java | 8 + .../incremental/java/delete/Main.java | 9 + .../incremental/java/delete/Target.30.java | 9 + .../incremental/java/delete/Target.java | 10 + .../incremental/java/static/Main.30.java | 9 + .../incremental/java/static/Main.40.java | 11 + .../incremental/java/static/Main.60.java | 11 + .../incremental/java/static/Main.java | 9 + .../incremental/java/static/Target.20.java | 8 + .../incremental/java/static/Target.40.java | 10 + .../incremental/java/static/Target.50.java | 8 + .../incremental/java/static/Target.java | 8 + testing-drivers/testing-drivers.mf.txt | 3 + .../testsrc/TestingDriversModuleTests.java | 32 + .../aspectj/testing/drivers/DriversTests.java | 32 + .../testing/drivers/HarnessSelectionTest.java | 286 ++++ .../aspectj/testing/drivers/SuiteTest.java | 197 +++ 54 files changed, 2835 insertions(+) create mode 100644 testing-drivers/.classpath create mode 100644 testing-drivers/.project create mode 100644 testing-drivers/readme-testing-drivers.html create mode 100644 testing-drivers/src/.cvsignore create mode 100644 testing-drivers/src/org/aspectj/testing/drivers/Harness.java create mode 100644 testing-drivers/src/org/aspectj/testing/drivers/RFE-find-tests-for-resource.teamtask create mode 100644 testing-drivers/src/org/aspectj/testing/drivers/package.html create mode 100644 testing-drivers/testdata/defaultSuite.xml create mode 100644 testing-drivers/testdata/incremental/harness/TestNoTester.java create mode 100644 testing-drivers/testdata/incremental/harness/classAdded/main/Main.20.java create mode 100644 testing-drivers/testdata/incremental/harness/classAdded/main/Main.java create mode 100644 testing-drivers/testdata/incremental/harness/classRemoved/main/Main.20.java create mode 100644 testing-drivers/testdata/incremental/harness/classRemoved/main/Main.java create mode 100644 testing-drivers/testdata/incremental/harness/classUnchanged/main/Main.20.java create mode 100644 testing-drivers/testdata/incremental/harness/classUnchanged/main/Main.java create mode 100644 testing-drivers/testdata/incremental/harness/classUpdated/main/Main.20.java create mode 100644 testing-drivers/testdata/incremental/harness/classUpdated/main/Main.java create mode 100644 testing-drivers/testdata/incremental/harness/defaultPackage/Main.30.java create mode 100644 testing-drivers/testdata/incremental/harness/defaultPackage/Main.40.java create mode 100644 testing-drivers/testdata/incremental/harness/defaultPackage/Main.java create mode 100644 testing-drivers/testdata/incremental/harness/defaultPackage/Target.20.java create mode 100644 testing-drivers/testdata/incremental/harness/defaultPackage/Target.delete.40.java create mode 100644 testing-drivers/testdata/incremental/harness/expClasses/Main.java create mode 100644 testing-drivers/testdata/incremental/harness/expClasses/exp/Main.class create mode 100644 testing-drivers/testdata/incremental/harness/selectionTest.xml create mode 100644 testing-drivers/testdata/incremental/harness/sourceAdded/main/Main.30.java create mode 100644 testing-drivers/testdata/incremental/harness/sourceAdded/main/Main.java create mode 100644 testing-drivers/testdata/incremental/harness/sourceAdded/main/Target.20.java create mode 100644 testing-drivers/testdata/incremental/harness/sourceDeleted/delete/DeleteMe.delete.20.java create mode 100644 testing-drivers/testdata/incremental/harness/sourceDeleted/delete/DeleteMe.java create mode 100644 testing-drivers/testdata/incremental/harness/sourceDeleted/delete/Main.java create mode 100644 testing-drivers/testdata/incremental/harness/sourceDeleted/delete/Target.30.java create mode 100644 testing-drivers/testdata/incremental/harness/sourceDeleted/delete/Target.java create mode 100644 testing-drivers/testdata/incremental/harness/suite.xml create mode 100644 testing-drivers/testdata/incremental/harness/suiteFails.xml create mode 100644 testing-drivers/testdata/incremental/inc-suite.xml create mode 100644 testing-drivers/testdata/incremental/java/delete/DeleteMe.delete.20.java create mode 100644 testing-drivers/testdata/incremental/java/delete/DeleteMe.java create mode 100644 testing-drivers/testdata/incremental/java/delete/Main.java create mode 100644 testing-drivers/testdata/incremental/java/delete/Target.30.java create mode 100644 testing-drivers/testdata/incremental/java/delete/Target.java create mode 100644 testing-drivers/testdata/incremental/java/static/Main.30.java create mode 100644 testing-drivers/testdata/incremental/java/static/Main.40.java create mode 100644 testing-drivers/testdata/incremental/java/static/Main.60.java create mode 100644 testing-drivers/testdata/incremental/java/static/Main.java create mode 100644 testing-drivers/testdata/incremental/java/static/Target.20.java create mode 100644 testing-drivers/testdata/incremental/java/static/Target.40.java create mode 100644 testing-drivers/testdata/incremental/java/static/Target.50.java create mode 100644 testing-drivers/testdata/incremental/java/static/Target.java create mode 100644 testing-drivers/testing-drivers.mf.txt create mode 100644 testing-drivers/testsrc/TestingDriversModuleTests.java create mode 100644 testing-drivers/testsrc/org/aspectj/testing/drivers/DriversTests.java create mode 100644 testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessSelectionTest.java create mode 100644 testing-drivers/testsrc/org/aspectj/testing/drivers/SuiteTest.java diff --git a/testing-drivers/.classpath b/testing-drivers/.classpath new file mode 100644 index 000000000..e7dfb2a5f --- /dev/null +++ b/testing-drivers/.classpath @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/testing-drivers/.project b/testing-drivers/.project new file mode 100644 index 000000000..7a151fc62 --- /dev/null +++ b/testing-drivers/.project @@ -0,0 +1,25 @@ + + + testing-drivers + + + asm + bcweaver + bridge + org.aspectj.ajdt.core + org.eclipse.jdt.core + testing + testing-client + util + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/testing-drivers/readme-testing-drivers.html b/testing-drivers/readme-testing-drivers.html new file mode 100644 index 000000000..8ac8fa7fb --- /dev/null +++ b/testing-drivers/readme-testing-drivers.html @@ -0,0 +1,8 @@ + + +This project is for integration testing. +

+It depends on other projects, but requires that +they export any required libraries. + + diff --git a/testing-drivers/src/.cvsignore b/testing-drivers/src/.cvsignore new file mode 100644 index 000000000..a3f0b1b77 --- /dev/null +++ b/testing-drivers/src/.cvsignore @@ -0,0 +1 @@ +*.lst diff --git a/testing-drivers/src/org/aspectj/testing/drivers/Harness.java b/testing-drivers/src/org/aspectj/testing/drivers/Harness.java new file mode 100644 index 000000000..46e50c8ce --- /dev/null +++ b/testing-drivers/src/org/aspectj/testing/drivers/Harness.java @@ -0,0 +1,1215 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.testing.drivers; + +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.IMessageHolder; +import org.aspectj.bridge.MessageHandler; +import org.aspectj.bridge.MessageUtil; +import org.aspectj.testing.harness.bridge.AjcTest; +import org.aspectj.testing.harness.bridge.AbstractRunSpec; +import org.aspectj.testing.harness.bridge.CompilerRun; +import org.aspectj.testing.harness.bridge.FlatSuiteReader; +import org.aspectj.testing.harness.bridge.IncCompilerRun; +import org.aspectj.testing.harness.bridge.JavaRun; +import org.aspectj.testing.harness.bridge.RunSpecIterator; +import org.aspectj.testing.harness.bridge.Sandbox; +import org.aspectj.testing.harness.bridge.Validator; +import org.aspectj.testing.run.IRun; +import org.aspectj.testing.run.IRunIterator; +import org.aspectj.testing.run.IRunListener; +import org.aspectj.testing.run.IRunStatus; +import org.aspectj.testing.run.IRunValidator; +import org.aspectj.testing.run.RunListener; +import org.aspectj.testing.run.RunStatus; +import org.aspectj.testing.run.RunValidator; +import org.aspectj.testing.run.Runner; +import org.aspectj.testing.util.BridgeUtil; +import org.aspectj.testing.util.RunUtils; +import org.aspectj.testing.util.StreamsHandler; +import org.aspectj.testing.xml.AjcSpecXmlReader; +import org.aspectj.testing.xml.XMLWriter; +import org.aspectj.util.FileUtil; +import org.aspectj.util.LangUtil; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringReader; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.StringTokenizer; + +/** + * Test harness for running AjcTest.Suite test suites. + * This can be easily extended by subclassing. + *

+ * See {@link report(IRunStatus, int, int)} for an explanation of test result + * categories. + */ +public class Harness { + /** + * Spaces up to the width that an option should take in the syntax, + * including the two-space leader + */ + protected static final String SYNTAX_PAD = " "; + private static final String JAVA_VERSION; + private static final String ASPECTJ_VERSION; + static { + String version = "UNKNOWN"; + try { version = System.getProperty("java.version", "UNKNOWN"); } + catch (Throwable t) {} + JAVA_VERSION = version; + + version = "UNKNOWN"; + try { + Class c = Class.forName("org.aspectj.bridge.Version"); + version = (String) c.getField("text").get(null); + } catch (Throwable t) { + // ignore + } + ASPECTJ_VERSION = version; + } + + /** factory for the subclass currently anointed as default */ + public static Harness makeHarness() { + return new FeatureHarness(); + } + + /** @param args String[] like runMain(String[]) args */ + public static void main(String[] args) throws Exception { + if (LangUtil.isEmpty(args)) { + args = new String[] { "-help" }; + } + makeHarness().runMain(args, null); + } + + /** + * Get known option aliases. + * Subclasses may add new aliases, where the key is the alias option, + * and the value is a comma-delimited String of target options. + * @return Properties with feature aliases or null + */ + protected static Properties getOptionAliases() { + if (null == optionAliases) { + optionAliases = new Properties(); + // XXX load from **OptionAliases.properties + } + return optionAliases; + } + + /** aliases key="option" value="option{,option}" */ + private static Properties optionAliases; + + /** be extra noisy if true */ + private boolean verboseHarness; + + /** be extra quiet if true */ + private boolean quietHarness; + + /** map of feature names to features */ + private HashMap features; + + /** if true, do not delete temporary files */ + private boolean keepTemp; + + /** if true, then log results in report(..) when done */ + private boolean logResults; + + protected Harness() { + features = new HashMap(); + } + + + /** + * Entry point for a test. + * This reads in the arguments, + * creates the test suite(s) from the input file(s), + * and for each suite does setup, run, report, and cleanup. + * When arguments are read, any option ending with "-" causes + * option variants, a set of args with and another without the + * option. See {@link LangUtil.optionVariants(String[])} for + * more details. + * @param args the String[] for the test suite - use -help to get options, + * and use "-" suffixes for variants. + * @param resultList List for IRunStatus results - ignored if null + */ + public void runMain(String[] args, List resultList) { + LangUtil.throwIaxIfFalse(!LangUtil.isEmpty(args), "empty args"); + // read arguments + final ArrayList globals = new ArrayList(); + final ArrayList files = new ArrayList(); + final LinkedList argList = new LinkedList(); + argList.addAll(Arrays.asList(args)); + for (int i = 0; i < argList.size(); i++) { + String arg = (String) argList.get(i); + List aliases = aliasOptions(arg); + if (!LangUtil.isEmpty(aliases)) { + argList.remove(i); + argList.addAll(i, aliases); + i--; + continue; + } + if ("-help".equals(arg)) { + logln("java " + Harness.class.getName() + " {option|suiteFile}.."); + printSyntax(getLogStream()); + return; + } else if (isSuiteFile(arg)) { + files.add(arg); + } else if (!acceptOption(arg)) { + globals.add(arg); + } // else our options absorbed + } + if (0 == files.size()) { + logln("## Error reading arguments: at least 1 suite file required"); + logln("java " + Harness.class.getName() + " {option|suiteFile}.."); + printSyntax(getLogStream()); + return; + } + String[] globalOptions = (String[]) globals.toArray(new String[0]); + String[][] globalOptionVariants = LangUtil.optionVariants(globalOptions); + AbstractRunSpec.RT runtime = new AbstractRunSpec.RT(); + if (verboseHarness) { + runtime.setVerbose(true); + } + + // run suites read from each file + AjcTest.Suite.Spec spec; + for (Iterator iter = files.iterator(); iter.hasNext();) { + File suiteFile = new File((String) iter.next()); + if (!suiteFile.canRead()) { + logln("runMain(..) cannot read file: " + suiteFile); + continue; + } + if (null == (spec = readSuite(suiteFile))) { + logln("runMain(..) cannot read suite from file: " + suiteFile); + continue; + } + + MessageHandler holder = new MessageHandler(); + for (int i = 0; i < globalOptionVariants.length; i++) { + runtime.setOptions(globalOptionVariants[i]); + holder.init(); + boolean skip = !spec.adoptParentValues(runtime, holder); + // awful/brittle assumption about number of skips == number of skip messages + final List skipList = MessageUtil.getMessages(holder, IMessage.INFO, false, "skip"); + if (verboseHarness || skip || (0 < skipList.size())) { + final List curArgs = Arrays.asList(globalOptionVariants[i]); + logln("runMain(" + suiteFile + ", " + curArgs + ")"); + if (verboseHarness) { + String format = "yyyy.MM.dd G 'at' hh:mm:ss a zzz"; + SimpleDateFormat formatter = new SimpleDateFormat (format); + String date = formatter.format(new Date()); + logln("test date: " + date); + logln("harness features: " + listFeatureNames()); + logln("Java version: " + JAVA_VERSION); + logln("AspectJ version: " + ASPECTJ_VERSION); + } + if (!quietHarness && holder.hasAnyMessage(null, true)) { + MessageUtil.print(getLogStream(), holder, "skip - "); + MessageUtil.printMessageCounts(getLogStream(), holder, "skip - "); + } + } + if (!skip) { + final long startTime = System.currentTimeMillis(); + RunResult result = run(spec); + if (null != resultList) { + resultList.add(result); + } + final long elapsed = System.currentTimeMillis() - startTime; + report(result.status, skipList.size(), result.numIncomplete, elapsed); + } + } + } + } + + /** Run the test suite specified by the spec */ + protected RunResult run(AjcTest.Suite.Spec spec) { + LangUtil.throwIaxIfNull(spec, "spec"); + /* + * For each run, initialize the runner and validator, + * create a new set of IRun{Iterator} tests, + * and run them. + * Delete all temp files when done. + */ + Runner runner = new Runner(); + if (0 != features.size()) { + for (Iterator iter = features.entrySet().iterator(); iter.hasNext();) { + Feature feature = (Feature) ((Map.Entry) iter.next()).getValue(); + runner.registerListener(feature.clazz, feature.listener); + } + } + IMessageHolder holder = new MessageHandler(); + int numIncomplete = 0; + RunStatus status = new RunStatus(holder, runner); + status.setIdentifier(spec); + // validator is used for all setup in entire tree... + Validator validator = new Validator(status); + validator.lock(this); + Sandbox sandbox = null; + try { + sandbox = new Sandbox(spec.getSuiteDirFile(), validator); + IRunIterator tests = spec.makeRunIterator(sandbox, validator); + runner.runIterator(tests, status, null); + if (tests instanceof RunSpecIterator) { + numIncomplete = ((RunSpecIterator) tests).getNumIncomplete(); + } + } finally { + validator.unlock(this); + if (!keepTemp) { + validator.deleteTempFiles(verboseHarness); + } + } + return new RunResult(status, numIncomplete); + } + + /** + * Report the results of a test run after it is completed. + * Clients should be able to identify the number of: + *