diff --git a/thirdparty/bcunit/HPKBUILD b/thirdparty/bcunit/HPKBUILD new file mode 100755 index 0000000000000000000000000000000000000000..86d5fc562b10ed686b215ccb4b10ae64633d748c --- /dev/null +++ b/thirdparty/bcunit/HPKBUILD @@ -0,0 +1,80 @@ +# Contributor: xucaiming <719260170@qq.com> +# Maintainer: xucaiming <719260170@qq.com> + +pkgname=bcunit +pkgver=5.2.62 +pkgrel=0 +pkgdesc="BcUnit is a Unit testing framework" +url="https://github.com/BelledonneCommunications/bcunit" +archs=("armeabi-v7a" "arm64-v8a") +license=("LGPL-2.0") +depends=() +makedepends=() +source="https://github.com/BelledonneCommunications/$pkgname/archive/refs/tags/$pkgver.tar.gz" +buildtools="cmake" + +autounpack=true +downloadpackage=true +patchflag=true + +builddir=${pkgname}-${pkgver} +packagename=${pkgname}-${pkgver}.tar.gz + +source envset.sh + +prepare() { + if $patchflag + then + cd $builddir + # 编译Test时, 链接和头文件包含缺失 + patch -p1 < `pwd`/../bcunit_oh_pkg.patch + # patch只需要打一次,关闭打patch + patchflag=false + cd $OLDPWD + fi + mkdir -p $builddir/$ARCH-build + if [ $ARCH == "arm64-v8a" ];then + setarm64ENV + elif [ $ARCH == "armeabi-v7a" ];then + setarm32ENV + else + echo "${ARCH} not support" + return -1 + fi +} + +build() { + cd $builddir + ${OHOS_SDK}/native/build-tools/cmake/bin/cmake "$@" -DENABLE_TEST=ON \ + -DOHOS_ARCH=$ARCH -B$ARCH-build -S./ -L > `pwd`/$ARCH-build/build.log 2>&1 + make -j4 -C $ARCH-build VERBOSE=1 >> `pwd`/$ARCH-build/build.log 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +package() { + cd $builddir + make -C $ARCH-build install VERBOSE=1 >> `pwd`/$ARCH-build/build.log 2>&1 + cd $OLDPWD +} + +check() { + if [ $ARCH == "arm64-v8a" ];then + unsetarm64ENV + elif [ $ARCH == "armeabi-v7a" ];then + unsetarm32ENV + else + echo "${ARCH} not support" + return -1 + fi + + echo "The test must be on an OpenHarmony device!" + # cd $builddir/$ARCH-build/BCUnit/Sources/Test + # ./test_bcunit +} + +# 清理环境 +cleanbuild(){ + rm -rf ${PWD}/$builddir +} diff --git a/thirdparty/bcunit/HPKCHECK b/thirdparty/bcunit/HPKCHECK new file mode 100755 index 0000000000000000000000000000000000000000..7785c7f3771d342b05b5547621e192a9bcfc82a6 --- /dev/null +++ b/thirdparty/bcunit/HPKCHECK @@ -0,0 +1,15 @@ +# Contributor: xucaiming <719260170@qq.com> +# Maintainer: xucaiming <719260170@qq.com> + +source HPKBUILD > /dev/null 2>&1 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log + +openharmonycheck() { + res=0 + cd $builddir/$ARCH-build/BCUnit/Sources/Test + ./test_bcunit > ${logfile} 2>&1 + res=$? + cd $OLDPWD + + return $res +} diff --git a/thirdparty/bcunit/OAT.xml b/thirdparty/bcunit/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..cec1f54d4b10ba18ec5f6af1dd1bb5af2f5dddc2 --- /dev/null +++ b/thirdparty/bcunit/OAT.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/thirdparty/bcunit/README.OpenSource b/thirdparty/bcunit/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..37eb373e0e886a67f4330edd036dba7daf0b7e9a --- /dev/null +++ b/thirdparty/bcunit/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "bcunit", + "License": "LGPL-2.0 license", + "License File": "LICENSES", + "Version Number": "5.2.62", + "Owner": "cmxud@isoftstone.com", + "Upstream URL": "https://github.com/BelledonneCommunications/bcunit/archive/refs/tags/5.2.62.tar.gz", + "Description": "BcUnit is a Unit testing framework" + } +] diff --git a/thirdparty/bcunit/README_zh.md b/thirdparty/bcunit/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..7350b44dc383ced954eed4afbc27046a8dd19259 --- /dev/null +++ b/thirdparty/bcunit/README_zh.md @@ -0,0 +1,11 @@ +# bcunit三方库说明 +## 功能简介 +bcunit是一个单元测试框架。 +## 使用约束 +- IDE版本:DevEco Studio 3.1 Release +- SDK版本:ohos_sdk_public 4.0.8.1 (API Version 10 Release) +- 三方库版本:5.2.62 +- 当前适配的功能:bcunit是一个C语言单元测试框架 + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/bcunit/SHA512SUM b/thirdparty/bcunit/SHA512SUM new file mode 100755 index 0000000000000000000000000000000000000000..49dbdadea4dc49618a5e6858d7f5201c2a8c7097 --- /dev/null +++ b/thirdparty/bcunit/SHA512SUM @@ -0,0 +1,2 @@ +a833aa18738e0abef271769338251d8f2a2371aeacb1fa9f93ee63065936ca5d546db0f75ea64218303a94c34ee7125fcf75fdd91e922e5b4b5b58e79ccb7d3d bcunit-5.2.62.tar.gz +6870e6a0f3a9da43f6411e392d8fff4869edcf55e0a6b81b780e89c7fae63f0e63e30ba3afa9619ece90f47c40d4e5fda67f4d5ab7a0f3656ddc78c0138ffd14 bcunit_oh_pkg.patch diff --git a/thirdparty/bcunit/bcunit_oh_pkg.patch b/thirdparty/bcunit/bcunit_oh_pkg.patch new file mode 100644 index 0000000000000000000000000000000000000000..5d54501b9edc457dd26ea2e05dd44466884108d7 --- /dev/null +++ b/thirdparty/bcunit/bcunit_oh_pkg.patch @@ -0,0 +1,14 @@ +--- a/BCUnit/Sources/CMakeLists.txt ++++ b/BCUnit/Sources/CMakeLists.txt +@@ -207,6 +207,10 @@ if(ENABLE_TEST) + add_library(bcunit_test STATIC ${FRAMEWORK_SOURCE_FILES}) + target_compile_definitions(bcunit_test PUBLIC MEMTRACE BCUNIT_BUILD_TESTS BCUNIT_DO_NOT_DEFINE_UNLESS_BUILDING_TESTS) + target_include_directories(bcunit_test PUBLIC Test) +- ++ target_include_directories(bcunit_test PUBLIC ++ $ ++ $ ++ ) ++ target_link_libraries(bcunit_test bcunit) + add_subdirectory(Test) + endif() diff --git a/thirdparty/bcunit/docs/hap_integrate.md b/thirdparty/bcunit/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..3d8aa3a1e2039a3f1b0cbc7ec33b6205b08ecfaa --- /dev/null +++ b/thirdparty/bcunit/docs/hap_integrate.md @@ -0,0 +1,90 @@ +# bcunit 集成到应用hap + +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +## 开发环境 + +- ubuntu20.04 +- [OpenHarmony3.2Release镜像](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fdayu200_standard_arm32.tar.gz) +- [ohos_sdk_public 4.0.8.1 (API Version 10 Release)](https://gitee.com/link?target=http%3A%2F%2Fdownload.ci.openharmony.cn%2Fversion%2FMaster_Version%2FOpenHarmony_4.0.8.1%2F20230608_091058%2Fversion-Master_Version-OpenHarmony_4.0.8.1-20230608_091058-ohos-sdk-public.tar.gz) +- [DevEco Studio 3.1 Release](https://gitee.com/link?target=https%3A%2F%2Fcontentcenter-vali-drcn.dbankcdn.cn%2Fpvt_2%2FDeveloperAlliance_package_901_9%2F81%2Fv3%2FtgRUB84wR72nTfE8Ir_xMw%2Fdevecostudio-windows-3.1.0.501.zip%3FHW-CC-KV%3DV1%26HW-CC-Date%3D20230621T074329Z%26HW-CC-Expire%3D315360000%26HW-CC-Sign%3D22F6787DF6093ECB4D4E08F9379B114280E1F65DA710599E48EA38CB24F3DBF2) +- [准备三方库构建环境](../../../lycium/README.md#1编译环境准备) +- [准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + +## 编译三方库 + +- 下载本仓库 + + ``` + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ```shell + tpc_c_cplusplus/thirdparty/bcunit #三方库bcunit的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── HPKCHECK #自动化测试脚本 + ├── SHA512SUM #三方库校验文件 + ├── OAT.xml #OAT开源审查文本 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── bcunit_oh_pkg.patch #补丁文件 + ├── README_zh.md + ``` + +- 在lycium目录下编译三方库 + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + + ``` + cd lycium + ./build.sh bcunit + ``` + + +- 三方库头文件及生成的库 + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ``` + bcunit/arm64-v8a bcunit/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库拷贝到该目录下,如下图所示 +   + + ![thirdparty_install_dir](pic/bcunit_install_dir.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + + ```shell + #将三方库加入工程中 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/bcunit/${OHOS_ARCH}/lib/libbcunit.a) + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/bcunit/${OHOS_ARCH}/include) + ``` + + ![bcunit_usage](pic/bcunit_usage.png) + +## 测试三方库 + +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + +进入到构建目录,执行如下命令 +``` +cd /BCUnit/Sources/Test +./test_bcunit +``` +(arm64-v8a-build为构建64位的目录,armeabi-v7a-build为构建32位的目录) + + ![bcunit_test](pic/bcunit_test.png) + +## 参考资料 + +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) diff --git a/thirdparty/bcunit/docs/pic/bcunit_install_dir.png b/thirdparty/bcunit/docs/pic/bcunit_install_dir.png new file mode 100644 index 0000000000000000000000000000000000000000..adfd7fd7a8e1df7f47b530614db366c5ee884941 Binary files /dev/null and b/thirdparty/bcunit/docs/pic/bcunit_install_dir.png differ diff --git a/thirdparty/bcunit/docs/pic/bcunit_test.png b/thirdparty/bcunit/docs/pic/bcunit_test.png new file mode 100644 index 0000000000000000000000000000000000000000..b6e5da0814d047f4329d20f57ddb6b629c4a14df Binary files /dev/null and b/thirdparty/bcunit/docs/pic/bcunit_test.png differ diff --git a/thirdparty/bcunit/docs/pic/bcunit_usage.png b/thirdparty/bcunit/docs/pic/bcunit_usage.png new file mode 100644 index 0000000000000000000000000000000000000000..40e79aa1903fd8f280f061c1db379f448a20f943 Binary files /dev/null and b/thirdparty/bcunit/docs/pic/bcunit_usage.png differ