Test instruction generation method, apparatus and device, and computer program product

By generating the abstract syntax tree of test cases and the target language learning model, the test cases are automatically converted into test instructions, which solves the problem of long smart card testing time and improves testing efficiency.

CN118796199APending Publication Date: 2024-10-18CHINA MOBILE M2M +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410259791.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-07
Publication Date
2024-10-18

Smart Images

  • Figure CN118796199A_ABST
    Figure CN118796199A_ABST
Patent Text Reader

Abstract

The invention provides a test instruction generation method, device and equipment and a computer program product, and the method comprises the steps: generating an abstract syntax tree of a test case, recognizing each conditional statement node in the abstract syntax tree, and determining a target language learning model matched with each conditional statement node by using nested parameters included in each conditional statement node, and identifying variables included in the conditional statement nodes by using the target language learning model, and finally generating a test instruction of a test code corresponding to the conditional statement nodes based on the variables. Visibly, by means of the abstract syntax tree and the target language learning model, the test case is automatically converted into the test instruction, and compared with the process of arranging the test case into the test instruction by means of the related technology, the test efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the technical field of Internet of Things, and specifically relates to a test instruction generation method, device, equipment and computer program product. Background Art

[0002] There are many types of smart cards, such as financial cards, IoT cards, and telecommunication cards. With the rapid development of smart cards, the complexity, security requirements, and machine-card compatibility of smart cards are increasing, which puts higher requirements on smart card testing.

[0003] In the related art, when testing a smart card, a test script is written based on the smart card platform, and then a test suite is manually written according to the test script, and the smart card is tested using the test suite, wherein the test suite is a collection of APDU (Application Protocol data unit) test instructions. However, the process of manually arranging the test script into a test suite will result in a problem of too long testing time and low testing efficiency for the smart card. Summary of the invention

[0004] The present application proposes a test instruction generation method, device, equipment and computer program product, which can alleviate the problem in the related art that the process of manually arranging test scripts into test suites will cause the test time of smart cards to be too long and the test efficiency to be low.

[0005] The first embodiment of the present application provides a test instruction generation method, including:

[0006] Generate an abstract syntax tree of test cases;

[0007] Traversing the abstract syntax tree to obtain a plurality of conditional statement nodes in the abstract syntax tree;

[0008] Determining a target language learning model that matches each of the conditional statement nodes based on a nesting parameter included in each of the conditional statement nodes; the nesting parameter is used to indicate the number of layers of conditional statements nested in the conditional statement node;

[0009] Based on the target language learning model, obtaining variables included in each of the conditional statement nodes;

[0010] Based on the variables, generating test instructions of the test codes corresponding to the conditional statement nodes;

[0011] Based on the test instructions corresponding to each of the conditional statement nodes, a final test instruction of the test case is obtained.

[0012] In one or more embodiments, determining a target language learning model matching each of the conditional statement nodes based on the nested parameters included in each of the conditional statement nodes includes:

[0013] Get the number of variable retrievals of each of the pre-configured multiple language learning models;

[0014] Based on the variable retrieval number, the target language learning model whose variable retrieval number is consistent with the nesting parameter is searched from the multiple language learning models.

[0015] In one or more embodiments, generating a test instruction of a test code corresponding to each of the conditional statement nodes based on the variable includes:

[0016] Obtaining variable items and variable values ​​included in the variable;

[0017] The parameter value of the parameter item that is the same as the variable item in the command header included in the preset APDU instruction template is set to be the variable value, so as to obtain the test instruction.

[0018] In one or more embodiments, obtaining the variables included in each of the conditional statement nodes based on the target language learning model includes:

[0019] Obtaining a variable relationship list corresponding to each of the conditional statement nodes output by the target language learning model;

[0020] The variables included in each of the conditional statement nodes are obtained from the variable relationship list.

[0021] In one or more embodiments, traversing the abstract syntax tree to obtain a plurality of conditional statement nodes in the abstract syntax tree includes:

[0022] From the abstract syntax tree, searching for multiple target nodes whose nodes include preset keywords;

[0023] The multiple target nodes are used as the multiple conditional statement nodes.

[0024] In one or more embodiments, before generating an abstract syntax tree of a test case, the method further includes:

[0025] The test case is obtained by retrieving the entry function of the test case.

[0026] In one or more embodiments, the method further comprises:

[0027] When determining the target language learning model that matches each of the conditional statement nodes, acquiring expected response data included in each of the conditional statement nodes based on the target language learning model;

[0028] Based on the variables, generating a test instruction of the test code corresponding to each of the conditional statement nodes, including:

[0029] The test instruction is generated based on the variable and the expected response data.

[0030] The second aspect of the present application provides a test instruction generating device, including:

[0031] A first generation module, used to generate an abstract syntax tree of a test case;

[0032] A first obtaining module, configured to traverse the abstract syntax tree to obtain a plurality of conditional statement nodes in the abstract syntax tree;

[0033] A determination module, configured to determine a target language learning model matching each of the conditional statement nodes based on a nesting parameter included in each of the conditional statement nodes; the nesting parameter is used to indicate the number of levels of conditional statements nested in the conditional statement node;

[0034] An acquisition module, used for acquiring the variables included in each of the conditional statement nodes based on the target language learning model;

[0035] A second generating module, used for generating a test instruction of a test code corresponding to each of the conditional statement nodes based on the variable;

[0036] The second obtaining module is used to obtain the final test instruction of the test case based on the test instruction corresponding to each of the conditional statement nodes.

[0037] A third aspect of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method described in the first aspect.

[0038] A fourth aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the program is executed by a processor to implement the method described in the first aspect.

[0039] The technical solution provided in the embodiments of the present application has at least the following technical effects or advantages:

[0040] In the embodiment of the present application, by generating an abstract syntax tree of the test case, identifying each conditional statement node in the abstract syntax tree, using the nested parameters included in each conditional statement node, determining the target language learning model that matches each conditional statement node, thereby using the target language learning model to identify the variables included in the conditional statement node, and finally generating the test instructions of the test code corresponding to the conditional statement node based on the variables. It can be seen that with the help of the abstract syntax tree and the target language learning model, the test case is automatically converted into a test instruction, which improves the test efficiency compared to the process of arranging the test case into a test instruction by means of the related art.

[0041] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] By reading the detailed description of the preferred embodiment below, other advantages and benefits will become clear to those of ordinary skill in the art. The accompanying drawings are only used for the purpose of illustrating the preferred embodiment and are not to be considered as limiting the present application. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0043] Figure 1 A schematic diagram of a flow chart of a test instruction generation method provided in an embodiment of the present application is shown;

[0044] Figure 2 A schematic diagram showing a script code provided by an embodiment of the present application is shown;

[0045] Figure 3 It shows that an embodiment of the present application provides a Figure 2 Schematic diagram of the abstract syntax tree generated by the script code;

[0046] Figure 4 A schematic diagram showing the recognition of code snippets by a language learning model provided in an embodiment of the present application is shown;

[0047] Figure 5 A schematic diagram showing the recognition of code snippets by a language learning model provided in an embodiment of the present application is shown;

[0048] Figure 6 A schematic diagram showing the recognition of code snippets by a language learning model provided in an embodiment of the present application is shown;

[0049] Figure 7 A schematic diagram of a conditional statement node provided in an embodiment of the present application is shown;

[0050] Figure 8 A schematic diagram of a conditional statement node provided in an embodiment of the present application is shown;

[0051] Fig. 9 A schematic diagram of a conditional statement node provided in an embodiment of the present application is shown;

[0052] Fig.10 Another schematic diagram of a flow chart of a test instruction generation method provided in an embodiment of the present application is shown;

[0053] Fig.11 A schematic diagram showing the structure of a test instruction generating device provided in an embodiment of the present application is shown;

[0054] Fig.12 A schematic diagram of the structure of an electronic device provided by an embodiment of the present application is shown;

[0055] Fig.13 A schematic diagram of a storage medium provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0056] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0057] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0058] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.

[0059] Currently, card vendors on the market develop smart cards based on mature smart card platforms, and at the same time develop test suites for testing smart cards based on the smart card platforms. Therefore, once the smart card platform used to develop smart cards changes, it is necessary to recreate a matching test suite.

[0060] In the related art, the process of creating a test suite is as follows:

[0061] 1. Write an application project based on the smart card platform, write the test script in the application project, and then compile the application file. Customize many APDU instructions in the test script to test different smart cards.

[0062] 2. Based on the application file, manually write and organize APDU test instructions, load APDU test instructions through the APDU instruction test tool, and download and install the APDU test instructions into the card reader. The card reader inputs the APDU test instructions into the smart card, so that the APDU test instructions complete the test of the smart card.

[0063] However, the process of manually arranging the test scripts into test suites will result in the problem of excessively long smart card testing time and low testing efficiency.

