CN111258915B - Method for carrying out automatic unit test on PLC program - Google Patents

Method for carrying out automatic unit test on PLC program Download PDF

Info

Publication number
CN111258915B
CN111258915B CN202010124563.7A CN202010124563A CN111258915B CN 111258915 B CN111258915 B CN 111258915B CN 202010124563 A CN202010124563 A CN 202010124563A CN 111258915 B CN111258915 B CN 111258915B
Authority
CN
China
Prior art keywords
test
plc
program
ltest
executed
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.)
Active
Application number
CN202010124563.7A
Other languages
Chinese (zh)
Other versions
CN111258915A (en
Inventor
李继磊
沈武
李翔龙
许志轩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Leetro Automation Co ltd
Original Assignee
Leetro Automation Co ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Leetro Automation Co ltd filed Critical Leetro Automation Co ltd
Priority to CN202010124563.7A priority Critical patent/CN111258915B/en
Publication of CN111258915A publication Critical patent/CN111258915A/en
Application granted granted Critical
Publication of CN111258915B publication Critical patent/CN111258915B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/02Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Programmable Controllers (AREA)

Abstract

The invention discloses a method for carrying out automatic unit test on a PLC program, which comprises the following steps: 1) Inputting a source code through a C# program, and writing a functional block capable of automatically testing PLC software; 2) Compiling the program source code to generate a public intermediate language file; 3) Generating a firmware library file from a public intermediate language file through a firmware library generator in PLC programming software, and constructing a firmware library; 4) Adding a constructed firmware library into PLC programming software; 5) Constructing a test framework by using functional blocks in a firmware library through PLC programming software; 6) Compiling a PLC program according to the constructed test frame, and generating a PLC engineering mirror image; 7) And installing the generated engineering mirror image in an operation platform of the PLC program, and starting operation. According to the invention, the automatic test framework is introduced into the PLC programming, so that the test set or test case to be executed can be flexibly adjusted according to the requirement, the writing of the test program is simplified, and the test efficiency is improved.

Description

