Esempio n. 1
0
def negedge():
    global cycles, idle, Ain, state, Max
    cycles += 1
    veri.force('tb.cycles', str(cycles))
    if (cycles > 1000):
        veri.listing('tb', '1000', 'cucu.list')
        veri.finish()
    rst_n = veri.peek('tb.rst_n')
    if (rst_n != '1'):
        ain = veri.peek('tb.ain')
        Len = len(ain)
        Max = 1 << Len
        return

    veri.force('tb.en', '1')

    if state == 'idle':
        Ain = random.randint(0, Max)
        veri.force('tb.ain', logs.make_str(Ain))
        veri.force('tb.vldin', '1')
        state = 'work0'
    elif state == 'work0':
        veri.force('tb.vldin', '0')
        state = 'wait0'
    elif state == 'wait0':
        vldout = logs.peek('tb.vldout')
        if vldout == 1:
            Out = logs.peek('tb.out')
            Exp = int(math.sqrt(Ain))
            if Out == Exp:
                logs.log_correct('in=%d out=%d' % (Ain, Out))
            else:
                logs.log_wrong('ain=%d max=%d expected=%d act=%d' %
                               (Ain, Max, int(math.sqrt(Ain)), Out))
            state = 'idle'
Esempio n. 2
0
 def print_fail(self, What, Sig, Char, Now):
     Str = '%s %s exp=%s act=%s vec=%d line=%d cycle=%d time=%s\n' % (
         What, Sig, str(Char), str(Now), self.emitting, self.activeline,
         self.cycle, str(veri.stime()))
     logs.log_wrong(Str)
     self.bads += 1
     veri.force('tb.bads', str(self.bads))
Esempio n. 3
0
    def force(self,Sig,Val):
        if self.Aluka:
            Now = self.peek(Sig)
            if str(Val)!=str(Now):
                logs.log_wrong('aluka %s  sig=%s   exp=%s act=%s'%(self.Path,Sig,Val,Now))
#            else:
#                logs.log_correct('aluka %s  sig=%s   exp=%s act=%s'%(self.Path,Sig,Val,Now))
            return
        return veri.force('%s.%s'%(self.Path,Sig),str(Val))
Esempio n. 4
0
 def checkVar(self, Var, Val, Bin):
     if Var == 'R1': return
     if Var not in self.Vars:
         logs.log_error('ilia! @%s checkvar got %s (%s) undefined in rtl' %
                        (self.Name, Var, Val))
     elif closeEnough(Val, self.Vars[Var]):
         logs.log_correct('checkvar @%s ok on %s = %s 0x%08x (%s)' %
                          (self.Name, Var, Val, Bin, self.Vars[Var]))
     else:
         logs.log_wrong('@%s checkvar on %s = %s 0x%08x (%s)' %
                        (self.Name, Var, Val, Bin, self.Vars[Var]))
Esempio n. 5
0
def negedge():
    global cycles, idle, Ain, state, Max, Pause
    cycles += 1
    veri.force('tb.cycles', str(cycles))
    if (cycles > 1000000):
        veri.listing('tb', '1000', 'cucu.list')
        veri.finish()
        return
    veri.force('tb.en', '1')

    rst_n = veri.peek('tb.rst_n')
    if (rst_n != '1') and (cycles < 100):
        ain = veri.peek('tb.ain')
        Len = len(ain)
        Max = 1 << Len
        veri.force('tb.makeStuckList', '1')
        return

    if (cycles > 30):
        for Mon in Monitors:
            Mon.run()

    if state == 'reset':
        Pause -= 1
        if Pause == 0:
            state = 'idle'
            veri.force('tb.rst_n', '1')
    elif state == 'idle':
        Ain = random.randint(0, Max)
        veri.force('tb.ain', logs.make_str(Ain))
        veri.force('tb.vldin', '1')
        state = 'work0'
    elif state == 'work0':
        veri.force('tb.vldin', '0')
        state = 'wait0'
    elif state == 'wait0':
        vldout = logs.peek('tb.vldout')
        if vldout == 1:
            state = 'idle'
            return
            Out = logs.peek('tb.out')
            Exp = int(math.sqrt(Ain))
            if Out == Exp:
                logs.log_correct('in=%d out=%d' % (Ain, Out))
            else:
                logs.log_wrong('ain=%d max=%d expected=%d act=%d' %
                               (Ain, Max, int(math.sqrt(Ain)), Out))
            state = 'idle'
