JP7059827B2 - Source code generator - Google Patents
Source code generator Download PDFInfo
- Publication number
- JP7059827B2 JP7059827B2 JP2018122141A JP2018122141A JP7059827B2 JP 7059827 B2 JP7059827 B2 JP 7059827B2 JP 2018122141 A JP2018122141 A JP 2018122141A JP 2018122141 A JP2018122141 A JP 2018122141A JP 7059827 B2 JP7059827 B2 JP 7059827B2
- Authority
- JP
- Japan
- Prior art keywords
- source code
- model
- processing
- generated
- unit
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
Images
Landscapes
- Debugging And Monitoring (AREA)
- Stored Programmes (AREA)
Description
本開示は、モデルからソースコードを生成する技術に関する。 The present disclosure relates to a technique for generating source code from a model.
入力データに対する処理を複数の処理ブロック間におけるデータの入出力の仕様として記述されるモデルから、モデルに対応するソースコードを生成する技術として、例えば、特許文献1に記載されているものが知られている。
As a technique for generating a source code corresponding to a model from a model in which processing for input data is described as specifications for input / output of data between a plurality of processing blocks, for example, one described in
特許文献1に記載されているように、モデルまたはソースコードに対しては、モデルまたはソースコードの品質を検査するためにテストケースが生成される。テストケースは、テスト対象のモデルまたはソースコードに対する入力データである。通常、テストケースは、モデルの出力側から入力側に向けて逆算して生成される。
As described in
そして、モデルまたはソースコードがテストケースを実行した結果、モデルまたはソースコードにおける処理経路がどの程度テストされたかを表すカバレッジは、テストケースによる品質検査を保証するために必要な所定値以上であることが要求される。 And, as a result of executing the test case by the model or source code, the coverage showing how much the processing path in the model or source code has been tested is equal to or more than the predetermined value required to guarantee the quality inspection by the test case. Is required.
モデルが大型化し複雑になると、所定値以上のカバレッジを達成することが困難になる場合がある。そこで、モデルを分割し小型化して複数のサブシステムを生成し、サブシステム毎にテストケースを生成してカバレッジを向上させることが考えられる。 As the model becomes larger and more complex, it may be difficult to achieve coverage above a given value. Therefore, it is conceivable to divide the model and miniaturize it to generate a plurality of subsystems, and generate a test case for each subsystem to improve the coverage.
この場合、サブシステムに対応するサブソースコードを関数として定義すれば、サブソースコードからモデルに対応するソースコードを容易に生成でき、サブシステム毎のテストケースをサブシステムまたはサブソースコードで実行できる。 In this case, if the subsource code corresponding to the subsystem is defined as a function, the source code corresponding to the model can be easily generated from the subsource code, and the test case for each subsystem can be executed in the subsystem or the subsource code. ..
しかし、サブソースコードが関数として定義されると、定義される関数の数が上昇するのに従い関数の呼び出し回数が増加する。その結果、サブソースコードから生成されるソースコードの実行時間が増加するという課題が生じる。また、関数として定義しない場合には、サブシステムの入出力に相当するものがソースコードに無く、サブシステムのテストケースがソースコード上で実行できないという課題が生じる。 However, when the subsource code is defined as a function, the number of function calls increases as the number of defined functions increases. As a result, there arises a problem that the execution time of the source code generated from the subsource code increases. Further, if it is not defined as a function, there is no equivalent to the input / output of the subsystem in the source code, and there arises a problem that the test case of the subsystem cannot be executed on the source code.
本開示は、モデルを分割したサブシステム毎にサブソースコードを生成しても、モデルに対応してサブソースコードから生成されるソースコードの実行時間の増加を抑制しつつ、サブシステム毎のテストケースを実行可能にする技術を提供する。 In this disclosure, even if the subsource code is generated for each subsystem that divides the model, the test for each subsystem is suppressed while suppressing the increase in the execution time of the source code generated from the subsource code corresponding to the model. Provides technology that makes cases feasible.
本開示のソースコード生成装置(50)は、入力データに対する処理を複数の処理ブロック(112、120~128)間におけるデータの入出力の仕様として記述されるモデル(12、100)から、モデルに対応するソースコード(14、210)を生成するソースコード生成装置であって、カバレッジ判定部(64、S406、S414)と、対応付け部(70、S430、S432)と、パラメータ定義部(72、S434)と、サブコード生成部(74、S436~S448)と、ソースコード生成部(76、S450)と、を備える。 The source code generator (50) of the present disclosure is a model from a model (12, 100) in which processing for input data is described as specifications for input / output of data between a plurality of processing blocks (112, 120 to 128). A source code generator that generates the corresponding source code (14, 210), including a coverage determination unit (64, S406, S414), a mapping unit (70, S430, S432), and a parameter definition unit (72, S434), a subcode generation unit (74, S436 to S448), and a source code generation unit (76, S450).
カバレッジ判定部は、モデルから生成されるテストケースをモデルに実行させたカバレッジが所定値未満の場合、モデルを分割して生成された複数のサブシステム(130、140)のそれぞれに対し、サブシステムから生成されるテストケースを実行させたカバレッジが所定値以上か否かを判定する。 When the coverage of the test case generated from the model executed by the model is less than the predetermined value, the coverage judgment unit is a subsystem for each of the plurality of subsystems (130, 140) generated by dividing the model. It is determined whether or not the coverage for executing the test case generated from is equal to or higher than the predetermined value.
対応付け部は、複数のサブシステムのカバレッジがすべて所定値以上であるとカバレッジ判定部が判定すると、サブシステム毎に、サブシステムに分割される前のモデルから生成された元のソースコード(200)と、処理ブロックおよび処理ブロックの入出力パラメータとを対応付ける。 When the coverage determination unit determines that the coverage of a plurality of subsystems is all equal to or higher than a predetermined value, the association unit is the original source code (200) generated from the model before being divided into subsystems for each subsystem. ) And the processing block and the input / output parameters of the processing block are associated with each other.
パラメータ定義部は、対応付け部が対応付けた結果において、元のソースコードで定義されていない入出力パラメータが存在すれば、サブシステム毎に、定義されていない入出力パラメータを定義する。 The parameter definition unit defines the input / output parameters that are not defined for each subsystem if there are input / output parameters that are not defined in the original source code in the result of the mapping by the mapping unit.
サブコード生成部は、サブシステム毎に、対応付け部が対応付けた結果とパラメータ定義部が定義する入出力パラメータとを使用して、サブシステムに対応するサブソースコード(212、214)を生成する。ソースコード生成部は、サブコード生成部が生成するサブソースコードから、モデルに対応するソースコードを生成する。 The subcode generation unit generates subsource codes (212, 214) corresponding to the subsystem by using the result associated with the mapping unit and the input / output parameters defined by the parameter definition unit for each subsystem. do. The source code generator generates the source code corresponding to the model from the subsource code generated by the subcode generator.
このように、本開示のソースコード生成装置では、モデルを分割したサブシステム毎に、分割前のモデルから生成された元のソースコードにおいて定義されていない入出力パラメータを新たに定義する。そして、サブシステム毎に、対応付け部が対応付けた結果とパラメータ定義部が定義する入出力パラメータとに基づいて、サブシステムに対応するサブソースコードが生成される。これにより、サブシステムに対応して生成されるサブソースコードとサブソースコードとの間で、入出力パラメータによりデータの受け渡しができる。 As described above, in the source code generator of the present disclosure, input / output parameters not defined in the original source code generated from the model before division are newly defined for each subsystem in which the model is divided. Then, for each subsystem, the subsource code corresponding to the subsystem is generated based on the result of the mapping by the mapping unit and the input / output parameters defined by the parameter definition unit. As a result, data can be exchanged between the subsource code generated corresponding to the subsystem and the subsource code by input / output parameters.
したがって、サブシステムから関数として定義されるサブソースコードを生成する場合に比べ、関数の呼び出しにより生じる実行時間の増加を抑制しつつ、サブシステム毎のテストケースを実行できる。 Therefore, it is possible to execute a test case for each subsystem while suppressing an increase in execution time caused by calling a function, as compared with the case of generating a subsystem code defined as a function from a subsystem.
尚、この欄および特許請求の範囲に記載した括弧内の符号は、一つの態様として後述する実施形態に記載の具体的手段との対応関係を示すものであって、本開示の技術的範囲を限定するものではない。 In addition, the reference numerals in parentheses described in this column and the scope of claims indicate the correspondence with the specific means described in the embodiment described later as one embodiment, and the technical scope of the present disclosure is defined. It is not limited.
以下、本開示の実施形態を図に基づいて説明する。
[1.構成]
図1に示すモデルベース開発システム2は、ソースコード生成部10と、モデル12と、ソースコード14と、テストケース生成部20と、ソースコード実行部30と、モデル実行部32と、実行結果比較部40と、結果表示部42とを備えている。モデルベース開発システム2は、例えば、ディスプレイ、入出力装置、CPU、RAM、ROM、HDD等を備えるパーソナルコンピュータにより実現される。
Hereinafter, embodiments of the present disclosure will be described with reference to the drawings.
[1. Constitution]
The model-based
以下、モデル12から生成されたソースコード14のカバレッジが所定値以上の場合のモデルベース開発システム2の作動について説明する。
ソースコード生成部10は、HDD等に記憶されているモデル12から、例えばC言語で記述されたソースコード14を生成する。
Hereinafter, the operation of the model-based
The source
ソースコード生成部10の例としては、Mathworks(登録商標)社のEmbedded Coder(登録商標)がある。なお、モデルは、モデルエディタ等のモデル作成用プログラムをパーソナルコンピュータで実行し、その実行時にユーザがモデル作成のための作業を入力装置を用いて行うことで作成されるようになっていてもよい。このようなモデルエディタがモデルベース開発システム2に含まれていてもよい。
As an example of the source
ここで、モデル12について説明する。モデル12は、時系列の中でのデータ演算、データ入力およびデータ出力のうち少なくともいずれか1つの機能を表す処理ブロック、および処理ブロック間の入出力関係の仕様、すなわち、処理ブロックからどの処理ブロックにデータが渡されるかを示す結線の組み合わせとして記述される。
Here, the
これら処理ブロックおよび結線の組み合わせによって、入力データに応じたモデル12の処理が記述される。例えば、車載装置の制御処理であれば、エンジン制御、ブレーキ制御等の処理がある。モデルの例として、Mathworks(登録商標)社のSimulink(登録商標)モデルがある。
The combination of these processing blocks and connections describes the processing of the
テストケース生成部20は、モデル12に基づいてテストケースを生成する。なお、テストケースは、モデル12のみに基づいて生成してもよいし、あるいは、モデル12のソースコード14に基づいて生成してもよいし、またあるいは、モデル12とソースコード14との両方に基づいて生成してもよい。
The test
テストケースとは、モデル12の品質、および、ソースコード生成部10によってモデル12から生成されたソースコード14の品質を検査するためのカバレッジテスト等の処理の実行において、その品質検査が十分となるよう、モデル12やソースコード14に入力するテスト用データである。例えば、後述するソースコード実行部30およびモデル実行部32の実行の際にも、このテストケースが使用される。
The test case is sufficient in executing a process such as a coverage test for inspecting the quality of the
品質検査が十分となるようなテストケースとは、例えば、できる限りモデル12の全ての処理ブロックまたはソースコード14の全ての命令文が実行されるような入力データである。
ソースコード実行部30は、テストケース生成部20によって生成されたテストケースを入力データとして、ソースコード14に記載された処理内容を実行する。その実行の際、ソースコード実行部30は、ソースコード14の実行単位による出力データ、および実行した命令文の時系列的なリストを生成する。
The test case for which the quality inspection is sufficient is, for example, input data in which all the processing blocks of the
The source
モデル実行部32は、テストケース生成部20によって生成されたテストケースを入力データとして、モデル12のシミュレーションを実行する。シミュレーションとは、モデル12の表現するデータの入出力の時間変化をパーソナルコンピュータ上で仮想的に再現する処理をいう。
The
モデル実行部32は、モデル12のシミュレーションによる外部への出力データ、ならびに処理ブロック毎の実行時間および入出力データをHDD等に格納する。
実行結果比較部40は、ソースコード実行部30およびモデル実行部32によって実行された実行結果データを比較し、その比較結果をHDD等に格納する。尚、比較とは、ソースコード実行部30が実行したソースコード14と、モデル実行部32がシミュレーションを行ったモデル12とのそれぞれの実行結果のデータの比較をいう。
The
The execution
比較項目としては、同じ入力データに対してモデル12、ソースコード14が出力したデータがある。そして実行結果比較部40は、比較の結果、それぞれが合致しているか否かの合否判定を行い、その合否判定の情報もHDD等に格納する。結果表示部42は、実行結果比較部40による比較結果をディスプレイに出力する。
As comparison items, there are data output by the
ここで、モデル12の構造が大型化しており複雑な場合、テストケース生成部20が生成するテストケースをソースコード実行部30とモデル実行部32とが実行しても、カババレッジが、モデル12またはソースコード14に対するテストケースによる品質検査を保証するために必要な所定値以上にならないことがある。
Here, when the structure of the
そこで、図2に、構造が大型化しており複雑な場合のモデル100であっても、ソースコード210でテストケースを実行した結果のカバレッジを所定値以上にする本実施形態のソースコード生成装置50を示す。
Therefore, FIG. 2 shows the
ソースコード生成装置50は、モデル入力部52と、ソースコード生成部54と、分析部60と、対応付け部70と、パラメータ定義部72と、サブコード生成部74と、ソースコード生成部76とを備えている。分析部60は、テストケース生成部62とカバレッジ判定部64とを備えている。
The source
ソースコード生成装置50の各要素が実行するソースコード生成処理について以下に説明する。
[2.処理]
[2-1.メイン処理]
ソースコード生成装置50が実行するソースコード生成のメイン処理について、図3のフローチャートに基づいて説明する。
The source code generation process executed by each element of the source
[2. process]
[2-1. Main processing]
The main process of source code generation executed by the source
S400においてモデル入力部52は、モデルと、モデルに付随する情報として、モデルを分割してサブシステムを生成する場合の分割箇所などを取得する。S402においてソースコード生成部54は、モデルからソースコードを生成する。この場合、ソースコード生成部54は、図1に示すソースコード生成部10と実質的に同じ処理を実行する。
In S400, the
図5に、モデル100の一例を示す。符号102~108は入力パラメータを示す。符号110は出力パラメータを示す。符号112、120~128は処理ブロックである。符号112は、1.01の定数を出力する定数ブロックである。符号120は、定数ブロック112の値と、遅延処理ブロック128の出力との積を出力する乗算ブロックである。
FIG. 5 shows an example of the
符号122~126が示す条件分岐ブロックは、上中下の入力パラメータのうち、中央の信号が0でないときに上の信号を出力し、中央の信号が0の場合は下の信号を出力する。
符号128が示す遅延処理ブロックは、1周期前の値を出力する。
The conditional branch block indicated by
The delay processing block indicated by
図5に示されるモデル100から、ソースコード生成部54が生成したC言語によるソースコード200を図6に示す。
S404において分析部60のテストケース生成部62は、モデル100に実行させるテストケースを生成する。この場合、テストケース生成部62は、図1に示すテストケース生成部20と実質的に同じ処理を実行する。S406において分析部60のカバレッジ判定部64は、モデル100にテストケースを実行させた結果のカバレッジが所定値以上であるか否かを判定する。
FIG. 6 shows the
In S404, the test
S406の判定がYesである、つまりモデル100にテストケースを実行させた結果のカバレッジが所定値以上の場合、S408において、図1に示すモデルベース開発システム2により、モデル100と、S402で生成されたソースコード200とに対してテストが実行される。
When the judgment of S406 is Yes, that is, when the coverage as a result of having the
これに対し、S406の判定がNoである、つまりモデル100にテストケースを実行させた結果のカバレッジが所定値未満の場合、S410においてカバレッジ判定部64は、S400でモデル入力部52が取得したモデル100の分割箇所でモデル100を分割し複数のサブシステムを生成する。
On the other hand, when the determination in S406 is No, that is, the coverage as a result of having the
図7に、S400でモデル入力部52が取得した分割情報に基づいてモデル100を2つのサブシステム130、140に分割した例を示す。
S412においてテストケース生成部62は、サブシステム130、140のそれぞれについてテストケースを生成する。
FIG. 7 shows an example in which the
In S412, the test
S414においてカバレッジ判定部64は、サブシステム130、140のそれぞれについてテストケースを実行した結果のカバレッジが所定値以上であるか否かを判定する。
S414の判定がNoである、つまりカバレッジが所定値未満のサブシステムが存在する場合、処理はS410に戻り、カバレッジが所定値未満のサブシステムがさらに複数のサブシステムに分割される。
In S414, the
If the determination in S414 is No, that is, if there is a subsystem whose coverage is less than the predetermined value, the process returns to S410, and the subsystem whose coverage is less than the predetermined value is further divided into a plurality of subsystems.
S414の判定がYesである、つまりすべてのサブシステム、図7の例ではサブシステム130、140のカバレッジが所定値以上の場合、S416のソースコード置換処置において、対応付け部70とパラメータ定義部72とサブコード生成部74とソースコード生成部76とは、S402で生成されたソースコードを置換して、複数のサブシステム130、140のそれぞれに対応するサブソースコードを生成する。
When the determination of S414 is Yes, that is, when the coverage of all the subsystems, that is, the
そして、サブソースコードをまとめて、モデル100に対応するソースコードを生成する。それぞれのサブシステム130、140のカバレッジが所定値以上であれば、それぞれのサブシステム130、140から生成されたサブソースコードをまとめて生成されたモデル100に対応するソースコードのカバレッジも所定値以上である。
Then, the sub-source code is put together to generate the source code corresponding to the
尚、S416のソースコード置換処理については、図4のフローチャートに基づいて詳細に説明する。
そして、S418において、S416で生成されたサブシステム130、140に対応するサブソースコードと、サブシステム130、140とに対して、図1に示すモデルベース開発システム2においてソースコード実行部30とモデル実行部32とが、S412で生成されたテストケースを使用してテストを実行する。
The source code replacement process of S416 will be described in detail with reference to the flowchart of FIG.
Then, in S418, the subsource code corresponding to the
[2-2.ソースコード置換処理]
図3のS416においてソースコード生成装置50が実行するソースコード置換処理について、図4のフローチャートに基づいて説明する。
[2-2. Source code replacement process]
The source code replacement process executed by the source
S430において対応付け部70は、モデル100を分割して生成されたサブシステム130、140に対し置換処理を実行する順番を決定する。モデル100において早く実行されるサブシステム130から置換処理が実行される。
In S430, the
S432において対応付け部70は、サブシステム130、140のそれぞれについて、処理ブロックと入出力パラメータと一時パラメータとに対し、ソースコード200を対応付けた一覧を生成する。図8に、対応付け部70がサブシステム130についてソースコード200を対応付けて生成した一覧を示す。
In S432, the
図8の一覧と図9に示すサブシステム130とにおいて、A、B、Cが処理ブロックであり、a、b、c、dが入力パラメータであり、eが出力パラメータであり、f、gが一時パラメータである。f、gが示す一時パラメータも、いずれかの処理ブロックにおける入力パラメータまたは出力パラメータである。
In the list of FIG. 8 and the
処理ブロックは、処理の種別として、反復、分岐、順接に分類される。分岐、順接が反復される場合は、反復/分岐、反復/順接として分類される。
各処理ブロックに対応付けるソースコードは、反復および順接については、処理ブロックに関連するソースコードの記述がすべて抽出される。分岐については、複数の分岐の条件がソースコードに記述されている場合、該当する分岐の条件だけが抽出される。
Processing blocks are classified into iteration, branching, and adjunct as processing types. When branching and adjunct are repeated, they are classified as iterative / branching and iterative / adjunct.
For the source code associated with each processing block, all the source code descriptions related to the processing block are extracted for iteration and adjunct. For branching, if multiple branching conditions are described in the source code, only the corresponding branching conditions are extracted.
図8の一覧において、入出力パラメータとして、「A」で表される条件分岐ブロック124の出力パラメータの「e」と、「B」で表される条件分岐ブロック122の出力パラメータであり条件分岐ブロック124の入力パラメータである一時パラメータの「f」と、「C」で表される乗算ブロック120の出力パラメータであり条件分岐ブロック122の入力パラメータである一時パラメータの「g」とに対応する記述が、図6に示すソースコード200において未定義であることが分かる。
In the list of FIG. 8, as input / output parameters, the output parameter "e" of the
そこで、S434においてパラメータ定義部72は、一覧において未定義の入出力パラメータとして、出力パラメータの「e」と一時パラメータの「f」、「g」とを、図10に示すように、double sub1_out1[2]、double sub1_tmp1[2]、double sub1_tmp2[2]として、図10の下線で示すように処理後のサブソースコードで定義する。
Therefore, in S434, the
S436においてサブコード生成部74は、サブシステム130において、ソースコードを置換してサブソースコードを生成する処理ブロックの順番を決定する。本実施形態では、サブコード生成部74は、乗算ブロック120と条件分岐ブロック122、124とのうち、条件分岐ブロック122、124を先に置換する。さらに、サブコード生成部74は、条件分岐ブロック122、124のうち、後段で分岐処理が実行される条件分岐ブロック124を条件分岐ブロック122よりも先に置換する。
In S436, the
これは、サブシステム130からサブソースコードが生成された場合、後段の条件分岐ブロックに対応するサブソースコードから実行されるので、分岐条件のいずれかが満たされない場合、分岐条件が満たされない場合に実行されるサブソースコードが実行されない。これにより、生成されたサブソースコードの実行時間が短縮される。
This is executed from the subsource code corresponding to the conditional branch block in the subsequent stage when the subsource code is generated from the
S436の処理により、サブシステム130において、条件分岐ブロック124、条件分岐ブロック122、乗算ブロック120の順番で、対応するソースコードが置換される。
S438においてサブコード生成部74は、今回の置換処理の対象である処理ブロックに対応するソースコードの記述において、分岐先の処理が省略されているか否かを判定する。S438の判定がYesである、つまりソースコードにおいて分岐先の処理が省略されている場合、処理はS440に移行する。S438の判定がNoである、つまり分岐先の処理が省略されていない場合、処理はS442に移行する。
By the process of S436, the corresponding source code is replaced in the
In S438, the
例えば、条件分岐ブロック124に対応する「if (!(in3[s4t_tmp] != 0.0F))」の判定に対し、ソースコード200には判定結果が偽の場合の分岐先の記述が省略されているので、S438の判定はYesである。
For example, in contrast to the determination of "if (! (in3 [s4t_tmp]! = 0.0F))" corresponding to the
この場合、S440においてサブコード生成部74は、図11の下線で示すように、条件分岐ブロック124に対応するサブソースコードにおいて、「else」が追加される。
S442において、サブコード生成部74は、処理ブロックに対応する処理で、出力パラメータに入力パラメータを代入する記述を追加する。
In this case, in S440, the
In S442, the
例えば、図12の下線で示すように、条件分岐ブロック124に対応する「if (!(in3[s4t_tmp] != 0.0F))」の判定に対し、判定結果が真であれば、sub1_out1[s4t_tmp]=out1[s4t_tmp]の記述が追加され、判定結果が偽であれば、sub1_out1[s4t_tmp]=sub1_tmp1[s4t_tmp]の記述が追加される。
For example, as shown by the underline in FIG. 12, if the judgment result is true for the judgment of "if (! (in3 [s4t_tmp]! = 0.0F))" corresponding to the
S444においてサブコード生成部74は、置換処理が終了した処理ブロックを対象から除く。S446においてサブコード生成部74は、すべての処理ブロックに対する置換処理が終了したか否かを判定する。S446の判定がNoである、つまり置換処理が未処理の処理ブロックが存在する場合、処理はS436に移行する。
In S444, the
例えば、条件分岐ブロック124に対する置換処理が終了しても、条件分岐ブロック122対する置換処理は終了していないので、処理はS436に移行し、条件分岐ブロック124と同様に条件分岐ブロック122に対する置換処理が実行される。
For example, even if the replacement process for the
条件分岐ブロック122の処理は条件分岐ブロック124において判定結果が偽である「else」側で実行されるので、図13の下線で示すように、サブソースコードにおいて条件分岐ブロック122の処理に対応する記述が条件分岐ブロック124のサブソースコードにおける「else」側に記述される。
Since the processing of the
この場合、条件分岐ブロック124の判定結果が偽のときに実行されるsub1_out1[s4t_tmp]=sub1_tmp1[s4t_tmp]において、条件分岐ブロック124の判定結果が真であればsub1_tmp1[s4t_tmp]=in1[s4t_tmp]が実行され、条件分岐ブロック124の判定結果が偽であればsub1_tmp1[s4t_tmp]=sub1_tmp2[s4t_tmp]が実行される。
In this case, in sub1_out1 [s4t_tmp] = sub1_tmp1 [s4t_tmp] executed when the judgment result of the
そして、条件分岐ブロック122に対する置換処理が終了すると、乗算ブロック120に対する置換処理が実行される。
この場合、図14の下線で示すように、条件分岐ブロック122の判定結果が偽のときに実行されるsub1_tmp1[s4t_tmp]=sub1_tmp2[s4t_tmp]の前に、乗算ブロック120の処理結果であるout1[s4t_tmp]*0.01がsub1_tmp2[s4t_tmp]に代入される。
Then, when the replacement process for the
In this case, as shown by the underline in FIG. 14, before sub1_tmp1 [s4t_tmp] = sub1_tmp2 [s4t_tmp] executed when the determination result of the
S446の判定がYesである、つまり、すべての処理ブロックの置換処理が終了した場合、S448においてサブコード生成部74は、分割された複数のサブシステムについて、置換処理が終了したか否かを判定する。S448の判定がNoである、つまり置換処理が未処理のサブシステムが存在する場合、処理はS432に移行する。
When the determination in S446 is Yes, that is, when the replacement processing of all the processing blocks is completed, the
例えば、図7においてモデル100を分割したサブシステム130、40のうち、サブシステム130の置換処理が終了すると、サブシステム130と同様にサブシステム140の置換処理が実行される。サブシステム140の置換処理では、サブシステム130の置換処理で定義された入出力パラメータが使用される。
For example, among the
そして、S448の判定がYesである、つまり、すべてのサブシステムの置換処理が終了すると、S450においてソースコード生成部76は、図15に示すように、生成されたサブソースコード212、214をまとめて、モデル100に対応するソースコード210を生成する。
Then, when the determination in S448 is Yes, that is, when the replacement processing of all the subsystems is completed, the source
図15において、符号212がサブシステム130から生成されたサブソースコードであり、符号214がサブシステム140から生成されたサブソースコードである。
サブシステム140に対応するソースコード214の部分において、条件分岐ブロック126の判定であるif (in4s4t_tmp] != 0.0F)の判定結果が偽の場合、out1[s4t_tmp]には同じ値が代入されるので、分岐先の記述は追加されていない。
In FIG. 15,
In the part of the
図15に示すように、モデル100から分割されたサブシステム130、140において、元のソースコード200に対して、置換処理により生成されたサブソースコード212、214には関数定義は存在していない。そして、サブソースコード212、214は、反復と分岐と順接との処理だけで記述されている。
As shown in FIG. 15, in the
図3のS418で実行されるテストは、S412においてサブシステム130、140のそれぞれに対して生成されたテストケースで実行される。
[3.効果]
以上説明した上記実施形態では、以下の効果を得ることができる。
The test executed in S418 of FIG. 3 is executed in the test case generated for each of the
[3. effect]
In the above-described embodiment, the following effects can be obtained.
(1)元のソースコード200に対して、置換処理により生成されたサブソースコード212、214には関数定義は存在しておらず、サブソースコード212、214は、反復と分岐と順接との処理だけで記述されている。したがって、サブソースコード212、214から生成されるソースコード210を実行するときに関数が呼び出されないので、ソースコード210の実行時間が増加することを抑制しつつ、サブシステム毎のテストケースを実行できる。
(1) There is no function definition in the
(2)モデル100から分割されて、簡単化かつ小型化されたサブシステム130、140と、サブシステム130、140に対応して生成されたサブソースコード212、214との組み合わせに対して、それぞれのサブシステム130、140から生成されたテストケースによりテストを実行する。
(2) For each combination of the simplified and
サブシステム130、140はモデル12よりも簡単化かつ小型化されているので、生成されたテストケースにより実行されたテストのカバレッジは向上する。
上記実施形態において、S406、S414がカバレッジ判定部の処理に対応し、S430、S432が対応付け部の処理に対応し、S434がパラメータ定義部の処理に対応し、S436~S448がサブコード生成部の処理に対応し、S450がソースコード生成部の処理に対応する。
[4.他の実施形態]
(1)上記実施形態では、置換処理前のモデルであるモデル100を1回分割して生成されたサブシステム130、140のカバレッジが所定値以上になる例を説明した。
Since the
In the above embodiment, S406 and S414 correspond to the processing of the coverage determination unit, S430 and S432 correspond to the processing of the mapping unit, S434 corresponds to the processing of the parameter definition unit, and S436 to S448 correspond to the processing of the subcode generation unit. Corresponds to the processing of, and S450 corresponds to the processing of the source code generation unit.
[4. Other embodiments]
(1) In the above embodiment, an example has been described in which the coverage of the
これに対し、分割して生成されたすべてのサブシステムのカバレッジが所定値以上になるまで、カバレッジが所定値未満のサブシステムをさらに分割して複数のサブシステムを生成してもよい。 On the other hand, until the coverage of all the divided and generated subsystems becomes the predetermined value or more, the subsystems whose coverage is less than the predetermined value may be further divided to generate a plurality of subsystems.
(2)上記実施形態では、ソースコード生成装置50のカバレッジ判定部64が、モデル100から取得する分割情報に基づいて、モデル100またはサブシステム130、140を分割して複数のサブシステムを生成した。
(2) In the above embodiment, the
これに対し、例えばオペレータが、ソースコード生成装置50のマウスまたはキーボード等の入力装置を操作してモデル100を分割してもよい。
(3)上記実施形態では、ソースコード生成装置50のカバレッジ判定部64が、モデル100から取得する分割情報に基づいて、モデル100またはサブシステム130、140を分割して複数のサブシステムを生成した。
On the other hand, for example, the operator may operate an input device such as a mouse or a keyboard of the source
(3) In the above embodiment, the
これに対し、ソースコード生成装置50が、モデル100の構造を解析し、モデル100の分割箇所を決定する分割部を備えてもよい。
(4)上記実施形態における一つの構成要素が有する複数の機能を複数の構成要素によって実現したり、一つの構成要素が有する一つの機能を複数の構成要素によって実現したりしてもよい。また、複数の構成要素が有する複数の機能を一つの構成要素によって実現したり、複数の構成要素によって実現される一つの機能を一つの構成要素によって実現したりしてもよい。また、上記実施形態の構成の一部を省略してもよい。また、上記実施形態の構成の少なくとも一部を、他の上記実施形態の構成に対して付加または置換してもよい。尚、特許請求の範囲に記載した文言のみによって特定される技術思想に含まれるあらゆる態様が本開示の実施形態である。
(5)上述したソースコード生成装置の他、当該ソースコード生成装置を構成要素とするシステム、当該ソースコード生成装置としてコンピュータを機能させるためのソースコード生成プログラム、このソースコード生成プログラムを記録した記録媒体、ソースコード生成方法など、種々の形態で本開示を実現することもできる。
On the other hand, the
(4) A plurality of functions possessed by one component in the above embodiment may be realized by a plurality of components, or one function possessed by one component may be realized by a plurality of components. Further, a plurality of functions possessed by the plurality of components may be realized by one component, or one function realized by the plurality of components may be realized by one component. Further, a part of the configuration of the above embodiment may be omitted. Further, at least a part of the configuration of the above embodiment may be added or replaced with the configuration of the other above embodiment. It should be noted that all aspects included in the technical idea specified only by the wording described in the claims are embodiments of the present disclosure.
(5) In addition to the above-mentioned source code generator, a system having the source code generator as a component, a source code generator for operating a computer as the source code generator, and a record of recording the source code generator. The present disclosure can also be realized in various forms such as a medium and a source code generation method.
50:ソースコード生成装置、64カバレッジ判定部、70:対応付け部、72:パラメータ定義部、74:サブコード生成部、76:ソースコード生成部、100:モデル、112:定数ブロック(処理ブロック)、120:乗算ブロック(処理ブロック)、122~126:条件分岐ブロック(処理ブロック)、128:遅延ブロック(処理ブロック)、130、140:サブシステム、200:元のソースコード、210:ソースコード、212、214:サブソースコード
50: Source code generation device, 64 coverage determination unit, 70: Correspondence unit, 72: Parameter definition unit, 74: Subcode generation unit, 76: Source code generation unit, 100: Model, 112: Constant block (processing block) , 120: Multiplication block (processing block), 122-126: Conditional branch block (processing block), 128: Delay block (processing block), 130, 140: Subsystem, 200: Original source code, 210: Source code, 212, 214: Sub source code
Claims (4)
前記モデル(100)から生成されるテストケースを前記モデルに実行させたカバレッジが所定値未満の場合、前記モデルを分割して生成された複数のサブシステム(130、140)のそれぞれに対し、前記サブシステムから生成されるテストケースを実行させた前記カバレッジが所定値以上か否かを判定するように構成されたカバレッジ判定部(64、S406、S414)と、
前記複数のサブシステムの前記カバレッジがすべて前記所定値以上であると前記カバレッジ判定部が判定すると、前記サブシステム毎に、前記サブシステムに分割される前の前記モデルから生成された元のソースコード(200)と、前記処理ブロックおよび前記処理ブロックの入出力パラメータとを対応付けるように構成された対応付け部(70、S430、S432)と、
前記対応付け部が対応付けた結果において、前記元のソースコードで定義されていない前記入出力パラメータが存在すれば、前記サブシステム毎に、定義されていない前記入出力パラメータを定義するように構成されたパラメータ定義部(72、S434)と、
前記サブシステム毎に、前記対応付け部が対応付けた結果と前記パラメータ定義部が定義する前記入出力パラメータとに基づいて、前記サブシステムに対応するサブソースコード(212、214)を生成するように構成されたサブコード生成部(74、S436~S448)と、
前記サブコード生成部が生成する前記サブソースコードから、前記モデルに対応するソースコードを生成するように構成されたソースコード生成部(76、S450)と、
を備えるソースコード生成装置。 A source code (14, 210) corresponding to the model is generated from a model (12, 100) in which processing for input data is described as data input / output specifications between a plurality of processing blocks (112, 120 to 128). Source code generator (50)
When the coverage of the test case generated from the model (100) executed by the model is less than a predetermined value, the above-mentioned is applied to each of the plurality of subsystems (130, 140) generated by dividing the model. A coverage determination unit (64, S406, S414) configured to determine whether or not the coverage for executing a test case generated from a subsystem is equal to or higher than a predetermined value.
When the coverage determination unit determines that the coverage of the plurality of subsystems is all equal to or higher than the predetermined value, the original source code generated from the model before being divided into the subsystems for each of the subsystems. (200), an association unit (70, S430, S432) configured to associate the processing block and the input / output parameters of the processing block, and
If the input / output parameter that is not defined in the original source code exists in the result of the mapping by the mapping unit, the input / output parameter that is not defined is defined for each of the subsystems. Parameter definition unit (72, S434)
For each of the subsystems, the subsystem code (212, 214) corresponding to the subsystem is generated based on the result of the mapping by the mapping unit and the input / output parameters defined by the parameter definition unit. Subcode generators (74, S436-S448) configured in
A source code generation unit (76, S450) configured to generate a source code corresponding to the model from the sub-source code generated by the sub-code generation unit.
Source code generator equipped with.
前記カバレッジ判定部は、前記サブシステムに前記テストケースを実行させた前記カバレッジが所定値未満の場合、前記カバレッジが所定値未満の前記サブシステムをさらに分割して生成された複数のサブシステムのそれぞれに対し、生成されたテストケースを実行させた前記カバレッジが所定値以上であるか否かを判定するように構成されている、
ソースコード生成装置。 The source code generator according to claim 1.
When the coverage obtained by causing the subsystem to execute the test case is less than a predetermined value, the coverage determination unit is a plurality of subsystems generated by further dividing the subsystem having a coverage less than a predetermined value. On the other hand, it is configured to determine whether or not the coverage for executing the generated test case is equal to or higher than a predetermined value.
Source code generator.
前記サブコード生成部は、前記サブシステムにおいて後段の処理を実行する前記処理ブロックから順番に、前記パラメータ定義部が定義する前記入出力パラメータを使用して、前記元のソースコードに基づいて、前記処理ブロックの処理に対応する前記サブソースコードを生成するように構成されている、
ソースコード生成装置。 The source code generator according to claim 1 or 2.
The subcode generation unit uses the input / output parameters defined by the parameter definition unit in order from the processing block that executes the subsequent processing in the subsystem, and uses the input / output parameters defined by the parameter definition unit, based on the original source code. It is configured to generate the subsource code corresponding to the processing of the processing block,
Source code generator.
前記サブコード生成部は、前記処理ブロックが条件分岐の処理を実行し、いずれかの分岐先の処理に対応する記述が前記元のソースコードに存在しない場合、記述が存在しない分岐先の処理を表すサブコードを生成するように構成されている、
ソースコード生成装置。
The source code generator according to claim 3.
When the processing block executes the conditional branch processing and the description corresponding to the processing of one of the branch destinations does not exist in the original source code, the subcode generation unit performs the processing of the branch destination where the description does not exist. It is configured to generate the subcode that represents it,
Source code generator.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP2018122141A JP7059827B2 (en) | 2018-06-27 | 2018-06-27 | Source code generator |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP2018122141A JP7059827B2 (en) | 2018-06-27 | 2018-06-27 | Source code generator |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| JP2020004036A JP2020004036A (en) | 2020-01-09 |
| JP7059827B2 true JP7059827B2 (en) | 2022-04-26 |
Family
ID=69100290
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| JP2018122141A Expired - Fee Related JP7059827B2 (en) | 2018-06-27 | 2018-06-27 | Source code generator |
Country Status (1)
| Country | Link |
|---|---|
| JP (1) | JP7059827B2 (en) |
Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JP2005301568A (en) | 2004-04-09 | 2005-10-27 | Denso Corp | Display information storage control device and display information storage control program |
| JP2009294846A (en) | 2008-06-04 | 2009-12-17 | Denso Corp | Test case generator, and test case generation program and method |
| JP2010250669A (en) | 2009-04-17 | 2010-11-04 | Denso Corp | Test case generation device, object inspection device, and program |
| US9665350B1 (en) | 2009-05-29 | 2017-05-30 | The Mathworks, Inc. | Automatic test generation for model-based code coverage |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JPH01303533A (en) * | 1988-05-31 | 1989-12-07 | Toshiba Corp | Measuring system for test comprehension rate |
-
2018
- 2018-06-27 JP JP2018122141A patent/JP7059827B2/en not_active Expired - Fee Related
Patent Citations (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JP2005301568A (en) | 2004-04-09 | 2005-10-27 | Denso Corp | Display information storage control device and display information storage control program |
| JP2009294846A (en) | 2008-06-04 | 2009-12-17 | Denso Corp | Test case generator, and test case generation program and method |
| JP2010250669A (en) | 2009-04-17 | 2010-11-04 | Denso Corp | Test case generation device, object inspection device, and program |
| US9665350B1 (en) | 2009-05-29 | 2017-05-30 | The Mathworks, Inc. | Automatic test generation for model-based code coverage |
Also Published As
| Publication number | Publication date |
|---|---|
| JP2020004036A (en) | 2020-01-09 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US10025696B2 (en) | System and method for equivalence class analysis-based automated requirements-based test case generation | |
| US10296447B2 (en) | Automated software program repair | |
| CN111104335B (en) | A C language defect detection method and device based on multi-level analysis | |
| US20090319829A1 (en) | Pattern extraction method and apparatus | |
| JP6316120B2 (en) | Test case generation system and recording medium recording test case | |
| US20110145799A1 (en) | Path-sensitive dataflow analysis including path refinement | |
| JP6878707B2 (en) | Test equipment, test methods and test programs | |
| JP6003699B2 (en) | Test data generation program, method and apparatus | |
| US10936474B2 (en) | Software test program generation | |
| JP2009169828A (en) | Test case generation apparatus and test case generation program | |
| He et al. | Swe-perf: Can language models optimize code performance on real-world repositories? | |
| JP2009294846A (en) | Test case generator, and test case generation program and method | |
| JP6002507B2 (en) | Software verification program and software verification system | |
| JP7059827B2 (en) | Source code generator | |
| WO2020194455A1 (en) | Test case generation device, test case generation method, and test case generation program | |
| JP2015069400A (en) | Software test system | |
| JP2010250669A (en) | Test case generation device, object inspection device, and program | |
| JPWO2019142266A1 (en) | Test case generation device, test case generation method, and test case generation program | |
| JP5811978B2 (en) | Test case generation apparatus and test case generation method for model-based control apparatus | |
| WO2021161426A1 (en) | Program generation device, program generation method, and program | |
| JP2009205239A (en) | Software verification system | |
| US20040111684A1 (en) | Design method of logic circuit | |
| JP6693898B2 (en) | Test case generation method, computer and program | |
| JPH0773044A (en) | Optimizing compiling method and optimizing compiling device | |
| JP6583033B2 (en) | Driver generation program, apparatus, and method |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| A621 | Written request for application examination |
Free format text: JAPANESE INTERMEDIATE CODE: A621 Effective date: 20210218 |
|
| A977 | Report on retrieval |
Free format text: JAPANESE INTERMEDIATE CODE: A971007 Effective date: 20220228 |
|
| TRDD | Decision of grant or rejection written | ||
| A01 | Written decision to grant a patent or to grant a registration (utility model) |
Free format text: JAPANESE INTERMEDIATE CODE: A01 Effective date: 20220315 |
|
| A61 | First payment of annual fees (during grant procedure) |
Free format text: JAPANESE INTERMEDIATE CODE: A61 Effective date: 20220328 |
|
| R151 | Written notification of patent or utility model registration |
Ref document number: 7059827 Country of ref document: JP Free format text: JAPANESE INTERMEDIATE CODE: R151 |
|
| LAPS | Cancellation because of no payment of annual fees |