Unit testing method, device, computing equipment and medium

By generating test modules in the user space of the Linux operating system and running identity management unit test cases, the problem of inefficient unit testing in the prior art is solved, and efficient management and operation of single or multiple unit test cases is achieved.

CN114691496BActive Publication Date: 2024-12-24ALIBABA (CHINA) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210206441.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-02
Publication Date
2024-12-24
Estimated Expiration
2042-03-02

AI Technical Summary

Technical Problem

During the unit testing of Linux operating systems, the existing technology requires rewriting the kernel module to run a certain unit test case separately, resulting in low testing efficiency.

Method used

After loading test code in the kernel space of the operating system, a test module is generated in the user space. By running the execution of the identification of the snap-in unit test case, it allows or prohibits it from running in the kernel space, obtains the run log and results, and realizes the single or multiple Run individually for each unit test case.

Benefits of technology

Improves the efficiency of unit testing, avoids the steps of rewriting kernel modules, and enhances the flexibility and management capabilities of testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114691496B_ABST
    Figure CN114691496B_ABST
Patent Text Reader

Abstract

One or more embodiments of the present specification provide a unit testing method, apparatus, computing device and medium to provide a more fine-grained unit test case management framework. When the test code in the kernel space of the operating system is loaded, at least one test module is generated for the test code in the user space of the operating system, and each test module is used to manage at least one unit test case respectively. Each unit test case is provided with a corresponding running identifier, so that based on the running identifier corresponding to each unit test case, the test code corresponding to the unit test case whose running identifier meets the target condition can be executed in the kernel space to obtain the running log and running result of the executed test code, thereby realizing the separate running of one or several unit test cases without rewriting the kernel module containing only this unit test case, thereby improving the efficiency of the unit testing process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the field of computer technology, and more particularly, to a unit testing method, apparatus, computing device, and medium. Background Art

[0002] In computer programming, unit testing refers to the testing work of checking the correctness of program units (the smallest unit of software design). Through unit testing, program components can be isolated to prove that each program component is correct, so as to achieve the purpose of discovering software problems in the early stage of software development process.

[0003] In the unit testing process of the Linux operating system, knuit is mainly used as the kernel code unit testing framework to write unit test cases in the kernel module, so that after the kernel module is loaded into the kernel space, the Linux kernel will run each unit test case in the kernel module to determine the correctness of each program component.

[0004] However, in knuit, unit test cases are stored in the kernel module in the form of functions. After loading the kernel module, the Linux kernel will run all the functions included in the kernel module at one time. If the user only wants to run a certain unit test case separately, the kernel module containing only a single unit test case must be rewritten, and then the kernel module containing only a single unit test case must be run again to realize the separate running of a certain unit test case, which leads to low efficiency of the unit testing process. Summary of the invention

[0005] In view of this, one or more embodiments of the present specification provide a unit testing method, apparatus, computing device, and medium.

[0006] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:

[0007] According to a first aspect of one or more embodiments of this specification, a unit testing method is provided, the method comprising:

[0008] When the test code in the kernel space of the operating system is loaded, at least one test module is generated for the test code in the user space of the operating system, each test module is used to manage at least one unit test case, each unit test case is provided with a corresponding run identifier, and the run identifier is used to indicate whether the test code corresponding to the unit test case is allowed to be executed;

[0009] Based on the running identifiers corresponding to the unit test cases, the test codes corresponding to the unit test cases whose running identifiers meet the target conditions are executed in the kernel space;

[0010] Get the running log and running results of the executed test code.

[0011] In some embodiments, the run flag includes a first run flag and a second run flag, the first run flag indicates that the test code corresponding to the unit test case is allowed to be executed, and the second run flag indicates that the test code corresponding to the unit test case is prohibited from being executed;

[0012] Based on the running identifiers corresponding to the unit test cases, the test code corresponding to the unit test cases whose running identifiers meet the target conditions is executed in the kernel space, including any of the following:

[0013] For any unit test case, when the running identifier of the unit test case is the first running identifier, the unit test case is executed in the kernel space;

[0014] When the running identifier of the unit test case is the second running identifier, it is not necessary to execute the unit test case in the kernel space.

[0015] In some embodiments, based on the running identifiers corresponding to the unit test cases, executing the test code corresponding to the unit test cases whose running identifiers meet the target conditions in the kernel space includes:

