Copertura del codice

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

Gli sviluppatori stanno lavorando per fa sì che il codice sorgente di MariaDB sia più coperto dalla test suite mysql-test-run (MTR). E' un processo continuo (e lento) perché vi è ancora molto vecchio codice che ha una scarsa copertura.

Obiettivi del nuovo codice

Per il codice di MariaDB, si punta molto più in alto:

Gli obiettivi sono:

  1. Tutte le nuove righe di codice dovrebbero idealmente essere testate con MTR.
  2. Il codice che non può ragionevolmente essere testato con MTR deve essere testato con un altro strumento e tali righe devono essere marcate con /* purecov: tested */.
    • In questo caso lo strumento utilizzato per il testing dovrebbe essere documentato nella relativa voce del worklog o nel messaggio che accompagna il commit.
  3. Il codice che non può essere ragionevolmente testato (come le condizioni di errore) dovrebbe essere testato con '/* purecov: inspected */' in modo tale che il revisore possa identificarlo facilmente.
  4. Il codice che si sospetta sia irraggiungibile dovrebbe avere un 'DBUG_ASSERT(0)' o essere marcato con '/* purecov: deadcode */' in modo che si possa poi verificare se viene eseguito.

Il motivo per cui si usa 'purecov' per marcare le righe è dovuto allo strumento purecov, usato originariamente per la copertura del codice nei primi anni di MySQL.

Marcatori

I marcatori raccomandati sono

/* purecov: tested */

  • Per le righe di codice che sono testate con qualcosa di diverso da mysql-test-run:

/* purecov: inspected */

  • For code lines that are hard to test but for which one has read the line multiple times to ensure it is correct. A code reviewer should also inspect these lines with care as they have not been properly tested.

/* purecov: deadcode */

  • For code lines that one suspects will never be called. Having this marker allows us to generate a warning during mysql-test-run code coverage if this line is executed.

The comment must be placed on the line/lines that are affected.

For code blocks larger than 1 line one can use the block syntax:

/* purecov: begin tested */
....
/* purecov: end */

Running mysql-test-run with gcov

To be able to see the level of coverage within the current test suite, do the following:

  1. Make sure gcov is installed
  2. Compile MariaDB with BUILD/compile-pentium-gcov (if your machine does not have a pentium CPU, hack this script, or just live with the pentium-specific stuff)
  3. In the mysql-test directory, run this command: ./mysql-test-run -gcov
  4. To see the level of coverage for a given source file:
    • grep source_file_name /tmp/gcov.out
  5. To see which lines are not yet covered, look at source_file_name.gcov in the source tree. Then think hard about a test case which will cover those lines, and write one.

Using dgcov

The dgcov tool allows to check the coverage for the new code. (Original documentation: http://forge.mysql.com/wiki/DGCov) (code: "bzr branch lp:mariadb-tools", or http://bazaar.launchpad.net/~maria-captains/mariadb-tools/trunk/view/head:/dgcov.pl)

Tools

For code coverage one can also use the lcov tool.

Work in progress

We are working on enhancing our buildbot builds to do automatic code coverage for all new pushed code.

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.