环境信息:
SDK版本信息(LiteOS开发包):
Hi3516EV200R002C05SPC011\01.software\board\Hi3516EV200_SDK_V5.0.1.1
LiteOS版本信息:
version : Huawei LiteOS V200R002C00SPC050B012
open-version : Huawei LiteOS 3.2.3
Iperf 是一个网络性能测试工具。Iperf可以测试最大TCP和UDP带宽性能,具有多种参数和UDP特性,可以根据需要调整,可以报告带宽、延迟抖动和数据包丢失
您可以按照下述流程一步步完成iperf的移植,也可以直接使用6.8.2.5 (就是下方的编译环节)编译。
Iperf源码包可以从下面网址下载“iperf-2.0.5.tar.gz”,版本号为2.0.5。下载地址: https://sourceforge.net/projects/iperf/
运行./configure对iperf进行配置,并生成相关的Makefile文件
修改文件:修改顶层Makefile
修改说明:适配liteos的工具链和LITEOS_FLAGS,增加Makefile进行iperf源码编译,生成库文件。文件内容可参考如下:
# A simple Makefile for lib(libxxx.a)
# By Late Lee(http://www.latelee.org)
include $(LITEOSTOPDIR)/config.mk
INCLUDE_PATH += -I include -I oss_inc/
ifeq ($(LOSCFG_COMPILER_HIMIX100_64), y)
CMNFLAGS:=-Wall -Wpointer-arith -Wundef -Wno-write-strings \
$(LITEOS_ARM_ARCH) -O2 -ffunction-sections -fdata-sections \
-fno-short-enums $(INCLUDE_PATH)
else
CMNFLAGS:=-Wall -Wpointer-arith -Wundef -Wno-write-strings \
-mno-thumb-interwork \
$(LITEOS_ARM_ARCH) -O2 -ffunction-sections -fdata-sections \
-fno-short-enums $(INCLUDE_PATH)
endif
CFLAGS += $(LITEOS_CMACRO) $(CMNFLAGS) -Wstrict-prototypes -fno-builtin
CXXFLAGS := $(LITEOS_CMACRO) $(CMNFLAGS) -Woverloaded-virtual -fno-rtti -fpermissive -fno-builtin -fexceptions
ARFLAGS = cr
LIBOUT = $(BUILD)/iperf
LIB_IPERF = $(OUT)/lib/libiperf.a
all: $(LIBOUT) $(LIB_IPERF)
RM = -rm -rf
LIB_IPERF_CPPSRC = src/Client.cpp \
src/Launch.cpp \
src/List.cpp \
src/Listener.cpp \
src/main.cpp \
src/PerfSocket.cpp \
src/Settings.cpp \
src/Server.cpp
LIB_IPERF_CSRC = src/Extractor.c \
src/ReportCSV.c \
src/ReportDefault.c \
src/Reporter.c \
src/SocketAddr.c \
src/sockets.c \
src/Locale.c \
src/stdio.c \
src/tcp_window_size.c \
src/gnu_getopt.c \
src/gnu_getopt_long.c \
src/iperf_shell.c \
compat/error.c \
compat/string.c \
compat/Thread.c
LIB_IPERF_CSRC += oss_adapt/oss_list.c \
oss_adapt/oss_string.c \
oss_adapt/oss_memfile.c \
oss_adapt/oss_timer.c \
oss_adapt/os_support.c
LIB_IPERF_COBJ = $(patsubst %.c,$(LIBOUT)/%.o,$(LIB_IPERF_CSRC))
LIB_IPERF_CPPOBJ = $(patsubst %.cpp,$(LIBOUT)/%.o,$(LIB_IPERF_CPPSRC))
LIB_IPERF_OBJ = $(LIB_IPERF_COBJ) $(LIB_IPERF_CPPOBJ)
$(LIB_IPERF_OBJ): $(LIBOUT)
$(LIB_IPERF_COBJ): $(LIBOUT)/%.o : %.c
@$(CC) $(CFLAGS) $(LITEOS_INCLUDE) -c $< -o $@
$(LIB_IPERF_CPPOBJ): $(LIBOUT)/%.o : %.cpp
@$(GPP) $(CXXFLAGS) $(LITEOS_INCLUDE) -c $< -o $@
$(LIB_IPERF): $(LIB_IPERF_OBJ)
@$(AR) $(ARFLAGS) $@ $(LIB_IPERF_OBJ)
$(LIBOUT):
mkdir -p $(LIBOUT)/src $(LIBOUT)/compat
mkdir -p $(LIBOUT)/oss_adapt
clean:
@$(RM) $(LIBOUT) $(LIB_IPERF) *.bak *~
.PHONY: all clean
主要修改思路:
完成上述修改的源码包和解压后未经修改的源码包相比,差异patch如下,供参考。
https://download.csdn.net/download/spy_007_/12317835
也可跳过上述修改步骤,直接将.patch文件放到iperf2.0.5源码的根目录下,执行patch 命令:
patch -p2 < iperf-2.0.5.patch 即可
具体编译链接步骤如下:
ifeq ($(LOSCFG_TOOLS_IPERF), y)
LITEOS_LD_OPTS += -uiperf_shellcmd
LITEOS_BASELIB += -liperf
LIB_SUBDIRS += tools/iperf-2.0.5
endif
source "../../tools/iperf-2.0.5/Kconfig"
Debug->Enable a Debug Version->Enable Shell->Enable Iperf-2.0.5
注意,Hi3518ev300的Liteos内核(3.2.3)起始已经删除了对iperf的支持,所以才会有以下额外的移植操作
----------以下为Hi3518ev300 LiteOS内核实际操作的额外笔记---------------------------------------------------------------------------------
Hi3518ev300为了移植iperf所做的改动,参照Hi3516ev100 的内核:
搜索关键词LOSCFG_TOOLS_IPERF
Hi3516ev100:
[root@localhost liteos]#
[root@localhost liteos]# grep -r "LOSCFG_TOOLS_IPERF"
.config:LOSCFG_TOOLS_IPERF=y
tools/menuconfig/sys_config.h:#define __LOSCFG_TOOLS_IPERF__ 1
tools/scripts/module_coupling/module_decouple.sh: echo "LOSCFG_TOOLS_IPERF=y" >> .config
tools/scripts/module_coupling/module_decouple.sh: sed -i "s/LOSCFG_TOOLS_IPERF=y/LOSCFG_TOOLS_IPERF=n/g" .config
tools/iperf-2.0.5/src/iperf_shell.c:#ifdef LOSCFG_TOOLS_IPERF
tools/iperf-2.0.5/iperf-2.0.5.patch:+config LOSCFG_TOOLS_IPERF
tools/iperf-2.0.5/iperf-2.0.5.patch:+#ifdef LOSCFG_TOOLS_IPERF
tools/iperf-2.0.5/Kconfig:config LOSCFG_TOOLS_IPERF
config_hi3516cv300:# LOSCFG_TOOLS_IPERF is not set
build/mk/los_config.mk:ifeq ($(LOSCFG_TOOLS_IPERF), y)
build/mk/los_config.mk: LITEOS_CMACRO += -DLOSCFG_TOOLS_IPERF
[root@localhost liteos]#
[root@localhost liteos]#
Hi3518ev300:
[root@localhost liteos]# grep -r "LOSCFG_TOOLS_IPERF"
tools/iperf-2.0.5/src/iperf_shell.c:#ifdef LOSCFG_TOOLS_IPERF
tools/iperf-2.0.5/iperf-2.0.5.patch:+config LOSCFG_TOOLS_IPERF
tools/iperf-2.0.5/iperf-2.0.5.patch:+#ifdef LOSCFG_TOOLS_IPERF
tools/iperf-2.0.5/Kconfig:config LOSCFG_TOOLS_IPERF
build/mk/los_config.mk:ifeq ($(LOSCFG_TOOLS_IPERF), y)
[root@localhost liteos]#
Hi3518ev300对照上方Hi3516ev100的差异项一项一项去补充好。
最后设备APP项目编译时(gcc编译)应加上 -lstdc++ ,因为iperf里边有一部分是g++编译的
之后iperf测试可参照该篇博客(安装以及使用):
https://www.cnblogs.com/saneri/p/11169926.html
windows下的iperf3打开方式(包括运行时闪退的问题):
https://blog.csdn.net/weixin_43914200/article/details/88966108#%E4%B8%80.%E8%BD%AF%E4%BB%B6%E4%B8%8B%E8%BD%BD
----------注意事项------------------------------------------------------------------------------------------------
server 端和 client 端的iperf版本尽量保持一致,否则可能出现测试异常,
各平台 iperf3 版本下载:https://iperf.fr/iperf-download.php