CN106155897B - Service processing method and device - Google Patents

Service processing method and device Download PDF

Info

Publication number
CN106155897B
CN106155897B CN201510180527.1A CN201510180527A CN106155897B CN 106155897 B CN106155897 B CN 106155897B CN 201510180527 A CN201510180527 A CN 201510180527A CN 106155897 B CN106155897 B CN 106155897B
Authority
CN
China
Prior art keywords
function
code
service
target
source code
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
CN201510180527.1A
Other languages
Chinese (zh)
Other versions
CN106155897A (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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201510180527.1A priority Critical patent/CN106155897B/en
Publication of CN106155897A publication Critical patent/CN106155897A/en
Application granted granted Critical
Publication of CN106155897B publication Critical patent/CN106155897B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The embodiment of the invention provides a service processing method and a device, wherein the method comprises the following steps: analyzing a source code of a service to be processed to obtain key information of at least one function contained in the source code; performing instrumentation processing on the source code according to the key information of the at least one function to obtain a target code; running the target code and collecting function calling information of the target code in the running process; and calculating the coverage parameters of the service according to the function calling information. The method and the device can calculate the coverage parameters of the services based on the functions, improve the calculation precision of the coverage parameters of the services, and improve the accuracy of judging the integrity of the services.

Description

Service processing method and device
Technical Field
The present invention relates to the field of internet technologies, in particular, to the field of internet service technologies, and in particular, to a service processing method and apparatus.
Background
Coverage parameters are an important index for measuring the integrity of internet services, and in the prior art, code coverage is usually used to represent the coverage parameters of services, such as: in the test service of the internet software, the code coverage rate of the test service is usually required to be calculated so as to know the scheme integrity of the test service; generally, statistical tools such as GCov/LCov (code coverage testing tool), EMMA (a code coverage testing tool), or the like can be used to calculate the code coverage of a service; however, the above statistical tool adopts a calculation mode of "line-based code coverage", that is, the code coverage is obtained according to the calling condition of each code line, and is accurate to each code line in the source code of the service, and due to the service iteration requirement, the code line of the source code of the service is frequently changed, thereby reducing the calculation accuracy of "line-based code coverage" in the prior art and affecting the integrity judgment of the service.
Disclosure of Invention
Embodiments of the present invention provide a service processing method and apparatus, which can calculate a coverage parameter of a service based on a function, improve calculation accuracy of the coverage parameter of the service, and improve accuracy of service integrity evaluation.
A first aspect of an embodiment of the present invention provides a service processing method, which may include:
analyzing a source code of a service to be processed to obtain key information of at least one function contained in the source code;
performing instrumentation processing on the source code according to the key information of the at least one function to obtain a target code;
running the target code and collecting function calling information of the target code in the running process;
and calculating the coverage parameters of the service according to the function calling information.
A second aspect of the embodiments of the present invention provides a service processing apparatus, which may include:
the analysis unit is used for analyzing a source code of a service to be processed to obtain key information of at least one function contained in the source code;
the instrumentation processing unit is used for performing instrumentation processing on the source code according to the key information of the at least one function to obtain a target code;
an execution unit configured to execute the object code;
the acquisition unit is used for acquiring function calling information of the target code in the running process;
and the calculating unit is used for calculating the coverage parameters of the service according to the function calling information.
The embodiment of the invention has the following beneficial effects:
in the embodiment of the invention, the source code of the service can be subjected to instrumentation processing according to the key information of at least one function contained in the source code of the service to obtain the target code, the function call information in the running process of the target code is acquired, and the coverage parameter of the service is calculated based on the function call information, so that the coverage parameter of the service can be accurate to the function in the source code without being limited by the change of a code line, the calculation precision of the coverage parameter of the service is improved, and the accuracy of judging the integrity of the service is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a flowchart of a service processing method according to an embodiment of the present invention;
fig. 2 is a flowchart of another service processing method according to an embodiment of the present invention;
FIG. 3 is a detailed step of step S210 of the embodiment shown in FIG. 2;
fig. 4 is a schematic structural diagram of a service processing apparatus according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an analysis unit according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of an insertion processing unit according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of an acquisition unit according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of a computing unit 105 according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of an embodiment of the coverage calculating unit shown in fig. 8.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The service processing method provided by the embodiment of the present invention will be described in detail below with reference to fig. 1 to 3.
Please refer to fig. 1, which is a flowchart of a service processing method according to an embodiment of the present invention; the method may include the following steps S101 to S105.
S101, analyzing a source code of a service to be processed to obtain key information of at least one function contained in the source code.
The service of the embodiment of the invention refers to an internet service, and can include but is not limited to: testing service of internet software, detection service of application program, etc., and the service implements corresponding service functions through source codes, for example: the source code of the testing service of the internet software can realize the testing function of the internet software. Generally, at least one function is included in the source code, and the source code selectively calls the at least one function included in the source code according to requirements in the running process to realize the corresponding service function.
In the embodiment of the present invention, the key information of a function includes: a globally unique name for a function and a start location for the function, the start location for the function including a start code row and a start code column for the function. The global unique name of the function is a unique name which is obtained by naming the function by adopting a global unique naming rule and can be used for identifying the function; in a specific implementation, the globally unique naming rule for the function of the object-oriented language may include four parts of contents, including: package name, class name, function name, and function parameter type name, for example: the global unique name of a function compiled by a certain object-oriented language is com.sample.class1.func1(int ), and according to the global unique naming rule, the global unique name comprises 4 parts of contents, wherein the first part of contents is a package name com.sample, the second part of contents is a class name class1, the third part of contents is a function name func1, and the fourth part of contents is a function parameter type name (int ). The globally unique naming convention for functions of a non-object-oriented language may contain three parts of content, including: file path, file name, and function name. In this step, the source code of the service to be processed may be analyzed, including lexical and/or syntactic analysis of the source code, to obtain the key information of each function included in the source code.
S102, performing instrumentation processing on the source code according to the key information of the at least one function to obtain a target code.
The instrumentation processing of the source code means that instrumentation code is inserted into the source code, and execution information such as control flow, data flow and the like of the source code in the running process is obtained through execution of the instrumentation code. The key of the instrumentation process is to determine the insertion position of the instrumentation code, and in this step, the start position of each function may be determined as the insertion position of the instrumentation code, so that the instrumentation process is performed on the source code, and the source code after the instrumentation process is completed may be referred to as a target code.
S103, operating the object code. This step requires running the object code, i.e. running the source code with stub code.
And S104, collecting function calling information of the target code in the running process.
The target code is a source code with stub codes, and each time the target code calls a function in the running process, the stub codes at the starting positions of the functions are executed so as to output the calling information of the functions, and in the step, the calling information of all the functions called by the target code in the running process can be collected and counted; the function call information preferably includes a globally unique name of the called function, and further, the function call information may further include other information such as a use case identifier, a called number of times, and a called time of the called function.
And S105, calculating the coverage parameters of the service according to the function calling information.
The coverage parameter is an important index for measuring the integrity of the internet service, and the coverage parameter of the service is represented by adopting a code coverage rate in the prior art; the embodiment of the invention can adopt the function coverage rate to represent the coverage parameter of the service. The function call information preferably includes a globally unique name of the called function, that is, in the process of calculating the coverage parameter of the service, the embodiment focuses only on the globally unique name of the called function, and does not focus on the code line in the called function any more, so that the coverage parameter of the service can be accurate to the function without limiting the change of the code line, and the calculation accuracy of the coverage parameter of the service is improved.
In the embodiment of the invention, the source code of the service can be subjected to instrumentation processing according to the key information of at least one function contained in the source code of the service to obtain the target code, the function call information in the running process of the target code is acquired, and the coverage parameter of the service is calculated based on the function call information, so that the coverage parameter of the service can be accurate to the function in the source code without being limited by the change of a code line, the calculation precision of the coverage parameter of the service is improved, and the accuracy of judging the integrity of the service is improved.
Please refer to fig. 2, which is a flowchart of another service processing method according to an embodiment of the present invention; the method may include the following steps S201 to S210.
S201, acquiring a source code of the service to be processed.
The service of the embodiment of the invention refers to an internet service, and can include but is not limited to: testing service of internet software, detection service of application program, etc., and the service implements corresponding service functions through source codes, for example: the source code of the testing service of the internet software can realize the testing function of the internet software. In this step, the source code of the service to be processed needs to be obtained, and in a specific implementation, the source code of the service can be obtained from a service configuration file of the service to be processed.
S202, performing static analysis on the source code to obtain at least one function contained in the source code.
Generally, at least one function is included in the source code, and the source code selectively calls the at least one function included in the source code according to requirements in the running process to realize the corresponding service function. In this step, the source code of the service to be processed may be statically analyzed, including lexical and/or syntactic analysis of the source code, to obtain at least one function included in the source code.
S203, reading the key information of the at least one function.
Key information for a function includes: a globally unique name for a function and a start location for the function, the start location for the function including a start code row and a start code column for the function. The global unique name of the function is a unique name which is obtained by naming the function by adopting a global unique naming rule and can be used for identifying the function; in a specific implementation, the globally unique naming rule for the function of the object-oriented language may include four parts of contents, including: package name, class name, function name, and function parameter type name, for example: the global unique name of a function compiled by a certain object-oriented language is com.sample.class1.func1(int ), and according to the global unique naming rule, the global unique name comprises 4 parts of contents, wherein the first part of contents is a package name com.sample, the second part of contents is a class name class1, the third part of contents is a function name func1, and the fourth part of contents is a function parameter type name (int ). The globally unique naming convention for functions of a non-object-oriented language may contain three parts of content, including: file path, file name, and function name. In this step, according to at least one function obtained by parsing in step S202, key information of each function can be read.
Steps S201 to S203 of the present embodiment may be specific refinements of step S101 of the embodiment shown in fig. 1.
And S204, inserting pile codes into the initial positions of the functions respectively according to the globally unique names of the functions in the at least one function.
A globally unique name may be used to uniquely identify a function; in this step, a stub code may be inserted into the starting position of each function according to the globally unique name of each function in the at least one function, that is, one function corresponds to one stub code. The specific form of the stub code may be determined according to actual conditions, for example: stub code may be log (funcname), the specific form of which may be the same as the specific form of the source code, and so on.
S205, determining the source code containing the stub code as a target code.
And inserting stub codes into the source codes, and obtaining running information such as control flow, data flow and the like of the source codes in the running process through the execution of the stub codes. In this step, the source code after the instrumentation process is completed is referred to as target code.
Steps S204 to S205 of the present embodiment may be specific refinements of step S102 of the embodiment shown in fig. 1.
S206, operating the object code. This step requires running the object code, i.e. running the source code with stub code.
And S207, outputting the global unique name of the target function called by the target code in the running process of the target code.
The target code is a source code with stub codes, each time the target code calls a function in the running process, the stub codes at the starting positions of the functions are executed so as to output the calling information of the functions, and the globally unique name of each target function called by the target code can be output in the step.
And S208, generating a calling function set according to the global unique name of the target function.
According to the globally unique name of each target function, a calling function set can be generated, for example: assuming that step S207 outputs globally unique names a1, a2 and a3, this step may generate a set of calling functions a, which includes a1, a2 and a3, indicating that the target functions called by the target code include a function identified by a1, a function identified by a2 and a function identified by a 3.
S209, generating a primitive function set according to the global unique name of at least one function contained in the source code.
According to the globally unique name of each function contained in the source code, a primitive function set can be generated, for example: assuming that the source code includes four functions with globally unique names a1, a2, a3, and B1, the step may generate a source function set B, where the calling function set B includes a1, a2, a3, and B1, which indicates that the functions included in the source code include a function identified by a1, a function identified by a2, a function identified by a3, and a function identified by B1.
And S210, calculating the function coverage rate of the service by adopting a preset coverage rate calculation rule according to the calling function set and the primitive function set.
The coverage parameter is an important index for measuring the integrity of the internet service, and the coverage parameter of the service is represented by adopting a code coverage rate in the prior art; the embodiment of the invention can adopt the function coverage rate to represent the coverage parameter of the service.
Please refer to fig. 3, which is a detailed step of step S210 in the embodiment shown in fig. 2; the step S210 may specifically include the following steps S11-S13.
s11, finding the intersection of the calling function set and the original function set.
According to the example shown in step S208 to step S209, assuming that the call function set is a and the original function set is B, step S11 needs to obtain the intersection a & B of the call function set a and the original function set B, where, & represents the intersection calculation.
s12, calculating a function percentage of the intersection relative to the set of primitive functions.
According to the example of step s11, the functional percentage of the intersection set a & B with respect to the original function set B calculated in step s12 may be expressed as ((a & B)/B) × 100%.
s13, determining the calculated function percentage as the function coverage of the service. This step s13 may determine that the functional coverage of the traffic is ((a & B)/B) × 100%.
In the embodiment of the invention, the source code of the service can be subjected to instrumentation processing according to the key information of at least one function contained in the source code of the service to obtain the target code, the function call information in the running process of the target code is acquired, and the coverage parameter of the service is calculated based on the function call information, so that the coverage parameter of the service can be accurate to the function in the source code without being limited by the change of a code line, the calculation precision of the coverage parameter of the service is improved, and the accuracy of judging the integrity of the service is improved.
The structure and function of the service processing device provided by the embodiment of the invention will be described in detail with reference to fig. 4 to 9. It should be noted that the service processing device described below can be applied to execute the methods shown in fig. 1 to fig. 3.
Please refer to fig. 4, which is a schematic structural diagram of a service processing apparatus according to an embodiment of the present invention; the apparatus may include: the system comprises an analysis unit 101, an instrumentation processing unit 102, an operation unit 103, an acquisition unit 104 and a calculation unit 105.
The parsing unit 101 is configured to parse a source code of a service to be processed, and obtain key information of at least one function included in the source code.
The service of the embodiment of the invention refers to an internet service, and can include but is not limited to: testing service of internet software, detection service of application program, etc., and the service implements corresponding service functions through source codes, for example: the source code of the testing service of the internet software can realize the testing function of the internet software. Generally, at least one function is included in the source code, and the source code selectively calls the at least one function included in the source code according to requirements in the running process to realize the corresponding service function.
In the embodiment of the present invention, the key information of a function includes: a globally unique name for a function and a start location for the function, the start location for the function including a start code row and a start code column for the function. The global unique name of the function is a unique name which is obtained by naming the function by adopting a global unique naming rule and can be used for identifying the function; in a specific implementation, the globally unique naming rule for the function of the object-oriented language may include four parts of contents, including: package name, class name, function name, and function parameter type name, for example: the global unique name of a function compiled by a certain object-oriented language is com.sample.class1.func1(int ), and according to the global unique naming rule, the global unique name comprises 4 parts of contents, wherein the first part of contents is a package name com.sample, the second part of contents is a class name class1, the third part of contents is a function name func1, and the fourth part of contents is a function parameter type name (int ). The globally unique naming convention for functions of a non-object-oriented language may contain three parts of content, including: file path, file name, and function name. The parsing unit 101 may parse a source code of a service to be processed, including lexical and/or syntactic analysis of the source code, to obtain key information of each function included in the source code.
And the instrumentation processing unit 102 is configured to perform instrumentation processing on the source code according to the key information of the at least one function to obtain a target code.
The instrumentation processing of the source code means that instrumentation code is inserted into the source code, and execution information such as control flow, data flow and the like of the source code in the running process is obtained through execution of the instrumentation code. The key of the instrumentation process is to determine the insertion position of the instrumentation code, and the instrumentation processing unit 102 may determine the start position of each function as the insertion position of the instrumentation code, so as to perform the instrumentation process on the source code, and the source code after the instrumentation process is completed may be referred to as a target code.
An execution unit 103, configured to execute the object code. The execution unit 103 needs to execute the target code, i.e. execute the source code with stub code.
And the acquisition unit 104 is configured to acquire function call information of the target code in the running process.
The target code is a source code with stub code, each time the target code calls a function in the running process, the stub code at the starting position of the function is executed to output the calling information of the function, and the acquisition unit 104 can acquire and count the calling information of all functions called by the target code in the running process; the function call information preferably includes a globally unique name of the called function, and further, the function call information may further include other information such as a use case identifier, a called number of times, and a called time of the called function.
A calculating unit 105, configured to calculate a coverage parameter of the service according to the function call information.
The coverage parameter is an important index for measuring the integrity of the internet service, and the coverage parameter of the service is represented by adopting a code coverage rate in the prior art; the embodiment of the invention can adopt the function coverage rate to represent the coverage parameter of the service. The function call information preferably includes a globally unique name of the called function, that is, in the process of calculating the coverage parameter of the service, the embodiment focuses only on the globally unique name of the called function, and does not focus on the code line in the called function any more, so that the coverage parameter of the service can be accurate to the function without limiting the change of the code line, and the calculation accuracy of the coverage parameter of the service is improved.
In the embodiment of the invention, the source code of the service can be subjected to instrumentation processing according to the key information of at least one function contained in the source code of the service to obtain the target code, the function call information in the running process of the target code is acquired, and the coverage parameter of the service is calculated based on the function call information, so that the coverage parameter of the service can be accurate to the function in the source code without being limited by the change of a code line, the calculation precision of the coverage parameter of the service is improved, and the accuracy of judging the integrity of the service is improved.
Fig. 5 is a schematic structural diagram of an analysis unit according to an embodiment of the present invention; the parsing unit 101 may include: a source code acquisition unit 1001, a static parsing unit 1002, and a key information reading unit 1003.
A source code obtaining unit 1001, configured to obtain a source code of a service to be processed.
The service of the embodiment of the invention refers to an internet service, and can include but is not limited to: testing service of internet software, detection service of application program, etc., and the service implements corresponding service functions through source codes, for example: the source code of the testing service of the internet software can realize the testing function of the internet software. The source code obtaining unit 1001 needs to obtain a source code of a service to be processed, and in a specific implementation, the source code of the service may be obtained from a service configuration file of the service to be processed.
A static parsing unit 1002, configured to perform static parsing on the source code to obtain at least one function included in the source code.
Generally, at least one function is included in the source code, and the source code selectively calls the at least one function included in the source code according to requirements in the running process to realize the corresponding service function. The static parsing unit 1002 may perform static parsing on a source code of a service to be processed, including lexical and/or syntactic analysis of the source code, to obtain at least one function included in the source code.
A key information reading unit 1003, configured to read key information of the at least one function.
Key information for a function includes: a globally unique name for a function and a start location for the function, the start location for the function including a start code row and a start code column for the function. The global unique name of the function is a unique name which is obtained by naming the function by adopting a global unique naming rule and can be used for identifying the function; in a specific implementation, the globally unique naming rule for the function of the object-oriented language may include four parts of contents, including: package name, class name, function name, and function parameter type name, for example: the global unique name of a function compiled by a certain object-oriented language is com.sample.class1.func1(int ), and according to the global unique naming rule, the global unique name comprises 4 parts of contents, wherein the first part of contents is a package name com.sample, the second part of contents is a class name class1, the third part of contents is a function name func1, and the fourth part of contents is a function parameter type name (int ). The globally unique naming convention for functions of a non-object-oriented language may contain three parts of content, including: file path, file name, and function name. The key information reading unit 1003 may read the key information of each function according to at least one function obtained by the parsing.
In the embodiment of the invention, the source code of the service can be subjected to instrumentation processing according to the key information of at least one function contained in the source code of the service to obtain the target code, the function call information in the running process of the target code is acquired, and the coverage parameter of the service is calculated based on the function call information, so that the coverage parameter of the service can be accurate to the function in the source code without being limited by the change of a code line, the calculation precision of the coverage parameter of the service is improved, and the accuracy of judging the integrity of the service is improved.
Fig. 6 is a schematic structural diagram of an insertion processing unit according to an embodiment of the present invention; the staking processing unit 102 may include: an stub code insertion unit 2001 and a target code determination unit 2002.
An stub code inserting unit 2001, configured to insert a stub code at a start position of each function according to a globally unique name of each function in the at least one function.
A globally unique name may be used to uniquely identify a function; the stub code inserting unit 2001 may insert one stub code at the start position of each function according to the globally unique name of each function in the at least one function, that is, one function corresponds to one stub code. The specific form of the stub code may be determined according to actual conditions, for example: stub code may be log (funcname), the specific form of which may be the same as the specific form of the source code, and so on.
An object code determination unit 2002 for determining the source code containing the stub code as an object code.
And inserting stub codes into the source codes, and obtaining running information such as control flow, data flow and the like of the source codes in the running process through the execution of the stub codes. The object code determination unit 2002 refers to the source code after the instrumentation processing is completed as an object code.
In the embodiment of the invention, the source code of the service can be subjected to instrumentation processing according to the key information of at least one function contained in the source code of the service to obtain the target code, the function call information in the running process of the target code is acquired, and the coverage parameter of the service is calculated based on the function call information, so that the coverage parameter of the service can be accurate to the function in the source code without being limited by the change of a code line, the calculation precision of the coverage parameter of the service is improved, and the accuracy of judging the integrity of the service is improved.
Fig. 7 is a schematic structural diagram of an acquisition unit according to an embodiment of the present invention; the acquisition unit 104 may include: an output unit 3001 and a calling function set generation unit 3002.
An output unit 3001, configured to output, during the running process of the object code, a globally unique name of an object function called by the object code.
The target code is a source code with stub code, each time the target code calls a function in the running process, the stub code at the starting position of the function is executed to output the calling information of the function, and the output unit 3001 may output the globally unique name of each target function called by the target code.
A calling function set generating unit 3002, configured to generate a calling function set according to the globally unique name of the target function.
According to the globally unique name of each target function, a calling function set can be generated, for example: assuming that globally unique names a1, a2, and a3 are output in common, the called function set generating unit 3002 may generate a called function set a, which includes a1, a2, and a3, indicating that the target function called by the target code includes a function identified by a1, a function identified by a2, and a function identified by a 3.
In the embodiment of the invention, the source code of the service can be subjected to instrumentation processing according to the key information of at least one function contained in the source code of the service to obtain the target code, the function call information in the running process of the target code is acquired, and the coverage parameter of the service is calculated based on the function call information, so that the coverage parameter of the service can be accurate to the function in the source code without being limited by the change of a code line, the calculation precision of the coverage parameter of the service is improved, and the accuracy of judging the integrity of the service is improved.
Please refer to fig. 8, which is a schematic structural diagram of a computing unit 105 according to an embodiment of the present invention; the calculation unit 105 may include: an original function set generating unit 4001 and a coverage ratio calculating unit 4002.
A primitive function set generating unit 4004, configured to generate a primitive function set according to the globally unique name of the at least one function included in the source code.
According to the globally unique name of each function contained in the source code, a primitive function set can be generated, for example: assuming that the source code includes four functions with globally unique names a1, a2, a3, and B1, the primitive function set generating unit 4004 may generate a primitive function set B, where the called function set B includes a1, a2, a3, and B1, which indicates that the functions included in the source code include a function identified by a1, a function identified by a2, a function identified by a3, and a function identified by B1.
And a coverage rate calculation unit 4002, configured to calculate a function coverage rate of the service according to the calling function set and the primitive function set by using a preset coverage rate calculation rule.
The coverage parameter is an important index for measuring the integrity of the internet service, and the coverage parameter of the service is represented by adopting a code coverage rate in the prior art; the embodiment of the invention can adopt the function coverage rate to represent the coverage parameter of the service.
Please refer to fig. 9, which is a schematic structural diagram of the coverage calculating unit shown in fig. 8; the coverage ratio calculation unit 4002 includes: an intersection solving unit 5001, a percentage calculating unit 5002 and a coverage calculating unit 5003.
An intersection calculating unit 5001 configured to calculate an intersection between the call function set and the primitive function set.
According to the example in the embodiment shown in fig. 8, assuming that the set of calling functions is a and the set of original functions is B, the intersection solving unit 5001 needs to solve the intersections a & B between the set of calling functions a and the set of original functions B, where, & represents the intersection solving operation.
A percentage calculation unit 5002 for calculating a function percentage of the intersection with respect to the primitive function set.
According to the example shown in this embodiment, the percentage calculation unit 5002 may calculate the function percentage of the intersection a & B with respect to the primitive function set B as ((a & B)/B) × 100%.
A coverage determining unit 5003, configured to determine the calculated function percentage as a function coverage of the service. The coverage determination unit 5003 may determine the functional coverage of the traffic as ((a & B)/B) × 100%.
In the embodiment of the invention, the source code of the service can be subjected to instrumentation processing according to the key information of at least one function contained in the source code of the service to obtain the target code, the function call information in the running process of the target code is acquired, and the coverage parameter of the service is calculated based on the function call information, so that the coverage parameter of the service can be accurate to the function in the source code without being limited by the change of a code line, the calculation precision of the coverage parameter of the service is improved, and the accuracy of judging the integrity of the service is improved.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The above disclosure is only for the purpose of illustrating the preferred embodiments of the present invention, and it is therefore to be understood that the invention is not limited by the scope of the appended claims.

Claims (11)

1. A method for processing a service, comprising:
acquiring a source code of a service to be processed;
performing static analysis on the source code to obtain at least one function contained in the source code; the static resolution includes at least one of: lexical analysis, grammatical analysis, lexical analysis and grammatical analysis;
reading key information of the at least one function, wherein the key information of one function comprises: a globally unique name of the function and a starting position of the function; the globally unique name of the function is a unique name which is obtained by naming the function by adopting a globally unique naming rule and can be used for identifying the function; the global unique name of the language-oriented function comprises a package name, a class name, a function name and a function parameter type name; the globally unique names of the non-language-oriented functions include file paths, file names, and function names;
inserting pile codes into the initial positions of the functions respectively according to the globally unique names of the functions in the at least one function;
determining a source code containing the stub code as a target code;
running the target code and collecting function calling information of the target code in the running process, wherein each time the target code calls a target function in the running process, the stub code at the starting position of the called target function is executed to output the function calling information of the called target function; the function calling information comprises a globally unique name of a called target function;
calculating the coverage parameters of the service according to the function calling information, wherein the coverage parameters of the service comprise function coverage, the function coverage refers to the intersection between a calling function set and a primary function set and is a function percentage relative to the primary function set, and the calling function set is formed by each target function called by the target code in the running process; the set of primitive functions is formed by the functions included in the source code.
2. The method of claim 1, wherein the start location of the function comprises a start code row and a start code column of the function.
3. The method of claim 1 or 2, wherein the collecting function call information of the object code in the running process comprises:
outputting a global unique name of a target function called by the target code in the running process of the target code;
and generating a calling function set according to the global unique name of the target function.
4. The method of claim 3, wherein said calculating the coverage parameter of the service based on the function call information comprises:
generating a primitive function set according to the global unique name of at least one function contained in the source code;
and calculating the function coverage rate of the service by adopting a preset coverage rate calculation rule according to the calling function set and the primitive function set.
5. The method of claim 4, wherein the calculating the function coverage of the service according to the set of calling functions and the set of primitive functions by using a preset coverage calculation rule comprises:
obtaining the intersection of the calling function set and the original function set;
calculating a function percentage of the intersection relative to the set of primitive functions;
and determining the calculated function percentage as the function coverage rate of the service.
6. A traffic processing apparatus, comprising:
the analysis unit is used for analyzing a source code of a service to be processed to obtain key information of at least one function contained in the source code;
the instrumentation processing unit is used for performing instrumentation processing on the source code according to the key information of the at least one function to obtain a target code;
an execution unit configured to execute the object code;
the acquisition unit is used for acquiring function calling information of the target code in the running process; the calculation unit is configured to calculate a coverage parameter of the service according to the function call information, where the coverage parameter of the service includes a function coverage rate, and the function coverage rate refers to an intersection between a call function set and a primitive function set and is a percentage of functions of the primitive function set relative to the primitive function set, where the call function set is formed by target functions called by the target code in an operation process; the primitive function set is composed of functions contained in the source code;
the analysis unit includes:
the source code acquisition unit is used for acquiring a source code of a service to be processed;
the static analysis unit is used for carrying out static analysis on the source code to obtain at least one function contained in the source code; the static resolution includes at least one of: lexical analysis, grammatical analysis, lexical analysis and grammatical analysis;
a key information reading unit, configured to read key information of the at least one function, where the key information of one function includes: a globally unique name of the function and a starting position of the function; the globally unique name of the function is a unique name which is obtained by naming the function by adopting a globally unique naming rule and can be used for identifying the function; the globally unique name of the function of the oriented language comprises a package name, a class name, a function name and a function parameter type name; globally unique names for non-language-oriented functions include file path, file name, and function name;
the stake processing unit includes:
the stub code inserting unit is used for respectively inserting stub codes into the initial positions of the functions according to the globally unique names of the functions in the at least one function;
a target code determination unit for determining a source code containing the stub code as a target code;
when the target code calls a target function in the running process, executing the stub code at the starting position of the called target function to output the function calling information of the called target function; the function call information includes a globally unique name of the called target function.
7. The apparatus of claim 6, wherein the start location of the function comprises a start code row and a start code column of the function.
8. The apparatus of claim 6 or 7, wherein the acquisition unit comprises:
the output unit is used for outputting the global unique name of the target function called by the target code in the running process of the target code;
and the calling function set generating unit is used for generating a calling function set according to the global unique name of the target function.
9. The apparatus of claim 8, wherein the computing unit comprises:
a primitive function set generating unit, configured to generate a primitive function set according to a globally unique name of at least one function included in the source code;
and the coverage rate calculation unit is used for calculating the function coverage rate of the service by adopting a preset coverage rate calculation rule according to the calling function set and the primitive function set.
10. The apparatus of claim 9, wherein the coverage calculation unit comprises:
the intersection set solving unit is used for solving the intersection set of the calling function set and the original function set;
a percentage calculation unit for calculating a function percentage of the intersection set with respect to the primitive function set;
and the coverage rate determining unit is used for determining the calculated function percentage as the function coverage rate of the service.
11. A computer-readable storage medium, in which a computer program is stored, which program, when executed, comprises a service processing method according to any one of claims 1 to 5.
CN201510180527.1A 2015-04-16 2015-04-16 Service processing method and device Active CN106155897B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510180527.1A CN106155897B (en) 2015-04-16 2015-04-16 Service processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510180527.1A CN106155897B (en) 2015-04-16 2015-04-16 Service processing method and device

Publications (2)

Publication Number Publication Date
CN106155897A CN106155897A (en) 2016-11-23
CN106155897B true CN106155897B (en) 2020-12-08

Family

ID=58058698

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510180527.1A Active CN106155897B (en) 2015-04-16 2015-04-16 Service processing method and device

Country Status (1)

Country Link
CN (1) CN106155897B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108073513A (en) * 2017-04-21 2018-05-25 富士通株式会社 The apparatus and method tested the intelligent contract based on block chain
CN110196801B (en) * 2018-02-24 2022-11-11 武汉斗鱼网络科技有限公司 Code coverage rate based test method and device
CN109325900A (en) * 2018-09-19 2019-02-12 北京润科通用技术有限公司 A kind of dispositions method and system of algorithm
CN110705715B (en) * 2019-09-27 2023-04-18 北京迈格威科技有限公司 Hyper-parameter management method and device and electronic equipment
CN114416029A (en) * 2021-12-24 2022-04-29 北京百度网讯科技有限公司 Data processing method, device, equipment, storage medium and computer program product
CN116991751B (en) * 2023-09-28 2023-12-22 英诺达(成都)电子科技有限公司 Code testing method and device, electronic equipment and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102346710A (en) * 2011-10-13 2012-02-08 北京航空航天大学 Dynamic stubbing technology based time-delay analysis method for data packet processing
CN103473171A (en) * 2013-08-28 2013-12-25 北京信息科技大学 Coverage rate dynamic tracking method and device based on function call paths
CN103617120A (en) * 2013-12-05 2014-03-05 北京奇虎科技有限公司 Unit testing method and device
CN103699476A (en) * 2012-09-27 2014-04-02 腾讯科技(深圳)有限公司 Coverage rate testing method and system
CN104199773A (en) * 2014-09-03 2014-12-10 腾讯科技(深圳)有限公司 Method and device for obtaining code coverage information
CN104317723A (en) * 2014-11-14 2015-01-28 清华大学 Method and system for tracking running information of drive program

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5748878A (en) * 1995-09-11 1998-05-05 Applied Microsystems, Inc. Method and apparatus for analyzing software executed in embedded systems
CN101464829B (en) * 2007-12-18 2010-09-15 珠海金山软件有限公司 Method and test device for confirming code coverage rate
CN101561777A (en) * 2008-04-14 2009-10-21 中兴通讯股份有限公司 System and method for realizing coverage rate test
CN101833500A (en) * 2010-04-07 2010-09-15 南京航空航天大学 Embedded software intelligent testing method based on Agent
JP5767471B2 (en) * 2010-12-24 2015-08-19 インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation Apparatus and method for evaluating test completeness
CN102419728B (en) * 2011-11-01 2014-10-29 北京邮电大学 Method for determining software test process sufficiency based on coverage rate quantitative indicators

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102346710A (en) * 2011-10-13 2012-02-08 北京航空航天大学 Dynamic stubbing technology based time-delay analysis method for data packet processing
CN103699476A (en) * 2012-09-27 2014-04-02 腾讯科技(深圳)有限公司 Coverage rate testing method and system
CN103473171A (en) * 2013-08-28 2013-12-25 北京信息科技大学 Coverage rate dynamic tracking method and device based on function call paths
CN103617120A (en) * 2013-12-05 2014-03-05 北京奇虎科技有限公司 Unit testing method and device
CN104199773A (en) * 2014-09-03 2014-12-10 腾讯科技(深圳)有限公司 Method and device for obtaining code coverage information
CN104317723A (en) * 2014-11-14 2015-01-28 清华大学 Method and system for tracking running information of drive program

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
一种基于Selenium的Web自动化测试低耦合框架;边耐政等;《计算机应用与软件 软件技术与研究》;20141009;全文 *
基于http服务器的嵌入式软件自动化测试框架的设计与实现;韦涛;《中国优秀硕士学位论文全文数据库 信息科技辑》;20150215;第I138-235页 *

Also Published As

Publication number Publication date
CN106155897A (en) 2016-11-23

Similar Documents

Publication Publication Date Title
CN106155897B (en) Service processing method and device
CN101261604B (en) Software quality evaluation apparatus and software quality evaluation quantitative analysis method
CN111104335B (en) C language defect detection method and device based on multi-level analysis
CN109446066B (en) Static detection method and system for inaccessible codes in C/C + + program
JP2008191963A (en) Source code verification system, source code verification method and source code verification program
KR101979329B1 (en) Method and apparatus for tracking security vulnerable input data of executable binaries thereof
CN107066302B (en) Defect inspection method, device and service terminal
CN108399321B (en) Software local plagiarism detection method based on dynamic instruction dependence graph birthmark
CN109634822B (en) Function time consumption statistical method and device, storage medium and terminal equipment
CN102521135B (en) The method of testing of linear system and device
CN101551773B (en) Binary vulnerability detection location device for symbol error and assignment truncation
CN111382052A (en) Code quality evaluation method and device and electronic equipment
CN115576831A (en) Test case recommendation method, device, equipment and storage medium
CN113127367B (en) Defect detection method for Android dynamic permission application
CN115421831A (en) Method, device, equipment and storage medium for generating calling relation of activity component
JP2014228889A (en) Performance information collection program, information processing device, and performance information collection method
CN111338956A (en) Automatic pressure measurement method, device, equipment and storage medium
CN113806231A (en) Code coverage rate analysis method, device, equipment and medium
CN113282504A (en) Incremental code coverage rate detection method and service development method and device
CN107368742B (en) Fine-grained virtual function table hijacking attack defense method based on GCC
CN110888811A (en) Code coverage rate information processing method and device, electronic equipment and medium
KR101674787B1 (en) System and method for measuring performance of program
CN111078574A (en) Method and device for generating influence analysis report
CN112099838B (en) Method, device and storage medium for determining version difference
CN112527672B (en) Detection method and equipment for shell adding tool

Legal Events

Date Code Title Description
C06 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