blob: 9c1e2837c9aa171ed325793d6ca2478a0a569355 [file] [log] [blame]
keunyoungefa794f2013-03-26 17:04:22 -07001/*
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 Scotta1f2d052013-11-13 11:21:30 -080016package com.android.cts.tradefed.util;
keunyoungefa794f2013-03-26 17:04:22 -070017
18import java.util.concurrent.ConcurrentHashMap;
19
20/**
Stuart Scotta132af62013-11-07 10:30:32 -080021 * Utility class for storing Cts Results.
keunyoungefa794f2013-03-26 17:04:22 -070022 * This is necessary for host tests where test metrics cannot be passed.
23 */
Stuart Scotta132af62013-11-07 10:30:32 -080024public class CtsHostStore {
keunyoungefa794f2013-03-26 17:04:22 -070025
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 Scotta132af62013-11-07 10:30:32 -080032 * Stores CTS result. Existing result with the same key will be replaced.
keunyoungefa794f2013-03-26 17:04:22 -070033 * 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 Scotta1f2d052013-11-13 11:21:30 -080035 * @param deviceSerial
36 * @param classMethodName
Stuart Scotta132af62013-11-07 10:30:32 -080037 * @param result CTS result string
keunyoungefa794f2013-03-26 17:04:22 -070038 */
Stuart Scotta132af62013-11-07 10:30:32 -080039 public static void storeCtsResult(String deviceSerial, String classMethodName, String result) {
keunyoungefa794f2013-03-26 17:04:22 -070040 mMap.put(generateTestKey(deviceSerial, classMethodName), result);
41 }
42
43 /**
Stuart Scotta132af62013-11-07 10:30:32 -080044 * retrieves a CTS result for the given condition and remove it from the internal
keunyoungefa794f2013-03-26 17:04:22 -070045 * storage. If there is no result for the given condition, it will return null.
46 */
Stuart Scott7ac29742013-11-11 14:33:12 -080047 public static String removeCtsResult(String deviceSerial, String classMethodName) {
48 return mMap.remove(generateTestKey(deviceSerial, classMethodName));
keunyoungefa794f2013-03-26 17:04:22 -070049 }
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}