[0064] In order to alleviate the problem of long test time for smart cards in manually arranging test suites in the related art, the embodiments of the present application provide a test instruction generation method, device, equipment and computer program product, which generates an abstract syntax tree of the test case, identifies each conditional statement node in the abstract syntax tree, and uses the nested parameters included in each conditional statement node to determine the target language learning model that matches each conditional statement node, thereby using the target language learning model to identify the variables included in the conditional statement node, and finally generates the test instructions of the test code corresponding to the conditional statement node based on the variables. It can be seen that with the help of the abstract syntax tree and the target language learning model, the test case is automatically converted into a test instruction, which improves the test efficiency compared to the process of arranging the test case into a test instruction by means of the related art.

[0065] To facilitate understanding of the present embodiment, a test instruction generation method disclosed in the embodiment of the present application is first introduced in detail. The execution subject of the test instruction generation method provided in the embodiment of the present application is generally a computer device with certain computing capabilities, and the computer device includes, for example: a terminal device or a server or other processing device, and the terminal device can be a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computing device, etc. In some possible implementations, the test instruction generation method can be implemented by a processor calling a computer-readable instruction stored in a memory.

[0066] See also Figure 1 As shown, it is a flowchart of a test instruction generation method provided in an embodiment of the present application, and the method may include the following steps:

[0067] Step 101: Generate an abstract syntax tree of the test case.

[0068] In this embodiment, the test case can be converted into an abstract syntax tree (AST) by calling a syntax tool in the relevant technology. The abstract syntax tree is a tree representation of the abstract syntax structure of the source code written in a programming language. Each node of the tree represents a construct that appears in the source code. The syntax is "abstract" because it does not represent every detail that appears in the real syntax, but only structural, content-related details. For example, grouping brackets are implicit in the tree structure, and a syntax structure like an if-condition-then expression can be represented by a single node with three branches.

[0069] As an example, given Figure 2 The schematic diagram of the script code shown and the Figure 3 Based on the Figure 2 Schematic diagram of the abstract syntax tree generated by the script code.

[0070] In an optional embodiment, the test case may be obtained based on the entry function of the test case. In a specific implementation, before generating the abstract syntax tree of the test case, the method may further include:

[0071] Get the test case by retrieving the entry function of the test case.

[0072] In the application, before the test case is automatically converted into the final test instruction, it is necessary to first determine the entry of the language learning model, that is, to determine the location of the test case. Each test case has a corresponding entry function, which can indicate the location of the test case. Therefore, by retrieving the entry function, the corresponding test case can be obtained.

[0073] Step 102: traverse the abstract syntax tree to obtain multiple conditional statement nodes in the abstract syntax tree.

[0074] In this embodiment, the conditional statement node refers to a node including a specific keyword in the abstract syntax tree. The specific keywords include but are not limited to if statement and switch statement. Therefore, when obtaining the conditional statement node in the abstract syntax tree, the abstract syntax tree can be searched based on the specific keyword, and the target node including the specific keyword is used as the conditional statement node.

[0075] Step 103: Determine a target language learning model that matches each conditional statement node based on a nesting parameter included in each conditional statement node; the nesting parameter is used to indicate the number of levels of conditional statements nested in the conditional statement node.

[0076] In this embodiment, a conditional statement may be nested under each conditional statement node, and the nesting parameters of different conditional statement nodes may be different, that is, the number of layers of conditional statements nested in different conditional statement nodes is different, for example, some conditional statement nodes may be nested with one layer of conditional statements, and some conditional statement nodes may be nested with two layers of conditional statements. It should be understood that when a conditional statement node is nested with one layer of conditional statements, it means that the conditional statement node includes two layers of conditional statements.

[0077] In this embodiment, the language learning model matched by the conditional statement node may be determined based on the nested parameters of the conditional statement node and the number of variable retrievals of the language learning model.

[0078] In a specific implementation, in an optional embodiment, determining a target language learning model matching each conditional statement node based on the nested parameters included in each conditional statement node may include:

[0079] Get the number of variable retrievals of each of the pre-configured multiple language learning models;

[0080] Based on the number of variable retrievals, a target language learning model whose number of variable retrievals is consistent with the nesting parameters is searched from multiple language learning models.

[0081] In this embodiment, when the number of variable searches = nesting parameter + 1, it is considered that the number of variable searches is consistent with the nesting parameter. For example, if the nesting parameter is 1, that is, the conditional statement node has a layer of conditional statements nested, then the language learning model with the number of variable searches of 2 is considered to be the target language learning model that matches the conditional statement node.

