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