Skip to content

Commit

Permalink
feat: modify vcs comp and run module
Browse files Browse the repository at this point in the history
  • Loading branch information
maksyuki committed Feb 28, 2024
1 parent 9bb4827 commit 756d525
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 27 deletions.
8 changes: 8 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
VCS_CPU_DIR = VCS_DIR + '/cpu'
VCS_SCRIPT_DIR = VCS_DIR + '/script'

TESTCASE_NAME_LIST = ['hello', 'memtest', 'rtthread']
TESTCASE_TYPE_LIST = ['flash', 'mem', 'sdram']
TESTCASE_RES_DICT = {
'hello': 'Hello World!',
'memtest': 'ALL TESTS PASSED!!',
'rtthread': 'Hello RISC-V'
}


def exec_cmd(cmd: str) -> str:
try:
Expand Down
7 changes: 2 additions & 5 deletions src/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ def check_prog(self, cfg_list: Dict[str, Any]) -> Tuple[bool, str]:
if prog.get('type') is None:
return (False, 'dont have prog sub type cfg item')

test_name_list = ['hello', 'memtest', 'rtthread']
test_type_list = ['flash', 'mem', 'sdram']

for vn in test_name_list:
for vt in test_type_list:
for vn in config.TESTCASE_NAME_LIST:
for vt in config.TESTCASE_TYPE_LIST:
if (vn == prog['name'] and vt == prog['type']):
self.sub_cfg.vcs_cfg.prog = (prog['name'], prog['type'])
return (True, 'prog check done with no error')
Expand Down
4 changes: 2 additions & 2 deletions src/repo_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def check_repo(self, core_info: CoreInfo):
QueueInfo(core_info.sid, ret[1],
config_parser.submit_config()))
else:
report.gen_state(core_info.sid, parse_res[1])
report.gen_state(parse_res[1])
config.git_commit(config.RPT_DIR, '[bot] update state file',
True)

Expand All @@ -108,7 +108,7 @@ def check_repo(self, core_info: CoreInfo):
QueueInfo(core_info.sid, ret[1],
config_parser.submit_config()))
else:
report.gen_state(core_info.sid, parse_res[1])
report.gen_state(parse_res[1])
config.git_commit(config.RPT_DIR, '[bot] update state file',
True)
else:
Expand Down
11 changes: 5 additions & 6 deletions src/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@

class Report(object):
def __init__(self):
self.stat = ''
self.dut_rpt_dir = ''


report = Report()


def create_dir(sid: str):
core_rpt_dir = config.RPT_DIR + '/' + sid
os.system(f'mkdir -p {core_rpt_dir}')
report.dut_rpt_dir = config.RPT_DIR + '/' + sid
os.system(f'mkdir -p {report.dut_rpt_dir}')


def gen_state(sid: str, stat: str):
core_rpt_dir = config.RPT_DIR + '/' + sid
os.system(f'echo {stat} > {core_rpt_dir}/state')
def gen_state(stat: str):
os.system(f'echo {stat} > {report.dut_rpt_dir}/state')


def main():
Expand Down
105 changes: 91 additions & 14 deletions src/vcs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self):
self.lint = []
self.warn = []
self.err = []
self.run_res = {}
self.dut_cfg = DUTConfig('', '', '', '')
self.vcs_cfg = VCSConfig(25, ('', ''), False)

Expand All @@ -28,6 +29,7 @@ def clear(self):
self.lint = []
self.warn = []
self.err = []
self.run_res = {}
self.dut_cfg = DUTConfig('', '', '', '')
self.vcs_cfg = VCSConfig(25, ('', ''), False)
self.clear_env()
Expand All @@ -51,13 +53,18 @@ def intg_soc(self):
os.system('python autowire.py')
os.chdir(config.HOME_DIR)

def comp(self):
os.chdir(config.VCS_RUN_DIR)
cmd = 'make comp'
os.system(cmd)
def program(self, prog_name: str, prog_type: str):
if prog_type == 'flash':
os.system(
f'ln -sf program/{prog_name}.{prog_type} mem_Q128_bottom.vmf')
else:
os.system(f'ln -sf program/jump.{prog_type} mem_Q128_bottom.vmf')
os.system(
f'ln -sf program/{prog_name}.{prog_type} init_{prog_type}.bin.txt'
)

