Overview of code coverage metrics

Unit tests are essential in software engineering nowadays. The quality of software begins with unit testing, but they are useless if there isn’t a metric or an indicator that shows how good the unit tests are. This is called code coverage. There are different kinds of code coverage metrics.

Statement Coverage

Let’s say we’ve got the following code

int myMethod(int x)
{
    do
    {
        /* some stuff */
    }while(x == 0);

    return -42;
}

A unit test (in this case CPPUnit light) for this could be

TEST(Quick, test)
{
    CHECK(myMethod(1) == -42);
}

Statement coverage means, as you might expect, that every statement is covered, which is the case with the test above. But there are several flaws in this. The potential endless loop isn’t covered or even detectable. Also, depending on the compiler, there might be machine code, which is still untested.

Decision or Branch Coverage

Again another example:

int myMethod(bool a, bool b)
{
    int result = 0;

    if(a && b){
            result = 1;
    }

    return result;
}

A unit tests for this could be:

TEST(Quick, test)
{
    CHECK(myMethod(true, false) == 0);

    CHECK(myMethod(true, true) == 1);
}

With branch coverage, every control flow needs to be tested and that means two tests. With code coverage only one test would be necessary.

Decision and Condition Coverage

If you look at the last unit test example, you can see that variable a wasn’t changed. Decision and condition coverage means, that every variable has to have every possible condition. In this case

TEST(Quick, test)
{
    CHECK(myMethod(true, false) == 0);

    CHECK(myMethod(false, true) == 1);
}

Modified Condition and Decision Coverage

A much more intensified approach is the modified condition and decision coverage (MC/DC). MC/DC is often used in a high risk environment. It is also used by NASA (see [1]). It’s supposed to show that every condition could have influence on the control flow. In this case it means three tests (n condition – 1).

TEST(Quick, test)
{
    CHECK(myMethod(true, true) == 1);

    CHECK(myMethod(false, true) == 0);

    CHECK(myMethod(true, false) == 0);
}

Which metric should I use?

There is no correct answer for this. It depends on the purpose of the system or device. For a lower risk, just choose statement coverage or branch coverage. If there is a higher risk, branch or decision and condition coverage is always a good choice. If you develop spacecrafts or an artificial lung, as a customer I would highly appreciate the modified condition and decision coverage.

[1]: http://shemesh.larc.nasa.gov/fm/papers/Hayhurst-2001-tm210876-MCDC.pdf

Posted in C/C++, Development | Tagged , , , , | Leave a comment

Unable to play DVDs on Xubuntu or GStreamer backend error

Despite the fact that DVDs are a little bit old fashioned, I tried to watch one the other day. To my surprise I wasn’t able to do so. Every time I tried I got the following error

GStreamer backend error
Could not read DVD. This may be because the DVD is encrypted and a DVD decryption library is not installed.

But I already installed the library. I added the Medibuntu repository with the following command

sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get --quiet update && sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring && sudo apt-get --quiet update

and installed libdvdcss2

sudo apt-get install libdvdcss2 -y

But I still wasn’t able to watch the DVD. As it turned out, I need to set the region of the DVD drive. That’s pretty simply done with the tool regionset, which can be installed with your favorite package manager. Afterwards just execute the tool and set the region with the wizard.

regionset /dev/sr0

Posted in Linux, Technology | Tagged , , , , | Leave a comment

Using nmap to find a Raspberry Pi within a network

I find it really annoying to connect an HDMI monitor and a keyboard to the Pi, in order to get the IP address to connect with SSH. The terminal program nmap is able to scan your network and gets the IP easily.

If nmap isn’t installed, install it with your favorite paket manager. On debian based systems you can use the following command:

sudo apt-get install nmap

Get your own ip with the following command.

ifconfig

In my case my address is 192.168.1.106. This means that the Pi must be also within this range. The following command scans between 192.168.1.0 and 255.255.255.255, but the maximum has to be entered as CIDR and in binary. The binary value of each section (max number is 255) is 11111111, in sum 24 x 1 and that is exactly what needs to be entered.

nmap 192.168.1.0/24

The result of the command depends on the network. In my case it looks like the following:

