Test method, device, electronic equipment and storage medium of program code

By automatically generating variables and associating them with files, the problem of variable corruption during code debugging is solved, achieving efficient code debugging and maintenance.

CN115757131BActive Publication Date: 2026-07-07EVE POWER CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
EVE POWER CO LTD
Filing Date
2022-11-17
Publication Date
2026-07-07

AI Technical Summary

Technical Problem

In existing technologies, manually adding variables during code debugging can disrupt the original code structure, leading to difficulties in code maintenance, low debugging efficiency, and difficulty in shielding related functions, thus affecting the verification of underlying functions.

Method used

By acquiring the variable to be processed and the existing variable with the same name, the variable name is modified according to the preset format, the current calibration variable and the observed variable are generated, the current source file, header file and A2L file are automatically generated, and they are associated with the project file for testing.

Benefits of technology

It achieves automatic restoration of the original code structure without adding process variables or writing code manually during debugging, thus improving code debugging efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115757131B_ABST
    Figure CN115757131B_ABST
Patent Text Reader

Abstract

This application relates to a method, apparatus, electronic device, and storage medium for testing program code. The method involves obtaining a variable to be processed and existing variables with the same name; modifying the variable names of the variable to be processed and existing variables with the same name based on a preset format to obtain a variable to be processed in a first format and existing variables with the same name in each first format; generating a current calibration variable and an observation variable based on the variable to be processed in the first format and existing variables with the same name in each first format; generating a current source file, a current header file, and a current A2L file based on the current calibration variable and the observation variable; associating the current source file, current header file, and current A2L file with a project file, and testing the associated project file. This achieves efficient testing of the corresponding program code, automatically restoring the original code without adding process variables or writing code manually during debugging, ensuring code structure, and improving code debugging efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of code testing technology, and in particular to a method, apparatus, electronic device, and storage medium for testing program code. Background Technology

[0002] When debugging a function in embedded code, it is necessary to add some variables to the process, compile the corresponding part of the code, and observe the process data in order to obtain the process data for easier debugging.

[0003] Based on the principles of debugging, most development tools and software on the market follow this method. Currently, in existing code debugging for a specific function, the variables that need to be added during the process can disrupt the original code structure and hinder code maintenance. Secondly, manually adding variables in the code involves a significant amount of work, resulting in low debugging efficiency. Furthermore, when debugging a specific function, if there are many related functions, it is impossible to manually disable them one by one, making it difficult to compare and verify the underlying functions. Summary of the Invention

[0004] Therefore, it is necessary to address the problems mentioned above, such as the inability to manually add variables during the debugging of a certain function of the code, which can disrupt the original code structure, hinder code maintenance, reduce debugging efficiency, and make it difficult to shield related functions and compare the debugging and verification of underlying functions. A method, device, electronic device, and storage medium should be provided to automatically restore the original code during debugging without adding process variables or writing code manually, thus ensuring the code structure and improving debugging efficiency.

[0005] Firstly, this application provides a method for testing program code, comprising the following steps:

[0006] Get the variable to be processed and the existing variable with the same name;

[0007] Based on the preset format, the variable names of the variables to be processed and the original variables with the same name are modified to obtain the first format variables to be processed and the original variables with the same name in the first format.

[0008] Based on the variables to be processed in the first format and the original variables with the same name in each first format, generate the current calibration variable and the observed variables corresponding to the variables to be processed in the first format;

[0009] Generate the current source file, current header file, and current A2L file based on the current calibration and observation variables;

[0010] Associate the current source file, current header file, and current A2L file with the project file, and then test the associated project file.

[0011] Optionally, the steps to obtain the variable to be processed may include:

[0012] Obtain the various source files of the project file;

[0013] The variable names of each source file are identified and processed to obtain the original variables of each corresponding source file; each original variable includes several original variables with the same name and several remaining original variables.

[0014] Optionally, the steps for identifying and processing variable names in each source file include:

[0015] Locate the columns in each source file that contain the first header field and the first tail field to obtain the columns to be processed;

[0016] Obtain the intermediate field between the first head field and the first tail field in each column to be processed, and confirm the intermediate field as the original variable to obtain each original variable.

[0017] Optionally, the steps for renaming the variables to be processed and the existing variables with the same name include:

[0018] Based on the path information of the corresponding variable to be processed and the path information of each existing variable with the same name, a prefix field is set for the variable to be processed and each existing variable with the same name to obtain the first format variable to be processed and each existing variable with the same name in the first format.

[0019] Optionally, the steps for generating the observed variables corresponding to the variables to be processed in the first format include:

[0020] Declare the variables to be processed in the first format to obtain the observed variables.

[0021] Optionally, the steps for generating the current source file based on the current calibration variables and observed variables include:

[0022] The current calibration variable and the observed variable are correlated to obtain the current source file.

[0023] Optionally, the steps for generating the current header file include:

[0024] Based on the number of variables in the current source file, declare them in the header file to obtain the current header file.

[0025] Optionally, the steps for generating the current A2L file include:

[0026] Based on the A2L file format, obtain the file header and file footer information from the original A2L file;

[0027] Generate the current A2L file based on the file header information, file footer information, and current calibration variables.

[0028] Secondly, this application provides a program code testing apparatus, which includes:

[0029] The variable selection unit is used to obtain the variable to be processed and the existing variable with the same name;

[0030] The variable modification unit is used to modify the variable name of the variable to be processed and each existing variable with the same name based on a preset format, so as to obtain the variable to be processed in the first format and each existing variable with the same name in the first format.

[0031] The variable generation unit is used to generate the current calibration variable and the observation variable corresponding to the first format variable based on the first format variable to be processed and the original variables with the same name in each first format;

[0032] The file generation unit is used to generate the current source file, the current header file, and the current A2L file based on the current calibration variables and observation variables.

[0033] The associated test unit is used to associate the current source file, the current header file, and the current A2L file with the project file respectively, and to test the associated project file.

[0034] Thirdly, this application provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the test method of any of the above-mentioned program codes.

[0035] Fourthly, this application also provides a computer-readable storage medium having executable code stored thereon, which, when executed by a processor of an electronic device, causes the processor to perform any of the methods described above.

[0036] One of the above technical solutions has the following advantages and beneficial effects:

[0037] In the above-described testing method for program code, the following steps are taken: First, the variable to be processed and existing variables with the same name are obtained. Second, based on a preset format, the variable names of the variable to be processed and existing variables with the same name are modified to obtain a first-format variable to be processed and existing variables with the same name in the first format. Third, based on the first-format variable to be processed and existing variables with the same name in the first format, a current calibration variable and an observed variable corresponding to the first-format variable to be processed are generated. Fourth, based on the current calibration variable and observed variables, a current source file, a current header file, and a current A2L file are generated. Fifth, the current source file, current header file, and current A2L file are associated with the project file, and the associated project file is tested, thereby achieving efficient testing of the corresponding program code. This application redefines existing variables with new ones, hides the original variables, and automatically generates three files: the current source file, the current header file, and the current A2L file. These files are then linked to the original variables. This allows for program code debugging by modifying only the new variables. During debugging, no process variables need to be added, and no code needs to be written manually. The program code can automatically restore the original code, maintain the code structure, and improve debugging efficiency. Attached Figure Description

[0038] Figure 1 This is a schematic diagram illustrating the application scenario of the testing method for the program code in the embodiments of this application.

[0039] Figure 2 This is a first structural diagram of the test method of the program code in the embodiments of this application.

[0040] Figure 3 This is a second structural diagram of the test method of the program code in the embodiments of this application.

[0041] Figure 4 This is a schematic diagram of the third structure of the test method of the program code in the embodiments of this application.

[0042] Figure 5 This is a schematic diagram of the structure of the testing device for the program code in the embodiments of this application.

[0043] Figure 6 This is a schematic diagram of the structure of the electronic device in the embodiments of this application. Detailed Implementation

[0044] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0045] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0046] In addition, the term "multiple" should mean two or more.

[0047] The testing methods for the program code provided in this application can be applied to, for example... Figure 1 In the application environment shown, the processing device may include a processor 102 and a memory 104. The memory 104 can be used to store data such as project files, current source files, current header files, and current A2L files. The processor 102 can be used to obtain the variable to be processed and existing variables with the same name; based on a preset format, modify the variable names of the variable to be processed and each existing variable with the same name to obtain a first-format variable to be processed and each existing variable with the same name in the first format; generate a current calibration variable and an observation variable corresponding to the first-format variable to be processed based on the first-format variable to be processed and each existing variable with the same name in the first format; generate a current source file, a current header file, and a current A2L file based on the current calibration variable and the observation variable; associate the current source file, current header file, and current A2L file with the project file respectively, and test the associated project file. The processing device may also include a display 106, which can display data such as project files, current source files, current header files, and current A2L files through a graphical interface. In one example, the processing device may be, but is not limited to, a desktop computer, a laptop computer, or a tablet computer.

[0048] In debugging existing code for a specific function, manually adding variables can disrupt the original code structure, hinder code maintenance, reduce debugging efficiency, and make it difficult to shield related functions, leading to difficulties in comparing and verifying underlying functionalities. In one embodiment, such as... Figure 2 As shown, a method for testing program code is provided, which can be applied to... Figure 1 Taking processor 102 as an example, the following steps are included:

[0049] Step S210: Obtain the variable to be processed and the original variable with the same name.

[0050] Here, "project file" refers to the entire project file (project) based on C language program code. "Variables to be processed" refers to the variables selected by the user from all variables contained in the project file. For example, the corresponding project file can be pre-selected, all variables can be queried from the project file, and then all header files (i.e., *.c files) can be searched within the project file to extract all variables; then, the observations that need to be debugged and modified can be selected; from all the obtained variables, variables can be selected or searched to obtain the variables to be processed.

[0051] In one example, within the same project file, the project file includes multiple existing variables, and at least one variable has the same name as the variable to be processed. The variable with the same name as the variable to be processed is identified as an existing variable with the same name.

[0052] Step S220: Based on the preset format, modify the variable names of the variable to be processed and each existing variable with the same name to obtain the variable to be processed in the first format and each existing variable with the same name in the first format.

[0053] The preset format can be obtained based on C language rules. For example, the preset format can be, but is not limited to, identifier characters of the same format.

[0054] The processor can modify the names of variables to be processed based on a preset format to obtain variables to be processed in a first format. Furthermore, the processor can modify the names of existing variables with the same name based on the preset format to obtain existing variables with the same name in the first format. For example, by adding a pre-set identifier character to the names of the variables to be processed and all existing variables with the same name, the processor can uniformly modify the names of the variables to be processed and all existing variables with the same name.

[0055] Step S230: Based on the variables to be processed in the first format and the original variables with the same name in each first format, generate the current calibration variable and the observed variable corresponding to the variables to be processed in the first format.

[0056] Observed variables can be obtained by declaring variables in the first format. The currently labeled variable refers to a new variable generated based on the variables in the first format and existing variables with the same name in each first format. For example, the currently labeled variable can be obtained by setting a suffix field after the variable name. For instance, the name of the currently labeled variable could be "variable_Adap_C". For example, the number of currently labeled variables corresponds one-to-one with the number of variables in the first format.

[0057] Step S240: Generate the current source file, current header file, and current A2L file based on the current calibration variables and observation variables.

[0058] The current source file is a new C file generated based on the current calibration and observation variables. The current header file is a new H file (i.e., a new *.h file) generated based on the current source file, and the current A2L file (i.e., a new *.a2l file) is a new A2L file generated based on the current calibration and observation variables. The A2L file is a calibration description file, in text format, describing the communication parameters of the ECU (Electronic Control Unit), as well as the addresses of calibration and observation variables and the formulas for calculating physical values.

[0059] The processor associates the current calibration variables and observed variables one-to-one, thereby generating the current source file. Further, based on program code design rules, it converts the current source file into a header file, thus obtaining the current header file. Based on A2L file design rules, it processes the current calibration variables and observed variables to obtain the current A2L file.

[0060] Step S250: Associate the current source file, the current header file, and the current A2L file with the project file respectively, and test the associated project file.

[0061] The processor can associate the newly generated current source file, current header file, and current A2L file with the corresponding project file to obtain the associated project file. It can then test the associated project file, enabling the automatic modification of original variable names and the automatic generation of new variables during program code debugging without adding process variables. This eliminates the need for manual coding and facilitates the automatic restoration of the original code, ensuring the code structure remains intact.

[0062] In the above embodiments, the process involves obtaining the variable to be processed and existing variables with the same name; modifying the names of the variable to be processed and existing variables with the same name based on a preset format to obtain a first-format variable to be processed and existing variables with the same name in the first format; generating a current calibration variable and an observation variable corresponding to the first-format variable to be processed based on the first-format variable to be processed and existing variables with the same name in the first format; generating a current source file, a current header file, and a current A2L file based on the current calibration variable and the observation variable; associating the current source file, current header file, and current A2L file with the project file, and testing the associated project file, thereby achieving efficient testing of the corresponding program code. This application redefines a new variable for the existing variable, hides the existing variable, automatically generates three files (current source file, current header file, and current A2L file), and associates them with the existing variable. This allows for debugging of the program code by only modifying the new variable, eliminating the need to add process variables or write code manually during debugging, automatically restoring the original code, ensuring code structure, and improving debugging efficiency.

[0063] In one embodiment, such as Figure 3 As shown, a method for testing program code is provided, which can be applied to... Figure 1 Taking processor 102 as an example, the following steps are included:

[0064] Step S310: Obtain the various source files of the project file.

[0065] Based on the program code to be tested, select the project file, search for each source file under the project file, and then obtain the corresponding source files of the project file.

[0066] Step S320: Identify and process the variable names of each source file to obtain the original variables of each corresponding source file; each original variable includes several original variables with the same name and several remaining original variables.

[0067] Based on the obtained source files, variable name identification processing is performed on each source file to obtain the original variables of each corresponding source file. The project file includes at least one source file, and each source file contains at least one original variable. Variables with the same name as the variable to be processed are identified as original variables with the same name; remaining original variables refer to the variables remaining after removing the variable to be processed and the original variables with the same name from the original variables.

[0068] For example, step S320 includes: finding columns in each source file that contain a first header field and a first tail field to obtain each column to be processed; obtaining the intermediate field between the first header field and the first tail field in each column to be processed, and confirming the intermediate field as the original variable to obtain each original variable.

[0069] The first header field can be an identifier string, for example, the first header field could be the string "volatile". The first tail field can be an identifier character, for example, the first tail field could be a semicolon (";") or a space (""). The middle field refers to the field name located between the first header field and the first tail field. Specifically, the processor can query each source file to obtain columns in the source file that contain "volatile" as the first header field and a semicolon (";") or space ("") as the first tail field, and confirm the middle name located between the first header field and the first tail field as the middle field, and confirm the name of the middle field as the name of the original variable, thereby obtaining each original variable.

[0070] Furthermore, the original variables are merged into an array for display on the interface, so that users can select the corresponding variables.

[0071] Step S330: Obtain the variable to be processed and the original variable with the same name.

[0072] For a detailed explanation of step S330 above, please refer to the description of the above embodiments, which will not be repeated here.

[0073] Step S340: Based on the preset format, modify the variable names of the variable to be processed and each existing variable with the same name to obtain the variable to be processed in the first format and each existing variable with the same name in the first format.

[0074] For a detailed explanation of step S340 above, please refer to the description of the above embodiments, which will not be repeated here.

[0075] Step S350: Based on the variables to be processed in the first format and the original variables with the same name in each first format, generate the current calibration variable and the observed variable corresponding to the variables to be processed in the first format.

[0076] For a detailed explanation of step S350, please refer to the description of the above embodiments, which will not be repeated here.

[0077] Step S360: Generate the current source file, current header file, and current A2L file based on the current calibration variables and observation variables.

[0078] For a detailed explanation of step S360, please refer to the description of the above embodiments, which will not be repeated here.

[0079] Step S370: Associate the current source file, the current header file, and the current A2L file with the project file respectively, and test the associated project file.

[0080] For a detailed explanation of step S370, please refer to the description of the above embodiments, which will not be repeated here.

[0081] In the above embodiments, by redefining a new variable to an existing variable and disabling the existing variable, three files—the current source file, the current header file, and the current A2L file—are automatically generated and associated with the existing variable. This allows for program code debugging by modifying only the new variable. It enables debugging without adding process variables or writing code manually, automatically restoring the original code, ensuring code structure, and improving debugging efficiency.

[0082] In one embodiment, such as Figure 4 As shown, a method for testing program code is provided, which can be applied to... Figure 1 Taking processor 102 as an example, the following steps are included:

[0083] Step S410: Obtain the variable to be processed and the original variable with the same name.

[0084] For a detailed explanation of step S410, please refer to the description of the above embodiments, which will not be repeated here.

[0085] Step S420: Based on the path information of the corresponding variable to be processed and the path information of each existing variable with the same name, a prefix field is set for the variable to be processed and each existing variable with the same name to obtain the first format variable to be processed and each existing variable with the same name in the first format.

[0086] The path information of the variable to be processed refers to the file path address of the variable to be processed in the project file, and the path information of the original variable with the same name refers to the file path address of the original variable with the same name in the project file.

[0087] When retrieving variables to be processed from the corresponding project file, the path address of the variable to be processed is recorded and maintained. Then, based on the path information of the variable to be processed, a prefix field can be set for the variable to be processed to obtain the variable to be processed in the first format. When querying existing variables with the same name from the corresponding project file, the path address of each existing variable with the same name is recorded and maintained. Then, based on the path information of each existing variable with the same name, a prefix field can be set for each existing variable with the same name to obtain each existing variable with the same name in the first format.

[0088] For example, the prefix field can be an identifier string, such as "Adap_". This allows the system to add the prefix "Adap_" to the name of the selected variable based on its path, and to add the prefix "Adap_" to all variables with the same name in the source file, thus achieving automatic modification of variable names.

[0089] Step S430: Based on the variables to be processed in the first format and the original variables with the same name in each first format, generate the current calibration variable and the observed variables corresponding to the variables to be processed in the first format.

[0090] For a detailed explanation of step S430 above, please refer to the description of the above embodiments, which will not be repeated here.

[0091] For example, in step S430, the step of generating the observed variable corresponding to the first format variable to be processed includes: declaring the first format variable to be processed to obtain the observed variable.

[0092] The program code in this application can be embedded code, such as C language-based program code. The processor can declare variables of the first format to be processed based on the C language program code rules to obtain the observed variables.

[0093] Step S440: Generate the current source file, current header file, and current A2L file based on the current calibration variables and observation variables.

[0094] For a detailed explanation of step S440, please refer to the description of the above embodiments, which will not be repeated here.

[0095] For example, in step S440, the step of generating the current source file based on the current calibration variable and the observed variable includes: associating the current calibration variable and the observed variable to obtain the current source file.

[0096] The processor correlates the current calibration variables and observed variables obtained from the processing to obtain the current source file, and then completes the generation of a new C file.

[0097] In step S440, the step of generating the current header file includes: declaring variables in the header file according to the number of variables in the current source file to obtain the current header file.

[0098] The processor, based on C language rules, declares variables in the header file according to the number of variables in the current source file, obtains the current header file, and then completes the generation of the new H file.

[0099] In step S440, the steps for generating the current A2L file include: obtaining the file header information and file footer information from the original A2L file according to the A2L file format; and generating the current A2L file based on the file header information, file footer information, and the current calibration variable.

[0100] This involves any A2L file within the project files of the original A2L file. According to the A2L file rules, the processor retrieves the header and footer files from any A2L file in the project files, removing the calibration and observation definitions from the middle of that A2L file. Based on the retrieved header and footer information and the current calibration variables, the processor merges the information, generating the current A2L file, and then completes the generation of a new *A2L file.

[0101] Step S450: Associate the current source file, the current header file, and the current A2L file with the project file respectively, and test the associated project file.

[0102] For a detailed explanation of step S450, please refer to the description of the above embodiments, which will not be repeated here.

[0103] For example, in step S450, the specific implementation process of associating the project files can be as follows: add #include "Adapter.h" to ASW_rte.h; add Adap_step() to the Swc.Os.c 10ms process (add if Swc.Os.c file is found); add Adap_Step() to the RTE_Bsw.c 10ms process (add if RTE_Bsw.c file is found); when the variable name is confirmed to contain COMR or BCMR, add the prefix "Adap_" to the name of the selected variable in the BCMR_DChrgComProc_types.h file; when the variable name is confirmed to contain COMR or BCMR, add the prefix "Adap_" to the name of the selected variable in the RTE_1939.c file.

[0104] In the above embodiments, by redefining a new variable to mask the original variable, three files—the current source file, the current header file, and the current A2L file—are automatically generated and associated with the original variable. This allows for debugging of the program code by modifying only the new variable. During debugging, no process variables need to be added, and no code needs to be written manually. The original code can be automatically restored, preserving the code structure and avoiding disruption. This facilitates code maintenance and improves debugging efficiency.

[0105] It should be understood that, although Figure 2-4 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2-4At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0106] In one embodiment, such as Figure 5 As shown, a program code testing device is provided, the program code testing device includes;

[0107] The variable selection unit 510 is used to obtain the variable to be processed and the existing variable with the same name.

[0108] The variable modification unit 520 is used to modify the variable name of the variable to be processed and each existing variable with the same name based on a preset format, so as to obtain the variable to be processed in the first format and each existing variable with the same name in the first format.

[0109] The variable generation unit 530 is used to generate the current calibration variable and the observation variable corresponding to the first format variable to be processed based on the first format variable to be processed and the original variables with the same name in each first format.

[0110] The file generation unit 540 is used to generate the current source file, the current header file, and the current A2L file based on the current calibration variables and observation variables.

[0111] The associated test unit 550 is used to associate the current source file, the current header file, and the current A2L file with the project file respectively, and to test the associated project file.

[0112] In one example, the test device for the program code is also used to: obtain the various source files of the project file;

[0113] The variable names of each source file are identified and processed to obtain the original variables of each corresponding source file; each original variable includes several original variables with the same name and several remaining original variables.

[0114] In one example, the test device of the program code is also used to: find the columns in each source file that contain the first header field and the first tail field to obtain each column to be processed; obtain the intermediate field between the first header field and the first tail field in each column to be processed, and confirm the intermediate field as the original variable to obtain each original variable.

[0115] In one example, the variable modification unit 520 is also used to: set a prefix field for the variable to be processed and each original variable with the same name based on the path information of the corresponding variable to be processed and the path information of each original variable with the same name, so as to obtain the variable to be processed in the first format and each original variable with the same name in the first format.

[0116] In one example, the variable generation unit 530 is also used to: declare variables for the first format variables to be processed, and obtain the observed variables.

[0117] In one example, the file generation unit 540 is also used to: associate the current calibration variable and the observed variable to obtain the current source file.

[0118] In one example, the file generation unit 540 is also used to: declare variables in the header file according to the number of variables in the current source file, and obtain the current header file.

[0119] In one example, the file generation unit 540 is also used to: obtain the file header information and file footer information from the original A2L file according to the A2L file format; and generate the current A2L file based on the file header information, file footer information, and the current calibration variable.

[0120] Specific limitations regarding the testing device for program code can be found in the limitations of the testing method for program code described above, and will not be repeated here. Each module in the aforementioned testing device for program code can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independently of the processor in the electronic device, or stored in software in the memory of the electronic device, so that the processor can call and execute the operations corresponding to each module.

[0121] In one embodiment, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the test method of any of the above-described program codes.

[0122] The processor is used to execute the following test method of program code:

[0123] Obtain the variable to be processed and the existing variables with the same name; based on a preset format, modify the variable names of the variable to be processed and each existing variable with the same name to obtain the variable to be processed in the first format and each existing variable with the same name in the first format; based on the variable to be processed in the first format and each existing variable with the same name in the first format, generate the current calibration variable and the observed variable corresponding to the variable to be processed in the first format; based on the current calibration variable and the observed variable, generate the current source file, the current header file, and the current A2L file; associate the current source file, the current header file, and the current A2L file with the project file respectively, and test the associated project file.

[0124] In the above embodiments, by redefining a new variable to an existing variable and disabling the existing variable, three files—the current source file, the current header file, and the current A2L file—are automatically generated and associated with the existing variable. This allows for program code debugging by modifying only the new variable. It enables debugging without adding process variables or writing code manually, automatically restoring the original code, ensuring code structure, and improving debugging efficiency.

[0125] In one embodiment, an electronic device is provided. The electronic device can be, but is not limited to, various types, including, desktop computers, laptop computers, or tablet computers. The internal structure diagram of the electronic device can be as follows: Figure 6 As shown. The electronic device includes a processor and memory connected via a system bus; the electronic device may also include a network interface and input devices. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements a method for testing program code.

[0126] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the electronic device to which the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.

[0127] In one embodiment, a computer-readable storage medium is also provided having executable code stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute program code as described above, a test method.

[0128] In one example, when a computer program is executed by a processor, it performs the following steps:

[0129] Obtain the variable to be processed and the existing variables with the same name; based on a preset format, modify the variable names of the variable to be processed and each existing variable with the same name to obtain the variable to be processed in the first format and each existing variable with the same name in the first format; based on the variable to be processed in the first format and each existing variable with the same name in the first format, generate the current calibration variable and the observed variable corresponding to the variable to be processed in the first format; based on the current calibration variable and the observed variable, generate the current source file, the current header file, and the current A2L file; associate the current source file, the current header file, and the current A2L file with the project file respectively, and test the associated project file.

[0130] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the division operations described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0131] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0132] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A method for testing program code, characterized in that, Includes the following steps: Get the variable to be processed and the existing variable with the same name; Based on a preset format, the variable names of the variables to be processed and the original variables with the same name are modified to obtain the variables to be processed in the first format and the original variables with the same name in the first format. Based on the variables to be processed in the first format and the existing variables with the same name in the first format, generate the current calibration variable and the observation variable corresponding to the variables to be processed in the first format; Based on the current calibration variables and the observed variables, generate the current source file, the current header file, and the current A2L file; The current source file, the current header file, and the current A2L file are each associated with a project file, and the associated project file is then tested. in, The step of generating the current source file based on the current calibration variable and the observed variable includes: The current calibration variable and the observed variable are correlated to obtain the current source file; The steps for generating the current header file include: Based on the number of variables in the current source file, declare them in the header file to obtain the current header file.

2. The method for testing program code according to claim 1, characterized in that, Prior to the step of obtaining the variable to be processed, the following is included: Obtain the various source files of the project file; The variable names of each source file are identified and processed to obtain the original variables corresponding to each source file; each original variable includes several original variables with the same name and several remaining original variables.

3. The method for testing program code according to claim 2, characterized in that, The steps for identifying and processing the variable names of each of the source files include: Locate the columns in each of the aforementioned source files that contain the first header field and the first tail field to obtain the columns to be processed; Obtain the intermediate field located between the first head field and the first tail field in each of the columns to be processed, and confirm the intermediate field as the original variable to obtain each of the original variables.

4. The method for testing program code according to claim 1, characterized in that, The step of modifying the variable names of the variable to be processed and each of the original variables with the same name includes: Based on the path information of the variable to be processed and the path information of each of the original variables with the same name, a prefix field is set for the variable to be processed and each of the original variables with the same name to obtain the variable to be processed in the first format and each of the original variables with the same name in the first format.

5. The method for testing program code according to claim 1, characterized in that, The step of generating the observed variable corresponding to the variable to be processed in the first format includes: The observed variables are obtained by declaring the variables to be processed in the first format.

6. The method for testing program code according to claim 1, characterized in that, The steps for generating the current A2L file include: Based on the A2L file format, obtain the file header and file footer information from the original A2L file; The current A2L file is generated based on the file header information, the file footer information, and the current calibration variable.

7. A testing device for program code, characterized in that, include: The variable selection unit is used to obtain the variable to be processed and the existing variable with the same name; The variable modification unit is used to modify the variable to be processed and each of the original variables with the same name based on a preset format, so as to obtain the variable to be processed in the first format and each of the original variables with the same name in the first format. The variable generation unit is used to generate the current calibration variable and the observation variable corresponding to the first format variable based on the first format variable to be processed and each existing variable with the same name in the first format; The file generation unit is used to generate a current source file, a current header file, and a current A2L file based on the current calibration variable and the observed variable. Generating the current source file includes associating the current calibration variable and the observed variable to obtain the current source file. Generating the current header file includes declaring the variables in the header file according to the number of variables in the current source file to obtain the current header file. The associated test unit is used to associate the current source file, the current header file, and the current A2L file with the project file respectively, and to test the associated project file.

8. An electronic device, characterized in that, It includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the test method of the program code according to any one of claims 1 to 6.

9. A computer-readable storage medium having executable code stored thereon, which, when executed by a processor of an electronic device, causes the processor to perform the method as described in any one of claims 1 to 6.