Background technology
In the communications field, for guaranteeing the reliability of communication system, research and development of software process wherein must comprise test phase, to find the mistake in the software as much as possible.
In the prior art, the white-box testing system is the testing tool of using always.In the white-box testing system, need write the needed numerous driving functions of test, pile function with concrete programming language, driving function that these are numerous and pile function constitute test code.These test codes generate executable file with tested code through compiling, connection back, test by the operation of this executable file then.In a single day need in the test process to revise test code, just need carry out once more amended test code is repeated processes such as compiling, link with tested code.Processes such as the compiling of this repetition, link can cause testing efficiency low; And along with improving constantly of the continuous increase of system under test (SUT), complexity, such repetitive operation will be many more, and the efficient that finally causes testing will be low more.
Be the process schematic diagram that directly carries out software test in the prior art as shown in Figure 1 with programming language structure test pile function, at first construct the test pile function, be written as the test source code with concrete programming language, should test compilation of source code then, link, and generate executable system and test with the measured source code.As seen, will revise the test pile function as required in test process, be written as the test source code again, repeat processes such as compiling, link, until finishing test, obviously, testing efficiency is not high.
Be to describe the process schematic diagram that pile function carries out software test as shown in Figure 2 with formatted language, the difference of this system and system shown in Figure 1 is to provide a kind of formative stake describing method, the user only need be described pile function according to certain form, be converted to concrete C language function by system according to user's description, compiling then, with tested systematic connection, generate executable system.Though such system provides the pile function of scripting to describe means, final or script describing is converted into concrete C language function, still there is the problem that compiles, link of repeating, thereby determines that the efficient of such method of operation is still lower.
The shortcoming of above-mentioned two kinds of test macros is: can't avoid compiling, the link process of repetition in the test process, cause testing efficiency lower; Will be difficult more to abnormality test use-case structure.In addition, also have numerous test codes in the system as shown in Figure 1, the maintenance of these test codes needs certain cost.Along with the development of measuring technology, press for the raising testing efficiency.
Summary of the invention
What the present invention will solve is that existing test macro and method of testing cause the lower technical problem of testing efficiency because of compiling, the link process that can't avoid repetition in test process.
A kind of white-box testing system that uses script patch comprises test control system and tested system, it is characterized in that, also comprises communication module, script module and test module; Described test module comprises patch processing center, mute's patch function group and address information table;
Described address information table is used for writing down the address information of function of the described tested system of dynamic acquisition; Described mute's patch function group is a series of mute's function; Described communication module connects described test control system by socket or serial communication; Test instruction and script pile function that described script module is sent by communication module acceptance test control system are explained and are carried out test instruction; Described patch processing center is called the corresponding interface of described script module, realizes the execution of described script pile function according to described test instruction;
Described tested system with described communication module, described script module, described test module compile, link become executable system be used for the operation.
Described communication module, described script module and described test module do not change with the different of tested system;
When described testing control module and system broke away from, described tested system can independent operating, and described communication module, described script module and described test module are in the resting state that does not influence the operation of described tested system.
A kind of white-box testing method of using script patch comprises the steps:
1. the needs according to tested system dynamically increase the script pile function;
2. increase the corresponding relation of function in described script pile function and the described tested system;
3. adopt patching technology to activate described script pile function, revise the instruction of code segment, realize the commentaries on classics of moving of implementation, cover the described script pile function of operation or insert the described script pile function of operation from described tested system to described script pile function.
The white-box testing method of above-mentioned use script patch, the process that covers the Run Script pile function in described step in 3. comprises the steps:
A1, when the A function call in the described tested system is in the B function of patch state, do not carry out described B function, directly jump to the mute patch function corresponding with described B function;
The corresponding interface of a2, the described script module of described mute's patch function call is carried out corresponding script pile function, and the return value of described script pile function is passed to described mute's patch function;
A3, described mute's patch function return to the A function with the return value of described script pile function.
The 3. middle process of inserting the Run Script pile function of the white-box testing method of above-mentioned use script patch, its step comprises the steps:
B1, when the A function call in the described tested system is in the B function of patch state, do not carry out described B function, directly jump to the mute patch function corresponding with described B function;
The corresponding interface of b2, the described script module of described mute's patch function call is carried out corresponding script pile function, and the return value of script pile function is passed to described mute's patch function;
B3, recover described B function and be patch state not;
B4, in described mute's patch function, directly call described B function, the return value that obtains and preserve described B function;
B5, the B function is set is patch state;
B6, the return value of described B function is returned to described A function.
Described step a2 or step b2 are by the visit to class ESP register, and the input value during with call function is hinted obliquely at and is the script entity, and the parameter of importing into when making described script pile function can visit, revise the described B function of described A function call realizes.
After the present invention has adopted technique scheme, owing to adopted patching technology, script technology, construct the various types of pile functions that need in the test process by script function, and the script technology possesses directly the characteristics of writing, directly working, avoid compiling repeatedly, link process, thereby improved testing efficiency.Compared with prior art, can construct pile function with script flexibly by this technology, guarantee not revise under the situation of tested system and on-the-fly modify pile function, determine the return value of pile function flexibly, realize the relatively independent of test script and tested system simultaneously, reduced the cost that test code is safeguarded.The present invention can also be used for the market error diagnosis and urgent repairing of operational system.The emulation of the present invention's process, simulation, and in the mirror image testing tool, use, reliably feasible through facts have proved.
Embodiment
Be the structural representation block diagram of white-box testing of the present invention system as shown in Figure 3, comprise test control system 10; Communication module 20; Script module 30; Test module 40 and tested system 50.Tested system 50 compiles, links and become executable system with communication module 20, script module 30, test module 40.Communication module 20 and test control system 10 connect acceptance test instruction, script pile function by socket or serial communication.Communication module 20, script module 30, test module 40 are fixed, and do not change because of the difference of tested system.
The present invention adopts patching technology, script technology, construct the various types of pile functions that need in the test process by script function, test control system 10 briefly is exactly a user interface, the user can be at this compile script pile function, send to communication module 20 then, receive the message of communication module 20 simultaneously, and this message is shown to the user.Test control system 10 is initiated connection request to communication module 20, and after the successful connection, test control system 10 and communication module 20 just enter interaction mode.Communication module 20 and script module 30 are two independently tasks, carry out communication by message queue, communication module 20 just sends instruction to script module 30 by message queue after receiving the test instruction of test control system 10, and script module 30 is explained and carried out this test instruction; The load mode of script pile function also can and instruction load mode identical, the script pile function is imported from testing control module 10 by communication module 20, exists in the script module 30.
Test module 40 comprises patch processing center module 41; Mute's patch function group 42; Address information table 43.
Mute's patch function group 42 comprises a series of mute's function, when tested function is called after the patch installing, at first jump in corresponding mute's patch function, this mute's patch function directly calls patch processing center module 41 interfaces then, tell 41 1 functions in patch center to enter patch, need to carry out corresponding script function.
So-called mute's patch function, be mainly used in the bridge that serves as by between patch function and the script processing center 41, by revising by the code command of patch function, directly redirect (JMP) is to corresponding mute's patch function, mute's patch function is according to by the return value type of patch function, the distinct interface of decision invoke script processing center is told the patch processing center with the address of patch number and ESP register, and patch processing center 41 can correctly be called corresponding script patch function by patch number; The parametric solution that proper address by access classes ESP register can import into when calling by the patch function separates out, thereby guarantees that the parameter of importing into can be used by the script patch function.
Address information table 43 is used for writing down the address information of tested system 50 functions, and this address information is dynamically to obtain in the test process after compiling, link.Concrete acquisition way comprises the steps:
Extem
*Function 1 (
* *);
Extem
*Function 2 (
* *);
……
Extern
*Function n (
* *);
Addressinf[]=(unsigned long) function 1, (unsigned long) function 2 ...,
Unsigned long} function n}
Extem is each function of quoting in the tested system 50 in the above-mentioned code, is the basis of address information table 43 structure, Addressinf[] be address information table 43.
Patch processing center module 41 is transferred the corresponding interface of script module 30, realizes the execution of script pile function.Patch processing center module 41 mainly comprises two functions:
unsigned?long?mirrorProcssPatchUlong(unsigned?long?patchId,unsigned?long
espAddr)
double?mirrorProcssPatch?Double(unsigned?long?patchId,unsigned?long
espAddr)。
Parameter p atchId in the above-mentioned C language function represents current script patch sequence number (ID).Parameter espAddr represents the value of current class esp register.The function of these two functions is script pile functions of ID script patch correspondence calling in this function, and obtains the return value of script pile function.
Replace the operation of concrete C language function in the system under test (SUT) 50 merely with a script function, this script function is referred to as script patch.If a function itself does not exist, and with the certain function of finishing of a script function replacement, then this script function is referred to as the script pile function.Script patch is with the related of script pile function, and the realization of script pile function relies on the script patch technology, can the various types of return values of flexible construction by the script pile function, be mainly used in test; Script patch can be widely used in BUG modification, error diagnosis.Script pile function, script function patch are same contents in fact, are the occasion difference of using, the difference of custom title, and the notion of script pile function is mainly used in field tests, and the notion of script function patch is mainly used in the location of BUG.
Technology of the present invention can be used for the market error diagnosis and urgent repairing of operational system equally.White-box testing system code amount of the present invention is very little in fact, approximately has only 20,000 row C codes, fully can be resident in market product.When market product is pinpointed the problems, again testing control module 10 is connected in this system, by script patch diagnosis BUG reason, use a script function then, substitute the operation of error functions, thus the mistake of avoiding.When not being connected with testing control module 10, all modules of system can be in resting state, product systems are not constituted any influence.
Fig. 4 is the test flow chart of white-box testing of the present invention system, and A function, B function are the C language function in the tested system 50 among the figure, and physical relationship is: the B function is by the A function call.In the test process, need replace the operation of B function, thereby the flexible construction return value is given the A function in script function with script function.
Step 1.2. represents among Fig. 4: increase the script pile function in control system 10, and pass to script module 30 by communication module 20;
Step 3.4.5. represents among Fig. 4: the corresponding relation that increases script pile function and tested system respective function by control system 10 and communication module 20 in the patch processing center module 41 of test module 40;
Step 6.7. represents among Fig. 4: adopt general patching technology, activate the script stake by control system 10 by test module 40, revise the instruction of code segment, realize the commentaries on classics of moving of implementation;
Step 8. expression among Fig. 4: when the A function call B function in the system under test (SUT), because the B function is by patch installing, direct JMP corresponding mute's patch function in mute's patch function group 42;
Step 9.10. represents among Fig. 4: mute's patch function call patch processing center module 41 corresponding interfaces, tell patch processing center module 41, and B function patch is triggered;
Step 11.12. represents among Fig. 4: patch processing center module 41 invoke script modules 30 corresponding interfaces, carry out corresponding script pile function, and obtain the return value of script pile function simultaneously;
Step 13.14. represents among Fig. 4: patch processing center module 41 return values with the script stake pass to mute's patch function, and mute's patch function directly returns to the A function with this value then, thereby have realized replacing with the script pile function operation of B function.
Above-mentioned steps has been described script patch and has promptly been covered the running of Run Script stake, by adding other operations in the middle of the step 13.14. in Fig. 4, can realize inserting the test run process of script stake or script patch, the stake of so-called insertion script is exactly before operation B function, carry out script function, and then continue operation B function, insert script patch and be widely used in the legitimacy of function input parameter is judged.
Fig. 5 adopts inserted mode to use the detail flowchart of script patch, and its concrete steps 1.--13. is identical with Fig. 4, introduces step 14.--17. below in detail:
Step 14. expression among Fig. 5: recover function B and be patch state not;
Step 15. expression among Fig. 5: call the B function, obtain and preserve the return value of B function, (when calling the B function, do suitable processing) with the parameter that guarantees that the B function imports in the time of can correctly obtaining the A function call to the ESP register.
Step 16. expression among Fig. 5: recovering function B is patch state
Step 17. expression among Fig. 5: the return value of the B function that step 15. among Fig. 5 is obtained directly returns to the A function.
The operating process of above-mentioned steps 14-17 is simple, clear, realize that this operating process has multiple operation skill, for example how to adjust the ESP register, how to guarantee the parameter that the B function imports in the time of can correctly obtaining the A function call, how to preserve the return value of B function etc.When inserted mode is used script patch, these parameters import different with the preparation method of return value into, all belong to protection scope of the present invention.
Fig. 6 is a white-box testing of the present invention system operational process schematic diagram, has vividly described thinking of the present invention more.In test process, the B function is by patch installing; When the A function call B function in the tested system, directly jump to corresponding mute's function, this mute's function call mute patch center 41 corresponding interfaces, by these interface interchange script system 30 corresponding interfaces, carry out corresponding script pile function C, obtain the return value of script pile function C simultaneously, patch center 41 passes to mute's function with the return value of script stake, mute's patch function directly returns to the A function with this value then, thereby has realized replacing with script pile function C the operation of B function.
(main thought is tested system entity (variable, function) to be hinted obliquely at be the script entity to cooperate the mirror image measuring technology, thereby by operation to the script entity, reach purpose) to tested system entity operation, by visit to the ESP register, input value in the time of can be with call function is hinted obliquely at and is the script entity, thereby in script stake (script patch), can visit equally, revise and call these parameters, the parameter of importing into when for example Fig. 6 script pile function C can visit A function call B function equally.
The present invention can be applicable to various tested systems.
Illustrate with the C language in the above description, do not represent restriction range of application of the present invention.
Understanding the present invention in order further to help, as one embodiment of the present of invention, is code and the description that example provides mute's patch function d ummyPatchFunc0 PROC with the C language below:
DummyPatchFunc0 PROC push 0 call mpGetPatchedFuncType; Acquisition is by the type add esp of the return value of patch function, 4 push eax pop functype0 push esp; With the ESP register, in the time of can obtaining A and call B by this value, be pressed into heap<!--SIPO<DP n=" 7 "〉--〉<dp n=" d7 "/the parameter p ush 0 of stack; Patch ID .if functype0=0 call mirrorProcssPatchDouble .else call mirrorProcssPatchUlong .endif add esp, 8 pushad push, 0 call mpGetPatchType; Obtain the type add esp of patch, 4 push eax pop patchtype0 popad .ifpatchtype0=0; Cover patch and directly return ret .else; Insert patch .if functype0=0 fstp qword ptr[dummy0] .endif push 0 call mpResumeUnPatchState; To be reverted to not patch state add esp by the patch function, 4 mov funcaddr0, eax pop oldeip0 call funcaddr0; Call by the function push oldeip0 of patch<!--SIPO<DP n=" 8 "〉--〉<dp n=" d8 "/pushad push 0 call mpResumePatchState; Recovery is patch state add esp by the patch function, 4 popad .endif ret dummyPatchFunc0 endp dummyPatchFunc1 PROC push, 1 call mpGetPatchedFuncType add esp, 4 push eax pop functype1 push esp push, 1 .if functype1=0 call mirrorProcssPatchDouble .else call mirrorProcssPatchUlong .endif add esp, 8 pushad push, 1 call mpGetPatchType add esp, 4 push eax<!--SIPO<DP n=" 9 "〉--〉<dp n=" d9 "/pop patchtype 1 popad .ifpatchtype1=0 ret .else .if functype1=0 fstp qword ptr[dumy1] .endif push 1 call mpResumeUnPatchState add esp, 4 mov funcaddr1, eax pop oldeip1 call funcaddr 1 push oldeip1 pushad push 1 call mpResumePatchState add esp, 4 popad .endif ret dummyPatchFunc 1endp dummyPatchFunc2 PROC push, 2 call mpGetPatchedFuncType add esp, 4<!--SIPO<DP n=" 10 "〉--〉<dp n=" d10 "/push eax pop functype2 push esp push 2 .if functype2=0 call mirrorProcssPatchDouble .else call mirrorProcssPatchUlong .endif add esp, 8 pushad push, 2 call mpGetPatchType add esp, 4 push eax pop patchtype2 popad .if patchtype2=0 ret .else .if functype2=0 fstp qword ptr[dummy2] .endif push 2 call mpResumeUnPatchState add esp, 4 mov funcaddr2, eax pop oldeip2<!--SIPO<DP n="11"〉--〉 <dp n="d11"/〉 call funcaddr2 push oldeip2 pushad push 2 call mpResumePatchState add esp;4 popad .endif ret dummyPatchFunc2 endp dummyPatchFunc3 PROC push 3 call mpGetPatchedFuncType add esp;4 push eax pop functype3 push esp push 3 .if functype3=0 call mirrorProcssPatchDouble .else call mirrorProcssPatchUlong .endif add esp,8 pushad push 3 call mpGetPatchType <!--SIPO<DP n=" 12 "〉--〉<dp n=" d12 "/add esp, 4 push eax pop patchtype3 popad .if patchtype3=0 ret .else .if functype3=0 fstp qword ptr[dummy3] .endif push 3 call mpResumeUnPatchState add esp, 4 mov funcaddr3, eax pop oldeip3 call funcaddr3 push oldeip3 pushad push3 call mpResumePatchState add esp, 4 popad .endif ret dummyPatchFunc3 endp