1/* 2 * Copyright (C) 2014 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 17package dexfuzz; 18 19import java.util.List; 20 21/** 22 * Stores the output of an executed command. 23 */ 24public class ExecutionResult { 25 public List<String> output; 26 public List<String> error; 27 public int returnValue; 28 29 private String flattenedOutput; 30 private String flattenedOutputWithNewlines; 31 private String flattenedError; 32 private String flattenedErrorWithNewlines; 33 private String flattenedAll; 34 35 private static final int TIMEOUT_RETURN_VALUE = 124; 36 private static final int SIGABORT_RETURN_VALUE = 134; 37 38 /** 39 * Get only the output, with all lines concatenated together, excluding newline characters. 40 */ 41 public String getFlattenedOutput() { 42 if (flattenedOutput == null) { 43 StringBuilder builder = new StringBuilder(); 44 for (String line : output) { 45 builder.append(line); 46 } 47 flattenedOutput = builder.toString(); 48 } 49 return flattenedOutput; 50 } 51 52 /** 53 * Get only the output, with all lines concatenated together, including newline characters. 54 */ 55 public String getFlattenedOutputWithNewlines() { 56 if (flattenedOutputWithNewlines == null) { 57 StringBuilder builder = new StringBuilder(); 58 for (String line : output) { 59 builder.append(line).append("\n"); 60 } 61 flattenedOutputWithNewlines = builder.toString(); 62 } 63 return flattenedOutputWithNewlines; 64 } 65 66 /** 67 * Get only the error, with all lines concatenated together, excluding newline characters. 68 */ 69 public String getFlattenedError() { 70 if (flattenedError == null) { 71 StringBuilder builder = new StringBuilder(); 72 for (String line : error) { 73 builder.append(line); 74 } 75 flattenedError = builder.toString(); 76 } 77 return flattenedError; 78 } 79 80 /** 81 * Get only the error, with all lines concatenated together, including newline characters. 82 */ 83 public String getFlattenedErrorWithNewlines() { 84 if (flattenedErrorWithNewlines == null) { 85 StringBuilder builder = new StringBuilder(); 86 for (String line : error) { 87 builder.append(line).append("\n"); 88 } 89 flattenedErrorWithNewlines = builder.toString(); 90 } 91 return flattenedErrorWithNewlines; 92 } 93 94 /** 95 * Get both the output and error, concatenated together, excluding newline characters. 96 */ 97 public String getFlattenedAll() { 98 if (flattenedAll == null) { 99 flattenedAll = getFlattenedOutput() + getFlattenedError(); 100 } 101 return flattenedAll; 102 } 103 104 public boolean isTimeout() { 105 return (returnValue == TIMEOUT_RETURN_VALUE); 106 } 107 108 public boolean isSigabort() { 109 return (returnValue == SIGABORT_RETURN_VALUE); 110 } 111}