zoukankan      html  css  js  c++  java
  • 19_Linux Rolling_Counter正确性验证

    19_Linux Rolling_Counter正确性验证

    19.1、需求定义

      遍历结果日志中最后一位字符(Rolling Counter)的正确性。

    19.2、需求分析

        最后一位字符从0到15循环计数,一个完整循环为"0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",即提取验证首字符,首字符后值依次加1,直至15,然后跳转至完整循环;若出现字符异常,如"0 1 3 4 5 ...",即判定失败。

    19.3、需求分解

        1)实现获取首字符后,定义该字符完整数组,从0到15存在16种定义数组模式:

        0   :(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)

        1   :(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0)

        2   :(2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1)

        ... ...

        13 :(13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12)

        14 :(14 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13)

        15 :(15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14)

        2)获取首字符定义完整数组,依次获取日志中每一行的结果并进行结果判定,若判定结果失败,则输出当前失败行数与当前失败值

    19.4、实现代码

      源代码:test.sh

      #!/bin/bash

      function create_array_list()
      {
          # Create a complete array defined by the first character
          local value_init=0
          local value_end=15
          local value_len=16
          array=()
          if [ "$1" -eq 0 ]
          then
          {
                array=(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
          }  
          elif [ "$1" -le 15 ] && [ "$1" -gt 0 ]
          then
          {
                for ((i=$1;i<=${value_end};i++))
                do
                {
                      let array[${value_init}]+=$i
                      let value_init++
                }
                done
                local ii=0
                for ((ii=0;ii<$1;ii++))
                do
                {
                      let array[${value_init}]+=$ii
                      let value_init++
                }
                done
          }
          else
          {
                printf "error ... "
          }
          fi
      }

      function sequence_check_result()
      {
          # Get log content and judge the result
          local array_init=0
          local rows_count=1
          while read line
          do
          {
                if [ "${line}" == "${array[${array_init}]}" ]
                then
                {
                      printf "lines ${rows_count} success value ${line} "
                }
                else
                {
                      printf "lines ${rows_count} fail value ${line} "
                      break
                }
                fi
                let array_init++
                let rows_count++
                if [ "${array_init}" -eq 16 ]
                then
                {
                      local array_init=0
                }
                fi
          }  
          done < $1
      }

      function main()
      {
          # Main program entry
          local check_log="info.log"
          local first_value=$(head -1 ${check_log})
          create_array_list ${first_value}
          sequence_check_result ${check_log}
      }

      main

      测试内容:info.log

      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      1
      2

      验证结果:./test.sh

      选区_257.png


      原文链接:https://mp.weixin.qq.com/mp/appmsgalbum?action=getalbum&album_id=1374601582674919425&__biz=MzIyMDI3MTg5OQ==#wechat_redirect

      更多精彩,请扫描下方微信公众号,添加关注

      

  • 相关阅读:
    vbscript错误代码及对应解释大全(希望还没过时)
    对象存储服务MinIO安装部署分布式及Spring Boot项目实现文件上传下载
    一道算法题,求更好的解法
    浅谈SQLite——实现与应用
    Linux网络协议栈(二)——套接字缓存(socket buffer)
    服务器开发入门——理解异步I/O
    理解MySQL——复制(Replication)
    线性时间排序算法
    Linux网络协议栈(一)——Socket入门(2)
    理解MySQL——索引与优化
  • 原文地址:https://www.cnblogs.com/jianqiang-1/p/13089989.html
Copyright © 2011-2022 走看看