White-box testing method for functional safety software and related device
Patent Information
- Application Number
- CN202111374610.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-19
- Publication Date
- 2026-09-25
- Estimated Expiration
- 2041-11-19
AI Technical Summary
可见,在现有测试技术中随着程序分支数量(n)的增加,测试用例数量呈指数型增长,大幅降低了白盒测试的执行效率
[0045]从上面所述可以看出,本申请提供的功能安全软件的白盒测试方法,通过采用优化的粒子群算法,根据程序的结构及历史测试情况,对每个测试用例的执行情况进行筛选和优化选择,可以有效地选取执行时间异常的用例,从而,以最小的成本达到最大的覆盖率实现了快速定位问题,提高了测试效率。
Smart Images

Figure CN116149975B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software testing technology, and in particular to a white-box testing method and related equipment for functional safety software. Background Technology
[0002] When software is used in safety-critical systems such as automobiles, rail transportation, or aircraft, it acquires safety attributes. Therefore, functional safety software is software that has undergone thorough safety analysis in the relevant application scenarios and possesses high reliability and high availability.
[0003] When representing software functionality using a program flowchart, the software's entry point, exit point, and branch decisions are all considered nodes, while the sequential execution of statements between nodes is considered a path. The difference between functionally safe software and non-functionally safe software lies in the sufficient measures taken to ensure the smooth execution of the software path. Therefore, the main objective of white-box testing for functionally safe software is to verify the completeness of the protective measures, that is, to identify situations that may lead to erroneous execution or timeouts of system functionality.
[0004] However, traditional white-box testing methods need to cover all decision conditions of program branches. For a program with n selected branches, at most 2... n Only a certain number of test cases can ensure coverage of all execution paths of the program, thus ensuring the integrity of software functional safety. It is evident that in existing testing techniques, the number of test cases increases exponentially with the increase in the number of program branches (n), significantly reducing the execution efficiency of white-box testing. Summary of the Invention
[0005] In view of this, the purpose of this application is to propose a white-box testing method and related equipment for functional safety software, so as to improve the testing efficiency of functional safety software.
[0006] To achieve the above objectives, this application provides a white-box testing method for functional safety software, comprising:
[0007] Based on the value range of the selection branches contained in the program flowchart of the functional safety software, multiple initial test cases are set, and the multiple initial test cases correspond to multiple positions in the coordinate system respectively.
[0008] The execution time of each initial test case is obtained by substituting it into the selected branch and executing it.
[0009] In response to determining that the execution time of one of the plurality of initial test cases is greater than a preset time threshold, the initial test case is used as a local optimization test case;
[0010] Based on the target position corresponding to the local optimized test case among the plurality of positions, the plurality of initial test cases are used as a particle swarm, and the plurality of positions are iteratively updated using the particle swarm algorithm to obtain the global optimized test case of the plurality of initial test cases.
[0011] The functional safety software was subjected to white-box testing using the global optimization test cases.
[0012] Optionally, the step of determining that the execution time of one of the plurality of initial test cases is greater than a preset time threshold, and using that initial test case as a local optimization test case, includes:
[0013] If the execution time of one of the multiple initial test cases is determined to be greater than a preset time threshold, the iteration number of the initial test case is detected.
[0014] In response to determining that the number of iterations exceeds a preset iteration threshold, the initial test case is used as the local optimization test case;
[0015] In response to determining that the number of iterations does not exceed a preset iteration threshold, the initial test case is substituted back into the selected branch for execution to obtain the locally optimized test case.
[0016] Optionally, the step of iteratively updating the multiple positions based on the target position corresponding to the local optimization test case among the multiple positions, using the multiple initial test cases as particle swarms, and employing the particle swarm optimization algorithm to obtain the global optimization test cases of the multiple initial test cases includes:
[0017] In response to determining that the number of local optimization test cases is greater than a preset threshold, the particle swarm algorithm is iterated based on the local optimization test cases;
[0018] In response to determining that the number of local optimization test cases is less than a preset threshold, the local optimization test cases are used as global optimization test cases.
[0019] Optionally, the step of responding to determining that the number of local optimization test cases is greater than a preset threshold, and then performing particle swarm optimization algorithm iteration based on the local optimization test cases, includes:
[0020] The local optimization test cases are substituted into the program branch for execution, and the execution time of the local optimization test cases is recorded.
[0021] The execution time of the locally optimized test cases is compared with the pre-obtained average execution time;
[0022] In response to determining that the execution time exceeds the average execution time, the local optimization test case is used as the global optimization test case;
[0023] In response to determining that the execution time is less than the average execution time, the position of the local optimization test case in the coordinate system is updated, and the updated local optimization test case is substituted into the program branch for execution again.
[0024] Optionally, in response to determining that the execution time is less than the average execution time, updating the position of the local optimization test case in the coordinate system and re-introducing the updated local optimization test case into the program branch for execution includes:
[0025] The velocity and position of the local optimization test case in the coordinate system are updated using the following formula, and the updated local optimization test case is then substituted back into the program branch for execution:
[0026]
[0027]
[0028] d∈{1,2,3,...,Q}
[0029] c1 + c2 = 1
[0030] in, Let be the velocity of the particle in branch i. Let be the position of the particle in branch i, α be the constraint factor, J be the historical local optimum, k be the global optimum, c1 and c2 be acceleration constants used to adjust the weight of the historical local optimum J and the global optimum k, and r be a variation factor that randomly takes a value between 0 and 1. Let i be the local optimal position of branch i.
[0031] Optionally, the average execution time can be obtained through the following operations:
[0032] Obtain the execution time of each of the multiple initial test cases;
[0033] In response to determining that the execution time of one of the plurality of initial test cases is less than a preset time threshold, the execution time of the plurality of initial test cases is obtained, and the average execution time is calculated based on the execution time of the plurality of initial test cases.
[0034] Based on the same inventive concept, one or more embodiments of this specification also provide a white-box testing apparatus for functional safety software, comprising:
[0035] The setting module is configured to set multiple initial test cases based on the value range of the selection branches contained in the program flowchart of the functional safety software, wherein the multiple initial test cases correspond to multiple positions in the coordinate system.
[0036] The execution module is configured to obtain the execution time of each of the multiple initial test cases by substituting them into the selected branch for execution.
[0037] The determination module is configured to, in response to determining that the execution time of one of the plurality of initial test cases is greater than a preset time threshold, use that initial test case as a local optimization test case;
[0038] The iterative module is configured to iteratively update the multiple positions based on the target position corresponding to the local optimization test case among the multiple positions, using the multiple initial test cases as particle swarms, to obtain the global optimization test case of the multiple initial test cases;
[0039] The testing module is configured to perform white-box testing on the functional safety software using the globally optimized test cases.
[0040] Optionally, the iterative module includes:
[0041] In response to determining that the number of local optimization test cases is greater than a preset threshold, the particle swarm algorithm is iterated based on the local optimization test cases;
[0042] In response to determining that the number of local optimization test cases is less than a preset threshold, the local optimization test cases are used as global optimization test cases.
[0043] Based on the same inventive concept, one or more embodiments of this specification also provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in any of the above.
[0044] Based on the same inventive concept, one or more embodiments of this specification also provide a non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform any of the methods described above.
[0045] As can be seen from the above, the white-box testing method for functional safety software provided in this application, by employing an optimized particle swarm optimization algorithm, filters and optimizes the execution of each test case based on the program structure and historical testing data. This effectively selects test cases with abnormal execution times, thereby achieving maximum coverage at minimal cost, enabling rapid problem localization, and improving testing efficiency. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in this application or related technologies, the drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 This is a flowchart of a white-box testing method for functional safety software according to an embodiment of this application;
[0048] Figure 2 This is a schematic diagram of the initial test cases in a two-dimensional coordinate system according to an embodiment of this application;
[0049] Figure 3 This is a schematic diagram of a white-box testing apparatus for functional safety software according to an embodiment of this application;
[0050] Figure 4 This is a schematic diagram of the electronic device structure according to an embodiment of this application. Detailed Implementation
[0051] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with specific embodiments and the accompanying drawings.
[0052] It should be noted that, unless otherwise defined, the technical or scientific terms used in the embodiments of this application should have the ordinary meaning understood by those skilled in the art to which this application pertains. The terms "first," "second," and similar terms used in the embodiments of this application do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects.
[0053] As described in the background section, existing white-box testing methods, due to the need to cover various decision situations of program branches, require at most 2n test cases to ensure coverage of all execution paths in a program with n selected branches, thus ensuring that every selected branch is tested and achieving comprehensive testing. However, as the number of program branches (n) increases, the number of test cases grows exponentially, significantly impacting the execution efficiency of white-box testing and posing a major challenge to the testing of functional safety software.
[0054] In the process of developing this application, the applicant discovered that in the testing of functional safety software, the execution time of test cases in error-prone branches is significantly longer than that in normal branches. Therefore, execution time can serve as an important indicator for measuring whether a branch is error-prone. Furthermore, optimizing test cases can not only reduce the number of test cases but also improve test results and reduce testing time while ensuring test quality.
[0055] In view of the problems existing in the prior art and based on the applicant's findings, this application provides a white-box testing method for functional safety software, which mainly includes value range division, initial test case value setting, algorithm strategy, test case iteration, and optimization process. The number and value of initial test cases are determined by dividing the value range, and the initial test cases are iterated and optimized by the algorithm strategy to obtain optimized test cases. Testing is carried out based on the optimized test cases, which not only ensures accurate positioning in the testing process, but also achieves the effect of optimizing test results and reducing testing time.
[0056] refer to Figure 1 The white-box testing method for functional safety software in this application includes:
[0057] Step 101: Based on the value range of the selection branch contained in the program flowchart of the functional safety software, set up multiple initial test cases, each of which corresponds to a multiple position in the coordinate system.
[0058] Step 102: By substituting the multiple initial test cases into the selected branch for execution, the execution time of each of the multiple initial test cases is obtained.
[0059] Step 103: In response to determining that the execution time of one of the multiple initial test cases is greater than a preset time threshold, the initial test case is used as a local optimization test case.
[0060] Step 104: Based on the target position corresponding to the local optimization test case among the multiple positions, use the multiple initial test cases as a particle swarm and iteratively update the multiple positions using the particle swarm algorithm to obtain the global optimization test case of the multiple initial test cases.
[0061] Step 105: Perform white-box testing on the functional safety software using the global optimization test cases.
[0062] In some implementations, the branch selection in the program code explicitly or implicitly indicates the basis for the branch decision. Therefore, the number of execution paths can be determined at the beginning of testing, and the value range can be divided according to the decision conditions. Then, initial test cases are determined based on these value ranges. Each initial test case corresponds to a position in a coordinate system, which can be a two-dimensional, three-dimensional, or multi-dimensional coordinate system, with its dimensions determined by the decision conditions. For example, refer to... Figure 2 At this point, the range of values for the condition is: a>3&b>2. Therefore, the test cases can be a=4&b=3, a=4&b=5, a=4&b=6, a=7&b=3, or even more. In a two-dimensional coordinate system, the horizontal axis is a and the vertical axis is b. When a=4&b=3, the corresponding position of a=4&b=3 in the coordinate system can be obtained, such as... Figure 2 As shown, similarly, any values of a and b will have corresponding positions in the two-dimensional coordinate system. Furthermore, a test case may also be determined by three values; for example, a test case might be determined by a>3, b>2, and c>4, in which case the initial test case's position might correspond to a three-dimensional coordinate system.
[0063] In some implementations, the execution time of the plurality of initial test cases is obtained; the execution time of the plurality of initial test cases is compared with a preset execution time, and the initial test cases that exceed the preset execution time are used as the local optimization test cases; the average execution time is calculated based on the execution time of the plurality of initial test cases.
[0064] Furthermore, the speed and location of each initial test case are updated in each iteration according to the following formula:
[0065]
[0066]
[0067] d∈{1,2,3,...,M}
[0068] in, Let be the velocity of the particle in branch i. Let be the position of the particle in branch i, α be the velocity constraint factor (usually between 0 and 1, used to constrain velocity values), and r be the variation factor (a random value between 0 and 1). Let i be the local optimal position of branch i in the coordinate system.
[0069] The velocity is the change in value from the initial test case to the locally optimized test case. For example, the initial test cases include a=4&b=3 and a=6&b=7. If the locally optimized test case after one execution is a=6&b=7, then the test case a=4&b=3 is updated to a=6&b=7. The change in value is recorded as the velocity of the particle.
[0070] In some implementations, each initial test case is carried into a program branch for execution, and the execution results are output and the execution time of each initial test case in the program branch is recorded. The average execution time is calculated based on the execution time of each initial test case in the program branch.
[0071] In some implementations, the initial test cases are iterated based on the position of the locally optimal test cases in a two-dimensional coordinate system, and the velocity and position of each initial test case are updated in each iteration; in response to determining that a preset number of iterations has been exceeded, the position of the initial test cases is updated to the position of the locally optimal test cases.
[0072] In some implementations, the initial test case that exceeds the preset execution time is taken as the locally optimal test case. If the number of iterations has not reached the preset number of iterations at this time, the locally optimal test case is used as the input value to be entered into the program branch for execution until the number of iterations reaches the maximum number of iterations. Then, the optimized test case obtained in the current iteration is taken as the locally optimized test case.
[0073] In some implementations, the number of local optimization test cases is used to calculate the number of global optimization test cases; in response to determining that the number of local optimization test cases is greater than a preset threshold, the number of global optimization test cases is calculated based on the local optimization test cases; in response to determining that the number of local optimization test cases is less than a preset threshold, the local optimization test cases are used as the global optimization test cases.
[0074] Furthermore, in response to determining that the number of local optimization test cases is greater than a preset threshold, the local optimization test cases are brought into the program branch for execution, and the execution time of the local optimization test cases is recorded; when the execution time exceeds the average execution time, the local optimization test cases are used as global optimization test cases.
[0075] The speed and location of the local optimization test cases are iteratively updated according to the following formula:
[0076]
[0077]
[0078] d∈{1,2,3,...,Q}
[0079] c1 + c2 = 1
[0080] in, Let be the velocity of the particle in branch i. Let be the position of the particle in branch i, α be the constraint factor, J be the historical local optimum in the coordinate system, k be the global optimum in the coordinate system, c1 and c2 be acceleration constants used to adjust the weight of the historical local optimum J and the global optimum k, and r be a variation factor (a random value between 0 and 1). Let i be the local optimal position of branch i.
[0081] In some implementations, when there are a large number of local optimization test cases, it indicates that the program code is large in size or complex in structure, and it is necessary to calculate based on the local optimization test cases to obtain global optimization test cases.
[0082] Specifically, the calculation includes: inputting local optimization test cases as input values into program branches for execution; recording the execution time of each local optimization test case in the branch; comparing the execution time of each local optimization test case in the branch with the average execution time to confirm whether there are any anomalies in the branch executing the local optimization test cases; if the execution time of a local optimization test case in the branch is greater than the average execution time, then the local optimization test case is recorded as a global optimization test case. If the execution time of a local optimization test case in the branch is less than the average execution time, then the position of the local optimization test case in the coordinate system is updated again to the position corresponding to the current locally optimal test case in the coordinate system, and the updated local optimization test case is input into the program branch for execution again. During execution, the execution time is compared with the average execution time again. If it is less than the average execution time, the position is updated again and input. This process is repeated multiple times until the execution time of a local optimization test case exceeds the average execution time, at which point it is recorded as a globally optimal test case.
[0083] Furthermore, after finding the globally optimal test case, the number of iterations is checked. If the number of iterations is less than the preset number of iterations, the obtained globally optimal test case is input into the program and executed again until the number of executions exceeds or equals the preset number of executions. Then the iteration is completed and the globally optimal test case is output.
[0084] In some implementations, multiple test cases are optimized using the particle swarm optimization algorithm, and testing is performed based on the optimized globally optimal test cases. This not only reduces unnecessary execution times but also improves testing efficiency.
[0085] White-box testing, also known as structural testing, transparent-box testing, logic-driven testing, or code-based testing, is a test case design methodology. The "box" refers to the software being tested, and "white-box" means the box is visible, meaning its internal structure and how it operates are clearly understood. The "white-box" method provides a comprehensive understanding of the program's internal logical structure and tests all logical paths. It is essentially exhaustive path testing. When using this approach, testers must examine the program's internal structure, starting with its logic, to derive test data. The number of independent paths traversing the program can be astronomical.
[0086] Functional safety software refers to highly reliable and highly available software that has undergone thorough safety analysis in its application or hypothetical application and has been developed using the latest technological advancements. This definition encompasses two concepts and one objective. The two concepts are that the software must undergo safety analysis and that it must be developed using the latest technological advancements. The objective is to achieve high reliability and high availability.
[0087] Software security testing (analysis) can be broadly divided into two categories: security analysis of conceptual design and security analysis of related failures.
[0088] In software system applications, loss of system integrity can lead to malfunctions, such as misleading warning messages in cars, unexpected acceleration or braking, or incorrect recommendations from the Traffic Collision Avoidance System (TCAS) in civil aviation. To maintain system integrity, architectural design typically incorporates measures to prevent or mitigate faults. These measures include heterogeneous redundancy (different algorithms implementing the same functionality), fault detection, and functional degradation to prevent integrity-related faults or protect the system from them. Therefore, system design must include fault detection and response or fault control requirements; these are common safety requirements and objectives in the automotive industry.
[0089] In today's advancing field of autonomous driving, systems must maintain not only integrity but also availability. The difference between availability and integrity lies in the requirement that the system continuously maintains its functionality or recoverability under all foreseeable operating conditions (whether normal or abnormal). In other words, whether it's a random hardware failure or a systemic software failure, critical functions must remain available during or after the failure. High availability typically requires a highly reliable redundant design. If redundancy ensures availability, the system needs to be able to detect faults and recover quickly. Therefore, software testing plays a crucial role in the normal operation of software systems. Testing ensures both the integrity and availability of the system.
[0090] As can be seen from the above, the white-box testing method for functional safety software provided in this application, by employing an optimized particle swarm optimization algorithm, filters and optimizes the execution of each test case based on the program structure and historical testing data. This effectively selects test cases with abnormal execution times, thereby achieving maximum coverage at minimal cost, enabling rapid problem localization, and improving testing efficiency.
[0091] Compared with existing methods for optimizing white-box testing based on genetic algorithms, the particle swarm optimization algorithm in this application simplifies the crossover and mutation process in genetic algorithms, has a simpler calculation method, and is more efficient in testing.
[0092] Taking a program that handles Ethernet communication as an example, this program requires six input parameters and has eight conditional branches. The last conditional branch, due to an incorrect data width setting, has a chance of causing a memory address access out of bounds after multiple loop executions, leading to abnormal program termination. Traditionally, to achieve full condition coverage, 2^8 = 256 test cases need to be written, each requiring six input parameters. Only after executing nearly 90% of the test cases sequentially is it possible to reach the last conditional branch and discover the program problem.
[0093] Optimizing white-box testing using genetic algorithms requires adjusting the crossover and mutation parameters multiple times based on the execution of conditional branches. If the adjustment process goes smoothly, only about 50% of the test cases need to be executed before reaching the last conditional branch and discovering program problems.
[0094] By optimizing using the particle swarm optimization algorithm of this invention, only the particle velocity and weight parameters need to be adjusted once to achieve the optimization result of the genetic algorithm. That is, only about 50% of the test cases are executed before reaching the last conditional branch and discovering program problems.
[0095] It should be noted that the method in this embodiment can be executed by a single device, such as a computer or server. The method can also be applied in a distributed scenario, where multiple devices cooperate to complete the task. In such a distributed scenario, one of these devices may execute only one or more steps of the method in this embodiment, and the multiple devices will interact with each other to complete the method described.
[0096] It should be noted that the above description describes some embodiments of this application. 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 a different order than that shown in the above embodiments and still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0097] Based on the same inventive concept, corresponding to any of the above embodiments, this application also provides a white-box testing device for functional safety software.
[0098] refer to Figure 3 The white-box testing apparatus for functional safety software includes:
[0099] The setting module is configured to set multiple initial test cases based on the value range of the selection branches contained in the program flowchart of the functional safety software, wherein the multiple initial test cases correspond to multiple positions in the coordinate system.
[0100] The execution module is configured to obtain the execution time of each of the multiple initial test cases by substituting them into the selected branch for execution.
[0101] The determination module is configured to, in response to determining that the execution time of one of the plurality of initial test cases is greater than a preset time threshold, use that initial test case as a local optimization test case;
[0102] The iterative module is configured to iteratively update the multiple positions based on the target position corresponding to the local optimization test case among the multiple positions, using the multiple initial test cases as particle swarms, to obtain the global optimization test case of the multiple initial test cases;
[0103] The testing module is configured to perform white-box testing on the functional safety software using the globally optimized test cases.
[0104] In some implementations, the iteration module includes:
[0105] In response to determining that the number of local optimization test cases is greater than a preset threshold, the particle swarm algorithm is iterated based on the local optimization test cases;
[0106] In response to determining that the number of local optimization test cases is less than a preset threshold, the local optimization test cases are used as global optimization test cases.
[0107] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, in implementing this application, the functions of each module can be implemented in one or more software and / or hardware.
[0108] The apparatus described above is used to implement the corresponding white-box testing method for functional safety software in any of the foregoing embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0109] Based on the same inventive concept, corresponding to the methods of any of the above embodiments, this application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the white-box testing method for functional safety software as described in any of the above embodiments.
[0110] Figure 4 This embodiment illustrates a more specific hardware structure of an electronic device, which may include a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, memory 1020, input / output interface 1030, and communication interface 1040 are interconnected internally via the bus 1050.
[0111] The processor 1010 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.
[0112] The memory 1020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program code is stored in the memory 1020 and is called and executed by the processor 1010.
[0113] The input / output interface 1030 is used to connect input / output modules to realize information input and output. Input / output modules can be configured as components within the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Input devices may include keyboards, mice, touchscreens, microphones, various sensors, etc., while output devices may include displays, speakers, vibrators, indicator lights, etc.
[0114] The communication interface 1040 is used to connect a communication module (not shown in the figure) to enable communication between this device and other devices. The communication module can communicate via wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0115] Bus 1050 includes a pathway for transmitting information between various components of the device, such as processor 1010, memory 1020, input / output interface 1030, and communication interface 1040.
[0116] It should be noted that although the above-described device only shows the processor 1010, memory 1020, input / output interface 1030, communication interface 1040, and bus 1050, in specific implementations, the device may also include other components necessary for normal operation. Furthermore, those skilled in the art will understand that the above-described device may only include the components necessary for implementing the embodiments of this specification, and not necessarily all the components shown in the figures.
[0117] The electronic devices described above are used to implement the corresponding white-box testing methods for functional safety software in any of the foregoing embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0118] Based on the same inventive concept, corresponding to the methods of any of the above embodiments, this application also provides a non-transitory computer-readable storage medium storing computer instructions for causing the computer to execute the white-box testing method for functional safety software as described in any of the above embodiments.
[0119] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change 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 technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.
[0120] The computer instructions stored in the storage medium of the above embodiments are used to cause the computer to execute the white-box testing method for functional safety software as described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0121] It should be noted that the embodiments of this application can also be further described in the following ways:
[0122] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of this application (including the claims) is limited to these examples; within the framework of this application, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of the embodiments of this application as described above, which are not provided in the details for the sake of brevity.
[0123] Additionally, to simplify the description and discussion, and to avoid obscuring the embodiments of this application, the well-known power / ground connections to integrated circuit (IC) chips and other components may or may not be shown in the provided drawings. Furthermore, the apparatus may be shown in block diagram form to avoid obscuring the embodiments of this application, and this also takes into account the fact that the details of the implementation of these block diagram apparatuses are highly dependent on the platform on which the embodiments of this application will be implemented (i.e., these details should be fully understood by those skilled in the art). While specific details (e.g., circuits) have been set forth to describe exemplary embodiments of this application, it will be apparent to those skilled in the art that the embodiments of this application can be implemented without these specific details or with variations thereof. Therefore, these descriptions should be considered illustrative rather than restrictive.
[0124] Although this application has been described in conjunction with specific embodiments thereof, many substitutions, modifications, and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may be used with the embodiments discussed.
[0125] The embodiments of this application are intended to cover all such substitutions, modifications, and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the embodiments of this application should be included within the protection scope of this application.
Claims
1. A white-box testing method for functional safety software, characterized in that, include: Based on the value range of the selection branches contained in the program flowchart of the functional safety software, multiple initial test cases are set, and the multiple initial test cases correspond to multiple positions in the coordinate system respectively. The execution time of each initial test case is obtained by substituting it into the selected branch and executing it. In response to determining that the execution time of one of the plurality of initial test cases is greater than a preset time threshold, the initial test case is used as a local optimization test case; Based on the target position corresponding to the local optimized test case among the plurality of positions, the plurality of initial test cases are used as a particle swarm, and the plurality of positions are iteratively updated using the particle swarm algorithm to obtain the global optimized test case of the plurality of initial test cases. The functional safety software was subjected to white-box testing using the global optimization test cases. The step of determining that the execution time of one of the plurality of initial test cases is greater than a preset time threshold, and using that initial test case as a local optimization test case, includes: If the execution time of one of the multiple initial test cases is determined to be greater than a preset time threshold, the iteration number of the initial test case is detected. In response to determining that the number of iterations exceeds a preset iteration threshold, the initial test case is used as the local optimization test case; In response to determining that the number of iterations does not exceed a preset iteration threshold, the initial test case is substituted back into the selected branch for execution to obtain the locally optimized test case.
2. The method according to claim 1, characterized in that, The step of iteratively updating the multiple positions based on the target position corresponding to the local optimization test case among the multiple positions, using the multiple initial test cases as a particle swarm, and employing the particle swarm algorithm to obtain the global optimization test case of the multiple initial test cases includes: In response to determining that the number of local optimization test cases is greater than a preset threshold, the particle swarm algorithm is iterated based on the local optimization test cases; In response to determining that the number of local optimization test cases is less than a preset threshold, the local optimization test cases are used as global optimization test cases.
3. The method according to claim 2, characterized in that, The step of responding to determining that the number of local optimization test cases is greater than a preset threshold, and then performing particle swarm optimization algorithm iteration based on the local optimization test cases, includes: The local optimization test cases are substituted into the program branch for execution, and the execution time of the local optimization test cases is recorded. The execution time of the locally optimized test cases is compared with the pre-obtained average execution time; In response to determining that the execution time exceeds the average execution time, the local optimization test case is used as the global optimization test case; In response to determining that the execution time is less than the average execution time, the position of the local optimization test case in the coordinate system is updated, and the updated local optimization test case is substituted into the program branch for execution again.
4. The method according to claim 3, characterized in that, In response to determining that the execution time is less than the average execution time, the position of the local optimization test case in the coordinate system is updated, and the updated local optimization test case is re-introduced into the program branch for execution, including: The velocity and position of the local optimization test case in the coordinate system are updated using the following formula, and the updated local optimization test case is then substituted back into the program branch for execution: in, Let be the velocity of the particle in branch i. Let be the position of the particle in branch i, α be the constraint factor, J be the historical local optimum, k be the global optimum, and c1 and c2 be acceleration constants used to adjust the weight of the historical local optimum J to the global optimum k. The change factor is a random value between 0 and 1. Let i be the local optimal position of branch i.
5. The method according to claim 3, characterized in that, The average execution time is obtained through the following operations: Obtain the execution time of each of the multiple initial test cases; In response to determining that the execution time of one of the plurality of initial test cases is less than a preset time threshold, the execution time of the plurality of initial test cases is obtained, and the average execution time is calculated based on the execution time of the plurality of initial test cases.
6. A white-box testing apparatus for functional safety software, characterized in that, include: The setting module is configured to set multiple initial test cases based on the value range of the selection branches contained in the program flowchart of the functional safety software, wherein the multiple initial test cases correspond to multiple positions in the coordinate system. The execution module is configured to obtain the execution time of each of the multiple initial test cases by substituting them into the selected branch for execution. The determination module is configured to, in response to determining that the execution time of one of the plurality of initial test cases is greater than a preset time threshold, use that initial test case as a local optimization test case; The iterative module is configured to iteratively update the multiple positions based on the target position corresponding to the local optimization test case among the multiple positions, using the multiple initial test cases as particle swarms, to obtain the global optimization test case of the multiple initial test cases; The testing module is configured to perform white-box testing on the functional safety software using the globally optimized test cases; The step of determining that the execution time of one of the plurality of initial test cases is greater than a preset time threshold, and using that initial test case as a local optimization test case, includes: If the execution time of one of the multiple initial test cases is determined to be greater than a preset time threshold, the iteration number of the initial test case is detected. In response to determining that the number of iterations exceeds a preset iteration threshold, the initial test case is used as the local optimization test case; In response to determining that the number of iterations does not exceed a preset iteration threshold, the initial test case is substituted back into the selected branch for execution to obtain the locally optimized test case.
7. The apparatus according to claim 6, characterized in that, The iterative module includes: In response to determining that the number of local optimization test cases is greater than a preset threshold, the particle swarm algorithm is iterated based on the local optimization test cases; In response to determining that the number of local optimization test cases is less than a preset threshold, the local optimization test cases are used as global optimization test cases.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the method as claimed in any one of claims 1 to 5.
9. A non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform the method of any one of claims 1 to 5.
Citation Information
Patent Citations
Application monitoring rule test method and device
CN111274121A
Particle-swarm-based automatic generation method for vehicle control strategy test case
CN112099468A