-
Notifications
You must be signed in to change notification settings - Fork 331
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
[tools] Fix tools/test and not for user-mode emulation #212
base: main
Are you sure you want to change the base?
Conversation
@tarunprabhu Could you maybe have a look at this? Without these changes, some tests in |
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.
Do we need a separate executable for this? Could we prepend the arguments when calling not
instead? Or perhaps pass these on the command line? It seems as if users have to check TEST_SUITE_USER_MODE_EMULATION
and TEST_SUITE_RUN_UNDER
and use a different tool anyway, so user code does have to be changed.
tools/not.cpp
Outdated
// In case of user-mode emulation, before spawning a new subprocess, the | ||
// emulator needs to be preprended to the argv vector for the child. | ||
// TEST_SUITE_RUN_UNDER will be defined to a comma-separated list of | ||
// string litterals. |
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.
NIT:
// string litterals. | |
// string literals. |
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.
Sorry, fixed.
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.
No need to apologize :-)
Fortran/gfortran/CMakeLists.txt
Outdated
@@ -716,10 +716,18 @@ function(gfortran_add_execute_test expect_error main others fflags ldflags) | |||
gfortran_make_working_dir("${target}" working_dir) | |||
get_filename_component(working_dir_name "${working_dir}" NAME) | |||
|
|||
# When running in a emulator, use the version of 'not' that will |
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.
NIT:
# When running in a emulator, use the version of 'not' that will | |
# When running in an emulator, use the version of 'not' that will |
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.
Sorry, fixed.
Fortran/gfortran/CMakeLists.txt
Outdated
# When running in a emulator, use the version of 'not' that will | ||
# spawn the subprocess under that emulator as well. | ||
if(TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER) | ||
set(NOT_HELPER "not-spawning-emulator") |
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.
Perhaps name this variable NOT_TOOL
. It's not really a helper.
set(NOT_HELPER "not-spawning-emulator") | |
set(NOT_TOOL "not-spawning-emulator") |
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.
Thanks, I changed the name and moved it to the root CMakeLists.txt
next to the fpcmp
utility name assignment.
tools/test/CMakeLists.txt
Outdated
add_dependencies(abrt not) | ||
llvm_test_run(EXECUTABLE "$<TARGET_FILE:not>" "--crash" "$<TARGET_FILE:abrt>") | ||
llvm_add_test_for_target(abrt) | ||
# These test will always fail under user-mode emulation because 'not' |
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 am not sure what tests you are referring to here. If you mean the check_env
test that you have removed, then perhaps this comment could be moved after the abort test instead.
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.
With the NOT_TOOL
assigned now and the check_env
test being modified so that it now works under emulation, this is almost back to how it was before (just with ${NOT_TOOL
instead of not
).
tools/test/CMakeLists.txt
Outdated
# These test will always fail under user-mode emulation because 'not' | ||
# spawns a subprocess outside the emulator and the check_env test | ||
# runs the host python interpreter under the emulator for the target. | ||
if(NOT(TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER)) |
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.
The negation of the conditional is a bit hard to read. Could the branches be switched with a "positive" conditional instead?
if(NOT(TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER)) | |
if(TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER) |
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.
With the NOT_TOOL
assigned now and the check_env
test being modified so that it now works under emulation, this is almost back to how it was before (just with ${NOT_TOOL
instead of not
).
tools/test/CMakeLists.txt
Outdated
llvm_add_test_for_target(abrt) | ||
# These test will always fail under user-mode emulation because 'not' | ||
# spawns a subprocess outside the emulator and the check_env test | ||
# runs the host python interpreter under the emulator for the target. |
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.
Does passing environment variables work with not-spawning-emulator
? Is it only the test here that cannot be run? It would be good to have a test for this if possible.
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.
Yes, the two user-mode emulator I know/use (mostly QEMU) do forward environment variables. I replaced the python script that sets the environment variable by a small C program inspired by not.cpp
, and with that, the test now also works under emulation.
01ab296
to
321227a
Compare
That was my first idea as well, and I can do that if its preferred. This just seamed easier to me, and other tools like Would a syntax similar to |
Thanks for the changes.
I think it might be better to stick with a single tool for this. I am guessing that
I assume that |
I just pushed a commit with the proposed solution so that you can have a look (single |
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.
Thank you for all the changes
tools/test/CMakeLists.txt
Outdated
if(TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER) | ||
# ${TEST_SUITE_RUN_UNDER} is needed here because test_not is not itself | ||
# user-mode emulation aware, unlike the not tool. | ||
llvm_test_run(EXECUTABLE ${Python_EXECUTABLE} "$<TARGET_FILE:test_not>" ${TEST_SUITE_RUN_UNDER} ${NOT_TOOL} "$<TARGET_FILE:check_env>") |
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.
Is ${Python_EXECUTABLE}
required here?
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.
Thanks for noticing, not it is not. I just tested in a clean build to make sure.
CMakeLists.txt
Outdated
# Shortcut for the path to the not executable | ||
set(NOT_TOOL "$<TARGET_FILE:not>") | ||
if (TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER) | ||
# Because 'not' spawns a subprocess for its argument, it needs to know about the |
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.
Nit:
The Github interface doesn't show columns, but does this comment fit within 80 characters? The rules for line width in cmake are not as strict as source files, but it would be good to stick to that width where we can.
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 reformatted this and the following two lines to make it fit.
tools/not.cpp
Outdated
// subcommand. If --crash is used as well, it has to come after the | ||
// '--run-under <...> ...' arguments. The double-dash is used to separate | ||
// emulator arguments from cmd arguments. This order makes it easier to | ||
// use the not tool in the test-suite. |
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.
Could you add sentence clarifying what the return value will be in this case.
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.
Just did that. This works as expected with QEMU and another emulator I use downstream, I will double check if this is also the behavior of other user-mode emulators such as Gem5 SE mode or RISC-V Spike.
tools/not.cpp
Outdated
@@ -29,17 +35,52 @@ | |||
#include <sys/wait.h> | |||
#endif | |||
|
|||
#include <vector> |
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.
Please move this include with the other system includes at the top of this file
tools/not.cpp
Outdated
++argv; | ||
} | ||
|
||
// If present, the crash flag is between the emulator |
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.
Nit:
Does this comment need to be split across two lines? clang-format
can be used to "fit" comments.
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.
Thanks for all the changes and for seeing this through.
// with the same exit status/signal than the emulated binary in case of | ||
// a crash, and the --crash flag will behave the same 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.
Nit
// with the same exit status/signal than the emulated binary in case of | |
// a crash, and the --crash flag will behave the same way. | |
// with the same exit status/signal as the emulated binary. The --crash flag | |
// will behave the same way. |
Add preliminary support for user-mode emulation to the
not
toolused in some fortran tests by adding a new mode where it spawns
the subprocess under the emulator. The original non-emulator-spawning
version is still needed for tests that use it to verify the output
using the host's
diff
. In the new version, theTEST_SUITE_RUN_UNDER
cmake option contents is prepended to the arguments then used to spawn
a subprocess.
Also disables the check_env test in tools/test in case of user-mode
emulation because it would run the host python interpreter in the
target emulator.