From: Scott D. <sc...@da...> - 2000-11-21 15:24:48
|
I've created a very simple script that works with the PIC Port of SDCC, gpasm, and gpsim to automatically test the code generarted by SDCC. I'm not sure if it is useful for the '51 port or not. But this is how it works: The test .c programs are written such that they all have a function called `done()' and a variable called `success'. There will also be code in program to service the WDT. I'll use a Makefile to: 1) compile the test program 2) Assemble it with gpasm 3) Invoke gpsim (the gnupic simulator) in command line mode and generate a log file. 4) gpsim will also be invoked with a script that will do this: load the program set a break point at done set a break point at the WDT timeout routine. run the program display the contents of the variable `success' 5) The output of the log file produced by gpsim is grep'd for success like so: # SDCC test script for the PIC Port # GPSIM_SCRIPT="s.stc" LOGFILE="r" echo "Test $GPSIM_SCRIPT" > $LOGFILE ./gpsim --cli -c $GPSIM_SCRIPT $2> test grep "success " test | grep "0x0" if [ $? -eq 0 ] ; then echo "PASSED" >> $LOGFILE else echo "FAILED" >> $LOGFILE fi If the simulation was successful, then the value of success will be a zero (0x0) and PASSED will be written to the logfile. 6) After the whole test is complete, the logfile can be grep'd again for FAILED to see which if any of the programs failed the test. Now the .c programs that are being tested have to be constructed in such a way to conform to the test. Each will have check it's own results if they fail, set the error in the variable `success'. Here's a contrived example: unsigned char uc0; unsigned char success=0; //assume success void done(void) { uc0 = 1; // won't get executed... } void WDT(void) { success |= 0x80; // Set msb to indicate WDT timeout - in case we get stuck // in a loop done(); } void test_plus(unsigned char uc) { uc0 += uc; } main() { uc0 = 5; test_plus(6); if(uc0 != 11) success = FAILED_TEST1; } I'd appreciate any suggestions on whether this is good idea or if it can be improved. Also, does anyone have some test code that I could borrow? Scott |