1 /*
2  * Copyright (C) 2018 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 TOOLS_TRACE_PROCESSOR_VTSCOVERAGEPROCESSOR_H_
18 #define TOOLS_TRACE_PROCESSOR_VTSCOVERAGEPROCESSOR_H_
19 
20 #include <android-base/macros.h>
21 #include <test/vts/proto/VtsReportMessage.pb.h>
22 
23 namespace android {
24 namespace vts {
25 // A class used for processing coverage report data, such as parse the
26 // coverage report file, merge multiple coverage reports, and compare
27 // two coverage reports.
28 class VtsCoverageProcessor {
29  public:
VtsCoverageProcessor()30   VtsCoverageProcessor(){};
~VtsCoverageProcessor()31   virtual ~VtsCoverageProcessor(){};
32 
33   // Merge the coverage files under coverage_file_dir and output the merged
34   // coverage data to merged_coverage_file.
35   void MergeCoverage(const std::string& coverage_file_dir,
36                      const std::string& merged_coverage_file);
37 
38   // Compare coverage data contained in new_msg_file with ref_msg_file and
39   // print the additional file/lines covered by the new_msg_file.
40   void CompareCoverage(const std::string& ref_msg_file,
41                        const std::string& new_msg_file);
42 
43   // Parse the given coverage_file into a coverage report.
44   void ParseCoverageData(const std::string& coverage_file,
45                          TestReportMessage* coverage_report);
46 
47   // Updates msg_to_be_updated by removing all the covered lines in ref_msg
48   // and recalculates the count of covered lines accordingly.
49   void UpdateCoverageData(const CoverageReportMessage& ref_msg,
50                           CoverageReportMessage* msg_to_be_updated);
51 
52   // Extract the files covered in ref_msg_file from full_msg_file and store
53   // the result in result_msg_file.
54   void GetSubsetCoverage(const std::string& ref_msg_file,
55                          const std::string& full_msg_file,
56                          const std::string& result_msg_file);
57 
58   // Parse the coverage report and print the coverage summary.
59   void GetCoverageSummary(const std::string& coverage_msg_file);
60 
61   // Calculate total coverage line in the given report message.
62   long GetTotalCoverageLine(const TestReportMessage& msg) const;
63   // Calculate total code line in the given report message.
64   long GetTotalCodeLine(const TestReportMessage& msg) const;
65 
66  private:
67   // Internal method to merge the ref_coverage_msg into merged_covergae_msg.
68   void MergeCoverageMsg(const CoverageReportMessage& ref_coverage_msg,
69                         CoverageReportMessage* merged_covergae_msg);
70 
71   // Help method to print the coverage summary.
72   void PrintCoverageSummary(const TestReportMessage& coverage_report);
73 
74   DISALLOW_COPY_AND_ASSIGN(VtsCoverageProcessor);
75 };
76 
77 }  // namespace vts
78 }  // namespace android
79 #endif  // TOOLS_TRACE_PROCESSOR_VTSCOVERAGEPROCESSOR_H_
80