ラベル 備忘録 の投稿を表示しています。 すべての投稿を表示
ラベル 備忘録 の投稿を表示しています。 すべての投稿を表示

ステップカウンタ(コードカウンタ/Code counter)

コンソール(コマンドライン)から実行して、そのままコンソールにアウトプットを表示してくれるツールを探していたのだけれども、ようやく発見することが出来た。Line Counterってやつ。

アウトプット以下のような感じ。


-----------------------------------------------
Number of lines of code: 0
Number of directive lines: 0
Number of empty lines: 0
Number of comment lines: 0
Number of empty comment lines: 0
-------------------------------------------
Total number of lines: 0
-----------------------------------------------


CCCCってツールはコンソールから実行出来るけども、アウトプットがhtml形式だけってのが駄目だった。ステップ数だけではなく、ファイルが大きくなりすぎているとか関数が大きくなりすぎているなんて事も教えてくれるスグレモノだけに惜しい。

Allpairs(All-pairs)テスト設計支援ツール

Allpairs(All-pairs)でテスト設計(まぁ、項目を作り出すだけですが)支援ツールの使用方法

ツールはこれ!
ALLPAIRS Test Case Generation Tool

使用方法はいたって簡単。
1.因子と水準をVARS.TXT(名前はなんでもいいけど)に書き出す
->マニュアルにはエクセルで簡単に作ったのをテキストファイルにコピペすればいいって書いてある
2.ALLPAIRS VARS.TXT > TESTCASES.TXT

はい、出来上がり。


↓Excelで作ったものをコピペ

(単にタブ区切りになっているだけ)

Eclipce+CDT+(gcov or gprof)

Eclipse+CDTのgccコンパイル設定に『-pg』オプションを使用するためのチェックがあるので、それをONにしてmakeするとリンク時に『undefined reference to _mcount』というエラーが出る。

Eclipse+CDTは不親切で、リンク時には『-pg』オプションを付けてくれないようだ。なので、リンクオプションで『-pg』を別で設定してあげなければならない。リンク設定にはチェックボックスがないので、自分でタイピングするほかない。

これは、coverage(カバレッジ)を測定するときに使用する『-fprofile-arcs -ftest-coverage』オプションでも同じ。

Eclipse+CDT+CUnit

原因は調べていないけど。。。
make Ver3.8.0じゃないとビルドが通らない(Ver3.8.1じゃだめ)
gdb-20041228じゃないとデバッガが動いてくれない(gdb-20060706じゃだめ)

環境のバージョンは何だったっけか

方法は簡単。以下のようにするだけ。




file:test.c
#include <stdio.h>

void hoge(int i){
if(0 == i){
printf("i = 0\n");
}else{
printf("i != 0\n");
}
}
int main(void){
hoge(0);
return(0);
}


上記test.cをコンパイルして実行ファイルを生成する。
$gcc -Wall -pedantic -fprofile-arcs -ftest-coverage test.c -o test.exe

生成した実行ファイルを実行することによりデータファイルが自動的に作られる。
$./test.exe

データファイルからカバレッジ情報(-bオプションで分岐情報も出力)を生成する。
$ gcov -b test.c
File `test.c'
Lines executed:85.71% of 7
Branches executed:100.00% of 2
Taken at least once:50.00% of 2
Calls executed:75.00% of 4
test.c:creating `test.c.gcov'




        -:    0:Source:test.c
-: 0:Graph:test.gcno
-: 0:Data:test.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include
<stdio.h>
-: 2:
function hoge called 1 returned 100% blocks executed 80%
1: 3:void hoge(int i){
1: 4: if(0 == i){
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
1: 5: printf("i = 0\n");
call 0 returned 100%
-: 6: }else{
#####: 7: printf("i != 0\n");
call 0 never executed
-: 8: }
-: 9:}
function main called 1 returned 100% blocks executed 100%
1: 10:int main(void){
call 0 returned 100%
1: 11: hoge(0);
call 0 returned 100%
1: 12: return(0);
-: 13:}



次に分岐を一つ増やしてみる。




file:test.c
#include <stdio.h>

void hoge(int i){
if(0 == i){
printf("i = 0\n");
}else if(1 == i){
printf("i = 1\n");
}else{
printf("i != 0\n");
}
}
int main(void){
hoge(0);
return(0);
}


前と同じようにコマンドを実行する。
$gcc -Wall -pedantic -fprofile-arcs -ftest-coverage test.c -o test.exe
$./test.exe
$ gcov -b test.c
File `test.c'
Lines executed:66.67% of 9
Branches executed:50.00% of 4
Taken at least once:25.00% of 4
Calls executed:60.00% of 5
test.c:creating `test.c.gcov'




        -:    0:Source:test.c
-: 0:Graph:test.gcno
-: 0:Data:test.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include
<stdio.h>
-: 2:
function hoge called 1 returned 100% blocks executed 50%
1: 3:void hoge(int i){
1: 4: if(0 == i){
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
1: 5: printf("i = 0\n");
call 0 returned 100%
#####: 6: }else if(1 == i){
branch 0 never executed
branch 1 never executed
#####: 7: printf("i = 1\n");
call 0 never executed
-: 8: }else{
#####: 9: printf("i != 0\n");
call 0 never executed
-: 10: }
-: 11:}
function main called 1 returned 100% blocks executed 100%
1: 12:int main(void){
call 0 returned 100%
1: 13: hoge(0);
call 0 returned 100%
1: 14: return(0);
-: 15:}


左側の数字が実行ファイルを実行した時の通過回数。#####は通過していない行。