[0016] When a unit test instruction is received, based on the running identifiers corresponding to the respective unit test cases, the test code corresponding to the unit test cases whose running identifiers meet the target conditions is executed in the kernel space.

[0017] In some embodiments, executing the test code corresponding to the unit test case whose running identification satisfies the target condition in the kernel space includes:

[0018] Create a corresponding thread in the kernel space for each unit test case whose running identifier meets the target condition;

[0019] The test code corresponding to the unit test case whose running identifier meets the target condition is executed in the kernel space through the created thread.

[0020] In some embodiments, the test code further includes a log acquisition function and a result acquisition function;

[0021] Get the running log and running results of the executed test code, including:

[0022] The running log of the test code is obtained through the log acquisition function, and the running result of the test code is obtained through the result acquisition function.

[0023] In some embodiments, each test module includes at least one running file corresponding to a unit test case, and the running file is used to store a running identifier.

[0024] In some embodiments, each test module also includes a log file and a result file corresponding to at least one unit test case;

[0025] After obtaining the running log and running result of the executed test code, the method further includes at least one of the following:

[0026] Store the running log in the log file corresponding to the test code;

[0027] Store the running results in the result file corresponding to the test code.

[0028] In some embodiments, for any test module, the test module includes at least one unit test case, or the test module includes at least one sub-module, and at least one sub-module includes at least one unit test case.

[0029] According to a second aspect of one or more embodiments of this specification, a unit testing device is provided, the device comprising:

[0030] A generating unit, configured to generate at least one test module for the test code in the user space of the operating system when the test code in the kernel space of the operating system is loaded, each test module being configured to manage at least one unit test case, each unit test case being configured with a corresponding running identifier, the running identifier being configured to indicate whether the test code corresponding to the unit test case is allowed to be executed;

[0031] An execution unit, for executing, in kernel space, test codes corresponding to unit test cases whose running identifiers satisfy target conditions, based on the running identifiers corresponding to the unit test cases;

[0032] Get the unit to get the running log and running results of the executed test code.

[0033] In some embodiments, the run flag includes a first run flag and a second run flag, the first run flag indicates that the test code corresponding to the unit test case is allowed to be executed, and the second run flag indicates that the test code corresponding to the unit test case is prohibited from being executed;

[0034] The execution unit, when executing the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space based on the running identifier corresponding to each unit test case, is used for any of the following:

[0035] For any unit test case, when the running identifier of the unit test case is the first running identifier, the unit test case is executed in the kernel space;

[0036] When the running identifier of the unit test case is the second running identifier, it is not necessary to execute the unit test case in the kernel space.

[0037] In some embodiments, the execution unit, when used to execute the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space based on the running identifier corresponding to each unit test case, is used to:

[0038] When a unit test instruction is received, based on the running identifiers corresponding to the respective unit test cases, the test code corresponding to the unit test cases whose running identifiers meet the target conditions is executed in the kernel space.

[0039] In some embodiments, the execution unit, when used to execute the test code corresponding to the unit test case whose running identifier satisfies the target condition in the kernel space, is used to:

[0040] Create a corresponding thread in the kernel space for each unit test case whose running identifier meets the target condition;

[0041] The test code corresponding to the unit test case whose running identifier meets the target condition is executed in the kernel space through the created thread.

[0042] In some embodiments, the test code includes a log acquisition function and a result acquisition function;

[0043] The acquisition unit, when used to obtain the running log and running results of the executed test code, is used to:

[0044] The running log of the test code is obtained through the log acquisition function, and the running result of the test code is obtained through the result acquisition function.

[0045] In some embodiments, each test module includes at least one running file corresponding to a unit test case, and the running file is used to store a running identifier.

[0046] In some embodiments, each test module also includes a log file and a result file corresponding to at least one unit test case;

[0047] The device also includes:

[0048] A storage unit for at least one of the following:

[0049] Store the running log in the log file corresponding to the test code;

[0050] Store the running results in the result file corresponding to the test code.

[0051] In some embodiments, for any test module, the test module includes at least one unit test case, or the test module includes at least one sub-module, and at least one sub-module includes at least one unit test case.

[0052] According to a third aspect of one or more embodiments of this specification, a computing device is provided, the computing device comprising:

[0053] processor;

