intel dpdk api test程序讲解 (dpdk库测试模块)

声明:此文档只做学习交流使用,请勿用作其他商业用途

author:朝阳_tony
E-mail : [email protected]
Create Date: 2013-8-5 9:58:56 Monday
Last Change: 2013-8-6 9:31:58 Tuesday

转载请注明出处:http://blog.csdn.net/linzhaolove


此文请结合intel dpdk源码去阅读,源码可以去http://dpdk.org/dev 网页中下载;更多官方文档请访问http://dpdk.org

intel DPDK交流群希望大家加入互相学习,QQ群号: 289784125


本文章基于intel dpdk  的源码1.3.1 版本进行讲解;


摘要

 intel dpdk  api提供了一个自身库测试模块,方便dpdk提供的各个库模块的独立测试;这个test程序的源码就在dpdk/app/test目录下;


1、test程序源码讲解

1)、源码位置

# ls app/test/
autotest_data.py        test_cmdline_cirbuf.c     test_eal_fs.c           test_memcpy.c        test_pmac_pm.h
autotest.py             test_cmdline_etheraddr.c  test_errno.c            test_memcpy_perf.c   test_prefetch.c
autotest_runner.py      test_cmdline.h            test_func_reentrancy.c  test_memory.c        test_ring.c
autotest_test_funcs.py  test_cmdline_ipaddr.c     test.h                  test_mempool.c       test_rwlock.c
commands.c              test_cmdline_lib.c        test_hash.c             test_mempool_perf.c  test_spinlock.c
Makefile                test_cmdline_num.c        test_hash_perf.c        test_memzone.c       test_string_fns.c
process.h               test_cmdline_portlist.c   test_interrupts.c       test_mp_secondary.c  test_tailq.c
test_alarm.c            test_cmdline_string.c     test_logs.c             test_pci.c           test_timer.c
test_atomic.c           test_cpuflags.c           test_lpm.c              test_per_lcore.c     test_version.c
test_byteorder.c        test_cycles.c             test_lpm_routes.h       test_pmac_acl.c
test.c                  test_debug.c              test_malloc.c           test_pmac_acl.h
test_cmdline.c          test_eal_flags.c          test_mbuf.c             test_pmac_pm.c
在dpdk的app/test目录下,存放了关于每个库模块的调用c文件,每个c文件包含相应模块的调用测试代码;

其中主要的test.c文件时test模块的main所在;

2)、test程序main函数讲解

ret = rte_eal_init(argc, argv);
还是先调用rte_eal_init对dpdk底层库初始化;关于dpdk底层初始化详解,请看我之前写的博文;

rte_timer_subsystem_init();
对dpdk自身的时钟子系统进行初始化,因为这个测试模块有对时钟模块的测试功能;

cl = cmdline_stdin_new(main_ctx, "RTE>>");
将命令行模块初始化,其中main_ctx是一个结构体指针;在app/test/commands.c文件中对其初始化;

cmdline_parse_ctx_t main_ctx[] = {
    (cmdline_parse_inst_t *)&cmd_autotest,
    (cmdline_parse_inst_t *)&cmd_dump,
    (cmdline_parse_inst_t *)&cmd_dump_one,
    (cmdline_parse_inst_t *)&cmd_set_ring,
    (cmdline_parse_inst_t *)&cmd_quit,
    NULL,
};
在main_ctx结构体中也是初始化了几个子结构体的指针;这包括自动测试,dump数据,set配置等;当命令行执行的时候,输入命令,命令行模块会调用相应的子结构体中的函数指针,进行命令的判断;

cmdline_parse_inst_t cmd_autotest = {
    .f = cmd_autotest_parsed,  /* function to call */
    .data = NULL,      /* 2nd arg of func */
    .help_str = "launch autotest",
    .tokens = {        /* token list, NULL terminated */
        (void *)&cmd_autotest_autotest,
        NULL,
    },
};
我们看一下其中的一个子结构体cmd_autotest,其内部的cmd_autotest_parsed就是命令行模块在判断命令执行的回调函数;在cmd_autotest_parsed函数源码中包含了,测试命令的匹配字符串;

    if (all || !strcmp(res->autotest, "atomic_autotest"))
        ret |= test_atomic();
    if (all || !strcmp(res->autotest, "malloc_autotest"))
        ret |= test_malloc();
    if (all || !strcmp(res->autotest, "spinlock_autotest"))
        ret |= test_spinlock();
在匹配好字符串后,就会去调用相应的测试函数,而这些测试函数,就是在相应的模块文件中定义的,同在app/test目录中;

    cmdline_interact(cl);
    cmdline_stdin_exit(cl);
在main函数中上面这两行,是命令行模块的运行和退出函数;


2、test程序编译运行测试

1)、test程序编译

make -C x86_64-default-linuxapp-gcc/
这样就可以了,一半编译后会在x86_64-default-linuxapp-gcc/app/目录中生成几个测试文件;
# ls x86_64-default-linuxapp-gcc/app/
cmdline_test      dump_cfg          test              testpmd
cmdline_test.map  dump_cfg.map      test.map          testpmd.map


当然你也可以执行

make -C app/test
这样编译后再app/test/build/app中产生执行文件;这和上面产生的文件时一样的;
# ls app/test/build/app/
test  test.map


2)、test程序运行

./x86_64-default-linuxapp-gcc/app/test -c 1f -n 4
我传入了两个参数

-c 1f 指定5个core分给dpdk使用;

-n4  指定内存4通道,  我到目前还不知道这个4通道的用途,dpdk是内存通道和rank的拓展,希望有高手指点????


运行后的输出,我只摘了一部分输出,大意是指分配了多少内存,和多少core等等;

EAL: Skip lcore 31 (not detected)
EAL: coremask set to 1f
EAL: Using native RDTSC
EAL: Setting up memory...
EAL: Ask a virtual area of 0x200000 bytes
EAL: Virtual area found at 0x7f6d9ea00000 (size = 0x200000)
EAL: Ask a virtual area of 0x7f000000 bytes
EAL: Virtual area found at 0x7f6d1f800000 (size = 0x7f000000)
EAL: Ask a virtual area of 0x400000 bytes
EAL: Virtual area found at 0x7f6d1f200000 (size = 0x400000)
EAL: Ask a virtual area of 0x600000 bytes
EAL: Virtual area found at 0x7f6d1ea00000 (size = 0x600000)
EAL: Ask a virtual area of 0x400000 bytes
EAL: Virtual area found at 0x7f6d1e400000 (size = 0x400000)
EAL: Requesting 1024 pages of size 2MB from socket 0
EAL: Increasing open file limit
func[rte_eal_tailq_lookup_by_idx]line[96] position
tailq_idx= 1 RTE_MAX_TAILQ=32
func[rte_eal_tailq_lookup_by_idx]line[96] position
tailq_idx= 2 RTE_MAX_TAILQ=32
func[rte_eal_tailq_lookup_by_idx]line[96] position
tailq_idx= 1 RTE_MAX_TAILQ=32
func[rte_eal_tailq_lookup_by_idx]line[96] position
tailq_idx= 0 RTE_MAX_TAILQ=32
EAL: Master core 0 is ready (tid=9f170800)
EAL: Core 3 is ready (tid=1bfef700)
EAL: Core 4 is ready (tid=1b7ee700)
EAL: Core 1 is ready (tid=1cff1700)
EAL: Core 2 is ready (tid=1c7f0700)
RTE>>

最后的RTE>> 是在执行命令初始化的时候,输入的提示信息;


我们应该输入什么命令测试呢,如果help看看;

RTE>>help
Command not found
RTE>>
没有help命令????,其实dpdk test模块的帮助命令是 "  shift+?" , 就是输入’?‘问号就行;
在输入'?'问号后,看一下输出结果;

 pci_autotest [Mul-choice STRING]: launch autotest
 memory_autotest [Mul-choice STRING]: launch autotest
 per_lcore_autotest [Mul-choice STRING]: launch autotest
 spinlock_autotest [Mul-choice STRING]: launch autotest
 rwlock_autotest [Mul-choice STRING]: launch autotest
 atomic_autotest [Mul-choice STRING]: launch autotest
 byteorder_autotest [Mul-choice STRING]: launch autotest
 prefetch_autotest [Mul-choice STRING]: launch autotest
 cycles_autotest [Mul-choice STRING]: launch autotest
 logs_autotest [Mul-choice STRING]: launch autotest
 memzone_autotest [Mul-choice STRING]: launch autotest
 ring_autotest [Mul-choice STRING]: launch autotest
 mempool_autotest [Mul-choice STRING]: launch autotest
 mbuf_autotest [Mul-choice STRING]: launch autotest
 timer_autotest [Mul-choice STRING]: launch autotest
 malloc_autotest [Mul-choice STRING]: launch autotest
 memcpy_autotest [Mul-choice STRING]: launch autotest
 hash_autotest [Mul-choice STRING]: launch autotest
 lpm_autotest [Mul-choice STRING]: launch autotest
 debug_autotest [Mul-choice STRING]: launch autotest
 errno_autotest [Mul-choice STRING]: launch autotest
 tailq_autotest [Mul-choice STRING]: launch autotest
 string_autotest [Mul-choice STRING]: launch autotest

然后我们再输入每行的前面字符串,就是指向相应模块的测试;

如输入version_autotest 看一下程序的版本号;

RTE>>version_autotest
Version string: 'RTE 1.3.1r2'
Test OK
RTE>>
嗯,我的dpdk版本是 1.3.1r2 ;


test程序还挺高一条命令交all_autotests ,也就是进行所有的子模块测试,这命令执行起来会让程序运行很长时间;


技术水平有待提高,如果文章有错误的地方希望读者指正,相互交流,互相学习;O(∩_∩)O~

你可能感兴趣的:(intel,dpdk,intel,dpdk,学习交流)