def test_generate_arbitrators_simple(self): """the project file is supposed to generate one file""" #read in the configuration file config_file_name = os.getenv("SAPLIB_BASE") + "/example_project/arb_example.json" try: self.project.read_config_file(config_file_name, debug=self.dbg) except TypeError as err: print "Error reading JSON Config File: %s" % str(err) self.assertEqual(True, False) #read in the template #if there is an error an assertion will be raised self.project.read_template(self.project.project_tags["TEMPLATE"]) self.project.filegen.set_tags(self.project.project_tags) #get the clock rate from the constraint file board_dict = saputils.get_board_config("sycamore1") cfiles = board_dict["default_constraint_files"] self.project.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(cfiles[0]) #generate the project directories and files self.project.project_tags["BASE_DIR"] = "~/sandbox/test_syc" saputils.create_dir(self.project.project_tags["BASE_DIR"]) #print "Parent dir: " + self.project.project_tags["BASE_DIR"] for key in self.project.template_tags["PROJECT_TEMPLATE"]["files"]: self.project.recursive_structure_generator( self.project.template_tags["PROJECT_TEMPLATE"]["files"], key, self.project.project_tags["BASE_DIR"]) arb_tags = saparbitrator.generate_arbitrator_tags(self.project.project_tags) self.project.project_tags["ARBITRATORS"] = arb_tags result = self.project.generate_arbitrators(debug = self.dbg) self.assertEqual(result, 1)
def test_generate_arbitrators_simple(self): """the project file is supposed to generate one file""" config_file_name = os.getenv("SAPLIB_BASE") + "/example_project/arb_example.json" result = self.project.read_config_file(config_file_name) self.assertEqual(result, True) result = self.project.read_template(self.project.project_tags["TEMPLATE"]) self.assertEqual(result, True) self.project.filegen.set_tags(self.project.project_tags) #get the clock rate from the constraint file self.project.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(self.project.project_tags["CONSTRAINTS"]["constraint_files"][0]) #generate the project directories and files self.project.project_tags["BASE_DIR"] = "~/sandbox/test_syc" saputils.create_dir(self.project.project_tags["BASE_DIR"]) #print "Parent dir: " + self.project.project_tags["BASE_DIR"] for key in self.project.template_tags["PROJECT_TEMPLATE"]["files"]: self.project.recursive_structure_generator( self.project.template_tags["PROJECT_TEMPLATE"]["files"], key, self.project.project_tags["BASE_DIR"]) arb_tags = saparbitrator.generate_arbitrator_tags(self.project.project_tags) self.project.project_tags["ARBITRATORS"] = arb_tags result = self.project.generate_arbitrators(debug = self.dbg) self.assertEqual(result, 1)
def recursive_structure_generator(self, parent_dict = {}, key="", parent_dir = "", debug=False): """recursively generate all directories and files""" if (parent_dict[key].has_key("dir") and parent_dict[key]["dir"]): #print "found dir" saputils.create_dir(parent_dir + "/" + key) if (parent_dict[key].has_key("files")): for sub_key in parent_dict[key]["files"]: #print "sub item :" + sub_key self.recursive_structure_generator( parent_dict = parent_dict[key]["files"], key = sub_key, parent_dir = parent_dir + "/" + key) else: #print "generate the file: " + key + " at: " + parent_dir self.filegen.process_file(key, parent_dict[key], parent_dir) return True
def test_generate_arbitrators_difficult(self): """the project calls for three arbitrators, but two are identical""" #read in the configuration file config_file_name = os.getenv( "SAPLIB_BASE") + "/example_project/arb_difficult_example.json" result = False try: self.project.read_config_file(config_file_name, debug=self.dbg) except TypeError as err: print "Error reading JSON Config File: %s" % str(err) self.assertEqual(True, False) #this will throw an exception if something failed self.project.read_template(self.project.project_tags["TEMPLATE"]) board_dict = saputils.get_board_config( self.project.project_tags["board"]) cfiles = board_dict["default_constraint_files"] self.project.filegen.set_tags(self.project.project_tags) #get the clock rate from the constraint file self.project.project_tags["CLOCK_RATE"] = saputils.read_clock_rate( cfiles[0]) #generate the project directories and files self.project.project_tags["BASE_DIR"] = "~/sandbox/test_syc" saputils.create_dir(self.project.project_tags["BASE_DIR"]) #print "Parent dir: " + self.project.project_tags["BASE_DIR"] for key in self.project.template_tags["PROJECT_TEMPLATE"]["files"]: self.project.recursive_structure_generator( self.project.template_tags["PROJECT_TEMPLATE"]["files"], key, self.project.project_tags["BASE_DIR"]) arb_tags = saparbitrator.generate_arbitrator_tags( self.project.project_tags) self.project.project_tags["ARBITRATORS"] = arb_tags result = self.project.generate_arbitrators(debug=self.dbg) self.assertEqual(result, 2)
def recursive_structure_generator(self, parent_dict = {}, key="", parent_dir = "", debug=False): """Recursively generate all directories and files Args: parent_dict: dictionary of the paret directory key: this is the name of the item to add parent_dir: name of the parent directory Return: Nothing Raises: IOError TypeError """ if (parent_dict[key].has_key("dir") and parent_dict[key]["dir"]): #print "found dir" # if (key == "arbitrators" and ("ARBITRATORS" in self.project_tags.keys() ) and (len(self.project_tags["ARBITRATORS"].keys()) > 0)): # return True saputils.create_dir(parent_dir + "/" + key) if (parent_dict[key].has_key("files")): for sub_key in parent_dict[key]["files"]: #print "sub item :" + sub_key self.recursive_structure_generator( parent_dict = parent_dict[key]["files"], key = sub_key, parent_dir = parent_dir + "/" + key) else: #print "generate the file: " + key + " at: " + parent_dir try: self.filegen.process_file(key, parent_dict[key], parent_dir) except ModuleFactoryError as err: print "ModuleFactoryError: %s" % str(err)
def recursive_structure_generator(self, parent_dict={}, key="", parent_dir="", debug=False): """Recursively generate all directories and files Args: parent_dict: dictionary of the paret directory key: this is the name of the item to add parent_dir: name of the parent directory Return: Nothing Raises: IOError TypeError """ if (parent_dict[key].has_key("dir") and parent_dict[key]["dir"]): #print "found dir" # if (key == "arbitrators" and ("ARBITRATORS" in self.project_tags.keys() ) and (len(self.project_tags["ARBITRATORS"].keys()) > 0)): # return True saputils.create_dir(parent_dir + "/" + key) if (parent_dict[key].has_key("files")): for sub_key in parent_dict[key]["files"]: #print "sub item :" + sub_key self.recursive_structure_generator( parent_dict=parent_dict[key]["files"], key=sub_key, parent_dir=parent_dir + "/" + key) else: #print "generate the file: " + key + " at: " + parent_dir try: self.filegen.process_file(key, parent_dict[key], parent_dir) except ModuleFactoryError as err: print "ModuleFactoryError: %s" % str(err)
def test_generate_arbitrators_simple(self): """the project file is supposed to generate one file""" #read in the configuration file config_file_name = os.getenv( "SAPLIB_BASE") + "/example_project/arb_example.json" try: self.project.read_config_file(config_file_name, debug=self.dbg) except TypeError as err: print "Error reading JSON Config File: %s" % str(err) self.assertEqual(True, False) #read in the template #if there is an error an assertion will be raised self.project.read_template(self.project.project_tags["TEMPLATE"]) self.project.filegen.set_tags(self.project.project_tags) #get the clock rate from the constraint file board_dict = saputils.get_board_config("sycamore1") cfiles = board_dict["default_constraint_files"] self.project.project_tags["CLOCK_RATE"] = saputils.read_clock_rate( cfiles[0]) #generate the project directories and files self.project.project_tags["BASE_DIR"] = "~/sandbox/test_syc" saputils.create_dir(self.project.project_tags["BASE_DIR"]) #print "Parent dir: " + self.project.project_tags["BASE_DIR"] for key in self.project.template_tags["PROJECT_TEMPLATE"]["files"]: self.project.recursive_structure_generator( self.project.template_tags["PROJECT_TEMPLATE"]["files"], key, self.project.project_tags["BASE_DIR"]) arb_tags = saparbitrator.generate_arbitrator_tags( self.project.project_tags) self.project.project_tags["ARBITRATORS"] = arb_tags result = self.project.generate_arbitrators(debug=self.dbg) self.assertEqual(result, 1)
def test_generate_arbitrators_difficult(self): """the project calls for three arbitrators, but two are identical""" #read in the configuration file config_file_name = os.getenv("SAPLIB_BASE") + "/example_project/arb_difficult_example.json" result = False try: self.project.read_config_file(config_file_name, debug=self.dbg) except TypeError as err: print "Error reading JSON Config File: %s" % str(err) self.assertEqual(True, False) #this will throw an exception if something failed self.project.read_template(self.project.project_tags["TEMPLATE"]) board_dict = saputils.get_board_config(self.project.project_tags["board"]) cfiles = board_dict["default_constraint_files"] self.project.filegen.set_tags(self.project.project_tags) #get the clock rate from the constraint file self.project.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(cfiles[0]) #generate the project directories and files self.project.project_tags["BASE_DIR"] = "~/sandbox/test_syc" saputils.create_dir(self.project.project_tags["BASE_DIR"]) #print "Parent dir: " + self.project.project_tags["BASE_DIR"] for key in self.project.template_tags["PROJECT_TEMPLATE"]["files"]: self.project.recursive_structure_generator( self.project.template_tags["PROJECT_TEMPLATE"]["files"], key, self.project.project_tags["BASE_DIR"]) arb_tags = saparbitrator.generate_arbitrator_tags(self.project.project_tags) self.project.project_tags["ARBITRATORS"] = arb_tags result = self.project.generate_arbitrators(debug = self.dbg) self.assertEqual(result, 2)
def test_create_dir(self): """create a directory""" result = saputils.create_dir("~/sandbox/projects") self.assertEqual(result, True)
def test_create_dir(self): """create a directory""" import saputils result = saputils.create_dir("~/sandbox/projects") self.assertEqual(result, True)
def generate_project(self, config_file_name, debug=False): """Generate the folders and files for the project Using the project tags and template tags this function generates all the directories and files of the project. It will go through the template structure and determine what files need to be added and call either a generation script (in the case of \"top.v\") or simply copy the file over (in the case of a peripheral or memory module. Args: config_file_name: name of the JSON configuration file Return: True: Success False: Failure Raises: TypeError IOError SapError """ #reading the project config data into the the project tags #XXX: This should be changed to an exception begin raised and not a True False statement self.read_config_file(config_file_name) board_dict = saputils.get_board_config(self.project_tags["board"]) cfiles = [] pt = self.project_tags if "constraint_files" in pt.keys(): cfiles = pt["constraint_files"] #if the user didn't specify any constraint files #load the default if len(cfiles) == 0: cfiles = board_dict["default_constraint_files"] #extrapolate the bus template #XXX: Need to check all the constraint files self.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(cfiles[0]) self.read_template(self.project_tags["TEMPLATE"]) #set all the tags within the filegen structure if debug: print "set all tags wihin filegen structure" self.filegen.set_tags(self.project_tags) #generate the project directories and files saputils.create_dir(self.project_tags["BASE_DIR"]) if debug: print "generated the first dir" #generate the arbitrator tags, this is important because the top #needs the arbitrator tags arb_tags = saparbitrator.generate_arbitrator_tags( self.project_tags, False) self.project_tags["ARBITRATORS"] = arb_tags #print "Parent dir: " + self.project_tags["BASE_DIR"] for key in self.template_tags["PROJECT_TEMPLATE"]["files"]: self.recursive_structure_generator( self.template_tags["PROJECT_TEMPLATE"]["files"], key, self.project_tags["BASE_DIR"]) if debug: print "generating project directories finished" if debug: print "generate the arbitrators" self.generate_arbitrators() #Generate all the slaves for slave in self.project_tags["SLAVES"]: fdict = {"location": ""} file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave" fn = self.project_tags["SLAVES"][slave]["filename"] try: self.filegen.process_file(filename=fn, file_dict=fdict, directory=file_dest, debug=debug) except ModuleFactoryError as err: print "ModuleFactoryError while generating a slave: %s" % str( err) #each slave if ("MEMORY" in self.project_tags): for mem in self.project_tags["MEMORY"]: fdict = {"location": ""} file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave" fn = self.project_tags["MEMORY"][mem]["filename"] try: self.filegen.process_file(filename=fn, file_dict=fdict, directory=file_dest) except ModuleFactoryError as err: print "ModuleFactoryError while generating a memory slave: %s" % str( err) #Copy the user specified constraint files to the constraints directory for constraint_fname in cfiles: sap_abs_base = os.getenv("SAPLIB_BASE") abs_proj_base = saputils.resolve_linux_path( self.project_tags["BASE_DIR"]) constraint_path = self.get_constraint_path(constraint_fname) if (len(constraint_path) == 0): print "Couldn't find constraint: " + constraint_fname + ", searched in current directory and " + sap_abs_base + " /hdl/" + self.project_tags[ "board"] continue shutil.copy(constraint_path, abs_proj_base + "/constraints/" + constraint_fname) #Generate the IO handler interface_filename = self.project_tags["INTERFACE"]["filename"] fdict = {"location": ""} file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/interface" result = self.filegen.process_file(filename=interface_filename, file_dict=fdict, directory=file_dest) if debug: print "copy over the dependencies..." print "verilog files: " for f in self.filegen.verilog_file_list: print f print "dependent files: " for d in self.filegen.verilog_dependency_list: fdict = {"location": ""} file_dest = self.project_tags["BASE_DIR"] + "/dependencies" result = self.filegen.process_file(filename=d, file_dict=fdict, directory=file_dest) if debug: print d return True
def generate_project(self, config_file_name, debug=False): """Recursively go through template structure and generate the folders and files""" #reading the project config data into the the project tags result = self.read_config_file(config_file_name) if (not result): if (debug): print "failed to read in project config file" return False #extrapolate the bus template result = self.read_template(self.project_tags["TEMPLATE"]) if (not result): if (debug): print "failed to read in template file" return False #set all the tags within the filegen structure if debug: print "set all tags wihin filegen structure" self.filegen.set_tags(self.project_tags) #generate the project directories and files saputils.create_dir(self.project_tags["BASE_DIR"]) if debug: print "generated the first dir" #print "Parent dir: " + self.project_tags["BASE_DIR"] for key in self.template_tags["PROJECT_TEMPLATE"]["files"]: self.recursive_structure_generator( self.template_tags["PROJECT_TEMPLATE"]["files"], key, self.project_tags["BASE_DIR"]) if debug: print "generating project directories finished" #Generate all the slaves for slave in self.project_tags["SLAVES"]: fdict = {"location":""} file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave" result = self.filegen.process_file(filename = slave, file_dict = fdict, directory=file_dest) #each slave #Copy the user specified constraint files to the constraints directory for constraint_fname in self.project_tags["CONSTRAINTS"]["constraint_files"]: sap_abs_base = os.getenv("SAPLIB_BASE") abs_proj_base = saputils.resolve_linux_path(self.project_tags["BASE_DIR"]) constraint_path = self.get_constraint_path(constraint_fname) if (len(constraint_path) == 0): print "Couldn't find constraint: " + constraint_fname + ", searched in current directory and " + sap_abs_base + " /hdl/" + self.project_tags["CONSTRAINTS"]["board"] continue shutil.copy (constraint_path, abs_proj_base + "/constraints/" + constraint_fname) #Generate the IO handler interface_filename = self.project_tags["INTERFACE"] fdict = {"location":""} file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/interface" result = self.filegen.process_file(filename = interface_filename, file_dict=fdict , directory=file_dest) if debug: print "copy over the dependencies..." print "verilog files: " for f in self.filegen.verilog_file_list: print f print "dependent files: " for d in self.filegen.verilog_dependency_list: fdict = {"location":""} file_dest = self.project_tags["BASE_DIR"] + "/dependencies" result = self.filegen.process_file(filename = d, file_dict = fdict, directory = file_dest) print d return True
def generate_project(self, config_file_name, debug=False): """Generate the folders and files for the project Using the project tags and template tags this function generates all the directories and files of the project. It will go through the template structure and determine what files need to be added and call either a generation script (in the case of \"top.v\") or simply copy the file over (in the case of a peripheral or memory module. Args: config_file_name: name of the JSON configuration file Return: True: Success False: Failure Raises: TypeError IOError SapError """ #reading the project config data into the the project tags #XXX: This should be changed to an exception begin raised and not a True False statement self.read_config_file(config_file_name) board_dict = saputils.get_board_config(self.project_tags["board"]) cfiles = [] pt = self.project_tags if "constraint_files" in pt.keys(): cfiles = pt["constraint_files"] #if the user didn't specify any constraint files #load the default if len(cfiles) == 0: cfiles = board_dict["default_constraint_files"] #extrapolate the bus template #XXX: Need to check all the constraint files self.project_tags["CLOCK_RATE"] = saputils.read_clock_rate(cfiles[0]) self.read_template(self.project_tags["TEMPLATE"]) #set all the tags within the filegen structure if debug: print "set all tags wihin filegen structure" self.filegen.set_tags(self.project_tags) #generate the project directories and files saputils.create_dir(self.project_tags["BASE_DIR"]) if debug: print "generated the first dir" #generate the arbitrator tags, this is important because the top #needs the arbitrator tags arb_tags = saparbitrator.generate_arbitrator_tags(self.project_tags, False) self.project_tags["ARBITRATORS"] = arb_tags #print "Parent dir: " + self.project_tags["BASE_DIR"] for key in self.template_tags["PROJECT_TEMPLATE"]["files"]: self.recursive_structure_generator( self.template_tags["PROJECT_TEMPLATE"]["files"], key, self.project_tags["BASE_DIR"]) if debug: print "generating project directories finished" if debug: print "generate the arbitrators" self.generate_arbitrators() #Generate all the slaves for slave in self.project_tags["SLAVES"]: fdict = {"location":""} file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave" fn = self.project_tags["SLAVES"][slave]["filename"] try: self.filegen.process_file(filename = fn, file_dict = fdict, directory=file_dest, debug=debug) except ModuleFactoryError as err: print "ModuleFactoryError while generating a slave: %s" % str(err) #each slave if ("MEMORY" in self.project_tags): for mem in self.project_tags["MEMORY"]: fdict = {"location":""} file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/slave" fn = self.project_tags["MEMORY"][mem]["filename"] try: self.filegen.process_file(filename = fn, file_dict = fdict, directory = file_dest) except ModuleFactoryError as err: print "ModuleFactoryError while generating a memory slave: %s" % str(err) #Copy the user specified constraint files to the constraints directory for constraint_fname in cfiles: sap_abs_base = os.getenv("SAPLIB_BASE") abs_proj_base = saputils.resolve_linux_path(self.project_tags["BASE_DIR"]) constraint_path = self.get_constraint_path(constraint_fname) if (len(constraint_path) == 0): print "Couldn't find constraint: " + constraint_fname + ", searched in current directory and " + sap_abs_base + " /hdl/" + self.project_tags["board"] continue shutil.copy (constraint_path, abs_proj_base + "/constraints/" + constraint_fname) #Generate the IO handler interface_filename = self.project_tags["INTERFACE"]["filename"] fdict = {"location":""} file_dest = self.project_tags["BASE_DIR"] + "/rtl/bus/interface" result = self.filegen.process_file(filename = interface_filename, file_dict=fdict , directory=file_dest) if debug: print "copy over the dependencies..." print "verilog files: " for f in self.filegen.verilog_file_list: print f print "dependent files: " for d in self.filegen.verilog_dependency_list: fdict = {"location":""} file_dest = self.project_tags["BASE_DIR"] + "/dependencies" result = self.filegen.process_file(filename = d, file_dict = fdict, directory = file_dest) if debug: print d return True