Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity Fixtures Compiling Bug (IDFGH-6322) #7984

Closed
Magdahime opened this issue Nov 30, 2021 · 7 comments
Closed

Unity Fixtures Compiling Bug (IDFGH-6322) #7984

Magdahime opened this issue Nov 30, 2021 · 7 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@Magdahime
Copy link

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

@espressif-bot espressif-bot added the Status: Opened Issue is new label Nov 30, 2021
@github-actions github-actions bot changed the title Unity Fixtures Compiling Bug Unity Fixtures Compiling Bug (IDFGH-6322) Nov 30, 2021
@igrr
Copy link
Member

igrr commented Nov 30, 2021

Hi @Magdahime, thank you for reporting the issue. It seems that unity_fixture.h header doesn't have C++ guards, which means that UnityMain gets declared with C++ linkage when included from main.cc; at the same time, when UnityMain is compiled, it is compiled with C linkage.

Can you please try changing your main.cc like this?

extern "C"
{
  #include "unity_fixture.h"
}
#include "unity_fixture_extras.h"

@Magdahime
Copy link
Author

Hi @igrr ! Thank you for your quick response :)

I changed it and now it gives me this:

../main/main.cc:7:12: fatal error: unity_fixture.h: No such file or directory
   #include "unity_fixture.h"
            ^~~~~~~~~~~~~~~~~
compilation terminated.

@igrr
Copy link
Member

igrr commented Nov 30, 2021

Oh, that's unexpected. Is this the only change you did? Could you revert back to the state without extern "C" and see if that makes the error disappear? If it doesn't, could you check if there's still CONFIG_UNITY_ENABLE_FIXTURE=y in the sdkconfig file?

@Magdahime
Copy link
Author

Hello once again :) Sorry I got sick a little bit. I am back.

I checked and for 100% I have fixtures enabled.

When I am trying without extern "C" I get this error:

[1011/1013] Linking CXX executable Tamagotchi_unit_tests.elf
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:20: undefined reference to `UnityMain(int, char const**, void (*)())'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1

This is the only change I am making.

@Magdahime
Copy link
Author

Magdahime commented Dec 4, 2021

Okay I am taking it back - I don't know what happened, but when I tried with extern "C" once again + I deleted whole build/ directory it works! 👍
Thank you for your help!!!! 😊😊

@igrr
Copy link
Member

igrr commented Dec 4, 2021

Thanks for confirming! The fix has been merged upstream to Unity repository (ThrowTheSwitch/Unity#586), we will update Unity submodule in IDF soon.

@igrr igrr reopened this Dec 6, 2021
@ESP-Marius
Copy link
Collaborator

Unity submodule used in IDF now includes this fix, so I think we can consider this one closed.

@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Opened Issue is new labels Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

4 participants