zoukankan      html  css  js  c++  java
  • dts--tests(一)

    cmdline.py

    """
    DPDK Test suite.
    Test cmdline.
    """
    
    import utils
    
    from test_case import TestCase
    
    
    class TestCmdline(TestCase):
    
        def set_up_all(self):
            """
            Run at the start of each test suite.
    
            Cmdline Prerequisites:
                cmdline build pass
                At least one core in DUT
            """
            out = self.dut.build_dpdk_apps('examples/cmdline')
            '''
                rm -rf ./app/test/test_resource_c.res.o
                dut.10.240.176.254: rm -rf ./app/test/test_resource_tar.res.o
                dut.10.240.176.254: rm -rf ./app/test/test_pci_sysfs.res.o
                dut.10.240.176.254: make -j 70 -C examples/cmdline
            '''
            self.verify('make: Leaving directory' in out, "Compilation failed")
            self.verify("Error" not in out, "compilation error 1")
            self.verify("No such file" not in out, "compilation error 2")
    
            # Run cmdline app
            cores = self.dut.get_core_list('1S/1C/1T')    #['1']
            '''
            (Pdb) self.dut.get_core_list('1S/3C/1T')
            ['1', '2', '3']
            (Pdb) self.dut.get_core_list('2S/3C/1T')
            ['1', '2', '3', '32', '33', '34']
            (Pdb) self.dut.get_core_list('1S/5C/1T')
            ['1', '2', '3', '4', '5']
            (Pdb) self.dut.get_core_list('1S/3C/1T')
            ['1', '2', '3']
    
            '''
            coreMask = utils.create_mask(cores)
            '''
            ['1']  -> '0x2'        #转换为16进制
            ['1', '2', '3'] -> '0xe'
            ['1', '2', '3', '32', '33', '34'] -> '0x70000000e'
            '''
            self.dut.send_expect("./examples/cmdline/build/app/cmdline -n 1 -c " + coreMask, "> ", 10)
    
        def set_up(self):
            """
            Run before each test case.
            Nothing to do.
            """
            pass
    
        def test_cmdline_sample_commands(self):
            """
            Sample commands test.
            """
    
            # add a test object with an IP address associated
            out = self.dut.send_expect("add object 192.168.0.1", "example> ")
            self.verify("Object object added, ip=192.168.0.1" in out, "add command error")
    
            # verify the object existance
            out = self.dut.send_expect("add object 192.168.0.1", "example> ")
            self.verify("Object object already exist" in out, "double add command error")
    
            # show the object result by 'show' command
            out = self.dut.send_expect("show object", "example> ")
            self.verify("Object object, ip=192.168.0.1" in out, "show command error")
    
            # delete the object in cmdline
            out = self.dut.send_expect("del object", "example> ")
            self.verify("Object object removed, ip=192.168.0.1" in out, "del command error")
    
            # double delete the object to verify the correctness
            out = self.dut.send_expect("del object", "example> ", 1)
            self.verify("Bad arguments" in out, "double del command error")
    
            # verify no such object anymore
            out = self.dut.send_expect("show object", "example> ", 1)
            self.verify("Bad arguments" in out, "final show command error")
    
            # verify the help command
            out = self.dut.send_expect("help", "example> ", 1)
    
            """
            Demo example of command line interface in RTE
    
            This is a readline-like interface that can be used to
            debug your RTE application. It supports some features
            of GNU readline like completion, cut/paste, and some
            other special bindings.
    
            This demo shows how rte_cmdline library can be
            extended to handle a list of objects. There are
            3 commands:
            - add obj_name IP
            - del obj_name
            - show obj_name
            """
            self.verify(" " in out, "help command error")
    
            out = self.dut.send_expect("?", "example> ", 1)
            """
            show [Mul-choice STRING]: Show/del an object
            del [Mul-choice STRING]: Show/del an object
            add [Fixed STRING]: Add an object (name, val)
            help [Fixed STRING]: show help
            """
            self.verify(" " in out, "? command error")
    
        def tear_down(self):
            """
            Run after each test case.
            Nothing to do.
            """
            pass
    
        def tear_down_all(self):
            """
            Run after each test suite.
            Stop cmdline app.
            """
            self.dut.kill_all()

    测试的目的:

    Test Case: cmdline sample commands test
    =======================================
    
    Add a test object with an IP address associated to it::
    
      example>add object 192.168.0.1
        Object object added, ip=192.168.0.1
    
    Verify the object existence::
    
      example>add object 192.168.0.1
        Object object already exist
    
    Show the object result by ``show`` command::
    
      example>show object
        Object object, ip=192.168.0.1
    
    Verify the output matches the configuration.
    
    Delete the object in cmdline and show the result again::
    
      example>del object
        Object object removed, ip=192.168.0.1
    
    Double delete the object to verify the correctness::
    
      example>del object
        Bad arguments
    
    Verify no such object exist now.::
    
      example>show object
        Bad arguments
    
    Verify the hidden command ? and help command::
    
      example>help
        Demo example of command line interface in RTE
    
        This is a readline-like interface that can be used to
        debug your RTE application. It supports some features
        of GNU readline like completion, cut/paste, and some
        other special bindings.
    
        This demo shows how rte_cmdline library can be
        extended to handle a list of objects. There are
        3 commands:
        - add obj_name IP
        - del obj_name
        - show obj_name
    
      example>?
        show [Mul-choice STRING]: Show/del an object
        del [Mul-choice STRING]: Show/del an object
        add [Fixed STRING]: Add an object (name, val)
        help [Fixed STRING]: show help
        
    cmdline.py
            # add a test object with an IP address associated
            out = self.dut.send_expect("add object 192.168.0.1", "example> ")
            self.verify("Object object added, ip=192.168.0.1" in out, "add command error")
    
            # verify the object existance
            out = self.dut.send_expect("add object 192.168.0.1", "example> ")
            self.verify("Object object already exist" in out, "double add command error")
    
            # show the object result by 'show' command
            out = self.dut.send_expect("show object", "example> ")
            self.verify("Object object, ip=192.168.0.1" in out, "show command error")
    
            # delete the object in cmdline
            out = self.dut.send_expect("del object", "example> ")
            self.verify("Object object removed, ip=192.168.0.1" in out, "del command error")
    
            # double delete the object to verify the correctness
            out = self.dut.send_expect("del object", "example> ", 1)
            self.verify("Bad arguments" in out, "double del command error")
    
            # verify no such object anymore
            out = self.dut.send_expect("show object", "example> ", 1)
            self.verify("Bad arguments" in out, "final show command error")
    
            # verify the help command
            out = self.dut.send_expect("help", "example> ", 1)
    
            """
            Demo example of command line interface in RTE
    
            This is a readline-like interface that can be used to
            debug your RTE application. It supports some features
            of GNU readline like completion, cut/paste, and some
            other special bindings.
    
            This demo shows how rte_cmdline library can be
            extended to handle a list of objects. There are
            3 commands:
            - add obj_name IP
            - del obj_name
            - show obj_name
            """
            self.verify(" " in out, "help command error")
    
            out = self.dut.send_expect("help", "example> ", 1)
            """
            show [Mul-choice STRING]: Show/del an object
            del [Mul-choice STRING]: Show/del an object
            add [Fixed STRING]: Add an object (name, val)
            help [Fixed STRING]: show help
            """
            self.verify(" " in out, "? command error")

    dut:执行详细信息

        [root@localhost cmdline]# ./examples/cmdline/build/app/cmdline -n 1 -c 0x2
        EAL: PCI device 0000:82:00.0 on NUMA socket 1
        EAL:   probe driver: 8086:10fb net_ixgbe
        EAL: PCI device 0000:82:00.1 on NUMA socket 1
        EAL:   probe driver: 8086:10fb net_ixgbe
        example> add object 192.168.0.1
        Object object added, ip=192.168.0.1
        example> add object 192.168.0.1
        Object object already exist
        example> show object 192.168.0.1
        Bad arguments
        example> show object
        Object object, ip=192.168.0.1
        example> del object
        Object object removed, ip=192.168.0.1
        example> del object
        Bad arguments
        example> show object
        Bad arguments
        example> help
        Demo example of command line interface in RTE
    
        This is a readline-like interface that can be used to
        debug your RTE application. It supports some features
        of GNU readline like completion, cut/paste, and some
        other special bindings.
    
        This demo shows how rte_cmdline library can be
        extended to handle a list of objects. There are
        3 commands:
        - add obj_name IP
        - del obj_name
        - show obj_name
    
        example>
         show [Mul-choice STRING]: Show/del an object
         del [Mul-choice STRING]: Show/del an object
         add [Fixed STRING]: Add an object (name, val)
         help [Fixed STRING]: show help
  • 相关阅读:
    每日一水 POJ8道水题
    编译和使用 MySQL C++ Connector
    j2ee model1模型完成分页逻辑的实现 详解!
    DB查询分析器访问EXCEL时,要在表名前后加上中括弧或双引号
    指向结构体变量的指针
    EOSS V3.0 企业运营支撑系统(基于RBAC原理的权限管理)
    MybatisGen1.0 Mybatis JavaBean Mapper生成工具
    The table name must be enclosed in double quotation marks or sqare bracket while accessing EXCEL by
    资源-Android:Android
    软件-开发软件:Android Studio
  • 原文地址:https://www.cnblogs.com/eilinge/p/9799324.html
Copyright © 2011-2022 走看看