QA:CodeCoverage
In order to perform code coverage exercise on the Firefox browser, we need to go through at least two iterations.
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.