このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
コード カバレッジ テストの生成
この例では、Simulink® Design Verifier™ を使用してテスト ケースを生成し、完全なコード カバレッジを取得する方法を説明します。
まず、ソフトウェアインザループ (SIL) シミュレーション モード用に設定されたモデル例のコード カバレッジを収集します。次に、Simulink® Design Verifier™ を使用して、テスト ケースを生成するテスト スイートを作成します。最後に、生成されたテスト ケースを SIL シミュレーション モードで実行し、フル カバレッジを検証します。
製品の可用性のチェック
Simulink® Coder™ と Embedded Coder™ ソフトウェアがマシンにインストールされていることを確認してください。
if ~(license('test', 'Real-Time_Workshop') && ... license('test','RTW_Embedded_Coder')) return end
初期設定
必ず、未編集バージョンのモデルを開きます。
model = 'sldv_cruise_control';
close_system(model, 0)
open_system(model)
SIL ベースのテストを生成するためのモデルの設定
1.[コンフィギュレーション パラメーター] ウィンドウで、[コード生成] をクリックして [システム ターゲット ファイル] を ert.tlc
に設定します。または、以下を入力します。
set_param(model,'SystemTargetFile','ert.tlc');
2.[ハードウェア実行] をクリックし、[デバイス ベンダー] と [デバイス タイプ] を SIL システムのベンダーとタイプに設定します。たとえば、64 ビットの Linux マシンの場合は、[デバイス ベンダー] を Intel
に、[デバイス タイプ] を x-86-64(Windows)
に設定します。または、以下を入力します。
if ismac lProdHWDeviceType = 'Intel->x86-64 (Mac OS X)'; elseif isunix lProdHWDeviceType = 'Intel->x86-64 (Linux 64)'; else lProdHWDeviceType = 'Intel->x86-64 (Windows64)'; end set_param(model, 'ProdHWDeviceType', lProdHWDeviceType);
カバレッジ計算のテスト ケースの検出
Simulink® Design Verifier™ を使用して sldv_cruise_control
モデルを解析し、より広いコード カバレッジを達成するテスト スイートを生成します。最上位モデルの MCDC カバレッジを達成するテスト ケースを生成するように、Simulink® Design Verifier™ のオプションを設定します。
opts = sldvoptions; opts.TestgenTarget = 'GenCodeTopModel'; opts.Mode = 'TestGeneration'; [~, files] = sldvrun(model, opts, true);
### Starting build procedure for: sldv_cruise_control ### Successful completion of build procedure for: sldv_cruise_control ### Preparing to start SIL simulation ... Building with 'gcc'. MEX completed successfully. ### Starting SIL simulation for component: sldv_cruise_control ### Stopping SIL simulation for component: sldv_cruise_control ### Starting build procedure for: sldv_cruise_control ### Generated code for 'sldv_cruise_control' is up to date because no structural, parameter or code replacement library changes were found. ### Successful completion of build procedure for: sldv_cruise_control Build Summary Top model targets built: Model Action Rebuild Reason ============================================================================== sldv_cruise_control Code compiled. Compilation artifacts were out of date. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 2.4465s ### Preparing to start SIL simulation ... ### Starting SIL simulation for component: sldv_cruise_control ### Stopping SIL simulation for component: sldv_cruise_control ### Completed code coverage analysis ### Starting SIL simulation for component: sldv_cruise_control ### Stopping SIL simulation for component: sldv_cruise_control ### Completed code coverage analysis ### Starting SIL simulation for component: sldv_cruise_control ### Stopping SIL simulation for component: sldv_cruise_control ### Completed code coverage analysis ### Starting SIL simulation for component: sldv_cruise_control ### Stopping SIL simulation for component: sldv_cruise_control ### Completed code coverage analysis
メモ: スクリプトを実行すると、SIL テスト生成によってコードが再生成され再コンパイルされます。
フル カバレッジの検証
関数 sldvruntest
は、生成されたテスト スイートを使用してモデルをシミュレートします。関数 cvhtml
が生成するカバレッジ レポートは、sldvdemo_cruise_control
モデルの最終的なカバレッジを示します。
[~, finalCov] = sldvruntest(model, files.DataFile, [], true);
cvhtml('sil_final_coverage', finalCov);
close_system(model, 0);
### Starting build procedure for: sldv_cruise_control ### Generated code for 'sldv_cruise_control' is up to date because no structural, parameter or code replacement library changes were found. ### Successful completion of build procedure for: sldv_cruise_control Build Summary Top model targets built: Model Action Rebuild Reason ============================================================================== sldv_cruise_control Code compiled. Compilation artifacts were out of date. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 2.4654s ### Preparing to start SIL simulation ... Building with 'gcc'. MEX completed successfully. ### Starting SIL simulation for component: sldv_cruise_control ### Stopping SIL simulation for component: sldv_cruise_control ### Completed code coverage analysis ### Starting SIL simulation for component: sldv_cruise_control ### Stopping SIL simulation for component: sldv_cruise_control ### Completed code coverage analysis ### Starting SIL simulation for component: sldv_cruise_control ### Stopping SIL simulation for component: sldv_cruise_control ### Completed code coverage analysis ### Starting SIL simulation for component: sldv_cruise_control ### Stopping SIL simulation for component: sldv_cruise_control ### Completed code coverage analysis
メモ: スクリプトを実行すると、SIL テスト生成によってコードが再生成され再コンパイルされます。