[0054] a memory for storing processor-executable instructions;

[0055] The processor implements the operations performed by the unit testing method provided in the first aspect and any embodiment of the first aspect by running executable instructions.

[0056] According to a fourth aspect of one or more embodiments of this specification, a computer-readable storage medium is proposed, on which computer instructions are stored. When the instructions are executed by a processor, the operations performed by the unit testing method provided in the above-mentioned first aspect and any embodiment of the first aspect are implemented.

[0057] According to the fifth aspect of one or more embodiments of this specification, a computer program product is proposed, including a computer program, which, when executed by a processor, implements the operations performed by the unit testing method provided in the above-mentioned first aspect and any embodiment of the first aspect.

[0058] The present application provides a more fine-grained unit test case management framework. When the test code in the kernel space of the operating system is loaded, at least one test module is generated for the test code in the user space of the operating system, and each test module is used to manage at least one unit test case respectively. Each unit test case is provided with a corresponding running identifier, so that based on the running identifier corresponding to each unit test case, the test code corresponding to the unit test case whose running identifier meets the target condition can be executed in the kernel space to obtain the running log and running result of the executed test code, so as to realize the separate running of one or several unit test cases without rewriting the kernel module containing only this unit test case, thereby improving the efficiency of the unit testing process. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Figure 1 It is a flowchart of a unit testing method provided by an exemplary embodiment.

[0060] Figure 2 It is a schematic diagram of a management framework of a unit test case provided by an exemplary embodiment.

[0061] Figure 3This is a schematic diagram of the interaction process between a user space and a kernel space provided by an exemplary embodiment.

[0062] Figure 4 It is a functional schematic diagram of an interface module provided by an exemplary embodiment.

[0063] Figure 5 It is an overall architecture diagram of a unit testing method provided by an exemplary embodiment.

[0064] Figure 6 It is a block diagram of a unit testing device provided by an exemplary embodiment.

[0065] Figure 7 It is a schematic structural diagram of a computing device provided by an exemplary embodiment. DETAILED DESCRIPTION

[0066] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.

[0067] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0068] The present application provides a unit testing method for checking the correctness of a program module to be run in the kernel space of a Linux operating system, thereby discovering problems existing in program codes in the early stages of a software development process.

[0069] The above-mentioned unit testing method can be executed by a computing device equipped with a Linux operating system. The computing device can be a server, such as one server, multiple servers, a server cluster, a cloud computing platform, etc. Optionally, the computing device can also be a terminal device, such as a desktop computer, a portable computer, a PDA, a tablet computer, etc. This application does not limit the device type and number of computing devices.

[0070] The above is an introduction to the application environment of the present application. The following is an explanation of the implementation process of the unit testing method provided by the present application.

[0071] See also Figure 1 , Figure 1 is a flowchart of a unit testing method provided by an exemplary embodiment, the method comprising:

[0072] Step 101. When the test code in the kernel space of the operating system is loaded, at least one test module is generated for the test code in the user space of the operating system. Each test module is used to manage at least one unit test case. Each unit test case is provided with a corresponding run identifier, and the run identifier is used to indicate whether the test code corresponding to the unit test case is allowed to be executed.

[0073] Step 102: Based on the running identifiers corresponding to the unit test cases, the test codes corresponding to the unit test cases whose running identifiers meet the target conditions are executed in the kernel space.

[0074] Step 103: Obtain the running log and running results of the executed test code.

[0075] The present application provides a more fine-grained unit test case management framework. When the test code in the kernel space of the operating system is loaded, at least one test module is generated for the test code in the user space of the operating system, and each test module is used to manage at least one unit test case respectively. Each unit test case is provided with a corresponding running identifier, so that based on the running identifier corresponding to each unit test case, the test code corresponding to the unit test case whose running identifier meets the target condition can be executed in the kernel space to obtain the running log and running result of the executed test code, so as to realize the separate running of one or several unit test cases without rewriting the kernel module containing only this unit test case, thereby improving the efficiency of the unit testing process.

[0076] After introducing the basic implementation process of the present application, the unit testing method provided by the present application is further explained below in combination with multiple optional embodiments of the present application.

[0077] In some embodiments, when the test code in the kernel space of the operating system is loaded, the computing device can automatically generate at least one test module for the test code in the user space of the operating system.

