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