summaryrefslogtreecommitdiffstats
path: root/luni/src/test/java/com
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 18:28:14 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 18:28:14 -0800
commit1c0fed63c71ddb230f3b304aac12caffbedf2f21 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /luni/src/test/java/com
parent2fb02ef3025449e24e756a7f645ea6eab7a1fd4f (diff)
downloadlibcore-1c0fed63c71ddb230f3b304aac12caffbedf2f21.zip
libcore-1c0fed63c71ddb230f3b304aac12caffbedf2f21.tar.gz
libcore-1c0fed63c71ddb230f3b304aac12caffbedf2f21.tar.bz2
auto import from //depot/cupcake/@135843
Diffstat (limited to 'luni/src/test/java/com')
-rw-r--r--luni/src/test/java/com/google/coretests/Main.java50
-rw-r--r--luni/src/test/java/com/google/coretests/PerfStatCollector.java257
-rw-r--r--luni/src/test/java/com/google/coretests/ResultPrinter.java157
-rw-r--r--luni/src/test/java/com/google/coretests/StatTestRunner.java230
-rw-r--r--luni/src/test/java/com/google/coretests/StatsStore.java309
-rw-r--r--luni/src/test/java/com/google/coretests/Version.java30
6 files changed, 0 insertions, 1033 deletions
diff --git a/luni/src/test/java/com/google/coretests/Main.java b/luni/src/test/java/com/google/coretests/Main.java
deleted file mode 100644
index 8dba719..0000000
--- a/luni/src/test/java/com/google/coretests/Main.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-import junit.textui.TestRunner;
-import tests.AllTests;
-
-/**
- * Main class to run the core tests.
- */
-public class Main
-{
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Running all tests...");
- TestRunner.run(AllTests.suite());
- } else if ("--stats".equals(args[0])) {
- // Delegate to new stats test runner
- String[] args2 = new String[args.length - 1];
- System.arraycopy(args, 1, args2, 0, args2.length);
-
- if (args2.length == 0) {
- System.out.println("Running all tests with stats...");
- StatTestRunner.run(AllTests.suite());
- } else {
- System.out.println("Running selected tests with stats...");
- StatTestRunner.main(args2);
- }
- } else {
- System.out.println("Running selected tests...");
- TestRunner.main(args);
- }
-
- Runtime.getRuntime().halt(0);
- }
-}
diff --git a/luni/src/test/java/com/google/coretests/PerfStatCollector.java b/luni/src/test/java/com/google/coretests/PerfStatCollector.java
deleted file mode 100644
index 11f745e..0000000
--- a/luni/src/test/java/com/google/coretests/PerfStatCollector.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-import dalvik.system.VMDebug;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestListener;
-
-import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-public class PerfStatCollector implements TestListener {
-
- public boolean listAll = false;
- public boolean listBad = false;
- public long thresholdDuration = 3600 * 1000; // in milliseconds
- public boolean twoLines = true;
- public boolean bigMarking = true;
-
- private static boolean havePreciseTime =
- VMDebug.threadCpuTimeNanos() != -1;
-
- public class Item {
- Test test;
- long startTime, duration;
- int res;
- public boolean existsInStore;
- public int id;
- public int bestRes;
- public long lastBestAt;
- public int lastRes;
- public long lastDuration;
- public int statCount;
- public double statAvgDuration;
- public long statMinDuration;
- public long statMaxDuration;
- int adhocRelevance;
- public int histRelevance;
- public boolean isTransition;
- boolean printed = false;
-
- void update(boolean rBad, long rthDurat) {
- // AdHoc Evaluation:
- if (rBad && (res != 0)) {
- // no success:
- adhocRelevance = 2;
- }
- else if (duration >= rthDurat) {
- // long duration:
- adhocRelevance = 1;
- }
- else {
- adhocRelevance = 0;
- }
-
- StatsStore.use1(this);
- }
-
- void print1(PrintStream out, boolean bigMarking) {
- switch (histRelevance) {
- case -4:
- if (bigMarking) {
- out.println();
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- out.println("Test ran SUCCESSFULLY once, but NOT this time!!!!");
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- }
- out.print("-4 VBAD"); break;
- case 4: out.print(" 4 Good"); break;
- case 3: out.print(" 3 good"); break;
- case -2: out.print("-2 SLOW"); break;
- case 2: out.print(" 2 Fast"); break;
- case 1: out.print(" 1 fast"); break;
- case -3:
- if (res == -2) out.print("-3 FAIL");
- else out.print("-3 ERR ");
- break;
- default:
- if (res == 0) out.print(" ");
- else if (res == -2) out.print(" fail");
- else out.print(" err ");
- }
- if (isTransition) out.print("! ");
- else out.print(" ");
- out.print(test.toString());
- out.format(": %d# %d(%d) [%d..%d] %.1f ms",
- statCount, duration, lastDuration,
- statMinDuration, statMaxDuration, statAvgDuration);
- out.println();
- printed = true;
- }
-
- void print2(PrintStream out, boolean bigMarking) {
- out.format("%5d. ", id);
-
- out.println(test.toString());
- out.print(" ");
-
- switch (histRelevance) {
- case -4: out.print("FAIL"); break;
- case 4: out.print("PASS"); break;
- case 3: out.print("PASS"); break;
- case -2: out.print("SLOW"); break;
- case 2: out.print("FAST"); break;
- case 1: out.print("PASS"); break;
- case -3:
- if (res == -2) out.print("FAIL");
- else out.print("ERR ");
- break;
- default:
- if (res == 0) out.print("PASS");
- else if (res == -2) out.print("FAIL");
- else out.print("XCPT");
- }
-
- out.format(" %d ms (min %d ms, max %d ms, avg %#.1f ms, %d runs)",
- duration,
- statMinDuration, statMaxDuration, statAvgDuration,
- statCount);
- out.println();
-
- printed = true;
- }
-
- void print(PrintStream out, boolean bigMarking) {
- if (twoLines) print2(out, bigMarking);
- else print1(out, bigMarking);
- }
-
- boolean checkPrint(PrintStream out) {
- if (printed) return false;
- print(out, false);
- return true;
- }
- }
-
- ArrayList<Item> items;
- Item current;
-
- PrintStream fWriter;
- int fColumn= 0;
-
- public PerfStatCollector(PrintStream writer) {
- fWriter= writer;
- items = new ArrayList();
- }
-
- synchronized void digest() {
- int totalCnt = 0;
- int adhocRelevantCnt = 0;
- int histRelevantCnt = 0;
- long evalStartTime = System.currentTimeMillis();
- PrintStream out = fWriter;
- out.println("Failure and Performance Statistics:");
- Iterator<Item> r = items.iterator();
- while (r.hasNext()) {
- Item item = r.next();
- item.update(listBad, thresholdDuration);
- if (item.histRelevance != 0) {
- item.print(out, bigMarking);
- histRelevantCnt++;
- }
- if (item.adhocRelevance != 0) {
- if (item.checkPrint(out))
- adhocRelevantCnt++;
- }
- if (listAll) item.checkPrint(out);
- totalCnt++;
- }
- long evalDuration = System.currentTimeMillis() - evalStartTime;
- out.println();
- out.print(totalCnt); out.println(" tests run totally.");
- out.print(histRelevantCnt);
- out.println(" tests listed due to historical relevance.");
-// out.print(adhocRelevantCnt);
-// out.println(" tests listed due to ad-hoc-relevance.");
-// out.print(totalCnt - histRelevantCnt - adhocRelevantCnt);
-// out.println(" tests NOT listed due to relevance.");
- out.println();
- out.print("Time used in Statistics Acquisition: ");
- out.print(evalDuration);
- out.print("ms");
- out.println();
- }
-
-
- public PrintStream getWriter() {
- return fWriter;
- }
-
- /**
- * @see junit.framework.TestListener#addError(Test, Throwable)
- */
- public void addError(Test test, Throwable t) {
- current.res = -1;
- }
-
- /**
- * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
- */
- public void addFailure(Test test, AssertionFailedError t) {
- current.res = -2;
- }
-
- /**
- * @see junit.framework.TestListener#startTest(Test)
- */
- public void startTest(Test test) {
- System.gc();
- current = new Item();
- current.test = test;
- current.startTime = currentTimeMillis();
- items.add(current);
- }
-
- /**
- * @see junit.framework.TestListener#endTest(Test)
- */
- public void endTest(Test test) {
- current.duration = currentTimeMillis() - current.startTime;
- }
-
- /*
- * Returns a "current time" in ms. Depending on the environment, this is
- * either the actual CPU time out current thread has used so far, or the
- * wall clock time of the system.
- */
- private long currentTimeMillis() {
- if (havePreciseTime) {
- return VMDebug.threadCpuTimeNanos() / 1000;
- } else {
- return System.currentTimeMillis();
- }
- }
-
-}
diff --git a/luni/src/test/java/com/google/coretests/ResultPrinter.java b/luni/src/test/java/com/google/coretests/ResultPrinter.java
deleted file mode 100644
index cfd5227..0000000
--- a/luni/src/test/java/com/google/coretests/ResultPrinter.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-import java.io.PrintStream;
-// The following line was removed for compatibility with Android libraries.
-//import java.text.NumberFormat;
-import java.util.Enumeration;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestFailure;
-import junit.framework.TestListener;
-import junit.framework.TestResult;
-import junit.runner.BaseTestRunner;
-
-public class ResultPrinter implements TestListener {
- PrintStream fWriter;
- int fColumn= 0;
-
- public ResultPrinter(PrintStream writer) {
- fWriter= writer;
- }
-
- /* API for use by textui.TestRunner
- */
-
- synchronized void print(TestResult result, long runTime) {
- printHeader(runTime);
- printErrors(result);
- printFailures(result);
- printFooter(result);
- }
-
- void printWaitPrompt() {
- getWriter().println();
- getWriter().println("<RETURN> to continue");
- }
-
- /* Internal methods
- */
-
- protected void printHeader(long runTime) {
- getWriter().println();
- getWriter().println("Time: "+elapsedTimeAsString(runTime));
- }
-
- protected void printErrors(TestResult result) {
- printDefects(result.errors(), result.errorCount(), "error");
- }
-
- protected void printFailures(TestResult result) {
- printDefects(result.failures(), result.failureCount(), "failure");
- }
-
- protected void printDefects(Enumeration booBoos, int count, String type) {
- if (count == 0) return;
- if (count == 1)
- getWriter().println("There was " + count + " " + type + ":");
- else
- getWriter().println("There were " + count + " " + type + "s:");
- for (int i= 1; booBoos.hasMoreElements(); i++) {
- printDefect((TestFailure) booBoos.nextElement(), i);
- }
- }
-
- public void printDefect(TestFailure booBoo, int count) { // only public for testing purposes
- printDefectHeader(booBoo, count);
- printDefectTrace(booBoo);
- }
-
- protected void printDefectHeader(TestFailure booBoo, int count) {
- // I feel like making this a println, then adding a line giving the throwable a chance to print something
- // before we get to the stack trace.
- getWriter().print(count + ") " + booBoo.failedTest());
- }
-
- protected void printDefectTrace(TestFailure booBoo) {
- getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));
- }
-
- protected void printFooter(TestResult result) {
- if (result.wasSuccessful()) {
- getWriter().println();
- getWriter().print("OK");
- getWriter().println (" (" + result.runCount() + " test" + (result.runCount() == 1 ? "": "s") + ")");
-
- } else {
- getWriter().println();
- getWriter().println("FAILURES!!!");
- getWriter().println("Tests run: "+result.runCount()+
- ", Failures: "+result.failureCount()+
- ", Errors: "+result.errorCount());
- }
- getWriter().println();
- }
-
-
- /**
- * Returns the formatted string of the elapsed time.
- * Duplicated from BaseTestRunner. Fix it.
- */
- protected String elapsedTimeAsString(long runTime) {
- // The following line was altered for compatibility with
- // Android libraries.
- return Double.toString((double)runTime/1000);
- }
-
- public PrintStream getWriter() {
- return fWriter;
- }
- /**
- * @see junit.framework.TestListener#addError(Test, Throwable)
- */
- public void addError(Test test, Throwable t) {
- getWriter().print("E");
- }
-
- /**
- * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
- */
- public void addFailure(Test test, AssertionFailedError t) {
- getWriter().print("F");
- }
-
- /**
- * @see junit.framework.TestListener#endTest(Test)
- */
- public void endTest(Test test) {
- }
-
- /**
- * @see junit.framework.TestListener#startTest(Test)
- */
- public void startTest(Test test) {
- getWriter().print(".");
- if (fColumn++ >= 40) {
- getWriter().println();
- fColumn= 0;
- }
- }
-
-}
diff --git a/luni/src/test/java/com/google/coretests/StatTestRunner.java b/luni/src/test/java/com/google/coretests/StatTestRunner.java
deleted file mode 100644
index b4642b8..0000000
--- a/luni/src/test/java/com/google/coretests/StatTestRunner.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-import junit.framework.Test;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-import junit.runner.BaseTestRunner;
-import junit.runner.StandardTestSuiteLoader;
-import junit.runner.TestSuiteLoader;
-
-import java.io.PrintStream;
-
-/**
- * A command line based tool to run tests.
- * <pre>
- * java junit.textui.TestRunner [-wait] TestCaseClass
- * </pre>
- * TestRunner expects the name of a TestCase class as argument.
- * If this class defines a static <code>suite</code> method it
- * will be invoked and the returned test is run. Otherwise all
- * the methods starting with "test" having no arguments are run.
- * <p>
- * When the wait command line argument is given TestRunner
- * waits until the users types RETURN.
- * <p>
- * TestRunner prints a trace as the tests are executed followed by a
- * summary at the end.
- */
-public class StatTestRunner extends BaseTestRunner {
- private ResultPrinter fPrinter;
- private PerfStatCollector fPerfStatCollector;
-
- public static final int SUCCESS_EXIT= 0;
- public static final int FAILURE_EXIT= 1;
- public static final int EXCEPTION_EXIT= 2;
-
- public static final String DEFAULT_DATABASE = "sqlite:/coretests.db";
- public static final String DEFAULT_DRIVER = "SQLite.JDBCDriver";
-
- public static String connectionURL;
- public static String jdbcDriver;
-
- /**
- * Constructs a TestRunner.
- */
- public StatTestRunner() {
- this(System.out);
- }
-
- /**
- * Constructs a TestRunner using the given stream for all the output
- */
- public StatTestRunner(PrintStream writer) {
- this(new ResultPrinter(writer));
- }
-
- /**
- * Constructs a TestRunner using the given ResultPrinter all the output
- */
- public StatTestRunner(ResultPrinter printer) {
- fPrinter= printer;
- fPerfStatCollector = new PerfStatCollector(printer.getWriter());
- }
-
- /**
- * Runs a suite extracted from a TestCase subclass.
- */
- static public void run(Class testClass) {
- run(new TestSuite(testClass));
- }
-
- /**
- * Runs a single test and collects its results.
- * This method can be used to start a test run
- * from your program.
- * <pre>
- * public static void main (String[] args) {
- * test.textui.TestRunner.run(suite());
- * }
- * </pre>
- */
- static public TestResult run(Test test) {
- StatTestRunner runner= new StatTestRunner();
- try {
- return runner.doRun(test, false);
- }
- catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Runs a single test and waits until the user
- * types RETURN.
- */
- static public void runAndWait(Test suite) {
- StatTestRunner aTestRunner= new StatTestRunner();
- try {
- aTestRunner.doRun(suite, true);
- }
- catch (Exception e) {}
- }
-
- /**
- * Always use the StandardTestSuiteLoader. Overridden from
- * BaseTestRunner.
- */
- public TestSuiteLoader getLoader() {
- return new StandardTestSuiteLoader();
- }
-
- public void testFailed(int status, Test test, Throwable t) {
- }
-
- public void testStarted(String testName) {
- }
-
- public void testEnded(String testName) {
- }
-
- public TestResult doRun(Test suite, boolean wait) throws Exception {
- StatsStore.open(jdbcDriver, connectionURL);
- TestResult result = new TestResult();
- result.addListener(fPrinter);
- result.addListener(fPerfStatCollector);
- long startTime= System.currentTimeMillis();
- StatsStore.now = startTime;
- suite.run(result);
- long endTime= System.currentTimeMillis();
- long runTime= endTime-startTime;
- fPrinter.print(result, runTime);
- fPerfStatCollector.digest();
- StatsStore.close();
-
- pause(wait);
- return result;
- }
-
- protected void pause(boolean wait) {
- if (!wait) return;
- fPrinter.printWaitPrompt();
- try {
- System.in.read();
- }
- catch(Exception e) {
- }
- }
-
- public static void main(String args[]) {
- StatTestRunner aTestRunner= new StatTestRunner();
- try {
- TestResult r= aTestRunner.start(args);
- if (!r.wasSuccessful())
- System.exit(FAILURE_EXIT);
- System.exit(SUCCESS_EXIT);
- } catch(Exception e) {
- System.err.println(e.getMessage());
- System.exit(EXCEPTION_EXIT);
- }
- }
-
- /**
- * Starts a test run. Analyzes the command line arguments
- * and runs the given test suite.
- */
- protected TestResult start(String args[]) throws Exception {
- String testCase= "";
- boolean wait= false;
-
- jdbcDriver = System.getProperty("android.coretests.driver", DEFAULT_DRIVER);
- connectionURL = System.getProperty("android.coretests.database", "jdbc:" + DEFAULT_DATABASE);
-
- for (int i= 0; i < args.length; i++) {
- if (args[i].equals("--all"))
- fPerfStatCollector.listAll = true;
- else if (args[i].equals("--bad"))
- fPerfStatCollector.listBad = true;
- else if (args[i].equals("--nobig"))
- fPerfStatCollector.bigMarking = false;
- else if (args[i].equals("--s")) {
- fPerfStatCollector.thresholdDuration =
- Integer.valueOf(args[++i]);
- } else if (args[i].equals("-wait"))
- wait= true;
- else if (args[i].equals("-c"))
- testCase= extractClassName(args[++i]);
- else if (args[i].equals("-v"))
- System.err.println("JUnit "+Version.id()+" (plus Android performance stats)");
- else
- testCase= args[i];
- }
-
- if (testCase.equals(""))
- throw new Exception("Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class");
-
- try {
- Test suite= getTest(testCase);
- return doRun(suite, wait);
- }
- catch (Exception e) {
- throw new Exception("Exception: " + e);
- }
- }
-
- protected void runFailed(String message) {
- System.err.println(message);
- System.exit(FAILURE_EXIT);
- }
-
- public void setPrinter(ResultPrinter printer) {
- fPrinter= printer;
- }
-
-
-}
diff --git a/luni/src/test/java/com/google/coretests/StatsStore.java b/luni/src/test/java/com/google/coretests/StatsStore.java
deleted file mode 100644
index 2c18ab3..0000000
--- a/luni/src/test/java/com/google/coretests/StatsStore.java
+++ /dev/null
@@ -1,309 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-
-import junit.framework.Test;
-
-import java.io.File;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-
-public class StatsStore {
-
- static final String sysVersion = "1.0";
-
- static Connection conn;
- static Statement stmt;
- static PreparedStatement insertStmt, selectByNameStmt, updateStmt;
- static PreparedStatement insertDetStmt, insertEventStmt;
- static PreparedStatement selectAllStmt;
-
- public static long now;
-
- static int compareDuration(long dur, long refDur) {
- long diff = dur - refDur;
- if (diff <= 0) {
- if ((double)-diff / refDur > 0.5) return 1; // remarkably faster
- else return 0; // equivalent duration (maybe a bit faster)
- }
- else if (diff < 20) return 0; // not measurably slower: equivalent duration
- else if ((double)diff / refDur < 0.2) return 0; // just little slower: equivalent duration
- else return -1; // relevantly SLOWer
- }
-
- static void initStats(PerfStatCollector.Item a) {
- a.statMinDuration = a.duration;
- a.statMaxDuration = a.duration;
- a.statAvgDuration = a.duration;
- a.statCount = 1;
- }
-
- static void adjustStats(PerfStatCollector.Item a) {
- if (a.duration < a.statMinDuration) a.statMinDuration = a.duration;
- else
- if (a.duration > a.statMaxDuration) a.statMaxDuration = a.duration;
- a.statAvgDuration = ((a.statAvgDuration * a.statCount + a.duration) / (a.statCount + 1));
- a.statCount++;
- }
-
- static void adjustStatsOptimistic(PerfStatCollector.Item a) {
- adjustStats(a);
- // Could consider reducing a.statMaxDuration.
- }
-
- static void use1(PerfStatCollector.Item a) {
- Test test;
- int pos;
- PreparedStatement selectStmt = selectByNameStmt;
- try {
- try {
- insertStmt.setString(1, a.test.toString());
- insertStmt.execute();
- } catch (SQLException e) {}
- selectStmt.setString(1, a.test.toString());
- ResultSet row = selectStmt.executeQuery();
- row.first();
- pos = 1;
- a.id = row.getInt(pos); pos++;
- a.bestRes = row.getInt(pos); pos++;
- a.lastBestAt = row.getLong(pos); pos++;
- a.lastRes = row.getInt(pos); pos++;
- a.lastDuration = row.getLong(pos); pos++;
- a.statCount = row.getInt(pos); pos++;
- a.statAvgDuration = row.getDouble(pos); pos++;
- a.statMinDuration = row.getLong(pos); pos++;
- a.statMaxDuration = row.getLong(pos); pos++;
- if (a.res == 0) {
- if (a.bestRes == 100) {
- a.bestRes = 0; a.lastBestAt = now;
- a.histRelevance = 0; // Good from scratch.
- a.isTransition = false;
- initStats(a);
- } else if (a.bestRes != 0) {
- a.bestRes = 0; a.lastBestAt = now;
- a.histRelevance = 4; // "Good" for the first time:
- a.isTransition = true; // was bad before.
- initStats(a);
- } else if (a.lastRes != 0) {
- a.bestRes = 0; a.lastBestAt = now;
- a.histRelevance = 3; // "good" again:
- a.isTransition = true; // was bad in between.
- adjustStats(a);
- } else {
- // res == lastRes == bestRes == 0:
- int cmp = compareDuration(a.duration, a.statMinDuration);
- if (cmp >= 0) {
- a.bestRes = 0; a.lastBestAt = now;
- if (cmp > 0) {
- a.histRelevance = 2; // "Fast"er than ever before.
- a.isTransition = true;
- adjustStatsOptimistic(a);
- } else if (compareDuration(a.duration, a.lastDuration) > 0) {
- // As fast as best but faster than last run:
- a.histRelevance = 1; // "fast" again.
- a.isTransition = true;
- adjustStatsOptimistic(a);
- } else {
- a.histRelevance = 0; // Equivalent Duration:
- a.isTransition = false; // usual good case.
- adjustStats(a);
- }
- } else {
- if (compareDuration(a.duration, a.lastDuration) < 0) {
- a.histRelevance = -2; // "SLOW"!!!
- a.isTransition = true;
- adjustStats(a);
- } else {
- a.histRelevance = -2; // Still "SLOW"!!!
- a.isTransition = false; // (But NO transition!)
- adjustStats(a);
- }
- }
- }
- } else if (a.bestRes == 0) {
- if (a.lastRes == 0) {
- a.histRelevance = -4; // "VBAD"!!!
- a.isTransition = true;
- } else {
- a.histRelevance = -4; // Still "VBAD"!!!
- a.isTransition = false; // (But NO transition!)
- }
- // DON'T adjust statistics: they should reflect good runs, only.
- } else if (a.bestRes == 100) {
- a.bestRes = -3; // Just mark as NOT good.
- a.histRelevance = -3; // Bad (initial run).
- a.isTransition = true;
- initStats(a);
- } else {
- a.histRelevance = 0; // Still Failure or Error:
- a.isTransition = false; // usual bad case.
- adjustStats(a);
- }
- pos = 1;
- updateStmt.setInt(pos, a.bestRes); pos++;
- updateStmt.setLong(pos, a.lastBestAt); pos++;
- updateStmt.setInt(pos, a.res); pos++;
- updateStmt.setLong(pos, a.duration); pos++;
- updateStmt.setInt(pos, a.statCount); pos++;
- updateStmt.setDouble(pos, a.statAvgDuration); pos++;
- updateStmt.setLong(pos, a.statMinDuration); pos++;
- updateStmt.setLong(pos, a.statMaxDuration); pos++;
- updateStmt.setInt(pos, a.id); pos++;
- updateStmt.execute();
- pos = 1;
- insertDetStmt.setInt(pos, a.id); pos++;
- insertDetStmt.setLong(pos, now); pos++;
- insertDetStmt.setInt(pos, a.statCount); pos++;
- insertDetStmt.setInt(pos, a.res); pos++;
- insertDetStmt.setLong(pos, a.duration); pos++;
- insertDetStmt.execute();
- if (a.isTransition) {
- pos = 1;
- insertEventStmt.setInt(pos, a.id); pos++;
- insertEventStmt.setLong(pos, now); pos++;
- insertEventStmt.setInt(pos, a.histRelevance); pos++;
- insertEventStmt.setInt(pos, a.res); pos++;
- insertEventStmt.setLong(pos, a.duration); pos++;
- insertEventStmt.execute();
- }
- }
- catch (SQLException e) {
- int x = 0;
- }
- }
-
-// static void use2(PerfStatCollector.Item a) {
-// }
-
- static void execOrIgnore(String sql) {
- try { stmt.execute(sql); }
- catch (SQLException e) {}
- }
-
- static void open(String jdbcDriver, String connectionURL)
- throws Exception {
-// try {
- Class.forName(jdbcDriver).newInstance();
- conn = DriverManager.getConnection(connectionURL);
- stmt = conn.createStatement();
- String dbVersion;
- try {
- ResultSet res = stmt.executeQuery("SELECT id FROM Version");
- res.first();
- dbVersion = res.getString(1);
- }
- catch (SQLException e) {
- dbVersion = "";
- }
- if (!dbVersion.equals(sysVersion)) {
- execOrIgnore("DROP TABLE Test_Cases;");
- stmt.execute("CREATE TABLE Test_Cases (" +
- " id INTEGER PRIMARY KEY AUTOINCREMENT, " +
- " name VARCHAR(255) UNIQUE, " +
- // (best_Res != 0) ==> (last_Best_At == 0) never ran good!
- " best_Res INTEGER, last_Best_At INTEGER, " +
- " last_Res INTEGER, last_Duration INTEGER, " +
- " stat_Cnt INTEGER, stat_Avg NUMBER(20, 2), " +
- " stat_Min INTEGER, stat_Max INTEGER);");
- execOrIgnore("DROP TABLE Test_Case_Runs;");
- stmt.execute("CREATE TABLE Test_Case_Runs (" +
- " test_Id INTEGER, run_At INTEGER, " +
- " iteration INTEGER, res INTEGER, duration INTEGER, " +
- " PRIMARY KEY (test_Id, run_At));");
- execOrIgnore("DROP TABLE Test_Case_Events;");
- stmt.execute("CREATE TABLE Test_Case_Events (" +
- " test_Id INTEGER, run_At INTEGER, " +
- " relevance INTEGER, " +
- " res INTEGER, duration INTEGER, " +
- " PRIMARY KEY (test_Id, run_At));");
-// stmt.execute("CREATE PROCEDURE useSample (IN pName TEXT, " +
-// "pRes INTEGER, pDuration INTEGER, pTime INTEGER) " +
-// "BEGIN " +
-// " INSERT OR IGNORE INTO TestCases (name)" +
-// " VALUES (pName);" +
-// "END;");
- execOrIgnore("DROP TABLE Version;");
- stmt.execute("CREATE TABLE Version(id VARCHAR(31));");
- stmt.execute("INSERT INTO Version (id) VALUES ('" + sysVersion + "');");
- }
-// updateStmt = conn.prepareStatement("useSample(:name, :res, :duration, :time)");
- // firstConnection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
- // firstStmt = firstConnection.createStatement();
- // firstStmt.execute("create table tbl1(one varchar(10), two smallint)");
- insertStmt = conn.prepareStatement("INSERT " +
- "INTO Test_Cases (name, stat_Cnt) VALUES (?, 0);");
- selectByNameStmt = conn.prepareStatement("SELECT id, " +
- " IFNULL(best_Res, 100), IFNULL(last_Best_At, 0), " +
- " IFNULL(last_Res, 100), IFNULL(last_Duration, 0), " +
- " IFNULL(stat_Cnt, 0), IFNULL(stat_Avg, 0), " +
- " IFNULL(stat_Min, 0), IFNULL(stat_Max, 0) " +
- "FROM Test_Cases WHERE name = ?;");
- updateStmt = conn.prepareStatement("UPDATE Test_Cases SET " +
- " best_Res = ?, last_Best_At = ?, " +
- " last_Res = ?, last_Duration = ?, " +
- " stat_Cnt = ?, stat_Avg = ?, " +
- " stat_Min = ?, stat_Max = ? " +
- "WHERE id = ?;");
- insertDetStmt = conn.prepareStatement("INSERT " +
- "INTO Test_Case_Runs (test_Id, run_At, iteration, res, duration) " +
- "VALUES (?, ?, ?, ?, ?);");
- insertEventStmt = conn.prepareStatement("INSERT " +
- "INTO Test_Case_Events (test_Id, run_At, relevance, res, duration) " +
- "VALUES (?, ?, ?, ?, ?);");
- selectAllStmt = conn.prepareStatement("SELECT id, name, " +
- "last_Res, stat_Cnt, " +
- "last_Duration, stat_Avg, stat_Min, stat_Max " +
- "FROM Test_Cases;");
-
- try {
-// ResultSet res = stmt.executeQuery("PRAGMA CACHE_SIZE;");
-// res.first();
-// System.out.print("CACHE_SIZE = ");
-// System.out.println(res.getString(1));
-// stmt.execute("PRAGMA CACHE_SIZE = 5000;");
- stmt.execute("PRAGMA SYNCHRONOUS = OFF;");
- stmt.execute("PRAGMA temp_store = MEMORY;");
- }
- catch (SQLException e) {
- dbVersion = "";
- }
- stmt.close();
- conn.commit();
-// }
-// catch (Exception e) {
-// conn = null;
-// }
-// return conn != null;
- }
-
- static void close() {
- try {
- conn.commit();
- conn.close();
- conn = null;
- }
- catch (Exception e) {
- conn = null;
- }
- }
-}
diff --git a/luni/src/test/java/com/google/coretests/Version.java b/luni/src/test/java/com/google/coretests/Version.java
deleted file mode 100644
index e76a6bb..0000000
--- a/luni/src/test/java/com/google/coretests/Version.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-/**
- * This class defines the current version of JUnit
- */
-public class Version {
- private Version() {
- // don't instantiate
- }
-
- public static String id() {
- return "0.1";
- }
-}