CN114115884A - Management method and related device for programming service - Google Patents

Management method and related device for programming service Download PDF

Info

Publication number
CN114115884A
CN114115884A CN202010871294.0A CN202010871294A CN114115884A CN 114115884 A CN114115884 A CN 114115884A CN 202010871294 A CN202010871294 A CN 202010871294A CN 114115884 A CN114115884 A CN 114115884A
Authority
CN
China
Prior art keywords
function
task
target
test
programming
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.)
Pending
Application number
CN202010871294.0A
Other languages
Chinese (zh)
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 CN202010871294.0A priority Critical patent/CN114115884A/en
Publication of CN114115884A publication Critical patent/CN114115884A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Library & Information Science (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application discloses a management method of programming service and a related device. Obtaining a corresponding source code in the execution process of the programming service; then analyzing the source code to convert the source code into a structured file; a hook function is injected into a function statement corresponding to the structured file to obtain a target executable file; and then carrying out interaction of the target task based on the target executable file, wherein the interaction process of the target task is associated with the hook function. The method and the device have the advantages that the target task execution process in the programming service operation process is realized, the hook function is adopted to compile the executable file indicating the source code, the target task can be conveniently set, the operation of the programming service is not influenced, and therefore the execution efficiency of the test task in the programming service is improved.

Description

Management method and related device for programming service
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and a related apparatus for managing a programming service.
Background
Cloud computing (cloud computing) is a computing model that distributes computing tasks over a pool of resources formed by a large number of computers, enabling various application systems to obtain computing power, storage space, and information services as needed. The network that provides the resources is referred to as the "cloud". Resources in the "cloud" appear to the user as being infinitely expandable and available at any time, available on demand, expandable at any time, and paid for on-demand.
As cloud computing evolves, more and more projects are developed using the Go programming language. In the function-level exception test, a tester needs to tamper the parameters of the function, throw the function incorrectly or delay execution of the function and other exception operations to verify the robustness of the service.
However, in the function modification process of the static programming language, function insertion cannot be realized during running, and it is not easy to perform compiling instruction insertion on the compiled machine code to further realize function insertion, which affects the efficiency of the exception test.
Disclosure of Invention
In view of this, the present application provides a method for managing a programming service, which can effectively improve the efficiency of an abnormal test in the programming service.
A first aspect of the present application provides a method for managing a programming service, which may be applied to a system or a program that includes a management function of the programming service in a terminal device, and specifically includes:
acquiring a corresponding source code in a programming service execution process;
analyzing the source code to convert the source code into a structured file;
injecting a hook function into the function statement corresponding to the structured file to obtain a target executable file;
and performing interaction of a target task based on the target executable file, wherein an interaction process of the target task is associated with the hook function.
Optionally, in some possible implementation manners of the present application, the injecting a hook function into a function statement corresponding to the structured file to obtain a target executable file includes:
determining the function statement corresponding to the structured file;
converting the structured file into an anonymous function based on the function declaration;
and injecting the hook function into the anonymous function through the function declaration to obtain the target executable file.
Optionally, in some possible implementations of the present application, injecting the hook function into the anonymous function through the function declaration to obtain the target executable file includes:
determining an injection node corresponding to the function statement;
and injecting the hook function into the anonymous function through the injection node to obtain the target executable file.
Optionally, in some possible implementations of the present application, injecting, by the injection node, the hook function into the anonymous function to obtain the target executable file includes:
injecting the hook function into the anonymous function through the injection node to obtain an intermediate code;
converting the intermediate code into machine code;
and compiling based on the machine code to obtain the target executable file.
Optionally, in some possible implementations of the present application, injecting, by the injection node, the hook function into the anonymous function to obtain an intermediate code, includes:
determining an enhancement code corresponding to the hook function;
injecting the enhancement code into the anonymous function through the injection node to obtain a conversion code;
determining a node operator corresponding to the conversion code;
transcoding based on the node operators to obtain the intermediate code.
Optionally, in some possible implementation manners of the present application, the performing interaction of the target task based on the target executable file includes:
determining function call information output by the target executable file in the running process;
interacting with a cache database based on the function call information;
determining the target task in response to a task instruction in the cache database;
and configuring the function call information based on the target task so as to test the programming service.
Optionally, in some possible implementations of the present application, the determining the target task in response to the task instruction in the cache database includes:
determining a function tag in response to the task instruction in the cache database;
determining a task function based on the function label to generate the target task.
Optionally, in some possible implementation manners of the present application, the configuring the function call information based on the target task to test the programming service includes:
determining configuration information based on the task function corresponding to the target task, wherein the configuration information comprises caller information and callee information;
and configuring the function calling information according to the configuration information so as to test the programming service.
Optionally, in some possible implementation manners of the present application, the configuring the function call information based on the target task to test the programming service includes:
configuring the function call information based on the target task to determine a test function;
determining corresponding method parameters in the test function;
determining an execution rule based on the method parameter to test the programming service.
Optionally, in some possible implementations of the present application, the method further includes:
responding to a test instruction to determine test parameters, wherein the test parameters comprise the type, the occurrence opportunity or the occurrence probability of a test case;
updating the method parameters based on the test parameters.
Optionally, in some possible implementation manners of the present application, the target task is an abnormal test task, and the method further includes:
determining an exception handling capability value of the programming service based on the test information of the exception test task;
and determining the processing authority of the programming service according to the comparison relationship between the abnormal processing capacity value and a preset value, wherein the processing authority is used for indicating the payment operation in a financial scene.
Optionally, in some possible implementation manners of the present application, the programming service is obtained by editing based on a static programming language, the structured file is set based on an abstract syntax tree, and the target task is an exception testing task.
A second aspect of the present application provides a management apparatus for a programming service, including: the system comprises an acquisition unit, a processing unit and a control unit, wherein the acquisition unit is used for acquiring a corresponding source code in the execution process of the programming service;
the analysis unit is used for analyzing the source code so as to convert the source code into a structured file;
the injection unit is used for injecting a hook function into the function statement corresponding to the structured file so as to obtain a target executable file;
and the management unit is used for carrying out interaction of a target task based on the target executable file, and the interaction process of the target task is associated with the hook function.
Optionally, in some possible implementations of the present application, the injection unit is specifically configured to determine the function declaration corresponding to the structured file;
the injection unit is specifically configured to convert the structured file into an anonymous function based on the function declaration;
the injection unit is specifically configured to inject the hook function into the anonymous function through the function declaration to obtain the target executable file.
Optionally, in some possible implementation manners of the present application, the injection unit is specifically configured to determine an injection node corresponding to the function statement;
the injection unit is specifically configured to inject the hook function into the anonymous function through the injection node to obtain the target executable file.
Optionally, in some possible implementations of the present application, the injecting unit is specifically configured to inject the hook function into the anonymous function through the injecting node to obtain an intermediate code;
the injection unit is specifically configured to convert the intermediate code into a machine code;
the injection unit is specifically configured to compile based on the machine code to obtain the target executable file.
Optionally, in some possible implementations of the present application, the injection unit is specifically configured to determine an enhancement code corresponding to the hook function;
the injection unit is specifically configured to inject the enhancement code into the anonymous function through the injection node to obtain a conversion code;
the injection unit is specifically configured to determine a node operator corresponding to the translation code;
the injection unit is specifically configured to perform transcoding based on the node operator to obtain the intermediate code.
Optionally, in some possible implementation manners of the present application, the management unit is specifically configured to determine function call information output by the target executable file in an operation process;
the management unit is specifically used for interacting with a cache database based on the function calling information;
the management unit is specifically configured to determine the target task in response to a task instruction in the cache database;
the management unit is specifically configured to configure the function call information based on the target task, so as to test the programming service.
Optionally, in some possible implementations of the present application, the management unit is specifically configured to determine a function tag in response to the task instruction in the cache database;
the management unit is specifically configured to determine a task function based on the function tag to generate the target task.
Optionally, in some possible implementation manners of the present application, the management unit is specifically configured to determine configuration information based on the task function corresponding to the target task, where the configuration information includes caller information and callee information;
the management unit is specifically configured to configure the function call information according to the configuration information, so as to test the programming service.
Optionally, in some possible implementation manners of the present application, the management unit is specifically configured to configure the function call information based on the target task to determine a test function;
the management unit is specifically configured to determine a corresponding method parameter in the test function;
the management unit is specifically configured to determine an execution rule based on the method parameter, so as to test the programming service.
Optionally, in some possible implementation manners of the present application, the management unit is specifically configured to determine a test parameter in response to the test instruction, where the test parameter includes a type, an occurrence opportunity, or an occurrence probability of a test case;
the management unit is specifically configured to update the method parameter based on the test parameter.
Optionally, in some possible implementation manners of the present application, the target task is an abnormal test task, and the management unit is specifically configured to determine an abnormal handling capability value of the programming service based on test information of the abnormal test task;
the management unit is specifically configured to determine a processing authority of the programming service according to a comparison relationship between the abnormal handling capability value and a preset value, where the processing authority is used to indicate a payment operation in a financial scenario.
A third aspect of the present application provides a computer device comprising: a memory, a processor, and a bus system; the memory is used for storing program codes; the processor is configured to execute the method for managing a programming service according to any one of the first aspect or the first aspect, according to instructions in the program code.
A fourth aspect of the present application provides a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to execute the method for managing a programming service of any one of the first aspect or the first aspect described above.
According to an aspect of the application, a computer program product or computer program is provided, comprising computer instructions, the computer instructions being stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to cause the computer device to perform the method for managing a programming service provided in the first aspect or the various alternative implementations of the first aspect.
According to the technical scheme, the embodiment of the application has the following advantages:
obtaining a corresponding source code in the execution process of the programming service; then analyzing the source code to convert the source code into a structured file; a hook function is injected into a function statement corresponding to the structured file to obtain a target executable file; and then carrying out interaction of the target task based on the target executable file, wherein the interaction process of the target task is associated with the hook function. The method and the device have the advantages that the target task execution process in the programming service operation process is realized, the hook function is adopted to compile the executable file indicating the source code, the target task can be conveniently set, the operation of the programming service is not influenced, and therefore the execution efficiency of the test task in the programming service is improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, it is obvious that the drawings in the following description are only embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a diagram of a network architecture for managing system operation of programming services;
FIG. 2 is a flowchart of the management of a programming service provided by an embodiment of the present application;
FIG. 3 is a flowchart of a method for managing programming services according to an embodiment of the present disclosure;
fig. 4 is a flowchart illustrating a method for managing a programming service according to an embodiment of the present disclosure;
fig. 5 is a schematic view of a scenario of a management method for programming services according to an embodiment of the present application;
FIG. 6 is a flowchart illustrating another method for managing programming services according to an embodiment of the present disclosure;
fig. 7 is a schematic view of a scenario of another management method for programming services according to an embodiment of the present application;
FIG. 8 is a flowchart illustrating another method for managing programming services according to an embodiment of the present disclosure;
FIG. 9 is a flowchart illustrating another method for managing programming services according to an embodiment of the present disclosure;
fig. 10 is a schematic structural diagram of a management apparatus for programming services according to an embodiment of the present application;
fig. 11 is a schematic structural diagram of a server according to an embodiment of the present application.
Detailed Description
The embodiment of the application provides a management method and a related device of programming services, which can be applied to a system or a program containing a management function of the programming services in terminal equipment, and can acquire corresponding source codes in the execution process of the programming services; then analyzing the source code to convert the source code into a structured file; a hook function is injected into a function statement corresponding to the structured file to obtain a target executable file; and then carrying out interaction of the target task based on the target executable file, wherein the interaction process of the target task is associated with the hook function. The method and the device have the advantages that the target task execution process in the programming service operation process is realized, the hook function is adopted to compile the executable file indicating the source code, the target task can be conveniently set, the operation of the programming service is not influenced, and therefore the execution efficiency of the test task in the programming service is improved.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims of the present application and in the drawings described above, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the application described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "corresponding" and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
First, some nouns that may appear in the embodiments of the present application are explained.
Go programming language: also known as Golang, is a static strongly typed, compiled language. Go language grammar is similar to C language, but has the characteristics of memory security, garbage recovery, structural form and concurrent computation.
The function declares: the system is used for informing the compiling system of the name, the function type, the shape parameter type, the number and the sequence of the function so that the system performs comparison check according to the rule when the function is called; such as whether the function name is correct, and whether the actual parameters are consistent with the type and number of the form parameters.
Abstract Syntax Tree (AST): the syntax structure of the programming language is represented in the form of a tree.
Hook function (hook): before the system does not call the primitive function, the hook function can obtain the control right first, process or change the behavior of the primitive function, and can also end the transmission of the message forcibly.
It should be understood that the management method for the programming service provided by the present application may be applied to a system or a program including a management function of the programming service in a terminal device, for example, programming software, specifically, the management system for the programming service may run in a network architecture as shown in fig. 1, which is a network architecture diagram of the management system for the programming service, as can be seen from the diagram, the management system for the programming service may provide a management process for the programming service with multiple information sources, that is, each terminal may execute a corresponding programming service process, and when an exception handling capability test is required, an executable file encapsulating hook is sent to a server for testing, so as to determine an exception handling capability; it is understood that, fig. 1 shows various terminal devices, in an actual scenario, there may be more or fewer types of terminal devices participating in the process of managing the programming service, and the specific number and types depend on the actual scenario, which is not limited herein, and in addition, fig. 1 shows one server, but in an actual scenario, there may also be participation of multiple servers, especially in a scenario of multi-model training interaction, the specific number of servers depends on the actual scenario.
In this embodiment, the server may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a network service, cloud communication, a middleware service, a domain name service, a security service, a CDN, a big data and artificial intelligence platform, and the like. The terminal may be, but is not limited to, a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, and the like. The terminal and the server may be directly or indirectly connected through wired or wireless communication, and the application is not limited herein.
It will be appreciated that the management system of the programming service described above may be run on a personal mobile terminal, for example: the application, such as programming software, can be run on a server, and can also be run on a third-party device to provide management of the programming service so as to obtain a management processing result of the programming service of the information source; the specific management system of the programming service may be run in the device in the form of a program, may also be run as a system component in the device, and may also be used as one of the cloud service programs, and a specific operation mode is determined according to an actual scene, which is not limited herein.
Cloud computing (cloud computing) is a computing model that distributes computing tasks over a pool of resources formed by a large number of computers, enabling various application systems to obtain computing power, storage space, and information services as needed. The network that provides the resources is referred to as the "cloud". Resources in the "cloud" appear to the user as being infinitely expandable and available at any time, available on demand, expandable at any time, and paid for on-demand.
As a basic capability provider of cloud computing, a cloud computing resource pool (called as IaaS (Infrastructure as a Service) platform for short is established, and multiple types of virtual resources are deployed in the resource pool and are selected by external clients for use.
According to the logic function division, a PaaS (Platform as a Service) layer can be deployed on an IaaS (Infrastructure as a Service) layer, a SaaS (Software as a Service) layer is deployed on the PaaS layer, and the SaaS can be directly deployed on the IaaS. PaaS is a platform on which software runs, such as a database, a web container, etc. SaaS is a variety of business software, such as web portal, sms, and mass texting. Generally speaking, SaaS and PaaS are upper layers relative to IaaS.
As cloud computing evolves, more and more projects are developed using the Go programming language. In the function-level exception test, a tester needs to tamper the parameters of the function, throw the function incorrectly or delay execution of the function and other exception operations to verify the robustness of the service.
However, in the function modification process of the static programming language, function insertion cannot be realized during running, and it is not easy to perform compiling instruction insertion on the compiled machine code to further realize function insertion, which affects the efficiency of the exception test.
In order to solve the above problem, the present application provides a method for managing a programming service, which is applied to a flow framework of management of the programming service shown in fig. 2, and as shown in fig. 2, the method is a flow framework of management of the programming service provided in an embodiment of the present application, that is, a Go native tool AST library is used to implement full scan on a Go service source code and structure the source code AST, and then a hook is injected into a function body under the AST structure and can interact with an external cache database, so that a process of implementing function test in a running state is achieved by setting the external cache database.
It can be understood that the method provided by the present application may be a program written as a processing logic in a hardware system, or may be a management device of a programming service, and the processing logic is implemented in an integrated or external manner. As one implementation manner, the management device of the programming service acquires a corresponding source code in the execution process of the programming service; then analyzing the source code to convert the source code into a structured file; a hook function is injected into a function statement corresponding to the structured file to obtain a target executable file; and then carrying out interaction of the target task based on the target executable file, wherein the interaction process of the target task is associated with the hook function. The method and the device have the advantages that the target task execution process in the programming service operation process is realized, the hook function is adopted to compile the executable file indicating the source code, the target task can be conveniently set, the operation of the programming service is not influenced, and therefore the execution efficiency of the test task in the programming service is improved.
With reference to the above flow architecture, a management method for a programming service in the present application will be introduced below, please refer to fig. 3, fig. 3 is a flow chart of a management method for a programming service provided in an embodiment of the present application, where the management method may be executed by a terminal device, or by a server, or by both the terminal device and the server, and the following description will be given by taking the terminal device as an example. The embodiment of the application at least comprises the following steps:
301. and acquiring a corresponding source code in the programming service execution process.
In this embodiment, the programming language corresponding to the programming service is a static programming language, such as Go language; this is because, in performing the function-level exception test, a tester needs to tamper with the parameters of the function, throw the function out incorrectly, or delay execution of the function, to verify the robustness of the service. The Go language is a static programming language, different from a Java programming language, and has no virtual machine, so that the function capability enhancement cannot be realized during running, and the compiled machine code is not easy to be subjected to compiling instruction enhancement so as to realize function capability enhancement. To realize the function capability enhancement in the runtime stage, the Go language native standard tool does not provide a corresponding tool to meet the requirement of the exception test.
It can be understood that the present application is also applicable to other static programming languages in the process of testing the abnormal capability, the specific language form depends on the actual scenario, and the present application takes Go language as an example for description.
302. The source code is parsed to convert the source code into a structured file.
In this embodiment, the process of analyzing the source code may be to perform full scanning on the source code of the Go programming services, and convert the file included in each Go programming service into a structured file, for example, perform AST structuring, and other specific structuring functions are also applicable to this embodiment, which is not limited herein.
In a possible scenario, the AST structuring process is shown in fig. 4, where fig. 4 is a flowchart illustrating a method for managing a programming service according to an embodiment of the present application; the form of the source code is shown, as well as the tree diagram after AST structural conversion.
303. And injecting a hook function into the function statement corresponding to the structured file to obtain the target executable file.
In this embodiment, the hook function (hook) is injected into the structured file, so that the function information corresponding to the program service running process can be obtained in the program service running process, specifically, the hook function may be a full function, or a specific part, and is not limited herein.
Specifically, the process of obtaining the target executable file can convert the source function body of all functions into an internal anonymous function as it is based on the AST structure, and the specific conversion relates to the processing operation of function declaration. Firstly, determining a function statement corresponding to a structured file; then converting the structured file into an anonymous function based on the function declaration; and then, a hook function is injected into the anonymous function through the function declaration to obtain a target executable file, so that the code logic of the source code is not changed after the source code is injected into the hook.
It can be understood that, for the injection of the hook function, it may be performed based on the injection node, specifically, the injection node corresponding to the function declaration is determined first; and then injecting a hook function into the anonymous function through the injection node to obtain the target executable file. In a possible scenario, referring to fig. 5, fig. 5 is a schematic flowchart of another management method for programming services provided in an embodiment of the present application; the source code structure a1, the position a2 of the function declaration, the injection node A3, and the code portion a4 after the hook function is injected are shown in the figure, wherein the position a2 of the function declaration indicates the position corresponding to the feature field of the function declaration in the source code, namely (, ast.funcdel); the injection node a3 indicates an operation node specifically corresponding to the hook function, for example, the stmt method shown in the figure, that is, the stmt method is called for each node in the incoming source code, in this method, the compiler converts the current AST into a corresponding intermediate code according to the difference of the node operators, and the analysis degree of the source code can be improved and the analysis accuracy can be improved due to the generation of the intermediate code.
Specifically, for the utilization of the intermediate code, a hook function may be first injected into an anonymous function through an injection node to obtain the intermediate code; then converting the intermediate code into a machine code; and thus compiled based on machine code to obtain the target executable file.
Because the function of the source code is expanded due to the injection of hook, the expanded content can also be called as an enhanced code, and for the determination process of the intermediate code, the enhanced code corresponding to the hook function can also be determined firstly; then, injecting an enhanced code into the anonymous function through the injection node to obtain a conversion code; further determining a node operational character corresponding to the conversion code; therefore, the code conversion is carried out based on the node operational characters to obtain the intermediate code, and because the intermediate code is a representation form which is closer to a machine language, the optimization and analysis of the intermediate code are easier than the direct analysis of a high-level programming language, and the efficiency of the original code conversion is improved.
In a possible scenario, reference may be made to fig. 6 for a process of generating the target executable file, where fig. 6 is a flowchart illustrating another management method for a programming service provided by an embodiment of the present application; firstly, carrying out code analysis on Go source codes and further carrying out structural conversion; thereby converting the original function body into an anonymous function based on the function statement in the structured file, and injecting a hook function to update the function body; in order to facilitate the device to identify the updated function body, an intermediate code may be further generated, and a corresponding machine code may be generated.
Correspondingly, the coding conversion process can be obtained by compiling Go programming service through a full-function hook compiling tool; for example, the Go built-astrenthhance xxx _ project instruction is executed by a full-function hook compiling tool, and the full-function hook compiling tool injects hook enhanced codes on the basis of source codes in the compiling process and compiles an executable file. Then, performing AST structure organization on the compiled AST structure at a function declaration position (asst. funcdcl) by using a Go standard tool AST library, and implementing full-function hook method injection, where injection results are shown in fig. 7, and fig. 7 is a scene schematic diagram of a management method for programming services provided by the embodiment of the present application; the injection result is shown in (1) in fig. 7 and (2) in fig. 7 of the source code, and it can be seen that the hook-based injection part B1 in the injection result contains the execution logic B3 of the source code, and the execution logic B3 is the same as the code B2 in the source code, so that it is explained that the code logic of the primitive function is guaranteed not to change because the primitive function is repeatedly mounted in the internal anonymous function in the full-function hook method.
It can be understood that, because the function statement of the source code is modified based on the AST structure of the Go native tool AST library to realize the Go service source code, the source code is not directly modified, and the source code is guaranteed not to be modified by the hook method, but the generated executable file contains hook injection enhancement code.
304. And performing interaction of the target task based on the target executable file.
In this embodiment, the interaction process of the target task is associated with the hook function, that is, the full function in the running process of the programming service is obtained through the hook function, and then the full function is processed based on the target task, and the related test information is obtained. Specifically, the test information may include a test of the abnormal behavior handling capability, for example, a response condition of the test programming service to the operations of delaying, skipping, repeating, throwing mistakes and tampering.
In one possible scenario, the hook injected enhancement code, i.e., the target executable file; interaction is carried out with the cache database, abnormal behaviors of corresponding functions can be set directly according to specific function tags in the running stage, wherein the specific cache database is located outside the programming service, namely, the cache database can be located in another device or a virtual machine of the same device, and the specific location is determined by an actual scene.
Specifically, an interaction process with the cache database is shown in fig. 8, and fig. 8 is a schematic flow chart of another management method for programming services provided in the embodiment of the present application; firstly, determining function calling information output by a target executable file in the running process; then interacting with a cache database based on the function calling information; further responding to the task instruction in the cache database to determine a target task; and configuring the function call information based on the target task to test the programming service.
Alternatively, the process of determining the target task may be set based on a function tag, that is, the function tag is determined in response to a task instruction in the cache database; a task function is then determined based on the function label to generate a target task. Specifically, an executable file with a full function hook is deployed to a test environment, and cache database information is set; and the function tag is called by a tester or control equipment through setting a configuration instruction, so that the cache database is interacted with the Go programming service in the running period in real time, and corresponding abnormal behaviors are set.
In the process of testing and setting abnormal behaviors, function calling information can be configured on the basis of a target task to determine a test function; then determining corresponding method parameters in the test function; and determining an execution rule based on the method parameter to test the programming service. The execution rule may be an execution order, for example, because the method body of the primitive function testHook is moved to the innerFunc0 internal anonymous function, before declaring the internal anonymous function, the method parameters and the return result may be packed into a structure respectively, so as to be conveniently and uniformly transferred to the full function hook injection object. After the hook injection object is created, the pre-method, the primitive function executing method and the post-method are executed in sequence, and parameters are returned according to the primitive function rule, so that the testing process is realized.
Optionally, the setting of the abnormal behavior may further include setting of configuration information and execution information; determining caller information and callee information for the configuration information, namely based on a task function corresponding to the target task; and configuring the function call information according to the configuration information so as to test the programming service. The code form of the configuration information may include call _ func _ name: calling a name of a function; and (3) called _ func _ name: the name of the called party function.
For the configuration of the execution information, the test parameters can be determined in response to the test instruction, and the test parameters comprise the type, the occurrence opportunity or the occurrence probability of the test case; the method parameters are then updated based on the test parameters. For example, for a full function hook injection object, function call information is output during the operation period, and the interaction process is performed with a cache database; and when the user configures the cache database according to the abnormal effective rule, the real-time abnormal behavior execution can be started. The rule corresponding to the abnormal behavior may include:
call_func_name:called_func_name#inject_name.params1.params2…
wherein, call _ func _ name: calling a name of a function;
and (3) called _ func _ name: a called party function name;
inject _ name: the name of the abnormal injection can be set to delay, skip, repeat, throw wrong panic, tamper and the like;
params 1/2: setting parameters of abnormal injection, including occurrence probability, occurrence opportunity, occurrence parameters and the like;
the method comprises the following steps of (1) representing that a main function calls a main, testhook # delay, before-injection delay abnormal behaviors are carried out, such as main, testhook # delay, before-injection delay abnormal behaviors;
main, testhook # delay, probability of occurrence of delay abnormal behavior;
main, testhook # delay, mean, which represents the average sleep opportunity for delayed abnormal behavior.
Therefore, the setting of abnormal behaviors with different dimensions is realized, and the comprehensiveness of the detection of the abnormal capacity of the programming service is ensured.
With the above embodiments, it can be known that the corresponding source code in the program service execution process is obtained; then analyzing the source code to convert the source code into a structured file; a hook function is injected into a function statement corresponding to the structured file to obtain a target executable file; and then carrying out interaction of the target task based on the target executable file, wherein the interaction process of the target task is associated with the hook function. The method and the device have the advantages that the target task execution process in the programming service operation process is realized, the hook function is adopted to compile the executable file indicating the source code, the target task can be conveniently set, the operation of the programming service is not influenced, and therefore the execution efficiency of the test task in the programming service is improved.
The foregoing embodiment describes a process of determining the abnormal behavior handling capability, and a scenario corresponding to the abnormal behavior handling capability will be described below. Referring to fig. 9, fig. 9 is a flowchart of another management method for programming services according to an embodiment of the present application, where the embodiment of the present application at least includes the following steps:
901. and inputting the target executable file into a cache database.
In this embodiment, the generation process of the target executable file refers to step 301 and step 303 in the embodiment shown in fig. 3, which are not described herein again.
902. An exception task is set in response to the target operation.
In this embodiment, the target operation may be set by a relevant person, or may be an operation automatically generated by the cache database, for example, an abnormal task in a history is used as an abnormal task of a current test, and a specific manner is determined according to an actual scene.
903. And determining an abnormal capacity processing value according to the execution condition of the abnormal task.
In this embodiment, the determination of the abnormal capability handling value is positively correlated with the execution condition of the abnormal task, that is, the more the number of the executed abnormal tasks is, the higher the corresponding abnormal capability handling value is; the specific calculation method of the abnormal capability processing value may also perform weighting calculation based on different abnormal tasks, for example, the higher the abnormal occurrence frequency is, the higher the weight corresponding to the task is, and the specific calculation method is determined by the actual scene.
904. An execution permission is assigned to the programming service based on the exception capability handling value.
In the embodiment, the robustness of the programming service is verified by the size of the abnormal capability processing value, and high-risk service business can be allocated to the programming service with higher robustness.
In one possible scenario, the processing authority of the programming service may be determined according to a comparison of the exception handling capability value with a preset value, the processing authority being used to indicate payment operations in a financial scenario. For example, if the abnormal handling capability value reaches the preset value 80, the payment-related operation can be processed, thereby ensuring the safety of the payment process.
In order to better implement the above-mentioned aspects of the embodiments of the present application, the following also provides related apparatuses for implementing the above-mentioned aspects. Referring to fig. 10, fig. 10 is a schematic structural diagram of a management device for programming services according to an embodiment of the present application, where the management device 1000 for programming services includes:
an obtaining unit 1001, configured to obtain a source code corresponding to a programming service in an execution process;
the parsing unit 1002 is configured to parse the source code to convert the source code into a structured file;
an injecting unit 1003, configured to inject a hook function into a function declaration corresponding to the structured file to obtain a target executable file;
a management unit 1004, configured to perform interaction of a target task based on the target executable file, where an interaction process of the target task is associated with the hook function.
Optionally, in some possible implementation manners of the present application, the injecting unit 1003 is specifically configured to determine the function declaration corresponding to the structured file;
the injecting unit 1003 is specifically configured to convert the structured file into an anonymous function based on the function declaration;
the injecting unit 1003 is specifically configured to inject the hook function into the anonymous function through the function declaration to obtain the target executable file.
Optionally, in some possible implementation manners of the present application, the injection unit 1003 is specifically configured to determine an injection node corresponding to the function statement;
the injecting unit 1003 is specifically configured to inject the hook function into the anonymous function through the injecting node, so as to obtain the target executable file.
Optionally, in some possible implementations of the present application, the injecting unit 1003 is specifically configured to inject the hook function into the anonymous function through the injecting node to obtain an intermediate code;
the injection unit 1003 is specifically configured to convert the intermediate code into a machine code;
the injection unit 1003 is specifically configured to perform compilation based on the machine code to obtain the target executable file.
Optionally, in some possible implementations of the present application, the injection unit 1003 is specifically configured to determine an enhancement code corresponding to the hook function;
the injecting unit 1003 is specifically configured to inject the enhancement code into the anonymous function through the injecting node to obtain a conversion code;
the injection unit 1003 is specifically configured to determine a node operator corresponding to the conversion code;
the injection unit 1003 is specifically configured to perform code conversion based on the node operator to obtain the intermediate code.
Optionally, in some possible implementations of the present application, the management unit 1004 is specifically configured to determine function call information output by the target executable file in a running process;
the management unit 1004 is specifically configured to interact with a cache database based on the function call information;
the management unit 1004 is specifically configured to determine the target task in response to a task instruction in the cache database;
the management unit 1004 is specifically configured to configure the function call information based on the target task, so as to test the programming service.
Optionally, in some possible implementations of the present application, the management unit 1004 is specifically configured to determine a function tag in response to the task instruction in the cache database;
the management unit 1004 is specifically configured to determine a task function based on the function tag to generate the target task.
Optionally, in some possible implementation manners of the present application, the management unit 1004 is specifically configured to determine configuration information based on the task function corresponding to the target task, where the configuration information includes caller information and callee information;
the management unit 1004 is specifically configured to configure the function call information according to the configuration information, so as to test the programming service.
Optionally, in some possible implementation manners of the present application, the management unit 1004 is specifically configured to configure the function call information based on the target task to determine a test function;
the management unit 1004 is specifically configured to determine corresponding method parameters in the test function;
the management unit 1004 is specifically configured to determine an execution rule based on the method parameter, so as to test the programming service.
Optionally, in some possible implementation manners of the present application, the management unit 1004 is specifically configured to determine a test parameter in response to a test instruction, where the test parameter includes a type, an occurrence opportunity, or an occurrence probability of a test case;
the management unit 1004 is specifically configured to update the method parameter based on the test parameter.
Optionally, in some possible implementation manners of the present application, the target task is an exception test task, and the management unit 1004 is specifically configured to determine an exception handling capability value of the programming service based on test information of the exception test task;
the management unit 1004 is specifically configured to determine a processing authority of the programming service according to a comparison relationship between the exception handling capability value and a preset value, where the processing authority is used to indicate a payment operation in a financial scenario.
Obtaining a corresponding source code in the execution process of the programming service; then analyzing the source code to convert the source code into a structured file; a hook function is injected into a function statement corresponding to the structured file to obtain a target executable file; and then carrying out interaction of the target task based on the target executable file, wherein the interaction process of the target task is associated with the hook function. The method and the device have the advantages that the target task execution process in the programming service operation process is realized, the hook function is adopted to compile the executable file indicating the source code, the target task can be conveniently set, the operation of the programming service is not influenced, and therefore the execution efficiency of the test task in the programming service is improved.
Referring to fig. 11, fig. 11 is a schematic structural diagram of a server provided in the embodiment of the present application, where the server 1100 may generate large differences due to different configurations or performances, and may include one or more Central Processing Units (CPUs) 1122 (e.g., one or more processors) and a memory 1132, and one or more storage media 1130 (e.g., one or more mass storage devices) storing an application program 1142 or data 1144. Memory 1132 and storage media 1130 may be, among other things, transient storage or persistent storage. The program stored on the storage medium 1130 may include one or more modules (not shown), each of which may include a series of instruction operations for the server. Still further, the central processor 1122 may be provided in communication with the storage medium 1130 to execute a series of instruction operations in the storage medium 1130 on the server 1100.
The server 1100 may also include one or more power supplies 1126, one or more wired or wireless network interfaces 1150, one or more input-output interfaces 1158, and/or one or more operating systems 1141, such as Windows Server, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, and so forth.
The steps performed by the management apparatus in the above-described embodiment may be based on the server configuration shown in fig. 11.
Also provided in the embodiments of the present application is a computer-readable storage medium, which stores therein management instructions of a programming service, and when the management instructions are executed on a computer, the computer is enabled to execute the steps executed by a management apparatus of the programming service in the method described in the foregoing embodiments shown in fig. 2 to 9.
Also provided in an embodiment of the present application is a computer program product including instructions for programming a service, which when run on a computer, causes the computer to perform the steps performed by the management apparatus for programming the service in the method as described in the embodiments of fig. 2 to 9.
The embodiment of the present application further provides a management system of a programming service, and the management system of the programming service may include a management apparatus of the programming service in the embodiment described in fig. 10, or a server described in fig. 11.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a management device of a programming service, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a read-only memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

Claims (15)

1. A method for managing programming services, comprising:
acquiring a corresponding source code in a programming service execution process;
analyzing the source code to convert the source code into a structured file;
injecting a hook function into the function statement corresponding to the structured file to obtain a target executable file;
and performing interaction of a target task based on the target executable file, wherein an interaction process of the target task is associated with the hook function.
2. The method of claim 1, wherein the injecting a hook function into the function declaration corresponding to the structured file to obtain the target executable file comprises:
determining the function statement corresponding to the structured file;
converting the structured file into an anonymous function based on the function declaration;
and injecting the hook function into the anonymous function through the function declaration to obtain the target executable file.
3. The method of claim 2, wherein injecting the hook function into the anonymous function through the function declaration to obtain the target executable file comprises:
determining an injection node corresponding to the function statement;
and injecting the hook function into the anonymous function through the injection node to obtain the target executable file.
4. The method of claim 3, wherein injecting, by the injection node, the hook function into the anonymous function to obtain the target executable file comprises:
injecting the hook function into the anonymous function through the injection node to obtain an intermediate code;
converting the intermediate code into machine code;
and compiling based on the machine code to obtain the target executable file.
5. The method of claim 4, wherein injecting, by the injection node, the hook function into the anonymous function to obtain an intermediary code comprises:
determining an enhancement code corresponding to the hook function;
injecting the enhancement code into the anonymous function through the injection node to obtain a conversion code;
determining a node operator corresponding to the conversion code;
transcoding based on the node operators to obtain the intermediate code.
6. The method of claim 1, wherein the interacting of the target task based on the target executable file comprises:
determining function call information output by the target executable file in the running process;
interacting with a cache database based on the function call information;
determining the target task in response to a task instruction in the cache database;
and configuring the function call information based on the target task so as to test the programming service.
7. The method of claim 6, wherein determining the target task in response to a task instruction in the cache database comprises:
determining a function tag in response to the task instruction in the cache database;
determining a task function based on the function label to generate the target task.
8. The method of claim 6, wherein the configuring the function call information based on the target task to test the programming service comprises:
determining configuration information based on the task function corresponding to the target task, wherein the configuration information comprises caller information and callee information;
and configuring the function calling information according to the configuration information so as to test the programming service.
9. The method of claim 6, wherein the configuring the function call information based on the target task to test the programming service comprises:
configuring the function call information based on the target task to determine a test function;
determining corresponding method parameters in the test function;
determining an execution rule based on the method parameter to test the programming service.
10. The method of claim 9, further comprising:
responding to a test instruction to determine test parameters, wherein the test parameters comprise the type, the occurrence opportunity or the occurrence probability of a test case;
updating the method parameters based on the test parameters.
11. The method of any one of claims 1-10, wherein the target task is an exception testing task, the method further comprising:
determining an exception handling capability value of the programming service based on the test information of the exception test task;
and determining the processing authority of the programming service according to the comparison relationship between the abnormal processing capacity value and a preset value, wherein the processing authority is used for indicating the payment operation in a financial scene.
12. The method of claim 1, wherein the programming service is compiled based on a static programming language, the structured document is set based on an abstract syntax tree, and the target task is an exception testing task.
13. A management device for programming services, comprising:
the system comprises an acquisition unit, a processing unit and a control unit, wherein the acquisition unit is used for acquiring a corresponding source code in the execution process of the programming service;
the analysis unit is used for analyzing the source code so as to convert the source code into a structured file;
the injection unit is used for injecting a hook function into the function statement corresponding to the structured file so as to obtain a target executable file;
and the management unit is used for carrying out interaction of a target task based on the target executable file, and the interaction process of the target task is associated with the hook function.
14. A computer device, the computer device comprising a processor and a memory:
the memory is used for storing program codes; the processor is configured to execute the method of managing a programming service of any one of claims 1 to 12 in accordance with instructions in the program code.
15. A computer-readable storage medium having stored therein instructions which, when run on a computer, cause the computer to execute the method of managing programming services of any of the above claims 1 to 12.
CN202010871294.0A 2020-08-26 2020-08-26 Management method and related device for programming service Pending CN114115884A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010871294.0A CN114115884A (en) 2020-08-26 2020-08-26 Management method and related device for programming service

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010871294.0A CN114115884A (en) 2020-08-26 2020-08-26 Management method and related device for programming service

Publications (1)

Publication Number Publication Date
CN114115884A true CN114115884A (en) 2022-03-01

Family

ID=80374372

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010871294.0A Pending CN114115884A (en) 2020-08-26 2020-08-26 Management method and related device for programming service

Country Status (1)

Country Link
CN (1) CN114115884A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115599645A (en) * 2022-10-13 2023-01-13 安芯网盾(北京)科技有限公司(Cn) Method and device for testing stability of linux drive module
CN116775040A (en) * 2023-08-16 2023-09-19 北京安普诺信息技术有限公司 Pile inserting method for realizing code vaccine and application testing method based on code vaccine

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115599645A (en) * 2022-10-13 2023-01-13 安芯网盾(北京)科技有限公司(Cn) Method and device for testing stability of linux drive module
CN115599645B (en) * 2022-10-13 2023-05-02 安芯网盾(北京)科技有限公司 Method and device for testing stability of linux driving module
CN116775040A (en) * 2023-08-16 2023-09-19 北京安普诺信息技术有限公司 Pile inserting method for realizing code vaccine and application testing method based on code vaccine
CN116775040B (en) * 2023-08-16 2023-11-17 北京安普诺信息技术有限公司 Pile inserting method for realizing code vaccine and application testing method based on code vaccine

Similar Documents

Publication Publication Date Title
US8347272B2 (en) Call graph dependency extraction by static source code analysis
CN101930400B (en) SDK (Software Development Kit) automatic test system and method
CN110442327B (en) Application program construction method, device and server
CN110673837B (en) Code repairing method and device, electronic equipment and computer readable storage medium
CN114115884A (en) Management method and related device for programming service
CN108304164B (en) Business logic development method and development system
CN110018831B (en) Program processing method, program processing apparatus, and computer-readable storage medium
CN111913741A (en) Object interception method, device, medium and electronic equipment
CN111414154A (en) Method and device for front-end development, electronic equipment and storage medium
US11429358B2 (en) Representing asynchronous state machine in intermediate code
CN115291933A (en) Method, device and equipment for constructing small program data packet and storage medium
US11435989B2 (en) Thread-local return structure for asynchronous state machine
CN114881235A (en) Inference service calling method and device, electronic equipment and storage medium
CN113885844A (en) Business service arranging method and related device
CN113703734A (en) Applet generation method and device, electronic equipment and storage medium
CN113032256A (en) Automatic test method, device, computer system and readable storage medium
CN109308256B (en) Dynamic analysis method, equipment and storage medium for java program
CN112612474A (en) Product transplanting method and device, storage medium and electronic equipment
CN114356745A (en) Software testing method and device, electronic equipment and computer readable storage medium
CN107451050B (en) Function acquisition method and device and server
CN113778564B (en) Method, equipment and storage medium for efficiently executing EVM intelligent contract
CN113031960B (en) Code compiling method, device, server and storage medium
CN117093286B (en) Plug-in generation method, device, equipment and computer readable storage medium
CN113590166B (en) Application program updating method and device and computer readable storage medium
CN113342633B (en) Performance test method and device

Legal Events

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