Fix up documentation + go fmt.

pull/945/head
Morten Siebuhr 9 years ago
parent 7371dcc787
commit 9eb2e98509

@ -1,67 +1,91 @@
package promql // Copyright 2015 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Only build when go-fuzz is in use
// +build gofuzz // +build gofuzz
/* PromQL parser fuzzing instrumentation for use with https://github.com/dvyukov/go-fuzz. package promql
*
* Fuzz each parser by building appropriately instrumented parser, ex. FuzzParseMetric and execute it with it's // PromQL parser fuzzing instrumentation for use with
* // https://github.com/dvyukov/go-fuzz.
* go-fuzz-build -func FuzzParseMetric -o FuzzParseMetric.zip github.com/prometheus/prometheus/promql //
* // Fuzz each parser by building appropriately instrumented parser, ex.
* And then run the tests with the appropriate inputs // FuzzParseMetric and execute it with it's
* //
* go-fuzz -bin FuzzParseMetric.zip -workdir fuzz-data/ParseMetric // go-fuzz-build -func FuzzParseMetric -o FuzzParseMetric.zip github.com/prometheus/prometheus/promql
* //
* Further input samples should go in the folders fuzz-data/ParseMetric/corpus. // And then run the tests with the appropriate inputs
* //
* Repeat for ParseMetricSeletion, ParseExpr and ParseStmt // go-fuzz -bin FuzzParseMetric.zip -workdir fuzz-data/ParseMetric
*/ //
// Further input samples should go in the folders fuzz-data/ParseMetric/corpus.
//
// Repeat for ParseMetricSeletion, ParseExpr and ParseStmt.
// Tuning which value is returned from Fuzz*-functions has a strong influence
// on how quick the fuzzer converges on "interesting" cases. At least try
// switching between fuzzMeh (= included in corpus, but not a priority) and
// fuzzDiscard (=don't use this input for re-building later inputs) when
// experimenting.
const ( const (
fuzz_interesting = 1 fuzzInteresting = 1
fuzz_meh = 0 fuzzMeh = 0
fuzz_discard = -1 fuzzDiscard = -1
) )
// Fuzz the metric parser // Fuzz the metric parser.
//
// Note that his is not the parser for the text-based exposition-format; that
// lives in github.com/prometheus/client_golang/text.
func FuzzParseMetric(in []byte) int { func FuzzParseMetric(in []byte) int {
_, err := ParseMetric(string(in)) _, err := ParseMetric(string(in))
if err == nil { if err == nil {
return fuzz_interesting return fuzzInteresting
} }
return fuzz_discard return fuzzDiscard
} }
// Fuzz the metric selector parser // Fuzz the metric selector parser.
func FuzzParseMetricSelector(in []byte) int { func FuzzParseMetricSelector(in []byte) int {
_, err := ParseMetricSelector(string(in)) _, err := ParseMetricSelector(string(in))
if err == nil { if err == nil {
return fuzz_interesting return fuzzInteresting
} }
return fuzz_discard return fuzzDiscard
} }
// Fuzz the expression parser // Fuzz the expression parser.
func FuzzParseExpr(in []byte) int { func FuzzParseExpr(in []byte) int {
_, err := ParseExpr(string(in)) _, err := ParseExpr(string(in))
if err == nil { if err == nil {
return fuzz_interesting return fuzzInteresting
} }
return fuzz_discard return fuzzDiscard
} }
// Fuzz the parser // Fuzz the parser.
func FuzzParseStmts(in []byte) int { func FuzzParseStmts(in []byte) int {
_, err := ParseStmts(string(in)) _, err := ParseStmts(string(in))
if err == nil { if err == nil {
return fuzz_interesting return fuzzInteresting
} }
return fuzz_discard return fuzzDiscard
} }

Loading…
Cancel
Save