[0082] In the present embodiment, the number of variable retrievals is used to indicate the number of variables that the language learning model can retrieve. The number of variable retrievals of different language learning models in the pre-configured multiple language learning models is different. For example, for a language learning model with a variable retrieval number of 1, the number of variables that the language learning model can retrieve is 1. For a language learning model with a variable retrieval number of 1, the variable to be retrieved by the language learning model is not in a nested conditional statement, and the variable that the language learning model can retrieve can be any one of P1, P2 and INS, wherein P1, P2 and INS are fields in an APDU instruction, INS represents an instruction code, P1 and P2 represent command parameters, and in APDU instructions with different instruction codes, the meanings of P1 and P2 are also different. For a language learning model with a variable retrieval number of 2 and 3, the variables of the language learning model are nested in the conditional statement. Among them, for a language learning model with a variable retrieval number of 2, the variables that can be retrieved can be any two of P1, P2 and INS. For a language learning model with a variable retrieval number of 3, the variables that can be retrieved can be P1, P2 and INS.

[0083] As an example, we give Figure 4 , Figure 5 and Figure 6 Schematic diagram of the language learning model for code snippet recognition. Figure 4 In the example, model 1 with a variable search number of 1 is used to identify the code snippet. Figure 5 In the example, model 2 with 2 variables is used to identify the code snippet. Figure 6Model 3 with 3 variables is used to identify the code snippet. The abstract syntax tree obtained by converting the code snippet that needs to be identified by model 1 includes two conditional statement nodes. In one conditional statement node, the variable obtained by model 1 is INS=0x00, and in the other conditional statement node, the variable obtained by model 1 is P1=0x11. The abstract syntax tree obtained by converting the code snippet that needs to be identified by model 2 includes two conditional statement nodes. In one conditional statement node, the variable obtained by model 2 is INS=0x33, P1=0x01, and in the other conditional statement node, the variable obtained by model 2 is INS=0x33, P1=0x02. The abstract syntax tree obtained by converting the code snippet that needs to be identified by model 3 includes two conditional statement nodes. In one conditional statement node, the variable obtained by model 3 is INS=0x55, P1=0x10, P2=0x20, and in the other conditional statement node, the variable obtained by model 3 is INS=0x55, P1=0x10, P2=0x21.

[0084] For ease of understanding, the following example is given to illustrate the process of searching for a target language learning model based on the number of variable retrievals. Assume that there are three language learning models, Model 1, Model 2, and Model 3. The number of variable retrievals for Model 1 is 1, the number of variable retrievals for Model 2 is 2, and the number of variable retrievals for Model 3 is 3. If the conditional statement node includes two nested parameters, then Model 2 can be directly determined as the target language learning model that matches the conditional statement node.

[0085] In the application, this embodiment also configures a search engine in the electronic device, which supports single keyword matching, multiple keyword matching, supports keyword matching to return True or False (multiple keywords support logical AND, OR), and keyword matching to return the value of the keyword. The interface definition is as follows:

[0086] search_is_exist(keyword1,keyword2...,mode)

[0087] Function description: mode takes the value of and, or, and the function returns True or False.

[0088] search_get_value(keyword1,keyword2...)

[0089] Function description: Returns the search results of each keyword in the form of key:value. If no keyword is found, the value of the keyword is None.

[0090] Step 104: Based on the target language learning model, obtain the variables included in each conditional statement node.

[0091] In an optional embodiment, based on the target language learning model, the variables included in each conditional statement are obtained, including:

[0092] Obtain a variable relationship list corresponding to each conditional statement node output by the target language learning model;

[0093] Get the variables included in each conditional statement node from the variable relationship list.

[0094] In this embodiment, the variable relationship list is a sequence composed of variables, and the variables included in each conditional statement node can be obtained through the variable relationship list.

[0095] In an example, given Figure 7 The diagram of the conditional statement node is shown in Figure 7 In the example, there is no conditional statement nested in the conditional statement node, and the conditional statement node only includes one condition node. Therefore, the conditional statement node matches the language learning model as model 1 with a variable retrieval number of 1. The left node value of the conditional statement node includes the variable INS, and the value of the variable is 0x00. The variable relationship list output by model 1 can be {INS:0x00}, and the variable included in the conditional statement node obtained from the variable relationship list is INS=0x00.

[0096] In another example, given Figure 8 The diagram of the conditional statement node is shown in Figure 8 In the figure, there is one layer of conditional statements nested in the conditional statement node, and the conditional statement node includes two condition nodes. Therefore, the conditional statement node matches the language learning model as model 2 with a variable retrieval number of 2. The left node value of the conditional statement node includes two variables, INS and P1, and the value of INS is 0x33, and the value of P1 is 0x01. The variable relationship list output by the language learning model can be {INS:0x33, P1:0x01}, and the variables included in the conditional statement node obtained from the variable relationship list are INS=0x33, P1=0x01.

[0097] In another example, given Fig. 9 The diagram of the conditional statement node is shown in Fig. 9In the figure, there are two layers of conditional statements nested in the conditional statement node, and the conditional statement node includes three condition nodes. Therefore, the conditional statement node matches the language learning model as model 3 with a variable retrieval number of 3. The left node value of the conditional statement node includes two variables, INS, P1 and P2, and the value of INS is 0x55, the value of P1 is 0x10, and the value of P2 is 0x20. The variable relationship list output by the language learning model can be {INS: 0x55, P1: 0x10, P2: 0x20}, and the variables included in the conditional statement node further obtained from the variable relationship list are INS = 0x55, P1 = 0x10, P2 = 0x20.

[0098] Step 105: Generate test instructions of the test code corresponding to each conditional statement node based on the variables.

[0099] In an optional embodiment, a test instruction may be generated based on an APDU instruction model. In a specific implementation, a test instruction of a test code corresponding to each conditional statement node is generated based on a variable, including:

[0100] Get the variable items and variable values ​​included in the variable;

[0101] In the command header included in the preset APDU instruction template, the parameter value of the parameter item that is the same as the variable item is set to the variable value, and the test instruction is obtained.

[0102] In this embodiment, the structure of the APDU instruction template can be seen in the following Table 1:

[0103] Table 1

[0104]

[0105] Among them, CLA represents the instruction category (class), INS represents the instruction code (instruction), P1 and P2 represent command parameters. In APDU instructions with different execution codes, the meanings of P1 and P2 are also different. The P3 field represents the lc length. If data needs to be sent, lc is the length of the data, otherwise it is 0; le represents the length of the data that the instruction needs to return.

[0106] In this embodiment, the variable item is used to characterize the category of the variable. Taking the variable INS=0x55 as an example, the variable item of the variable is INS, and the variable value is 0x55.

[0107] It should be noted that when the number of variables retrieved by the language learning model is 1, the other two parameters in the test instruction except the variable retrieved by the language learning model can be set to any value. For example, if the variable retrieved by the language learning model is INS, then the two parameters P1 and P2 can be set to any value. Similarly, when the number of variables retrieved by the language learning model is 2, the other 1 parameter in the test instruction except the variable retrieved by the language learning model can be set to any value.

[0108] It should also be noted that in actual test activities, the test instructions do not need to have a command body, so the P3 parameter can be set to 0.

[0109] Step 106: Based on the test instructions corresponding to each conditional statement node, obtain the final test instructions of the test case.

[0110] In this embodiment, the final test instruction can be expressed in multiple forms. As examples, the following two forms are given. First, the final test instruction can be expressed in a form that can be loaded by the instruction test tool. In this case, the generated final test instruction can be: 01 00 22 33 00; 01 00 11 00 00;

[0113] 01 33 01 00 00.

[0114] Secondly, for ease of reading, notes can be added to the final test instructions. At the same time, in order to automatically determine whether the test of the smart card is successful, the final test instructions can also include expected response data, which can be output by the language learning model. Accordingly, when determining the target language learning model that matches each conditional statement node, the expected response data included in each conditional statement node can also be obtained based on the target language learning model. At the same time, when generating the test instructions of the test code corresponding to each conditional statement node, the test instructions are generated based on the variables and the expected response data.

[0115] Regarding the expected response data, such as Figure 7-9 As shown, the conditional statement node includes an allocation node representing the expected response data, and the variable (sw) in the allocation node is the expected response data.

[0116] As an example, the final test instructions generated for easy reading are as follows:

[0117] [case1]--Use case name

[0118] header:01 00 22 33 00--APDU command

[0119] expect:9000--Expected response data

[0120] [case2]--Use case name

[0121] header:01 00 11 00 00--APDU command

[0122] expect:9000--Expected response data.

[0123] In this embodiment, after the final test instruction is used to test the smart card, the smart card returns the test response data, and then it is determined whether the test of the smart card passes based on the expected response data and the test response data. It should be understood that in the first expression form, although there is no expected response data in the final test instruction, the tester can obtain the test response data based on the execution log of the test process, and then manually compare the test response data with the expected response data in the test case to determine whether the test of the smart card passes.

[0124] In the solution provided by this embodiment, by generating an abstract syntax tree of the test case, identifying each conditional statement node in the abstract syntax tree, using the nested parameters included in each conditional statement node, determining the target language learning model that matches each conditional statement node, thereby using the target language learning model to identify the variables included in the conditional statement node, and finally generating the test instructions of the test code corresponding to the conditional statement node based on the variables. It can be seen that with the help of the abstract syntax tree and the target language learning model, the test case is automatically converted into a test instruction, which improves the test efficiency compared to the process of arranging the test case into a test instruction by means of the related art.

[0125] For ease of understanding, Fig.10 The flow chart of the test instruction generation method shown in FIG. Fig.10 As shown, the method may include the following steps:

[0126] Step 1001: Call a grammar tool to generate an abstract syntax tree of a test case;

[0127] Step 1002: Searching for multiple target nodes whose nodes include preset keywords in the abstract syntax tree;

[0128] Step 1003: using multiple target nodes as multiple conditional statement nodes;

[0129] Step 1004, obtaining the number of variable retrievals of each of the pre-configured multiple language learning models;

[0130] Step 1005: based on the number of variable retrievals, searching from multiple language learning models for a target language learning model whose number of variable retrievals is consistent with a nesting parameter; the nesting parameter is used to indicate the number of levels of nested conditional statements in the conditional statement node;

[0131] Step 1006: Obtain a variable relationship list corresponding to each conditional statement node output by the target language learning model;

[0132] Step 1007: Obtain the variables included in each conditional statement node from the variable relationship list;

[0133] Step 1008: Obtain variable items and variable values ​​included in the variables;

[0134] Step 1009: Set the parameter value of the parameter item that is the same as the variable item in the command header included in the preset APDU instruction template to the variable value, and obtain a test instruction;

[0135] Step 1010: Based on the test instructions corresponding to each conditional statement node, obtain the final test instructions of the test case.

[0136] For ease of understanding, the following are given: Fig.11 The flowchart of the test instruction generation method shown in FIG. 1 may include the following steps:

[0137] Step 1: Determine the entrance.

[0138] First, we need to confirm the entry point for language learning model learning, which can be achieved through the entry function of the test case. Each test case is configured with an entry function, and the test case can be retrieved by searching the entry function. Taking JavaCard as an example, the entry function is process.

[0139] Step 2: Start model learning.

[0140] The implementation principle of the language learning model is to first convert the test case into an abstract syntax tree through the grammar tool, then extract variables from the abstract syntax tree to form a sequence of variables; finally, extract the dependencies between variables from the abstract syntax tree to construct a data flow graph. By analyzing the matching model of the variables and the data flow corresponding to the variables, once the language learning model is matched, the learning results of the language learning model are saved in a list.

[0141] Specifically, the model learning process is as follows:

[0142] Step 1: The language learning model converts the test case into an abstract syntax tree through grammatical analysis;

[0143] Step 2: Traverse the nodes of the abstract syntax tree and find all conditional statement nodes (including if statement and switch statement);

[0144] Step 3: Model matching and classification of conditional statements. The matching method is:

[0145] If there is no nested conditional statement under the conditional statement node, the number of variable retrievals of the language learning model matched by the conditional statement node is 1, and the value of the left node of the condition node of the conditional statement contains a keyword from P1, P2, and INS, the parameters in the left node can be identified through the matched language learning model.

[0146] If a conditional statement is nested with one layer of conditional statements, the number of variable retrievals of the language learning model matched by the conditional statement node is 2, and the values ​​of the left nodes of the two condition nodes contain two keywords, P1, P2, and INS, the parameters in the left node can be identified through the matched language learning model.

[0147] If a conditional statement is nested with three layers of conditional statements, the number of variable retrievals of the language learning model matched by the conditional statement node is 3, and the values ​​of the left nodes of the three condition nodes contain the three keywords P1, P2 and INS, the parameters in the left node can be identified through the matched language learning model.

[0148] Step 4: Output the variable relationship list. The conditional statement nodes that fail to match are discarded, and the variable relationship list that matches successfully is output. Each item in the relationship list is stored in a dictionary format, with keys P1, P2, INS, and SW, and values ​​representing their values. Figure 7-Figure 9 For example, Figure 7 The conditional statement node matches the OnePara model, and the output of the model is {ins:0x00, sw:0x9000}. Figure 8 The conditional statement node in matches the TwoParas model, whose output is {ins:0x33, p1:0x01, sw:0x9000}. Fig. 9 The conditional statement node in matches the ThreeParas model, the output of which is {ins:0x55, p1:0x10, p2:0x20, sw:0x9000}, and the final output variable relationship list is [{ins:0x00, sw:0x9000}, {ins:0x33, p1:0x01, sw:0x9000}, {ins:0x55, p1:0x10, p2:0x20, sw:0x9000}].

[0149] Among them, the OnePara model is a model with 1 variable retrieval number, the TwoParas model is a model with 2 variables retrieval number, and the ThreeParas model is a model with 3 variables retrieval number.

[0150] Step 3: Generate instructions.

[0151] Based on the variable relationship list output by the language learning model, test instructions are output according to the built-in template (the template is configurable).

[0152] The present application also provides a test instruction generation device, which is used to execute the test instruction generation method provided in any of the above embodiments. Fig.11 As shown, the device comprises:

[0153] A first generating module 1101 is used to generate an abstract syntax tree of a test case;

[0154] A first obtaining module 1102, configured to traverse the abstract syntax tree to obtain a plurality of conditional statement nodes in the abstract syntax tree;

[0155] A determination module 1103 is used to determine a target language learning model that matches each of the conditional statement nodes based on a nesting parameter included in each of the conditional statement nodes; the nesting parameter is used to indicate the number of levels of conditional statements nested in the conditional statement node;

[0156] An acquisition module 1104 is used to acquire variables included in each of the conditional statement nodes based on the target language learning model;

[0157] A second generating module 1105 is used to generate a test instruction of a test code corresponding to each of the conditional statement nodes based on the variables;

[0158] The second obtaining module 1106 is used to obtain the final test instruction of the test case based on the test instruction corresponding to each of the conditional statement nodes.

[0159] In some embodiments, the determination module 1103 is used to:

[0160] Get the number of variable retrievals of each of the pre-configured multiple language learning models;

[0161] Based on the variable retrieval number, the target language learning model whose variable retrieval number is consistent with the nesting parameter is searched from the multiple language learning models.

[0162] In some embodiments, the second generating module 1105 is used to:

[0163] Obtaining variable items and variable values ​​included in the variable;

[0164] The parameter value of the parameter item that is the same as the variable item in the command header included in the preset APDU instruction template is set to be the variable value, so as to obtain the test instruction.

[0165] In some embodiments, the acquisition module 1104 is used to:

[0166] Obtaining a variable relationship list corresponding to each of the conditional statement nodes output by the target language learning model;

[0167] The variables included in each of the conditional statement nodes are obtained from the variable relationship list.

[0168] In some embodiments, the first obtaining module 1102 is used to:

[0169] From the abstract syntax tree, searching for multiple target nodes whose nodes include preset keywords;

[0170] The multiple target nodes are used as the multiple conditional statement nodes.

[0171] In some embodiments, the device is also used to:

[0172] Before generating an abstract syntax tree of a test case, the test case is obtained by retrieving an entry function of the test case.

[0173] In some embodiments, the device is also used to:

[0174] When determining the target language learning model that matches each of the conditional statement nodes, acquiring expected response data included in each of the conditional statement nodes based on the target language learning model;

[0175] The second generating module 1105 is used for:

[0176] The test instruction is generated based on the variable and the expected response data.

[0177] The test instruction generation device provided in the embodiment of the present application and the test instruction generation method provided in the embodiment of the present application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented therein.

[0178] The present application also provides an electronic device to execute the above test instruction generation method. Fig.12 It shows a schematic diagram of an electronic device provided by some embodiments of the present application. Fig.12As shown, the electronic device 12 includes: a processor 1200, a memory 1201, a bus 1202 and a communication interface 1203, and the processor 1200, the communication interface 1203 and the memory 1201 are connected via the bus 1202; the memory 1201 stores a computer program that can be run on the processor 1200, and when the processor 1200 runs the computer program, it executes the test instruction generation method provided in any of the aforementioned embodiments of the present application.

[0179] The memory 1201 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the device network element and at least one other network element is realized through at least one communication interface 1203 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.

[0180] The bus 1202 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 1201 is used to store programs, and the processor 1200 executes the program after receiving an execution instruction. The test instruction generation method disclosed in any implementation of the embodiment of the present application may be applied to the processor 1200, or implemented by the processor 1200.

[0181] The processor 1200 may be an integrated circuit chip with signal processing capabilities. In the implementation process, the steps of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 1200. The above processor 1200 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a readily available programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor to be executed, or the hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 1201, and the processor 1200 reads the information in the memory 1201 and completes the steps of the above method in combination with its hardware.

[0182] The electronic device provided in the embodiment of the present application and the test instruction generation method provided in the embodiment of the present application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented therein.

[0183] The present application also provides a computer-readable storage medium corresponding to the test instruction generation method provided in the above embodiment. Fig.13 The computer-readable storage medium shown is a CD 30 on which a computer program (ie, a program product) is stored. When the computer program is run by a processor, the test instruction generation method provided in any of the aforementioned embodiments will be executed.

[0184] It should be noted that examples of the computer-readable storage medium may also 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 optical or magnetic storage media, which are not listed here one by one.

[0185] The computer-readable storage medium provided in the above-mentioned embodiment of the present application and the test instruction generation method provided in the embodiment of the present application are based on the same inventive concept and have the same beneficial effects as the method adopted, run or implemented by the application program stored therein.

[0186] An embodiment of the present application also provides a computer program product corresponding to the test instruction generation method provided in the aforementioned embodiment, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the test instruction generation method provided in any of the aforementioned embodiments.

[0187] It should be noted that:

[0188] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known structures and technologies are not shown in detail so as not to obscure the understanding of this description.

[0189] Similarly, it should be understood that in order to streamline the present application and aid in understanding one or more of the individual inventive aspects, in the above description of the exemplary embodiments of the present application, the individual features of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following schematic diagram: the claimed application requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, the inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present application.

[0190] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present application and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.

[0191] The above is only a preferred specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A test instruction generation method, characterized in that: include: Generate an abstract syntax tree of test cases; Traversing the abstract syntax tree to obtain a plurality of conditional statement nodes in the abstract syntax tree; Determining a target language learning model that matches each of the conditional statement nodes based on a nesting parameter included in each of the conditional statement nodes; the nesting parameter is used to indicate the number of layers of conditional statements nested in the conditional statement node; Based on the target language learning model, obtaining variables included in each of the conditional statement nodes; Based on the variables, generating test instructions of the test codes corresponding to the conditional statement nodes; Based on the test instructions corresponding to each of the conditional statement nodes, a final test instruction of the test case is obtained.

2. The method according to claim 1, characterized in that Determining a target language learning model matching each of the conditional statement nodes based on the nested parameters included in each of the conditional statement nodes includes: Get the number of variable retrievals of each of the pre-configured multiple language learning models; Based on the variable retrieval number, the target language learning model whose variable retrieval number is consistent with the nesting parameter is searched from the multiple language learning models.

3. The method according to claim 1, characterized in that Based on the variables, generating a test instruction of the test code corresponding to each of the conditional statement nodes, including: Obtaining variable items and variable values ​​included in the variable; The parameter value of the parameter item that is the same as the variable item in the command header included in the preset APDU instruction template is set to be the variable value, so as to obtain the test instruction.

4. The method according to claim 1, characterized in that: Based on the target language learning model, obtaining variables included in each of the conditional statement nodes includes: Obtaining a variable relationship list corresponding to each of the conditional statement nodes output by the target language learning model; The variables included in each of the conditional statement nodes are obtained from the variable relationship list.

5. The method according to claim 1, characterized in that Traversing the abstract syntax tree to obtain a plurality of conditional statement nodes in the abstract syntax tree includes: From the abstract syntax tree, searching for multiple target nodes whose nodes include preset keywords; The multiple target nodes are used as the multiple conditional statement nodes.

6. The method according to any one of claims 1 to 5, characterized in that: Before generating the abstract syntax tree of the test case, it also includes: The test case is obtained by retrieving the entry function of the test case.

7. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: When determining the target language learning model that matches each of the conditional statement nodes, acquiring expected response data included in each of the conditional statement nodes based on the target language learning model; Based on the variables, generating a test instruction of the test code corresponding to each of the conditional statement nodes, including: The test instruction is generated based on the variable and the expected response data.

8. A test instruction generating device, characterized in that: include: A first generation module, used to generate an abstract syntax tree of a test case; A first obtaining module, configured to traverse the abstract syntax tree to obtain a plurality of conditional statement nodes in the abstract syntax tree; A determination module, configured to determine a target language learning model matching each of the conditional statement nodes based on a nesting parameter included in each of the conditional statement nodes; the nesting parameter is used to indicate the number of levels of conditional statements nested in the conditional statement node; An acquisition module, used for acquiring the variables included in each of the conditional statement nodes based on the target language learning model; A second generating module, used for generating a test instruction of a test code corresponding to each of the conditional statement nodes based on the variable; The second obtaining module is used to obtain the final test instruction of the test case based on the test instruction corresponding to each of the conditional statement nodes.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: The processor runs the computer program to implement the method according to any one of claims 1 to 7.

10. A computer program product, characterized in that The invention comprises a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the method as claimed in any one of claims 1 to 7.