[0078] In a possible implementation, the kernel space may include an interface module, and the connection between the kernel space and the user space can be realized through the interface module of the kernel space. The interface module may include a register component, so that for step 101, when the test code in the kernel space of the operating system is loaded, when at least one test module is generated for the test code in the user space of the operating system, the register component can be used to generate at least one test module in the user space based on the test code in the kernel space according to a pre-set framework structure, so as to realize the management of unit test cases through the at least one test module.

[0079] The more fine-grained unit test case management framework (denoted as Munit, or asynchronous kernel unit test framework) provided by the present application can be applied to a virtual file system (Debugs) for kernel debugging, and is used to directly or indirectly manage unit test cases through test modules. For example, for any test module, the test module may include at least one unit test case, or the test module may include at least one submodule, and the at least one submodule may include at least one unit test case.

[0080] That is, for generating at least one test module in the user space, the at least one test module can directly include at least one unit test case, or the at least one test module can include at least one sub-module, and the at least one sub-module includes at least one unit test case, or a part of the at least one test module directly includes at least one unit test case, and another part of the test module includes at least one sub-module, and the at least one sub-module includes at least one unit test case, so that the management of at least one unit test case by at least one test module can be realized through at least one of the above three methods.

[0081] For example, see Figure 2 , Figure 2 is a schematic diagram of a management framework of a unit test case provided by an exemplary embodiment, such as Figure 2As shown, the asynchronous kernel unit test framework may include three test modules, denoted as test module 201 (Module201), test module 202 (Module202) and test module 203 (Module203), and the structures included in test module 201, test module 202 and test module 203 are different. Among them, test module 201 includes submodule 210 (Submod210), submodule 210 includes submodule 220 (Submod220), and submodule 220 includes unit test case 231 (Case231) and unit test case 232 (Case232), so that test module 201 can manage submodule 220 through submodule 210, and submodule 210 can manage unit test case 231 and unit test case 232 through submodule 220, so that test module 201 can manage unit test case 231 and unit test case 232; test module 202 may include submodule 2 11 (Submod211) and submodule 212 (Submod212), submodule 211 includes unit test case 233 (Case233), and submodule 212 includes unit test case 234 (Case234), so that test module 202 can manage unit test case 233 through submodule 211 and manage unit test case 234 through submodule 212; and test module 203 directly includes unit test case 235 (Case235) and unit test case 236 (Case236), so that test module 203 can directly manage unit test case 235 and unit test case 236.

[0082] Above Figure 2 The figure is only an exemplary unit test case management framework, which schematically shows three possible management methods of unit test cases, that is, the test module can directly include unit test cases, or the test module can include a layer of sub-modules, so that the management of unit test cases is achieved through this layer of sub-modules, or the test module can include multiple layers of sub-modules, so that the management of unit test cases is achieved through these multiple layers of sub-modules. Optionally, only the unit test cases can be managed by using Figure 2 One or two of the management methods are used to build a management framework for unit test cases.

[0083] It should be noted that, for the above-mentioned unit test case management framework, the number of test modules included in the unit test case management framework, whether the test module includes sub-modules, the number of layers of sub-modules included in the test module when the sub-module is included, and the number of unit test cases included in the sub-modules can all be configured according to actual needs. For example, the unit test case management framework can be configured according to the type of verification function to be implemented by the unit test case (such as functional verification, performance verification, stress testing, specific workload verification, etc.), the hardware structure of the computing device, the software architecture method in the operating system, etc. After the configuration is completed, the generation of at least one test module can be implemented according to the configured architecture method, so that at least one test module can manage at least one unit test case according to the configured architecture method.

[0084] In addition, it should be noted that no matter what method is adopted to implement the management of unit test cases by the test module, it is necessary to ensure that each unit test case is stored in the last layer of the unit test case management framework to ensure that the unit test case management framework can manage each unit test case.

[0085] Through the management framework of the unit test cases shown above, at least one of the above management methods can be used in the test module according to actual use requirements to achieve the management of each unit test case. Moreover, through the test module or multi-level sub-modules, the classification of unit test cases can be more conveniently achieved. For unit test cases belonging to the same category, the same test module or sub-module can be used for management, while unit test cases of different categories can be managed using different test modules or different sub-modules, thereby improving the management efficiency of unit test cases.