Esempio n. 6
0
 def report__(self, St):
     Exp1, Exp0, Indx = extract(self.Pix1, self.Pix0)
     Lefts = len(list(PIXELS[3].keys()))
     if Indx < 0:
         logs.log_wrong(
             '#%d %s %d (left %d) self.Pix1 = %x  self.Pix0 = %x (E1=%x E0=%x)'
             %
             (self.Indx, St, Indx, Lefts, self.Pix1, self.Pix0, Exp1, Exp0))
     else:
         logs.log_info(
             '#%d %s %d self.Pix1 = %x  self.Pix0 = %x (E1=%x E0=%x)' %
             (self.Indx, St, Indx, self.Pix1, self.Pix0, Exp1, Exp0))
     self.Indx += 1
     if self.Indx > 2368:
         for Key in PIXELS[3]:
             logs.log_info('leftovers ind=%d pix %04x %04x' %
                           (PIXELS[3][Key], Key[0], Key[1]))
Esempio n. 7
0
def monitor_rx():
    global arrivedCharacters
    if veri.peek('tb.rx_valid0')=='1':
        fdata = logs.peek('tb.rxdata0')
        if scoreboard==[]:
            logs.log_wrong('character arrived unexpectedly (%x)'%fdata)
        else:
            Expected = scoreboard.pop(0)
            if Expected==fdata:
                logs.log_correct('character arrived correctly (%x)'%fdata)
            else:
                logs.log_wrong('character arrived uncorrectly exp=%02x    act=%02x '%(Expected,fdata))
                

        arrivedCharacters += 1
        if arrivedCharacters>=TEST_LENGTH:
            logs.finish()
        veri.force('tb.read_rx0','1')
    else:
        veri.force('tb.read_rx0','0')
Esempio n. 8
0
    def run(self):
        Din = self.peek('din')
        self.values.pop(0)
        self.values.append(Din)

        denom = 0
        nomin = 0
        for II in range(0, 9):
            Coef = self.peek_mem('coeffs', II)
            denom += Coef
            nomin += Coef * self.values[II]
        Result = nomin / denom
        self.expecteds.append(Result)

        if len(self.expecteds) > DELAY:
            Dout = self.peek('dout')
            Dexp = self.expecteds.pop(0)
            if Dout == Dexp:
                logs.log_correct('exp=%d dout=%d' % (Dexp, Dout))
            else:
                logs.log_wrong('exp=%d dout=%d' % (Dexp, Dout))
Esempio n. 9
0
    def readAction(self, rid, rlast, rdatax, widrid, rresp):
        if self.AREADS == []:
            logs.log_error('READ ACTION %s and no AREADS' % (self.Name))
            return
        Len, Addr, Rid, Pos = self.AREADS[0]
        logs.log_info(
            'axi Master %s READ len=%x addr0=%x addr=%x arid=%x || rid=%x rlast=%x data=%x  rresp=%d  areads= %s'
            % (self.Name, Len, Addr, Addr + 8 * Pos, Rid, rid, rlast, rdatax,
               rresp, self.AREADS))
        self.AREADS[0] = (Len, Addr, Rid, Pos + 1)

        if (Rid & ((1 << widrid) - 1)) != rid:
            logs.log_wrong('sent ARID=%d RID=%d' % (Rid, rid))
        if rresp != 0:
            logs.log_wrong('RRESP came back %s  ADDR=%a  rid=0x%x' %
                           (rresp, Addr, Rid))

        if Addr in self.RDATAS:
            self.RDATAS[Addr].append(rdatax)
        else:
            self.RDATAS[Addr] = [rdatax]
        if rlast == 1:
            self.AREADS.pop(0)
