def test_userkeywords_1(self): filename = "userkeywords_1.stil" # Standard parsing: stil = pystil.STIL(file=os.path.join(PATH, filename), debug=DEBUG) stil.parse() # Checks: failed = False msg = [] # TODO: condense all tplp entries intoa single list. # tplp[stil.1] -> {tpl : {start,end,etc.} } # tplp[stil.2] -> {tpl : {start,end,etc.} } # tplp[stil.3] -> {tpl : {start,end,etc.} } # # [tpl1s, tpl2s, tpl ] if 'diepad' not in stil._tplp[filename]: failed = True msg.append("TPLP is missing 'diepad' user keyword.") if 'UserKeywords' not in stil._tplp[filename]: failed = True msg.append("TPLP is missing 'UserKeywords' keyword.") if 'UserFunctions' not in stil._tplp[filename]: failed = True msg.append("TPLP is missing 'UserFunctions' keyword.") if 'tchn' not in stil._tplp[filename]: failed = True msg.append("TPLP is missing 'tchn' user keyword.") if 'abs_min' not in stil._tplp[filename]: failed = True msg.append("TPLP is missing 'abs_min' user keyword.") self.assertTrue(failed == False, "\n".join(msg))
def test_signals_1(self): filename = "signals_1.stil" # Standard parsing. stil = pystil.STIL(file=os.path.join(PATH, filename), debug=DEBUG) stil.parse() # Check results failed = False; msg = [] # Check number of signals, # - Technically, 16 signal defintions. IO[0..7] is more 8 channels. # This acknowledges that we need to be able to reference multiple # variations of shorthand notation # TODO: Does this shorthand notation allow for subset references? # ex.) "a&b"[0..7], is the following references valid? # - "a&b"[0..2] -> "a&b"[0] "a&b"[1] "a&b"[2] # - "a&b"[6..4] -> "a&b"[6] "a&b"[5] "a&b"[4] signals = stil.get_signals() if signals.get_size() != 16: failed = True msg.append("The number of channels should be 16.") if len(signals.get_names()) != 9: failed = True msg.append("The number of names returned should be 9.") if len(signals.get_names(regex="D\d")) != 2: failed = True msg.append("The number of names returned from regex 'D\d' should be 2.") if len(signals.get_names(types=['Out'])) != 2: failed = True msg.append("The number of names returned from types should be 2.") if len(signals.get_names(regex="S0", types=['In'])) != 1: failed = True msg.append("The number of names returned from rege='S0' and types=['In'] should be 1.") self.assertTrue(failed == False, "\n".join(msg))
def test_header_1(self): _file = os.path.join(PATH, "header_1.stil") so = stil.STIL(sfp=_file, debug=DEBUG) so.parse() self.assertTrue(so.header.get_title() == "Sample STIL Title") self.assertTrue(so.header.get_date() == "Tue Apr 28 12:23:48 EST 1996") self.assertTrue(so.header.get_source() == "VHDL simulation on April 22, 1996") for i, ann in enumerate(so.header.get_history()): if i == 0: self.assertTrue(ann == "rev1 - 4/21/96 - made some change") if i == 1: self.assertTrue(ann == "rev2- 4/22/96 - made it work")
def test_patternburst_1(self): filename = "patternburst_1.stil" # Standard parsing. stil = pystil.STIL(file=os.path.join(PATH, filename), debug=DEBUG) stil.parse() # Check results failed = False; msg = [] if len(stil.PatternBursts()) != 1: failed = True msg.append("Expecting one block. Recieved %d"%(len(stil.PatternBursts()))) actPatternBurstNames = stil.PatternBursts().names() expPatternBurstNames = ['"myPatternBurst"'] if actPatternBurstNames != expPatternBurstNames: failed = True msg.append("PatternBursts names are not correct.") pb = stil.PatternBursts().get(expPatternBurstNames[0]) patternsRef = pb.patterns() expPatternList = ['"Pattern1"','"Pattern2"','"Pattern3"', '"Pattern4"','"Pattern5"','write_vecs','read_vecs'] if len(patternsRef) != len(expPatternList): failed = True msg.append("The number of refrenced patterns (%s) "\ "is not correct. Should be %d."%(len(patternsRef), len(expPatternList))) else: for pat in patternsRef: expPatternList.remove(pat) if len(expPatternList) != 0: failed = True msg.append("The patterns referenced didnt contain the following: %s"%(expPatternList)) patLists = pb.get_PatLists() # NOTE, there can be many patLists..... for name, details in patLists[0].patterns.items(): print(name, details ) patsets = pb.get_PatSets() # NOTE, there can be many patLists..... for name, details in patsets[0].patterns.items(): print(name, details) parallelPatLists = pb.get_ParallelPatLists() # NOTE, there can be many patLists..... for name, details in parallelPatLists[0].patterns.items(): print(name, details) #print(stil.PatternBursts().patterns()) self.assertTrue(failed == False, "\n".join(msg))
def test_timing_1(self): filename = "timing_1.stil" # Standard parsing. stil = pystil.STIL(file=os.path.join(PATH, filename), debug=DEBUG) stil.parse() # Check results failed = False msg = [] # stil.timing().get_waveformTables() #print(stil.Timings()) #print(stil.timing().get_timing(pystil.GLOBAL)) #print(stil.Timings().get(pystil.GLOBAL)) expectations = { "WavTbl1": { 'period': "'per'", 'numOfSignals': 9, }, "WavTbl2": { 'period': "'5.0ns'", 'numOfSignals': 9, }, } waveformtables = stil.Timings().WaveformTables() i = 0 end = len(waveformtables) - 1 while i <= end: wvtbl = waveformtables[i] # WaveformTable names: if wvtbl.name not in expectations: failed = True msg.append("WaveformTable %s was not found" % (wvtbl.name)) i += 1 continue expPeriod = expectations[wvtbl.name]['period'] # Periods: if expPeriod != wvtbl.period: failed = True msg.append("WaveformTable %s periods mismatched: Actual: %s" % (wvtbl.name, wvtbl.period)) # Number of signal definitions: if len(wvtbl.signals()) != expectations[ wvtbl.name]['numOfSignals']: failed = True msg.append( "WaveformTable %s number of signals mismatched %s: Actual: %s" % (wvtbl.name, expectations[wvtbl.name]['numOfSignals'], len(wvtbl.signals()))) i += 1 self.assertTrue(failed == False, "\n".join(msg))
def _handle_cmd_args(): parser = argparse.ArgumentParser() parser.add_argument("--debug", help="Increase console logging", action="store_true") parser.add_argument("--all", help="Tokenize entire STIL", action="store_true") parser.add_argument("stil", help="STIL file path",) args = parser.parse_args() if not os.path.isfile(args.stil): raise ValueError("Invalid STIL file.") return args if __name__ == "__main__": args = _handle_cmd_args() # Standard Parsing stil = pystil.STIL(file = args.stil, debug = args.debug) stil.parse() # Query parts signals = stil.get_signals() # NOTE: If this returns a single object, then get_signalGroups should return a list fo objects print("Signal: ") print("-------") print(signals.string()) # NOTE: Could override the __str__ function print("Signals.get_names()") print(" ", signals.get_names()) print("Signal.get_names(types=[\"Out\"])") print(" ", signals.get_names(types=["Out"])) print("Signals.get_names(regex=\"D\d\", types[\"In\"])") print(" ", signals.get_names(regex = "D\d", types=["In"]))
action="store_true") parser.add_argument( "stil", help="STIL file path", ) args = parser.parse_args() if not os.path.isfile(args.stil): raise ValueError("Invalid STIL file.") return args if __name__ == "__main__": args = _handle_cmd_args() # Various constructors: stil = pystil.STIL(readpath=args.stil, debug=args.debug) # Reading: # -------- # Can also provide readpath here, # iff not already set. stil.read() stil.print_tplp() # Writing: #stil.write() # This will write STIL file(s). # Includes: # --------: hasIncludes = False
def test_spec_1(self): filename = "spec_1.stil" # Standard parsing. stil = pystil.STIL(file=os.path.join(PATH, filename), debug=DEBUG) stil.parse() # Check results failed = False msg = [] #print(stil._tplp) #print(stil.specs()) # NOTE: The question is how will user typically reference the # category blocks. if len(stil.Specs()) != 1: failed = True msg.append("Expecting one block. Recieved %d" % (len(stil.Specs()))) spec = stil.Specs().get(name="tmode_spec") categories = spec.get_categories() if len(categories) != 2: failed = True msg.append("Expecting 2 categories. Recieved %d" % (len(categories))) tmodeCat = spec.category("tmode") if (len(tmodeCat) != 7): failed = True msg.append("Expecting 7 categories. Recieved %d" % (len(tmodeCat))) if tmodeCat.vars["dutyb"] != {'value': "'0.00ns'"}: failed = True msg.append("Dictionary for tmode's 'dutyb' is not proper.") tmodeSlow = spec.category("tmode_slow") if (len(tmodeSlow) != 7): failed = True msg.append("Expecting 7 categories. Recieved %d" % (len(tmodeCat))) if tmodeSlow.vars["shmsp5"] != { 'Min': "'0.00ns'", 'Typ': "'23.00ns'", 'Max': "'40.00ns'" }: failed = True msg.append("Dictionary for tmode_slow's 'shmsp5' is not proper.") if len(stil.selectors()) != 2: failed = True msg.append("Expecting 2 Selector. Recieved %s" % (len(stil.selectors()))) if stil.selectors().selector("tmode_typ").vars["sp5"] != 'Typ': failed = True msg.append("Expecting 'tmode_typ' 'sp5' to be 'Typ'.") if stil.selectors().selector("tmode_mix").vars["shmsp5"] != 'Max': failed = True msg.append("Expecting 'tmode_mix' 'shmsp5' to be 'Max'.") self.assertTrue(failed == False, "\n".join(msg))
def test_signals_2(self): filename = "signals_2.stil" # Standard parsing. stil = pystil.STIL(file=os.path.join(PATH, filename), debug=DEBUG) stil.parse() # Check results failed = False; msg = [] # Check number of signals defined: signals = stil.signals() numOfSignals = 26 if signals.get_size() != numOfSignals: failed = True msg.append("The number of channels should be %s; %s found."%(numOfSignals, signals.get_size())) signalGroups = stil.get_signalgroups() #signalGroups = stil.signalGroups() # This will return a list. # however we want an object interface. # NOTE: Never have multiple return types! # This makes maintainance tooo complicated. #signalGroups = stil.signalGroups() # TODO: Return SignalGroupBlocks #signalGroups.get_groups() # TODO: Return list of # NOTE: A list is returned here! Signals is different than nearily # all other block returns because stil standard only accepts one. # That is stil ignores all Signal blocks after the first one. domains = stil.signalGroups().get_domains() numOfDomains = 2 if len(domains) != numOfDomains: failed = True msg.append("The number of domains should be %s; %s found."%(numOfDomains, stil.signalGroups().get_domains())) blockX = stil.signalGroups().get_block(domain = " ") groups = blockX.get_groups(signal="B[1]") if len(groups) != 2: failed = True msg.append("The number of groups should be %s when search for B[1]; %s found."%(2, len(groups))) if groups[0] != 'bbus_pins': failed = True msg.append("The groups[0] = %s, should be %s found."%(groups[0], 'bbus_pins')) if groups[1] != 'bbus_odd': failed = True msg.append("The groups[1] = %s, should be %s found."%(groups[1], 'bbus_odd')) groups = blockX.get_groups() if len(groups) != 5: failed = True msg.append("The number of groups should be %s. %s found."%(5, len(groups))) groups = blockX.get_groups(signal="scan1") if len(groups) != 1: failed = True msg.append("The number of groups should be %s when search for 'scan1'; %s found."%(1, len(groups))) groups = stil.signalGroups().get_block(domain="quality").get_groups() if len(groups) != 3: failed = True msg.append("The number of groups should be %s. %s found."%(3, len(groups))) self.assertTrue(failed == False, "\n".join(msg))