[0086] In some embodiments, each unit test case in the test module of the user space may include corresponding files, such as a run (Run) file, a log (Log) file, and a result (Res) file. Optionally, each unit test case may also include other types of files. This application does not limit the specific types of files included in the unit test cases.

[0087] Still Figure 2 The management framework of the unit test case shown in the figure is used as an example to illustrate. Figure 2 In the asynchronous kernel unit test framework shown, Case 231, Case 232, Case 233, Case 234, Case 235 and Case 236 may include their respective corresponding Run files, Log files and Res files.

[0088] Among them, the Run file can be used to store the running identifier of the corresponding unit test case, so as to control the execution of the unit test case through the running identifier, the Log file can be used to store the log generated by the unit test case during the execution process, and the Res file can be used to store the execution results of the unit test case.

[0089] Among them, the run identifier stored in the run file may include a first run identifier and a second run identifier. The first run identifier indicates that the test code corresponding to the unit test case is allowed to be executed, and the second run identifier indicates that the test code corresponding to the unit test case is prohibited from being executed, so that the execution of each unit test case can be controlled by the run identifier.

[0090] In some embodiments, for step 102, based on the run identifiers corresponding to each unit test case, when executing the test code corresponding to the unit test case whose run identifier meets the target condition in the kernel space, the test code corresponding to the unit test case whose run identifier is the first run identifier can be executed.

[0091] That is, for any unit test case, when the running identifier of the unit test case is the first running identifier, the unit test case is executed in the kernel space; and when the running identifier of the unit test case is the second running identifier, there is no need to execute the unit test case in the kernel space.

[0092] Optionally, 1 may be used to represent the first operation identifier, and 0 may be used to represent the second operation identifier. In more possible implementations, the first operation identifier and the second operation identifier may have other forms of expression, which are not limited in the present application.

[0093] In some embodiments, each test module in the user space includes at least one running file corresponding to a unit test case, and the running identifier can be stored in the running file. When executing the test code of any unit test case based on the running identifier, the stored running identifier can be obtained from the running file, so as to determine whether to execute the test code corresponding to the unit test case according to whether the obtained running identifier is the first running identifier or the second running identifier.

[0094] Still like Figure 2 Taking the unit test case management framework shown in the figure as an example, Figure 2In the asynchronous kernel unit test framework shown, if the run identifier stored in the run files of Case231, Case233 and Case234 is the first run identifier (such as 1), the test code corresponding to Case231, Case233 and Case234 can be executed in the kernel space, and if the run identifier stored in the run files of Case232, Case235 and Case236 is the second run identifier (such as 0), there is no need to execute the test code corresponding to Case232, Case235 and Case236.

[0095] In one possible implementation, for step 102, based on the running identifiers corresponding to each unit test case, when executing the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space, the unit test instruction can be triggered by relevant technical personnel so that when the computing device receives the unit test instruction, it can execute the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space based on the running identifiers corresponding to each unit test case.

[0096] By providing a method for controlling the execution timing of unit test cases, relevant technicians can control the execution of unit test cases by triggering unit test instructions according to actual needs, without having to execute unit test cases immediately after the code is loaded into the kernel space, thereby improving the flexibility of the unit testing process.

[0097] In some embodiments, for step 102, executing the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space may include the following steps:

[0098] Step 1021: Create a corresponding thread in the kernel space for each unit test case whose running identifier meets the target condition.

[0099] In one possible implementation, the interface module may include interfaces corresponding to different types of files included in the unit test cases, and each interface also has a corresponding component in the kernel space, so that when implementing the above step 1021, the corresponding interface can be called through the interface in the interface module, thereby creating a corresponding thread for each unit test case in the kernel space.

[0100] When the files corresponding to the unit test case include Run files, Log files and Res files, the interface module may include Run interface, Log interface and Res interface. When executing the test code corresponding to the unit test case whose run identifier meets the target condition, the Run component located in the kernel space can be called through the Run interface, so that a thread is created for each unit test case to be executed through the Run component, so as to execute the test code of the corresponding unit test case through the created threads.

[0101] See also Figure 3 , Figure 3 is a schematic diagram of the interaction process between the user space and the kernel space provided by an exemplary embodiment, such as Figure 3 As shown, the unit test case of the virtual file system for kernel debugging (that is, Debugfs) located in the user space may include Run files, Log files and Res files, and the interface module located in the kernel space may include Run interface, Log interface and Res interface. When creating a thread for the unit test case, the Run interface can be controlled by the Run file, and then the thread creation can be realized through the Run interface.

