#!/bin/bash
set +x
source /opt/huawei/snas/script/inspect_mml/CheckItems
source /opt/inspect/inspect_map.sh
source /opt/node_type_recognize.sh > /dev/null 2>&1

function checkClockSourceRisk()
{
    local curInspectNum="136"
    local curInspectFun="$(GetInspectType $curInspectNum)"
    local resultFile="/tmp/tmpResult${curInspectFun}"
    local isPass=0
    local tmpClk="tsc"
    >${resultFile}

    local tempCurClkSrc=$(cat /sys/devices/system/clocksource/clocksource0/current_clocksource)
    if [ "X${tempCurClkSrc}" == "X" ];then 
        isPass=1
        echo "[ERR]INFO:Get current clocksource failed from command(cat /sys/devices/system/clocksource/clocksource0/current_clocksource)." >> ${resultFile} 2>&1
        LOG "[$LINENO]Get current clocksource failed."
        echo "${curInspectFun}_Pass $isPass" >>${resultFile}
        return
    fi
    
    #ARMʱԴarch_sys_counterĶtsc
    GetArcType
    if [ $? -eq 2 ];then
        tmpClk="arch_sys_counter"
    fi
    
    LOG "[$LINENO]CurrentClockSource:$tempCurClkSrc"
    if [ "${tempCurClkSrc}" != "${tmpClk}" ];then 
        isPass=$(check_pass $isPass 1)
        echo "[ERR]INFO:Current clock source is not ${tmpClk}." >> ${resultFile} 2>&1
    fi

    IsT3000Node
    #ֻT3000ڵͣڵ
    if [ $? -ne 0 ];then
        echo "CurrentClockSource:$tempCurClkSrc||ProductionDate:--" >> ${resultFile} 2>&1
        echo "${curInspectFun}_Pass $isPass" >>${resultFile}
        return 
    fi

    #豸
    local tempBoardSerial=$(ipmitool fru |grep "Board Serial" |awk '{print $4}')
    #豸н
    local tempProductYear=$(echo ${tempBoardSerial:8:1})
    local tempProductMonth=$(echo ${tempBoardSerial:9:1})

    if [ -z "$tempProductYear" ] || [ -z "$tempProductMonth" ] ; then
        echo "CurrentClockSource:$tempCurClkSrc||ProductionDate:--" >> ${resultFile} 2>&1
        echo "${curInspectFun}_Pass $isPass" >>${resultFile}
        return 
    fi

    #ֻ201308֮ǰ豸ʾѲ챨
    if [ "$tempProductYear" \< "D" ] ; then
        echo "[ERR]INFO:The ProduceDate of board is less than 2013-08!"  >>${resultFile}
        isPass=$(check_pass $isPass 4)
    elif [ "$tempProductYear" = "D" ] && [ "$tempProductMonth" \< "8" ] ; then
        echo "[ERR]INFO:The ProduceDate of board is less than 2013-08!"  >>${resultFile}
        isPass=$(check_pass $isPass 4)
    fi
    echo "CurrentClockSource:$tempCurClkSrc||ProductionDate:${tempProductYear}/${tempProductMonth}" >> ${resultFile} 2>&1
    echo "${curInspectFun}_Pass $isPass" >>${resultFile}
}

checkClockSourceRisk

