blob: da65c7f4e749cfc02db7d5e67aa8096fc8b8d1af [file] [log] [blame]
Tri Vof657d672017-07-26 16:13:02 -07001/*
2 * Copyright 2017 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#include "ProtoFuzzerStats.h"
18
19#include <iomanip>
20#include <iostream>
21#include <map>
22#include <sstream>
23
24using std::endl;
25using std::map;
26using std::string;
27using std::unordered_map;
28
29namespace android {
30namespace vts {
31namespace fuzzer {
32
33void ProtoFuzzerStats::RegisterTouch(string iface_name, string func_name) {
Tri Vod0229fb2017-08-10 17:27:49 -070034 // Update the touch count for the full function name.
Tri Vof657d672017-07-26 16:13:02 -070035 string key = iface_name + "::" + func_name;
36 touch_count_[key]++;
Tri Vod0229fb2017-08-10 17:27:49 -070037 // Record that this interface has been touched.
38 touched_ifaces_.insert(std::move(iface_name));
Tri Vof657d672017-07-26 16:13:02 -070039}
40
41string ProtoFuzzerStats::StatsString() const {
42 std::map<string, uint64_t> ordered_result{touch_count_.cbegin(),
43 touch_count_.cend()};
44
45 std::stringstream ss{};
46 ss << "HAL api function touch count: " << endl;
47 for (const auto &entry : ordered_result) {
48 ss << std::left << std::setfill(' ') << std::setw(40) << entry.first
49 << std::setw(40) << entry.second << endl;
50 }
51 ss << endl;
52 return ss.str();
53}
54
55} // namespace fuzzer
56} // namespace vts
57} // namespace android