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

Docker cpputest breaks on #include <unordered_map> #1768

Open
graial opened this issue Dec 12, 2023 · 16 comments
Open

Docker cpputest breaks on #include <unordered_map> #1768

graial opened this issue Dec 12, 2023 · 16 comments

Comments

@graial
Copy link

graial commented Dec 12, 2023

Greetings, I am encountering what appears to be this issue when trying to include ArduinoFake in a project that uses the docker version of cpputest. provided in cpputest-starter-project

In file included from /usr/local/include/c++/12.2.0/bits/hashtable.h:35, from /usr/local/include/c++/12.2.0/unordered_map:46, from mocks/ArduinoFake/src/ArduinoFake.h:8, from mocks/ArduinoFake/src/Arduino.h:1, from tests/MyFirstTest.cpp:3: /usr/local/include/c++/12.2.0/bits/hashtable_policy.h: In member function 'void std::__detail::_Local_iterator_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, false>::_M_init(const __hash_code_base&)': /usr/local/include/c++/12.2.0/bits/hashtable_policy.h:1495:15: error: expected type-specifier before 'this' 1495 | { ::new(this->_M_h()) __hash_code_base(__base); }

The fix mentioned in the seems like something that cannot be tweaked within the dockerfile. Would I need to do a native build instead?

Many thanks

@graial
Copy link
Author

graial commented Dec 12, 2023

I've created a minimal example in this repo to troubleshoot this.

I am trying from both the docker container and also a native build on my cpu (c++13.2.1).

After reading through the suggestions on memory leak

I tried adding MemoryLeakWarningPlugin::turnOffNewDeleteOverloads(); to the main() of AllTests.cpp without success

I've also noticed threads like this, which mention a default constructor. I'm not experienced enough with C++ to know how to implement this.

@basvodde
Copy link
Member

What are the first two lines in your test file? The error says "MyFirstTest.cpp:3" which means the file was included on line 3.

@graial
Copy link
Author

graial commented Dec 14, 2023

Ah shoot! I didn't notice that submodules cant be viewed on github. I've re-added cpputest-stater and ArduinoFake without the submodule.

To your question

The only line above includes TestHarness.h
see here:
https://github.com/graial/blink-arduino-cpputest/blob/main/unit-tests/tests/MyFirstTest.cpp

note: after added the comment, the failing line is now line 4.

@basvodde
Copy link
Member

Can you change these includes to before the TestHarness include ?

@graial
Copy link
Author

graial commented Dec 14, 2023

Same error when ArduinoFake is imported before TestHarness.
I've also tried adjusting a compiler flag on suggestion of FabioBatSilva
FabioBatSilva/ArduinoFake#56

@graial
Copy link
Author

graial commented Dec 18, 2023

Just a quick update that i encountered the same error from the opposite direction by adapting ArduinoFake's example project (using unity) to use cpputest instead
https://github.com/graial/ArduinoFake-cpputest

@graial
Copy link
Author

graial commented Dec 28, 2023

Good evening,

Today I was able to reduce that last to to a minimum reproducible example via cmake and the code sample provided in the last section of the cpputest README.

Hopefully you can reproduce it on your machine.

@ali-rostami
Copy link

Hello everyone
@graial Could you solve the issue?
In my case, I'm using cpputest-starter-project and if I add this line:
#include <unordered_map>
to before or after #include "CppUTest/TestHarness.h" in MyFirstTest.cpp I get this compile error:

compiling MyFirstTest.cpp
In file included from /usr/local/include/c++/13.2.0/bits/hashtable.h:35,
                 from /usr/local/include/c++/13.2.0/bits/unordered_map.h:33,
                 from /usr/local/include/c++/13.2.0/unordered_map:41,
                 from tests/MyFirstTest.cpp:1:
/usr/local/include/c++/13.2.0/bits/hashtable_policy.h: In member function 'void std::__detail::_Local_iterator_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, false>::_M_init(const __hash_code_base&)':
/usr/local/include/c++/13.2.0/bits/hashtable_policy.h:1531:15: error: expected type-specifier before 'this'       
 1531 |       { ::new(this->_M_h()) __hash_code_base(__base); }
      |               ^~~~
compilation terminated due to -Wfatal-errors.
make: *** [/opt/cpputest/build/MakefileWorker.mk:511: test-obj/tests/MyFirstTest.o] Error 1
make: Leaving directory '/home/tests'
root@e3ac4661c52c:/home#

@basvodde Do you have any ideas?

@thetic
Copy link
Contributor

thetic commented May 10, 2024

Have you tried building with memory leak detection disabled?

@graial
Copy link
Author

graial commented May 11, 2024 via email

@ali-rostami
Copy link

Hi @graial thanks for your answer.
I took a look at it, but it didn't help me.

I found an easier solution to reproduce the problem. Open cyber-dojo and click on "enter an existing practice" then enter this code "al5NpW".
You can see there, that when #include <unordered_map> is not commented in the HikerTest file, it gives a compile error.

@graial
Copy link
Author

graial commented May 13, 2024 via email

@ali-rostami
Copy link

Unfortunately it didn't help. I also tried to turn off memory leak detection by using this:

int main(int argc, char** argv)
{
    MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
    return CommandLineTestRunner::RunAllTests(argc, argv);
}

But it still gives me compile error.

@thetic
Copy link
Contributor

thetic commented May 13, 2024

I mean at build time by defining CPPUTEST_MEM_LEAK_DETECTION_DISABLED

@basvodde
Copy link
Member

@ali-rostami The error you get is because of a placement operator new usage in STL. You seem to use the MakefileWorking.mk, which enables the "new macro" for adding memory leak info in line 307. Which means that the macro replacement will be included before the ordered list.

As @thetic mentioned, you'll need to disable that. You can do that in the Makefileworker.mk by setting CPPUTEST_USE_MEM_LEAK_DETECTION to N. Then it will set the define that @thetic mentioned.

@ali-rostami
Copy link

Thanks to both of you🙏🙂
I finally could disable the MEM_LEAK_DETECTION by adding this line:
ENV CPPUTEST_USE_MEM_LEAK_DETECTION=N
to docker file of cpputest_starter_project.
Now it compiles successfully but I don't want to turn MEM_LEAK_DETECTION off. As It's a useful feature.
Unfortunately, I'm still struggling with your solutions.
So would you please help me with this stage too and send a PR to my forked repository -in the best case😉- or tell me specifically tell me what should I change in this project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants