Security test data generation method and device
By generating current test cases and using neuron output values to calculate coverage, high-coverage test cases are screened out, solving the problem that traditional methods cannot be applied to software testing of neural network models, and realizing high-quality intelligent model security test data generation.
Patent Information
- Application Number
- CN202510653892.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-21
- Publication Date
- 2025-09-26
AI Technical Summary
Traditional coverage calculation methods cannot be effectively applied to software based on neural network models, resulting in the inability to generate high-quality intelligent model security test data.
By generating current test cases and calculating coverage using neuron output values, test cases that can improve coverage are screened out and added to the seed queue to maintain high-quality test data.
It improves the coverage of intelligent model security testing, generates high-quality test cases, and solves problems that traditional methods cannot apply.
Smart Images

Figure CN120705032A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent safety technology, and in particular to a method and device for generating safety test data. Background Art
[0002] In traditional software engineering, coverage is used to measure the degree to which software testing covers and executes code and execution paths. Software test coverage refers to the ratio of the software program's code and execution paths that are tested during software testing. When testing a software function, the higher the quality of the test cases used, the higher the coverage and the better the testing results. Similarly, the higher the coverage, the higher the quality of the test cases.
[0003] In recent years, with the continuous development and maturity of new technologies such as big data and artificial intelligence, artificial intelligence (AI) technologies, centered around machine learning, have begun to be deeply applied to all aspects of the economy and daily life, and corresponding intelligent models have been widely used in various fields. To improve the security of intelligent models and minimize unexpected errors, they require security testing.
[0004] However, traditional software programming involves programming to define clear algorithmic rules, then calculating a specific output based on a given input. Artificial intelligence, on the other hand, first inputs data and results, with the intermediate rules learned during the AI training process. This shift in programming paradigm leads to a degree of randomness in the output of AI programs and a high degree of data dependence, making them impractical for security testing using traditional methods. Traditional coverage metrics track executed lines of code and branches. In contrast, neural network models are constructed from layers of neural networks (e.g., convolutional layers, fully connected layers, etc.). Each layer consists of neurons, their values, connections between neurons, weights, and activation functions. The underlying implementation of these elements may contain numerous branching statements, but most of these statements are solely related to the neural network's structure and do not affect the execution of different branches depending on the input. For different inputs, it is very likely that a neural network will execute the same code branch but still exhibit different behavior. Therefore, there are essential differences between traditional software and software based on neural network models in programming paradigms and development processes. When conducting security testing on intelligent models, it is impossible to directly apply traditional software testing techniques to software or intelligent agents based on neural network models, and thus it is impossible to generate high-quality intelligent model security test data. This makes testing software based on neural network models a new challenge.
[0005] In view of this, overcoming the defects of the prior art is an urgent problem to be solved in this technical field. Summary of the Invention
[0006] The technical problem to be solved by the present invention is to provide a security test data generation method and device, the purpose of which is to provide a coverage calculation method for the parameters and weights of an intelligent model, generate a current test case based on the original description sample in the seed queue, input the current test case into the intelligent model, and calculate the current coverage of the current test case based on the neuron output value generated by the intelligent model during the calculation process. The neuron output value is used to focus on the activation of the neuron level and the neural network level of the intelligent model to reflect the coverage of the parameters and weights of the current test case; the current coverage is used to screen the current test case, and the current test case that can make the current coverage higher than the historical coverage is selected, thereby maintaining the quality of the target test data in the seed queue at a high level, solving the problem that high-quality test cases cannot be obtained due to the inability to use the coverage calculation method in traditional software engineering when performing security testing on intelligent models.
[0007] The present invention adopts the following technical solutions: In a first aspect, the present invention provides a method for generating security test data, comprising: Generate the corresponding current test case based on the original description samples in the seed queue; Inputting the current test case into the intelligent model to obtain neuron output values generated by the intelligent model during the calculation process; determining the current coverage of the current test case based on the neuron output values; Input the current test case into the target program for execution; when no operational exception occurs, obtain historical coverage of other test cases generated based on the original description sample from the seed queue; when the current coverage is greater than the historical coverage, use the current test case as a new description sample and add the new description sample to the seed queue; When the number of use case generation times of all original description samples in the seed queue exceeds a mutation number threshold, all description samples in the seed queue are determined as target test data.
[0008] Furthermore, generating a corresponding current test case according to the original description sample in the seed queue includes: Determining data characteristics and / or quantity thresholds based on task type characteristics of the target program; Filtering at least one original description sample from a user-given sample set according to data characteristics and / or quantity thresholds; Determining a variation mode based on the data type of the original description sample; The original description sample is adjusted according to the mutation method to generate multiple current test cases different from the original description sample based on the original description sample without changing the semantic information of the original description sample; wherein the number of times the original description sample is adjusted is less than or equal to the mutation number threshold.
[0009] Furthermore, the step of selecting at least one original description sample from a sample set given by a user according to data characteristics and / or quantity thresholds includes: Screening out user-given samples that meet the data characteristics from the user-given sample set, determining them as original description samples, and adding the original description samples to a seed queue; And / or, multiple user-given samples in the user-given sample set are determined as original description samples, and the original description samples are added to a seed queue; wherein the number of the original description samples is less than or equal to the number threshold.
[0010] Furthermore, determining the current coverage of the current test case according to the neuron output value includes: Calculating the current coverage rate according to the first coverage rate formula; The first coverage formula is: ; in, represents the upper boundary area of the neuron, represents the lower boundary area of the neuron, Represents the test case set of the intelligent model input, the test case set Include multiple current test cases , , is the total number of neuron boundaries of the intelligent model; represents a set of neurons of the intelligent model, Represents the total number of neurons of the intelligent model; , , is the upper bound of the neuron’s output, is the lower bound of the neuron’s output, Represents the first test function that is executed in the given current test case Return to next The output value of a neuron.
[0011] Furthermore, determining the current coverage of the current test case according to the neuron output value includes: Calculating the current coverage rate according to a second coverage rate formula; The second coverage formula is:
[0012] in, Represents a test case suite Current test case in The second coverage rate indicates the maximum output value of the neuron in each neural network layer. neurons, is the total number of neuron boundaries of the intelligent model, Indicates that the current test case is given When, The neural network layer with the largest output value neurons.
[0013] Furthermore, determining the current coverage of the current test case according to the neuron output value includes: When the neuron output value is greater than an activation threshold, determining that the neuron corresponding to the neuron output value is in an activated state; Obtaining the number of activated neurons in the neural network of the intelligent model; Obtaining the total number of neurons in the neural network; The ratio of the activation number to the total number of neurons is determined as the average neuron coverage of the intelligent model during the calculation process; and the average neuron coverage is determined as the current coverage.
[0014] Furthermore, after inputting the current test case into the target program for execution, the method further includes: Detecting whether the target program has an abnormal operation; When a running exception occurs, the current test case is discarded; After obtaining the historical coverage of other test cases generated based on the original description sample from the seed queue when no operational exception occurs, the method further includes: When the current coverage is less than or equal to the historical coverage, the current test case is discarded so that the original description sample can be adjusted again to generate a test case different from the original description sample and the current test case based on the original description sample without changing the semantic information of the original description sample.
[0015] Further, a first current coverage is calculated according to the first coverage formula, a second current coverage is calculated according to the second coverage formula, and the average neuron coverage is determined as a third current coverage; When the current coverage is greater than the historical coverage, taking the current test case as a new description sample and adding the new description sample to the seed queue includes: Obtaining a first historical coverage, a second historical coverage, and a third historical coverage of the other test cases; wherein the first historical coverage is calculated according to the first coverage formula, the second historical coverage is calculated according to the second coverage formula, and the third historical coverage is the average neuron coverage of the other test cases; When the first current coverage is greater than the first historical coverage, the second current coverage is greater than the second historical coverage, and the third current coverage is greater than the third historical coverage, the current test case is used as a new description sample and the new description sample is added to the seed queue.
[0016] In a second aspect, the present invention further provides a security test data generating device, comprising: At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor to execute the security test data generating method described in the first aspect.
[0017] In a third aspect, the present invention further provides a non-volatile computer storage medium, wherein the computer storage medium stores computer executable instructions, which are executed by one or more processors to complete the security test data generation method described in the first aspect.
[0018] In a fourth aspect, a chip is provided, comprising: a processor and an interface, for calling and running a computer program stored in a memory, and executing the security test data generation method as in the first aspect.
[0019] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer or a processor, causes the computer or the processor to execute the security test data generation method according to the first to fourth aspects and any one of the above.
[0020] In a sixth aspect, the present invention further provides a security test data generation system, comprising the security test data generation device as in the second aspect, and using the security test data generation method as described in the first aspect to complete the interaction of the security test data generation device of the second aspect.
[0021] Different from the prior art, the present invention has at least the following beneficial effects: The present invention provides a coverage calculation method for parameters and weights of an intelligent model. The method generates a current test case based on an original description sample in a seed queue. After the current test case is input into the intelligent model, the current coverage of the current test case is calculated based on the neuron output value generated by the intelligent model during the calculation process. The neuron output value is used to focus on the activation status of the neuron level and the neural network level of the intelligent model to reflect the coverage of the parameters and weights of the current test case. The current coverage is used to screen the current test case, and the current test case that can make the current coverage higher than the historical coverage is selected, thereby maintaining the quality of the target test data in the seed queue at a high level. This solves the problem of not being able to obtain high-quality test cases due to the inability to use the coverage calculation method in traditional software engineering when performing security testing on intelligent models. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. Those skilled in the art can also derive other drawings based on these drawings without inventive effort.
[0023] Figure 1 This is a flow chart of a method for generating security test data provided by an embodiment of the present invention; Figure 2 This is a flow chart of another method for generating security test data provided by an embodiment of the present invention; Figure 3 This is a schematic diagram of a workflow for adding a new description sample to a seed queue provided by an embodiment of the present invention; Figure 4 is a flow chart of step 10 provided in an embodiment of the present invention; Figure 5 is a flow chart of step 102 provided in an embodiment of the present invention; Figure 6 is a flow chart of step 20 provided in an embodiment of the present invention; Figure 7 It is a schematic diagram of the architecture of a security test data generating device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0025] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0026] Unless the context requires otherwise, throughout the specification and claims, the term "including" is to be interpreted as meaning open inclusion, that is, "including, but not limited to". In the description of the specification, the terms "one embodiment", "some embodiments", "exemplary embodiments", "example", "specific example" or "some examples" and the like are intended to indicate that the specific features, structures, materials or characteristics associated with the embodiment or example are included in at least one embodiment or example of the present disclosure. The schematic representation of the above terms does not necessarily refer to the same embodiment or example. In addition, the specific features, structures, materials or characteristics may be included in any one or more embodiments or examples in any appropriate manner, that is, although they may be carried in the embodiments or examples of the above terms due to reasons such as the order and position of appearance, it is not limited to that they can be carried in combination by one embodiment or example.
[0027] In the description of the present invention, it should be understood that the terms "center", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", etc., indicating the orientation or position relationship, are based on the orientation or position relationship shown in the accompanying drawings, and are only for the convenience of describing the present disclosure and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present disclosure.
[0028] In the description of the present invention, the terms "first" and "second" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present disclosure, unless otherwise specified, "multiple" means two or more. In addition, for example, the description may also use the method of adding "A" and "B" at the end to describe the same type of nouns as two independent individuals. In this case, the corresponding features defined as "A" and "B" are only used to distinguish the description purposes of the same type of individuals, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated.
[0029] When describing some embodiments, the expressions “coupled”, “coupled” and “connected” and their derivatives may be used. For example, when describing some embodiments, the term “connected” may be used to indicate that two or more components are in direct physical or electrical contact with each other. For another example, when describing some embodiments, the term “coupled” may be used to indicate that two or more components are in direct physical or electrical contact. However, the term “connected” or “coupled” may also mean that two or more components are not in direct contact with each other, but still cooperate or interact with each other, such as “optical coupling”, “wireless connection”, etc. The embodiments disclosed herein are not necessarily limited to the contents of the present invention.
[0030] In the description of the present invention, the expression "A and / or B" (where A and B are used to formally represent specific characteristic contents) is involved, and the corresponding expressions include the following three combinations: only A, only B, and a combination of A and B.
[0031] As used herein, "about," "substantially," or "approximately" includes the stated value and an average value that is within an acceptable range of deviation from the particular value as determined by one of ordinary skill in the art taking into account the measurements in question and errors associated with measurement of the particular quantity (i.e., limitations of the measurement system).
[0032] Example 1: As AI technology rapidly penetrates and spreads, the quality of its applications is receiving significant attention. AI models, algorithms, and data are vulnerable to noise, such as adversarial examples, leading to unexpected errors. In open deployment environments, especially in complex scenarios, intelligent models using AI technologies like deep learning are more susceptible to environmental changes, input uncertainty, and adversarial perturbations, leading to model failure. Therefore, identifying these potential threats is crucial to improve the security of intelligent models and enable their application in more security-critical scenarios. Highly reliable and comprehensive testing can make intelligent model applications more secure and convenient. However, such testing requires high-quality test cases. Therefore, generating high-quality test cases tailored to the security testing scenarios of intelligent models is crucial.
[0033] In traditional software engineering, test case coverage is measured by tracking executed lines of code and branches. However, because the neural network structure of intelligent models is constructed from layers of neural networks (convolutional layers, fully connected layers, etc.), each layer consists of neurons, their values, connections between neurons, weights, and activation functions. The underlying implementation of these components may contain a large number of branching statements, but most of this is related only to the neural network structure and does not affect the execution of different branches based on the input test cases. When inputting different test cases, the neural network may execute the same code branch but still produce different behaviors and output results. Therefore, there are fundamental differences in the programming paradigms and development processes between traditional software and intelligent model-based software. Traditional software engineering testing techniques cannot be directly applied to intelligent model-based software or agents, making testing intelligent model-based software a new challenge.
[0034] In order to solve the above problems, Figure 1 As shown, an embodiment of the present invention provides a method for generating security test data, including: Step 10: Generate the corresponding current test case based on the original description samples in the seed queue.
[0035] The original description sample is a test case provided by the user for the intelligent model. In the initial state, the seed queue includes multiple original description samples. The embodiment of the present invention generates a new current test case by adjusting the original description samples.
[0036] Step 20: Input the current test case into the intelligent model to obtain the neuron output value generated by the intelligent model during the calculation process; determine the current coverage of the current test case based on the neuron output value.
[0037] Convolutional Neural Networks (CNNs) are suitable for processing data with a grid structure, such as image and speech data. The intelligent model targeted by the present invention is primarily a CNN model. In other words, in an optional embodiment, the network model structure of the intelligent model is a CNN. A CNN model is constructed from layers of neural networks (convolutional layers, fully connected layers, etc.). Each neural layer is composed of neurons, their values, connections between neurons, weights, and activation functions.
[0038] After the test case is input into the intelligent model, the intelligent model begins to perform iterative calculations. During each round of iteration, each neuron will generate a corresponding neuron output value. The embodiment of the present invention uses the neuron output value to calculate the current coverage of the current test case. The specific calculation method will be explained below.
[0039] Step 30: Input the current test case into the target program for execution; when no operational exception occurs, obtain the historical coverage of other test cases generated based on the original description sample from the seed queue; when the current coverage is greater than the historical coverage, use the current test case as a new description sample and add the new description sample to the seed queue.
[0040] In an embodiment of the present invention, to increase the diversity of generated test cases, multiple current test cases are generated based on each original description sample in the seed queue. Other test cases generated based on an original description sample refer to test cases other than the current test case generated from the same original description sample. For example, if test case 1 and test case 2 have already been generated from original description sample A, when test case 3 is generated, test case 3 becomes the current test case, and accordingly, test case 1 and test case 2 become other test cases.
[0041] After inputting the current test case into the target program for execution, the method further includes: detecting whether the target program has an operational anomaly; and discarding the current test case if an operational anomaly occurs. In an optional embodiment, common operational anomalies are crashes or infinite loops. When an operational anomaly occurs, the current test case is added to a crash set to discard the current test case.
[0042] Step 40: When the number of use case generation times of all original description samples in the seed queue exceeds the mutation number threshold, all description samples in the seed queue are determined as target test data.
[0043] The mutation threshold is selected by those skilled in the art based on specific usage scenarios.
[0044] The embodiment of the present invention screens the test cases in the seed queue based on coverage. When the current coverage is greater than the historical coverage, the current test case is used as a new description sample and added to the seed queue; if the number of times the original description sample is adjusted does not exceed the mutation number threshold, the original description sample is adjusted again to generate a new current test case, its current coverage is re-determined, and whether to add it to the seed queue is determined based on its coverage; if the number of times the original description sample is adjusted exceeds the mutation number threshold, other original description samples in the seed queue are used to continue to generate the corresponding current test case, calculate its current coverage, and determine whether to add it to the seed queue accordingly. When the current coverage is less than or equal to the historical coverage, the current test case is discarded so that the original description sample can be adjusted again to generate a test case different from the original description sample and the current test case based on the original description sample without changing the semantic information of the original description sample.
[0045] The present invention provides a coverage calculation method for parameters and weights of an intelligent model. The method generates a current test case based on an original description sample in a seed queue. After the current test case is input into the intelligent model, the current coverage of the current test case is calculated based on the neuron output value generated by the intelligent model during the calculation process. The neuron output value is used to focus on the activation status of the neuron level and the neural network level of the intelligent model to reflect the coverage of the parameters and weights of the current test case. The current coverage is used to screen the current test case, and the current test case that can make the current coverage higher than the historical coverage is selected, thereby maintaining the quality of the target test data in the seed queue at a high level. This solves the problem of not being able to obtain high-quality test cases due to the inability to use the coverage calculation method in traditional software engineering when performing security testing on intelligent models.
[0046] The overall process of generating target test data in the embodiment of the present invention is as follows: Figure 2 The workflow for adding new described samples to the seed queue is as follows Figure 3 As shown, it includes the following steps: Seed distillation: Filter out suitable seeds from the user-given sample set as original description samples, and form a seed queue with the original description samples.
[0047] Seed selection: Select an original description sample from the seed queue according to a certain strategy (i.e., Figure 3 in the seeds).
[0048] Energy allocation: Determine the threshold of the number of mutations used to generate test cases using the original description sample (i.e., Figure 3 energy distribution in the Test case generation: Test cases are generated using either mutation or generation algorithms. Mutation algorithms generate a corresponding number of test cases from the original description samples, depending on the energy (i.e., the mutation threshold). Generation algorithms generate a certain number of test cases from the original description samples.
[0049] The following is a detailed introduction to the processes of seed distillation, seed selection, energy allocation, and test case generation. Figure 4 As shown, in step 10, generating the corresponding current test case according to the original description sample in the seed queue includes: Step 101: Determine data characteristics and / or quantity thresholds according to the task type characteristics of the target program.
[0050] Step 102: Filter out at least one original description sample from a sample set given by the user according to data characteristics and / or quantity thresholds.
[0051] Seed distillation is the process of selecting seeds (i.e., original description samples) suitable for the target program from a large number of initial seeds (i.e., a set of user-provided samples). The quality of the initial seeds directly impacts the effectiveness of fuzz testing; good seeds maximize error coverage. This paper uses conditional screening to perform seed distillation, selecting original description samples that meet the criteria from a large number of initial seeds and adding them to a seed queue.
[0052] Seed selection involves selecting appropriate raw description samples from a seed queue according to a specific strategy for subsequent mutation. This paper employs a random selection strategy to randomly select raw description samples from a seed queue. It should be noted that sequentially selecting raw description samples from a seed queue is considered a special case of random seed selection.
[0053] Step 103: Determine a mutation method based on the data type of the original description sample.
[0054] Based on the characteristics of the original description sample selected in the seed selection step, a method for adjusting it (i.e., a mutation method) is determined. For example, when the original description sample is image data, the mutation method may be to change the brightness and contrast of the original description sample.
[0055] Step 104: Adjust the original description sample according to the mutation method to generate multiple current test cases different from the original description sample based on the original description sample without changing the semantic information of the original description sample; wherein the number of times the original description sample is adjusted is less than or equal to the mutation number threshold.
[0056] Energy allocation refers to the multiple mutation opportunities granted to selected original description samples during mutation. To increase the diversity of the resulting target test data, multiple mutation attempts are performed on an original description sample. After each mutation, the sample is tested to determine whether the current coverage has improved. If the number of mutations exceeds a threshold, the original description sample is no longer mutated to avoid wasting resources.
[0057] During the test case generation process, the present invention employs a domain-knowledge-based mutation method, mutating the seed based on the characteristics of the input (i.e., the mutation method is determined based on the data type of the original description sample), without changing the seed's semantics. For example, when the original description sample is image data, mutation methods can include brightness changes, contrast changes, translation, scaling, horizontal shearing, rotation, blurring, fog effects, and rain effects, without changing the image's meaning. The implementation steps of these mutation methods are determined by those skilled in the art based on specific usage scenarios and are not limited here. Fuzz testing is introduced, utilizing methods such as geometric changes in image data and adversarial sample noise to generate new test cases to expand the seed queue. Fuzz testing is a method for discovering software vulnerabilities by providing unexpected input to the target system and monitoring for abnormal results.
[0058] In order to illustrate the process of filtering out original description samples from the user-given sample set, as shown in Figure 5 As shown, step 102 includes: Step 1021: Filter out user-given samples that meet the data characteristics from the user-given sample set, determine them as original description samples, and add the original description samples to the seed queue.
[0059] Step 1022: and / or, determining multiple user-given samples in the user-given sample set as original description samples, and adding the original description samples to a seed queue; wherein the number of the original description samples is less than or equal to the number threshold.
[0060] This embodiment of the present invention performs seed distillation by using data types or by setting a threshold based on the task the intelligent model is required to complete. For example, when the intelligent model is required to complete an image recognition task and the data type is Portable Network Graphics (PNG), images with a resolution greater than 224*224 are selected. That is, if a user-given sample set contains multiple PNG images, those with a resolution greater than 224*224 are identified as original description samples and added to the seed queue.
[0061] The security test data generation method of the embodiment of the present invention preliminarily screens and generates current test cases based on different types of intelligent models, the tasks that the intelligent models need to complete, and the characteristics and types of the original description samples. It can adapt to a variety of data types and is suitable for generating security test data for images, text, voice, and time series data, and has high flexibility.
[0062] After generating the current test case, the embodiment of the present invention inputs it into the intelligent model to obtain the neuron output values of the neurons at each neural network layer in the intelligent model. The embodiment of the present invention provides three neural network coverage test indicators calculated based on neuron output values to guide test case screening. The specific calculation methods of the three neural network coverage test indicators are described below: As the basic unit of a neural network, neurons play an important role in the realization of neural network functions. Abnormal behavior of a single neuron may cause the intelligent model to fail. In the embodiment of the present invention, the coverage rate at the neuron level focuses on the activation of a single neuron and is measured by neuron coverage. The calculation process of neuron coverage is as follows: Figure 6 As shown, in step 20, determining the current coverage of the current test case according to the neuron output value includes: Step 201: When the neuron output value is greater than an activation threshold, it is determined that the neuron corresponding to the neuron output value is in an activated state.
[0063] The activation threshold is selected by those skilled in the art according to the specific usage scenario. When the neuron output value is less than or equal to the activation threshold, it is determined that the neuron corresponding to the neuron output value is in an inactive state. Step 202: Obtain the number of activated neurons in the neural network of the intelligent model.
[0064] Step 203: Obtain the total number of neurons in the neural network.
[0065] Step 204: Determine the ratio of the activation number to the total number of neurons as the average neuron coverage of the intelligent model during the calculation process; and determine the average neuron coverage as the current coverage.
[0066] The calculation formula of neuron coverage is as follows:
[0067] in, represents the number of neurons in the neural network that are activated. Represents the total number of neurons in the neural network.
[0068] In the intelligent model, the activation of neurons is related to the boundaries in the input space. When the input test case approaches the boundary of neuron activation, the behavior of the neuron may change. Therefore, understanding the boundary conditions of neurons in the input space is very important for evaluating the robustness and reliability of the neural network. In order to use the target test data finally generated to test whether the intelligent model fails, the embodiment of the present invention also provides a first coverage formula for focusing on the boundary conditions of a single neuron in the input space; specifically, in step 20, the current coverage of the current test case is determined according to the neuron output value, including: The current coverage is calculated according to a first coverage formula.
[0069] The first coverage formula is: .
[0070] in, represents the upper boundary area of the neuron, represents the lower boundary area of the neuron, Represents the test case set of the intelligent model input, the test case set Include multiple current test cases , , is the total number of neuron boundaries of the intelligent model; represents a set of neurons of the intelligent model, Represents the total number of neurons of the intelligent model; , , is the upper bound of the neuron’s output, is the lower bound of the neuron’s output, Represents the first test function that is executed in the given current test case Return to next The output value of a neuron.
[0071] Among them, the first test function In the given Downward return neuron Output value for the current test case ,like , it means that the neuron falls in the boundary area.
[0072] The first coverage measures how much of the boundary area is covered by the test case set, which is defined as the ratio of the number of covered boundary instances to the total number of boundary instances, as shown in the above formula.
[0073] The embodiment of the present invention further provides a second coverage rate for focusing on neuron activation within a neural network layer. In step 20, determining the current coverage rate of the current test case based on the neuron output value includes: The current coverage is calculated according to the second coverage formula. The second coverage is used to measure how many neurons in each layer have been the most active neurons. The second coverage is defined as the ratio of the total number of the most active neurons in each layer to the total number of neurons in the neural network. The second coverage formula is:
[0074] in, Represents a test case suite Current test case in The second coverage rate indicates the maximum output value of the neuron in each neural network layer. neurons, is the total number of neurons in the intelligent model, Indicates that the current test case is given When, The neural network layer with the largest output value neurons.
[0075] In order to maintain the quality of the target test data in the seed queue at a high level, in one embodiment, a first current coverage of the current test case may be calculated according to the first coverage formula, a second current coverage of the current test case may be calculated according to the second coverage formula, and an average neuron coverage of the current test case may be calculated according to steps 201 to 204, so as to determine the average neuron coverage as a third current coverage of the current test case. In an optional embodiment, as long as the first current coverage is greater than the first historical coverage, or the second current coverage is greater than the second historical coverage, or the third current coverage is greater than the third historical coverage, that is, whenever one of the three current coverages is greater than the corresponding historical coverage, the current test case is used as a new description sample and the new description sample is added to the seed queue.
[0076] In order to maintain the quality of the target test data in the seed queue at a higher level, in another embodiment, in step 30, when the current coverage is greater than the historical coverage, taking the current test case as a new description sample and adding the new description sample to the seed queue includes: Obtain a first historical coverage rate, a second historical coverage rate, and a third historical coverage rate for the other test cases; wherein the first historical coverage rate is calculated according to the first coverage rate formula, the second historical coverage rate is calculated according to the second coverage rate formula, and the third historical coverage rate is the average neuron coverage rate of the other test cases. For the same coverage rate, the current coverage rate is calculated in the same manner as the historical coverage rate, and will not be further described here. The only difference is that the current coverage rate is calculated as the current test case, while the historical coverage rate is calculated as the other test cases. When the first current coverage rate is greater than the first historical coverage rate, the second current coverage rate is greater than the second historical coverage rate, and the third current coverage rate is greater than the third historical coverage rate, the current test case is used as a new description sample and added to the seed queue. That is, only when all three current coverage rates meet the requirement of "the current coverage rate is greater than the corresponding historical coverage rate" is the current test case used as a new description sample and added to the seed queue.
[0077] The present invention constructs three neural network coverage test indicators (i.e., neuron coverage, first coverage, and second coverage), and uses these three neural network coverage test indicators to screen the current test cases generated each time, thereby improving the coverage of the neural network structure of the intelligent model by the final generated target test data. By controlling the quality of the test cases, the effect of security testing on the intelligent model is improved, and the security risk of the intelligent model is greatly reduced.
[0078] Example 2: like Figure 7 FIG. 1 is a schematic diagram of the architecture of a security test data generating device according to an embodiment of the present invention. The security test data generating device according to this embodiment includes one or more processors 21 and a memory 22. Figure 7 A processor 21 is taken as an example.
[0079] The processor 21 and the memory 22 may be connected via a bus or other means. Figure 7 The bus connection is taken as an example.
[0080] Memory 22, as a nonvolatile computer-readable storage medium, can be used to store nonvolatile software programs and nonvolatile computer-executable programs, such as the security test data generation method in this embodiment. Processor 21 executes the security test data generation method by running the nonvolatile software programs and instructions stored in memory 22.
[0081] The memory 22 may include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state memory device. In some embodiments, the memory 22 may optionally include a memory remotely located relative to the processor 21, and such remote memory may be connected to the processor 21 via a network. Examples of such networks include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0082] The program instructions / modules are stored in the memory 22, and when executed by the one or more processors 21, the security test data generation method in the above embodiment is executed, for example, each step of the security test data generation method in the embodiment of the present invention described above is executed.
[0083] An embodiment of the present invention further provides a non-volatile computer storage medium, wherein the computer storage medium stores computer executable instructions, and the computer executable instructions are executed by one or more processors, for example Figure 7 A processor 21 can enable the one or more processors to execute the security test data generation method in the specific embodiment of the present invention, for example, to execute the various steps of the security test data generation method of the embodiment of the present invention described above; it can also realize Figure 7 The various modules and units described above; or executing the security test data generating method in the specific embodiment of the present invention, for example, executing the various steps of the security test data generating method of the embodiment of the present invention described above; it can also be realized Figure 7 The various modules and units described.
[0084] It is worth noting that the information interaction, execution process, etc. between the modules and units within the above-mentioned devices and systems are based on the same concept as the processing method embodiment of the present invention. The specific content can be found in the description of the method embodiment of the present invention and will not be repeated here.
[0085] Those skilled in the art will understand that all or part of the steps in the various methods of the embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, which may include: read-only memory (ROM), random access memory (RAM), a disk or an optical disk, etc.
[0086] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for generating security test data, characterized in that: include: Generate the corresponding current test case based on the original description samples in the seed queue; Inputting the current test case into the intelligent model to obtain the neuron output value generated by the intelligent model during the calculation process; Determining the current coverage of the current test case according to the neuron output value; Input the current test case into the target program for execution; when no operational exception occurs, obtain historical coverage of other test cases generated based on the original description sample from the seed queue; when the current coverage is greater than the historical coverage, use the current test case as a new description sample and add the new description sample to the seed queue; When the number of use case generation times of all original description samples in the seed queue exceeds a mutation number threshold, all description samples in the seed queue are determined as target test data.
2. The method for generating security test data according to claim 1, wherein: Generating the corresponding current test case according to the original description sample in the seed queue includes: Determining data characteristics and / or quantity thresholds based on task type characteristics of the target program; Filtering at least one original description sample from a user-given sample set according to data characteristics and / or quantity thresholds; Determining a variation mode based on the data type of the original description sample; The original description sample is adjusted according to the mutation method to generate multiple current test cases different from the original description sample based on the original description sample without changing the semantic information of the original description sample; wherein the number of times the original description sample is adjusted is less than or equal to the mutation number threshold.
3. The method for generating security test data according to claim 2, wherein: The step of selecting at least one original description sample from a sample set given by a user according to data characteristics and / or quantity thresholds includes: Screening out user-given samples that meet the data characteristics from the user-given sample set, determining them as original description samples, and adding the original description samples to a seed queue; And / or, multiple user-given samples in the user-given sample set are determined as original description samples, and the original description samples are added to a seed queue; wherein the number of the original description samples is less than or equal to the number threshold.
4. The method for generating security test data according to claim 1, wherein: Determining the current coverage of the current test case according to the neuron output value includes: Calculating the current coverage rate according to the first coverage rate formula; The first coverage formula is: ; in, represents the upper boundary area of the neuron, represents the lower boundary area of the neuron, Represents the test case set of the intelligent model input, the test case set Include multiple current test cases , , is the total number of neuron boundaries of the intelligent model; represents a set of neurons of the intelligent model, Represents the total number of neurons of the intelligent model; , , is the upper bound of the neuron’s output, is the lower bound of the neuron’s output, Represents the first test function that is executed in the given current test case Return to next The output value of a neuron.
5. The method for generating security test data according to claim 1, wherein: Determining the current coverage of the current test case according to the neuron output value includes: Calculating the current coverage rate according to a second coverage rate formula; The second coverage formula is: in, Represents a test case suite Current test case in The second coverage rate indicates the maximum output value of the neuron in each neural network layer. neurons, is the total number of neurons in the intelligent model, Indicates that the current test case is given When, The neural network layer with the largest output value neurons.
6. The method for generating security test data according to claim 1, wherein: Determining the current coverage of the current test case according to the neuron output value includes: When the neuron output value is greater than an activation threshold, determining that the neuron corresponding to the neuron output value is in an activated state; Obtaining the number of activated neurons in the neural network of the intelligent model; Obtaining the total number of neurons in the neural network; The ratio of the activation number to the total number of neurons is determined as the average neuron coverage of the intelligent model during the calculation process; and the average neuron coverage is determined as the current coverage.
7. The method for generating security test data according to any one of claims 1 to 6, characterized in that: After inputting the current test case into the target program for execution, the method further includes: Detecting whether the target program has an abnormal operation; When a running exception occurs, the current test case is discarded; After obtaining the historical coverage of other test cases generated based on the original description sample from the seed queue when no operational exception occurs, the method further includes: When the current coverage is less than or equal to the historical coverage, the current test case is discarded so that the original description sample can be adjusted again to generate a test case different from the original description sample and the current test case based on the original description sample without changing the semantic information of the original description sample.
8. The method for generating security test data according to any one of claims 1 to 6, characterized in that: Calculate the first current coverage rate according to the first coverage rate formula, calculate the second current coverage rate according to the second coverage rate formula, and determine the average neuron coverage rate as the third current coverage rate; When the current coverage is greater than the historical coverage, taking the current test case as a new description sample and adding the new description sample to the seed queue includes: Obtaining a first historical coverage, a second historical coverage, and a third historical coverage of the other test cases; wherein the first historical coverage is calculated according to the first coverage formula, the second historical coverage is calculated according to the second coverage formula, and the third historical coverage is the average neuron coverage of the other test cases; When the first current coverage is greater than the first historical coverage, the second current coverage is greater than the second historical coverage, and the third current coverage is greater than the third historical coverage, the current test case is used as a new description sample and the new description sample is added to the seed queue.
9. A security test data generating device, characterized in that: The security test data generating device includes at least one processor and a memory, and the at least one processor and the memory are connected via a data bus. The memory stores instructions that can be executed by the at least one processor. After being executed by the processor, the instructions are used to implement the security test data generating method described in any one of claims 1-8.
10. A non-volatile computer storage medium, characterized in that The computer storage medium stores computer-executable instructions, and the computer-executable instructions are executed by one or more processors to complete the security test data generating method according to any one of claims 1 to 8.