Esempio n. 10
0
 def run(self):
     if self.lastRunTime>0:
         self.clockRunDuration =  veri.stime() - self.lastRunTime 
     self.lastRunTime  = veri.stime()
 
 
     if self.waiting:
         self.waiting -= 1
         if (self.waiting>0) and ((self.waiting % 100)==0):
             logs.log_info('waiting ilia %d'%self.waiting)
         return
 
 
     if self.waitUntilOr!=[]:
         for (Sig,Val) in self.waitUntilOr:
             Act = self.peek(Sig)
             if Act == logs.intxx(Val):
                 self.waitUntilOr=[]
                 logs.log_info('waitUntilOr done')
                 return
         self.waitNum += 1
         if (self.waitNum % 1000)==0:
                 logs.log_info('waitUntilOr %d  %s'%(self.waitNum,self.waitUntilOr))
         return
             
     if self.waitUntilAnd!=[]:
         for (Sig,Val) in self.waitUntilAnd:
             Act = self.peek(Sig)
             if Act != logs.intxx(Val):
                 self.waitNum += 1
                 if (self.waitNum % 1000)==0:
                         logs.log_info('waitUntilAnd %d  %s'%(self.waitNum,self.waitUntilAnd))
                 return
 
         self.waitUntilAnd=[]
         logs.log_info('waitUntilAnd done')
         return
             
     if self.waitVar:
         Exp = logs.getVar(self.waitVar)
         if (Exp == self.waitVal)or(str(Exp)==str(self.waitVal)):
             self.waitVar=False
             self.waitNum = 0
             logs.log_info('waitVar %s ended exp=%s '%(self.waitVar,Exp))
         else:
             self.waitNum += 1
             if (self.waitNum % 1000)==0:
                 logs.log_info('waitVar %s failed %d times over %s '%(self.waitVar,self.waitNum,self.waitVal))
             if (self.waitNum>self.waitLimit)and(self.waitLimit>0):
                 logs.log_error('waitVar %s reached limit (%d)'%(self.waitVar,self.waitLimit))
                 self.waitVar=False
                 self.waitNum = 0
         return
 
     if self.waitSig:
         Act = self.peek(self.waitSig)
         if self.waitVal[0] in '0123456789':
             Expr = '%s == %s'%(Act,self.waitVal)
         else:
             Expr = '%s %s'%(Act,self.waitVal)
             
         Cond = eval(Expr,self.Vars)
         if Cond:
             self.waitSig=False
             self.waitNum = 0
             logs.log_info('waitUntil %s ended act=%s exp=%s '%(self.waitSig,Act,self.waitVal))
         else:
             self.waitNum += 1
             if (self.waitNum % 1000)==0:
                 logs.log_info('waitUntil %s failed %d times act=%s exp=%s %s'%(self.waitSig,self.waitNum,Act,self.waitVal,Act==self.waitVal))
             if (self.waitNum>self.waitLimit)and(self.waitLimit>0):
                 logs.log_error('waitUntil %s reached limit (%d)'%(self.waitSig,self.waitLimit))
                 self.waitSig=False
                 self.waitNum = 0
 
         return
 
 
 
     if self.Queue==[]: logs.finishing()
 
 
         
 
 
     Cmd = self.Queue.pop(0)
     wrds = string.split(Cmd)
     if wrds==[]: return
     if wrds[0][0] in ['/','#']: return
 
     logs.log_info('cmd %s'%Cmd)
 
     if wrds[0]=='waitNanoSec':
         Dly = eval(wrds[1],self.Vars)
         Many = int(Dly*1000/self.clockRunDuration)
         self.waiting = Many
         logs.log_info('waitNanoSec dly=%d many=%d dura=%d'%(Dly,Many,self.clockRunDuration))
         return
 
     if wrds[0]=='waitMicroSec':
         Dly = eval(wrds[1],self.Vars)
         Many = int(Dly*1000000/self.clockRunDuration)
         self.waiting = Many
         logs.log_info('waitMicroSec dly=%d many=%d dura=%d'%(Dly,Many,self.clockRunDuration))
         return
 
     if wrds[0]=='wait':
         self.waiting = int(wrds[1])
         return
     if wrds[0]=='comment':
         Txt = string.join(wrds[1:],' ')
         forceComment(Txt)
         return
 
     if wrds[0]=='finish':
         logs.finishing()
         return
 
     if wrds[0]=='include':
         Fname = wrds[1]
         if not os.path.exists(Fname):
             logs.log_info('include file "%s" was not found'%Fname)
             return
         lines =  open(Fname).readlines()
         self.Queue = lines + db.Queue
         return
 
 
     if wrds[0]=='compareNet':
         Act = self.peek(wrds[1])
         self.Vars['table']=db.Table
         Exp = eval(wrds[2],self.Vars)
 
         if Act==Exp:
             logs.log_correct('compareNet %s got 0x%x'%(wrds[1],Exp))
         else:
             logs.log_wrong('compareNet %s exp=0x%x act=0x%x'%(wrds[1],Exp,Act))
         return
 
     if wrds[0]=='force':
         where= wrds[1]
         if (len(where)>3)and(where[:3]=='tb.'):
             veri.force(wrds[1],str(eval(wrds[2],self.Vars)))
         else:
             veri.force('tb.%s'%wrds[1],str(eval(wrds[2],self.Vars)))
         return
     if wrds[0]=='hard_force':
         where= wrds[1]
         if (len(where)>3)and(where[:3]=='tb.'):
             veri.hard_force(wrds[1],str(eval(wrds[2],self.Vars)))
         else:
             veri.hard_force('tb.%s'%wrds[1],str(eval(wrds[2],self.Vars)))
         return
 
 
     if wrds[0]=='waitVar':
         self.waitVar = wrds[1]
         self.waitVal = wrds[2]
         self.waitNum = 0
         if len(wrds)>3:
             self.waitLimit = int(wrds[3])
         else:
             self.waitLimit=0
         return
 
     if wrds[0]=='waitUntil':
         self.waitSig = wrds[1]
         self.waitVal = wrds[2]
         self.waitNum = 0
         if len(wrds)>3:
             self.waitLimit = int(wrds[3])
         else:
             self.waitLimit=0
         return
 
     if wrds[0]=='waitUntilOr':
         self.waitUntilOr=[]
         self.waitNum = 0
         ind=1
         while ind<len(wrds):
             self.waitUntilOr.append((wrds[ind],wrds[ind+1]))
             ind += 2
         return
     if wrds[0]=='waitUntilAnd':
         self.waitUntilAnd=[]
         self.waitNum = 0
         ind=1
         while ind<len(wrds):
             self.waitUntilAnd.append((wrds[ind],wrds[ind+1]))
             ind += 2
         return
 
     logs.log_error('bad command "%s"'%Cmd)
     return
