Summary of the invention
In view of this, the invention provides code segment method of testing and the device of program, to reduce original
The interference purpose of program.
First aspect, the invention provides the code segment method of testing of a kind of program, including:
When tested program is tested, described tested program is called the position of tested code section,
Breakpoint/redirect processing unit is set;
Run described tested program, when described tested program performs to calling described tested code fragment position
Time, described breakpoint/redirect processing unit interrupts the execution flow process of described tested code section, and by described quilt
The execution of ranging sequence jumps to testing process;
In performing described testing process, testing results code segment, and obtain test result.
In the first possible implementation of first aspect, the type of code of described tested code section
Including:
Binary program is videoed.
In conjunction with the first possible implementation of first aspect, in the implementation that the second is possible,
Described tested program includes:
Operating system program or application program.
In conjunction with in the implementation that the second of first aspect is possible, in the implementation that the third is possible,
Described breakpoint/redirect processing unit includes:
By arranging breakpoint, probe, dynamically amendment code segment or virtual executory one or combination in any
Realize.
In the 4th kind of possible implementation of first aspect, after described acquisition test result, also include:
After testing process terminates, recover the execution of described tested program.
In conjunction with the 4th kind of possible implementation of first aspect, in the 5th kind of possible implementation,
Described testing process includes:
Structure and inspection test environment;
Call described tested code section;
After described tested code section is finished, carry out inspection and the record of described test environment result.
In conjunction with the 4th kind of possible implementation of first aspect, in the 6th kind of possible implementation,
Described testing process includes:
Structure and inspection test environment;
Call the copy of described tested code section;
After the copy of described tested code section is finished, carry out described test environment result inspection and
Record.
In conjunction with the 5th kind or the 6th kind of possible implementation of first aspect, in the 7th kind of implementation,
Also include:
Before the execution of the described tested program that recovery is interrupted, clear up described test environment.
In conjunction with the 6th kind of possible implementation of first aspect, in the 8th kind of possible implementation,
Before described structure and inspection test environment, also include:
When described tested code section copy not in the presence of, create the copy of described tested code section.
In conjunction with the 8th kind of possible implementation of first aspect, in the 9th kind of possible implementation,
The copy of described tested code section includes:
Code segment with the equivalence of described tested code section logic function.
Second aspect, the present invention provides the code segment test device of a kind of program, including:
Breakpoint setup unit, for when testing tested program, calls in described tested program
The position of tested code section, arranges breakpoint/redirect processing unit;
Described breakpoint/redirect processing unit, for performing to calling described tested generation when described tested program
During code fragment position, described breakpoint/redirect processing unit interrupts the execution flow process of described tested code section, and
The execution of described tested program is jumped to testing process;
Test cell, is used in performing described testing process, testing results code segment, and obtains test
Result.
In the first possible implementation of second aspect, the type of code of described tested code section
Including:
Binary program is videoed.
In conjunction with the first possible implementation of second aspect, in the implementation that the second is possible,
Described tested program includes:
Operating system program or application program.
In conjunction with the implementation that the second of second aspect is possible, in the implementation that the third is possible,
Described breakpoint/redirect processing unit includes:
Breakpoint, probe, dynamically amendment code segment or virtual executory one or combination in any.
In the 4th kind of possible implementation of second aspect, also include:
Recovery unit, for by described breakpoint/redirect processing unit, recovering the execution of described tested program.
In conjunction with the 4th kind of possible implementation of second aspect, in the 5th kind of possible implementation,
Described test cell, including:
Test environment constructing module, is used for constructing and checking test environment;
Code segment calling module, is used for calling described tested code section;
Test result acquisition module, for after described tested code section is finished, carries out described survey
The inspection of examination environmental consequences and record.
In conjunction with the 4th kind of possible implementation of second aspect, in the 6th kind of possible implementation,
Described test cell, including:
Test environment constructing module, is used for constructing and checking test environment;
Code segment calling module, for calling the copy of described tested code section;
Test result acquisition module, after the copy of described tested code section is finished, carries out institute
State inspection and the record of test environment result.
In conjunction with the 5th kind or the 6th kind of possible implementation of second aspect, in the 7th kind of implementation
Described test cell, also includes:
Test environment cleaning module, before the execution of the described tested program being interrupted in recovery, cleaning
Described test environment.
In conjunction with the 6th kind of possible implementation of second aspect, in the 8th kind of possible implementation,
Described test cell, also includes:
Copy creating module, for before described structure and inspection test environment, when described tested code
Section copy not in the presence of, create the copy of described tested code section.
In conjunction with the 8th kind of possible implementation of second aspect, in the 9th kind of possible implementation,
The copy of described tested code section includes:
Code segment with the equivalence of described tested code section logic function.
The third aspect, the present invention provides the code segment test system of a kind of program, including the code segment of program
Test device;Described code segment test device includes:
Breakpoint setup unit, for when testing tested program, calls in described tested program
The position of tested code section, arranges breakpoint/redirect processing unit;
Described breakpoint/redirect processing unit, for performing to calling described tested generation when described tested program
During code fragment position, described breakpoint/redirect processing unit interrupts the execution flow process of described tested code section, and
The execution of described tested program is jumped to testing process;
Test cell, is used in performing described testing process, testing results code segment, and obtains test
Result.
From above-mentioned technical scheme it can be seen that the present invention test for code segment be no longer as existing
In technology like that, use the mode of hard coded, need the internal build in tested program to test module;And
Can be by a test program and perform to control tested program so that it is run tested program to calling
The position of tested code section is interrupted, and jumps to testing process carry out the survey of completion code section by performing flow process
Examination;Owing to the technical scheme in the present invention is not provided with test module, so will not carry in tested program
The complexity of high tested program logic, also would not introduce new defect to tested program, and then by this
Invention, it is possible to avoid cause original tested program is interfered due to the new defect of introducing.
Detailed description of the invention
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is carried out
Clearly and completely describe, it is clear that described embodiment is only a part of embodiment of the present invention, and
It is not all, of embodiment.Based on the embodiment in the present invention, those of ordinary skill in the art are not making
Go out the every other embodiment obtained under creative work premise, broadly fall into the scope of protection of the invention.
In order to realize reducing the purpose of the interference to original program, in one aspect of the invention, it is provided that one
The code segment method of testing of the program of kind, as it is shown in figure 1, include step:
S11, when tested program is tested, tested program is called the position of tested code section,
Breakpoint/redirect processing unit is set.
In the present invention, the code segment in program is tested, can be realized by a test program,
For the ease of understanding and distinguishing, in the present invention, the program belonging to tested code section is referred to as by ranging
Sequence, is referred to as test program by the program testing tested code section.
In order to test the code segment set in tested program, first test program is in tested code
The calling station of section is provided with breakpoint/redirect processing unit, to facilitate the control for tested program.
S12, run tested program, when tested program performs to when calling the position of described tested code section,
Breakpoint/redirect processing unit interrupts the execution flow process of tested code section, and the execution of tested program is redirected
Testing process to tested code section.
When carrying out the test of code segment, first run tested program, when tested program runs to need to adjust
During with the position of tested code section, breakpoint/redirect processing unit will the calling of adapter tested code section
Process;And tested program is redirected to the testing process of test program, the tune of adapter tested code section
Use process.Specifically can include, first interrupt the execution flow process of tested code section, then, by tested
The execution of program jumps to the testing process of tested code section.
S13, performing in described testing process, testing results code segment, and obtaining test result.
After the execution of tested program jumps to the testing process of tested code section, test program can be held
The testing process that row is corresponding, and then test result can be obtained.
In actual applications, test code segment can be the tested code self of modulation, it is also possible to be
The copy of test code segment.Such that it is able to tested code is surveyed by the operation of test code segment
Examination.
In the present invention, the test for code segment is no longer as in the prior art, using hard coded
Mode, needs to test module in the internal build of tested program, and can be by a test program
Control the execution route of tested code section corresponding programme so that it is enter testing process after interruption and complete generation
The test of code section;So, the complexity of logic in the program belonging to tested code section would not be improved, from
And avoid the interference to original program.
Preferably, in the present invention, for performing the type of code of the tested code section of test, permissible
Being binary code segment program image, such as, operating system program is videoed, owing to kernel program runs
Time be difficult to control and itself be the ISP of bottom, so cannot directly apply existing, as
The testing tools such as Xunit, so by the test mode in the present invention, can not change kernel binary system
Under mirror image scene, it is tested.So, kernel arrange redirect/breakpoint processing unit is triggered
After, programming jump to testing process performs.Testing process can be provided with test code, test code
A binary image file can be compiled in, it would however also be possible to employ dynamic-form loads with tested code.
So, in the present invention, by redirecting/breakpoint technique, solve and do not change kernel binary image scene
Under the problem of kernel test difficulty, thus improve debugging and the testing efficiency of kernel development.
In the test process realizing code segment, test code modulation tested code, can be by jumping
Turn/breakpoint trigger and test the coordinating of code logic, or the side by generation tested code equivalent copy
Formula, prevents tested code to be again triggered, thus avoid the occurrence of redirect/breakpoint processing unit is with tested
Occurring endless loop between code, final realization tests the code section encapsulation function to tested code.
In actual applications, breakpoint/redirect processing unit can be specifically by breakpoint, probe, dynamically repair
Change code segment or virtual executory one or more arrange be implemented in combination in.
Further, in the present invention, in order to not affect the execution of tested program, or, can continue
Carry out the test of other follow-up code segments, after the test result obtaining tested code section, it is also possible to
The execution flow process of test code segment is jumped to tested program;So, after testing process terminates, so that it may
To recover the execution of tested program.
In actual applications, the step of testing process can be as in figure 2 it is shown, include:
S21, construct and check test environment;
S22, call described tested code section;
After S23, described tested code section are finished, carry out inspection and the note of described test environment result
Record.
As it is shown on figure 3, when using the testing process described in step S21 to S23, carry out code segment
The overall flow of test be:
When tested program normally performs the position to tested code section, test program is by being positioned at herein
The invoked procedure of breakpoint/redirect processing unit adapter tested program, i.e. interrupt the execution of tested code section
Flow process, is then relocated to test by jump instruction by the execution of the program belonging to tested code section and flows
Journey.
In testing process, first construct and check test environment, additionally, call at test process tested
Before code, test program also to forbid redirecting/breakpoint processing logic in the repeating of jump instruction.
Then, test program can call tested code section, makes tested code section perform it and runs;
After the operation of tested code section is finished, perform inspection and the record of test environment result,
That is, test result is generated;
Then, the execution flow process of test code segment is jumped to tested program, such that it is able to recover by ranging
The subsequent execution of sequence.
Preferably, before the execution flow process of test code segment is jumped to tested program, it is also possible to include
Step: cleaning test environment, thus carry out environment cleaning work.
In actual applications, the step of testing process can also as shown in Figure 4, including:
S31, construct and check test environment;
S32, call the copy of described tested code section;
After S33, described tested code section are finished, carry out inspection and the note of described test environment result
Record.
As it is shown in figure 5, when using the testing process described in step S31 to S33, carry out code segment
The overall flow of test be:
When tested program normally performs the position to tested code section, test program is by being positioned at herein
The invoked procedure of breakpoint/redirect processing unit adapter tested program, i.e. interrupt the execution of tested code section
Flow process, is then relocated to test by jump instruction by the execution of the program belonging to tested code section and flows
Journey.
In testing process, first construct and check test environment.
Then, test program can call the copy of tested code section, and runs tested code section
Copy;Concrete, in the present invention, the copy of tested code section can be complete with tested code section
It is identical, additionally, the copy of tested code section can also be with the equivalence of tested code section logic function
Code segment.
After the operation of the copy of tested code section is finished, return the inspection performing test environment result
Look into and record, i.e. generate test result;
Then, the execution flow process of test code segment is jumped to tested program, such that it is able to recover by ranging
The subsequent execution of sequence.
Preferably, before the execution flow process of test code segment is jumped to tested program, it is also possible to include
Step: cleaning test environment, thus carry out environment cleaning work.
Preferably, before the above-mentioned copy calling tested code section, when tested code section copy not
In the presence of, it is also possible to create the step of the copy of tested code section.
Corresponding to the code segment method of testing embodiment of program illustrated in fig. 1, the opposing party of the application
Face, additionally provide a kind of program code segment test device, as shown in Figure 6, including:
Breakpoint setup unit 01, for breakpoint setup unit, is used for when testing tested program,
In described tested program, call the position of tested code section, breakpoint/redirect processing unit is set;
Breakpoint/redirect processing unit 02, for described breakpoint/redirect processing unit, for when described by ranging
Sequence performs to when calling described tested code fragment position, and described breakpoint/redirect processing unit interrupts described quilt
The execution flow process of test code segment, and the execution of described tested program is jumped to testing process;
Test cell 03, is used in performing described testing process, testing results code segment, and obtains survey
Test result.
In the present invention, the code segment test device testing the code segment in program, can be one
The test program realized by software, for the ease of understanding and distinguishing, in the present invention, by tested
Program belonging to code segment is referred to as tested program, is referred to as surveying by the program testing tested code section
Examination program.
In order to test the code segment set in tested program, first breakpoint setup unit 01 is tested
The calling station of examination code segment is provided with breakpoint/redirect processing unit, so, in the test carrying out code segment
Time, first run tested program, when tested program runs to the position needing to call tested code section,
Breakpoint/redirect processing unit 02 will the invoked procedure of adapter tested code section;And tested program is reset
To the testing process to test program, the invoked procedure of adapter tested code section specifically includes, first in
The execution flow process of disconnected tested code section, then, jumps to tested code section by the execution of tested program
Testing process.
After the execution of tested program jumps to the testing process of tested code section, test cell 03 can open
The execution of dynamic testing process, and then with testing results code segment, and test result can be obtained.
In the present invention, the test for code segment is no longer as in the prior art, using hard coded
Mode, needs to test module in the internal build of tested program, and can be by a test program
Control the execution route of tested code section corresponding programme so that it is enter testing process after interruption and complete generation
The test of code section;So, the complexity of logic in the program belonging to tested code section would not be improved, from
And avoid the interference to original program.
Preferably, in the present invention, for performing the type of code of the tested code section of test, permissible
Being binary code segment program image, such as, operating system program is videoed, owing to kernel program runs
Time be difficult to control and itself be the ISP of bottom, so cannot directly apply existing, as
The testing tools such as Xunit, so by the test mode in the present invention, can not change kernel binary system
Under mirror image scene, it is tested.So, kernel arrange redirect/breakpoint processing unit is triggered
After, programming jump to testing process performs.Testing process can be provided with test code, test code
A binary image file can be compiled in, it would however also be possible to employ dynamic-form loads with tested code.
So, in the present invention, by redirecting/breakpoint technique, solve and do not change kernel binary image scene
Under the problem of kernel test difficulty, thus improve debugging and the testing efficiency of kernel development.
In the test process realizing code segment, test code modulation tested code, can be by jumping
Turn/breakpoint trigger and test the coordinating of code logic, or the side by generation tested code equivalent copy
Formula, prevents tested code to be again triggered, thus avoid the occurrence of redirect/breakpoint processing unit is with tested
Occurring endless loop between code, final realization tests the code section encapsulation function to tested code.
In actual applications, breakpoint/redirect processing unit can be specifically by breakpoint, probe, dynamically repair
Change code segment or virtual executory one or more arrange be implemented in combination in.
Further, in the present invention, in order to not affect the execution of tested program, or, can continue
Carry out the test of other follow-up code segments, after the test result obtaining tested code section, it is also possible to
Including recovery unit, so, by recovery unit, the execution flow process of test code segment is jumped to by ranging
Sequence;So that, after testing process terminates, it is possible to recover the execution of tested program.
In actual applications, test cell 03 specifically can also include:
Test environment constructing module, is used for constructing and checking test environment;
Code segment calling module, for calling the copy of described tested code section;
Test result acquisition module, after tested code section is finished, carries out described test environment
The inspection of result and record.
As it is shown on figure 3, using test cell 03 to include that above-mentioned test environment constructing module, code segment are adjusted
During with module and test result acquisition module, the overall flow of the test carrying out code segment can be:
When tested program normally performs the position to tested code section, it is positioned at breakpoint herein/redirect process
The invoked procedure of unit 02 adapter tested program, i.e. interrupt the execution flow process of tested code section, then
By jump instruction, the execution of the program belonging to tested code section is relocated to testing process.
In testing process, first test environment constructing module structure and inspection test environment.
Then, code segment calling module test program can call the copy of tested code section, and runs
The copy of tested code section;Concrete, in the present invention, the copy of tested code section can be with quilt
Test code segment is identical, additionally, the copy of tested code section can also be and tested code section logic
The code segment of function equivalent.
After the operation of the copy of tested code section is finished, test result acquisition module returns and performs
The inspection of test environment result and record, i.e. generate test result;
Then, the execution flow process of test code segment is jumped to tested program by recovery unit, such that it is able to extensive
The subsequent execution of multiple tested program.
Preferably, the test cell in the application, it is also possible to include that test environment clears up module, test wrapper
Cleaning module in border is for before jumping to tested program by the execution flow process of test code segment, and cleaning is tested
Environment, thus carry out environment cleaning work.
Preferably, the test cell 03 in the present invention can also include copy creating module, copy creating mould
Block for before the above-mentioned copy calling tested code section, when tested code section copy not in the presence of,
Create the copy of tested code section.
In the another aspect of the application, additionally provide the code segment test system of another kind of program, this code
Section test system includes the code segment test device in an embodiment, due to the code in the present embodiment
Code segment test device in section test system and the code segment in a upper embodiment test the structure phase of device
With, operation principle is identical and beneficial effect is identical, so just repeating no more at this.
Further, the embodiment of the present invention additionally provides the hardware composition of code segment test device.Can include
At least one processor (such as CPU), and at least one memorizer.Processor is used for performing in memorizer
The executable module of storage, such as computer program.Memorizer may comprise high-speed random access memory
(RAM:Random Access Memory), it is also possible to also include non-labile memorizer
(non-volatile memory), for example, at least one disk memory.By at least one network interface
(can be wired or wireless) realizes the communication link between this system gateway and at least one other network element
Connect, it is possible to use the Internet, wide area network, LAN, Metropolitan Area Network (MAN) etc..
Seeing Fig. 7, in some embodiments, store programmed instruction in memorizer, programmed instruction is permissible
Being executed by processor, wherein, programmed instruction includes breakpoint setup unit 01, breakpoint/redirect processing unit 02
With test cell 03, each unit implement the corresponding units that can be found in disclosed in Fig. 6.
The present invention program can retouch in the general context of computer executable instructions
State, such as program unit.Usually, program unit includes performing particular task or realizing specific abstract number
According to the routine of type, program, object, assembly, data structure etc..Can also be at Distributed Calculation ring
Border is put into practice the present invention program, in these distributed computing environment, is connected by by communication network
Remote processing devices perform task.In a distributed computing environment, program unit may be located at and includes
Storage device is in interior local and remote computer-readable storage medium.
Each embodiment in this specification all uses the mode gone forward one by one to describe, identical between each embodiment
Similar part sees mutually, and what each embodiment stressed is different from other embodiments
Part.For device embodiment, owing to it is substantially similar to embodiment of the method, so retouching
Stating fairly simple, relevant part sees the part of embodiment of the method and illustrates.Dress described above
Putting embodiment is only schematically, and the wherein said unit that illustrates as separating component can be or also
Can not be physically separate, the parts shown as unit can be or may not be physics list
Unit, i.e. may be located at a place, or can also be distributed on multiple NE.Can be according to reality
The needing of border selects some or all of module therein to realize the purpose of the present embodiment scheme.This area
Those of ordinary skill, in the case of not paying creative work, is i.e. appreciated that and implements.
Being described in detail the embodiment of the present invention above, detailed description of the invention used herein is to this
Invention is set forth, and the explanation of above example is only intended to help to understand the method and apparatus of the present invention;
Simultaneously for one of ordinary skill in the art, according to the thought of the present invention, in detailed description of the invention and
All will change in range of application, in sum, this specification content should not be construed as the present invention
Restriction.