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 #ifndef __VTS_PROTO_FUZZER_STATS_H_
18 #define __VTS_PROTO_FUZZER_STATS_H_
19 
20 #include <string>
21 #include <unordered_map>
22 #include <unordered_set>
23 
24 namespace android {
25 namespace vts {
26 namespace fuzzer {
27 
28 // Holds stats about a fuzzer run.
29 class ProtoFuzzerStats {
30  public:
31   // Registers fuzzer touching an interface function.
32   void RegisterTouch(std::string iface_name, std::string func_name);
33   // Returns collected stats in string form.
34   std::string StatsString() const;
35   // Returns the set of touched interfaces.
TouchedIfaces()36   const std::unordered_set<std::string> &TouchedIfaces() const {
37     return touched_ifaces_;
38   }
39 
40  private:
41   // Counts the number of times a function was touched.
42   // This object will be written to often, so we use unordered_map.
43   std::unordered_map<std::string, uint64_t> touch_count_;
44   // The set of interfaces that have been touched to far.
45   std::unordered_set<std::string> touched_ifaces_;
46 };
47 
48 }  // namespace fuzzer
49 }  // namespace vts
50 }  // namespace android
51 
52 #endif  // __VTS_PROTO_FUZZER_STATS__
53