Skip to content

Commit

Permalink
feat: add meta cfg and mail send func
Browse files Browse the repository at this point in the history
  • Loading branch information
maksyuki committed Mar 13, 2024
1 parent 6c168cf commit 4bc3054
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}

RUN_LOG_SIZE_LIMIT = 5 * 1024 * 1024 # 5MB

SEND_MAIL_URL = '[email protected]'

def exec_cmd(cmd: str) -> str:
try:
Expand Down
54 changes: 47 additions & 7 deletions src/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
from typing import Any, Dict, Tuple, List
import tomli
import config
from data_type import DUTConfig, IverilogConfig
from data_type import VerilatorConfig, VCSConfig
from data_type import DCConfig, SubmitConfig
from data_type import MetaConfig, DUTConfig
from data_type import IverilogConfig, VerilatorConfig
from data_type import VCSConfig, DCConfig, SubmitConfig


class ConfigParser(object):
def __init__(self):
self.def_meta = MetaConfig('', '', '', ('', 'off'))
self.def_dut = DUTConfig('', '', '', '', '')
self.def_iv = IverilogConfig('')
self.def_ver = VerilatorConfig('')
self.def_vcs = VCSConfig(25, ('', ''), False)
self.def_dc = DCConfig('', 100, 'TYP', '', '', False, '')
self.sub_cfg = SubmitConfig(self.def_dut, self.def_iv, self.def_ver,
self.def_vcs, self.def_dc)
self.sub_cfg = SubmitConfig(self.def_meta, self.def_dut, self.def_iv,
self.def_ver, self.def_vcs, self.def_dc)

def clear(self):
self.sub_cfg = SubmitConfig(self.def_dut, self.def_iv, self.def_ver,
self.def_vcs, self.def_dc)
self.sub_cfg = SubmitConfig(self.def_meta, self.def_dut, self.def_iv,
self.def_ver, self.def_vcs, self.def_dc)

def check_item(self, item: str, cfg_list: Dict[str, Any],
option_list: List[str]) -> Tuple[bool, str, str]:
Expand All @@ -35,6 +36,35 @@ def check_item(self, item: str, cfg_list: Dict[str, Any],

return (False, f'{item} cfg item value is wrong', '')

#NOTE: no check the code
def check_proj_auth_ver(self, cfg_list: Dict[str,
Any]) -> Tuple[bool, str]:
if cfg_list.get('project') is not None:
self.sub_cfg.meta_cfg.proj = cfg_list['project']

if cfg_list.get('author') is not None:
self.sub_cfg.meta_cfg.auth = cfg_list['author']

if cfg_list.get('version') is not None:
self.sub_cfg.meta_cfg.ver = cfg_list['version']

return (True, 'proj, auth and ver check done with no error')

#NOTE: no check the code
def check_notif(self, cfg_list: Dict[str, Any]) -> Tuple[bool, str]:
if cfg_list.get('notif') is not None:
(notif_mail, notif_ena) = cfg_list['notif']
if notif_ena != 'off' and notif_ena != 'on':
return (False, 'notif ena item value is wrong')

# HACK: add more detailed check function
if not '@' in notif_mail:
return (False, 'notif mail item value is wrong')

self.sub_cfg.meta_cfg.notif = cfg_list['notif']

return (True, 'notif check done with no error')

def check_arch(self, cfg_list: Dict[str, Any]) -> Tuple[bool, str]:
option_list = ['rv32e', 'rv32i', 'rv32im', 'rv64i', 'rv64im']
(ck_state, ck_info, ck_val) = self.check_item('arch', cfg_list,
Expand Down Expand Up @@ -172,6 +202,12 @@ def check_commit(self, cfg_list: Dict[str, Any]) -> Tuple[bool, str]:
self.sub_cfg.dut_cfg.commit = ck_val
return (ck_state, ck_info)

def check_meta(self, cfg_list: Dict[str, Any]) -> Tuple[bool, str]:
if cfg_list.get('meta') is None:
return (False, 'dont have meta cfg table')

return (True, 'check meta cfg table done with no error')

def check_dut(self, cfg_list: Dict[str, Any]) -> Tuple[bool, str]:
if cfg_list.get('dut') is None:
return (False, 'dont have dut cfg table')
Expand Down Expand Up @@ -245,6 +281,10 @@ def check(self, repo) -> Tuple[bool, str]:
logging.info(msg=toml_cfg)
os.chdir(core_dir)
# check and parse config
check_res = self.check_meta(toml_cfg)
if check_res[0] is False:
return check_res

check_res = self.check_dut(toml_cfg)
if check_res[0] is False:
return check_res
Expand Down
24 changes: 18 additions & 6 deletions src/data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ def __str__(self) -> str:
return f'url: {self.url} repo: {self.repo} flag: {self.flag}'


class MetaConfig(object):
def __init__(self, proj: str, auth: str, ver: str, notif: Tuple[str, str]):
self.proj = proj
self.auth = auth
self.ver = ver
self.notif = notif

def __str__(self) -> str:
return f'proj: {self.proj} auth: {self.auth} ver: {self.ver} notif: {self.notif}'


class DUTConfig(object):
def __init__(self, arch: str, file: str, top: str, clk: str, commit: str):
self.arch = arch
Expand Down Expand Up @@ -80,19 +91,20 @@ def __str__(self) -> str:


class SubmitConfig(object):
def __init__(self, dut_cfg: DUTConfig, iv_cfg: IverilogConfig,
ver_cfg: VerilatorConfig, vcs_cfg: VCSConfig,
dc_cfg: DCConfig):
def __init__(self, meta_cfg: MetaConfig, dut_cfg: DUTConfig,
iv_cfg: IverilogConfig, ver_cfg: VerilatorConfig,
vcs_cfg: VCSConfig, dc_cfg: DCConfig):
self.meta_cfg = meta_cfg
self.dut_cfg = dut_cfg
self.iv_cfg = iv_cfg
self.ver_cfg = ver_cfg
self.vcs_cfg = vcs_cfg
self.dc_cfg = dc_cfg

def __str__(self) -> str:
return f'''dut_cfg: {self.dut_cfg} iv_cfg: {self.iv_cfg}
ver_cfg: {self.ver_cfg} vcs_cfg: {self.vcs_cfg}
dc_cfg: {self.dc_cfg}'''
return f'''meta_cfg: {self.meta_cfg} dut_cfg: {self.dut_cfg}
iv_cfg: {self.iv_cfg} ver_cfg: {self.ver_cfg}
vcs_cfg: {self.vcs_cfg} dc_cfg: {self.dc_cfg}'''


class QueueInfo(object):
Expand Down
43 changes: 42 additions & 1 deletion src/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import re
from typing import Tuple
from enum import Enum


def find_str(file: str, pat: str) -> Tuple[bool, int]:
Expand All @@ -20,7 +21,8 @@ def find_str(file: str, pat: str) -> Tuple[bool, int]:
top = 'ysyx_22000000'
clk = 'clock'

(top_state, top_pos) = find_str(file_path, f'\\s*module\\s*{top}\\s*[\\(\\)|\\(|\\s*]')
(top_state, top_pos) = find_str(file_path,
f'\\s*module\\s*{top}\\s*[\\(\\)|\\(|\\s*]')

if top_state is False:
print('error')
Expand All @@ -29,3 +31,42 @@ def find_str(file: str, pat: str) -> Tuple[bool, int]:
print('error')
else:
print('right')


class LogState(Enum):
start = 0
end = 1


file_path = '/home/liaoyuchi/Desktop/ysyx_ci_env/ysyx_ci_result/submit/'

lint = []
warn = []
err = []
log_state = [LogState.end, LogState.end, LogState.end]
with open(f'{file_path}/../../vcs/run/compile.log', 'r',
encoding='utf-8') as fp:
for line in fp:
if line[0:4] == 'Lint':
log_state[0] = LogState.start
elif line[0:7] == 'Warning':
log_state[1] = LogState.start
elif line[0:5] == 'Error':
log_state[2] = LogState.start
elif line == '\n':
log_state = [LogState.end, LogState.end, LogState.end]
if log_state[0] == LogState.start:
lint.append(line)
elif log_state[1] == LogState.start:
warn.append(line)
elif log_state[2] == LogState.start:
err.append(line)

print(len(lint))
print(len(warn))
print(len(err))

if len(lint) == 0 and len(warn) == 0 and len(err) == 0:
print('all clear')
else:
print('error')
6 changes: 6 additions & 0 deletions src/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def parse(self) -> bool:
config.git_commit(config.RPT_DIR, '[bot] new report!',
True) # NOTE: need to set 'True' when in product env

report.send_mail(
('[email protected]', 'on'),
f'{sub_cfg.dut_cfg.top}-{cmt_cfg.date}-{cmt_cfg.time}')
report.send_mail(
sub_cfg.meta_cfg.notif,
f'{sub_cfg.dut_cfg.top}-{cmt_cfg.date}-{cmt_cfg.time}')
return True


Expand Down
34 changes: 34 additions & 0 deletions src/report.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/python
import os
import logging
from typing import Tuple
import config


# helper class
class Report(object):
def __init__(self):
Expand All @@ -17,12 +19,44 @@ def create_dir(repo: str):
os.system(f'mkdir -p {report.dut_rpt_dir}')


def send_mail(notif_cfg: Tuple[str, str], commit: str):
(rcpt_mail_url, send_ena) = notif_cfg
if send_ena == 'on':
cmd = 'curl --url smtp://smtp.qq.com'
cmd += f' --mail-from {config.SEND_MAIL_URL}'
cmd += f' --mail-rcpt {rcpt_mail_url}'
os.system(
f'cp -rf {config.TEMPLATE_DIR}/mail.info {config.DATA_DIR}/tmp_mail.info'
)

config.repl_str(f'{config.DATA_DIR}/tmp_mail.info',
'TEMPLATE_SEND_MAIL_URL', config.SEND_MAIL_URL)

config.repl_str(f'{config.DATA_DIR}/tmp_mail.info',
'TEMPLATE_RCPT_MAIL_URL', rcpt_mail_url)

config.repl_str(f'{config.DATA_DIR}/tmp_mail.info', 'TEMPLATE_NAME',
rcpt_mail_url.split('@')[0])

config.repl_str(f'{config.DATA_DIR}/tmp_mail.info', 'TEMPLATE_COMMIT',
commit)

cmd += f' --upload-file {config.DATA_DIR}/tmp_mail.info'
with open(f'{config.TEMPLATE_DIR}/mail.token', 'r',
encoding='utf-8') as fp:
for v in fp:
cmd += f' --user {v.rstrip()}'
print(cmd)
os.system(cmd)


def gen_state(stat: str):
os.system(f'echo {stat} > {report.dut_rpt_dir}/state')


def main():
logging.info(msg='[return report]')
send_mail('[email protected]', '2024-03-11-09:52:51')


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 4bc3054

Please sign in to comment.