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 package com.android.compatibility.common.util; 17 18 import java.util.ArrayList; 19 import java.util.Collections; 20 import java.util.HashMap; 21 import java.util.HashSet; 22 import java.util.LinkedHashMap; 23 import java.util.List; 24 import java.util.Map; 25 import java.util.Set; 26 27 /** 28 * Data structure for the detailed Compatibility test results. 29 */ 30 public class InvocationResult implements IInvocationResult { 31 32 private long mTimestamp; 33 private Map<String, IModuleResult> mModuleResults = new LinkedHashMap<>(); 34 private Map<String, String> mInvocationInfo = new HashMap<>(); 35 private Set<String> mSerials = new HashSet<>(); 36 private String mBuildFingerprint; 37 private String mTestPlan; 38 private String mCommandLineArgs; 39 40 /** 41 * {@inheritDoc} 42 */ 43 @Override getModules()44 public List<IModuleResult> getModules() { 45 ArrayList<IModuleResult> modules = new ArrayList<>(mModuleResults.values()); 46 Collections.sort(modules); 47 return modules; 48 } 49 50 /** 51 * {@inheritDoc} 52 */ 53 @Override countResults(TestStatus result)54 public int countResults(TestStatus result) { 55 int total = 0; 56 for (IModuleResult m : mModuleResults.values()) { 57 total += m.countResults(result); 58 } 59 return total; 60 } 61 62 /** 63 * {@inheritDoc} 64 */ 65 @Override getOrCreateModule(String id)66 public IModuleResult getOrCreateModule(String id) { 67 IModuleResult moduleResult = mModuleResults.get(id); 68 if (moduleResult == null) { 69 moduleResult = new ModuleResult(id); 70 mModuleResults.put(id, moduleResult); 71 } 72 return moduleResult; 73 } 74 75 /** 76 * {@inheritDoc} 77 */ 78 @Override mergeModuleResult(IModuleResult moduleResult)79 public void mergeModuleResult(IModuleResult moduleResult) { 80 // Merge the moduleResult with any existing module result 81 IModuleResult existingModuleResult = getOrCreateModule(moduleResult.getId()); 82 existingModuleResult.mergeFrom(moduleResult); 83 } 84 85 /** 86 * {@inheritDoc} 87 */ 88 @Override addInvocationInfo(String key, String value)89 public void addInvocationInfo(String key, String value) { 90 mInvocationInfo.put(key, value); 91 } 92 93 /** 94 * {@inheritDoc} 95 */ 96 @Override getInvocationInfo()97 public Map<String, String> getInvocationInfo() { 98 return mInvocationInfo; 99 } 100 101 /** 102 * {@inheritDoc} 103 */ 104 @Override setStartTime(long time)105 public void setStartTime(long time) { 106 mTimestamp = time; 107 } 108 109 /** 110 * {@inheritDoc} 111 */ 112 @Override getStartTime()113 public long getStartTime() { 114 return mTimestamp; 115 } 116 117 /** 118 * {@inheritDoc} 119 */ 120 @Override setTestPlan(String plan)121 public void setTestPlan(String plan) { 122 mTestPlan = plan; 123 } 124 125 /** 126 * {@inheritDoc} 127 */ 128 @Override getTestPlan()129 public String getTestPlan() { 130 return mTestPlan; 131 } 132 133 /** 134 * {@inheritDoc} 135 */ 136 @Override addDeviceSerial(String serial)137 public void addDeviceSerial(String serial) { 138 mSerials.add(serial); 139 } 140 141 /** 142 * {@inheritDoc} 143 */ 144 @Override getDeviceSerials()145 public Set<String> getDeviceSerials() { 146 return mSerials; 147 } 148 149 /** 150 * {@inheritDoc} 151 */ 152 @Override setCommandLineArgs(String commandLineArgs)153 public void setCommandLineArgs(String commandLineArgs) { 154 mCommandLineArgs = commandLineArgs; 155 } 156 157 /** 158 * {@inheritDoc} 159 */ 160 @Override getCommandLineArgs()161 public String getCommandLineArgs() { 162 return mCommandLineArgs; 163 } 164 165 @Override setBuildFingerprint(String buildFingerprint)166 public void setBuildFingerprint(String buildFingerprint) { 167 mBuildFingerprint = buildFingerprint; 168 } 169 170 /** 171 * {@inheritDoc} 172 */ 173 @Override getBuildFingerprint()174 public String getBuildFingerprint() { 175 return mBuildFingerprint; 176 } 177 178 /** 179 * {@inheritDoc} 180 */ 181 @Override getModuleCompleteCount()182 public int getModuleCompleteCount() { 183 int completeModules = 0; 184 for (IModuleResult module : mModuleResults.values()) { 185 if (module.isDone()) { 186 completeModules++; 187 } 188 } 189 return completeModules; 190 } 191 } 192