Esempio n. 11
0
    def run(self):
        self.runSons()
        if self.waiting > 0:
            self.waiting -= 1
            return True
        if self.waitNotBusy:
            if self.agents[self.waitNotBusy].busy():
                if self.Guardian > 0:
                    self.Guardian -= 1
                    if self.Guardian == 0:
                        Lnum = self.Sequence[self.Ptr][1]
                        logs.log_error('Guardian expired %s at line %s' %
                                       (self.waitNotBusy, Lnum))
                        self.agents[self.waitNotBusy].busy(True)
                        self.agentsFinish()
                        logs.finish('Guardian expired %s at line %s' %
                                    (self.waitNotBusy, Lnum))
                        veri.finish()
                        sys.exit()
                return True
            self.waitNotBusy = False
        if self.Ptr == len(self.Sequence): return False
        Line, lnum = self.Sequence[self.Ptr]
        self.Ptr += 1
        if '#' in Line: Line = Line[:Line.index('#')]
        if '//' in Line: Line = Line[:Line.index('//')]
        logs.log_write('sequence: %s' % Line, 'seq')
        wrds = Line.split()
        if len(wrds) == 0: return True
        if wrds[0] == 'seed':
            Val = self.eval(wrds[1])
            random.seed(Val)
            logs.log_info('SEED FROM Sequence %s' % Val)
            return True
        if wrds[0] == 'logfile':
            logs.setLogfileName(wrds[1], 0)
            return True
        if wrds[0] == 'wait':
            self.waiting = self.eval(wrds[1])
            return True
        if wrds[0] == 'exec':
            Cmd = ' '.join(wrds[1:])
            exec(Cmd)
            return True
        if wrds[0] == 'define':
            Var = wrds[1]
            if len(wrds) == 3:
                Val = self.eval(wrds[2])
                self.Translates[Var] = Val
            elif len(wrds) > 3:
                Val = list(map(self.eval, wrds[2:]))
                self.Translates[Var] = Val

            return True
        if wrds[0] == 'finish':
            logs.log_info('finishing on sequence')
            self.agentsFinish()
            logs.finish('sequence %s seed=%d ' %
                        (self.testFileName, self.Seed))
            sys.exit()
        if (wrds[0] == 'marker'):
            veri.force('%s.marker' % TB, wrds[1])
            return True
        elif wrds[0] == 'label':
            self.Labels[wrds[1]] = self.Ptr - 1
        elif wrds[0] in ['spawn', 'fork']:
            Seq = self.Subs[wrds[1]]
            Name = wrds[2]
            self.newone(Seq, Name)
            logs.log_info('spawning %s %s' % (wrds[1], Name))
        elif wrds[0] == 'return':
            if self.Stack == []:
                logs.log_error('return in sequence from empty stack')
                return
            self.Ptr = self.Stack.pop(-1)
            return
        elif wrds[0] == 'call':
            Sub = wrds[1]
            if Sub not in self.Subs:
                logs.log_error('subsequence %s is not defined, ok %s' %
                               (Sub, list(self.Subs.keys())))
                return
            Params, _ = self.Subs[Sub]
            self.Stack.append(self.Ptr)
            Actuals = wrds[2:]
            if len(Actuals) != len(Params):
                logs.log_error(
                    'subsequence %s params %d != %d  act  %s params %s' %
                    (Sub, len(Actuals), len(Params), Actuals, Params))
                return
            Zip = list(zip(Params, Actuals))
            for (PP, AA) in Zip:
                Val = self.eval(AA)
                self.Translates[PP] = Val

            self.jumpLabel(Sub)
            self.Ptr += 1
            return
        elif wrds[0] == 'goto':
            Lbl = wrds[1]
            self.jumpLabel(Lbl)
            return
        elif wrds[0] == 'if':
            BB = makeExpr(wrds[1])
            Val = self.evalExpr(BB)
            if not Val: return
            Lbl = wrds[2]
            self.jumpLabel(Lbl)
            return
        elif (wrds[0] == 'force'):
            Ind = 1
            while Ind < len(wrds):
                BB = makeExpr(wrds[Ind + 1])
                Val = self.evalExpr(BB)
                self.force(wrds[Ind], Val)
                Ind += 2
            return True
        elif (wrds[0] == 'waitUntil'):
            if self.Guardian > 0:
                self.Guardian -= 1
                if self.Guardian == 0:
                    Lnum = self.Sequence[self.Ptr][1]
                    logs.log_error('Guardian expired at line %s' % (Lnum))
                    self.agentsFinish()
                    logs.finish('Guardian expired %s  at line %s' %
                                (self.testFileName, Lnum))
                    veri.finish()
                    sys.exit()
            if (len(wrds) == 3) and (self.Guardian == 0):
                Guard = self.eval(wrds[2])
                self.Guardian = Guard

            BB = makeExpr(wrds[1])
            Val = self.evalExpr(BB)
            if not Val:
                self.Ptr -= 1
                return True
            Lnum = self.Sequence[self.Ptr][1]
            logs.log_info(
                '>>>>> finished waitUntil %s (left %d)   at line %s' %
                (str(BB), self.Guardian, Lnum))
            self.Guardian = 0
            return True

        elif (wrds[0] == 'seq'):  # commands to myself
            if wrds[1] == 'import':
                Module = wrds[2]
                if Module.endswith('.py'):
                    Module = Module[:-3]
                if '/' in Module:
                    wrds = Module.split('/')
                    Path = '/'.join(wrds[:-1])
                    Module = wrds[-1]
                    sys.path.append(Path)
                That = importlib.import_module(Module)
                self.agents[Module] = That
                That.Caller = self
                self.Monitors.append(That)
                logs.log_info('helper %s added' % (Module))
            else:
                logs.log_error('sequence class accepts only import, not %s' %
                               str(wrds))
            return

        elif wrds[0] in self.agents:
            if wrds[1] == 'waitNotBusy':
                self.waitNotBusy = wrds[0]
                if len(wrds) > 2:
                    self.Guardian = eval(wrds[2])
                else:
                    self.Guardian = DEFAULTWAITGUARD

                return True
            Wrds = list(map(str, map(self.eval, wrds[1:])))
            Wrds2 = []
            for Wrd in Wrds:
                if '=' in Wrd:
                    ww = Wrd.split('=')
                    w1 = self.eval(ww[1])
                    Wrds2.append('%s=%s' % (ww[0], w1))
                else:
                    Wrds2.append(Wrd)
            self.agents[wrds[0]].action(' '.join(Wrds2))
            return True
        elif (wrds[0] == 'check'):
            BB = makeExpr(wrds[1])
            Val = self.evalExpr(BB)
            logs.log_ensure(Val,
                            'CHECK of %s  vars=%s ' % (wrds[1], self.DEFS))
        elif (wrds[0] in ['correct', 'wrong', 'print']):
            Res = ''
            for Wrd in wrds[1:]:
                if acceptablePath(Wrd) and self.peek(Wrd):
                    Res += ' %s=%s' % (Wrd, self.peek(Wrd))
                elif Wrd in self.Translates:
                    Trx = self.Translates[Wrd]
                    if type(Trx) is int:
                        Res += ' %s' % hex(self.Translates[Wrd])
                    else:
                        Res += str(self.Translates[Wrd])
                elif (Wrd[0] == '('):
                    BB = makeExpr(Wrd)
                    print('>>>>>>>', BB)
                    logs.log_info('>>>>>>> %s' % str(BB))
                    Val = self.evalExpr(BB)
                    Res += ' ' + str(Val)
                else:
                    Res += ' ' + Wrd
            if wrds[0] == 'correct':
                logs.log_correct('   %s' % Res)
            elif wrds[0] == 'wrong':
                logs.log_wrong('   %s' % Res)
            else:
                logs.log_info('PRINT %s' % Res)
            return True
        elif (wrds[0] == 'debuglevel'):
            veri.debuglevel(wrds[1])
        else:
            logs.log_error('what!! sequence failed %s on %s agents=%s' %
                           (wrds[0], Line, list(self.agents.keys())))
            return False
Esempio n. 12
0
    def run(self):
        if self.waiting > 0:
            self.waiting -= 1
            return
        if self.Queue == []: return
        What = self.Queue.pop(0)
        if What == 'finish':
            veri.finish()
            sys.exit()

        if What[0] == 'wait':
            self.waiting = What[1]
            return
        if self.Catch:
            self.Miso += str(self.peek('spi_miso'))
            self.Catch = False
            if len(self.Miso) >= 32:
                self.callback(self.Miso)
                self.Miso = ''

        if (What[0] == 0) and (self.was == 1):
            self.Back.append(str(self.peek('spi_miso')))
            self.Forw.append(str(What[1]))


#            veri.force(TB+'.help0',str(len(self.Back)))
        if What[1] == '?':
            if (What[0] == 0) and (self.was == 1):
                self.force('spi_mosi', 0)
                self.Catch = True
        else:
            self.Catch = False
            self.force('spi_mosi', What[1])
        self.force('spi_ss', What[2])
        self.was = What[0]
        self.force('spi_clk', What[0])

        if len(self.Back) >= 32:
            FL = self.Forw[:32]
            self.Forw = self.Forw[32:]
            Part = FL[:12]
            Part.reverse()
            Addr = int(''.join(Part).replace('?', '0'), 2)
            Cmd = '?'
            if FL[12] == '0': Cmd = 'RD'
            if FL[12] == '1': Cmd = 'WR'

            LL = self.Back[:32]
            self.Back = self.Back[32:]
            AA = ''.join(LL)
            LL.reverse()
            BB = ''.join(LL)
            AX, BX = 'x', 'x'
            if '-1' not in AA:
                AX = '%08x' % (int(AA, 2))
            if '-1' not in BB:
                BX = '%08x' % (int(BB, 2))
            logs.log_info('SPI MISO %s %s cmd=%s addr=%x' %
                          (AX, BX, Cmd, Addr))
            if Cmd == 'RD':
                if Addr in self.Expects:
                    Exp, Mask, Comment = self.Expects[Addr]
                    Exp = '%04x' % Exp
                    try:
                        Act = '%04x' % (int(BX[:4], 16) & ((1 << Mask) - 1))
                    except:
                        Act = 'x'
                    if Exp == Act:
                        logs.log_correct('MISO "%s" exp=%s act=%s for add=%x' %
                                         (Comment, Exp, Act, Addr))
                    else:
                        logs.log_wrong(
                            'MISO "%s" exp=%s act=%s for add=%x   %s %s ' %
                            (Comment, Exp, Act, Addr, type(Exp), type(Act)))