0

我正在尝试将统一测试框架与 NRF51822 板一起使用,但为了查看统一的输出,我需要重新路由它/管道,以便它在我的计算机上可见。我正在使用 SEGGER RTT 在我的项目中打印,理想情况下 id 将其用于 unity.c 输出。

根据统一

默认情况下,Unitystdout在运行时打印其结果。这在您使用本机编译器进行测试的大多数情况下都可以正常工作。只要它们已stdout路由回命令行,它也适用于某些模拟器。但是,有时模拟器将缺乏对转储结果的支持,或者您出于其他原因希望将结果路由到其他地方。在这些情况下,您应该定义UNITY_OUTPUT_CHAR宏。该宏一次接受一个字符(作为,因为这是最常用int的标准 C 函数的参数类型)。putchar你可以用你喜欢的任何函数调用来替换它。

* Output*     - by default, Unity prints to standard out with putchar.  define UNITY_OUTPUT_CHAR(a) with a different function if

想要的

   /*-------------------------------------------------------
     * Output Method: stdout (DEFAULT)
     *-------------------------------------------------------*/
    #ifndef UNITY_OUTPUT_CHAR
    /* Default to using putchar, which is defined in stdio.h */
    #include <stdio.h>
    #define UNITY_OUTPUT_CHAR(a) (void)putchar(a)
    #else
      /* If defined as something else, make sure we declare it here so it's ready for use */
      #ifndef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION
    extern void UNITY_OUTPUT_CHAR(int);
      #endif
    #endif

我试图定义

#define UNITY_OUTPUT_CHAR(a) SEGGER_RTT_WriteString(0, a)

但是我得到以下信息

> $ make rm -rf _build echo  Makefile Makefile mkdir _build Compiling
> file: system_nrf51.c Compiling file: main.c
> C:/NXTSNS/nRF5_SDK_11.0.0_89a8197/examples/peripheral/blinky/main.c:31:53:
> error: expected declaration specifiers or '...' before numeric
> constant 
> #define UNITY_OUTPUT_CHAR(a) SEGGER_RTT_WriteString(0, a)
>                                                      ^ C:/NXTSNS/Unittesting/unity/src/unity_internals.h:250:13: note: in
> expansion of macro 'UNITY_OUTPUT_CHAR'  extern void
> UNITY_OUTPUT_CHAR(int);
>              ^ Makefile:150: recipe for target '_build/main.o' failed make: *** [_build/main.o] Error 1

我还尝试了在函数中调用 segger 并转换为 char * 的替代方法,如下所示

void print_test(int a){
    SEGGER_RTT_WriteString(0, (char *) a);
}

但不幸的是,当我调用 print_test 时,我没有看到任何输出

我应该如何定义宏以便我可以将输出发送到 segger 或者如果有更合适的替代方案是什么?

4

0 回答 0