Method for carrying out automatic unit test on PLC program
Technical Field
The invention relates to the technical field of software testing, in particular to a method for carrying out automatic unit testing on a PLC program.
Background
PLC programming is an electronic system of digital arithmetic operations, designed specifically for application in an industrial environment. It uses programmable memory to store instructions for performing logic operations, sequence control, timing, counting and arithmetic operations, and controls various types of machines or processes by digital and analog inputs and outputs. The programmable controller and its related equipment should be designed in such a way that the industrial control system is easy to form a whole and the functions are easy to expand.
With the rapid development of microprocessors, computers and digital communication technology, computer control has expanded to almost all industrial fields. Modern society requires manufacturing to respond rapidly to market demands to produce small batches, varieties, specifications, low cost and high quality products, and to meet this demand, production equipment and automation line control systems must have extremely high reliability and flexibility, and PLC programming is emerging in compliance with this demand, which is a general industrial control device based on microprocessors. A step of
Unit testing refers to checking and verifying the smallest testable unit in software. For the meaning of a unit in unit test, generally, the specific meaning of the unit is to be determined according to practical situations, for example, a unit in C language refers to a function, a unit in Java refers to a class, and graphical software can refer to a window or a menu. In general, a unit is an artificially defined minimum measured function module. Unit testing is the lowest level of testing activity to be performed during the development of software, where individual units of software will be tested in isolation from other parts of the program.
At present, the technical means for testing the automatic control PLC software are few, and commercial software cannot directly test the software. The actual software and hardware operation environment is built, the test cost is high, and the test coverage rate cannot be ensured. The method has the advantages that the technical research of testing the PLC software is developed, the PLC software is isolated from the real environment, the independent software testing and verification are carried out under the condition of not connecting hardware, and the separation of software and hardware faults is realized, so that the testing cost of the existing software is reduced, the testing efficiency and quality are provided, and the method has important significance.
Disclosure of Invention
The invention aims to provide a method for automatically testing a unit of a PLC program, which has the advantages of higher testing efficiency, simpler testing, good flexibility and suitability for expansion.
The invention is realized by the following technical scheme: a method for automated unit testing for a PLC program, comprising the steps of:
(1) Inputting a source code through a C# program, and writing a functional block capable of automatically testing PLC software;
(2) Compiling the program source code to generate a public intermediate language file;
(3) Generating a firmware library file from a public intermediate language file through a firmware library generator in PLC programming software, and constructing a firmware library;
(4) Adding a constructed firmware library into PLC programming software;
(5) Constructing a test framework by using functional blocks in a firmware library through PLC programming software;
(6) Compiling a PLC program according to the constructed test frame, and generating a PLC engineering mirror image;
(7) And installing the generated engineering mirror image in an operation platform of the PLC program, starting operation, filling codes to be tested in the framework, and performing cyclic test.
Unit testing, also called module testing, is a test effort to perform correctness checking for program modules (the smallest unit of software design). The traditional PLC program has low testing efficiency or needs complex PLC programming, has low flexibility and is not suitable for expansion, and the automatic unit test is introduced into the programming of the PLC program, so that the development efficiency of the PLC software can be improved.
Because the PLC programming is a programming language designed specifically for industrial environment applications, the PLC program operates in a "sequential scan, continuous loop" manner.
Function (FU): the function is POU (Program Organization Units) with multiple input parameters and exactly one output parameter. Invoking a function with the same value always returns the same result. The return value may be a simple data type. Within a function, additional functions may be called, but no function blocks or programs can be called, and recursive calls are not allowed.
Functional Block (FB): the function block is POU (Program Organization Units) with multiple input/output parameters and internal memory locations, the return value of the function block depends on the value of its internal memory locations, and exception function blocks or functions may be called within the function block, but no program may be called, and recursive calls are not allowed.
The method comprises the steps of compiling a functional block for automatic unit test by using a C# program, generating a firmware library file by the functional block, loading the firmware library by PLC programming software, constructing test codes according to the functional block in the firmware library, finally generating an engineering mirror image capable of running on a target platform of the PLC program, loading the engineering mirror image on the target platform, and running the test program by the target platform to realize automatic unit test of the PLC software.
In order to better implement the present invention, further, the program written by the c# program input source code in the step (1) includes:
LTest_SetUp declares the common execution part of the test group before starting to execute the test case;
the LTest_SetUpDone is matched with the LTest_SetUp in pairs;
LTest_TearDown declares the common execution part of the test group after the test case is executed;
LTest_TearDown is matched with LTest_TearDown in pairs;
LTest_TestCaseStart, declaring a test case;
ltest_testcaseend, paired with ltest_testcasestart;
LTest_Result, obtaining an execution Result of the current test;
LTest_Config, configures test cases that need to be executed or not.
The ltest_setup and ltest_teardown are common execution parts added before and after the test case, and can be understood as a start character and a stop character of the test group to identify the test group. All test cases are grouped according to the same beginning and ending, so that code repetition is avoided, the grouping is called a test group, and the grouping can be further performed according to the tested function.
Each Test case is executed according to the sequence of SetUp- > Test- > TearDown to Test.
In operation, setUp, tearDown divides the PLC program into a plurality of test groups and Start, end divides the program within the test groups into a plurality of test cases.
All the functional blocks are uniformly managed by an internal state machine, each functional block (except Result, config) corresponds to one internal state, done and End is used for recording a state, and the states indicate whether the code segment is executed, whether the code between SetUp and SetUpDone is executed or not, whether the code between TearDown and TearDown is executed or not, and whether the code between TearStart and TestCaseStart is executed or not are indicated by the fact that the code segment is executed.
In order to better implement the present invention, further, the firmware library file generated in the step (3) includes function block names, input variables, output variables, and input/output variables.
In order to better realize the invention, the PLC programming software is Multiprog. MultiProg is a programming system according to IEC standards and traditional PLC standards, and can edit, compile and debug PLC engineering.
In order to better implement the present invention, in the step (6), the compiling process of the PLC program according to the constructed test code is that the common intermediate language file is converted into the machine code of the ProConOS platform by using the method of converting the common intermediate language file into the machine code. Procon OS is a high performance PLC engine designed specifically for embedded and PC-based control applications. Procon OS is capable of cooperating with mainstream embedded systems (e.g., vxworks, QNX, OS 9) and the like, providing deterministic control performance down to 1ms run-time.
In order to better implement the present invention, further, the operation platform of the PLC program in the step (7) is a ProConOS platform.
Compared with the prior art, the invention has the following advantages:
(1) According to the invention, the automatic test framework is introduced into the PLC programming, so that the test set or test case to be executed can be flexibly adjusted according to the needs, the programming of the test program of the PLC software is simplified, and the test efficiency of the PLC software is greatly improved;
(2) The invention realizes the program test of the PLC software by using C# program programming, so that the written functional blocks can accord with 61131-3 standard without additional parameter setting;
(3) The invention has simple technical principle and simple realization process, is beneficial to program test of PLC software and is suitable for wide popularization and application.
Drawings
Other features, objects and advantages of the present invention will become more apparent upon reading of the detailed description of non-limiting embodiments, given with reference to the accompanying drawings in which:
FIG. 1 is a basic flow chart of an implementation process of the present invention;
FIG. 2 is a timing diagram illustrating test case execution according to the present invention.
Detailed Description
In order to make the objects, process conditions and advantages of the present invention more apparent, the present invention will be further described in detail with reference to the following examples, but the embodiments of the present invention are not limited thereto, and various substitutions and modifications according to the general knowledge and conventional means of the art without departing from the technical spirit of the present invention, should be included in the scope of the present invention, and the specific examples described herein are only for explaining the present invention and are not limited thereto.
Example 1:
the embodiment provides a method for performing automatic unit test on a PLC program, and the specific flow is shown in fig. 1, and includes the following steps:
(1) Inputting a source code through a C# program, and writing a functional block capable of automatically testing PLC software;
(2) Compiling the program source code to generate a public intermediate language file;
(3) Generating a firmware library file from a public intermediate language file through a firmware library generator in PLC programming software, and constructing a firmware library;
(4) Adding a constructed firmware library into PLC programming software;
(5) Constructing a test framework by using functional blocks in a firmware library through PLC programming software;
(6) Compiling a PLC program according to the constructed test frame, and generating a PLC engineering mirror image;
(7) And installing the generated engineering mirror image in an operation platform of the PLC program, starting operation, filling codes to be tested in the framework, and performing cyclic test.
The automatic unit Test framework constructed in the method can divide the Test engineering into a plurality of Test groups, each Test group comprises a plurality of Test cases, each Test case is executed according to the sequence SetUp- > Test- > TearDown, and the execution process is shown in figure 2.
The test frame is packaged into a functional block conforming to 61131-3 standard without additional parameter setting
1. The Test framework classifies all Test cases by groups, each group being referred to as a Test group (TestGroup)
2. The test group contains a beginning segment (SetUp) and an ending segment (TearDown);
3. each Test case is executed according to the sequence of SetUp- > Test- > TearDown to Test;
4. displaying the test structure after all the test cases are executed;
5. the Test group (TestGroup) or Test case (Test) to be executed can be flexibly adjusted according to the needs.
Example 2:
the embodiment is further based on the above embodiment, where the program written by the c# program input source code in the step (1) includes:
LTest_SetUp declares the common execution part of the test group before starting to execute the test case;
the LTest_SetUpDone is matched with the LTest_SetUp in pairs;
LTest_TearDown declares test, and after the test cases are executed by the test group, the test group commonly executes the part;
LTest_TearDown is matched with LTest_TearDown in pairs;
LTest_TestCaseStart, declaring a test case;
ltest_testcaseend, paired with ltest_testcasestart;
LTest_Result, obtaining an execution Result of the current test;
LTest_Config, configures test cases that need to be executed or not.
The ltest_setup and ltest_teardown are common execution parts added before and after the test case, and can be understood as a start character and a stop character of the test group to identify the test group. All test cases are grouped according to the same beginning and ending, so that code repetition is avoided, the grouping is called a test group, and the grouping can be further performed according to the tested function.
Each Test case is executed according to the sequence of SetUp- > Test- > TearDown to Test.
In operation, setUp, tearDown divides the PLC program into a plurality of test groups and Start, end divides the program within the test groups into a plurality of test cases.
All the functional blocks are uniformly managed by an internal state machine, each functional block (except Result, config) corresponds to one internal state, done and End is used for recording a state, and the states indicate whether the code segment is executed, whether the code between SetUp and SetUpDone is executed or not, whether the code between TearDown and TearDown is executed or not, and whether the code between TearStart and TestCaseStart is executed or not are indicated by the fact that the code segment is executed.
Other portions of this embodiment are the same as those of the above embodiment, and will not be described here again.
Example 3:
the embodiment is further based on the above embodiment, where the firmware library file generated in the step (3) includes a function block name, an input variable, an output variable, and an input/output variable.
Example 4:
the present embodiment is further based on the above embodiment, and the PLC programming software is Multiprog. MultiProg is a programming system according to IEC standards and traditional PLC standards, and can edit, compile and debug PLC engineering. Other portions of this embodiment are the same as those of the above embodiment, and will not be described here again.
Example 5:
in the embodiment, further, in the step (6), the compiling of the PLC program according to the constructed test code is performed by converting the common intermediate language file into the machine code by using a method of converting the common intermediate language file into the machine code of the ProConOS platform. Other portions of this embodiment are the same as those of the above embodiment, and will not be described here again.
Example 6:
based on the foregoing embodiment, the operation platform of the PLC program in step (7) is a ProConOS platform. Procon OS is a high performance PLC engine designed specifically for embedded and PC-based control applications. Procon OS is capable of cooperating with mainstream embedded systems (e.g., vxworks, QNX, OS 9) and the like, providing deterministic control performance down to 1ms run-time. Other portions of this embodiment are the same as those of the above embodiment, and will not be described here again.
While embodiments of the present invention have been shown and described, it will be understood by those of ordinary skill in the art that: many changes, modifications, substitutions and variations may be made to the embodiments without departing from the spirit and principles of the invention, the scope of which is defined by the claims and their equivalents.

