tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] implement test coverage


From: Herman ten Brugge
Subject: [Tinycc-devel] implement test coverage
Date: Sat, 23 Jan 2021 18:25:31 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0

I have implemented the -ftest-coverage option. It works a bit different
from the gcc version. It output .tcov text file which looks almost the
same as a gcov file after an executable/so file is run.

For example you can now do (x86_64 example):

git clone git://repo.or.cz/tinycc.git
cd tinycc
./configure --prefix=`pwd`/install --with-selinux
make; make install
./tcc -ftest-coverage -Iinclude -I. -DCONFIG_LDDIR="\"lib64\"" -DTCC_TARGET_X86_64 tcc.c -o tcc.tcc -lm -ldl -lpthread
mv tcc.tcc tcc
make test

After the tests have finished a file called tcc.tcc.tcov (the name of the
compiled executable) is present with code coverage of all testcases run.
It contains an overall entry, an entry per file and an entry per function.

        -:    0:Runs:183
        -:    0:All:/tmp/tinycc/tcc.tcc.tcov Files:13 Functions:598 75.93%
        -:    0:File:/tmp/tinycc/tccpp.c Functions:89 79.68%
...
        -:   98:ST_FUNC void skip(int c)
        -:   99:{
        -:    0:Function:skip 100.00%
  1766536:  100:    if (tok != c)
        3:  101:        tcc_error("'%c' expected (got \"%s\")", c, get_tok_str(tok, &tokc));
  1766533:  102:    next();
        -:  103:}

This also works for shared object files. The name is sofile.tcov

Code coverage is difficult for code like:

        -:  348:char *unicode_to_utf8 (char *b, uint32_t Uc)
        -:  349:{
        -:    0:Function:unicode_to_utf8 18.18%
       2*:  350:    if (Uc<0x80) *b++=Uc;
        2:  351:    else if (Uc<0x800) *b++=192+Uc/64, *b++=128+Uc%64;
    #####:  352:    else if (Uc-0xd800u<0x800) return b;
    #####:  353:    else if (Uc<0x10000) *b++=224+Uc/4096, *b++=128+Uc/64%64, *b++=128+Uc%64;     #####:  354:    else if (Uc<0x110000) *b++=240+Uc/262144, *b++=128+Uc/4096%64, *b++=128+Uc/64%64, *b++=128+Uc%64;
        -:  355:    return b;
        -:  356:}

The problem is that there are 2 code blocks on one line.
A '*' is used if the code after the if is not executed (same as gcov).

    Herman



reply via email to

[Prev in Thread] Current Thread [Next in Thread]