[gdal-dev] GDAL code coverage

Even Rouault even.rouault at mines-paris.org
Sun Apr 20 11:17:47 EDT 2008


Hi,

I've improved the output of the coverage report so that it reflects the 
directory structure of the GDAL source tree, which makes it more usefull to 
identify the coverage for each driver.

The archive http://home.gdal.org/tmp/coverage.zip has been updated with the 
new result.

However, the way to achieve that is a bit hackish since I had to patch both 
GCOV utility (from GCC sources) and the geninfo perl script that is used by 
the lcov perl script.

The new procedure is then :

1) Rebuild your GDAL tree with the GCC coverage options :
	CC="gcc --coverage" CXX="g++ --coverage" ./configure 'your_usual_options'
	make clean
	make
2) Run the autotest suite. This will generate .gcda files in the object 
directories of GDAL tree
3) In $(GDAL_ROOT) : create a 'coverage' subdirectory
4) In $(GDAL_ROOT) : lcov -g 
~/gcc-4.1/gcc-4.1.2/host-i686-pc-linux-gnu/gcc/gcov --directory . --capture --output-file ./gdal.info

(Replace ~/gcc-4.1/gcc-4.1.2/host-i686-pc-linux-gnu/gcc/gcov by the full path 
to the patched version of gcov) 
The patched version of geninfo is supposed to be in /usr/bin too

5) In $(GDAL_ROOT) : genhtml -o ./coverage --num-spaces 2 ./coverage/gdal.info
6) Enjoy ./coverage/index.html

Below, the 2 patches.

even at pc-amd64:~/gcc-4.1/gcc-4.1.2$ diff -u gcc/gcov.c.ori gcc/gcov.c
--- gcc/gcov.c.ori      2006-01-21 19:29:08.000000000 +0100
+++ gcc/gcov.c  2008-04-19 15:17:58.000000000 +0200
@@ -538,6 +538,33 @@
          char *gcov_file_name = make_gcov_file_name (file_name, src->name);
          FILE *gcov_file = fopen (gcov_file_name, "w");

+
+
+            struct stat status;
+            if (stat(src->name, &status) != 0)
+            {
+                char* base_name = xstrdup(basename(src->name));
+                char command[256];
+                sprintf(command, "find 
PUT_HERE_THE_PATH_TO_THE_ROOT_DIRECTORY_OF_YOUR_GDAL_SOURCE_TREE -name \"%s\" 
> /tmp/gcov.tmp", base_name);
+                system(command);
+                FILE* f = fopen("/tmp/gcov.tmp", "rt");
+                char filename[256];
+                fgets(filename, 256, f);
+                fclose(f);
+                free(base_name);
+                if (strchr(filename, '\n'))
+                {
+                    *strchr(filename, '\n') = 0;
+                    fprintf(stderr, "%s -> %s\n", src->name, filename);
+                    free(src->name);
+                    src->name = xstrdup(filename);
+                }
+                else
+                {
+                    fprintf(stderr, "cannot find %s in %s\n", src->name, 
getcwd(filename, 256));
+                }
+            }
+
          if (gcov_file)
            {
              fnotice (stdout, "%s:creating '%s'\n",

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

even at pc-amd64:/usr/bin$ diff -u /usr/bin/geninfo.backup  /usr/bin/geninfo
--- /usr/bin/geninfo.backup     2008-04-19 15:08:59.000000000 +0200
+++ /usr/bin/geninfo    2008-04-19 15:31:59.000000000 +0200
@@ -625,8 +625,8 @@
                        warn("WARNING: cannot find an entry for ".$gcov_file.
                             " in $graph_file_extension file, skipping ".
                             "file!\n");
-                       unlink($gcov_file);
-                       next;
+#unlink($gcov_file);
+#next;
                }

                # Read in contents of gcov file
@@ -642,17 +642,19 @@
                        next;
                }

-               if (scalar(@matches) == 1)
-               {
-                       # Just one match
-                       $source_filename = $matches[0];
-               }
-               else
-               {
-                       # Try to solve the ambiguity
-                       $source_filename = solve_ambiguous_match($gcov_file,
-                                               \@matches, \@gcov_content);
-               }
+#              if (scalar(@matches) == 1)
+#              {
+#                      # Just one match
+#                      $source_filename = $matches[0];
+#              }
+#              else
+#              {
+#                      # Try to solve the ambiguity
+#                      $source_filename = solve_ambiguous_match($gcov_file,
+#                                              \@matches, \@gcov_content);
+#              }
+
+                $source_filename = $source;

                # Remove processed file from list
                for ($index = scalar(@unprocessed) - 1; $index >= 0; $index--)




Le Sunday 13 April 2008 22:26:34 Even Rouault, vous avez écrit :
> Hi,
>
> I experimented a bit gcov on GDAL to see the code coverage of the python
> autotest suite.
>
> The result on my own GDAL tree (roughly latest trunk with some personnal
> changes) is available at : http://home.gdal.org/tmp/coverage.zip.
>
> The output is not as nice as I would have wished as it was tricky to make
> the coverage report generator find the source files.
>
> Here's the procedure I followed to generate the report :
>
> 1) Rebuild your GDAL tree with the GCC coverage options :
> 	CC="gcc --coverage" CXX="g++ --coverage" ./configure 'your_usual_options'
> 	make clean
> 	make
> 2) Run the autotest suite. This will generate .gcda files in the object
> directories of GDAL tree
> 3)  In $(GDAL_ROOT) : create a 'coverage' subdirectory
> 4)  In $(GDAL_ROOT) :
> 		lcov --directory . --capture --output-file ./coverage/gdal.info
>
> 	This will fail as lcov doesn't manage to find the source files. I had to
> add various symbolic links. The main steps are :
> 		cd $(GDAL_ROOT)/ogr/ogrsf_frmts/o
> 		for i in `find ../../.. -name "*.c*" | grep -v svn`; do ln -s $i; done
> 		for i in `find ../../.. -name "*.h*" | grep -v svn`; do ln -s $i; done
> 		ln -s ../geojson/jsonc .
> 		cd ..
> 		ln -s ili/iom
> 		cd $(GDAL_ROOT)/frmts/o
> 		for i in `find .. -name "*.c*" | grep -v svn`; do ln -s $i; done
> 		for i in `find .. -name "*.h*" | grep -v svn`; do ln -s $i; done
> 		ln -s ../pcraster/libcsf .
> 		ln -s ../gtiff/libtiff .
> 		ln -s ../gtiff/libgeotiff .
> 		ln -s ../grib/degrib18 .
>
> Try 'lcov --directory . --capture --output-file ./coverage/gdal.info' and
> add all necessary symbolic links until this finally works
>
> 5) In $(GDAL_ROOT) : genhtml -o ./coverage --num-spaces 2
> ./coverage/gdal.info
>
> 6) Enjoy ./coverage/index.html
>
> If someone knows how to tell lcov how to find the source files where they
> really are instead of creating all those symbolic links that would be great
> !
>
>
> Even
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev




More information about the gdal-dev mailing list