使用 XC32 与 Ceedling 进行嵌入式 C 单元测试 - 无法构建

问题描述 投票:0回答:1

我正在尝试使用 Ceedling 为自己设置测试驱动开发工作流程 - https://github.com/ThrowTheSwitch/Ceedling/blob/master/docs/CeedlingPacket.md

我的项目使用的是PIC32MX575F256H。目前,该项目没有我自己编写的任何代码。

我的 Ceedling YAML 脚本如下。我还提供了当我尝试运行它时得到的 shell 输出的副本。

    \[12:18:12\] user@mypc:\~/MPLAB$ ceedling --trace test:all

    Test 'test_main.c'
    -

    In file included from /opt/microchip/xc32/v4.35/pic32mx/include/xc.h:376,
         from src/config/default/device.h:47,
         from src/config/default/peripheral/gpio/plib_gpio.h:45,
         from src/config/default/definitions.h:52,
         from test/test_main.c:10:
    /opt/microchip/xc32/v4.35/pic32mx/include/proc/PIC32MX/p32mx575f256h.h:29106:10: fatal error: proc/ppic32mx.h: No such file or directory
    29106 | #include "proc/ppic32mx.h"
          |     ^\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~
    compilation terminated.
    ERROR: Shell command failed.

    > Shell executed command:
    > 'gcc -E -I"/home/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src" -I"/home/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/vendor/cmock/src" -I"build/test/mocks" -I"test" -I"test/simulation" -I"test/support" -I"src" -I"src/config" -I"src/config/default" -I"src/config/default/PIC32MX_DFP" -I"src/config/default/default.mhc" -I"src/config/default/peripheral" -I"src/config/default/peripheral/clk" -I"src/config/default/peripheral/evic" -I"src/config/default/peripheral/gpio" -I"src/config/default/stdio" -I"/opt/microchip/xc32/v4.35/pic32mx/include" -D__PIC32MX_\_ -D__32MX575F256H_\_ -D__LANGUAGE_C_\_ -DUNITY_INT_WIDTH=32 -DCMOCK_MEM_INDEX_TYPE=uint32_t -DCMOCK_MEM_PTR_AS_INT=uint32_t -DCMOCK_MEM_SIZE=2056 -DTEST -D__PIC32MX_\_ -D__32MX575F256H_\_ -D__LANGUAGE_C_\_ -DTEST -DGNU_COMPILER "test/test_main.c" -o "build/test/preprocess/files/test_main.c"'
    > And exited with status: \[1\].

    rake aborted!
    ShellExecutionException: ShellExecutionException
    /home/user/.rbenv/versions/3.0.0/bin/ceedling:23:in `load' /home/user/.rbenv/versions/3.0.0/bin/ceedling:23:in `\<main\>'
    Tasks: TOP =\> test:all
    (See full trace by running task with --trace)
    ERROR: Ceedling Failed

   :project:
        :use_exceptions: FALSE
        :use_test_preprocessor: TRUE
        :use_auxiliary_dependencies: TRUE
        :build_root: build
        #  :release_build: TRUE
        :test_file_prefix: test_
        :which_ceedling: gem
        :ceedling_version: 0.31.1
        :default_tasks:
        - test:all

    #:test_build:
        #  :use_assembly: TRUE

    #:release_build:
        #  :output: MyApp.out
        #  :use_assembly: FALSE

    :environment:
        - :mcu:  32MX575F256L
        - :freq: 80000000UL

    :extension:
        :executable: .elf

    :paths:
        :test:
        - +:test/**
        - -:test/support
    :source:
        - src/**
    :support:
        - test/support
    :libraries: []
    :include:
        - "/opt/microchip/xc32/v4.35/pic32mx/include/"

    :defines:

        :common: &common_defines 
            - __PIC32MX__
            - __32MX575F256H__
            - __LANGUAGE_C__
        :test:
            - *common_defines
            - UNITY_INT_WIDTH=32
            - CMOCK_MEM_INDEX_TYPE=uint32_t
            - CMOCK_MEM_PTR_AS_INT=uint32_t
            - CMOCK_MEM_SIZE=2056
            - TEST
         :test_preprocess:
            - *common_defines
            - TEST

    :cmock:
        :mock_prefix: mock_
        :when_no_prototypes: :warn
        :enforce_strict_ordering: TRUE
        :plugins:
            - :ignore
            - :callback
        :treat_as:
            uint8:    HEX8
            uint16:   HEX16
            uint32:   UINT32
            int8:     INT8
            bool:     UINT8

    :gcov:
        :reports:
        - HtmlDetailed
    :gcovr:
        :html_medium_threshold: 75
        :html_high_threshold: 90

    :libraries:
        :placement: :end
        :flag: "-l${1}"
        :path_flag: "-L ${1}"
        :system: []    # for example, you might list 'm' to grab the math library
        :test: []
        :release: []

    :tools:
        :test_compiler:
            :executable: "/opt/microchip/xc32/v4.35/bin/xc32-gcc"
            :arguments:
               - -mprocessor=32MX575F256L
               - -x c
               - -c
               - "${1}"
               - -o "${2}"
               - -D$: COLLECTION_DEFINES_TEST_AND_VENDOR
               - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR
               - -Iinclude/
               - -Wall
        :test_linker: 
            :executable: "/opt/microchip/xc32/v4.35/bin/xc32-gcc"
            :arguments:
                - -mprocessor=32MX575F256L
                - -gdwarf-3
                - -D"$": COLLECTION_DEFINES_TEST_AND_VENDOR
                - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR
                - -Wl,-Map="${3}"
                - -o"./build/ceedling/generated/test/out/test_build.elf"
                - "{'${1}'.split(' ').map { |x| (x.include? '/out/c/') ? (Pathname(x).sub_ext('.p1')).to_s : x }.join(' ') }"
                - "${4}"
   
            
    :test_fixture:
        :executable: ruby
        :name: "Microchip simulator test fixture"
        :stderr_redirect: :win #inform Ceedling what model of $stderr capture to use
        :arguments:
            - test/simulation/sim_test_fixture.rb
                   

    :plugins:
        :load_paths:
            - "#{Ceedling.load_path}"
        :enabled:
            - stdout_pretty_tests_report
            - module_generator

当我尝试通过 MPLAB X IDE 时,我的项目构建正常;但是,我不太熟悉直接从命令行调用编译器,并且无法让事情正常工作。据我所知,我的 YAML 中的包含内容应该涵盖丢失的文件,但显然这没有发生。

我已尝试遵循 tihs 指南,但它似乎没有解决我的问题:https://github.com/crespum/Ceedling-PIC32

unit-testing embedded ceedling xc32
1个回答
0
投票

我自己不是 Ceedling 方面的专家,但我会尝试指出一些引起我注意的事情:

  • 如果我没记错的话, :test_fixture: 是 :tools: 的一部分,所以将其放置在与 test_linker 和 test_compiler 类似的位置。

  • ceedling paths:include 将显示所有包含的路径。

  • 我没有看到您在 project.yml 文件中的任何位置包含 proc/ 。如果它位于该路径的更深处,请尝试使用 /opt/microchip/xc32/v4.35/pic32mx/include/** (注意 ** ),以便它知道更深入。

  • 您还可以给Ceedling一个路径(在环境下:path:)来查找编译器/链接器等,这样您就不必在工具中使用可执行文件的路径。

附注Ceedling 坚持使用 gcc,因为它是默认的链接器/编译器,这意味着你的工具部分不正确,它根本找不到 xc32-gcc。

© www.soinside.com 2019 - 2024. All rights reserved.