1 /*
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 
24 using std::endl;
25 using std::map;
26 using std::string;
27 using std::unordered_map;
28 
29 namespace android {
30 namespace vts {
31 namespace fuzzer {
32 
RegisterTouch(string iface_name,string func_name)33 void ProtoFuzzerStats::RegisterTouch(string iface_name, string func_name) {
34   // Update the touch count for the full function name.
35   string key = iface_name + "::" + func_name;
36   touch_count_[key]++;
37   // Record that this interface has been touched.
38   touched_ifaces_.insert(std::move(iface_name));
39 }
40 
StatsString() const41 string 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
58