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 17 package dexfuzz.listeners; 18 19 import dexfuzz.ExecutionResult; 20 import dexfuzz.executors.Executor; 21 22 import java.util.List; 23 import java.util.Map; 24 25 /** 26 * Implements the live updating table of results when --repeat is being used. 27 */ 28 public class UpdatingConsoleListener extends BaseListener { 29 long successfulVerification; 30 long failedVerification; 31 long failedMutation; 32 long success; 33 long timedOut; 34 long divergence; 35 long selfDivergent; 36 long architectureSplit; 37 long iterations; 38 39 @Override setup()40 public void setup() { 41 System.out.println("|-----------------------------------------------------------------|"); 42 System.out.println("|Iterations|VerifyFail|MutateFail|Timed Out |Successful|Divergence|"); 43 System.out.println("|-----------------------------------------------------------------|"); 44 } 45 46 @Override handleSuccessfulHostVerification()47 public void handleSuccessfulHostVerification() { 48 successfulVerification++; 49 } 50 51 @Override handleFailedHostVerification(ExecutionResult verificationResult)52 public void handleFailedHostVerification(ExecutionResult verificationResult) { 53 failedVerification++; 54 } 55 56 @Override handleFailedTargetVerification()57 public void handleFailedTargetVerification() { 58 failedVerification++; 59 } 60 61 @Override handleIterationStarted(int iteration)62 public void handleIterationStarted(int iteration) { 63 iterations++; 64 } 65 66 @Override handleIterationFinished(int iteration)67 public void handleIterationFinished(int iteration) { 68 String output = String.format("| %-9d| %-9d| %-9d| %-9d| %-9d| %-9d|", 69 iterations, failedVerification, failedMutation, timedOut, success, 70 divergence - (selfDivergent + architectureSplit)); 71 System.out.print("\r" + output); 72 } 73 74 @Override handleTimeouts(List<Executor> timedOut, List<Executor> didNotTimeOut)75 public void handleTimeouts(List<Executor> timedOut, List<Executor> didNotTimeOut) { 76 this.timedOut++; 77 } 78 79 @Override handleDivergences(Map<String, List<Executor>> outputMap)80 public void handleDivergences(Map<String, List<Executor>> outputMap) { 81 divergence++; 82 } 83 84 @Override handleSelfDivergence()85 public void handleSelfDivergence() { 86 selfDivergent++; 87 } 88 89 @Override handleArchitectureSplit()90 public void handleArchitectureSplit() { 91 architectureSplit++; 92 } 93 94 @Override handleSuccess(Map<String, List<Executor>> outputMap)95 public void handleSuccess(Map<String, List<Executor>> outputMap) { 96 success++; 97 } 98 99 @Override handleMutationFail()100 public void handleMutationFail() { 101 failedMutation++; 102 } 103 104 @Override handleSummary()105 public void handleSummary() { 106 System.out.println("\n|-----------------------------------------------------------------|"); 107 } 108 } 109