Claims (5)

1. A method for automated unit testing for a PLC program, comprising the steps of:
(1) Inputting source codes through a C# program, and writing functional blocks capable of automatically testing PLC software, wherein the program written through the C# program comprises the following components:
LTest_SetUp declares the common execution part of the test group before starting to execute the test case;
the LTest_SetUpDone is matched with the LTest_SetUp in pairs;
LTest_TearDown declares the common execution part of the test group after the test case is executed;
LTest_TearDown is matched with LTest_TearDown in pairs;
LTest_TestCaseStart, declaring a test case;
ltest_testcaseend, paired with ltest_testcasestart;
LTest_Result, obtaining an execution Result of the current test;
LTest_Config, configuring test cases which need to be executed or not executed;
the test case execution method comprises the steps of determining a test set, wherein LTest_SetUp and LTest_TearDown are common execution parts added before and after test case execution, represent a start character and a stop character of the test set and are used for identifying the test set;
grouping all test cases according to the same start and end, avoiding duplicating codes, and enabling the groups to be called as test groups;
each Test case is executed according to the sequence of SetUp- > Test- > TearDown to Test;
during operation, setUp and TearDown divide a PLC program into a plurality of test groups, and Start and End divide the program in the test groups into a plurality of test cases; all the functional blocks are uniformly managed by an internal state machine, each functional block corresponds to an internal state, done and End and is used for recording a state, the state indicates that the code segment is executed, setUp controls whether codes between SetUp and SetUpDone are executed, tearDown controls whether codes between TearDown and TearDown are executed, and TestCaseStart controls whether codes between TestCaseStart and TestCaseEnd are executed;
(2) Compiling the program source code to generate a public intermediate language file;
(3) Generating a firmware library file from a public intermediate language file through a firmware library generator in PLC programming software, and constructing a firmware library;
(4) Adding a constructed firmware library into PLC programming software;
(5) Constructing a test framework by using functional blocks in a firmware library through PLC programming software;
(6) Compiling a PLC program according to the constructed test frame, and generating a PLC engineering mirror image;
(7) Installing the generated engineering mirror image in an operation platform of the PLC program, starting operation, filling codes to be tested in a frame, and performing cyclic test;
the automatic unit test framework constructed in the method can divide the test engineering into a plurality of test groups, and each test group comprises a plurality of test cases;
the test framework is packaged into a functional block conforming to 61131-3 standard, and no additional setting parameters are needed: the Test framework classifies all Test cases Test by groups, and each group is called a Test group; the test group comprises a head section SetUp and an end section TearDown; displaying the test structure after all the test cases are executed; the Test group or the Test case Test to be executed is flexibly adjusted according to the requirement.
2. The method of claim 1, wherein the firmware library file generated in the step (3) includes a function block name, an input variable, an output variable, and an input-output variable.
3. The method of automated unit testing for PLC programs of claim 1, wherein the PLC programming software is Multiprog.
4. The method for performing automated unit testing for PLC programs according to claim 1, wherein in step (6), the compiling process of the PLC program according to the constructed test code is as follows: and converting the public intermediate language file into the machine code of the ProConOS platform by using the method for converting the public intermediate language file into the machine code.
5. The method for automated unit testing for PLC programs according to claim 1, wherein the operating platform of the PLC program in step (7) is a ProConOS platform.
CN202010124563.7A 2020-02-27 2020-02-27 Method for carrying out automatic unit test on PLC program Active CN111258915B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010124563.7A CN111258915B (en) 2020-02-27 2020-02-27 Method for carrying out automatic unit test on PLC program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010124563.7A CN111258915B (en) 2020-02-27 2020-02-27 Method for carrying out automatic unit test on PLC program

