カバレッジ データから詳細な情報を抽出
この例では、カバレッジのユーティリティ コマンドを使用して、cvdata オブジェクトから個々のサブシステム、ブロック、または Stateflow® オブジェクトの情報を抽出する方法を示します。
モデル例
この例では、サポートされているさまざまなカバレッジ メトリクスの要素を含む小さいモデルのカバレッジ データに、コマンド ラインを使用してアクセスする方法を説明します。
次のコマンドを使用して、モデル 'slvnvdemo_cv_small_controller' と、そのサブシステム 'Gain' を開きます。
open_system('slvnvdemo_cv_small_controller'); open_system('slvnvdemo_cv_small_controller/Gain');

カバレッジ データと HTML レポートの生成
simを使用して、モデルのシミュレーションを実行します。Simulink.SimulationInputオブジェクトを使用してカバレッジ設定をキャプチャし、それを sim への入力として使用します。シミュレーション後、カバレッジ データは cvdata オブジェクトに格納されます。
simIn = Simulink.SimulationInput('slvnvdemo_cv_small_controller'); simIn = simIn.setModelParameter('CovEnable','on'); simIn = simIn.setModelParameter('CovMetricStructuralLevel','MCDC'); simIn = simIn.setModelParameter('CovSaveSingleToWorkspaceVar','on'); simIn = simIn.setModelParameter('CovSaveName','covData'); simIn = simIn.setModelParameter('CovScope','EntireSystem'); simIn = simIn.setModelParameter('CovMetricLookupTable','on'); simIn = simIn.setModelParameter('CovMetricSignalRange','on'); simOut = sim(simIn);
cvsim コマンドから返されるカバレッジ データを、レポート生成コマンド cvhtml で処理します。結果のレポートは、モデル全体のモデル カバレッジの便利な表現です。
cvhtml('tempfile.html',covData);
カバレッジ データはシミュレーション出力オブジェクトでも使用できます。
simOut
simOut =
Simulink.SimulationOutput:
covData: [1x1 cvdata]
tout: [59x1 double]
yout: [59x1 double]
SimulationMetadata: [1x1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char]
判定カバレッジ情報の抽出
decisioninfo コマンドを使用して、個々の Simulink ブロックまたは Stateflow オブジェクトの判定カバレッジ情報を抽出します。
次のコマンドは、モデル全体のカバレッジ配列を抽出します。1 番目の要素は、モデルについて達成されたカバレッジ オブジェクティブの結果の数です。2 番目の要素は、モデルについてのカバレッジ オブジェクティブの結果の合計の数です。
cov = decisioninfo(covData,'slvnvdemo_cv_small_controller')
percent = 100*cov(1)/cov(2)
cov =
4 6
percent =
66.6667
ブロックの絶対パスを使用して 'Saturation' ブロックのカバレッジ情報を取得します。そのブロック内のカバレッジ オブジェクティブの結果のテキストによる説明のための 2 番目の戻り引数を提供します。
[blkCov, description] = decisioninfo(... covData,'slvnvdemo_cv_small_controller/Saturation') decision1 = description.decision(1).text out_1a = description.decision(1).outcome(1).text count_1a = description.decision(1).outcome(1).executionCount out_1b = description.decision(1).outcome(2).text count_1b = description.decision(1).outcome(2).executionCount
blkCov =
3 4
description =
struct with fields:
isFiltered: 0
justifiedCoverage: 0
isJustified: 0
filterRationale: ''
decision: [1×2 struct]
decision1 =
'U >= LL'
out_1a =
'false'
count_1a =
0
out_1b =
'true'
count_1b =
7
量的カバレッジ情報は、カバレッジ オブジェクティブの結果を含むまたはもつ階層内の、それぞれの結果に対して使用できます。テキストによる説明は、自身がカバレッジ オブジェクティブの結果をもつオブジェクトについてのみ生成されます。たとえば、バーチャル サブシステム Gain に対して decisioninfo を呼び出すと、説明の戻り値は空になります。
[blkCov, description] = decisioninfo(... covData,'slvnvdemo_cv_small_controller/Gain')
blkCov =
1 2
description =
struct with fields:
isFiltered: 0
justifiedCoverage: 0
isJustified: 0
filterRationale: ''
あるオブジェクトに内部的なカバレッジ オブジェクティブがあるものの、追加のカバレッジ オブジェクティブをもつ子孫も含まれている場合があります。子孫の無視を表す 3 番目の引数が 1 に設定されている場合を除き、カバレッジ情報には通常、すべての子孫が含まれています。
subsysOnlycov = decisioninfo(... covData,'slvnvdemo_cv_small_controller/Gain',1)
subsysOnlycov =
[]
decisioninfo コマンドは、ブロック ハンドル、Stateflow ID および Stateflow API オブジェクトにも対応します。
blkHandle = get_param('slvnvdemo_cv_small_controller/Saturation','Handle') blkCov = decisioninfo(covData,blkHandle)
blkHandle =
336.0029
blkCov =
3 4
判定カバレッジをもたないオブジェクトの場合、コマンドは空の出力を返します。
missingBlkCov = decisioninfo(covData,'slvnvdemo_cv_small_controller/Sine1')
missingBlkCov =
[]
条件カバレッジ情報の抽出
条件カバレッジは、論理式への論理入力が true と false の両方に評価されたかどうかを示します。Simulink では、条件は論理演算に対する入力です。
条件カバレッジ情報を抽出するための conditioninfo コマンドは、decisioninfo コマンドによく似ています。通常は、オブジェクトおよびそのすべての子孫に関する情報を返しますが、子孫を無視するかどうかを示す 3 番目の引数を取ることもできます。また、各条件の説明を含む 2 番目の出力を返すこともできます。
cov = conditioninfo(covData,'slvnvdemo_cv_small_controller/Gain/Logic') [cov, desc] = conditioninfo(... covData,'slvnvdemo_cv_small_controller/Gain/Logic'); desc.condition(1) desc.condition(2)
cov =
2 4
ans =
struct with fields:
isFiltered: 0
isJustified: 0
filterRationale: ''
text: 'port1'
trueCnts: 59
falseCnts: 0
trueOutcomeFilter: [1×1 struct]
falseOutcomeFilter: [1×1 struct]
trueExecutedIn: []
falseExecutedIn: []
ans =
struct with fields:
isFiltered: 0
isJustified: 0
filterRationale: ''
text: 'port2'
trueCnts: 0
falseCnts: 59
trueOutcomeFilter: [1×1 struct]
falseOutcomeFilter: [1×1 struct]
trueExecutedIn: []
falseExecutedIn: []
改良条件判定カバレッジ情報の抽出
論理式内の条件に対して改良条件判定カバレッジ (MCDC) が達成されるのは、"独立ペア" を表す式の評価が 2 つあり、その条件の値が式全体の結果に個々に影響する場合です。つまり、これらの評価においては、条件の値を切り替えた場合、式の結果も同様に切り替えられることになります。
この例では、論理 AND ブロックが MCDC 用に解析され、mcdcinfo コマンドを使用してこの情報を抽出できます。このコマンドは、conditioninfo および decisioninfo コマンドと同じ構文を使用します。
[cov, desc] = mcdcinfo(covData,'slvnvdemo_cv_small_controller/Gain/Logic')
desc.condition(1)
desc.condition(2)
cov =
0 2
desc =
struct with fields:
text: 'Output'
condition: [1×2 struct]
isFiltered: 0
filterRationale: ''
justifiedCoverage: 0
ans =
struct with fields:
text: 'port1'
achieved: 0
trueRslt: '(TT)'
falseRslt: '(FT)'
isFiltered: 0
isJustified: 0
filterRationale: ''
trueExecutedIn: []
falseExecutedIn: []
ans =
struct with fields:
text: 'port2'
achieved: 0
trueRslt: '(TT)'
falseRslt: 'TF'
isFiltered: 0
isJustified: 0
filterRationale: ''
trueExecutedIn: []
falseExecutedIn: []
ルックアップ テーブル カバレッジ情報の抽出
ルックアップ テーブル カバレッジは、内挿間隔ごとのルックアップの発生頻度を記録します。カバレッジ目的で有効な間隔には、最小ブレークポイントより小さい値と、最大ブレークポイントより大きい値も含まれます。他のコマンドとの整合性を保つために、この情報は、実行した間隔の数と間隔の合計数のカウントのペアとして返されます。
2 番目の出力引数を指定すると、tableinfo はすべての内挿間隔の実行数を返します。テーブルが M 行 N 列の出力値をもつ場合、実行数は M+1 行 N+1 列の行列で返されます。
3 番目の出力引数を指定すると、tableinfo は入力とブレークポイントが厳密に等しくなるカウント数を返します。これは、それぞれがテーブル内の各次元に対応するベクトルの cell 配列で返されます。
[cov,execCnts,brkEq] = tableinfo(covData, ... 'slvnvdemo_cv_small_controller/Gain/Gain Table')
cov =
23 121
execCnts =
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 2 12 14 10 2 0 0 0
0 0 4 12 0 0 0 12 0 0 0
0 0 22 0 0 0 0 0 12 0 0
0 0 21 0 0 0 0 0 59 0 0
0 0 21 0 0 0 0 0 29 0 0
0 0 7 28 0 0 0 28 6 0 0
0 0 0 4 22 18 23 5 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
brkEq =
1×2 cell array
{10×1 double} {10×1 double}
信号範囲情報の抽出
信号範囲メトリクスは、Simulink ブロック出力と Stateflow データ オブジェクトの最小値と最大値を記録します。sigrangeinfo コマンドは、最小値と最大値の 2 つの戻り引数を個別に返します。
sigrangeinfo コマンドは、計算を実行するリーフ ブロックに対してのみ機能し、それ以外の場合は空の引数を返します。リーフ ブロックは、Product ブロックなど、子ブロックをもたないブロックです。非リーフ ブロックは、Subsystem など、子ブロックをもつブロックです。
たとえば、Gain Table という名前のリーフ ブロックの信号範囲の結果を、Gain という名前の Subsystem ブロックの信号範囲の結果と比較します。
[sigMin, sigMax] = sigrangeinfo(covData,... 'slvnvdemo_cv_small_controller/Gain/Gain Table') [sigMin, sigMax] = sigrangeinfo(covData,... 'slvnvdemo_cv_small_controller/Gain')
sigMin =
3.3656
sigMax =
7.6120
sigMin =
[]
sigMax =
[]