summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGopinath <gelanchezhian@google.com>2015-08-18 15:12:31 -0700
committerGopinath <gelanchezhian@google.com>2015-08-23 13:42:30 -0700
commitabd68b2987dea8704f5ac49f15714989073d2e4e (patch)
tree18aa706339f63502f29b53e0b948f5e4b9db7aba
parent3310ebbf1d7248540abe9beecd8d732c84beabc6 (diff)
downloadplatform_testing-abd68b2987dea8704f5ac49f15714989073d2e4e.tar.gz
Adding time result helper
Added time and result logger Change-Id: I4db5738a611d29de652e5954afbcd6fb2ca7c457
-rw-r--r--libraries/timeresult-helper/Android.mk24
-rw-r--r--libraries/timeresult-helper/src/android/support/test/timeresulthelper/TimeResultLogger.java63
2 files changed, 87 insertions, 0 deletions
diff --git a/libraries/timeresult-helper/Android.mk b/libraries/timeresult-helper/Android.mk
new file mode 100644
index 000000000..4c0541525
--- /dev/null
+++ b/libraries/timeresult-helper/Android.mk
@@ -0,0 +1,24 @@
+#
+# Copyright (C) 2015 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := timeresult-helper-lib
+LOCAL_SDK_VERSION := 21
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/libraries/timeresult-helper/src/android/support/test/timeresulthelper/TimeResultLogger.java b/libraries/timeresult-helper/src/android/support/test/timeresulthelper/TimeResultLogger.java
new file mode 100644
index 000000000..ad6606c52
--- /dev/null
+++ b/libraries/timeresult-helper/src/android/support/test/timeresulthelper/TimeResultLogger.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2015 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 android.support.test.timeresulthelper;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import android.os.Bundle;
+
+/**
+ * Class contains helper methods to log the start and stop time and backup the results to a file.
+ */
+public class TimeResultLogger {
+
+ public static void writeTimeStamp(String logType, String testCase, long delay, File destFile)
+ throws IOException {
+ writeTimeStamp(logType, testCase, System.currentTimeMillis(), delay, destFile);
+ }
+
+ public static void writeTimeStamp(String logType, String testCase, long time,
+ long delay, File destFile) throws IOException {
+ FileWriter outputWriter = new FileWriter(destFile, true);
+ outputWriter.write(String.format("%d %s %s\n", (time + delay),
+ logType, testCase));
+ outputWriter.close();
+ }
+
+ public static void writeTimeStampLogStart(String testCase, File destFile) throws IOException {
+ writeTimeStamp("AUTOTEST_TEST_BEGIN", testCase, 5 * 1000, destFile);
+ }
+
+ public static void writeTimeStampLogEnd(String testCase, File destFile) throws IOException {
+ writeTimeStamp("AUTOTEST_TEST_SUCCESS", testCase, 0, destFile);
+ }
+
+ public static void writeResultToFile(String testCase, File destFile, Bundle result)
+ throws IOException {
+ FileWriter outputWriter = new FileWriter(destFile, true);
+ outputWriter.write(String.format("Result %s\n", testCase));
+ for (String key : result.keySet()) {
+ outputWriter.write(String.format("%s %s\n", key,
+ result.get(key)));
+ }
+ outputWriter.close();
+ }
+
+}
+