<commit_before># -*- coding: utf-8 -*-
''' SPMU GNRPRB hand checking
Case 描述：当MME/SGSN运行大约248天后，SMMU的GRNPRB的hand group 2里面的50个hand会自动被
释放，而不能重启创建，从现象上可以观察到终端用户PDP激活困难，SGSN会出大量的
0x167( no_rsp_co_process_c )的错误代码
临时解决方案：重启所有的 SMMU 单元
'''
import re
from libs.checker import ResultInfo,CheckStatus
from libs.log_spliter import LogSpliter, LOG_TYPE_FLEXI_NS

## Mandatory variables
##--------------------------------------------
module_id = 'fns2016030720'
tag  = ['flexing','china']
priority = 'critical'
name = "SMMU GRNPRB hand checking"
desc = __doc__
criteria = u''' 检查SMMU GRNPRB hand group 2 的hand数，50为通过
'''
result = ResultInfo(name)
error = ''
##--------------------------------------------

##--------------------------------------------

##--------------------------------------------
## Optional variables
target_version = ['NS30', 'NS40', 'NS15']
command='ZDDE:SMMU,x:"ZL:9","ZLP:9,FAM","Z9H:404";'
#match_start= 'HAND FO:PREV NEXT TIME     GR STATE    STABITS  JBUFFER      RCOMP FAM  PROC FO'
patten = re.compile("^[0-9,A-F]{4}")
smmu_info="SMMU-%s GRNPRB hand check %s\n"
##

def read_block(logfile,blkname):
    # loglines = file(logfile).readlines()
    #
    # return ''.join(loglines)
    logspliter=LogSpliter(type=LOG_TYPE_FLEXI_NS)
    logspliter.load(logfile)
    return logspliter.get_log(blkname,fuzzy=True)

def hardwareinfo():
    hwinfo = {}
    return hwinfo

def get_card(caretype):
    return
##--------------------------------------------
## Mandatory function: log_collection
##--------------------------------------------
def log_collection():
    cmds = ['ZDDE:SMMU,x:"ZL:9","ZLP:9,FAM","Z9H:132";'
            ]
    for cmd in cmds:
        print cmd

##--------------------------------------------
## Mandatory function: run
##--------------------------------------------
def run(logfile):
    rsult_info=[]

    blocks = read_block(logfile,'ZDDE:SMMU,')

    for block in blocks:
        m=re.match(r".+SMMU,(\d+)",block.command)
        unit_index=''
        if m:
            unit_index=m.groups(1)[0]
        else:
            continue
        status = CheckStatus.UNCHECKED
        hands=[]
        for line in list(block.result):
            line=line.strip()
            if (patten.search(line)):
                fields=line.split(' ')
                if fields[5]=='02':
                    hands.append(line[:4])
        if len(hands)==50:
            status=CheckStatus.PASSED
        else:
            status=CheckStatus.FAILED

        if status == CheckStatus.UNCHECKED:
            status = CheckStatus.UNKNOWN
        rsult_info.append(smmu_info %(unit_index,status))

    result.load(status=status,info=rsult_info,error=error)

    return result<commit_msg>Add total_status to get the final status.<commit_after># -*- coding: utf-8 -*-
''' SPMU GNRPRB hand checking
Case 描述：当MME/SGSN运行大约248天后，SMMU的GRNPRB的hand group 2里面的50个hand会自动被
释放，而不能重启创建，从现象上可以观察到终端用户PDP激活困难，SGSN会出大量的
0x167( no_rsp_co_process_c )的错误代码
临时解决方案：重启所有的 SMMU 单元
'''
import re
from libs.checker import ResultInfo,CheckStatus
from libs.log_spliter import LogSpliter, LOG_TYPE_FLEXI_NS

## Mandatory variables
##--------------------------------------------
module_id = 'fns2016030720'
tag  = ['flexing','china']
priority = 'critical'
name = "SMMU GRNPRB hand checking"
desc = __doc__
criteria = u''' 检查SMMU GRNPRB hand group 2 的hand数，50为通过
'''
result = ResultInfo(name)
error = ''
##--------------------------------------------

##--------------------------------------------

##--------------------------------------------
## Optional variables
target_version = ['NS30', 'NS40', 'NS15']
command='ZDDE:SMMU,x:"ZL:9","ZLP:9,FAM","Z9H:404";'
#match_start= 'HAND FO:PREV NEXT TIME     GR STATE    STABITS  JBUFFER      RCOMP FAM  PROC FO'
patten = re.compile("^[0-9,A-F]{4}")
smmu_info="SMMU-%s GRNPRB hand check %s\n"
##

def read_block(logfile,blkname):
    # loglines = file(logfile).readlines()
    #
    # return ''.join(loglines)
    logspliter=LogSpliter(type=LOG_TYPE_FLEXI_NS)
    logspliter.load(logfile)
    return logspliter.get_log(blkname,fuzzy=True)

def hardwareinfo():
    hwinfo = {}
    return hwinfo

def get_card(caretype):
    return
##--------------------------------------------
## Mandatory function: log_collection
##--------------------------------------------
def log_collection():
    cmds = ['ZDDE:SMMU,x:"ZL:9","ZLP:9,FAM","Z9H:132";'
            ]
    for cmd in cmds:
        print cmd

##--------------------------------------------
## Mandatory function: run
##--------------------------------------------
def run(logfile):
    rsult_info=[]
    total_status=CheckStatus.PASSED

    blocks = read_block(logfile,'ZDDE:SMMU,')

    for block in blocks:
        m=re.match(r".+SMMU,(\d+)",block.command)
        unit_index=''
        if m:
            unit_index=m.groups(1)[0]
        else:
            continue
        status = CheckStatus.UNCHECKED
        hands=[]
        for line in list(block.result):
            line=line.strip()
            if (patten.search(line)):
                fields=line.split(' ')
                if fields[5]=='02':
                    hands.append(line[:4])
        if len(hands)==50:
            status=CheckStatus.PASSED
        else:
            status=CheckStatus.FAILED
            total_status=CheckStatus.FAILED

        if status == CheckStatus.UNCHECKED:
            status = CheckStatus.UNKNOWN
        rsult_info.append(smmu_info %(unit_index,status))

    result.load(status=total_status,info=rsult_info,error=error)

    return result
{'fraction_non_alphanumeric': 0.2444806369887803, 'fraction_numerical': 0.01918204849800941, 'mean_word_length': 1.9493062966915689, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3084925', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1892, 'n_words': 329}