QA:CodeCoverage: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
(Replaced content with "Documentation moved in-tree: https://firefox-source-docs.mozilla.org/tools/code-coverage/index.html")
 
(41 intermediate revisions by 4 users not shown)
Line 1: Line 1:
In order to perform code coverage exercise on the Firefox browser, we need to go through at least two iterations.
Documentation moved in-tree: https://firefox-source-docs.mozilla.org/tools/code-coverage/index.html
 
First : Instrument the C/C++ code in the Firefox browser using 'gcov' and run all tests against the browser.
 
Second: Instrument the javascript part of the Firefox browser and run all tests against the browser.
 
Finally we will generate a combined report which would also have the path traversal capability so that we can look at the details of coverage at the source code line level.
 
*STEP 1
 
      Create a .mozconfig file with the following statements
 
     
        export CFLAGS="-fprofile-arcs -ftest-coverage"
        export CXXFLAGS="-fprofile-arcs -ftest-coverage"
        export EXTRA_DSO_LDFLAGS="-lgcov -static-libgcc"
        export LDFLAGS="-lgcov -static-libgcc"
        ac_add_options --enable-application=browser
        mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/../mozcentral-dbg
        ac_add_options --enable-tests
        ac_add_options --enable-mochitest
        ac_add_options --enable-debug
        ac_add_options --disable-optimize
        ac_add_options --enable-jsd
        mk_add_options MOZ_MAKE_FLAGS="-j3"
        mk_add_options AUTOCONF=autoconf2.13
 
 
As of now, there is a bug https://bugzilla.mozilla.org/show_bug.cgi?id=461270 which prevents the NSPR from getting linked in the code coverage mode.
 
The work around to address this problem is as follows:
* Modify [ in the trunk you checked out ] src/nsprpub/config/rules.mk on line #352
** Change it from $(MKSHLIB) $(OBJS) $(RES) $(EXTRA_LIBS) to  $(MKSHLIB) $(OBJS) $(RES) $(EXTRA_LIBS) $(LD_FLAGS)
 
 
Execute the usual build command 'make -f client.mk build'
 
Please make sure that you have all the build dependencies installed properly before attempting the build.
 
Once the build is ready , all you have to do is to go into
 
~/mozcentral-dbg/_tests/testing/mochitest and execute the following command.
* python runtests.py
 
Please keep the focus on the Firefox browser at all times or else your tests will fail.
 
After you are done with the test runs, you will end up with a bunch of *.gcda and *.gcno files in your build directory.
 
Now, come back into your home directory and execute the following command
 
        lcov -c -i -d mozcentral-dbg -o app.info
 
The lcov tool will go through the entire build directory and generates an app.info file in your home directory
 
Then, execute the following command
 
        genhtml app.info
        If by any chance the above command fails to complete, use the following option.
        genhtml --no-source app.info
 
 
The resulting index.html is the landing page for all your code coverage data for the C/C++ code in the Firefox browser.
 
 
* STEP 2
 
Code coverage for the Javascript part of the Firefox can be dne in multiple ways.
* Using the Firebug add-on.
* Using the JSCoverage tool.
* Using the venkman.
 
I will explain in detail the efforts and the problems in using each of these approaches.

Latest revision as of 10:38, 18 May 2020