Nmap scan report for 192.168.1.103
Host is up (0.045s latency).
Not shown: 999 closed ports
PORT STATE SERVICE
22/tcp open ssh

After you got the IP, you can use ssh to get access to the PI with the username pi and the password raspberry

ssh pi@192.168.1.103

I highly recommend to change the password after you successfully logged in for the first time.

Posted in Linux, Technology | Tagged , , , | Leave a comment

Step by step installation of Raspbian on a Raspberry Pi

First of all, download Raspbian. Check the website for the latest version. In my case I used wget to download the version:

wget http://212.187.212.42/bt/29aa44acfa3a7a78dd438e9e91dd3142247817fd/data/2014-09-09- wheezy-raspbian.zip

Get the checksum to check if the download was correct:

sha1sum 2014-09-09-wheezy-raspbian.zip

Unpack the zip archive:

unzip 2014-09-09-wheezy-raspbian.zip

Check all block devices with the following command, before you put the SD card into your PC:

lsblk

Unmount the partition:

sudo umount /dev/

Copy the img file to the SD card – Be careful not to overwrite your HDD.

sudo dd if=2014-09-09-wheezy-raspbian.img of=/dev/ bs=4k

You’re finished. Put the SD card into the Pi and turn it on.

Posted in Linux, Technology | Tagged , , | 1 Comment

Podcasts recommendations

I listen to podcasts nearly every day during my commute with my bicycle and I do love podcasts. Here is a short list of recommendations.

Stuff you should know
I know “Stuff you should know” for nearly one year now and it is definitely my favorite. Each episode is 30 min ish long, which makes is perfect for me and the topics are often interesting. The best thing is, however, that the hosts, Josh and Chuck, explain in a very funny and way. Sometimes I just want to listen to them, even if the topic is boring.

Hanselminutes
If you’re a .NET developer, you know Scott Hanselman. His podcast hanselminutes is often interesting. Scott is a .NET and C# developer by heart, but his podcasts isn’t focused on .NET only.

Chaosradio (German)
Chaosradio is the radio show of the Chaos Computer Club in Germany. The radio show started in 1996 and my first listen was back in 1998. Sometimes very technical, but every time interesting.

Posted in Linux, Other, Technology, Windows | Tagged , , | Leave a comment

Xubuntu, Code::Blocks and Ctrl+F9

Code::Blocks uses the Shortcut Ctrl + F9 to do a build. Unfortunately uses Xubuntu in its default settings Ctrl + F9 to switch to the workspace 9, if available. Xfce wins over Code::Blocks, which means Ctrl + F9 simply doesn’t work.

The solution is simple: Open Settings, go to Window Manager and clear the Workspace 9 shortcut.

windowmanager

Posted in C/C++, Development, Linux, Technology | Tagged , | Leave a comment

The problem with smartwatches

Smartwatches are a thing now, at least that what most of the tech news sites or the Apple Watch marketing department says. THEY must be right.

I own a smartwatch for nearly a year now. I bought a Pebble, because I think their concept is one of the best, even if it is one of the first and oldest ones. I love the display, because I am able to read it in every situation or condition, even in direct sunlight. The battery time is just awesome. Mine lasts for ten days.

I’m used to have a smartwatch and to get messages, calls or notifications directly to my watch. The vibration of the watch is key and it makes sure I don’t miss anything. My phone is in silent mode nowadays, because I don’t need the tones or the vibration anymore. Every notification is silent and only noticeable to me.

There is just one bad thing, that heads other people to the perception that I’m being impolite.

When I get a message I immediatly look at my watch, even if I talk to other people. People now tend to think that I need to go or that I don’t have enough time, sometimes they think that their topic isn’t that interesting to me or that I don’t care. People these days know that there are smart watches, but they barely have seen one. No one expects that I’m having one. No one knows that I’ve just looked what happened. If I would use my phone instead, people wouldn’t have a problem, because I guess that this is socially widely accepted, even that it is still kind of impolite, too.

So, I need to keep in mind not to look at my watch during a conversation or – more important – a meeting.

Posted in Technology | Tagged , , | Leave a comment