Publications (2)

Publication Number Publication Date
CN111258915A CN111258915A (en) 2020-06-09
CN111258915B true CN111258915B (en) 2023-07-04

Family

ID=70951357

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010124563.7A Active CN111258915B (en) 2020-02-27 2020-02-27 Method for carrying out automatic unit test on PLC program

Country Status (1)

Country Link
CN (1) CN111258915B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112349340B (en) * 2020-11-08 2023-10-10 北京工业大学 Method for constructing waste equipment overwriting scheme library based on cyclic test
CN112506793B (en) * 2020-12-18 2024-05-28 航天信息股份有限公司 Method and system for testing embedded software unit, readable medium and electronic equipment

Family Cites Families (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8279204B1 (en) * 2005-12-22 2012-10-02 The Mathworks, Inc. Viewer for multi-dimensional data from a test environment
CN101876940B (en) * 2009-11-30 2011-12-28 飞天诚信科技股份有限公司 Automatic test method and device
CN103645730B (en) * 2013-12-09 2016-01-13 成都乐创自动化技术股份有限公司 A kind of motion control card with self-checking function and detection method
CN104407973B (en) * 2014-11-25 2018-04-06 珠海格力电器股份有限公司 A kind of implementation method and device of automation cell test
US9921941B2 (en) * 2015-04-10 2018-03-20 Siemens Aktiengesellschaft Verification and validation of third party PLC code
CN105740477B (en) * 2016-03-18 2019-03-29 中国科学院信息工程研究所 For the Selecting Function System method and search engine of extensive embedded device firmware
CN108052453A (en) * 2017-12-29 2018-05-18 北京天诚同创电气有限公司 Test method, device, equipment and the medium of programmable logic controller program
CN108415828B (en) * 2018-01-23 2021-09-24 广州视源电子科技股份有限公司 Program testing method and device, readable storage medium and computer equipment
CN109840201B (en) * 2018-12-15 2023-07-18 中国平安人寿保险股份有限公司 UI test method, device, electronic equipment and computer readable storage medium
CN110532177A (en) * 2019-08-05 2019-12-03 华东师范大学 A kind of automatic test cases generation system towards PLC program
CN110471851B (en) * 2019-08-09 2022-06-21 北京首都在线科技股份有限公司 Automatic testing method and device

Also Published As

Publication number Publication date
CN111258915A (en) 2020-06-09

Similar Documents

Publication Publication Date Title
CN107273286B (en) Scene automatic test platform and method for task application
CN103150249B (en) A kind of method and system of automatic test
CN107562969B (en) Method and device for integrating aero-engine control system software
CN103631720A (en) Method and device for generating test case
CN111258915B (en) Method for carrying out automatic unit test on PLC program
US11687062B2 (en) Configuration of a modular plant
CN108132876B (en) Embedded software object code unit testing method based on injection mode
US20070061641A1 (en) Apparatus and method for generating test driver
Jamro POU-oriented unit testing of IEC 61131-3 control software
CN111428431A (en) Method and system for supporting automatic test and recording of EDA (electronic design automation) software
Wahler et al. CAST: Automating software tests for embedded systems
CN111723009A (en) Framework system of python automated testing series products
CN111611157A (en) Automatic testing method and system for GMS continuous integration construction
CN113254054B (en) Intelligent contract one-stop development system and method
Vogel-Heuser et al. Key maturity indicators for module libraries for PLC-based control software in the domain of automated Production Systems
CN114924737A (en) Battery management system source code integration test method and device and electronic equipment
CN112783769A (en) Self-defined automatic software testing method
CN116090380B (en) Automatic method and device for verifying digital integrated circuit, storage medium and terminal
Jamro et al. Agile and hierarchical round-trip engineering of IEC 61131-3 control software
JP3978285B2 (en) Nonvolatile memory built-in semiconductor device test method
CN103165405A (en) Mutli-dimensional variable code real-time generation method through general purpose interface bus (GPIB) interface
KR20190094779A (en) Automatically Generate Device for PLC Instruction Compiler Test-Case
Zhang et al. An approach for resource Function Block generation: Towards RAMI4. 0-compliant PLC Programming
CN111061244A (en) Automatic testing method for power distribution master station monitoring system
CN112445695A (en) Tool for quickly generating test description file and application thereof

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant