Background
An Integrated Development Environment (IDE Integrated Development Environment) of a chip plays an important role as a platform for manufacturers to develop the chip, IDE software generally comprises a C compiler and an assembler, along with the rapid demand of the chip market, the Development efficiency of the traditional assembler is difficult to meet, and the C compiler plays a key role in the embedded field nowadays. In the process of developing the C compiler by the chip manufacturer, a problem is involved in how to verify the correctness of the C compiler and the related tool chain (C compiler, assembler, linker).
When the compiler test mode comprises a traditional compiler test mode and a Ctcgen tool test mode, the traditional compiler test mode: according to the grammar, a test program generator is designed, and then the test cases are compiled by a compiler to be tested, and expected test results are contained in the test program, so that the comparison of the test results can be carried out, but the defects are all defects in the aspect of deep test.
Disclosure of Invention
Based on this, the first objective of the present invention is to provide a method for automated testing of a C compiler, which solves the problems of tedious manual testing and slow speed of the C compiler.
Another objective of the present invention is to provide a method for automated testing of C compiler, which realizes rapid automated testing of C compiler, and combines the development environment of the entire IDE to indirectly test the correctness of the tool chain of the entire C compiler, and can liberate testers and reduce the work intensity.
In order to achieve the purpose, the technical scheme of the invention is as follows:
a method for automatically testing a C compiler is characterized in that assembly is embedded in a C source file, an HEX file is obtained by compiling a CSCC (C compiler), a CSASM (assembler) and a CSLINK (linker), and an expected result is verified by combining a lower computer hardware simulator, so that the aim of verifying the CSCC compiler is fulfilled.
The method comprises the following specific steps:
101. clicking a batch processing file to run;
102. creating a log folder and a log file of the test;
103. reading an initial configuration file init.xml, and obtaining the configurations of a test case folder of a C project to be tested, a path of a C compiler and the like;
104. reading a C project file list with a suffix name of csuprj of a test case folder;
105. calling a ProjectParser.dll module, analyzing the C engineering file, and acquiring configuration parameters in the C engineering file; the parameters mainly comprise a source file name, a chip model, a source file and the like;
106. generating a makefile according to the configuration parameters, wherein the makefile is mainly called by make.exe;
107. generating a script.lik file according to the configuration parameters, wherein the file is mainly called by a CSLinker;
108. exe, namely constructing and compiling the C engineering file;
109. judging whether the compiling is correct or not, and determining the existence of a hex machine code file;
110. downloading an rbf file according to the model of the chip, and reconstructing a simulation model of the chip;
111. calling RunTest.exe, and checking the running result of the lower computer;
112. saving the result of the printing operation;
113. and (5) looping back to the step 105 until all test cases are run.
The specific flow of the simulation model for reconstructing the chip is as follows:
201. the PC sends a connection command;
202. the FPGA receives and analyzes the command;
203. PC waits for response;
204. loading a chip RBF simulation time sequence file;
205. waiting for the response of the FPGA;
206. judging whether the time sequence file is sent completely;
207. and finishing the reconstruction of the chip simulation model.
The test operation flow comprises the following steps:
301. entering simulation;
302. break points are set at 0x002 and 0x003 of a PC (program counter);
303. executing full-speed operation;
304. reading the stopped PC;
305. judging whether the test case is correct or incorrect according to the writing method of the previous test case;
306. storing the result into a log file;
307. and (6) exiting.
The automatic testing method realizes the quick automatic testing of the C compiler, simultaneously combines the development environment of the whole IDE, indirectly tests the correctness of the tool chain of the whole C compiler, and solves the problems of complicated manual compiling, entering simulation setting, low operation speed and the like of the C compiler. Thereby greatly freeing the tester and reducing the working strength.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The test scheme implemented by the invention needs a reference compiler, preferably a PICC compiler of Microchip company, but the difference exists between the running library (PICC RunTime Lib) called by the PICC compiler and the running library (CSCC RunTime Lib) of Chihai, so that the generated object code has indeterminate difference. The current feasible technical scheme is as follows: according to the characteristics of the kernel of the chip, assembly is embedded in a C source file, an HEX file is obtained by compiling through a CSCC (C compiler), a CSASM (assembler) and a CSLINK (linker), and an expected result is verified by combining a lower computer hardware simulator, so that the aim of verifying the CSCC compiler is fulfilled.
A platform is provided for the C compiler to implement the rapid automated testing of the C compiler, as shown in fig. 1, the specific steps are described as follows:
s101, clicking a batch processing file to start running;
the file is a batch file with the suffix of bat, and is mainly used for facilitating one-key test of testers and improving the working efficiency.
S102, creating a log folder and a log file of the test;
folders and log files are created using the time of Python, log module, named according to the time of each click. And recording the operation result of the platform in the log file in the whole process. Meanwhile, the information printed by the console window is recorded, so that errors in the test process can be conveniently searched.
S103, reading an initial configuration file init.xml, and acquiring the configurations of a test case folder of the C project to be tested, a path of a C compiler and the like;
after the tester writes all the test cases, the tester places the test cases in an environment position of a specified position, such as a certain path of an IDE (integrated development environment) according to the compiler exe provided by a developer of the C compiler, and the tester can configure the path of the C engineering file set and the path of the C compiler to test the C compiler of the current version.
S104, reading a C project file list with a test case folder suffix name of csuprj;
the C project file can be placed in any place of the folder, the Python algorithm can search all the C project files under the folder, the file paths are stored in a Python list, and each C project test case can be tested circularly through the list.
S105, calling a ProjectParser.dll module, analyzing the C engineering file, and acquiring configuration parameters in the C engineering file; the parameters mainly comprise a source file name, a chip model, a source file and the like;
the Python script analyzes the C engineering file by calling a ProjectParser. dll module, the format of the engineering file is similar to an xml file, and the main acquired parameters are as follows: output folders, project file paths, project file names, chip families, chip models, C compiler options, assembler options, linker options, code options, assembly file lists, and the like. This information is necessary to generate the makefile and script.
S106, generating a makefile according to the configuration parameters, wherein the makefile is mainly called by make.
The standard IDE has makefile files, and a compiler, an assembler and a linker are called by make.
S107, generating a script file according to the configuration parameters, wherein the file is mainly called by a CSLinker;
s108, executing make.exe, which is equivalent to the construction and compiling of the C engineering file;
s109, judging whether the compiling is correct or not, and determining the existence of the hex machine code file;
s110, downloading an rbf file according to the model of the chip, and reconstructing a simulation model of the chip;
this step is mainly prepared for testing hex machine code, and the significance of reconstructing the simulation model of the chip is that when the tested C project contains different chip models, it is not feasible for automated testing if manual switching is required if the actual chip is used. The simulation model of the reconstructed chip is described in detail in the second section.
S111, calling RunTest.exe, and checking the running result of the lower computer;
s112, saving the result of the printing operation
And S113, circularly returning to the step S105 until all the test cases are operated.
And reconstructing the simulation model of the chip, wherein after the automatic compilation of the project is finished, the PC and the FPGA realize communication through a USB according to the chip type parameters provided by the C project file, and the time sequence file of the RBF simulation model of the chip is sent to a lower computer simulation board to realize the reconstruction of the simulation model of the chip. The block diagram of the PC and the FPGA is shown in FIG. 2, and a specific flow chart of the module is shown in FIG. 3. The specific process comprises the following steps:
s201, the PC sends a connection command;
s202, receiving and analyzing a command by the FPGA;
s203, the PC waits for response;
s204, loading a chip RBF simulation time sequence file;
s205, waiting for the response of the FPGA;
s206, judging whether the time sequence file is sent completely;
s207, reconstructing the chip simulation model;
and S208, printing result information.
As shown in fig. 4, the result of the test operation is that after the compiling is completed and the chip simulation model is reconstructed, the hardware of the lower computer is communicated:
s301, entering simulation;
firstly, sending a connection establishing instruction (PSFSD) to an FPGA by a PC end; the version number of the FPGA is given back to the PC; if the FPGA end reads correct data, a response instruction (FSPDACK) is sent back, if the instruction is found to be read wrongly, an error information receiving instruction (FSPERR) is sent back, the PC end resends the connection instruction to the FPGA, and if the instruction is still wrong, a user is prompted to have a problem in connection.
S302, setting breakpoints at 0x002 and 0x003 of the PC;
and the PC sends a breakpoint information instruction PSFB to the FPGA. The breakpoint command sent by the PC includes 16bytes of data, which respectively correspond to 6 breakpoints and 2 macro breakpoints, and each breakpoint data includes 2 bytes. The first 12 data correspond to 6 breakpoints, the last 4 data correspond to 2 macro breakpoints, and the high byte is in front, and debugging breakpoints are set at addresses 0x002 and 0x003 according to the protocol.
S303, executing full-speed operation;
the running program has two modes, Freun and run. The difference between these two modes is that a run mode is selected because a break point encountered in a Free run will not stop, and a run will stop when a break point is encountered, where the break point is to be stopped. When the situation is met, a timer is set in a running thread, and when the time of the thread exceeds the timed time, the thread is forced to stop running and return an error code.
S304, reading the stopped PC;
after receiving the trace debugging instruction PSFTRACE, the FPGA sends a data return instruction FSPRB to the PC and returns SFR and RAM data. The PC end receives the instruction and the data, and after the verification result is correct, if more RAM data need to be read, the PSFCACK instruction is returned, and the data continues to be received; if no more data needs to be read, a PSFEACK instruction is returned indicating that no error is received. The return PC (program counter) can be obtained by parsing the packet.
S305, judging whether the test case is correct or incorrect according to the previous compiling method of the test case;
setting a condition for judging normal operation of a program in each C file test case, wherein according to the characteristics of an 8-bit singlechip chip, general users of 002H and 003H addresses of a PC of the program cannot access the program, and embedding the following assembly statements in the C program as judgment:
if (a ═ b) { asm ("goto 003H"); // if successful, PC points to 003
Else { asm ("goto 002H"); // if wrong, PC points to 002
}
Breakpoints are set at test case PC-0 x02 and PC-0 x 03. If the test point of the peripheral test passes after the test case runs, the PC is stopped at 0x03 by call PASSED, and if the test point passes, the PC is stopped at 0x02 by call FAILED, and then the test result is output.
S306, storing the result into a log file;
according to the prior process of automated compiling test of the C compiler, one step is a logging module of logger, python determines the correctness of operation by calling a module of Runtest. exe and the return value of exe, thereby achieving the verification of the operation result.
And S307, exiting.
The automatic testing method realizes the quick automatic testing of the C compiler, simultaneously combines the development environment of the whole IDE, indirectly tests the correctness of the tool chain of the whole C compiler, and solves the problems of complicated manual compiling, entering simulation setting, low operation speed and the like of the C compiler. Thereby greatly freeing the tester and reducing the working strength.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents and improvements made within the spirit and principle of the present invention are intended to be included within the scope of the present invention.