1 /* 2 * Copyright (C) 2013 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 package com.android.cts.tradefed.util; 17 18 import java.util.concurrent.ConcurrentHashMap; 19 20 /** 21 * Utility class for storing Cts Results. 22 * This is necessary for host tests where test metrics cannot be passed. 23 */ 24 public class CtsHostStore { 25 26 // needs concurrent version as there can be multiple client accessing this. 27 // But there is no additional protection for the same key as that should not happen. 28 private static final ConcurrentHashMap<String, String> mMap = 29 new ConcurrentHashMap<String, String>(); 30 31 /** 32 * Stores CTS result. Existing result with the same key will be replaced. 33 * Note that key is generated in the form of device_serial#class#method name. 34 * So there should be no concurrent test for the same (serial, class, method). 35 * @param deviceSerial 36 * @param abi 37 * @param classMethodName 38 * @param result CTS result string 39 */ storeCtsResult(String deviceSerial, String abi, String classMethodName, String result)40 public static void storeCtsResult(String deviceSerial, String abi, String classMethodName, String result) { 41 mMap.put(generateTestKey(deviceSerial, abi, classMethodName), result); 42 } 43 44 /** 45 * retrieves a CTS result for the given condition and remove it from the internal 46 * storage. If there is no result for the given condition, it will return null. 47 */ removeCtsResult(String deviceSerial, String abi, String classMethodName)48 public static String removeCtsResult(String deviceSerial, String abi, String classMethodName) { 49 return mMap.remove(generateTestKey(deviceSerial, abi, classMethodName)); 50 } 51 52 /** 53 * @return test key in the form of device_serial#abi#class_name#method_name 54 */ generateTestKey(String deviceSerial, String abi, String classMethodName)55 private static String generateTestKey(String deviceSerial, String abi, String classMethodName) { 56 return String.format("%s#%s#%s", deviceSerial, abi, classMethodName); 57 58 } 59 } 60