[0102] It should be noted that the interface module of the kernel space may include a service component, which can receive unit test instructions triggered by relevant technicians through the Service component, and then respond to the unit test instructions, find the test code (that is, the run function) corresponding to the unit test case in the kernel module through the Service component, and then hand over the acquired test code to the Run interface, and create a thread through the Run interface so that the test code can be executed through the Run interface.

[0103] See also Figure 4 , Figure 4 is a functional schematic diagram of an interface module provided by an exemplary embodiment, such as Figure 4 As shown, the interface module can call the Register component to register all unit test cases of the test module included in the user space to the kernel space, and create corresponding directories and files in Debugfs according to the pre-established management framework. After receiving the unit test command through the interface module, the Service component of the interface module can find the unit test case to be executed in the unit test case registered in the kernel space, that is, the function in the kernel module (such as run function 411, run function 412 and run function 413), and then hand over the function in the kernel module to the Run interface in the interface module so that the Run interface creates the corresponding thread to implement the execution of the test code.

[0104] Among them, a running function in the kernel module corresponds to a unit test case, continue to see Figure 4 , Figure 4 The run function 411 corresponds to the unit test case 401 , the run function 412 corresponds to the unit test case 402 , and the run function 413 corresponds to the unit test case 403 .

[0105] Step 1022: Execute the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space through the created thread.

[0106] Through the above process, a corresponding thread can be created for each unit test case to be executed. Through the executed threads, multiple unit test cases can be executed in parallel, thereby realizing asynchronous execution of unit test cases without the need to execute multiple unit test cases to be executed serially in sequence, thereby improving the execution efficiency of unit test cases.

[0107] In some embodiments, during the execution of the unit test case, the running log and the running result of the executed test code can be obtained through step 103.

[0108] In a possible implementation, the test code includes a log acquisition function and a result acquisition function. Based on this, for step 103, when acquiring the running log and running result of the executed test code, it can be implemented in the following manner:

[0109] The running log of the test code is obtained through the log acquisition function, and the running result of the test code is obtained through the result acquisition function.

[0110] In some embodiments, after obtaining the execution log and the execution result of the executed test code, the execution log may be stored in a log file corresponding to the test code, and / or the execution result may be stored in a result file corresponding to the test code.

[0111] In a possible implementation, the operation log may be stored in a log file located in the user space through an interface included in the interface module of the kernel space, and / or the operation result may be stored in a result file located in the user space.

[0112] Still see Figure 3 ,like Figure 3 As shown, the interface module includes a Log interface and a Res interface. After obtaining the running log and running result of the test code, the running log can be stored in the log file of Debugfs located in the user space through the Log interface, and the running result can be stored in the result file of Debugfs located in the user space.

[0113] It should be noted that in the Debugfs of the user space, each unit test case has its own corresponding log file and result file. Therefore, when storing the operation log and operation results, for any unit test case, the operation log corresponding to the unit test case can be stored in the log file of the unit test case, and the operation result corresponding to the unit test case can be stored in the result file of the unit test case.

[0114] Through the above process, not only can the running data (including running logs and running results) of each unit test case be stored separately, so that the running data of different unit test cases can be stored in their respective corresponding positions, but also, when storing the running data of each unit test case, the running log and running result of each unit test case can be stored separately, so that when the running log and running result are to be obtained later, the corresponding content can be obtained from the corresponding file without searching in a large number of files, and without writing complex processing scripts to extract the running log or running result, thereby improving the acquisition efficiency of the running log and running result. In addition, the running log and running result of each unit test case can be managed more conveniently.

[0115] The above embodiments respectively introduce the architecture of the unit testing method provided by the present application in the user space and the kernel space, and the overall architecture of the unit testing method provided by the present application can be seen in Figure 5 , Figure 5 is an overall architecture diagram of a unit testing method provided by an exemplary embodiment, such as Figure 5 As shown, the asynchronous kernel unit test framework provided by the present application includes a user space part and a kernel space part. The user space controls the operation, log and result collection of all unit test cases through Debugfs, and the kernel space is responsible for registering the unit test cases included in the test module of the user space to the kernel module, so as to create a thread to asynchronously run the corresponding unit test case after receiving the unit test instruction from the user space, and write the operation log and operation result to the user space during the operation of the unit test case.

