System testing method and system
By setting code paths and transmitting test case information during system testing, it solves the problem that traditional testing methods are difficult to fully detect errors, achieves more accurate and comprehensive system testing, and ensures product stability.
Patent Information
- Application Number
- CN202410821740.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-24
- Publication Date
- 2024-10-01
AI Technical Summary
Traditional system testing methods, especially black box testing, are difficult to comprehensively and accurately discover errors in the program, which may lead to malfunctions or security issues after the product is released.
By setting the code path, test case information is sent to the electronic device, including multiple tag codes, to form a code path, and the test case identifier is received. If the execution path matches the code path, the corresponding test instructions are sent to execute the test task and the system is implemented. Sexual test task allocation and coverage control.
It improves the comprehensiveness and accuracy of system testing, ensures code coverage, reduces undetected errors, and enhances testing accuracy and product stability.
Smart Images

Figure CN118733458A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a system testing method, and in particular to a white-box testing method and a testing system. Background Art
[0002] In the software development process, system testing is a crucial part, which aims to discover and fix potential errors and abnormal situations. Traditional system testing methods mainly rely on black-box testing, that is, testing based on functions and specifications, but this method may not be able to fully and accurately discover errors in the program.
[0003] In order to improve the comprehensiveness and accuracy of the test, another white-box testing method has also been proposed. White-box testing is a method of system testing based on program code and internal structure, but white-box testing requires a detailed understanding of the internal structure of the code in order to cover all the code. If all the code is not covered, there may be undetected errors. These errors will not be discovered during the testing phase and may cause failures or safety issues after the product is released.
[0004] Therefore, a system testing method is urgently needed to solve the above problems. Summary of the invention
[0005] The present invention provides a system testing method and a testing system, which can systematically assign testing tasks by setting code paths, and also facilitate statistics or control of the scope of test coverage.
[0006] An embodiment of the present invention provides a system testing method for a host system, wherein the host system establishes a communication connection with an electronic device. The system testing method includes: transmitting test case information to the electronic device, wherein the test case information includes a plurality of tag codes, and the tag codes form a plurality of code paths; receiving a test case identifier from the electronic device, wherein the code path identified by the test case identifier is the same as the execution path of the electronic device execution code; and transmitting a test instruction corresponding to the test case identifier to the electronic device, so that the electronic device executes a target test task according to the test instruction.
[0007] From another perspective, an embodiment of the present invention proposes a system testing method for an electronic device, where the electronic device establishes a communication connection with a host system. The system testing method includes: receiving test case information from the host system, where the test case information includes multiple label codes, and these label codes form at least one code path; executing the code and recording multiple labels encountered when executing the code, and these labels form an execution path; if there is an execution path that conforms to the code path, transmitting a test case identifier corresponding to the code path to the host system; and receiving a test instruction from the host system, and executing a test task according to the test instruction.
[0008] From another perspective, an embodiment of the present invention proposes a test system, including a host system and an electronic device that are communicatively connected to each other. The host system is used to transmit test case information to the electronic device, and this test case information includes multiple label codes, and these label codes form multiple code paths. The electronic device is used to execute the code and record multiple labels encountered when executing the code, and these labels form an execution path. When the execution path matches the code path, the electronic device transmits a test case identifier corresponding to the code path to the host system. The host system transmits a test instruction corresponding to the test case identifier to the electronic device, and the electronic device is used to execute the test task indicated by the test instruction. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Figure 1 is a schematic diagram of a testing system according to an embodiment;
[0010] Figure 2 is a flow chart of a testing method according to an embodiment;
[0011] Figure 3 is a schematic diagram showing a list in test case information according to an embodiment;
[0012] Figure 4 is a schematic diagram of a code snippet according to an embodiment. DETAILED DESCRIPTION
[0013] Reference will now be made in detail to exemplary embodiments of the present invention, examples of which are illustrated in the accompanying drawings. Whenever possible, the same reference numerals are used in the drawings and the description to refer to the same or like parts.
[0014] Figure 1 is a schematic diagram of a test system according to an embodiment. Figure 1The test system 100 includes a host system 110 and an electronic device 120. The host system 110 can be any type of computer system, such as a smart phone, a tablet computer, a notebook computer, a desktop computer, an industrial computer, a game console, a server, etc., and the type of the host system 110 is not limited thereto.
[0015] The electronic device 120 is a device to be tested, and the electronic device 120 may be a storage device, a computing device, a sensor device, a communication device, etc., but the present invention is not limited thereto. For example, when the electronic device 120 is a storage device, the electronic device 120 may include a solid state drive, a USB flash drive, a memory card, or other types of non-volatile storage devices, which include one or more rewritable non-volatile memory modules. Each rewritable non-volatile memory module may include one or more memory cell arrays. The memory cells in the memory cell array store data in the form of voltage. For example, the memory module may include a single level cell (SLC) NAND flash memory module, a multilevel cell (MLC) NAND flash memory module, a triple level cell (TLC) NAND flash memory module, a quad level cell (QLC) NAND flash memory module, and / or other memory modules having the same or similar characteristics.
[0016] The host system 110 can establish a communication connection with the electronic device 120 in a wired or wireless manner. For example, in a wired communication embodiment, the host system 110 can be electrically connected to the electronic device 120 through an embedded Multi-Media Card (embedded Multi-Media Card, eMMC), Universal Flash Storage (UFS), Peripheral Component Interconnect Express (PCI Express), Non-Volatile Memory Express (NVM express), Serial Advanced Technology Attachment (SATA), Universal Serial Bus (USB) or other types of connection interface standards. In a wireless communication embodiment, the host system 110 can be connected to the electronic device 120 through a cellular network (or mobile network), near field communication, infrared communication, Bluetooth, Wi-Fi, etc.
[0017] The electronic device 120 includes a processor 121 and a memory 122. The processor 121 is, for example, a central processing unit, a microprocessor, a microcontroller, an application-specific integrated circuit, etc. The memory 122 can be a random access memory, a read-only memory, etc., which stores codes to be tested, and the processor 121 executes these codes.
[0018] Figure 2 is a flow chart of a testing method according to an embodiment. Figure 2 The test method proposed herein is about the interactive operation between the host system 110 and the electronic device 120. Steps 201, 203-205, 208, 211-214 are executed by the electronic device 120, and steps 202, 206, 207, 209, 210, and 212 are executed by the host system. The steps executed by the host system 110 and the electronic device 120 respectively can be called a test method.
[0019] First, in step 201 , the electronic device 120 is initialized.
[0020] The initialization includes but is not limited to: executing power-on, loading code, loading configuration files and other procedures.
[0021] In step 202 , the host system 110 transmits test case information to the electronic device 120 .
[0022] Figure 3 is a schematic diagram of an example of test case information according to an embodiment. Figure 3 The test case information includes a list 300, which records the test case identifier, the category of the test task, the code path formed by multiple label codes, the specified conditions and the number of hits.
[0023] In this example, the category of the test task can be "Power Cycle", "Inject Error" or "ForceAction". When the category of the test task is "Power Cycle", it is to instruct the electronic device 120 to power off and then reinitialize. In the embodiment where the electronic device 120 includes a memory module, the memory module will also be initialized. When the category of the test task is "Inject Error", it is to add some noise or errors to the electronic device 120. For example, in the embodiment where the electronic device 120 includes a memory module, a read, write, or erase error can be created to allow the electronic device to execute the relevant error handling procedure. In the embodiment where the electronic device 120 is a communication device, one or more bits in the packet can be deliberately changed to form a decoding error, thereby testing the error handling procedure of the electronic device 120. In addition, when the category of the test task is "Force Action", it is to force the electronic device 120 to execute a specific program, but the present invention does not limit the content of this program.
[0024] Among them, list 300 also includes a code path formed by multiple label codes "4", "1", and "3". The purpose of the code path and other contents of list 300 are explained in the following paragraphs.
[0025] In step 203 , the electronic device 120 receives test case information from the host system 110 .
[0026] In step 204 , the electronic device 120 executes the code and records a plurality of tags encountered when executing the code.
[0027] In one embodiment, some tags can be added to the code to be tested, and these tags can be distributed in one or more functions. When the code is executed, if a tag is encountered, the tag can be recorded, and the tags form an execution path. This execution path represents the scope covered when testing the code.
[0028] Furthermore, the execution path is compared with the code path in the test case information. If there is an identical code path, the corresponding test case identifier is determined.
[0029] Therefore, the test tasks to be performed subsequently can be determined by controlling or analyzing the comparison results between the execution path and the test case information during the execution of these codes.
[0030] Specifically, Figure 4 is a schematic diagram of a code snippet according to an embodiment. Figure 4, code snippets 401 to 403 are shown here, and these code snippets 401 to 403 can correspond to different functions, modules, etc., wherein code snippet 401 includes a label "4", code snippet 402 includes a label "1" and a label "2", and code snippet 403 includes a label "3" and a label "7". Assuming that the electronic device 120 executes the codes in the code snippets 401 and 402 in sequence, it will encounter the labels "4", "1", and "2" in sequence, and these three labels form an execution path. In one embodiment, the electronic device 120 will add these labels to a stack in sequence to record the execution path.
[0031] In step 205 , it is determined whether the execution path matches the code path. When the execution path matches the code path (ie, the execution path is the same as the code path), the electronic device 120 transmits a test case identifier corresponding to the code path to the host system 110 .
[0032] For example, in Figure 3 and Figure 4 In the example, the execution path is 4; 1; 2, and the code path of the test case identifier “0” is also 4; 1; 2, the two match (or the test case identifier “0” is matched once), so the electronic device 120 transmits the test case identifier “0” to the host system 110.
[0033] In one embodiment, the code includes a checkpoint, and the electronic device 120 may start to check whether the execution path complies with the code path when encountering a checkpoint. The checkpoint may be set at any position in the code, and the present invention is not limited thereto.
[0034] In an embodiment using a stack, the electronic device 120 obtains multiple labels from the stack at a checkpoint and compares the execution path formed by these labels with the code path in the test case information. Since the stack operates on the principle of first-in-last-out, the order of these labels needs to be reversed when obtaining labels from the stack so that the execution path can be obtained.
[0035] For example, in the example of the execution path 4; 1; 2, the label "2" will be obtained from the stack first, followed by the labels "1" and "4" in sequence, and then the execution path 4; 1; 2 will be obtained after the reverse order. In one embodiment, the stack is a global data structure, so even if different functions are executed, the stack can be retrieved, and the labels under different functions can be added to the stack in sequence.
[0036] It should be noted that even if the execution paths are the same, sometimes different tests need to be performed due to different code parameters. Therefore, in one embodiment, in addition to determining whether the execution path conforms to the code path, the electronic device 120 also determines whether the execution condition of the electronic device 120 conforms to the specified condition in the test case information when encountering a checkpoint in step 205.
[0037] For example, in Figure 3 In the embodiment, the specified condition corresponding to the test case identifier "0" is "1", which is to determine whether a certain code parameter is "1". If it is met, the test case identifier "0" corresponding to the code path 4; 1; 2 will be transmitted to the host system 110.
[0038] exist Figure 3 The specified condition only checks one code parameter, but the present invention is not limited to this. In other embodiments, multiple code parameters can also be checked. The specified condition of each code parameter can be a value, a range, or a specific character, etc.
[0039] In one embodiment, Figure 3 The same code path in Listing 300 may have different specified conditions, which correspond to different test case identifiers.
[0040] In this way, by adding the determination of the specified conditions, the task that the electronic device 120 needs to test can be better determined. For example, even if the same code is executed, different code parameters may represent different scenarios and require different test tasks.
[0041] In step 206 , the host system 110 receives the test case identifier from the electronic device 110 .
[0042] Through this test case identifier, the host system 110 can know that the code path identified by the test case identifier is the same as the execution path of the code executed by the electronic device 120. In the embodiment where the electronic device 120 has a judgment specified condition, the host system 110 can also know that a specific code parameter has met the restricted value.
[0043] For example, in Figure 3 In the embodiment, when the host system 110 receives the test case identifier “0”, the host system 110 knows that the execution path of the electronic device 120 is 4; 1; 2, and the specific code parameter is “1”.
[0044] In step 207 , the host system 110 transmits a test instruction corresponding to the test case identifier to the electronic device 120 , so as to allow the electronic device 120 to execute the test task according to the test instruction.
[0045] In one embodiment, the host system 110 may query Figure 3 List 300 to get the category to be tested.
[0046] In one embodiment, the same test case identifier may correspond to multiple categories, for example, these categories include "Power Cycle", "Inject Error" and "Force Action", and the host system 110 can specify the category to be tested. This is to execute different categories under the same execution path to check for code problems.
[0047] Since a test case identifier may be matched multiple times, the host system 110 can set a minimum number of executions for each test case identifier, and this minimum number of executions is greater than or equal to the number of corresponding categories. Each time the host system 110 receives a test case identifier, it sets a test instruction so that each time the electronic device 120 executes a test task within the minimum number of executions, the corresponding categories are different from each other.
[0048] For example, the minimum number of executions corresponding to a test case identifier is equal to 3. When the host system 110 receives this test case identifier for the first time, it will set the category of the test task to "Power Cycle"; when the host system 110 receives this test case identifier for the second time, it will set the category of the test task to "Inject Error"; when the host system 110 receives this test case identifier for the third time, it will set the category of the test task to "Force Action".
[0049] In one embodiment, the host system 110 can modify the categories in the list 300 so that the electronic device 120 executes different categories each time, thereby improving the comprehensiveness of the test and improving the accuracy of the test.
[0050] In step 208 , the electronic device 120 receives the test instruction from the host system 110 , and executes the test task according to the test instruction.
[0051] If the test task has multiple categories, the test instruction will also indicate the category to be tested, and the electronic device 120 can execute the corresponding category accordingly.
[0052] In step 209 , the host system 110 updates the test case information.
[0053] For example, Figure 3In the example of , the list 300 also includes a hit count, which indicates the number of times the corresponding test task is matched. The host system 110 will update this hit count, and the updated hit count can be used for subsequent decisions or analysis. In some embodiments, the host system 110 can also adjust other fields in the test case information according to these hit counts, such as adjusting the category, code path, and specified conditions of the test task. For example, in the above-mentioned embodiment where the host system 110 adjusts the category, the category to be tested can be determined based on the hit count.
[0054] In step 210 , the host system 110 transmits an initialization command to the electronic device 120 to reinitialize the electronic device 120 .
[0055] In step 211 , the electronic device 120 receives the initialization instruction.
[0056] In step 212 , the host system 110 transmits the updated test case information to the electronic device 120 .
[0057] In step 213 , the electronic device 120 receives updated test case information.
[0058] In step 214, initialization is performed.
[0059] After the electronic device 120 is reinitialized, it will use the updated test case information, and can subsequently test codes that have not been tested, or categories that have not been tested.
[0060] In one embodiment, the untested code or untested category corresponds to different test case identifiers. Specifically, the test case information includes multiple test case identifiers and corresponding test task categories, code paths, instruction conditions, hit counts, etc.
[0061] For example, Figure 3 In the list 300, the test case identifier "1" corresponds to the code path 4;3;7, the type of the test task is "Inject Error", the specified condition is "0", and the hit count is "0". When the execution path of the electronic device 120 is 4;3;7 and the specific code parameter is "0", the electronic device 120 will transmit the test case identifier "1" to the host system 110.
[0062] In order to achieve balanced testing, each code path should be tested evenly so that the number of times these test case identifiers are matched conforms to a probability distribution, which can be a uniform distribution or other distributions.
[0063] In one embodiment, this probability distribution is formed according to the minimum number of executions of each test case identifier. Specifically, the minimum number of executions of each test case identifier will be greater than or equal to the number of corresponding categories. The greater the minimum number of executions, the greater the number of times the test case identifier needs to be matched. Therefore, the probability of the test case identifier being executed can be set to be proportional to its own minimum number of executions. For example, if there are 5 test case identifiers, and their minimum number of executions are 4, 5, 3, 6, and 2, respectively, the probability of the first test case identifier being executed can be set to 4 / (4+5+3+6+2)=20%, and the probability of the other four test case identifiers being executed is 25%, 15%, 30%, and 10%, respectively. These probabilities form the above-mentioned probability distribution. When a total of N (for example, 100) tests are performed, the number of times the test case identifier is actually matched should conform to such a probability distribution. If a test task corresponding to a test case identifier has only one category, the corresponding minimum number of executions can be set to 1, which can still be applied to the above-mentioned probability distribution calculation.
[0064] Various suitable means may be used to adjust the number of times each test case identifier is matched. For example, after the electronic device 120 is initialized in step 214, the electronic device 120 may change one or more execution parameters to execute different codes and generate different execution paths, so that the number of times these test case identifiers are executed conforms to the above probability distribution. For example, please refer to Figure 4 After the above adjustment, the electronic device 120 executes the code segments 401 and 403 in sequence, and the resulting execution path is 4; 3; 7, which is consistent with the code path 4; 3; 7 corresponding to the test case identifier “1” in the list 300.
[0065] In one embodiment, the file root path location can also be inserted into the environment variable of the test code to execute different codes. Specifically, by determining the file root path location of the test code to be executed (for example, by "import osROOT_PATH=os.getcwd()" to obtain the file root path location), and then inserting the root path into the environment variable of the test code to be executed (for example, by "sys.path.insert(0,ROOT_APP)" to achieve insertion); further, each time the test code to be executed is executed, the execution path can be found from the root path; finally, by setting different execution paths to achieve coverage of each test node, and by setting the number of executions, the coverage rate of different nodes can be achieved.
[0066] In another embodiment, the host system 110 may also adjust the code path or specify conditions when updating the test case information in step 209, so that the possibility of a test case identifier being matched is increased. When the electronic device 120 receives new test case information and executes the code, it may be matched to the expected test case identifier based on the new code path or specified conditions, so that the number of times the test case identifier is matched can meet the above-mentioned probability distribution.
[0067] In the above-mentioned test system and test method, since the code path and conditions are specified, the code range covered during testing is easy to control or count, which also helps to design test tasks systematically (for example, according to probability distribution), such as testing the necessary code more times, testing various categories of test tasks, or determining whether there is a path that has not been tested.
[0068] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A system testing method, characterized in that: Used in a host system, the host system establishes a communication connection with an electronic device, and the system testing method includes: Transmitting test case information to the electronic device, wherein the test case information includes a plurality of tag codes, and the plurality of tag codes form a plurality of code paths; receiving a test case identifier from the electronic device, the code path identified by the test case identifier being the same as an execution path of code executed by the electronic device; and A test instruction corresponding to the test case identifier is transmitted to the electronic device, so that the electronic device performs a test task according to the test instruction.
2. The system testing method according to claim 1, characterized in that: The test case information also includes a specified condition, which is used to allow the electronic device to check at a checkpoint whether the execution path complies with the code path and whether the execution condition of the electronic device complies with the specified condition.
3. The system testing method according to claim 1, characterized in that: The test task belongs to one of a plurality of categories, and the system testing method further comprises: Setting a minimum number of executions of the test case identifier; and It is set that each time the test task is executed within the minimum execution times, the corresponding categories are different from each other.
4. The system testing method according to claim 1, characterized in that: The test case information also includes a hit count, which is used to indicate the number of times the corresponding test case identifier is matched.
5. The system testing method according to claim 4, characterized in that: After the step of transmitting the test instruction to the electronic device, the system testing method further includes: Updating the hit count in the test case information; transmitting an initialization instruction to the electronic device to reinitialize the electronic device; and The updated test case information is transmitted to the electronic device.
6. A system testing method, characterized in that: For an electronic device, the electronic device establishes a communication connection with a host system, and the system testing method includes: Receiving test case information from the host system, wherein the test case information includes a plurality of label codes, the plurality of label codes form a code path, and the code path includes at least one; Executing code and recording a plurality of tags encountered when executing the code, wherein the plurality of tags form an execution path; If there is an execution path that matches the code path, transmitting a test case identifier corresponding to the code path to the host system; and A test instruction is received from the host system, and a test task is executed according to the test instruction.
7. The system testing method according to claim 6, characterized in that: The test case information also includes a specified condition, and the system testing method also includes: At a checkpoint, it is checked whether the execution path meets the code path and whether the execution condition of the electronic device meets the specified condition.
8. The system testing method according to claim 7, characterized in that: Before the step of transmitting the test case identifier corresponding to the code path to the host system, the method further includes: If the execution condition of the electronic device meets the specified condition, the test case identifier corresponding to the code path is transmitted to the host system.
9. The system testing method according to claim 7, characterized in that: The steps of executing the code and recording multiple tags encountered when executing the code include: Add the multiple tags to the stack in sequence, The system testing method further comprises: The plurality of tags are retrieved from the stack at the checkpoint, and the execution path is compared with the code path in the test case information.
10. The system testing method according to claim 6, characterized in that: The test case information also includes a hit count, which is used to indicate the number of times each of the test case identifiers is matched.
11. The system testing method according to claim 10, characterized in that: The test case information includes a plurality of test case identifiers, each of the test case identifiers has a minimum number of executions, and the minimum number of executions forms a probability distribution. The system testing method further includes: Initialize; and The execution parameters are changed so that the number of times the plurality of test case identifiers are matched conforms to the probability distribution.
12. A testing system, characterized in that: include: Host system; as well as an electronic device, communicatively connected to the host system, in, The host system is used to transmit test case information to the electronic device, wherein the test case information includes a plurality of label codes, and the plurality of label codes form a plurality of code paths. The electronic device is used to execute code and record multiple tags encountered when executing the code, wherein the multiple tags form an execution path. When the execution path matches the code path, the electronic device transmits a test case identifier corresponding to the code path to the host system, The host system transmits a test instruction corresponding to the test case identifier to the electronic device, and the electronic device is used to execute the test task indicated by the test instruction.
13. The test system according to claim 12, characterized in that: The test case information also includes specified conditions, wherein the electronic device is used to check at a checkpoint whether the execution path complies with the code path and whether the execution condition of the electronic device complies with the specified condition, When the execution path meets the code path and the execution condition meets the specified condition, the electronic device transmits the test case identifier corresponding to the code path to the host system.
14. The test system according to claim 13, characterized in that: wherein the electronic device is used to sequentially add the plurality of tags into a stack, The electronic device obtains the multiple tags from the stack at the checkpoint and compares the execution path with the code path in the test case information.
15. The test system according to claim 12, characterized in that: The test task belongs to one of a plurality of categories, The host system is used to set a minimum number of execution times of the test case identifier, and to set the corresponding categories to be different each time the electronic device executes the test task within the minimum number of execution times.
16. The test system according to claim 12, characterized in that: The test case information also includes a hit count, which indicates the number of times the corresponding test case identifier is matched. The test case information includes a plurality of test case identifiers, each of which has a minimum number of executions, and the minimum number of executions forms a probability distribution. The electronic device is further used to perform initialization and change execution parameters so that the number of times the multiple test case identifiers are matched conforms to the probability distribution.
