am dc4e179: AI 148315: CTS: Import existing sessions from result directo
Merge commit 'dc4e179f1821bbeac2e66a383beb51c2edbb7d55' into donut
* commit 'dc4e179f1821bbeac2e66a383beb51c2edbb7d55':
AI 148315: CTS: Import existing sessions from result directory when restarting console
diff --git a/tools/host/src/com/android/cts/CtsTestResult.java b/tools/host/src/com/android/cts/CtsTestResult.java
index e0e9e82..9860c83 100644
--- a/tools/host/src/com/android/cts/CtsTestResult.java
+++ b/tools/host/src/com/android/cts/CtsTestResult.java
@@ -47,6 +47,7 @@
public static final String STR_PASS = "pass";
private static HashMap<Integer, String> sCodeToResultMap;
+ private static HashMap<String, Integer> sResultToCodeMap;
static {
sCodeToResultMap = new HashMap<Integer, String>();
sCodeToResultMap.put(CODE_NOT_EXECUTED, STR_NOT_EXECUTED);
@@ -54,6 +55,10 @@
sCodeToResultMap.put(CODE_FAIL, STR_FAIL);
sCodeToResultMap.put(CODE_ERROR, STR_ERROR);
sCodeToResultMap.put(CODE_TIMEOUT, STR_TIMEOUT);
+ sResultToCodeMap = new HashMap<String, Integer>();
+ for (int code : sCodeToResultMap.keySet()) {
+ sResultToCodeMap.put(sCodeToResultMap.get(code), code);
+ }
}
public CtsTestResult(int resCode) {
@@ -66,6 +71,17 @@
mStackTrace = stackTrace;
}
+ public CtsTestResult(final String result, final String failedMessage,
+ final String stackTrace) throws InvalidTestResultStringException {
+ if (!sResultToCodeMap.containsKey(result)) {
+ throw new InvalidTestResultStringException(result);
+ }
+
+ mResultCode = sResultToCodeMap.get(result);
+ mFailedMessage = failedMessage;
+ mStackTrace = stackTrace;
+ }
+
/**
* Check if the result indicates failure.
*
@@ -178,6 +194,6 @@
* @return If valid, return true; else, return false.
*/
static public boolean isValidResultType(final String resultType) {
- return sCodeToResultMap.containsValue(resultType);
+ return sResultToCodeMap.containsKey(resultType);
}
}
diff --git a/tools/host/src/com/android/cts/HostConfig.java b/tools/host/src/com/android/cts/HostConfig.java
index dd1ac40..543ee6a 100644
--- a/tools/host/src/com/android/cts/HostConfig.java
+++ b/tools/host/src/com/android/cts/HostConfig.java
@@ -64,10 +64,10 @@
private String mConfigRoot;
private CaseRepository mCaseRepos;
- private Repository mResultRepos;
+ private ResultRepository mResultRepos;
private PlanRepository mPlanRepos;
private HashMap<String, TestPackage> mTestPackageMap;
-
+
enum Ints {
// Number of tests executed between reboots. A value <= 0 disables reboots.
maxTestCount (200),
@@ -85,17 +85,17 @@
packageInstallTimeoutMs (2 * 60 * 1000),
// Time to wait [ms] after a package installation or removal
postInstallWaitMs (30 * 1000);
-
+
private int value;
-
+
Ints(int value) {
this.value = value;
}
-
+
int value() {
return value;
}
-
+
void setValue(int value) {
this.value = value;
}
@@ -118,7 +118,7 @@
public static int getMaxTestCount() {
return Ints.maxTestCount.value();
}
-
+
/**
* Load configuration.
*
@@ -126,7 +126,7 @@
* @return If succeed in loading, return true; else, return false.
*/
public boolean load(String configPath) throws SAXException, IOException,
- ParserConfigurationException, NoSuchAlgorithmException {
+ ParserConfigurationException {
String fileName = null;
String[] subDirs = configPath.split("\\" + File.separator);
@@ -166,7 +166,7 @@
}
getConfigValues(doc);
-
+
String caseRoot = repositoryRoot + File.separator + caseCfg;
String planRoot = repositoryRoot + File.separator + planCfg;
String resRoot = repositoryRoot + File.separator + resCfg;
@@ -188,19 +188,14 @@
}
mCaseRepos = new CaseRepository(caseRoot);
- mResultRepos = new Repository(resRoot);
+ mResultRepos = new ResultRepository(resRoot);
mPlanRepos = new PlanRepository(planRoot);
- boolean validConfig = validCase && validRes && validPlan;
- if (validConfig) {
- loadTestPackages();
- }
-
- return validConfig;
+ return validCase && validRes && validPlan;
}
/**
- * Extract the result resources into the specified diretory.
+ * Extract the result resources into the specified directory.
*
* @param resRoot the directory to extract the resources into.
*/
@@ -230,6 +225,21 @@
}
/**
+ * Load repositories.
+ */
+ public void loadRepositories() throws NoSuchAlgorithmException {
+ loadTestPackages();
+ loadTestResults();
+ }
+
+ /**
+ * Load test results to create session accordingly.
+ */
+ private void loadTestResults() {
+ getResultRepository().loadTestResults();
+ }
+
+ /**
* Load all of the test packages.
*/
public void loadTestPackages() throws NoSuchAlgorithmException {
@@ -302,10 +312,10 @@
return cfgStr;
}
-
+
/**
* Load configuration values from config file.
- *
+ *
* @param doc The document from which to load the values.
*/
private void getConfigValues(final Document doc) {
@@ -400,7 +410,7 @@
*
* @return The result repository.
*/
- public Repository getResultRepository() {
+ public ResultRepository getResultRepository() {
return mResultRepos;
}
@@ -423,11 +433,59 @@
public String getRoot() {
return mRoot;
}
+
+ /**
+ * Check if the specified file is a valid XML file.
+ *
+ * @param f The file to be valid.
+ * @return If valid XML file, return true; else, return false.
+ */
+ public boolean isValidXmlFile(File f) {
+ if (f.getPath().endsWith(FILE_SUFFIX_XML)) {
+ return true;
+ }
+
+ return false;
+ }
}
/**
+ * Storing the information of result repository.
+ */
+ class ResultRepository extends Repository {
+
+ ResultRepository(String root) {
+ super(root);
+ }
+
+ /**
+ * Load test results to create session accordingly.
+ */
+ public void loadTestResults() {
+
+ for (File f : new File(mRoot).listFiles()) {
+ if (f.isDirectory()) {
+ String pathName = mRoot + File.separator + f.getName()
+ + File.separator + TestSessionLog.CTS_RESULT_FILE_NAME;
+ if (HostUtils.isFileExist(pathName)) {
+ try {
+ TestSessionLog log =
+ TestSessionLogBuilder.getInstance().build(pathName);
+ TestSession ts = TestSessionBuilder.getInstance().build(log);
+ if (ts != null) {
+ TestHost.getInstance().addSession(ts);
+ }
+ } catch (Exception e) {
+ Log.e("Error importing existing result from " + pathName, e);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
* Storing the information of case repository.
- *
*/
class CaseRepository extends Repository {
CaseRepository(String root) {
@@ -548,21 +606,6 @@
}
/**
- * Check if the specified file is a valid XML file.
- *
- * @param f The file to be valid.
- * @return If valid XML file, return true; else, return false.
- */
- private boolean isValidXmlFile(File f) {
- String filePath = f.getPath();
- if (!filePath.endsWith(FILE_SUFFIX_XML)) {
- return false;
- }
-
- return true;
- }
-
- /**
* Add package to case repository.
*
* @param packagePath The package to be added.
diff --git a/tools/host/src/com/android/cts/InvalidTestResultStringException.java b/tools/host/src/com/android/cts/InvalidTestResultStringException.java
new file mode 100644
index 0000000..4ac667f
--- /dev/null
+++ b/tools/host/src/com/android/cts/InvalidTestResultStringException.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2009 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.android.cts;
+
+/**
+ * Thrown to indicate that the test result string is not valid.
+ */
+public class InvalidTestResultStringException extends Exception {
+ private String mTestResultString;
+
+ public InvalidTestResultStringException(String resultString) {
+ super();
+
+ mTestResultString = resultString;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String getMessage() {
+ return "Invalid test result string: " + mTestResultString;
+ }
+}
diff --git a/tools/host/src/com/android/cts/Test.java b/tools/host/src/com/android/cts/Test.java
index d122105..9e3f0bd 100644
--- a/tools/host/src/com/android/cts/Test.java
+++ b/tools/host/src/com/android/cts/Test.java
@@ -193,6 +193,18 @@
}
/**
+ * Add test result.
+ *
+ * @param result The result.
+ */
+ public void addResult(CtsTestResult result) {
+ if (isKnownFailure()) {
+ result.reverse();
+ }
+ mResult = result;
+ }
+
+ /**
* Get the result.
*
* @return the result.
diff --git a/tools/host/src/com/android/cts/TestHost.java b/tools/host/src/com/android/cts/TestHost.java
index 5425f75..7d86ffe 100644
--- a/tools/host/src/com/android/cts/TestHost.java
+++ b/tools/host/src/com/android/cts/TestHost.java
@@ -361,12 +361,13 @@
if (loadConfig(filePath) == false) {
exit();
}
+
+ Log.initLog(sConfig.getConfigRoot());
+ sConfig.loadRepositories();
} catch (Exception e) {
Log.e("Error while parsing cts config file", e);
exit();
}
-
- Log.initLog(sConfig.getConfigRoot());
return cp;
}
@@ -410,7 +411,7 @@
* @return If succeed, return true; else, return false.
*/
static boolean loadConfig(final String configPath) throws SAXException,
- IOException, ParserConfigurationException, NoSuchAlgorithmException {
+ IOException, ParserConfigurationException {
sConfig = HostConfig.getInstance();
return sConfig.load(configPath);
@@ -453,6 +454,7 @@
return;
}
+ ts.setObserver(getInstance());
TestDevice device = sDeviceManager.allocateFreeDeviceById(deviceId);
TestSessionLog sessionLog = ts.getSessionLog();
ts.setTestDevice(device);
@@ -510,7 +512,6 @@
String testPlanPath = sConfig.getPlanRepository().getPlanPath(testPlanName);
TestSession ts = TestSessionBuilder.getInstance().build(testPlanPath);
- ts.setObserver(getInstance());
sSessions.add(ts);
return ts;
@@ -688,4 +689,13 @@
}
return rawPlanName;
}
+
+ /**
+ * Add test session.
+ *
+ * @param ts The test session.
+ */
+ public void addSession(TestSession ts) {
+ sSessions.add(ts);
+ }
}
diff --git a/tools/host/src/com/android/cts/TestSession.java b/tools/host/src/com/android/cts/TestSession.java
index 7ee1954..2ac840b 100644
--- a/tools/host/src/com/android/cts/TestSession.java
+++ b/tools/host/src/com/android/cts/TestSession.java
@@ -141,6 +141,9 @@
* @return device ID.
*/
public String getDeviceId() {
+ if (mDevice == null) {
+ return null;
+ }
return mDevice.getSerialNumber();
}
@@ -213,11 +216,6 @@
}
mStatus = STATUS.STARTED;
- String resultPath = mSessionLog.getResultPath();
- if ((resultPath == null) || (resultPath.length() == 0)) {
- mSessionLog.setStartTime(System.currentTimeMillis());
- }
-
startImpl();
}
@@ -225,6 +223,10 @@
* Implement starting/resuming session.
*/
private void startImpl() throws ADBServerNeedRestartException {
+ String resultPath = mSessionLog.getResultPath();
+ if ((resultPath == null) || (resultPath.length() == 0)) {
+ mSessionLog.setStartTime(System.currentTimeMillis());
+ }
resetTestCount();
mTestThread.start();
try {
diff --git a/tools/host/src/com/android/cts/TestSessionBuilder.java b/tools/host/src/com/android/cts/TestSessionBuilder.java
index 7b2645d..c592476 100644
--- a/tools/host/src/com/android/cts/TestSessionBuilder.java
+++ b/tools/host/src/com/android/cts/TestSessionBuilder.java
@@ -54,11 +54,10 @@
private static final String ATTRIBUTE_RUNNER = "runner";
private static final String ATTRIBUTE_JAR_PATH = "jarPath";
private static final String ATTRIBUTE_APP_NAME_SPACE = "appNameSpace";
- private static final String ATTRIBUTE_APP_PACKAGE_NAME = "appPackageName";
+ public static final String ATTRIBUTE_APP_PACKAGE_NAME = "appPackageName";
private static final String ATTRIBUTE_TARGET_NAME_SPACE = "targetNameSpace";
private static final String ATTRIBUTE_TARGET_BINARY_NAME = "targetBinaryName";
private static final String ATTRIBUTE_TYPE = "type";
- private static final String ATTRIBUTE_METHOD = "method";
private static final String ATTRIBUTE_CONTROLLER = "HostController";
private static final String ATTRIBUTE_KNOWN_FAILURE = "KnownFailure";
private static final String ATTRIBUTE_HOST_SIDE_ONLY = "hostSideOnly";
@@ -84,10 +83,23 @@
}
/**
+ * Create TestSession via TestSessionLog.
+ *
+ * @param log The test session log.
+ * @return The test session.
+ */
+ public TestSession build(TestSessionLog log) {
+ if (log == null) {
+ return null;
+ }
+ return new TestSession(log, 1);
+ }
+
+ /**
* Create TestSession via TestPlan XML configuration file.
*
- * @param config TestPlan XML configuration file
- * @return TestSession
+ * @param config TestPlan XML configuration file.
+ * @return TestSession.
*/
public TestSession build(final String config) throws SAXException, IOException,
TestPlanNotFoundException, TestNotFoundException, NoSuchAlgorithmException {
@@ -183,31 +195,43 @@
public TestPackage loadPackage(final File packageConfigFile, ArrayList<String> excludedList)
throws SAXException, IOException, NoSuchAlgorithmException {
Node pNode = mDocBuilder.parse(packageConfigFile).getDocumentElement();
+ return loadPackage(pNode, excludedList);
+ }
+
+ /**
+ * Load TestPackage via Package XML configuration file.
+ *
+ * @param pkgNode the test package node in the XML file
+ * @param excludedList The list containing the excluded suites and sub types.
+ * @return loaded TestPackage from test package XML configuration file
+ */
+ public TestPackage loadPackage(final Node pkgNode, ArrayList<String> excludedList)
+ throws NoSuchAlgorithmException {
String appBinaryName, targetNameSpace, targetBinaryName, version, frameworkVersion,
runner, jarPath, appNameSpace, appPackageName, hostSideOnly;
- NodeList suiteList = pNode.getChildNodes();
+ NodeList suiteList = pkgNode.getChildNodes();
- appBinaryName = getStringAttributeValue(pNode, ATTRIBUTE_NAME);
- targetNameSpace = getStringAttributeValue(pNode, ATTRIBUTE_TARGET_NAME_SPACE);
- targetBinaryName = getStringAttributeValue(pNode, ATTRIBUTE_TARGET_BINARY_NAME);
- version = getStringAttributeValue(pNode, ATTRIBUTE_VERSION);
- frameworkVersion = getStringAttributeValue(pNode, ATTRIBUTE_FRAMEWORK_VERSION);
- runner = getStringAttributeValue(pNode, ATTRIBUTE_RUNNER);
- jarPath = getStringAttributeValue(pNode, ATTRIBUTE_JAR_PATH);
- appNameSpace = getStringAttributeValue(pNode, ATTRIBUTE_APP_NAME_SPACE);
- appPackageName = getStringAttributeValue(pNode, ATTRIBUTE_APP_PACKAGE_NAME);
- hostSideOnly = getStringAttributeValue(pNode, ATTRIBUTE_HOST_SIDE_ONLY);
- String signature = getStringAttributeValue(pNode, ATTRIBUTE_SIGNATURE_CHECK);
- String referenceAppTest = getStringAttributeValue(pNode, ATTRIBUTE_REFERENCE_APP_TEST);
+ appBinaryName = getStringAttributeValue(pkgNode, ATTRIBUTE_NAME);
+ targetNameSpace = getStringAttributeValue(pkgNode, ATTRIBUTE_TARGET_NAME_SPACE);
+ targetBinaryName = getStringAttributeValue(pkgNode, ATTRIBUTE_TARGET_BINARY_NAME);
+ version = getStringAttributeValue(pkgNode, ATTRIBUTE_VERSION);
+ frameworkVersion = getStringAttributeValue(pkgNode, ATTRIBUTE_FRAMEWORK_VERSION);
+ runner = getStringAttributeValue(pkgNode, ATTRIBUTE_RUNNER);
+ jarPath = getStringAttributeValue(pkgNode, ATTRIBUTE_JAR_PATH);
+ appNameSpace = getStringAttributeValue(pkgNode, ATTRIBUTE_APP_NAME_SPACE);
+ appPackageName = getStringAttributeValue(pkgNode, ATTRIBUTE_APP_PACKAGE_NAME);
+ hostSideOnly = getStringAttributeValue(pkgNode, ATTRIBUTE_HOST_SIDE_ONLY);
+ String signature = getStringAttributeValue(pkgNode, ATTRIBUTE_SIGNATURE_CHECK);
+ String referenceAppTest = getStringAttributeValue(pkgNode, ATTRIBUTE_REFERENCE_APP_TEST);
TestPackage pkg = null;
if ("true".equals(referenceAppTest)) {
- String apkToTestName = getStringAttributeValue(pNode, ATTRIBUTE_APK_TO_TEST_NAME);
- String packageUnderTest = getStringAttributeValue(pNode, ATTRIBUTE_PACKAGE_TO_TEST);
+ String apkToTestName = getStringAttributeValue(pkgNode, ATTRIBUTE_APK_TO_TEST_NAME);
+ String packageUnderTest = getStringAttributeValue(pkgNode, ATTRIBUTE_PACKAGE_TO_TEST);
pkg = new ReferenceAppTestPackage(runner, appBinaryName, targetNameSpace,
targetBinaryName, version, frameworkVersion, jarPath,
- appNameSpace, appPackageName,
+ appNameSpace, appPackageName,
apkToTestName, packageUnderTest);
} else if ("true".equals(signature)) {
pkg = new SignatureCheckPackage(runner, appBinaryName, targetNameSpace,
@@ -357,31 +381,7 @@
Node testNode = mNodes.item(t);
if ((testNode.getNodeType() == Document.ELEMENT_NODE)
&& (testNode.getNodeName().equals(TAG_TEST))) {
- String cType = getStringAttributeValue(testNode, ATTRIBUTE_TYPE);
- String name = getStringAttributeValue(testNode, ATTRIBUTE_METHOD);
- String description = getStringAttributeValue(testNode,
- ATTRIBUTE_CONTROLLER);
- String knownFailure = getStringAttributeValue(testNode,
- ATTRIBUTE_KNOWN_FAILURE);
- String fullJarPath =
- HostConfig.getInstance().getCaseRepository().getRoot()
- + File.separator + pkg.getJarPath();
-
- Test test = null;
- if (pkg.isHostSideOnly()) {
- test = new HostSideOnlyTest(testCase, name, cType,
- knownFailure,
- CtsTestResult.CODE_NOT_EXECUTED);
- description = test.getFullName();
- } else {
- test = new Test(testCase, name, cType,
- knownFailure,
- CtsTestResult.CODE_NOT_EXECUTED);
- }
-
- TestController controller =
- genTestControler(fullJarPath, description);
- test.setTestController(controller);
+ Test test = loadTest(pkg, testCase, testNode);
if (!checkFullMatch(excludedCaseList, test.getFullName())) {
testCase.addTest(test);
} else {
@@ -403,6 +403,91 @@
}
/**
+ * Load test via test node.
+ *
+ * @param pkg The test package.
+ * @param testCase The test case.
+ * @param testNode The test node.
+ * @return The test loaded.
+ */
+ private Test loadTest(final TestPackage pkg, TestCase testCase,
+ Node testNode) {
+ String cType = getStringAttributeValue(testNode, ATTRIBUTE_TYPE);
+ String name = getStringAttributeValue(testNode, ATTRIBUTE_NAME);
+ String description = getStringAttributeValue(testNode,
+ ATTRIBUTE_CONTROLLER);
+ String knownFailure = getStringAttributeValue(testNode,
+ ATTRIBUTE_KNOWN_FAILURE);
+ String fullJarPath =
+ HostConfig.getInstance().getCaseRepository().getRoot()
+ + File.separator + pkg.getJarPath();
+ CtsTestResult testResult = loadTestResult(testNode);
+ Test test = null;
+ if (pkg.isHostSideOnly()) {
+ test = new HostSideOnlyTest(testCase, name, cType,
+ knownFailure,
+ CtsTestResult.CODE_NOT_EXECUTED);
+ description = test.getFullName();
+ } else {
+ test = new Test(testCase, name, cType,
+ knownFailure,
+ CtsTestResult.CODE_NOT_EXECUTED);
+ }
+
+ TestController controller =
+ genTestControler(fullJarPath, description);
+ test.setTestController(controller);
+ if (testResult != null) {
+ test.addResult(testResult);
+ }
+ return test;
+ }
+
+ /**
+ * Load the CTS test result from the test node.
+ *
+ * @param testNode The test node.
+ * @return The CTS test result.
+ */
+ private CtsTestResult loadTestResult(Node testNode) {
+ String result = getStringAttributeValue(testNode,
+ TestSessionLog.ATTRIBUTE_RESULT);
+
+ String failedMessage = null;
+ String stackTrace = null;
+ NodeList nodes = testNode.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i ++) {
+ Node rNode = nodes.item(i);
+ if ((rNode.getNodeType() == Document.ELEMENT_NODE)
+ && (rNode.getNodeName().equals(TestSessionLog.TAG_FAILED_SCENE))) {
+ failedMessage = getStringAttributeValue(rNode, TestSessionLog.TAG_FAILED_MESSAGE);
+ stackTrace = getStringAttributeValue(rNode, TestSessionLog.TAG_STACK_TRACE);
+ if (stackTrace == null) {
+ NodeList sNodeList = rNode.getChildNodes();
+ for (int j = 0; j < sNodeList.getLength(); j ++) {
+ Node sNode = sNodeList.item(i);
+ if ((sNode.getNodeType() == Document.ELEMENT_NODE)
+ && (sNode.getNodeName().equals(TestSessionLog.TAG_STACK_TRACE))) {
+ stackTrace = sNode.getTextContent();
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ CtsTestResult testResult = null;
+ if (result != null) {
+ try {
+ testResult = new CtsTestResult(result, failedMessage, stackTrace);
+ } catch (InvalidTestResultStringException e) {
+ }
+ }
+
+ return testResult;
+ }
+
+ /**
* Generate controller according to the description string.
*
* @return The test controller.
@@ -434,7 +519,7 @@
private String getFullSuiteName(Node node) {
StringBuilder buf = new StringBuilder();
buf.append(getStringAttributeValue(node, TestPlan.Attribute.NAME));
-
+
Node parent = node.getParentNode();
while (parent != null) {
if (parent.getNodeType() == Document.ELEMENT_NODE
diff --git a/tools/host/src/com/android/cts/TestSessionLog.java b/tools/host/src/com/android/cts/TestSessionLog.java
index e975912..32dc038 100644
--- a/tools/host/src/com/android/cts/TestSessionLog.java
+++ b/tools/host/src/com/android/cts/TestSessionLog.java
@@ -40,12 +40,12 @@
private static final String EXPR_TEST_FAILED = ".+\\((\\S+):(\\d+)\\)";
private static Pattern mTestFailedPattern = Pattern.compile(EXPR_TEST_FAILED);
private static final String ATTRIBUTE_NAME = "name";
- private static final String ATTRIBUTE_RESULT = "result";
+ static final String ATTRIBUTE_RESULT = "result";
private static final String ATTRIBUTE_VERSION = "version";
private static final String ATTRIBUTE_DIGEST = "digest";
private static final String ATTRIBUTE_KNOWN_FAILURE = "KnownFailure";
- private static final String CTS_RESULT_FILE_NAME = "testResult.xml";
+ public static final String CTS_RESULT_FILE_NAME = "testResult.xml";
private static final String CTS_RESULT_FILE_VERSION = "1.1";
static final String ATTRIBUTE_STARTTIME = "starttime";
@@ -83,6 +83,7 @@
static final String TAG_SCREEN = "Screen";
static final String TAG_BUILD_INFO = "BuildInfo";
static final String TAG_PHONE_SUB_INFO = "PhoneSubInfo";
+ static final String TAG_TEST_RESULT = "TestResult";
static final String TAG_TESTPACKAGE = "TestPackage";
static final String TAG_TESTSUITE = "TestSuite";
static final String TAG_TESTCASE = "TestCase";
@@ -266,7 +267,7 @@
ProcessingInstruction pr = doc.createProcessingInstruction(
"xml-stylesheet", "type=\"text/xsl\" href=\"cts_result.xsl\"");
doc.appendChild(pr);
- Node root = doc.createElement("TestResult");
+ Node root = doc.createElement(TAG_TEST_RESULT);
doc.appendChild(root);
setAttribute(doc, root, ATTRIBUTE_VERSION, CTS_RESULT_FILE_VERSION);
@@ -355,7 +356,9 @@
for (TestPackage testPackage : mTestPackages) {
Node testPackageNode = doc.createElement(TAG_TESTPACKAGE);
- setAttribute(doc, testPackageNode, ATTRIBUTE_NAME, testPackage.getAppPackageName());
+ setAttribute(doc, testPackageNode, ATTRIBUTE_NAME, testPackage.getAppBinaryName());
+ setAttribute(doc, testPackageNode, TestSessionBuilder.ATTRIBUTE_APP_PACKAGE_NAME,
+ testPackage.getAppPackageName());
setAttribute(doc, testPackageNode, ATTRIBUTE_DIGEST,
testPackage.getMessageDigest());
diff --git a/tools/host/src/com/android/cts/TestSessionLogBuilder.java b/tools/host/src/com/android/cts/TestSessionLogBuilder.java
new file mode 100644
index 0000000..2ad82db
--- /dev/null
+++ b/tools/host/src/com/android/cts/TestSessionLogBuilder.java
@@ -0,0 +1,127 @@
+/*
+ * 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.android.cts;
+
+import java.io.File;
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * Builder of test session from the test result XML file.
+ */
+public class TestSessionLogBuilder extends XMLResourceHandler {
+ private static TestSessionLogBuilder sInstance;
+
+ private DocumentBuilder mDocBuilder;
+
+ public static TestSessionLogBuilder getInstance()
+ throws ParserConfigurationException {
+ if (sInstance == null) {
+ sInstance = new TestSessionLogBuilder();
+ }
+
+ return sInstance;
+ }
+
+ private TestSessionLogBuilder() throws ParserConfigurationException {
+ mDocBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ }
+
+ /**
+ * Create TestSessionLog from the result XML file.
+ *
+ * @param resultFilePath The result file path.
+ * @return TestSessionLog.
+ */
+ public TestSessionLog build(final String resultFilePath) throws SAXException, IOException,
+ TestPlanNotFoundException, TestNotFoundException,
+ NoSuchAlgorithmException, ParserConfigurationException {
+
+ File file = new File(resultFilePath);
+ if (!file.exists()) {
+ throw new TestPlanNotFoundException();
+ }
+
+ Document doc = mDocBuilder.parse(file);
+ return loadSessionLog(doc);
+ }
+
+ /**
+ * Load TestSessionLog from a Test result DOM doc.
+ *
+ * @param doc Test result DOM Document.
+ * @return loaded test session log from Test result DOM Document.
+ */
+ private TestSessionLog loadSessionLog(Document doc)
+ throws NoSuchAlgorithmException, ParserConfigurationException,
+ SAXException, IOException, TestPlanNotFoundException,
+ TestNotFoundException {
+
+ ArrayList<TestPackage> pkgsFromResult = new ArrayList<TestPackage>();
+ NodeList resultList = doc.getElementsByTagName(TestSessionLog.TAG_TEST_RESULT);
+
+ // currently, there should be just one test result tag in the result file
+ Node resultNode = resultList.item(0);
+ String planName = getStringAttributeValue(resultNode, TestSessionLog.ATTRIBUTE_TESTPLAN);
+ String planFilePath = HostConfig.getInstance().getPlanRepository().getPlanPath(planName);
+ TestSession sessionFromPlan = TestSessionBuilder.getInstance().build(planFilePath);
+
+ NodeList pkgList = resultNode.getChildNodes();
+ for (int i = 0; i < pkgList.getLength(); i++) {
+ Node pkgNode = pkgList.item(i);
+ if (pkgNode.getNodeType() == Document.ELEMENT_NODE
+ && TestSessionLog.TAG_TESTPACKAGE.equals(pkgNode.getNodeName())) {
+ TestPackage pkg = TestSessionBuilder.getInstance().loadPackage(pkgNode, null);
+ if (pkg != null) {
+ pkgsFromResult.add(pkg);
+ }
+ }
+ }
+
+ Collection<TestPackage> pkgsFromPlan = sessionFromPlan.getSessionLog().getTestPackages();
+ for (TestPackage pkgFromPlan : pkgsFromPlan) {
+ for (TestPackage pkgFromResult : pkgsFromResult) {
+ if (pkgFromPlan.getAppPackageName().equals(pkgFromResult.getAppPackageName())) {
+ Collection<Test> testsFromPlan = pkgFromPlan.getTests();
+ Collection<Test> testsFromResult = pkgFromResult.getTests();
+ for (Test testFromPlan : testsFromPlan) {
+ for (Test testFromResult : testsFromResult) {
+ if (testFromPlan.getFullName().equals(testFromResult.getFullName())) {
+ CtsTestResult result = testFromResult.getResult();
+ testFromPlan.addResult(testFromResult.getResult());
+ break;
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ return new TestSessionLog(pkgsFromPlan, planName);
+ }
+}
diff --git a/tools/host/test/com/android/cts/ConsoleTests.java b/tools/host/test/com/android/cts/ConsoleTests.java
index ed44a24..81f4958 100644
--- a/tools/host/test/com/android/cts/ConsoleTests.java
+++ b/tools/host/test/com/android/cts/ConsoleTests.java
@@ -277,6 +277,7 @@
* @param xmlMsg The message as the content of the package.
* @param packageName The package name.
*/
+ @Override
protected void createTestPackage(String xmlMsg, String packageName) throws IOException {
String caseRoot = ROOT;
@@ -355,7 +356,7 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Cases -->\n"
- + " <Test method=\"" + testName + "\"" + " type=\"automatic\"" + ">\n"
+ + " <Test name=\"" + testName + "\"" + " type=\"automatic\"" + ">\n"
+ " <Description>Simple deadloop test</Description>"
+ " </Test>"
+ " </TestCase>"
diff --git a/tools/host/test/com/android/cts/TestPlanBuilderTests.java b/tools/host/test/com/android/cts/TestPlanBuilderTests.java
index ba9e4ed..7f2f74e 100644
--- a/tools/host/test/com/android/cts/TestPlanBuilderTests.java
+++ b/tools/host/test/com/android/cts/TestPlanBuilderTests.java
@@ -67,14 +67,14 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " <TestSuite name=\"TestSuiteName\">\n"
+ " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testName1\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " </TestSuite>\n"
@@ -147,16 +147,16 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"" + testName1 + "\" type=\"automatic\"" + "/>\n"
+ + " <Test name=\"" + testName1 + "\" type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " <TestSuite name=\"" + nestedSuiteName1+ "\"" + ">\n"
+ " <TestSuite name=\"" + nestedSuiteName2+ "\"" + ">\n"
+ " <TestCase name=\"" + cName2 + "\"" + " priority=\"mandatory\">\n"
- + " <Test method=\"" + testName2 +"\" type=\"automatic\" />\n"
- + " <Test method=\"" + testName3 +"\" type=\"automatic\" />\n"
- + " <Test method=\"" + testName4 +"\" type=\"automatic\" />\n"
- + " <Test method=\"" + testName5 +"\" type=\"automatic\" />\n"
+ + " <Test name=\"" + testName2 +"\" type=\"automatic\" />\n"
+ + " <Test name=\"" + testName3 +"\" type=\"automatic\" />\n"
+ + " <Test name=\"" + testName4 +"\" type=\"automatic\" />\n"
+ + " <Test name=\"" + testName5 +"\" type=\"automatic\" />\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " </TestSuite>\n"
@@ -223,21 +223,21 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"" + testName1 + "\" type=\"automatic\"" + "/>\n"
+ + " <Test name=\"" + testName1 + "\" type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " <TestSuite name=\"" + nestedSuiteName1+ "\"" + ">\n"
+ " <TestSuite name=\"" + nestedSuiteName2+ "\"" + ">\n"
+ " <TestCase name=\"" + cName2 + "\"" + " priority=\"mandatory\">\n"
- + " <Test method=\"" + testName2 +"\" type=\"automatic\" />\n"
- + " <Test method=\"" + testName3 +"\" type=\"automatic\" />\n"
+ + " <Test name=\"" + testName2 +"\" type=\"automatic\" />\n"
+ + " <Test name=\"" + testName3 +"\" type=\"automatic\" />\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " <TestCase name=\"" + caseName1 + "\"" + " category=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"" + testName1 + "\" type=\"automatic\"" + "/>\n"
+ + " <Test name=\"" + testName1 + "\" type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ "</TestPackage>\n";
diff --git a/tools/host/test/com/android/cts/TestSessionBuilderTests.java b/tools/host/test/com/android/cts/TestSessionBuilderTests.java
index fbb1e1b..26eb561 100644
--- a/tools/host/test/com/android/cts/TestSessionBuilderTests.java
+++ b/tools/host/test/com/android/cts/TestSessionBuilderTests.java
@@ -94,7 +94,7 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ "</TestPackage>\n";
@@ -188,7 +188,7 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ "</TestPackage>\n";
@@ -274,7 +274,7 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ "</TestPackage>\n";
@@ -347,14 +347,14 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " <TestSuite name=\"TestSuiteName\">\n"
+ " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testName\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " </TestSuite>\n"
@@ -450,16 +450,16 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " <TestSuite name=\"TestSuiteName\">\n"
+ " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testName1\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testName2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " </TestSuite>\n"
@@ -528,16 +528,16 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " <TestSuite name=\"TestSuiteName\">\n"
+ " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testName1\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testName2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " </TestSuite>\n"
@@ -610,16 +610,16 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " <TestSuite name=\"TestSuiteName\">\n"
+ " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testName1\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testName2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " </TestSuite>\n"
@@ -678,15 +678,15 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testName1\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testName2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ "</TestPackage>\n";
@@ -759,15 +759,15 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testName1\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testName2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ "</TestPackage>\n";
@@ -827,8 +827,8 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ "</TestPackage>\n";
@@ -902,8 +902,8 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
- + " <Test method=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello2\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ "</TestPackage>\n";
@@ -967,13 +967,13 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"" + testName1 + "\" type=\"automatic\"" + "/>\n"
+ + " <Test name=\"" + testName1 + "\" type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " <TestSuite name=\"" + suiteName2 + "\"" + ">\n"
+ " <TestCase name=\"" + caseName2 + "\"" + " priority=\"mandatory\">\n"
- + " <Test method=\"" + testName2 +"\" type=\"automatic\" />\n"
- + " <Test method=\"" + testName3 +"\" type=\"automatic\" />\n"
+ + " <Test name=\"" + testName2 +"\" type=\"automatic\" />\n"
+ + " <Test name=\"" + testName3 +"\" type=\"automatic\" />\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ "</TestPackage>\n";
@@ -1059,14 +1059,14 @@
+ " <TestCase name=\"" + caseName1 + "\"" + " category=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc" + "</Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"" + testName1 + "\" type=\"automatic\"" + "/>\n"
+ + " <Test name=\"" + testName1 + "\" type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " <TestSuite name=\"" + nestedSuiteName1 + "\"" + ">\n"
+ " <TestSuite name=\"" + nestedSuiteName2 + "\"" + ">\n"
+ " <TestCase name=\"" + caseName2 + "\"" + " priority=\"mandatory\">\n"
- + " <Test method=\"" + testName2 +"\" type=\"automatic\" />\n"
- + " <Test method=\"" + testName3 +"\" type=\"automatic\" />\n"
+ + " <Test name=\"" + testName2 +"\" type=\"automatic\" />\n"
+ + " <Test name=\"" + testName3 +"\" type=\"automatic\" />\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " </TestSuite>\n"
@@ -1159,7 +1159,7 @@
+ " <TestCase name=\"CtsTestHello\"" + " priority=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ "</TestPackage>\n";
@@ -1258,14 +1258,14 @@
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testHello\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " <TestSuite name=\"TestSuiteName\">\n"
+ " <TestCase name=\"TestCaseName\" priority=\"mandatory\">\n"
+ " <Description>" + "something extracted from java doc"
+ " </Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testName1\"" + " type=\"automatic\"" + "/>\n"
+ + " <Test name=\"testName1\"" + " type=\"automatic\"" + "/>\n"
+ " </TestCase>\n"
+ " </TestSuite>\n"
+ " </TestSuite>\n"
@@ -1405,7 +1405,7 @@
+ " <Description>"
+ "something extracted from java doc" + "</Description>\n"
+ " <!-- Test Methods -->\n"
- + " <Test method=\"testName1\""
+ + " <Test name=\"testName1\""
+ " type=\"automatic\"" + " HostController=\""
+ description + "\"" + "/>\n" + " </TestCase>\n"
+ " </TestSuite>\n" + "</TestPackage>\n";
diff --git a/tools/host/test/com/android/cts/TestSessionLogBuilderTests.java b/tools/host/test/com/android/cts/TestSessionLogBuilderTests.java
new file mode 100644
index 0000000..7deb9af
--- /dev/null
+++ b/tools/host/test/com/android/cts/TestSessionLogBuilderTests.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2009 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.android.cts;
+
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+/**
+ * Test the logic of TestSessionLogBuilder.
+ *
+ */
+public class TestSessionLogBuilderTests extends CtsTestBase {
+
+ public void testLoadTestSessionLogBuilder() throws IOException, NoSuchAlgorithmException,
+ SAXException, TestPlanNotFoundException, TestNotFoundException,
+ ParserConfigurationException {
+
+ final String resultFile =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<?xml-stylesheet type=\"text/xsl\" href=\"cts_result.xsl\"?>\n" +
+ "\n" +
+ "<TestResult endtime=\"Wed Apr 29 10:36:47 CST 2009\" " +
+ "starttime=\"Wed Apr 29 10:36:30 CST 2009\" testPlan=\"location\" version=\"1.0\">\n" +
+ " <DeviceInfo>\n" +
+ " <Screen resolution=\"480x320\"/>\n" +
+ " <PhoneSubInfo subscriberId=\"15555218135\"/>\n" +
+ " <BuildInfo Xdpi=\"164.75456\" Ydpi=\"165.87724\" androidPlatformVersion=\"3\" " +
+ " buildID=\"CUPCAKE\" buildName=\"generic\" buildVersion=\"1.5\" " +
+ " build_board=\"unknown\" build_brand=\"generic\" build_device=\"generic\" " +
+ " build_fingerprint=\"test-keys\" build_model=\"generic\" build_type=\"eng\" " +
+ " deviceID=\"emulator-5554\" imei=\"000000000000000\" imsi=\"310260000000000\" " +
+ " keypad=\"qwty\" locales=\"en_US;\" navigation=\"trkball\" network=\"Android\" " +
+ " touch=\"finger\"/>\n" +
+ " </DeviceInfo>\n" +
+ " <Summary failed=\"22\" notExecuted=\"0\" pass=\"22\" timeout=\"0\"/>\n" +
+ " <TestPackage digest=\"7GDPKCxBGKuVyEkH1PGWJc= \" name=\"android.location\" " +
+ " appPackageName=\"android.location\">\n" +
+ " <TestSuite name=\"android\">\n" +
+ " <TestSuite name=\"location\">\n" +
+ " <TestSuite name=\"cts\">\n" +
+ " <TestCase name=\"LocationManagerTest\" priority=\"\">\n" +
+ " <Test endtime=\"Wed Apr 29 10:36:44 CST 2009\" name=\"testOne\"" +
+ " result=\"fail\" starttime=\"Thu Jan 01 07:00:00 CST 1970\">\n" +
+ " <FailedScene message=\"java.SecurityException: (Parcel.java:1234)\">\n" +
+ " <StackTrace>at android.os.Parcel.readException(Parcel.java:1234)\n" +
+ " at android.os.Parcel.readException(Parcel.java:1222)\n" +
+ " at android.location.addTestProvider(ILocationManager.java:821)\n" +
+ " at android.location.addTestProvider(LocationManager.java:987)\n" +
+ " </StackTrace>\n" +
+ " </FailedScene>\n" +
+ " </Test>\n" +
+ " <Test endtime=\"Wed Apr 29 10:36:44 CST 2009\" name=\"testTwo\"" +
+ " result=\"fail\" starttime=\"Thu Jan 01 07:00:00 CST 1970\">\n" +
+ " <FailedScene message=\"java.SecurityException: (Parcel.java:1234)\">\n" +
+ " <StackTrace>at android.os.Parcel.readException(Parcel.java:1234)\n" +
+ " at android.os.Parcel.readException(Parcel.java:1222)\n" +
+ " at android.location.(ILocationManager.java:821)\n" +
+ " </StackTrace>\n" +
+ " </FailedScene>\n" +
+ " </Test>\n" +
+ " </TestCase>\n" +
+ " <TestCase name=\"AddressTest\" priority=\"\">\n" +
+ " <Test endtime=\"Wed Apr 29 10:36:43 CST 2009\" name=\"testThree\" " +
+ " result=\"pass\" starttime=\"Thu Jan 01 07:00:00 CST 1970\"/>\n" +
+ " <Test endtime=\"Wed Apr 29 10:36:43 CST 2009\" name=\"testFour\" " +
+ " result=\"pass\" starttime=\"Thu Jan 01 07:00:00 CST 1970\"/>\n" +
+ " </TestCase>\n" +
+ " </TestSuite>\n" +
+ " </TestSuite>\n" +
+ " </TestSuite>\n" +
+ " </TestPackage>\n" +
+ "</TestResult>";
+
+ final String pkgDescription =
+ "<TestPackage name=\"android.location\" " +
+ "appPackageName=\"android.location\" targetNameSpace=\"targetNameSpace\" " +
+ " version=\"1.0\" AndroidFramework=\"Android 1.0\"" +
+ " runner=\"runner\">\n" +
+ " <Description>something extracted from java doc</Description>\n" +
+ " <TestSuite name=\"android\">\n" +
+ " <TestSuite name=\"location\">\n" +
+ " <TestSuite name=\"cts\">\n" +
+ " <TestCase name=\"LocationManagerTest\" priority=\"\">\n" +
+ " <Test name=\"testOne\" />\n" +
+ " <Test name=\"testTwo\" />\n" +
+ " </TestCase>\n" +
+ " <TestCase name=\"AddressTest\" priority=\"\">\n" +
+ " <Test name=\"testThree\" />\n" +
+ " <Test name=\"testFour\" />\n" +
+ " </TestCase>\n" +
+ " </TestSuite>\n" +
+ " </TestSuite>\n" +
+ " </TestSuite>\n" +
+ "</TestPackage>\n";
+
+ final String testPlanConfigStr = "<TestPlan version=\"1.0\">\n" +
+ "\t<Description>Demo test plan</Description>\n" +
+ "\t\t<PlanSettings>\n" +
+ "\t\t\t<RequiredDevice amount=\"" + 1 + "\"" + "/>\n" +
+ "\t\t</PlanSettings>\n" +
+ "\t<Entry uri=\"android.location\"/>\n" +
+ "</TestPlan>";
+
+ final String resultFileName = "testResult.xml";
+ final String descriptionFileName = "CtsLocation.xml";
+
+ HostConfig.getInstance().removeTestPacakges();
+
+ String planPath =
+ HostConfig.getInstance().getPlanRepository().getPlanPath("location");
+ createFile(testPlanConfigStr, planPath);
+
+ String resultPath =
+ HostConfig.getInstance().getResultRepository().getRoot() + resultFileName;
+ createFile(resultFile, resultPath);
+
+ createTestPackage(pkgDescription, "android.location");
+ HostConfig.getInstance().loadTestPackages();
+ TestSession ts = TestSessionBuilder.getInstance().build(
+ TestSessionLogBuilder.getInstance().build(resultPath));
+ assertNotNull(ts);
+ TestSessionLog log = ts.getSessionLog();
+ assertNotNull(log);
+ assertEquals("location", log.getTestPlanName());
+
+ Collection<TestPackage> packages = log.getTestPackages();
+ assertEquals(1, packages.size());
+ TestPackage pkg = packages.iterator().next();
+
+ Collection<Test> tests = pkg.getTests();
+ assertNotNull(tests);
+ assertEquals(4, tests.size());
+ Iterator<Test> iterator = tests.iterator();
+ Test test1 = iterator.next();
+ assertEquals("android.location.cts.LocationManagerTest#testOne", test1.getFullName());
+
+ CtsTestResult result = test1.getResult();
+ assertNotNull(result);
+ assertEquals("fail", result.getResultString());
+ assertNotNull(result.getFailedMessage());
+ assertNotNull(result.getStackTrace());
+
+ Test test2 = iterator.next();
+ Test test3 = iterator.next();
+ assertEquals("android.location.cts.AddressTest#testThree", test3.getFullName());
+
+ result = test3.getResult();
+ assertNotNull(result);
+ assertEquals("pass", result.getResultString());
+ assertNull(result.getFailedMessage());
+ assertNull(result.getStackTrace());
+ }
+}
diff --git a/tools/utils/DescriptionGenerator.java b/tools/utils/DescriptionGenerator.java
index 88d864a..d629fb8 100644
--- a/tools/utils/DescriptionGenerator.java
+++ b/tools/utils/DescriptionGenerator.java
@@ -79,7 +79,6 @@
static final String ATTRIBUTE_VALUE_FRAMEWORK = "Android 1.0";
static final String ATTRIBUTE_NAME = "name";
- static final String ATTRIBUTE_METHOD = "method";
static final String ATTRIBUTE_XML_INFO = "XML_INFO";
static final String ATTRIBUTE_HOST_CONTROLLER = "HostController";
static final String ATTRIBUTE_KNOWN_FAILURE = "KnownFailure";
@@ -392,7 +391,7 @@
}
Node caseNode = elem.appendChild(mDoc.createElement(TAG_TEST));
- setAttribute(caseNode, ATTRIBUTE_METHOD, caze.mName);
+ setAttribute(caseNode, ATTRIBUTE_NAME, caze.mName);
if ((caze.mController != null) && (caze.mController.length() != 0)) {
setAttribute(caseNode, ATTRIBUTE_HOST_CONTROLLER, caze.mController);
}
diff --git a/tools/utils/genDefaultTestPlan.sh b/tools/utils/genDefaultTestPlan.sh
index c0c2dd0..9baffb4 100644
--- a/tools/utils/genDefaultTestPlan.sh
+++ b/tools/utils/genDefaultTestPlan.sh
@@ -39,7 +39,7 @@
echo "<TestSuite name=\"tests\">" >> ${SIGNATURE_CHECK_PATH}
echo "<TestSuite name=\"sigtest\">" >> ${SIGNATURE_CHECK_PATH}
echo "<TestCase name=\"SignatureTest\">" >> ${SIGNATURE_CHECK_PATH}
- echo "<Test method=\"signatureTest\">" >> ${SIGNATURE_CHECK_PATH}
+ echo "<Test name=\"signatureTest\">" >> ${SIGNATURE_CHECK_PATH}
echo "</Test>" >> ${SIGNATURE_CHECK_PATH}
echo "</TestCase>" >> ${SIGNATURE_CHECK_PATH}
echo "</TestSuite>" >> ${SIGNATURE_CHECK_PATH}
@@ -71,7 +71,7 @@
echo "<TestSuite name=\"${pack_part}\">" >> ${PACKAGE_PATH}
done
echo "<TestCase name=\"${CLASS_NAME}\">" >> ${PACKAGE_PATH}
- echo "<Test method=\"${METHOD_NAME}\">" >> ${PACKAGE_PATH}
+ echo "<Test name=\"${METHOD_NAME}\">" >> ${PACKAGE_PATH}
echo "</Test>" >> ${PACKAGE_PATH}
echo "</TestCase>" >> ${PACKAGE_PATH}
for pack_part in ${JAVA_PACKAGE_LIST}; do