If you think it's ok, we can actually migrate to new PICShell version... Seb
> Revision: 1361 > Author: [email protected] > Date: Tue Sep 29 01:44:14 2009 > Log: undo unittest changeset > http://code.google.com/p/jallib/source/detail?r=1361 > > Deleted: > /trunk/test/unittest/18f14k50_adc.jalt > Modified: > /trunk/tools/jallib.py > > ======================================= > --- /trunk/test/unittest/18f14k50_adc.jalt Mon Sep 28 16:41:33 2009 > +++ /dev/null > @@ -1,137 +0,0 @@ > --- Title: unittest to check ADC libs for 18f14k50 > --- Author: Albert Faber, Copyright (c) 2009, all rights reserved. > --- Adapted-by: > --- Compiler: >=2.4l > --- > --- This file is part of jallib (http://jallib.googlecode.com) > --- Released under the BSD license > (http://www.opensource.org/licenses/bsd-license.php) > --- > --- Description: this describes multiple unittests (a testcase), to test > the > --- many different combination while setting up ADC. > --- > --- Notes: see jallib wiki page about unit testing to learn how to use this > file > --- > - > -;@jallib section pic > -include 18f14k50 ;@no_debug > -pragma target OSC HS > -pragma target clock 20_000_000 > -pragma target WDT disabled > -enable_digital_io() > --- force analog pin/port to be output, so we can check they are > --- automagically set as input when configured (else it can be optimized > away) > -porta_direction = all_output > -portb_direction = all_output > -portc_direction = all_output > - > - > -;@jallib section self_test > -include unittest > -var byte a = 120 > -test_byte(a) ;@assertEquals 120 test_test > - > - > -;@jallib testcase test_all_analog_pins > -;@jallib use pic > -;@jallib use self_test > -const byte ADC_NVREF = 0 > -const bit ADC_HIGH_RESOLUTION = false > -const word ADC_RSOURCE = 2_500 > -porta_direction = all_output > -portb_direction = all_output > -portc_direction = all_output > - > -include adc > -adc_init() > - > -set_analog_pin(0) > --- check pin on PORTA configured as inputs (not supported) > -asm nop > -test_byte(TRISA) ;@assertEquals 0 test_porta_pin_an0_input > -asm nop > -test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an0_input > -asm nop > -test_byte(TRISC) ;@assertEquals 0 test_portb_pin_an0_input > - > - > -set_analog_pin(1) > --- check pin on PORTA configured as inputs (not supported) > -asm nop > -test_byte(TRISA) ;@assertEquals 0 test_porta_pin_an01_input > -asm nop > -test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an01_input > -asm nop > -test_byte(TRISC) ;@assertEquals 0 test_portb_pin_an01_input > - > -set_analog_pin(2) > --- check pin on PORTA configured as inputs (not supported) > -asm nop > -test_byte(TRISA) ;@assertEquals 0 test_porta_pin_an012_input > -asm nop > -test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an012_input > -asm nop > -test_byte(TRISC) ;@assertEquals 0 test_portb_pin_an012_input > - > - > -set_analog_pin(3) > --- check pin on PORTA configured as inputs (0b_0001_0000 => RA{4}) > -asm nop > -test_byte(TRISA) ;@assertEquals 32 test_porta_pin_an0123_input > -asm nop > -test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an0123_input > -asm nop > -test_byte(TRISC) ;@assertEquals 0 test_portb_pin_an0123_input > - > -set_analog_pin(4) > --- check pin on PORTC configured as inputs (0b_0000_0001 => RC{0} ) > -asm nop > -test_byte(TRISA) ;@assertEquals 32 test_porta_pin_an01234_input > -asm nop > -test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an01234_input > -asm nop > -test_byte(TRISC) ;@assertEquals 1 test_portb_pin_an01234_input > - > -set_analog_pin(5) > --- check pin on PORTC configured as inputs (0b_0000_0011 => RC{1},RC{0} ) > -asm nop > -test_byte(TRISA) ;@assertEquals 32 test_porta_pin_an012345_input > -asm nop > -test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an012345_input > -asm nop > -test_byte(TRISC) ;@assertEquals 3 test_portb_pin_an012345_input > - > -set_analog_pin(6) > --- check pin on PORTC configured as inputs (0b_0000_0111 => > RC{2},RC{1},RC{0} ) > -asm nop > -test_byte(TRISA) ;@assertEquals 32 test_porta_pin_an0123456_input > -asm nop > -test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an0123456_input > -asm nop > -test_byte(TRISC) ;@assertEquals 7 test_portb_pin_an0123456_input > - > -set_analog_pin(7) > --- check pin on PORTC configured as inputs (0b_0000_1111 => > RC{3},RC{2},RC{1},RC{0} ) > -asm nop > -test_byte(TRISA) ;@assertEquals 32 test_porta_pin_an01234567_input > -asm nop > -test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an01234567_input > -asm nop > -test_byte(TRISC) ;@assertEquals 15 test_portb_pin_an01234567_input > - > -set_analog_pin(8) > --- check pin on PORTC configured as inputs (0b_0100_1111 => > RC(6),RC{3},RC{2},RC{1},RC{0} ) > -asm nop > -test_byte(TRISA) ;@assertEquals 32 test_porta_pin_an012345678_input > -asm nop > -test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an012345678_input > -asm nop > -test_byte(TRISC) ;@assertEquals 79 test_portb_pin_an012345678_input > - > -set_analog_pin(9) > --- check pin on PORTC configured as inputs (0b_1100_1111 => > RC{7},RC{6},RC{3},RC{2},RC{1},RC{0} ) > -asm nop > -test_byte(TRISA) ;@assertEquals 32 test_porta_pin_an0123456789_input > -asm nop > -test_byte(TRISB) ;@assertEquals 0 test_portb_pin_an0123456789_input > -asm nop > -test_byte(TRISC) ;@assertEquals 207 test_portb_pin_an0123456789_input > ======================================= > --- /trunk/tools/jallib.py Mon Sep 28 15:23:55 2009 > +++ /trunk/tools/jallib.py Tue Sep 29 01:44:14 2009 > @@ -47,6 +47,12 @@ > except ImportError: > has_subprocess = False > > +try: > + import picshell.engine.core.PicEngine > + has_picshell = True > +except ImportError: > + has_picshell = False > + > > ######### > # TOOLS # > @@ -756,6 +762,81 @@ > # JALAPI FUNC # > #-------------# > > +def picshell_unittest(jalFileName,asmFileName,hexFileName): > + > + if not has_picshell: > + print >> sys.stderr, "Can't find PICShell libraries. Install > PICShell and adjust PYTHONPATH" > + sys.exit(255) > + > + # This piece of code is loosely based on PICShell implementation. > + # This is a quick & dirty assembling :) > + > + from picshell.parser.JalV2AsmParser import JalV2AsmParser > + from picshell.parser.AnnotationParser import AnnotationParser > + from picshell.engine.core.PicThreadEngine import PicThreadEngine > + from picshell.engine.core.PicEngine import PicEngine > + from picshell.engine.core.State import State > + from picshell.util.AssertUtil import AssertUtil > + > + from picshell.ui.UIManager import UIManager > + > + asmParser = JalV2AsmParser() > + wholeCode = asmParser.parseAsmFile(asmFileName, []) > + varTypeDict = JalV2AsmParser.buildVarTypeDict(wholeCode) > + > + parseRes = AnnotationParser.parse(file(jalFileName).read()) > + noDebugList = parseRes["noDebug"] > + debugList = parseRes["debug"] > + langParser = JalV2AsmParser() > + code = langParser.parseAsmFile(asmFileName, noDebugList,debugList) > + > + def unittest_callback(address,oracle): > + line = langParser.adrToLine[address] > + if line != None: > + txt = code[line].line > + if "@assertEquals" in txt: > + res = AssertUtil.parse(txt) > + var = res["var"].lower() > + label = res["label"] > + ref = res["ref"] > + if (langParser.varAdrMapping.has_key("v_"+str(var))): > + varAddr = langParser.varAdrMapping["v_"+str(var)] > + varType = type = varTypeDict.get(var,'bit') > + val = ui.varValue(varAddr,varType) > + res= varType+" "+var+" (@"+str(varAddr)+") = 0x%X , > expected : 0x%X" %(val,ref) > + > + print label, > + if (ref == val) : > + oracle['success'] += 1 > + print ": OK" > + else : > + oracle['failure'] += 1 > + print ": FAIL, %s != %s" % (ref,val) > + else: > + oracle['notrun'] += 1 > + print "Can't run test '%s' because var '%s' can't be > found" % (label,var) > + > + emu = PicEngine.newInstance(State(),hexFileName) > + # needed to access varValue function > + ui = UIManager() > + ui.emu = emu > + > + # success failure notrun > + oracle = {'success' : 0, 'failure' : 0, 'notrun' : 0} > + def run(to,emu,unittest_callback): > + current_address = emu.runNext() > + while current_address != to: > + #unit testing ? > + if unittest_callback != None: > + unittest_callback(current_address,oracle) > + current_address = emu.runNext() > + # last call on finishing address > + unittest_callback(current_address,oracle) > + > + run(emu.lastAddress,emu,unittest_callback) > + > + return oracle > + > def unittest(filename,verbose=False): > oracle = {'success' : None, 'failure' : None, 'notrun' : None} > content = file(filename).read().splitlines() > @@ -766,8 +847,6 @@ > fout = file(fnout,"w") > ferr = file(fnerr,"w") > status = > > do_compile([filename],exitonerror=False,clean=False,stdout=fout,stderr=ferr) > - fout.close() > - ferr.close() > except Exception,e: > print >> sys.stderr, "Error while compiling file '%s': %s" % > (filename,e) > raise > @@ -778,30 +857,15 @@ > jal = filename > asm = filename.replace(".jal",".asm") > hex = filename.replace(".jal",".hex") > - > - try: > - from picshell.console.picshell_unittest import > picshell_unittest > - oracle = picshell_unittest(jal,asm,hex) > - except ImportError: > - print >> sys.stderr, "Can't find PICShell libraries. > Install PICShell and adjust PYTHONPATH" > - sys.exit(255) > - oracle['failure'] = 1 > - > + oracle = picshell_unittest(jal,asm,hex) > else: > oracle['failure'] = 1 > > finally: > - fout = file(fnout) > - ferr = file(fnerr) > - > clean_compiler_products(filename) > - > - fout.close() > - ferr.close() > if verbose: > - print fout.read() > - print ferr.read() > - > + print file(fnout).read() > + print file(fnerr).read() > os.unlink(fnout) > os.unlink(fnerr) > > @@ -1210,7 +1274,8 @@ > tests, several sections, which are assembled on the fly > (something like board/test files producing samples) > > -Tests is done using PICShell unittesting facilities. Several actions can > be checked: > +Tests is done using PICShell unittesting facilities. PIC 18F aren't > +supported. Several actions can be checked: > > - @assertEquals: will check a variable against a value (from PICShell). > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jallib?hl=en -~----------~----~----~----~------~----~------~--~---