[0116] The above is only a brief introduction to the overall architecture of the present application. For the detailed introduction of each part, please refer to the above embodiments, which will not be repeated here.

[0117] The unit testing method provided in the present application naturally supports the asynchronous execution of each unit test case by taking a single unit test case as the minimum management unit, making the execution of unit test cases more flexible and being able to execute a single unit test case. Moreover, the multi-level management framework provided in the present application can conveniently manage all unit test cases and provide more convenient and complete log and result collection functions.

[0118] Corresponding to the aforementioned method embodiments, this specification also provides embodiments of an apparatus and a computing device used therein.

[0119] See also Figure 6 , Figure 6 1 is a block diagram of a unit testing device provided by an exemplary embodiment, the device comprising:

[0120] A generating unit 601 is used to generate at least one test module for the test code in the user space of the operating system when the test code in the kernel space of the operating system is loaded, each test module is used to manage at least one unit test case, each unit test case is provided with a corresponding running identifier, and the running identifier is used to indicate whether the test code corresponding to the unit test case is allowed to be executed;

[0121] An execution unit 602 is used to execute, in the kernel space, the test code corresponding to the unit test case whose running identifier meets the target condition based on the running identifier corresponding to each unit test case;

[0122] The acquisition unit 603 is used to acquire the running log and running result of the executed test code.

[0123] In some embodiments, the run flag includes a first run flag and a second run flag, the first run flag indicates that the test code corresponding to the unit test case is allowed to be executed, and the second run flag indicates that the test code corresponding to the unit test case is prohibited from being executed;

[0124] The execution unit 602 is used for any of the following when executing the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space based on the running identifier corresponding to each unit test case:

[0125] For any unit test case, when the running identifier of the unit test case is the first running identifier, the unit test case is executed in the kernel space;

[0126] When the running identifier of the unit test case is the second running identifier, it is not necessary to execute the unit test case in the kernel space.

[0127] In some embodiments, the execution unit 602, when used to execute the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space based on the running identifier corresponding to each unit test case, is used to:

[0128] When a unit test instruction is received, based on the running identifiers corresponding to the respective unit test cases, the test code corresponding to the unit test cases whose running identifiers meet the target conditions is executed in the kernel space.

[0129] In some embodiments, the execution unit 602, when used to execute the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space, is used to:

[0130] Create a corresponding thread in the kernel space for each unit test case whose running identifier meets the target condition;

[0131] The test code corresponding to the unit test case whose running identifier meets the target condition is executed in the kernel space through the created thread.

[0132] In some embodiments, the test code includes a log acquisition function and a result acquisition function;

[0133] The acquisition unit 603, when used to acquire the running log and running result of the executed test code, is used to:

[0134] The running log of the test code is obtained through the log acquisition function, and the running result of the test code is obtained through the result acquisition function.

[0135] In some embodiments, each test module includes at least one running file corresponding to a unit test case, and the running file is used to store a running identifier.

[0136] In some embodiments, each test module also includes a log file and a result file corresponding to at least one unit test case;

[0137] The device also includes:

[0138] A storage unit for at least one of the following:

[0139] Store the running log in the log file corresponding to the test code;

[0140] Store the running results in the result file corresponding to the test code.

[0141] In some embodiments, for any test module, the test module includes at least one unit test case, or the test module includes at least one sub-module, and at least one sub-module includes at least one unit test case.

[0142] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.

[0143] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the scheme of this specification. Ordinary technicians in this field can understand and implement it without paying creative work.

[0144] The present application also provides a computing device, see Figure 7 , Figure 7 is a schematic structural diagram of a computing device provided by an exemplary embodiment. Figure 7 At the hardware level, the device includes a processor 702, an internal bus 704, a network interface 706, a memory 708, and a non-volatile memory 710, and may also include hardware required to implement other functions. One or more embodiments of this specification may be implemented based on software, such as the processor 702 reading the corresponding computer program from the non-volatile memory 710 into the memory 708 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0145] The present application also provides a computer program product, including a computer program, which implements the unit testing method provided in any embodiment of the present application when the computer program is executed by a processor.

[0146] The systems, devices or modules described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.

