Today is for working towards finishing up Lab 3: SwatDB Heap Page and testing. We are going to quickly look at gcov code coverage tool that might be helpful as you are testing your code.

As you work on the lab, in addtion to the lab assignment page, look at the resources and information off the weekly lab pages from the past two weeks:

1. gcov

First, we are going to breifly look at the gcov code coverage tool. A code coverage tool identifies parts of the program code that are executed (and not) whe the program is run. These types of tools can are useful for code testing, as they identify paths through methods that are not taken. Often, these are error handling cases that you might be missing in your test code, but sometime it can be larger functionality.

gcov has its limitations; having 100% coverage of your HeapPage implementation tells you nothing about the quality of your tests, nor the correctness of your logic. It also does not test the interactions between different functions in your code.

Here is a new Makefile to copy into your repo that has a make gcov option to compile a version of unittest that will output gcov information when run:

First, copy and add to your lab repo, over a new version of the Lab3 Makefile that includes the -fprofile-arcs and -ftest-coverage compilation flags, and a new .gitignore file that ignores gcov generated files:

# from your Lab03-you-partner directory:
cp ~newhall/public/cs44/lab03/Makefile .
cp ~newhall/public/cs44/lab03/.gitignore .

git add Makefile .gitignore

Once you have the new Makefile: . run make gcov to compile a gcov-enabled version of the unittest program (gcovunit), and run it:

make gcov
./gcovunit
  1. Then run gcov on heappage.cpp to output coverage statistics (and similary on heappagescanner.cpp):

gcov heappage.cpp

File 'heappage.cpp'
Lines executed:78.81% of 151
Creating 'heappage.cpp.gcov'

File '/usr/include/c++/7/iostream'
Lines executed:100.00% of 1
Creating 'iostream.gcov'

File '/home/newhall/..//include/exceptions.h'
Lines executed:57.14% of 7
Creating 'exceptions.h.gcov'


gcov heappagescanner.cpp
...
  1. To To see specifically which lines of code were run (and how many times), open up heappage.cpp.gcov, an output result of gcov (you can run dos2unix on it first to get rid of ^M at end of each line):

dos2unix -f heappage.cpp.gcov
vim heappage.cpp.gcov

The series of hash symbols ### means that these lines of code were never executed. Our test suite did not test them! Maybe we should fix that by writing a new test and starting the gcov analysis again.

Below is an example from some the starting point we gave you. You can see that insertRecord is called a lot, 35 times, but the helper function _insertRecord, that is not yet implemented, is not called at all.


       35:  177:SlotId HeapPage::insertRecord(Data *record_data){
        -:  178:
       35:  179:  SlotId slot_id = 0;
        -:  180:
        -:  181:  // TODO: implement this function, and change its return value
        -:  182:
       35:  183:  return slot_id;
        -:  184:}

...
    #####:  278:void HeapPage::_insertRecord(SlotId slot_id, Data *record_data) {
        -:  279:
        -:  280:  // TODO: implement this function
        -:  281:
    #####:  282:}