-
Notifications
You must be signed in to change notification settings - Fork 274
Fix CMake syntax to enable memory analyzer tests #5932
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
Fix CMake syntax to enable memory analyzer tests #5932
Conversation
a2fe5b9
to
8fe639c
Compare
8fe639c
to
4b6075d
Compare
4b6075d
to
6e20e6d
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5932 +/- ##
===========================================
+ Coverage 75.12% 75.13% +0.01%
===========================================
Files 1435 1444 +9
Lines 156301 157261 +960
===========================================
+ Hits 117416 118165 +749
- Misses 38885 39096 +211
Continue to review full report at Codecov.
|
unit/memory-analyzer/gdb_api.cpp
Outdated
compile_test_filet() : compiled("test", "") | ||
{ | ||
temporary_filet tmp("test", ".c"); | ||
std::ofstream of(tmp().c_str()); | ||
REQUIRE(of.is_open()); | ||
|
||
of << "int x;\n" | ||
"float y;\n" | ||
"char z;\n" | ||
"\n" | ||
"char *s = \"abc\";\n" | ||
"int *p;\n" | ||
"void *vp;\n" | ||
"int *np = 0;\n" | ||
"void *vp_string;\n" | ||
"\n" | ||
"void checkpoint()\n" | ||
"{\n" | ||
"}\n" | ||
"void checkpoint2()\n" | ||
"{\n" | ||
"}\n" | ||
"\n" | ||
"void func()\n" | ||
"{\n" | ||
" checkpoint2();\n" | ||
"}\n" | ||
"\n" | ||
"int main()\n" | ||
"{\n" | ||
" x = 8;\n" | ||
" y = 2.5;\n" | ||
" z = 'c';\n" | ||
"\n" | ||
" p = &x;\n" | ||
" vp = (void *)&x;\n" | ||
" vp_string = s;\n" | ||
"\n" | ||
" checkpoint();\n" | ||
"\n" | ||
" return 0;\n" | ||
"}\n"; | ||
of.close(); | ||
|
||
REQUIRE(run("gcc", {"gcc", "-g", "-o", compiled(), tmp()}) == 0); | ||
} | ||
|
||
temporary_filet compiled; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessarily ugly, is there a reason to do it this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If, as was the case before, we keep the contents in a separate file, then this file must either be included in the compiled unit test binary (e.g., via #include
), or else the compiled unit test binary necessarily relies on the source tree being present as well. It seems reasonable to assume that the source tree will be present, but then also the exact location of the file must be known.
I made these changes as I found the above conditions not to be satisfied in my ad-hoc testing for I wasn't aware where the unit test had to be run from to make things work. That being said, we have the same problem in other unit tests. So maybe it's not all that important to fix if people are concerned about this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the motivation, I was more considering that there might be a prettier way to have the text inside the file.
unit/memory-analyzer/gdb_api.cpp
Outdated
std::ofstream of(tmp().c_str()); | ||
REQUIRE(of.is_open()); | ||
|
||
of << "abc\n" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" | ||
"xyz"; | ||
of.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, is this the best way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've modified this to use ansi-c/file_converter
and #include
them instead.
6e20e6d
to
d748fa0
Compare
d748fa0
to
047fb2e
Compare
When gdb wasn't available, the forked child would not terminate and the parent would wait forever.
Make the unit tests less fragile by not relying on a particular directory that they are being run from. Test files had to be loaded from a specific location; instead, place them in the source code and generate temporary files at runtime.
"option" requires the help text as second, not as third argument. This resulted in memory analyzer tests being disabled no matter what the OS being built on.
This test isn't strictly dependent on memory-analyzer being available, but is only of interest if that is the case.
047fb2e
to
0e6b393
Compare
"option" requires the help text as second, not as third argument. This
resulted in memory analyzer tests being disabled no matter what the OS
being built on.