Skip to content

Commit

Permalink
chore: modify many vars' name
Browse files Browse the repository at this point in the history
maksyuki committed Mar 4, 2024
1 parent 40e29fe commit c994f51
Showing 6 changed files with 90 additions and 79 deletions.
103 changes: 51 additions & 52 deletions src/add_dut.py
Original file line number Diff line number Diff line change
@@ -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__':
4 changes: 2 additions & 2 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/data_type.py
Original file line number Diff line number Diff line change
@@ -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:
44 changes: 22 additions & 22 deletions src/repo_update.py
Original file line number Diff line number Diff line change
@@ -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,46 +81,46 @@ 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])
config.git_commit(config.RPT_DIR, '[bot] update state file',
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:
2 changes: 1 addition & 1 deletion src/task.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
def main_task():
add_dut.main()
repo_update.main()
dispatch.main()
# dispatch.main()


# prio level: DEBUG < INFO < WARNING < ERROR < CRITICAL
12 changes: 12 additions & 0 deletions src/vcs_test.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit c994f51

Please sign in to comment.