Skip to content

Unity Fixtures Compiling Bug (IDFGH-6322) #7984

@Magdahime

Description

@Magdahime

Environment

  • Development Kit: [ESP32-Wrover-Kit]
  • Kit version (WroverKit): [v1|v2|v3|v4]
  • Module or chip used: [ESP32-WROOM-32D
  • IDF version (run git describe --tags to find it):
    v4.4-dev-1594-g1d7068e4be
  • Build System: [idf.py]
  • Compiler version (run xtensa-esp32-elf-gcc --version to find it):
    xtensa-esp32-elf-gcc.exe (crosstool-NG esp-2020r3) 8.4.0
  • Operating System: Windows
  • (Windows only) environment type: [Plain Command Prompt].
  • Using an IDE?: [Yes - Visual Studio Code]
  • Power Supply: [USB]

Problem Description

I have problem with compiling my unit tests with idf.py. I am trying to use fixtures in my project and I am doing everything as described in https://github.com/ThrowTheSwitch/Unity/tree/master/examples/example_2.

I set up my project as described in https://github.com/espressif/esp-idf/blob/master/examples/system/unit_test/README.md

So my project structure looks like this

project                      — Application project directory
  - components                 — Components of the application project
    - esp
        - component1
          - include
          - test
        - component2
        ....
    - generic
        - component1
        - include
          - test
        - component2
        ....
  + main                       - Main source files of the application project
  + test                       — Test project directory
  Makefile / CMakeLists.txt    - Makefiles of the application project

I keep getting this error while trying to compile it with idf.py -p COM3 flash monitor:
FAILED: Tamagotchi_unit_tests.elf
cmd.exe /C "cd . && C:\Users\magda.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wno-frame-address @CMakeFiles\Tamagotchi_unit_tests.elf.rsp -o Tamagotchi_unit_tests.elf && cd ."
c:/users/magda/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cc.obj):(.literal.app_main+0x10): undefined reference to UnityMain(int, char const**, void (*)())' c:/users/magda/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cc.obj): in function app_main':
c:\users\magda\documents\esp\tamagotchi\test\build/../main/main.cc:21: undefined reference to `UnityMain(int, char const**, void (*)())'

Expected Behavior

It should compile.

Actual Behavior

It's not compiling.

Steps to reproduce

  1. Create new project
  2. In components directory create new two directories
  3. Insert some components into these two directories
  4. Write unit test for these components using fixtures. It's important that you place the test runners at the end of the test.c file
  5. Create inside this project a new test project as described in https://github.com/espressif/esp-idf/blob/master/examples/system/unit_test/README.md
  6. Try to compile it

Code to reproduce this issue

This is the main.cc of my main component in test project.

#include <string.h>

#include "unity_fixture.h"
#include "unity_fixture_extras.h"

static void run_all_tests(void)
{
    RUN_TEST_GROUP(ST7789VWDriverTests);
    RUN_TEST_GROUP(RecyclingContainerTests);
    RUN_TEST_GROUP(ST7789VWUtilsTests);
}

static void print_banner(const char* text) {
  printf("\n#### %s #####\n\n", text);
}

extern "C" void app_main() {
  print_banner("Running all the registered tests");
  UNITY_MAIN_FUNC(run_all_tests);
}

Debug Logs

FAILED: Tamagotchi_unit_tests.elf
cmd.exe /C "cd . && C:\Users\magda\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe  -mlongcalls -Wno-frame-address   @CMakeFiles\Tamagotchi_unit_tests.elf.rsp  -o Tamagotchi_unit_tests.elf  && cd ."
c:/users/magda/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cc.obj):(.literal.app_main+0x10): undefined reference to `UnityMain(int, char const**, void (*)())'
c:/users/magda/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: esp-idf/main/libmain.a(main.cc.obj): in function `app_main':
c:\users\magda\documents\esp\tamagotchi\test\build/../main/main.cc:21: undefined reference to `UnityMain(int, char const**, void (*)())'

Other items if possible

sdkconfig.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions