OLD | NEW |
1 package data | 1 package data |
2 | 2 |
3 import ( | 3 import ( |
4 "bytes" | 4 "bytes" |
5 "encoding/gob" | 5 "encoding/gob" |
6 "fmt" | 6 "fmt" |
7 "sort" | 7 "sort" |
8 "sync" | 8 "sync" |
9 | 9 |
10 "github.com/skia-dev/glog" | 10 "github.com/skia-dev/glog" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 func FindFuzzSummary(category string) FuzzReportTree { | 95 func FindFuzzSummary(category string) FuzzReportTree { |
96 cache, found := currentData.caches[category] | 96 cache, found := currentData.caches[category] |
97 if !found { | 97 if !found { |
98 return FuzzReportTree{} | 98 return FuzzReportTree{} |
99 } | 99 } |
100 return cache.SummaryReport | 100 return cache.SummaryReport |
101 } | 101 } |
102 | 102 |
103 // FindFuzzDetails returns the detailed fuzz reports for a file name, function n
ame, and line number. | 103 // FindFuzzDetails returns the detailed fuzz reports for a file name, function n
ame, and line number. |
104 // If functionName is "" or lineNumber is -1, all reports are shown. | 104 // If functionName is "" or lineNumber is -1, all reports are shown. |
105 func FindFuzzDetails(category, fileName, functionName string, lineNumber int) (F
ileFuzzReport, error) { | 105 func FindFuzzDetails(category, fileName, functionName string, lineNumber int) (F
uzzReportTree, error) { |
106 » cache := currentData.caches[category] | 106 » cache, found := currentData.caches[category] |
107 » for _, file := range cache.FullReport { | 107 » if found { |
108 » » if file.FileName == fileName { | 108 » » if fileName == "" { |
109 » » » if functionName == "" { | 109 » » » return cache.FullReport, nil |
110 » » » » return file, nil | 110 » » } |
| 111 » » for _, file := range cache.FullReport { |
| 112 » » » if file.FileName == fileName { |
| 113 » » » » if functionName == "" { |
| 114 » » » » » return FuzzReportTree{file}, nil |
| 115 » » » » } |
| 116 » » » » file.filterByFunctionName(functionName) |
| 117 » » » » if lineNumber == common.UNKNOWN_LINE { |
| 118 » » » » » return FuzzReportTree{file}, nil |
| 119 » » » » } |
| 120 » » » » file.Functions[0].filterByLineNumber(lineNumber) |
| 121 » » » » return FuzzReportTree{file}, nil |
111 } | 122 } |
112 file.filterByFunctionName(functionName) | |
113 if lineNumber == common.UNKNOWN_LINE { | |
114 return file, nil | |
115 } | |
116 file.Functions[0].filterByLineNumber(lineNumber) | |
117 return file, nil | |
118 } | 123 } |
119 } | 124 } |
120 » return FileFuzzReport{}, fmt.Errorf("File %q not found", fileName) | 125 |
| 126 » return nil, fmt.Errorf("File %q not found", fileName) |
121 } | 127 } |
122 | 128 |
123 // filterByFunctionName removes all FuzzReportFunction except that which matches
functionName | 129 // filterByFunctionName removes all FuzzReportFunction except that which matches
functionName |
124 func (file *FileFuzzReport) filterByFunctionName(functionName string) { | 130 func (file *FileFuzzReport) filterByFunctionName(functionName string) { |
125 for _, function := range file.Functions { | 131 for _, function := range file.Functions { |
126 if functionName == function.FunctionName { | 132 if functionName == function.FunctionName { |
127 file.Functions = []FunctionFuzzReport{function} | 133 file.Functions = []FunctionFuzzReport{function} |
128 break | 134 break |
129 } | 135 } |
130 } | 136 } |
(...skipping 11 matching lines...) Expand all Loading... |
142 func CategoryOverview(category string) FuzzReportTree { | 148 func CategoryOverview(category string) FuzzReportTree { |
143 overview, found := currentData.caches[category] | 149 overview, found := currentData.caches[category] |
144 if found { | 150 if found { |
145 return overview.SummaryReport | 151 return overview.SummaryReport |
146 } | 152 } |
147 return FuzzReportTree{} | 153 return FuzzReportTree{} |
148 } | 154 } |
149 | 155 |
150 // FindFuzzDetailForFuzz returns a tree containing the single | 156 // FindFuzzDetailForFuzz returns a tree containing the single |
151 // report with the given name, or an error, it it doesn't exist. | 157 // report with the given name, or an error, it it doesn't exist. |
152 func FindFuzzDetailForFuzz(category, name string) (FileFuzzReport, error) { | 158 func FindFuzzDetailForFuzz(category, name string) (FuzzReportTree, error) { |
153 if cache, found := currentData.caches[category]; found { | 159 if cache, found := currentData.caches[category]; found { |
154 for _, file := range cache.FullReport { | 160 for _, file := range cache.FullReport { |
155 if file.filterByFuzzName(name) { | 161 if file.filterByFuzzName(name) { |
156 » » » » return file, nil | 162 » » » » return FuzzReportTree{file}, nil |
157 } | 163 } |
158 } | 164 } |
159 } | 165 } |
160 » return FileFuzzReport{}, fmt.Errorf("Fuzz with name %q not found", name) | 166 » return nil, fmt.Errorf("Fuzz with name %q not found", name) |
161 } | 167 } |
162 | 168 |
163 // filterByFuzzName filters out all functions that do not contain a fuzz with th
e given | 169 // filterByFuzzName filters out all functions that do not contain a fuzz with th
e given |
164 // name and returns true. If such a fuzz does not exist, it returns false. | 170 // name and returns true. If such a fuzz does not exist, it returns false. |
165 func (file *FileFuzzReport) filterByFuzzName(name string) bool { | 171 func (file *FileFuzzReport) filterByFuzzName(name string) bool { |
166 for _, function := range file.Functions { | 172 for _, function := range file.Functions { |
167 if function.filterByFuzzName(name) { | 173 if function.filterByFuzzName(name) { |
168 file.Functions = []FunctionFuzzReport{function} | 174 file.Functions = []FunctionFuzzReport{function} |
169 return true | 175 return true |
170 } | 176 } |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 490 } |
485 | 491 |
486 // containsName returns the FuzzReport and true if a fuzz with the given name is
in the list. | 492 // containsName returns the FuzzReport and true if a fuzz with the given name is
in the list. |
487 func (p SortedFuzzReports) containsName(fuzzName string) (FuzzReport, bool) { | 493 func (p SortedFuzzReports) containsName(fuzzName string) (FuzzReport, bool) { |
488 i := sort.Search(len(p), func(i int) bool { return p[i].FuzzName >= fuzz
Name }) | 494 i := sort.Search(len(p), func(i int) bool { return p[i].FuzzName >= fuzz
Name }) |
489 if i < len(p) && p[i].FuzzName == fuzzName { | 495 if i < len(p) && p[i].FuzzName == fuzzName { |
490 return p[i], true | 496 return p[i], true |
491 } | 497 } |
492 return FuzzReport{}, false | 498 return FuzzReport{}, false |
493 } | 499 } |
OLD | NEW |