keunyoung | efa794f | 2013-03-26 17:04:22 -0700 | [diff] [blame] | 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 | */ |
Stuart Scott | a1f2d05 | 2013-11-13 11:21:30 -0800 | [diff] [blame] | 16 | package com.android.cts.tradefed.util; |
keunyoung | efa794f | 2013-03-26 17:04:22 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.concurrent.ConcurrentHashMap; |
| 19 | |
| 20 | /** |
Stuart Scott | a132af6 | 2013-11-07 10:30:32 -0800 | [diff] [blame] | 21 | * Utility class for storing Cts Results. |
keunyoung | efa794f | 2013-03-26 17:04:22 -0700 | [diff] [blame] | 22 | * This is necessary for host tests where test metrics cannot be passed. |
| 23 | */ |
Stuart Scott | a132af6 | 2013-11-07 10:30:32 -0800 | [diff] [blame] | 24 | public class CtsHostStore { |
keunyoung | efa794f | 2013-03-26 17:04:22 -0700 | [diff] [blame] | 25 | |
| 26 | // needs concurrent verion 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 | /** |
Stuart Scott | a132af6 | 2013-11-07 10:30:32 -0800 | [diff] [blame] | 32 | * Stores CTS result. Existing result with the same key will be replaced. |
keunyoung | efa794f | 2013-03-26 17:04:22 -0700 | [diff] [blame] | 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). |
Stuart Scott | a1f2d05 | 2013-11-13 11:21:30 -0800 | [diff] [blame] | 35 | * @param deviceSerial |
| 36 | * @param classMethodName |
Stuart Scott | a132af6 | 2013-11-07 10:30:32 -0800 | [diff] [blame] | 37 | * @param result CTS result string |
keunyoung | efa794f | 2013-03-26 17:04:22 -0700 | [diff] [blame] | 38 | */ |
Stuart Scott | a132af6 | 2013-11-07 10:30:32 -0800 | [diff] [blame] | 39 | public static void storeCtsResult(String deviceSerial, String classMethodName, String result) { |
keunyoung | efa794f | 2013-03-26 17:04:22 -0700 | [diff] [blame] | 40 | mMap.put(generateTestKey(deviceSerial, classMethodName), result); |
| 41 | } |
| 42 | |
| 43 | /** |
Stuart Scott | a132af6 | 2013-11-07 10:30:32 -0800 | [diff] [blame] | 44 | * retrieves a CTS result for the given condition and remove it from the internal |
keunyoung | efa794f | 2013-03-26 17:04:22 -0700 | [diff] [blame] | 45 | * storage. If there is no result for the given condition, it will return null. |
| 46 | */ |
Stuart Scott | 7ac2974 | 2013-11-11 14:33:12 -0800 | [diff] [blame] | 47 | public static String removeCtsResult(String deviceSerial, String classMethodName) { |
| 48 | return mMap.remove(generateTestKey(deviceSerial, classMethodName)); |
keunyoung | efa794f | 2013-03-26 17:04:22 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /** |
| 52 | * return test key in the form of device_serial#class_name#method_name |
| 53 | */ |
| 54 | private static String generateTestKey(String deviceSerial, String classMethodName) { |
| 55 | return String.format("%s#%s", deviceSerial, classMethodName); |
| 56 | |
| 57 | } |
| 58 | } |