According to best practices of model-driven engineering, the implementation of a system should be obtained from its model through a systematic model-to-code transformation. We present in this paper a methodology supported by the Asm2C++ tool, which allows the users to generate C++ code from abstract state machine models.Thanks to Asm2C++, the implementation is generated in a seamless manner with an assurance of potential bug freeness of the generated code. Following the same approach, model-based testing suggests deriving also (unit) tests from abstract models. We extend the Asm2C++ tool such that it can automatically produce unit tests for the generated code. Abstract test sequences, either generated randomly or through model checking, are translated to concrete C++ unit tests using the Boost library. In a similar manner, also, scenarios are generated in a behavior-driven development (BDD) approach. To guarantee the correctness of the transformation process, we define a mechanism to test the correctness of the model-to-code transformation with respect to two main criteria: syntactical correctness and semantic correctness, which is based on the definition of conformance between the specification and the code. Using this approach, we have devised a process able to test the generated code by reusing unit tests. The process has been used to validate our model-to-code transformations.
KEYWORDSabstract state machine, automatic code generation, C++, model-driven engineering, transformation validation, unit tests generation
| INTRODUCTIONFormal methods are often used to model requirements of a system under construction at the abstract level. Formal requirement models are then amenable to a series of quality assurance activities including dynamic analysis like simulation and static analysis like property verification. However, it may remain unclear how to properly link the final implementation to its abstract specification, since the implementation may contain platformcentric details, be written in a programming language, and running on a specific hardware. Performing a manual transformation of formal models into code increases costs, limits the reuse of a formal specification, is error prone as some faults can be introduced in the code writing process, and can be a barrier for a wider adoption of formal methods. It would be very useful to assist designers also in this very delicate last phase of the development process.Abstract state machine (ASM) 1 is a formal method that proposes a rigorous software and systems development process for seamless transformation of informal requirements into implementation. The ASM method is based on the design concept of refinement that allows to capture all