oss-fuzz icon indicating copy to clipboard operation
oss-fuzz copied to clipboard

How to add code coverage for compile_native_go_fuzzer?

Open antonmedv opened this issue 1 year ago • 12 comments

I see what project expr has no coverage report.

From the documentation looks like go-fuzz should have cov reporting, but not compile_native_go_fuzzer, is that right?

How to add coverage for compile_native_go_fuzzer?

Thanks.

antonmedv avatar Sep 03 '23 09:09 antonmedv

@AdamKorcz could you assist here?

DavidKorczynski avatar Sep 03 '23 09:09 DavidKorczynski

Hi, facing same issue with mongo-go-driver, its also using compile_native_go_fuzzer https://github.com/google/oss-fuzz/blob/5f372e6e7928c9a7b78542a7b710a0020b4de4b4/projects/mongo-go-driver/build.sh#L26

Coverage report link is throwing 404, Coverage builds are passing but it shows following lines:

2023/09/12 06:27:30 failed to parse go file: open go.mongodb.org/workspace/out/libfuzzer-coverage-x86_64/mongo-driver/bson/bson_corpus_spec.go: no such file or directory
Step #5: 2023/09/12 06:27:30 failed to parse go file: open go.mongodb.org/workspace/out/libfuzzer-coverage-x86_64/mongo-driver/bson/decoder.go: no such file or directory
Step #5: 2023/09/12 06:27:30 failed to parse go file: open go.mongodb.org/workspace/out/libfuzzer-coverage-x86_64/mongo-driver/bson/encoder.go: no such file or directory
Step #5: 2023/09/12 06:27:30 failed to parse go file: open go.mongodb.org/workspace/out/libfuzzer-coverage-x86_64/mongo-driver/bson/fuzz.go: no such file or directory
Step #5: 2023/09/12 06:27:30 failed to parse go file: open go.mongodb.org/workspace/out/libfuzzer-coverage-x86_64/mongo-driver/bson/marshal.go: no such file or directory
Step #5: 2023/09/12 06:27:30 failed to parse go file: open go.mongodb.org/workspace/out/libfuzzer-coverage-x86_64/mongo-driver/bson/primitive_codecs.go: no such file or directory

manunio avatar Sep 12 '23 15:09 manunio

Seems what coverage for expr still failing. 🤔

antonmedv avatar Sep 16 '23 15:09 antonmedv

Looks like code at https://github.com/google/oss-fuzz/blob/d4f443201aa7fef94f597e49ca768cfcabe9e25b/infra/base-images/base-builder/compile_native_go_fuzzer#L52C1-L52C1 selects all go files. In my expr there are two go files. So next cp fails.

antonmedv avatar Sep 16 '23 15:09 antonmedv

Yes, it might be that it is the -r flag that causes issues. I assume you have two fuzz_test.go?

AdamKorcz avatar Sep 16 '23 16:09 AdamKorcz

I can delete fuzz_coverage_test.go

antonmedv avatar Sep 16 '23 18:09 antonmedv

After dropping fuzz_coverage_test file coverage reporting works. But it strange: coverage reported only for one file: https://storage.googleapis.com/oss-fuzz-coverage/expr/reports/20230917/linux/index.html#file0

image

Only fuzz_env.go file in coverage.

antonmedv avatar Sep 18 '23 13:09 antonmedv

After dropping fuzz_coverage_test file coverage reporting works. But it strange: coverage reported only for one file: https://storage.googleapis.com/oss-fuzz-coverage/expr/reports/20230917/linux/index.html#file0

image Only fuzz_env.go file in coverage.

Thank you for testing it out @antonmedv; I am happy that it is working. The issue with only showing a single file is in Golang: AFAIK, Golang only includes the packages that have coverage in the report.

Closing, since things are fixed on the OSS-Fuzz side.

AdamKorcz avatar Sep 21 '23 08:09 AdamKorcz

But why Expr source files were not included in the coverage report? fuzz_text calls expr.Run() but it is not included.

antonmedv avatar Sep 21 '23 09:09 antonmedv

But why Expr source files were not included in the coverage report? fuzz_text calls expr.Run() but it is not included.

Let me check that.

AdamKorcz avatar Sep 21 '23 10:09 AdamKorcz

Coverage is still reported only for one file (100%):

Screenshot 2023-10-02 at 22 53 31 Screenshot 2023-10-02 at 22 53 52

antonmedv avatar Oct 02 '23 20:10 antonmedv