简体   繁体   中英

ceedling with MPLABx and XC8

I am starting unit testing using ceedling from Windows Powershell. I have made a lot of progress getting Unity to work with the XC8 compiler. But I have a problem I can't seem to solve. Here is a bit of the build dump.

'xc8-cc -mcpu=PIC16F18325 -gdwarf-3 -D"__PIC16f18325__" -D"__XC8" -D"UNITY_INT_WIDTH=16" -D"UNITY_POINTER_WIDTH=16" -D"CMOCK_MEM_INDEX_TYPE=uint16_t" -D"CMOCK_MEM_PTR_AS_INT=uint16_t" -D"CMOCK_MEM_ALIGN=1" -D"CMOCK_MEM_SIZE=256" -D"UNITY_OUTPUT_COLOR" -D"TEST" -D"UNITY_INCLUDE_CONFIG_H" -D"UNITY_EXCLUDE_SETJMP_H" -D"UNITY_EXCLUDE_MATH_H" -D"UNITY_EXCLUDE_FLOAT" -D"CMOCK_MEM_SIZE=256" -I"C:/Users/timtru/MPLABXProjects/XT_Lock_PIC16F18325.X/vendor/ceedling/vendor/unity/src" -I"C:/Users/timtru/MPLABXProjects/XT_Lock_PIC16F18325.X/vendor/ceedling/vendor/cmock/src" -I"build/ceedling/generated/test/mocks" -I"test" -I"test/source" -I"test/support" -I"source" -I"source/mcc_generated_files" -I"source/mcc_generated_files/docs/doxygen_generator" -I"source/mcc_generated_files/drivers" -I"C:/Program Files/Microchip/xc8/v2.36/pic/include" -I"C:/Program Files/Microchip/xc8/v2.36/pic/include/c90" -I"C:/Program Files/Microchip/xc8/v2.36/pic/include/c99" -I"C:/Program Files/Microchip/xc8/v2.36/pic/include/legacy" -I"C:/Program Files/Microchip/xc8/v2.36/pic/include/proc" -Wl,-Map="build/ceedling/generated/test/out/test_main.map" -o"./build/ceedling/generated/test/out/test_build.elf" build/ceedling/generated/test/out/c/test_main_runner.p1 build/ceedling/generated/test/out/c/test_main.p1 build/ceedling/generated/test/out/c/unity.p1 build/ceedling/generated/test/out/c/mcc.p1 build/ceedling/generated/test/out/c/main.p1 build/ceedling/generated/test/out/c/I2_p0.p1 build/ceedling/generated/test/out/c/process_commands.p1 build/ceedling/generated/test/out/c/cmock.p1 2>&1'
> Produced output:
C:\Program Files\Microchip\xc8\v2.36\pic\sources\c99\pic\__eeprom.c:22:9: error: use of undeclared identifier 'NVMCON1bits'

'NVMCON1bits is declared in pic16f18325.h file in the XC8 install directory-"C:/Program Files/Microchip/xc8/v2.36/pic/include/proc", which seen as the last -I in the xc8-cc argument list. In the IDE MPLAB uses a XC.H file to inform the compiler what processor it is building for. This mechanism caused the correct "processor".h file to be pulled in. <xc.h> necessarily appears in every source file. What is needed (in the project.yml) to get this to work?

# Notes:
# Project.yml


:project:
  :build_root: build/ceedling/generated
  :test_file_prefix: test_
  :which_ceedling: vendor/ceedling
  :use_exceptions: FALSE
  :release_build: FALSE
  :use_test_preprocessor: FALSE
  :use_auxiliary_dependencies: TRUE
  :default_tasks:
    - test:all

:environment:
  - :mcu: PIC16F18325
  - :mplabx_root: "C:/Program Files/Microchip/xc8/v2.36/"
  - :path:
    - "C:/Program Files/Microchip/xc8/v2.36/pic/include/**"
    - "#{ENV['PATH']}"
    - build
    - source/**
    - source/*
    - vendor/ceedling/vendor/unity/src


#:test_build:
#  :use_assembly: TRUE

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



:module_generator:
  :project_root: ./
  :source_root: source/
  :test_root: test/
  
:extension:
  :object: .p1
  :executable: .elf
  :assembly: .S

:paths:
  :test:
    - +:test/**
    - -:test/support
  :source:
    - source/**
    - -:source/mcc_generated_files/docs
    - -:source/mcc_generated_files/examples
  :include:
    - "C:/Program Files/Microchip/xc8/v2.36/pic/include/*"
    - "C:/Program Files/Microchip/xc8/v2.36/pic/include/proc/pic16f18325.h"
  :support:
    - test/support
  :libraries: []

:defines:
  # in order to add common defines:
  #  1) remove the trailing [] from the :common: section
  #  2) add entries to the :common: section (e.g. :test: has TEST defined)
  :commmon: &common_defines
    - __PIC16f18325__
    - __XC8
    - UNITY_INT_WIDTH=16
    - UNITY_POINTER_WIDTH=16
    - CMOCK_MEM_INDEX_TYPE=uint16_t
    - CMOCK_MEM_PTR_AS_INT=uint16_t
    - CMOCK_MEM_ALIGN=1
    - CMOCK_MEM_SIZE=256
  :test:
    - *common_defines
#    - UNITY_INCLUDE_CONFIG_H
    - UNITY_OUTPUT_COLOR #this is just here to make sure it gets removed by ceedling
    - TEST
  :test_preprocess:
    - *common_defines
    - TEST
:unity:
  :defines:
    - UNITY_INCLUDE_CONFIG_H 
    - UNITY_EXCLUDE_SETJMP_H
    - UNITY_EXCLUDE_MATH_H
    - UNITY_EXCLUDE_FLOAT
    
:cmock:
  :mock_prefix: mock_
  :when_no_prototypes: :warn
  :treat_externs: :include
  :enforce_strict_ordering: TRUE
  :fail_on_unexpected_calls: FALSE
  :exclude_setjmp_h: TRUE
  :defines:
    - CMOCK_MEM_SIZE=256
  :plugins:
    - :ignore
    - :ignore_arg
    - :callback
    - :expect_any_args
  :treat_as:
    int8:       INT8
    uint8:      HEX8
    uint16:     HEX16
    uint32:     UINT32
    int8_t:     INT8
    uint8_t:    HEX8
    uint16_t:   HEX16
    uint32_t:   UINT32
    bool:       UINT8

# Add -gcov to the plugins list to make sure of the gcov plugin
# You will need to have gcov and gcovr both installed to make it work.
# For more information on these options, see docs in plugins/gcov
:gcov:
  :reports:
    - HtmlDetailed
  :gcovr:
    :html_medium_threshold: 75
    :html_high_threshold: 90

:tools:
  :release_compiler:
    :name: "Microchip XC8 Compiler"
    :executable: xc8-cc
    :arguments:
      - "-mcpu=#{ENV['MCU']}"
      - -std=c99
      - -O1
      - -Wa,-a
      - -D"$": COLLECTION_DEFINES_RELEASE_AND_VENDOR
      - -I"$": COLLECTION_PATHS_SOURCE_AND_INCLUDE
      - -Iinclude/
      - -o "${2}"
      - -c
      - "${1}"

  :release_assembler:
    :name: "Microchip XC8 Compiler"
    :executable: xc8-cc
    :arguments:
      - "-mcpu=#{ENV['MCU']}"
      - -std=c99
      - -O1
      - -Wa,-a
      - -D"$": COLLECTION_DEFINES_RELEASE_AND_VENDOR
      - -I"$": COLLECTION_PATHS_SOURCE_AND_INCLUDE
      - -o "${2}"
      - -c
      - "${1}"

  :release_linker:
    :name: "Microchip XC8 Linker"
    :executable: xc8-cc
    :arguments:
      - "-mcpu=#{ENV['MCU']}"
      - -gdwarf-3
      - -D"$": COLLECTION_DEFINES_RELEASE_AND_VENDOR
      - -I"$": COLLECTION_PATHS_SOURCE_AND_INCLUDE
      - -Wl,-Map="${3}"
      - -o "${2}"
      - "{'${1}'.split(' ').map { |x| (x.include? '/out/c/') ? (Pathname(x).sub_ext('.p1')).to_s : x }.join(' ') }"
      - "${4}"

  :test_compiler:
    :name: "Microchip XC8 Compiler"
    :executable: xc8-cc
    :arguments:
      - -mcpu=#{ENV['MCU']}
      - -std=c99
      - -O1
      - -Wa,-a
      - -D"$": COLLECTION_DEFINES_TEST_AND_VENDOR
      - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR
      - -Iinclude/
      - -o "${2}"
      - -c
      - "${1}"

  :test_file_preprocessor:
    :name: "Microchip XC8 preprocessor"
    :executable: xc8-cc
    :arguments:
      - -mcpu=#{ENV['MCU']}
      - -std=c99
      - -D"$": COLLECTION_DEFINES_TEST_AND_VENDOR
      - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR
      - "${1}"

  :test_includes_preprocessor:
    :name: "Microchip XC8 includes preprocessor"
    :executable: xc8-cc
    :arguments:
      - -mcpu=#{ENV['MCU']}
      - -std=c99
      - -D"$": COLLECTION_DEFINES_TEST_AND_VENDOR
      - -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR
      - "${1}"

  :test_linker:
    :name: "Microchip XC8 Linker"
    :executable: xc8-cc
    :arguments:
      - -mcpu=#{ENV['MCU']}
      - -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:
    - vendor/ceedling/plugins
  :enabled:
    - stdout_pretty_tests_report
    - module_generator
    - raw_output_report
    - warnings_report

You may found usefull informations on this blog (Ceedling maintainer) : Unit Test How? Registers

Do you have any files in test/support ?

There is a way to test your PIC registers but this require some effort to modify your original PIC header file.

Let me introduce what I did for a dsPIC33 with XC16 this should be very similar for XC8.

I am using a modified p33EP256MC506.h copied from XC16 directory to support where :

  • Added this code at the top because I compile with both XC16 or GCC compiler :
#ifdef TEST_GCC
#define EXTERN 
#else
#define EXTERN extern
#endif
  • Removed each __attribute__(( ...
  • Replaced each extern to EXTERN
  • Added this code :
/* ---------------------------------------------------------- */
/* Some useful macros for inline assembler instructions       */
/* ---------------------------------------------------------- */
    
#define Nop()    ; //__builtin_nop()
#define ClrWdt() ; //__builtin_clrwdt()
#define Sleep()  ; //__builtin_pwrsav(0)
#define Idle()   ; //__builtin_pwrsav(1)

You may also have to add support directory to include :

:paths:
  :test:
    - +:test/**
    - -:test/support
  :source:
    - src/**
  :support:
    - test/support  
  :include:
    - test/support 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM