def setup_simout(self): timestamp = str(int(round(time.time() * 1000))) seed = str(random.randint(0, 0xffffffff)) self.simout = pathjoin(self.ocaccel_root,\ "hardware", "sim", self.simulator,\ timestamp + "." + seed) if self.unit_sim == True: self.simout = ".".join((self.simout, self.unit_test)) mkdirs(self.simout) self.check_simout() msg.header_msg("Simulation run dir: %s" % self.simout) # In unit sim mode, simulation jobs might be submitted via LSF to run in parallel, # don't create the symbol link `latest` to avoid conflict. if self.unit_sim == False: latest = pathjoin(self.ocaccel_root,\ "hardware", "sim", self.simulator,\ "latest") if islink(latest): os.unlink(latest) os.symlink(self.simout, latest) # Generate a flag in simout for simulation status open(pathjoin(self.simout, '.RUNNING'), 'a').close()
def run_ocse(self): self.ocse_log = pathjoin(self.simout, "ocse.log") ocse_cmd = pathjoin(self.ocse_root, "ocse", "ocse") self.ocse_pid =\ run_in_background(cmd = ocse_cmd, work_dir = self.simout, log = self.ocse_log) if int(self.ocse_pid) > 0: msg.header_msg("OCSE running with pid %s" % self.ocse_pid) else: msg.fail_msg("Failed to run OCSE! Exiting ... ")
def ask_clean(self, question): a = raw_input(" ".join((question,\ choice_str))) if a.upper() == "Y": msg.header_msg("Got Yes! Proceed to clean the environment.") self.options.clean = True return self.options else: msg.header_msg("Got No! Skip cleanning the environment.") self.options.clean = False return self.options
def ask_make_image(self, question): a = raw_input(" ".join((question,\ choice_str))) if a.upper() == "Y": msg.header_msg("Got Yes! Proceed to make FPGA image.") self.options.make_image = True return self.options else: msg.header_msg("Got No! Skip making FPGA image.") self.options.make_image = False return self.options
def ask_make_model(self, question): a = raw_input(" ".join((question,\ choice_str))) if a.upper() == "Y": msg.header_msg("Got Yes! Proceed to make simulation model.") self.options.no_make_model = False return self.options else: msg.header_msg("Got No! Skip making simulation model.") self.options.no_make_model = True return self.options
def print_env(self): msg.header_msg("SNAP ROOT\t %s" % self.ocaccel_root) msg.header_msg("ACTION ROOT\t %s" % self.action_root) self.simulator.print_env() if self.unit_sim == False: self.ocse.print_env() self.testcase.print_env() else: msg.header_msg("Unit test name\t %s" % self.unit_test) msg.header_msg("Unit test seed\t %s" % self.sv_seed)
def configure(self): msg.ok_msg_blue("--------> Configuration") os.environ['SNAP_ROOT'] = self.ocaccel_root if self.options.predefined_config is not None: defconf = pathjoin(self.options.ocaccel_root, 'defconfig', self.options.predefined_config) if not isfile(defconf): msg.fail_msg("%s is not a valid defconfig file" % defconf) copyfile(defconf, pathjoin(self.options.ocaccel_root, self.snap_cfg_file)) self.setup_cfg() if self.options.predefined_config is not None: run_and_wait(cmd="make -s oldconfig", work_dir=".", log=self.log) run_and_wait(cmd="make -s snap_env", work_dir=".", log=self.log) else: rc = run_to_stdout(cmd="make snap_config", work_dir=".") if rc != 0: msg.warn_msg( "=====================================================================" ) msg.warn_msg( "==== Failed to bringup the configuration window. ====" ) msg.warn_msg( "==== Please check if libncurses5-dev is installed on your system.====" ) msg.warn_msg( "==== Also check if 'https://github.com/guillon/kconfig' ") msg.warn_msg( "==== is accessible from your system. ====" ) msg.fail_msg( "================= Configuration FAILED! =============================" ) self.setup_ocaccel_env() msg.ok_msg("SNAP Configured") msg.header_msg("You've got configuration like:") self.print_cfg()
def get_ocse_server_dat(self): ocse_server_dat_file = pathjoin(self.simout, "ocse_server.dat") ocse_server_dat_line = None progress_bar_size = 30 for i in range(self.timeout): sleep(1) progress_bar(i, self.timeout, progress_bar_size) ocse_server_dat_line = grep_file(self.ocse_log, "listening on") if ocse_server_dat_line is not None: break if ocse_server_dat_line is None: msg.fail_msg("Timeout waiting for OCSE to startup! Exiting ...") progress_bar(self.timeout - 1, self.timeout, progress_bar_size, True) ocse_server_dat = re.search("listening on (.*$)", ocse_server_dat_line).group(1) with open(ocse_server_dat_file, 'w+') as outfile: outfile.write(ocse_server_dat) msg.header_msg(" OCSE listening on socket: %s" % ocse_server_dat)
def get_host_shim(self): sim_host_shim = pathjoin(self.simout, "shim_host.dat") sim_host_shim_line = None msg.header_msg("Waiting for simulator running!") progress_bar_size = 30 for i in range(self.timeout): sleep(1) progress_bar(i, self.timeout, progress_bar_size) sim_host_shim_line = grep_file(self.sim_log, "waiting for connection") if sim_host_shim_line is not None: break if sim_host_shim_line is None: msg.fail_msg("Timeout waiting for simulator to startup! Exiting ...") progress_bar(self.timeout - 1, self.timeout, progress_bar_size, True) host_shim = re.search("waiting for connection on (.*$)", sim_host_shim_line).group(1) with open(sim_host_shim, 'w+') as outfile: outfile.write("tlx0," + host_shim) msg.header_msg(" Simulator running successfully on socket: %s" % host_shim)
def ask_configure(self, question): a = raw_input(" ".join((question,\ choice_str))) if a.upper() == "Y": if hasattr(self, "cfg"): if self.cfg.cfg_existence(): msg.header_msg("Configuration existed as below:") self.cfg.print_cfg() a = raw_input(" ".join(("Do you really want to configure again?",\ choice_str))) if a.upper() == "Y": msg.header_msg("Got Yes! Proceed to configure SNAP.") self.options.no_configure = False return self.options msg.header_msg("Got No! Skip configuring SNAP.") self.options.no_configure = True return self.options
def ask_run_sim(self, question): if self.options.simulator == "nosim": msg.warn_msg("Simulator is chosen as NOSIM, skip running simulation!") self.options.no_run_sim = True return self.options a = raw_input(" ".join((question,\ choice_str))) if a.upper() == "Y": msg.header_msg("Got Yes! Proceed to run simulation.") self.options.no_run_sim = False a = raw_input(ask_testcase_str) if a == "": a = "terminal" self.options.testcase = a msg.header_msg("The testcase to run: %s" % a) return self.options else: msg.header_msg("Got No! Skip running simulation.") self.options.no_run_sim = True return self.options
def print_env(self): msg.header_msg("Testcase cmd:\t %s" % self.cmd) msg.header_msg("Testcase args:\t %s" % self.args)
def print_cfg(self): if isfile(self.snap_env_file): msg.header_msg("\t%s\t%s" % ("ACTION_ROOT", search_file_group_1(self.snap_env_file, 'ACTION_ROOT\s*=\s*(.*)'))) if isfile(self.snap_cfg_file): msg.header_msg("\t%s\t%s" % ("FPGACARD", search_file_group_1(self.snap_cfg_file, 'FPGACARD\s*=\s*"(.*)"'))) msg.header_msg("\t%s\t%s" % ("FPGACHIP", search_file_group_1(self.snap_cfg_file, 'FPGACHIP\s*=\s*"(.*)"'))) msg.header_msg("\t%s\t%s" % ("SIMULATOR", search_file_group_1(self.snap_cfg_file, 'SIMULATOR\s*=\s*"(.*)"'))) msg.header_msg("\t%s\t%s" % ("CAPI_VER", search_file_group_1(self.snap_cfg_file, 'CAPI_VER\s*=\s*"(.*)"'))) msg.header_msg("\t%s\t%s" % ("OCSE_ROOT", search_file_group_1(self.snap_cfg_file, 'OCSE_PATH\s*=\s*"(.*)"')))
def print_env(self): msg.header_msg("OCSE_ROOT\t %s" % self.ocse_root)
def run_simulator(self): if self.simulator == "xcelium": sim_cmd = "xrun" sim_init = "-xminitialize x" sim_args = "-batch +model_data+. -64bit" if self.wave: sim_args += " -input ncaet.tcl" sim_args += " -input ncrun.tcl -r" unit_args = "".join( ("+UVM_TESTNAME=", self.unit_test, " -seed ", self.sv_seed, " +UVM_VERBOSITY=", self.uvm_ver)) if self.unit_sim == False: sim_top = "work.top" else: sim_top = "work.unit_top" self.sim_log = pathjoin(self.simout, "sim.log") if self.unit_sim == False: self.simulator_pid =\ run_in_background(cmd = " ".join((sim_cmd, sim_init, sim_args, sim_top)),\ work_dir = self.simout,\ log = self.sim_log) if int(self.simulator_pid) > 0: msg.header_msg("Simulator running on process ID %s" % self.simulator_pid) else: msg.fail_msg("Failed to run simulator! Exiting ... ") else: try: rc = run_and_poll(cmd = " ".join((sim_cmd, sim_init, sim_args, sim_top, unit_args)),\ work_dir = self.simout,\ log = self.sim_log) unit_sim_passed = self.check_unit_sim_result(self.sim_log) os.remove(pathjoin(self.simout, '.RUNNING')) if not unit_sim_passed: msg.warn_msg("============") msg.warn_msg("Test FAILED!") msg.warn_msg("============") # Generate a flag in simout for simulation status open(pathjoin(self.simout, '.FAILED'), 'a').close() msg.fail_msg( "UVM check failed, please check log in %s" % (self.sim_log)) else: msg.ok_msg("============") msg.ok_msg("Test PASSED!") msg.ok_msg("============") # Generate a flag in simout for simulation status open(pathjoin(self.simout, '.PASSED'), 'a').close() msg.ok_msg("UVM check passed, please check log in %s" % (self.sim_log)) except: if isfile(pathjoin(self.simout, '.RUNNING')): os.remove(pathjoin(self.simout, '.RUNNING')) open(pathjoin(self.simout, '.FAILED'), 'a').close() msg.fail_msg("An error occured, please check log in %s" % (self.sim_log)) elif self.simulator == "xsim": sim_cmd = "xsim" sim_init = "" sim_args = "" if self.wave: sim_args += "-t xsaet.tcl" sim_args += " -t xsrun.tcl" sim_top = "top" self.sim_log = pathjoin(self.simout, "sim.log") self.simulator_pid =\ run_in_background(cmd = " ".join((sim_cmd, sim_init, sim_args, sim_top)),\ work_dir = self.simout,\ log = self.sim_log) if int(self.simulator_pid) > 0: msg.header_msg("Simulator running on process ID %s" % self.simulator_pid) else: msg.fail_msg("Failed to run simulator! Exiting ... ") else: msg.fail_msg("%s is not supported" % self.simulator)
def print_env(self): msg.header_msg("SIMULATOR\t %s" % self.simulator) msg.header_msg("SIMOUT PATH\t %s" % self.simout)
def setup(self): msg.header_msg("Setup simulation for %s " % self.simulator) self.setup_simout() self.prepare_sim_files()