1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.support.test.timeresulthelper; 18 19 import java.io.File; 20 import java.io.FileWriter; 21 import java.io.IOException; 22 23 import android.os.Bundle; 24 25 /** 26 * Class contains helper methods to log the start and stop time and backup the results to a file. 27 */ 28 public class TimeResultLogger { 29 writeTimeStamp(String logType, String testCase, long delay, File destFile)30 public static void writeTimeStamp(String logType, String testCase, long delay, File destFile) 31 throws IOException { 32 writeTimeStamp(logType, testCase, System.currentTimeMillis(), delay, destFile); 33 } 34 writeTimeStamp(String logType, String testCase, long time, long delay, File destFile)35 public static void writeTimeStamp(String logType, String testCase, long time, 36 long delay, File destFile) throws IOException { 37 FileWriter outputWriter = new FileWriter(destFile, true); 38 outputWriter.write(String.format("%d %s %s\n", (time + delay), 39 logType, testCase)); 40 outputWriter.close(); 41 } 42 writeTimeStampLogStart(String testCase, File destFile)43 public static void writeTimeStampLogStart(String testCase, File destFile) throws IOException { 44 writeTimeStamp("AUTOTEST_TEST_BEGIN", testCase, 5 * 1000, destFile); 45 } 46 writeTimeStampLogEnd(String testCase, File destFile)47 public static void writeTimeStampLogEnd(String testCase, File destFile) throws IOException { 48 writeTimeStamp("AUTOTEST_TEST_SUCCESS", testCase, 0, destFile); 49 } 50 writeResultToFile(String testCase, File destFile, Bundle result)51 public static void writeResultToFile(String testCase, File destFile, Bundle result) 52 throws IOException { 53 FileWriter outputWriter = new FileWriter(destFile, true); 54 outputWriter.write(String.format("Result %s\n", testCase)); 55 for (String key : result.keySet()) { 56 outputWriter.write(String.format("%s %s\n", key, 57 result.get(key))); 58 } 59 outputWriter.close(); 60 } 61 62 } 63 64