display.c revision 4b5281ec38fca285482e367ec1c4180366a4d7e7
1/*
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>
30#include <stdio.h>
31#include <unistd.h>
32
33#include "log.h"
34
35#define OUTFD STDOUT_FILENO
36#if !defined(_HF_ARCH_LINUX)
37#define dprintf(x, fmt, ...) fprintf(stdout, fmt, __VA_ARGS__)
38#endif
39
40#define ESC_CLEAR "\033[H\033[2J"
41#define ESC_NAV(x,y) "\033["#x";"#y"H"
42#define ESC_BOLD "\033[1m"
43#define ESC_RESET "\033[0m"
44
45extern void display_Display(honggfuzz_t * hfuzz)
46{
47    size_t curr_exec_cnt = __sync_add_and_fetch(&hfuzz->mutationsCnt, 0UL);
48    static size_t prev_exec_cnt = 0UL;
49
50    uintptr_t exec_per_sec = curr_exec_cnt - prev_exec_cnt;
51    prev_exec_cnt = curr_exec_cnt;
52
53    dprintf(OUTFD, "%s", ESC_CLEAR);
54
55    dprintf(OUTFD, "Iterations: " ESC_BOLD " %zu" ESC_RESET, curr_exec_cnt);
56    if (hfuzz->mutationsMax) {
57        dprintf(OUTFD, " (out of: " ESC_BOLD "%zu" ESC_RESET ")", hfuzz->mutationsMax);
58    }
59    dprintf(OUTFD, "\n");
60
61    dprintf(OUTFD, "Input file/dir: '" ESC_BOLD "%s" ESC_RESET "'\n", hfuzz->inputFile);
62    dprintf(OUTFD, "Fuzzed cmd: '" ESC_BOLD "%s" ESC_RESET "'\n", hfuzz->cmdline[0]);
63
64    dprintf(OUTFD, "Fuzzing threads: " ESC_BOLD "%zu" ESC_RESET "\n", hfuzz->threadsMax);
65    dprintf(OUTFD, "Execs per second: " ESC_BOLD "%zu" ESC_RESET "\n", exec_per_sec);
66
67    dprintf(OUTFD, "Crashes: " ESC_BOLD "%zu" ESC_RESET "\n",
68            __sync_add_and_fetch(&hfuzz->crashesCnt, 0UL));
69    dprintf(OUTFD, "Timeouts: " ESC_BOLD "%zu" ESC_RESET "\n",
70            __sync_add_and_fetch(&hfuzz->timeoutedCnt, 0UL));
71
72    dprintf(OUTFD,
73            "Dynamic file size: " ESC_BOLD "%zu" ESC_RESET " (max: " ESC_BOLD "%zu" ESC_RESET ")\n",
74            hfuzz->dynamicFileBestSz, hfuzz->maxFileSz);
75
76    dprintf(OUTFD, "Coverage:\n");
77    dprintf(OUTFD, "  max instructions taken:       " ESC_BOLD "%zu" ESC_RESET "\n",
78            __sync_add_and_fetch(&hfuzz->branchBestCnt[0], 0UL));
79    dprintf(OUTFD, "  max branches taken:           " ESC_BOLD "%zu" ESC_RESET "\n",
80            __sync_add_and_fetch(&hfuzz->branchBestCnt[1], 0UL));
81    if (hfuzz->dynFileMethod & _HF_DYNFILE_UNIQUE_BLOCK_COUNT) {
82        dprintf(OUTFD, "  max individual PCs seen:      ");
83    } else {
84        dprintf(OUTFD, "  max individual branches seen: ");
85    }
86    dprintf(OUTFD, ESC_BOLD "%zu" ESC_RESET "\n",
87            __sync_add_and_fetch(&hfuzz->branchBestCnt[2], 0UL));
88    dprintf(OUTFD, "  max custom feedback:          " ESC_BOLD "%zu" ESC_RESET "\n",
89            __sync_add_and_fetch(&hfuzz->branchBestCnt[3], 0UL));
90}
91