blob: 421b208a37c414be971d23e83f685c19a3420b67 [file] [log] [blame]
Jaggerbaa20ea2015-09-06 01:12:08 +02001/*
2 *
3 * honggfuzz - display statistics
4 * -----------------------------------------
5 *
6 * Author: Robert Swiecki <swiecki@google.com>
7 *
8 * Copyright 2010-2015 by Google Inc. All Rights Reserved.
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License. You may obtain
12 * a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
19 * implied. See the License for the specific language governing
20 * permissions and limitations under the License.
21 *
22 */
23
24#define _WITH_DPRINTF
25
26#include "common.h"
27#include "display.h"
28
29#include <string.h>
Jagger7acbf2e2015-09-06 20:02:32 +020030#include <stdarg.h>
Jaggerbaa20ea2015-09-06 01:12:08 +020031#include <stdio.h>
32#include <unistd.h>
Anestis Bechtsoudise83ec672015-12-26 20:28:28 +020033#include <inttypes.h>
Jaggerbaa20ea2015-09-06 01:12:08 +020034
35#include "log.h"
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020036#include "util.h"
Jaggerbaa20ea2015-09-06 01:12:08 +020037
Jaggerbaa20ea2015-09-06 01:12:08 +020038#define ESC_CLEAR "\033[H\033[2J"
39#define ESC_NAV(x,y) "\033["#x";"#y"H"
Jagger76b11bc2015-09-06 02:11:44 +020040#define ESC_BOLD "\033[1m"
41#define ESC_RESET "\033[0m"
Jaggerbaa20ea2015-09-06 01:12:08 +020042
Jagger7acbf2e2015-09-06 20:02:32 +020043static void display_put(const char *fmt, ...)
44{
Anestis Bechtsoudisc06f8b32015-12-26 14:48:05 +020045 char buf[1024 * 4];
Jagger7acbf2e2015-09-06 20:02:32 +020046
47 va_list args;
48 va_start(args, fmt);
49 int ret = vsnprintf(buf, sizeof(buf), fmt, args);
50 va_end(args);
51
52 if (ret <= 0) {
53 return;
54 }
55 if (write(STDOUT_FILENO, buf, ret) == -1) {
56 return;
57 }
58}
59
Robert Swiecki7353a8d2015-09-08 15:53:59 +020060static void display_displayLocked(honggfuzz_t * hfuzz)
Jaggerbaa20ea2015-09-06 01:12:08 +020061{
Jagger269cea52015-09-06 04:46:07 +020062 unsigned long elapsed = (unsigned long)(time(NULL) - hfuzz->timeStart);
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020063
Jagger7acbf2e2015-09-06 20:02:32 +020064 size_t curr_exec_cnt = __sync_fetch_and_add(&hfuzz->mutationsCnt, 0UL);
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020065 /*
66 * We increase the mutation counter unconditionally in threads, but if it's
67 * above hfuzz->mutationsMax we don't really execute the fuzzing loop.
68 * Therefore at the end of fuzzing, the mutation counter might be higher
69 * than hfuzz->mutationsMax
70 */
71 if (hfuzz->mutationsMax > 0 && curr_exec_cnt > hfuzz->mutationsMax) {
72 curr_exec_cnt = hfuzz->mutationsMax;
73 }
Jaggerbaa20ea2015-09-06 01:12:08 +020074 static size_t prev_exec_cnt = 0UL;
Jaggerbaa20ea2015-09-06 01:12:08 +020075 uintptr_t exec_per_sec = curr_exec_cnt - prev_exec_cnt;
76 prev_exec_cnt = curr_exec_cnt;
77
Jagger7acbf2e2015-09-06 20:02:32 +020078 display_put("%s", ESC_CLEAR);
Jagger3905f552015-09-06 21:04:37 +020079 display_put("============================== STAT ==============================\n");
Jaggerbaa20ea2015-09-06 01:12:08 +020080
Jagger7acbf2e2015-09-06 20:02:32 +020081 display_put("Iterations: " ESC_BOLD "%zu" ESC_RESET, curr_exec_cnt);
Jaggerbaa20ea2015-09-06 01:12:08 +020082 if (hfuzz->mutationsMax) {
Jagger7acbf2e2015-09-06 20:02:32 +020083 display_put(" (out of: " ESC_BOLD "%zu" ESC_RESET ")", hfuzz->mutationsMax);
Jaggerbaa20ea2015-09-06 01:12:08 +020084 }
Jaggerbcd57852015-09-06 23:10:44 +020085 display_put("\n");
Jagger56ed7642015-09-06 04:06:57 +020086
Robert Swiecki81c6a0d2015-09-08 15:43:20 +020087 char start_time_str[128];
88 util_getLocalTime("%F %T", start_time_str, sizeof(start_time_str), hfuzz->timeStart);
89 display_put("Start time: " ESC_BOLD "%s" ESC_RESET " (" ESC_BOLD "%lu"
90 ESC_RESET " seconds elapsed)\n", start_time_str, elapsed);
Jaggerbaa20ea2015-09-06 01:12:08 +020091
Jagger7acbf2e2015-09-06 20:02:32 +020092 display_put("Input file/dir: '" ESC_BOLD "%s" ESC_RESET "'\n", hfuzz->inputFile);
Robert Swiecki72d2bef2016-01-19 14:39:26 +010093 display_put("Fuzzed cmd: '" ESC_BOLD "%s" ESC_RESET "'\n", hfuzz->cmdline_txt);
Jaggerbaa20ea2015-09-06 01:12:08 +020094
Jagger7acbf2e2015-09-06 20:02:32 +020095 display_put("Fuzzing threads: " ESC_BOLD "%zu" ESC_RESET "\n", hfuzz->threadsMax);
96 display_put("Execs per second: " ESC_BOLD "%zu" ESC_RESET " (avg: " ESC_BOLD "%zu" ESC_RESET
97 ")\n", exec_per_sec, elapsed ? (curr_exec_cnt / elapsed) : 0);
Jaggerbaa20ea2015-09-06 01:12:08 +020098
Anestis Bechtsoudis46ea10e2015-11-07 18:16:25 +020099 /* If dry run, print also the input file count */
100 if (hfuzz->flipRate == 0.0L && hfuzz->useVerifier) {
101 display_put("Input Files: '" ESC_BOLD "%zu" ESC_RESET "'\n", hfuzz->fileCnt);
102 }
103
Anestis Bechtsoudisd59af692015-09-21 15:15:05 +0300104 display_put("Crashes: " ESC_BOLD "%zu" ESC_RESET " (unique: " ESC_BOLD "%zu" ESC_RESET
Anestis Bechtsoudis79b799e2015-11-01 00:02:25 +0200105 ", blacklist: " ESC_BOLD "%zu" ESC_RESET ", verified: " ESC_BOLD "%zu" ESC_RESET
106 ") \n", __sync_fetch_and_add(&hfuzz->crashesCnt, 0UL),
Anestis Bechtsoudisd59af692015-09-21 15:15:05 +0300107 __sync_fetch_and_add(&hfuzz->uniqueCrashesCnt, 0UL),
Anestis Bechtsoudis79b799e2015-11-01 00:02:25 +0200108 __sync_fetch_and_add(&hfuzz->blCrashesCnt, 0UL),
109 __sync_fetch_and_add(&hfuzz->verifiedCrashesCnt, 0UL));
Jagger7acbf2e2015-09-06 20:02:32 +0200110 display_put("Timeouts: " ESC_BOLD "%zu" ESC_RESET "\n",
111 __sync_fetch_and_add(&hfuzz->timeoutedCnt, 0UL));
Jaggerbaa20ea2015-09-06 01:12:08 +0200112
Anestis Bechtsoudis02b99be2015-12-27 11:53:01 +0200113 /* Feedback data sources are enabled. Start with common headers. */
114 if (hfuzz->dynFileMethod != _HF_DYNFILE_NONE || hfuzz->useSanCov) {
Robert Swiecki53958402015-09-08 16:20:50 +0200115 display_put("Dynamic file size: " ESC_BOLD "%zu" ESC_RESET " (max: " ESC_BOLD "%zu"
116 ESC_RESET ")\n", hfuzz->dynamicFileBestSz, hfuzz->maxFileSz);
Anestis Bechtsoudis02b99be2015-12-27 11:53:01 +0200117 display_put("Dynamic file max iterations keep for chosen seed (" ESC_BOLD "%zu" ESC_RESET
118 "/" ESC_BOLD "%zu" ESC_RESET ")\n",
119 __sync_fetch_and_add(&hfuzz->dynFileIterExpire, 0UL), _HF_MAX_DYNFILE_ITER);
Robert Swiecki53958402015-09-08 16:20:50 +0200120 display_put("Coverage (max):\n");
Jaggerbaa20ea2015-09-06 01:12:08 +0200121 }
Anestis Bechtsoudis02b99be2015-12-27 11:53:01 +0200122
123 /* HW perf specific counters */
Robert Swiecki53958402015-09-08 16:20:50 +0200124 if (hfuzz->dynFileMethod & _HF_DYNFILE_INSTR_COUNT) {
Anestis Bechtsoudise83ec672015-12-26 20:28:28 +0200125 display_put(" - cpu instructions: " ESC_BOLD "%" PRIu64 ESC_RESET "\n",
Jagger3b513552015-09-09 02:08:35 +0200126 __sync_fetch_and_add(&hfuzz->hwCnts.cpuInstrCnt, 0UL));
Robert Swiecki53958402015-09-08 16:20:50 +0200127 }
128 if (hfuzz->dynFileMethod & _HF_DYNFILE_BRANCH_COUNT) {
Anestis Bechtsoudise83ec672015-12-26 20:28:28 +0200129 display_put(" - cpu branches: " ESC_BOLD "%" PRIu64 ESC_RESET "\n",
Jagger3b513552015-09-09 02:08:35 +0200130 __sync_fetch_and_add(&hfuzz->hwCnts.cpuBranchCnt, 0UL));
Robert Swiecki53958402015-09-08 16:20:50 +0200131 }
132 if (hfuzz->dynFileMethod & _HF_DYNFILE_UNIQUE_BLOCK_COUNT) {
Anestis Bechtsoudise83ec672015-12-26 20:28:28 +0200133 display_put(" - unique branch targets: " ESC_BOLD "%" PRIu64 ESC_RESET "\n",
Jagger3b513552015-09-09 02:08:35 +0200134 __sync_fetch_and_add(&hfuzz->hwCnts.pcCnt, 0UL));
Robert Swiecki53958402015-09-08 16:20:50 +0200135 }
136 if (hfuzz->dynFileMethod & _HF_DYNFILE_UNIQUE_EDGE_COUNT) {
Anestis Bechtsoudise83ec672015-12-26 20:28:28 +0200137 display_put(" - unique branch pairs: " ESC_BOLD "%" PRIu64 ESC_RESET "\n",
Jagger3b513552015-09-09 02:08:35 +0200138 __sync_fetch_and_add(&hfuzz->hwCnts.pathCnt, 0UL));
Robert Swiecki53958402015-09-08 16:20:50 +0200139 }
140 if (hfuzz->dynFileMethod & _HF_DYNFILE_CUSTOM) {
Anestis Bechtsoudise83ec672015-12-26 20:28:28 +0200141 display_put(" - custom counter: " ESC_BOLD "%" PRIu64 ESC_RESET "\n",
Jagger3b513552015-09-09 02:08:35 +0200142 __sync_fetch_and_add(&hfuzz->hwCnts.customCnt, 0UL));
Robert Swiecki53958402015-09-08 16:20:50 +0200143 }
Anestis Bechtsoudis02b99be2015-12-27 11:53:01 +0200144
145 /* Sanitizer coverage specific counters */
Anestis Bechtsoudise83ec672015-12-26 20:28:28 +0200146 if (hfuzz->useSanCov) {
Anestis Bechtsoudis56e360f2016-01-11 14:29:17 +0200147 uint64_t hitBB = __sync_fetch_and_add(&hfuzz->sanCovCnts.hitBBCnt, 0UL);
148 uint64_t totalBB = __sync_fetch_and_add(&hfuzz->sanCovCnts.totalBBCnt, 0UL);
149 uint8_t covPer = totalBB ? ((hitBB * 100) / totalBB) : 0;
150 display_put(" - total hit #bb: " ESC_BOLD "%" PRIu64 ESC_RESET " (coverage %d%%)\n",
151 hitBB, covPer);
Anestis Bechtsoudisa16f70f2016-01-03 13:03:21 +0200152 display_put(" - total #dso: " ESC_BOLD "%" PRIu64 ESC_RESET " (instrumented only)\n",
153 __sync_fetch_and_add(&hfuzz->sanCovCnts.iDsoCnt, 0UL));
Anestis Bechtsoudis56e360f2016-01-11 14:29:17 +0200154 display_put(" - discovered #bb: " ESC_BOLD "%" PRIu64 ESC_RESET " (new from input seed)\n",
155 __sync_fetch_and_add(&hfuzz->sanCovCnts.newBBCnt, 0UL));
Anestis Bechtsoudisa16f70f2016-01-03 13:03:21 +0200156 display_put(" - crashes: " ESC_BOLD "%" PRIu64 ESC_RESET "\n",
157 __sync_fetch_and_add(&hfuzz->sanCovCnts.crashesCnt, 0UL));
Anestis Bechtsoudise83ec672015-12-26 20:28:28 +0200158 }
Jagger3905f552015-09-06 21:04:37 +0200159 display_put("============================== LOGS ==============================\n");
Jaggerbaa20ea2015-09-06 01:12:08 +0200160}
Robert Swiecki7353a8d2015-09-08 15:53:59 +0200161
162extern void display_display(honggfuzz_t * hfuzz)
163{
Robert Swiecki7353a8d2015-09-08 15:53:59 +0200164 display_displayLocked(hfuzz);
Robert Swiecki7353a8d2015-09-08 15:53:59 +0200165}