diff --git a/src/add_dut.py b/src/add_dut.py index 2271a55..ab521d0 100644 --- a/src/add_dut.py +++ b/src/add_dut.py @@ -1,98 +1,97 @@ #!/bin/python import os -import re +# import re import logging -from typing import List import config from data_type import CoreInfo -class Cores(object): - +class DUT(object): def __init__(self): - self.submit_list = [] - self.core_list = [] + self.new_dut_list = [] + self.dut_list = [] def clear(self): - self.submit_list.clear() - self.core_list.clear() + self.new_dut_list.clear() + self.dut_list.clear() # 1. pattern: ysyx_([0-9]{8}) # 2. pattern: ysyx_([0-9]{6}) # 3. in id list - def check_valid(self, val: str) -> str: - if re.match('ysyx_[0-9]{8}', val) is not None: - return val - elif re.match('ysyx_[0-9]{6}', val) is not None: - return val - else: - return '' - - def fill_data(self, term: List[str]): - self.submit_list.append(CoreInfo(term[0], term[1])) + def check_valid(self, val: str) -> bool: + return len(val) > 0 + # if re.match('ysyx_[0-9]{8}', val) is not None: + # return val + # elif re.match('ysyx_[0-9]{6}', val) is not None: + # return val + # else: + # return '' + + def fill_data(self, url: str, repo: str): + self.new_dut_list.append(CoreInfo(url, repo)) def handle_err(self, val: str): # NOTE: need to write to the submit info logging.info(msg=f'ID: error format, the err val: {val}') def add(self): - with open(config.SUBMIT_LIST_PATH, 'r+', encoding='utf-8') as fp: - for v in fp.readlines(): - tmp = v.split() - logging.debug(msg=tmp[1]) - if self.check_valid(tmp[1]) != '': - self.fill_data(tmp) + with open(config.SUBMIT_LIST_PATH, 'r', encoding='utf-8') as fp: + for url in fp: + repo_name = url.split('/')[-1] + logging.debug(msg=repo_name) + if self.check_valid(repo_name): + self.fill_data(url, repo_name) else: - self.handle_err(tmp) + self.handle_err(repo_name) # update the core list def update(self): os.chdir(config.SUBMIT_DIR) - os.system('git checkout ' + config.CUR_BRAN) + os.system(f'git checkout {config.CUR_BRAN}') logging.info(msg=f'git checkout {config.CUR_BRAN}') - with open(config.CORE_LIST_PATH, 'r+', encoding='utf-8') as fp: - for v in fp.readlines(): - tmp = v.split() + with open(config.DUT_LIST_PATH, 'r', encoding='utf-8') as fp: + for v in fp: + repo_name = v.split()[0] # filter err and spaces - if self.check_valid(tmp[0]) != '': - self.core_list.append(CoreInfo('', tmp[0])) - logging.debug(msg=f'id: {tmp[0]}') + if self.check_valid(repo_name): + self.dut_list.append(CoreInfo('', repo_name)) + logging.debug(msg=f'repo name: {repo_name}') - self.core_list.sort(key=lambda v: v.sid) - self.submit_list.sort(key=lambda v: v.sid) + self.dut_list.sort(key=lambda v: v.repo) + self.new_dut_list.sort(key=lambda v: v.repo) - new_id = [] - for va in self.submit_list: + new_dut = [] + for va in self.new_dut_list: is_find = False - for vb in self.core_list: - if va.sid == vb.sid: + for vb in self.dut_list: + if va.repo == vb.repo: is_find = True break if is_find is False: - os.system(f'git clone {va.url} submit/{va.sid}') - logging.debug(msg=f'git clone {va.url} submit/{va.sid}') - new_id.append(CoreInfo('', va.sid, 'F')) + os.system(f'git clone {va.url} submit/{va.repo}') + logging.debug(msg=f'git clone {va.url} submit/{va.repo}') + new_dut.append(CoreInfo('', va.repo, 'F')) - logging.debug(msg=f'new core num: {len(new_id)}') - self.core_list += new_id - self.core_list.sort(key=lambda v: v.sid) - logging.debug(msg=self.core_list) - with open(config.CORE_LIST_PATH, 'w+', encoding='utf-8') as fp: - for v in self.core_list: - fp.write(v.sid + ' ' + v.flag + '\n') + logging.debug(msg=f'new dut num: {len(new_dut)}') + self.dut_list += new_dut + self.dut_list.sort(key=lambda v: v.repo) + logging.debug(msg=self.dut_list) + with open(config.DUT_LIST_PATH, 'w+', encoding='utf-8') as fp: + for v in self.dut_list: + fp.write(v.repo + ' ' + v.flag + '\n') -cores = Cores() +dut = DUT() def main(): logging.info(msg='[add soc]') os.system(f'mkdir -p {config.DATA_DIR}') - cores.clear() - cores.add() - cores.update() + dut.clear() + dut.add() + dut.update() if __name__ == '__main__': diff --git a/src/config.py b/src/config.py index c26e9b6..6f001cc 100644 --- a/src/config.py +++ b/src/config.py @@ -11,9 +11,9 @@ # CUR_BRAN = '202302' CUR_BRAN = 'main' # NOTE: just for test HOME_DIR = os.getcwd() + '/' -DATA_DIR = f'{HOME_DIR}../data/CUR_BRAN' +DATA_DIR = f'{HOME_DIR}../data/{CUR_BRAN}' SUBMIT_LIST_PATH = f'{DATA_DIR}/submit_list' -CORE_LIST_PATH = f'{DATA_DIR}/core_list' +DUT_LIST_PATH = f'{DATA_DIR}/dut_list' QUEUE_LIST_PATH = f'{DATA_DIR}/queue_list' RUN_LOG_PATH = f'{DATA_DIR}/run.log' # NOTE: need to modify the SUBMIT_DIR path for the CICD repo diff --git a/src/data_type.py b/src/data_type.py index 7287be2..f5df8cd 100644 --- a/src/data_type.py +++ b/src/data_type.py @@ -4,9 +4,9 @@ class CoreInfo(object): - def __init__(self, url: str, sid: str, flag='E'): + def __init__(self, url: str, repo: str, flag='E'): self.url = url - self.sid = sid + self.repo = repo self.flag = flag def __str__(self) -> str: diff --git a/src/repo_update.py b/src/repo_update.py index bb2176e..3eeb098 100644 --- a/src/repo_update.py +++ b/src/repo_update.py @@ -67,7 +67,7 @@ def check_remote_update(self, submod_name: str) -> (Tuple[bool, str]): return (local_rev != remote_rev, std_date) def pull_repo(self, submod_name: str): - os.chdir(config.SUB_DIR + '/' + submod_name) + os.chdir(f'{config.SUB_DIR}/{submod_name}') self.sw_branch(config.BRANCH_NAME_DEV) cmd = 'git pull --progress -v --no-rebase "origin" ' @@ -81,17 +81,17 @@ def parse_cfg(self): pass # check if remote repo has been updated - def check_repo(self, core_info: CoreInfo): - ret = self.check_remote_update(core_info.sid) + def check_repo(self, dut_info: CoreInfo): + ret = self.check_remote_update(dut_info.repo) # restart is also right - if core_info.flag == 'F': - logging.info(msg=f'[{core_info.sid}] first! start pull...') - self.pull_repo(core_info.sid) - report.create_dir(core_info.sid) - parse_res = config_parser.main(core_info.sid) + if dut_info.flag == 'F': + logging.info(msg=f'[{dut_info.repo}] first! start pull...') + self.pull_repo(dut_info.repo) + report.create_dir(dut_info.repo) + parse_res = config_parser.main(dut_info.repo) if parse_res[0] is True: self.sub_list.append( - QueueInfo(core_info.sid, ret[1], + QueueInfo(dut_info.repo, ret[1], config_parser.submit_config())) else: report.gen_state(parse_res[1]) @@ -99,28 +99,28 @@ def check_repo(self, core_info: CoreInfo): True) elif ret[0] is True: - logging.info(msg=f'[{core_info.sid}] changed!! start pull...') - self.pull_repo(core_info.sid) - report.create_dir(core_info.sid) - parse_res = config_parser.main(core_info.sid) + logging.info(msg=f'[{dut_info.repo}] changed!! start pull...') + self.pull_repo(dut_info.repo) + report.create_dir(dut_info.repo) + parse_res = config_parser.main(dut_info.repo) if parse_res[0] is True: self.sub_list.append( - QueueInfo(core_info.sid, ret[1], + QueueInfo(dut_info.repo, ret[1], config_parser.submit_config())) else: report.gen_state(parse_res[1]) config.git_commit(config.RPT_DIR, '[bot] update state file', True) else: - logging.info(msg=f'[{core_info.sid}] not changed') + logging.info(msg=f'[{dut_info.repo}] not changed') # check if cores have been added to the cicd database def check_id(self): logging.info('[check id]') - with open(config.CORE_LIST_PATH, 'r+', encoding='utf-8') as fp: - for v in fp.readlines(): - tmp = v.split() - self.check_repo(CoreInfo('', tmp[0], tmp[1])) + with open(config.DUT_LIST_PATH, 'r', encoding='utf-8') as fp: + for v in fp: + dut_info = v.split() + self.check_repo(CoreInfo('', dut_info[0], dut_info[1])) def update_queue(self): logging.info('[update queue]') @@ -137,12 +137,12 @@ def update_queue(self): # check if new-submit cores are in self.sub_list for i, va in enumerate(self.old_sub_list): for j, vb in enumerate(self.sub_list): - if va.sid == vb.sid: + if va.repo == vb.repo: self.old_sub_list[i] = self.sub_list[j] - self.sub_list[j].sid = '@' + self.sub_list[j].repo = '@' for v in self.sub_list: - if v.sid != '@': + if v.repo != '@': self.old_sub_list.append(v) with open(config.QUEUE_LIST_PATH, 'wb') as fp: diff --git a/src/task.py b/src/task.py index c9d30f0..93269a8 100755 --- a/src/task.py +++ b/src/task.py @@ -19,7 +19,7 @@ def main_task(): add_dut.main() repo_update.main() - dispatch.main() + # dispatch.main() # prio level: DEBUG < INFO < WARNING < ERROR < CRITICAL diff --git a/src/vcs_test.py b/src/vcs_test.py index 034df47..e40bf5a 100644 --- a/src/vcs_test.py +++ b/src/vcs_test.py @@ -102,8 +102,15 @@ def gen_wave_rpt(self): wave_name = f'{self.dut_cfg.top}_{self.vcs_cfg.prog[0]}_{self.vcs_cfg.prog[1]}' os.system(f'fsdb2vcd asic_top.fsdb -o {wave_name}.vcd') os.system(f'vcd2fst -v {wave_name}.vcd -f {wave_name}.fst') + wave_path = self.gen_wave_dir() + os.system(f'cp -rf {wave_name}.fst {wave_path}') + os.chdir(wave_path) + os.chdir(config.HOME_DIR) + def clear_wave_rpt(self): + pass + def comp(self): os.chdir(config.VCS_RUN_DIR) os.system('make comp') @@ -138,6 +145,11 @@ def gen_rpt_dir(self) -> str: os.system(f'mkdir -p {rpt_path}') return rpt_path + def gen_wave_dir(self) -> str: + wave_path = f'{config.WAVE_DIR}/{self.dut_cfg.top}' + wave_path += f'/{self.date}-{self.time}' + os.system(f'mkdir -p {wave_path}') + return wave_path def gen_comp_rpt(self) -> bool: rpt_path = self.gen_rpt_dir()