Summary of the invention
In view of the above-mentioned defective of prior art, the purpose of this invention is to provide a kind of TTCN-3 test macro and method of testing based on the C++ mapping.This test macro and method of testing make full use of the characteristics of C++, and corresponding TTCN-3 running environment is satisfied carry out efficient and carry out the needs of secondary development at system under test (SUT), and the relevant limit of avoiding threading to bring.
For realizing above-mentioned goal of the invention, the present invention adopts following technical scheme:
A kind of TTCN-3 test macro based on the C++ mapping is characterized in that:
Described system comprises test manager, language converter, test case actuator, shared drive manager, in-line coding/demoder, C++ Map Interface, system under test (SUT) adapter and operating system adapter, wherein
Described test manager manages whole test system; Described language converter conversion TTCN-3 test case, and the C++ test case of generative semantics equivalence are responsible for execution by described test case actuator;
Test suite in the test case carries out encoding and decoding by described in-line coding/demoder to the data that it is stored in shared drive, and described shared drive manager manages described shared drive;
Described C++ Map Interface comprises test control interface and test execution interface, described test control interface is realized being connected between described test case actuator and described system under test (SUT) adapter and the described operating system adapter, and described test execution interface is realized being connected between described test manager and the described test case actuator.
Wherein, described test case actuator comprises the TTCN_Proces class, TTCN_Process_Options class and TTCN_Process_Manager class, and wherein said class TTCN_Proces realizes the encapsulation to test suite/process; Class TTCN_Process_Options realizes the encapsulation of test suite/process association attributes; Class TTCN_Process_Manager is used for the management testing assembly.
Open three layer interfaces of described shared drive manager application programs comprise the container storehouse that meets the STL specification; The new that meets the C++ specification, the delete interface; And the allocate that meets the C specification, the deallocate interface.
Each test suite in the described test case all is implemented as a process.
Adopt the inter-process communication techniques that meets the POSIX standard between described each process.
Described test macro adopts hierarchy, and C++ mapping standard is satisfied in the funcall interface strictness between each layer.
Described in-line coding/demoder utilizes the type and size of reflex mechanism Dynamic Recognition data.
A kind of method of testing that realizes based on above-mentioned TTCN-3 test macro is characterized in that comprising the steps:
(1) for the abstract test suite of TTCN-3, is converted into C++ test case cover by language converter;
(2) described C++ test case cover carries out binding with the running environment storehouse in the C++ compiler, generates the test case library file for test case actuator load and execution;
(3) test macro starts background process, and environment is carried out initialization, loading configuration file;
(4) according to the test case that will carry out, load corresponding test case library file;
(5) start test and management process, the test case in the instantiation library file;
(6) implementation of test cases, report test execution result.
Wherein, described language converter carries out following processing to the abstract test suite of TTCN-3: after lexical analyzer and syntax analyzer, generate abstract syntax tree, by the semantic information extraction apparatus when doing semantic test, from abstract syntax tree, extract semantic information, fill in each manager, comprise symbol manager, type manager, converter, global information index and action scope manager, by code generator the information of each manager is handled at last, under the help of assistant's class, generate the test case that satisfies the C++ Map Interface.
Described language converter adds type attribute information for data in the C++ test case that generates.
TTCN-3 test macro and method of testing based on the C++ mapping that the present invention realized not only can adapt to the requirement that General System is carried out Black-box Testing, can also satisfy the actual demand that system with characteristics such as concurrent, mutual, real-time tests, so the scope of application is wider.
Embodiment
As everyone knows, C is not a kind of object oriented programming languages, does not have the characteristic of reusing, and is difficult to be grafted directly in the other environment at the program of a certain concrete environment establishment and uses, and therefore uses the development efficiency of C language not high.And C++ is the same with Java, all is object oriented programming languages, and they can both realize reusing by encapsulation, succession, technological means such as polymorphic.But the compiled code of Java language is a kind of syllabified code, explain execution by the Java Virtual Machine on the operating system when operation, so operational efficiency can not show a candle to C++.C++ compares with C, possesses OO characteristic, is convenient to carry out secondary development at concrete system under test (SUT); On the other hand, it is the same with the C language again, has higher running efficiency.Therefore adopt C++ to realize that TTCN-3 running environment is more satisfactory selection at present.
In order to utilize C++ to realize TTCN-3 running environment, the work that we need carry out comprises sets up corresponding C ++ Map Interface.This Map Interface comprises test control interface and test execution interface.In addition, also need to set up the functional module that comprises test manager, language converter, test executing device, shared drive manager, in-line coding/demoder, system under test (SUT) adapter and operating system adapter.The set of above-mentioned these functional modules is exactly the TTCN-3 test macro based on the C++ mapping of the present invention.Respectively these functional modules are illustrated below.
The function of test manager is to be responsible for the management work of whole TTCN-3 test macro, and its main action comprises:
◆ test control: after system initialization, all tests all begin to carry out from test control service, and it is responsible for loading test suite, and corresponding test suite start-up parameter is provided.
◆ log management: be responsible for the maintenance system daily record, and be responsible in the record measuring executing process other modules to its various event notice contents of sending that need record.
◆ the test suite management: under many situations, the execution of a test case need be finished jointly by a plurality of test suites, and these assemblies may be distributed in the middle of the different physical systems.The test suite management function is responsible for establishment, distribution and the coordination execution work of each test suite.
◆ error handling processing:, carry out that mistake (unusually) is recovered and mistake (unusually) cleaning work when making a mistake in the measuring executing process or unusual the time.
Above-mentioned test suite (test suite) is the distinctive module of TTCN-3 system, and it is by introducing the explicit or implicitly complete description of statement (import statements) all definition and one group of required behavior description of test case of complete definition.
In the TTCN-3 of reality system running environment, test manager shows as graphic user interface, and its menu structure comprises following content:
● configuration: the various parameters of system and the configuration of adapter.
◆ systematic parameter configuration: realize the relevant system configuration of test macro, realize in the mode of reading system initialization files;
◆ adapter setting: the used adapter file of current test case is set.
● carry out: the execution flow process that realizes test case.
◆ module loading: will be compiled into dynamically (or shared library) later module loading;
◆ test module is specified: specify the module title that is used for current test assignment in the module list that has loaded;
◆ module parameter setting: support to dynamically arrange module parameter, allow the tester module relevant parameters to be set at gui interface;
◆ specify implementation of test cases: finish in module loading, and after the module used of nominative testing, in all test cases of listing automatically on the menu item in front module, the user can specify test case used in the current test assignment;
◆ carry out test: begin to carry out test;
◆ carry out cancellation: cancel the current test assignment of carrying out.
● statistics: reflect current test execution situation, the number of PTC such as statistics normal termination, failure.The main statistics that realizes following index:
◆ the use-case sum of current test assignment;
◆ current use-case sum by test;
◆ the current PTC data of moving;
◆ the PTC peak value of current test assignment;
◆ the PTC number that passes through of current test case;
◆ the unsanctioned PTC data of current test case;
◆ the PTC peak value of current test case;
◆ the process sum of test macro;
◆ system request shared drive number;
◆ the current shared drive number of having used;
◆ used internal memory peak value;
● log query: system's support is to the inquiry of test log, and the daily record that this realization will write the test log file outputs on the control desk again.
● Online Help: the Online Help function that realizes this test macro.
The effect of language converter is to change the TTCN-3 test case, and the C++ test case of generative semantics equivalence, and these test cases that are converted to satisfy C++ Map Interface standard simultaneously.It is one of core technology of the present invention.
Fig. 1 has provided the basic execution flow process of language converter.The TTCN-3 test suite is through after lexical analyzer and the syntax analyzer, the abstract syntax tree that generative grammar is correct, but this moment, semanteme might not be correct, need extract semantic information inspection from abstract syntax tree; In addition, in transfer process, have many local information that need just can provide in the back, the common backfill mechanism that adopts is fairly simple, but underaction is particularly many in the information that needs backfill, and we are to its structure unclear the time.Therefore, the semantic information extraction apparatus extracts semantic information from abstract syntax tree when doing semantic test, fill in each manager, comprises symbol manager, type manager, converter, global information index and action scope manager.By code generator the information of each manager is handled at last, under the help of assistant's class, generated the test case that satisfies the C++ Map Interface.
Language converter adopts technique of compiling to realize.This is the problem that persons skilled in the art can both solve easily, so just do not describe in detail at this.
The test case actuator is responsible for carrying out the test case of being write by the standard testing language, and various basic services are provided, and comprising:
◆ test configurations: a test configurations is carried out the related assembly of testing by communication port mutually by one group and is constituted.This service can realize the dynamic-configuration to test suite.
◆ use-case is selected: a test suite often comprises numerous test case.Use-case selects service to determine the number of times whether each test case is carried out and carried out according to Test Strategy.
◆ carry out engine: be responsible for the compiling and the execution of standard testing language.
◆ template and coupling: the match service between the data is provided, is used for data are detected.This service can be used to accept and send some specific data acquisitions.
◆ Clock management: the basic management function of clock is provided, comprises startup, read and write, stop, triggering etc.; The clock of having hidden different operating system simultaneously realizes that thereby details provides unified clock service interface.
◆ test suite communication: the component communication service based on message or process is provided, makes things convenient between the test suite and cooperate, to finish the execution of a test case jointly.
◆ parametrization: the parametrization of in the test run process the various data in the test case being carried out various ways.
◆ the execution result assessment: the execution result of assessment test case, wherein introduced the secondary evaluation mechanism, i.e. local result assessment and global outcome assessment, and stipulated 4 kinds of probable values and relevant value cover up rule.
Fig. 2 has described the main class formation relation of test case actuator.Because test suite all is implemented as process, so the way to manage of the function of these classes and structure and process and function are closely related.Wherein class TTCN_Proces has realized the encapsulation to test suite/process; Class TTCN_Process_Options has realized the encapsulation of test suite/process association attributes; Class TTCN_Process_Manager is mainly used in the management testing assembly.
The basic layer structure of shared drive manager as shown in Figure 3.Wherein, the effect of ShmInitializer class is the whole shared drive of initialization zone.It directly calls shmget, and functions such as shmat come to be the application shared memory space, all is the work of this class to the assurance of the aspects such as uniqueness of the size of shared drive, multi-process application.The SharedMemory class is responsible for direct managing shared memory, its application programs provides Allocate, the shared drive operation-interface of the C specification of Deallocate etc., and AddObject, shared drive Object Operations interfaces such as GetObject, the latter makes that using this shared drive manager to communicate between process becomes possibility.The ShmObject class is used the interface of SharedMemory, and encapsulates function such as its Allocate, for application program provides new, the internal memory operation interface of C++ specifications such as delete, any class just can directly be used new as long as inherit from ShmObject, the delete operation.Based on the ShmObject class, can develop the container storehouse of a simple STL type.List wherein, Queue, Priority Queue are three kinds of more complete containers, its interface meets the STL specification substantially.In addition, in Fig. 3, shared drive manager application programs has been opened three layer interfaces, comprise the container storehouse of the above-mentioned STL of meeting specification, the new of C++ specification, delete interface, and the allocate of C specification, interfaces such as deallocate, in the reality, application program can independently be selected the one deck or the several layers interface that will use fully as required.
When test, each test suite in the test case comprises main test suite, parallel testing assembly, system testing assembly, all is implemented as a process.Compare with the thread implementation, avoided the constraint of stack space size, in addition, can be because of not the increasing sharply of test suite quantity yet, and cause system to carry out the rapid decline of efficient.The establishment of process is corresponding with the create of test suite action.On concrete code was realized, first invoke system call fork () created subprocess, and then created the example of parallel testing assembly or main test suite.Carry out the exchanges data between process for convenience fast, system has adopted POSIX (portable operating system interface) inter-process communication techniques, comprise shared drive, mutual exclusion lock, incident or the like, wherein shared drive is used to deposit communication data, incident is used for notifying the variation of shared drive data, and mutual exclusion lock is used for the synchronization of access of each process to shared drive.
The process of carrying out the invocation of procedure between two processes based on shared drive as shown in Figure 4.Process PTC1 will call to write after application is encoded by coder/decoder by port Port1 and write shared drive, the event thread readout from shared drive of reading of process PTC2 calls incident and utilizes coder/decoder to decode, the decoding back finds it is the invocation of procedure application that belongs to port Port2, just it is distributed to the port Port2 on the PTC2, Port2 carries out invoked process, and the execution result coding is write shared drive; The event thread of reading of PTC1 was read return results and decoding from shared drive, it is distributed to port Port1 on the PTC1.
The effect of in-line coding/demoder is that the data of representing with C++ are added decoding.A test suite must utilize in-line coding/demoder to encode before data are being stored in shared drive; Another test suite also needs to utilize in-line coding/demoder to decode and could use afterwards in the data of reading from shared drive.In order to encode, we have realized the reflex mechanism that a cover is simplified at the data object of C++, and this mechanism can be supported: 1) realize an instantiation of pressing of object; 2) variable in the traversal object under not knowing the situation of object type carries out the operation of assignment value to variable.Introduce this machine-processed specific implementation method below.
One. press the realization of name instantiation:
1. all classes will be inherited in base class TTCNValue, and all like this objects could be quoted by the TTCNValue pointer.
2. in each class that need realize reflecting, need to provide a TTCNValue*newInstance () method, be similar to factory mode, can create the pointer of a concrete object in this method.
3. create the map pointer of a static state in the static zones of program, the mapping that is used for preserving class name and type information is so that realize by the name instantiation.In store such all information in the object of establishment are mentioned in the front, so what preserve among the map is the pointer of class name and such object.This map will set up in program start.
4. when the name of a given class, we arrive and go to search in the mapping of map, if find the name of this class, just call the newInstance () method of its corresponding object, have so just created the object of new such.Also just realized object by the name instantiation.
Two. variable travels through by name in the object
1.TTCNType class is used for preserving the information of the variable of class, the protected member variable of the sensing TTCNType* that has a static state of class TTCNValue.Each is inherited and all has a unique TTCNType object in the class of TTCNValue and report and deposit its type information like this.
2. the name of in store class among the TTCNType of each class correspondence.
3.TTCNValue in have a vector<TTCNValue* who preserves the pointer of member variable values.Pointer with its member variable in the constructed fuction of each particular type is kept among this vector in order.
4. the information of the member variable of class (variable name, type name) is kept at simple class Attribute{attrName, among the typeName}.
5. a vector<Attribute who preserves member variable attribute (Attribute) is arranged in TTCNType〉attributes.Attribute with its member variable in the constructed fuction of each particular type is kept among this vector in order.
Method TTCNValue is provided among the TTCNValue ﹠amp; GetAttributeByName (stringname), setAttributeValue (string name, TTCNValue ﹠amp; Value), just can operate the value of member variable by name of variables.
Utilize this reflex mechanism, the type and size that in-line coding/demoder can the Dynamic Recognition data.In order to use this reflex mechanism in the execution time, language converter also need add all kinds attribute information for various data in the C++ test case that generates.
The effect of system under test (SUT) adapter is: test executing device needs to carry out constantly finishing interactive operation based on communicating by letter of message and process with system under test (SUT) in the test case operational process, and these interactive operations must by by system adapter to adaptively just finishing that concrete system under test (SUT) carries out.In addition, in order to communicate, the system under test (SUT) adapter also needs the transmission data are done corresponding format conversion.
The effect of operating system adapter is: in the implementation of test case, test executing device need call various external functions.The operating system adapter carries out adaptive to different operating system, hide the details of different operating system to test executing device.In addition, the operating system adapter uses the external function except making things convenient for test executing device, can also provide support unified working time.
Fig. 5 shown towards the basic structure of the test control interface of test manager, and Fig. 6 has shown the test execution interface and towards the basic structure of the test control interface of test executing device.As shown in Figure 5 and Figure 6, wherein TriCommunicationSA, TriPlatformSA and TriPlatformPA have constituted the test execution interface, preceding two is calling interface between test case actuator and the system under test (SUT) adapter, and the 3rd is the calling interface between test case actuator and the operating system adapter.The test execution interface is TTCN-3 running environment and the mutual standard interface of ambient systems, and system under test (SUT) adapter, operating system adapter are based on all that it develops.TciTMRequired, TciTMProvided, TciCHRequired and TciCHProvided have constituted the test control interface together, wherein preceding two interface class have been provided by the method that test manager is called and should provides, and latter two interface class has been provided by the method that the test case actuator is called and should provides.The test control interface is a interface between test manager and the test case actuator, and it is mainly used in the message transmission between the test manager and test case actuator in the test case implementation.The test case actuator is started by test manager, the test case actuator needs constantly to circulate a notice of current executing state to test manager in the process of implementation, and test manager is according to execution state information, report current test case practice condition to the user, and final test result.
The TTCN-3 test macro that is made of above-mentioned each module adopts hierarchy, and C++ mapping standard is satisfied in the funcall interface strictness between each layer.
Utilize above-mentioned functional module, the concrete grammar of execution test comprises the steps: as shown in Figure 7
(1) for the abstract test suite (ATS) of TTCN-3, is converted into C++ test case cover by language converter;
(2) above-mentioned C++ test case cover carries out binding with running environment storehouse RBLib.a in the C++ compiler, generates test case library file TSlib.a for test case actuator load and execution;
(3) test macro starts background process, and environment is carried out initialization, loading configuration file;
(4) according to the test case that will carry out, load corresponding test case library file TSlib.a;
(5) start test and management process, the test case testcase in the instantiation library file;
(6) implementation of test cases testcase, report test execution result.
In Fig. 7, the right side is the main flow of TTCN-3 running environment, and the left side is the flow process that language converter is carried out.By each above-mentioned step, can be by working out C++ Map Interface standard, to become the test case with the C++ description of equal value with the test case conversion that TTCN-3 describes by language converter, the C++ test case that running environment compiling, loading, execution conversion generate, thereby can make full use of the characteristics of C++, realize the high-level efficiency of test process, satisfy the requirement that system with characteristics such as concurrent, mutual, real-time tests.
Above TTCN-3 test macro and the method for testing based on the C++ mapping of the present invention had been described in detail, but obvious specific implementation form of the present invention is not limited thereto.For the those skilled in the art in present technique field, the various conspicuous change of under the situation of spirit that does not deviate from the method for the invention and claim scope it being carried out is all within protection scope of the present invention.