测试

  1. 搭建OpenHarmony环境 以Hi3516DV300为例,编译出OpenHarmony镜像,烧写到开发板,相关操作可参考快速入门小型系统部分。

进入系统如下所示:

图1 OpenHarmony启动成功界面

  1. 挂载nfs目录,将表2中test目录下cctest可执行文件放入nfs目录

  2. 执行用例 该库采用非交叉编译时用例是通过make test执行,CMake会有相关的执行结果统计;交叉编译时无法使用该方法,因此可直接执行生成的测试文件完成测试。

        cd nfs
        ./cctest --list
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

上述命令执行结果部分展示:

        test-bignum/Assign<
        test-bignum/ShiftLeft<
        test-bignum/AddUInt64<
        test-bignum/AddBignum<
        test-bignum/SubtractBignum<
        test-bignum/MultiplyUInt32<
        test-bignum/MultiplyUInt64<
        test-bignum/MultiplyPowerOfTen<
        test-bignum/DivideModuloIntBignum<
        test-bignum/Compare<
        test-bignum/PlusCompare<
        test-bignum/Square<
        test-bignum/AssignPowerUInt16<
        test-bignum-dtoa/BignumDtoaVariousDoubles<
        test-bignum-dtoa/BignumDtoaShortestVariousFloats<
        test-bignum-dtoa/BignumDtoaGayShortest<
        test-bignum-dtoa/BignumDtoaGayShortestSingle<
        test-bignum-dtoa/BignumDtoaGayFixed<
        test-bignum-dtoa/BignumDtoaGayPrecision<
        test-conversions/DoubleToShortest<
        test-conversions/DoubleToShortestSingle<
        ...
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}"> class="hide-preCode-box">
        ./cctest test-bignum
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

测试结果如下则表示通过:

        Ran 13 tests.
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

将该库编译添加到OpenHarmony工程中

  1. 复制库到OpenHarmony工程中 拷贝已经能够成功交叉编译的库到OpenHarmony的third_party目录,为了不修改要移植的三方库目录下的BUILD.gn文件,再添加一层目录放置新增的gn转CMake编译适配文件,新增的文件有BUILD.gn、build_thirdparty.py、 config.gni,新增后的目录结构如下所示。

表3 添加到工程后的目录结构

class="table-box">
名称描述
OpenHarmony/third_party/double-conversion/BUILD.gn将三方库加入工程的gn适配文件
OpenHarmony/third_party/double-conversion/build_thirdparty.pyGN调用shell命令脚本文件,由上面GN文件将相关命令传入,实现GN转CMake
OpenHarmony/third_party/double-conversion/config.gni三方库编译配置文件,可修改该文件来配置用例是否参与构建等
OpenHarmony/third_party/double-conversion/double-conversion/要移植的三方库目录
  1. 添加gn到CMake适配文件
        import("config.gni")
        group("double-conversion") {
            if (ohos_build_thirdparty_migrated_from_fuchisa == true) {
                deps = [":make"]
            }
        }
        if (ohos_build_thirdparty_migrated_from_fuchisa == true) {
            action("make") {
                script = "//third_party/double-conversion/build_thirdparty.py"
                outputs = ["$root_out_dir/log_dc.txt"]
                exec_path = rebase_path(rebase_path("./build", ohos_third_party_dir))
                command = "rm * .* -rf && $CMAKE_TOOLS_PATH/cmake .. $CMAKE_FLAG $CMAKE_TOOLCHAIN_FLAG && make -j"
                args = [
                    "--path=$exec_path",
                    "--command=${command}"
                ]
            }
        }
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}"> class="hide-preCode-box">
        #CMAKE_FLAG: config compile feature
        CMAKE_FLAG = "-DBUILD_TESTING=ON -DCMAKE_CXX_STANDARD=11"

        #toolchain:follow up-layer,depend on $ohos_build_compiler
        if (ohos_build_compiler == "clang") {
            CMAKE_TOOLCHAIN_FLAG = "-DOHOS_SYSROOT_PATH=${root_out_dir}sysroot"
        } else {
            CMAKE_TOOLCHAIN_FLAG = ""
        }

        #CMake tools path,no need setting if this path already joined to $PATH.
        CMAKE_TOOLS_PATH = "setting CMake tools path..."
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
        import os
        import sys
        from subprocess import Popen
        import argparse
        import shlex

        def cmd_exec(command):
            cmd = shlex.split(command)
            proc = Popen(cmd)
            proc.wait()
            ret_code = proc.returncode
            if ret_code != 0:
                raise Exception("{} failed, return code is {}".format(cmd, ret_code))

        def main():
            parser = argparse.ArgumentParser()
            parser.add_argument('--path', help='Build path.')
            parser.add_argument('--command', help='Build command.')
            parser.add_argument('--enable', help='enable python.', nargs='*')
            args = parser.parse_args()

            if args.enable:
                if args.enable[0] == 'false':
                  return

            if args.path:
                curr_dir = os.getcwd()
                os.chdir(args.path)
                if args.command:
                    if '&&' in args.command:
                        command = args.command.split('&&')
                        for data in command:
                          cmd_exec(data)
                  else:
                      cmd_exec(args.command)
              os.chdir(curr_dir)

         if __name__ == '__main__':
            sys.exit(main())
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}"> class="hide-preCode-box">

在//build/lite/ohos_var.gni文件中添加下列配置:

        declare_args() {
            ohos_build_thirdparty_migrated_from_fuchisa = true
         }
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
  1. 编译构建 手动单独构建:

执行下列命令

    hb build -T //third_party/double-conversion:double-conversion
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

编译成功则build目录下会生成静态库文件和测试用例

如果大家想更加深入的学习 OpenHarmony(鸿蒙南向) 开发的全栈内容,不妨可以参考以下相关学习文档进行学习,助你快速提升自己:

OpenHarmony 开发环境搭建:https://qr18.cn/CgxrRy

《OpenHarmony源码解析》:https://qr18.cn/CgxrRy

系统架构分析:https://qr18.cn/CgxrRy

OpenHarmony 设备开发学习手册:https://qr18.cn/CgxrRy

在这里插入图片描述

OpenHarmony面试题(内含参考答案):https://qr18.cn/CgxrRy

写在最后

data-report-view="{"mod":"1585297308_001","spm":"1001.2101.3001.6548","dest":"https://blog.csdn.net/maniuT/article/details/140834275","extend1":"pc","ab":"new"}">> id="blogExtensionBox" style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box"> class="blog_extension blog_extension_type2" id="blog_extension"> class="extension_official" data-report-click="{"spm":"1001.2101.3001.6471"}" data-report-view="{"spm":"1001.2101.3001.6471"}"> class="blog_extension_card_left"> class="blog_extension_card_cont"> 鸿蒙开发学习资料领取!!! class="blog_extension_card_cont_r"> 微信名片
注:本文转载自blog.csdn.net的沧海一笑-dj的文章"https://blog.csdn.net/dengjin20104042056/article/details/95811760"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接

评论记录:

未查询到任何数据!