[0147] In a typical configuration, a computer includes one or more processors (Central Processing Unit, CPU), input / output interface, network interface and memory.

[0148] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0149] Computer readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. According to the definition in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0150] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0151] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0152] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0153] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0154] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.

Claims

1. A unit testing method, characterized in that: The method comprises: When the test code in the kernel space of the operating system is loaded, at least one test module is generated for the test code in the user space of the operating system, each test module is used to manage at least one unit test case, each unit test case is provided with a corresponding running identifier, and the running identifier is used to indicate whether the test code corresponding to the unit test case is allowed to be executed; Based on the running identifiers corresponding to the respective unit test cases, the test code corresponding to the unit test cases whose running identifiers satisfy the target conditions is executed in the kernel space; Get the running log and running results of the executed test code; The operation flag includes a first operation flag and a second operation flag, the first operation flag indicates that the test code corresponding to the unit test case is allowed to be executed, and the second operation flag indicates that the test code corresponding to the unit test case is prohibited from being executed; The executing, in the kernel space, the test code corresponding to the unit test case whose running identifier meets the target condition based on the running identifier corresponding to each unit test case includes any of the following: For any unit test case, when the running identifier of the unit test case is the first running identifier, executing the unit test case in the kernel space; When the running identifier of the unit test case is the second running identifier, it is not necessary to execute the unit test case in the kernel space.

2. The method according to claim 1, characterized in that The step of executing the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space based on the running identifier corresponding to each unit test case includes: When a unit test instruction is received, based on the running identifiers corresponding to the respective unit test cases, the test code corresponding to the unit test cases whose running identifiers satisfy the target conditions is executed in the kernel space.

3. The method according to claim 1, characterized in that: The test code corresponding to the unit test case whose running identification satisfies the target condition in the kernel space includes: Creating a corresponding thread in the kernel space for each unit test case whose running identifier meets the target condition; The test code corresponding to the unit test case whose running identifier meets the target condition is executed in the kernel space through the created thread.

4. The method according to claim 1, characterized in that: The test code includes a log acquisition function and a result acquisition function; The obtaining of the running log and running result of the executed test code includes: The running log of the test code is obtained through the log obtaining function, and the running result of the test code is obtained through the result obtaining function.

5. The method according to claim 1, characterized in that Each test module includes at least one running file corresponding to a unit test case, and the running file is used to store the running identifier.

6. The method according to claim 5, characterized in that Each test module also includes a log file and a result file corresponding to at least one unit test case; After obtaining the running log and running result of the executed test code, the method further includes at least one of the following: Storing the operation log in the log file corresponding to the test code; The running result is stored in the result file corresponding to the test code.

7. The method according to claim 1, characterized in that For any test module, the test module includes at least one unit test case, or the test module includes at least one sub-module, and the at least one sub-module includes the at least one unit test case.

8. A unit testing device, characterized in that: The device comprises: A generating unit, configured to generate at least one test module for the test code in the user space of the operating system when the test code in the kernel space of the operating system is loaded, each test module being configured to manage at least one unit test case, each unit test case being configured with a corresponding running identifier, and the running identifier being configured to indicate whether the test code corresponding to the unit test case is allowed to be executed; An execution unit, configured to execute, in the kernel space, test codes corresponding to unit test cases whose running identifiers satisfy target conditions, based on running identifiers corresponding to the unit test cases; An acquisition unit, used to obtain the running log and running results of the executed test code; The operation flag includes a first operation flag and a second operation flag, the first operation flag indicates that the test code corresponding to the unit test case is allowed to be executed, and the second operation flag indicates that the test code corresponding to the unit test case is prohibited from being executed; The execution unit is used for any of the following when executing the test code corresponding to the unit test case whose running identifier meets the target condition in the kernel space based on the running identifier corresponding to each unit test case: For any unit test case, when the running identifier of the unit test case is the first running identifier, executing the unit test case in the kernel space; When the running identifier of the unit test case is the second running identifier, it is not necessary to execute the unit test case in the kernel space.

9. A computing device, characterized in that The computing device comprises: processor; a memory for storing processor-executable instructions; The processor implements the unit testing method according to any one of claims 1 to 7 by running the executable instructions.

10. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instructions are executed by a processor, the unit testing method according to any one of claims 1 to 7 is implemented.