def collect_comp_log(self):
log_state = [LogState.end, LogState.end, LogState.end]
# NOTE: receive comp log
with open(config.VCS_RUN_DIR + '/compile.log', 'r',
encoding='utf-8') as fp:
for line in fp:
Expand All @@ -77,40 +84,110 @@ def comp(self):
elif log_state[2] == LogState.start:
self.err.append(line)

def collect_run_log(self, prog_name: str, prog_type: str):
with open(config.VCS_RUN_DIR + '/run.log', 'r',
encoding='utf-8') as fp:
tmp_res = ''
for line in fp:
if not '/home' in line:
tmp_res += line
if config.TESTCASE_RES_DICT[prog_name] in line: # test pass
self.run_res[f'{prog_name}-{prog_type}'] = ''
return

self.run_res[f'{prog_name}-{prog_type}'] = tmp_res

def comp(self):
os.chdir(config.VCS_RUN_DIR)
os.system('make comp')
self.collect_comp_log()

def run(self):
os.chdir(config.VCS_RUN_DIR)
if self.vcs_cfg.prog[0] == '':
os.system('make all-test')
for pl in config.TESTCASE_NAME_LIST:
for mt in config.TESTCASE_TYPE_LIST:
self.program(pl, mt)
os.system(f'make run test={pl}-{mt}')
self.collect_run_log(pl, mt)

else:
os.system(f'make {self.vcs_cfg.prog[0]}-{self.vcs_cfg.prog[1]}')
self.program(self.vcs_cfg.prog[0], self.vcs_cfg.prog[1])
os.system(
f'make run test={self.vcs_cfg.prog[0]}-{self.vcs_cfg.prog[1]}')
self.collect_run_log(self.vcs_cfg.prog[0], self.vcs_cfg.prog[1])

def gen_rpt(self):
rpt_path = config.RPT_DIR + '/' + self.dut
def gen_rpt_dir(self) -> str:
rpt_path = config.RPT_DIR + '/' + self.dut_cfg.top
rpt_path += f'/{self.date}-{self.time}'
os.system(f'mkdir -p {rpt_path}')
with open(rpt_path + '/vcs_report', 'a+', encoding='utf-8') as fp:
fp.writelines(f'\ncore: {self.dut}\n')
return rpt_path

def gen_comp_rpt(self) -> bool:
rpt_path = self.gen_rpt_dir()
with open(f'{rpt_path}/vcs_report', 'a+', encoding='utf-8') as fp:
fp.writelines(f'\ndut: {self.dut_cfg.top}\n')
fp.writelines(
'\n################\n#vcs compile log\n################\n')

if not self.err or not self.warn or not self.lint:
fp.writelines('all clear\n\n')
return True
else:
fp.writelines(self.err + self.warn + self.lint)
return False

def gen_run_res(self, prog_name: str, prog_type: str) -> str:
res = ''

if self.run_res[f'{prog_name}-{prog_type}'] == '':
res += f'{prog_name} test in {prog_type} pass!!\n'
else:
res += f'{prog_name} test in {prog_type} fail!!\n'
res += '======================================================\n'
res += self.run_res[f'{prog_name}-{prog_type}']
res += '======================================================\n\n'

return res

def gen_run_rpt(self) -> bool:
rpt_path = self.gen_rpt_dir()
with open(f'{rpt_path}/vcs_report', 'a+', encoding='utf-8') as fp:
fp.writelines(
'\n#####################\n#vcs program test\n#####################\n'
)

if self.vcs_cfg.prog[0] == '':
for pl in config.TESTCASE_NAME_LIST:
for mt in config.TESTCASE_TYPE_LIST:
fp.writelines(self.gen_run_res(pl, mt))
else:
fp.writelines(
self.gen_run_res(self.vcs_cfg.prog[0],
self.vcs_cfg.prog[1]))

return True


vcstest = VCSTest()


def main(dut_cfg: DUTConfig, vcs_cfg: VCSConfig):
def main(dut_cfg: DUTConfig, vcs_cfg: VCSConfig) -> bool:
logging.info(msg='[vcs test]')
vcstest.clear()
vcstest.dut_cfg = dut_cfg
vcstest.vcs_cfg = vcs_cfg
vcstest.intg_soc()
comp_res = True
vcstest.comp()
vcstest.run()
vcstest.gen_rpt()
comp_res = vcstest.gen_comp_rpt()

if comp_res is True:
vcstest.run()
run_info = vcstest.gen_run_rpt()
return run_info

return comp_res


if __name__ == '__main__':
Expand Down

0 comments on commit 756d525

Please sign in to comment.