Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage #13046

Open
3d4m-volodymyr opened this issue Dec 15, 2020 · 10 comments
Open

Code coverage #13046

3d4m-volodymyr opened this issue Dec 15, 2020 · 10 comments

Comments

@3d4m-volodymyr
Copy link

Is there anything done in emscripten for enabling Tests Code Coverage reports generation?

I found this very interesting article on how to do it manually.
Requires to recompile compiler-rt.

@sbc100
Copy link
Collaborator

sbc100 commented Dec 15, 2020

I don't think we have any direct support for that today, but its sounds like it would be fairly easy to add.

Sounds like it would involve a new option and new compiler-rt variant added to tools/system_libs.py

@3d4m-volodymyr
Copy link
Author

3d4m-volodymyr commented Dec 15, 2020

Is this the place to start looking at https://github.com/emscripten-core/emscripten/blob/master/tools/system_libs.py#L642 ?

I never dealt with the internals of emscripten. Probably will have lots of questions.

sbc100 added a commit that referenced this issue Dec 18, 2020
This is enought make it work up until llvm-cov tries to read the
named data sections in the binary and can't find them.  For this
final part to work we probably need to switch the object format to
using multiple code and data sections:
WebAssembly/tool-conventions#138

Not sure if its worth submitting this part in isolation without
a fully working solution?

See #13046
@sbc100
Copy link
Collaborator

sbc100 commented Dec 18, 2020

I took an initial stab at getting this to work: #13072

It works up until llvm-cov fails to parse the data sections in the wasm executable.

sbc100 added a commit that referenced this issue Dec 26, 2020
This is enought make it work up until llvm-cov tries to read the
named data sections in the binary and can't find them.  For this
final part to work we probably need to switch the object format to
using multiple code and data sections:
WebAssembly/tool-conventions#138

Not sure if its worth submitting this part in isolation without
a fully working solution?

See #13046
@nokotan
Copy link
Contributor

nokotan commented Oct 27, 2021

It seems that the gcc-like coverage tool will get worked with #13072.

Adding compile option -fprofile-arcs -ftest-coverage generates vaild *.gcdo into physical file system and *.gcda into virtual file system.
llvm-cov gcov is also working completely using these *.gcdo, *gcda files.

Therefore, I think that we have already a good reason to merge #13072.

@emaxx-google
Copy link

Hello, is there any update on this effort?
(We're looking into ways to set up coverage analysis for Google Smart Card Connector, and IIUC currently the only workaround is to switch to the regular clang/gcc, but this doesn't let test the code in the WebAssembly environment.)

@AnnieXia
Copy link

emcc -fprofile-instr-generate -fcoverage-mapping demo.cpp

wasm-ld: error: /var/folders/61/x35v93n50_5g1dfjrtprr2dw0000gn/T/emscripten_temp_xjrzk63_/demo_0.o: undefined symbol: __llvm_profile_runtime

have emcc supported code coverage? need help :)

@sbc100
Copy link
Collaborator

sbc100 commented Oct 17, 2022

No, emcc does not yet support this method of doing code coverage. #13072 is a start, but that has yet to land.

@junyuecao
Copy link
Contributor

junyuecao commented Mar 2, 2023

It looks like SanitizerCoverage works. I've tried the demo by replacing clang++ to em++

em++ -g  -fsanitize-coverage=trace-pc-guard trace-pc-guard-example.cc -c
em++ trace-pc-guard-cb.cc trace-pc-guard-example.o -fsanitize=address -sNO_EXIT_RUNTIME -o trace-pc-guard-cb.html

And the result can be printed as expected.
image

@3d4m-volodymyr
Copy link
Author

@junyuecao this is not the same.

@bbarwik
Copy link

bbarwik commented Oct 19, 2023

Hey. I've created a tutorial how to generate code coverage for webassembly projects. This one is dedicated for blockchains using WASM VM, however I think it may be useful to you too - https://github.com/hknio/code-coverage-for-webassembly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants