1

我一直在尝试将Unity 测试框架集成到 Keil 版本 5 中,自然我遇到了很多问题和错误并且能够解决很多问题,现在我遇到了一个错误,我希望得到您的支持。

一个简短的总结:

这是我的论文项目,它是嵌入式软件测试,实施团队正在使用 Keil uvision 5 以及使用 STM32CubeMx 生成的代码框架和配置,用于在我的大学开发自动驾驶汽车项目。

环境

OS: Windows 10
IDE-Version:
µVision V5.24.2.0
Tool Version Numbers:
Toolchain:        MDK-ARM Professional  Version: 5.24.1
Toolchain Path:    C:\Keil_v5\ARM\ARMCC\Bin
C Compiler:         Armcc.exe        V5.06 update 5 (build 528)
Assembler:          Armasm.exe        V5.06 update 5 (build 528)
Linker/Locator:     ArmLink.exe        V5.06 update 5 (build 528)
Library Manager:    ArmAr.exe        V5.06 update 5 (build 528)
Hex Converter:      FromElf.exe        V5.06 update 5 (build 528)
CPU DLL:               SARMCM3.DLL          V5.24.1
Dialog DLL:         DCM.DLL              V1.16.0.0
Target DLL:             STLink\ST-LINKIII-KEIL_SWO.dll      V3.0.1.0
Dialog DLL:         TCM.DLL              V1.32.0.0
Practice board: STM32F446ZETx

该方法

我计划通过使用 makefile 来集成 Unity FW,以在 Keil 提供的预构建选项中编译和运行测试。现在我正在尝试使用 Keil 外部的命令行使 makefile 工作,一旦它工作,我相信使用 Keil 预构建选项中的 make 命令运行它会很容易。我按照本教程创建了 makefile http://www.throwtheswitch.org/build/make

我通过添加适当的 armcc 和 armlinker 来编辑 makefile

结构

以下是使用 STM32CubeMx 创建的 TIM10 定时器的 Blinky 项目的示例结构,并将 Unity FW 手动添加到文件夹中

--root
----Drivers
--------CMSIS --> "Drivers related files"
--------STM32F4xx_HAL-Driver --> "Drivers related files"
----Inc
---------gpio.h
---------main.h
---------stm32f4xx_hal_config.h
---------stm32f4xx_it.h
---------tim.h
----MDK-ARM
---------"Other STM32 related folders and files"
----Src
---------gpio.c
---------main.c
---------stm32f4xx_hal_msp.c
---------stm32f4xx_hal_config.c
---------stm32f4xx_it.c
---------tim.c
----Unity
---------build
-------------depends --> "autogenerated by makefile"
-------------objs --> "autogenerated by makefile"
-------------results --> "autogenerated by makefile"
-------------testing --> "autogenerated by makefile"
-------------TIM10_LED_1_Ceedling_try1.map
---------src
-------------stm32f4xx_hal.h
-------------unity_internals.h
-------------unity.c
-------------unity.h
---------test
-------------Testgpio.c
--.mxproject
--makefile
--mx.scratch
--TIM10_LED_1_Ceedling_try1.ioc

生成文件

ifeq ($(OS),Windows_NT)
  ifeq ($(shell uname -s),) # not in a bash-like shell
    CLEANUP = del /F /Q
    MKDIR = mkdir
  else # in a bash-like shell, like msys
    CLEANUP = rm -f
    MKDIR = mkdir -p
  endif
    TARGET_EXTENSION=exe
else
    CLEANUP = rm -f
    MKDIR = mkdir -p
    TARGET_EXTENSION=out
endif

.PHONY: clean
.PHONY: test

PATHU = Unity/src/
PATHS = Src/
PATHI = Unity/src/
PATHI2 = Inc
PATHI3 = Drivers/STM32F4xx_HAL_Driver/Inc
PATHI4 = Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
PATHI5 = Drivers/CMSIS/Device/ST/STM32F4xx/Include
PATHI6 = Drivers/CMSIS/Include
PATHT = Unity/test/
PATHB = Unity/build/testing/
PATHD = Unity/build/depends/
PATHO = Unity/build/objs/
PATHR = Unity/build/results/

BUILD_PATHS = $(PATHB) $(PATHD) $(PATHO) $(PATHR)

SRCT = $(wildcard $(PATHT)*.c)

COMPILE=armcc -c --cpu Cortex-M4.fp -D__MICROLIB -g -O3 --apcs=interwork --split_sections
LINK=armlink --library_type=microlib --libpath="C:\Keil_v5\ARM\ARMCC\lib" --strict --scatter "MDK-ARM\TIM10_LED_1_Ceedling_try1\TIM10_LED_1_Ceedling_try1.sct" --diag_suppress=L6329 --summary_stderr --info summarysizes --map --xref --callgraph --symbols --info sizes --info totals --info unused --info veneers --list "TIM10_LED_1_Ceedling_try1.map" -o "MDK-ARM\TIM10_LED_1_Ceedling_try1\TIM10_LED_1_Ceedling_try1.axf"
DEPEND=armcc --no_depend_system_headers --depend_dir=$(PATHD)
CFLAGS=-I. -I$(PATHU) -I$(PATHS) -I$(PATHI) -I$(PATHI2) -I$(PATHI3) -I$(PATHI4) -I$(PATHI5) -I$(PATHI6)

RESULTS = $(patsubst $(PATHT)Test%.c,$(PATHR)Test%.txt,$(SRCT) )

PASSED = `grep -s PASS $(PATHR)*.txt`
FAIL = `grep -s FAIL $(PATHR)*.txt`
IGNORE = `grep -s IGNORE $(PATHR)*.txt`

test: $(BUILD_PATHS) $(RESULTS)
    @echo "-----------------------\nIGNORES:\n-----------------------"
    @echo "$(IGNORE)"
    @echo "-----------------------\nFAILURES:\n-----------------------"
    @echo "$(FAIL)"
    @echo "-----------------------\nPASSED:\n-----------------------"
    @echo "$(PASSED)"
    @echo "\nDONE"

$(PATHR)%.txt: $(PATHB)%.$(TARGET_EXTENSION)
    -./$< > $@ 2>&1

$(PATHB)Test%.$(TARGET_EXTENSION): $(PATHO)Test%.o $(PATHO)%.o $(PATHU)unity.o $(PATHD)Test%.d
    $(LINK) $@ $^

$(PATHO)%.o:: $(PATHT)%.c
    $(COMPILE) $(CFLAGS) $< -o $@

$(PATHO)%.o:: $(PATHS)%.c
    $(COMPILE) $(CFLAGS) $< -o $@

$(PATHO)%.o:: $(PATHU)%.c $(PATHU)%.h
    $(COMPILE) $(CFLAGS) $< -o $@

$(PATHD)%.d:: $(PATHT)%.c
    $(DEPEND) $@ $<

$(PATHB):
    $(MKDIR) $(PATHB)

$(PATHD):
    $(MKDIR) $(PATHD)

$(PATHO):
    $(MKDIR) $(PATHO)

$(PATHR):
    $(MKDIR) $(PATHR)

clean:
    $(CLEANUP) $(PATHO)*.o
    $(CLEANUP) $(PATHB)*.$(TARGET_EXTENSION)
    $(CLEANUP) $(PATHR)*.txt

.PRECIOUS: $(PATHB)Test%.$(TARGET_EXTENSION)
.PRECIOUS: $(PATHD)%.d
.PRECIOUS: $(PATHO)%.o
.PRECIOUS: $(PATHR)%.txt

电流输出和误差

$ makecc -I. -IUnity/src/ -ISrc/ -IUnity/src/ -IInc -IDrivers/STM32F4xx_HAL_Driver/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32F4xx/Include -IDrivers/CMSIS/Include   -c -o Unity/src/unity.o Unity/src/unity.c
armcc --no_depend_system_headers --depend_dir=Unity/build/depends/ Unity/build/depends/Testgpio.d Unity/test/Testgpio.c
Error: C4065E: type of input file 'Unity/build/depends/Testgpio.d' unknown

make: *** [makefile:74: Unity/build/depends/Testgpio.d] Error 1
rm Unity/src/unity.o

更新——简单的makefile来测试依赖错误

SRC = $(wildcard *.c)
TAR = $(SRC:.c=.d)
DEPEND=armcc --no_depend_system_headers

all: $(TAR)

%.d: %.c
    $(DEPEND) $@ $<

不幸的是它回来了armcc --no_depend_system_headers test.d test.c Error: C4065E: type of input file 'test.d' unknow

但是当将编译器和标志更改为

SRC = $(wildcard *.c)
TAR = $(SRC:.c=.d)
DEPEND=gcc -MM -MG -MF

all: $(TAR)

%.d: %.c
    $(DEPEND) $@ $<

它工作并且 test.d 是从 test.c 创建的——所有文件都在同一个文件夹中

更新

在检查文档后,我设法让 armcc 工作,我更新了我的 makefile,如下所示:

SRC = $(wildcard *.c)
TAR = $(SRC:.c=.d)
DEPEND=armcc --no_depend_system_headers --ignore_missing_headers --md --depend

all: $(TAR)

%.d: %.c
    $(DEPEND) $@ $<

将makefile和源文件放在同一个文件夹中,它可以正常工作。

现在,当返回到主 makefile 并将 DEPEND 标志更新为以下

armcc --no_depend_system_headers --ignore_missing_headers --md --depend

它返回了一个不同的错误,这与 armlink 有关,我不知道过程是如何进行的,首先触发的是什么,哪个取决于另一个,但是当我现在运行 make 时,事实仍然存在,它给出了以下错误:

$ make
cc -I. -IUnity/src/ -ISrc/ -IUnity/src/ -IInc -IDrivers/STM32F4xx_HAL_Driver/Inc -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32F4xx/Include -IDrivers/CMSIS/Include   -c -o Unity/src/unity.o Unity/src/unity.c
armlink --library_type=microlib --libpath="C:\Keil_v5\ARM\ARMCC\lib" --strict --scatter "MDK-ARM\TIM10_LED_1_Ceedling_try1\TIM10_LED_1_Ceedling_try1.sct" --diag_suppress=L6329 --summary_stderr --info summarysizes --map --xref --callgraph --symbols --info sizes --info totals --info unused --info veneers --list "TIM10_LED_1_Ceedling_try1.map" -o "MDK-ARM\TIM10_LED_1_Ceedling_try1\TIM10_LED_1_Ceedling_try1.axf" Unity/build/testing/Testgpio.exe Unity/build/objs/Testgpio.o Unity/build/objs/gpio.o Unity/src/unity.o
Fatal error: L6002U: Could not open file Unity/build/testing/Testgpio.exe: No such file or directory
Finished: 0 information, 0 warning, 0 error and 1 fatal error messages.
make: *** [makefile:62: Unity/build/testing/Testgpio.exe] Error 1
rm Unity/src/unity.o

我会继续努力,但如果有人可以帮忙,请做

伟大的更新!

之前的错误消失了,我开始看到实际的进展!我在 LINK 步骤中注释掉了 $(PATHD)Test%.d,因为它在我得到的原始文件中被注释掉了,当我包含它时,错误消失了,我现在面临来自实际文件的语法错误和警告:)请在下面查看并提供建议

$ make
armcc --no_depend_system_headers --ignore_missing_headers --depend Unity/build/depends/Testgpio.d Unity/test/Testgpio.c
"Unity/test/Testgpio.c", line 13: Warning:  #223-D: function "TEST_ASSERT_EQUAL" declared implicitly
      TEST_ASSERT_EQUAL(2, AddFunction_ReturnCorrect(1, 1));
      ^
"Unity/test/Testgpio.c", line 13: Warning:  #223-D: function "AddFunction_ReturnCorrect" declared implicitly
      TEST_ASSERT_EQUAL(2, AddFunction_ReturnCorrect(1, 1));
                           ^
"Unity/test/Testgpio.c", line 19: Warning:  #223-D: function "UnityBegin" declared implicitly
        UnityBegin("test/Testgpio.c");
        ^
"Unity/test/Testgpio.c", line 20: Warning:  #223-D: function "RUN_TEST" declared implicitly
        RUN_TEST(test_AddFunction_ReturnCorrect_ShouldReturnCorrectSum);
        ^
"Unity/test/Testgpio.c", line 22: Warning:  #223-D: function "UnityEnd" declared implicitly
        return (UnityEnd());
                ^
Unity/test/Testgpio.c: 5 warnings, 0 errors
Error: L6218E: Undefined symbol AddFunction_ReturnCorrect (referred from Testgpio.o).
Error: L6218E: Undefined symbol RUN_TEST (referred from Testgpio.o).
Error: L6218E: Undefined symbol TEST_ASSERT_EQUAL (referred from Testgpio.o).
Error: L6218E: Undefined symbol UnityBegin (referred from Testgpio.o).
Error: L6218E: Undefined symbol UnityEnd (referred from Testgpio.o).
Finished: 0 information, 0 warning and 5 error messages.
make: *** [makefile:74: Unity/build/depends/Testgpio.d] Error 1

更新

我不是这里发生的事情,在 3 4 之后返回之前的错误

更新

好的,如果我删除构建文件夹并运行 make,它会给出 L6218E 错误,如果我再次运行 make 它会给出 L6002U 错误。也有人可以解释为什么在每个 make it run 结束时rm Unity/src/unity.o

4

0 回答 0