Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Fortran/gfortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:

Suggested change
# When running in a emulator, use the version of 'not' that will
# When running in an emulator, use the version of 'not' that will

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, fixed.

# 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")
Copy link
Contributor

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.

Suggested change
set(NOT_HELPER "not-spawning-emulator")
set(NOT_TOOL "not-spawning-emulator")

Copy link
Contributor Author

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.

else()
set(NOT_HELPER "not")
endif()

llvm_test_executable_no_test(${target} ${main} ${others})
if (expect_error)
llvm_test_run(
EXECUTABLE "%b/not --crash %S/${target}"
EXECUTABLE "%b/${NOT_HELPER} --crash %S/${target}"
WORKDIR "%S/${working_dir_name}")
else ()
llvm_test_run(WORKDIR "%S/${working_dir_name}")
Expand Down
15 changes: 15 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,18 @@ else()
endif()

add_executable(not ${CMAKE_CURRENT_SOURCE_DIR}/not.cpp)

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
# emulator when running in user-mode emulation. This is not needed when using 'not' to
# verify outputs, only when using it to execute a test binary, which is why this
# definition is only added to the 'not-target' target.
separate_arguments(TEST_SUITE_RUN_UNDER_AS_LIST NATIVE_COMMAND ${TEST_SUITE_RUN_UNDER})
set(AS_STRINGLITS "")
foreach(arg ${TEST_SUITE_RUN_UNDER_AS_LIST})
set(AS_STRINGLITS "${AS_STRINGLITS}\t\"${arg}\",\n")
endforeach()
add_executable(not-spawning-emulator ${CMAKE_CURRENT_SOURCE_DIR}/not.cpp)
target_compile_definitions(not-spawning-emulator PUBLIC "-DTEST_SUITE_RUN_UNDER=${AS_STRINGLITS}")
unset(AS_STRINGLITS)
endif()
17 changes: 17 additions & 0 deletions tools/not.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include <sys/wait.h>
#endif

#ifdef TEST_SUITE_RUN_UNDER
#include <vector>
Copy link
Contributor

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

#endif

int main(int argc, char* const* argv) {
bool expectCrash = false;

Expand All @@ -54,6 +58,19 @@ int main(int argc, char* const* argv) {
if (argc == 0)
return 1;

#ifdef TEST_SUITE_RUN_UNDER
// 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:

Suggested change
// string litterals.
// string literals.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to apologize :-)

std::vector<char *> argvbuf = {TEST_SUITE_RUN_UNDER};
for (char *const *argp = argv; *argp != NULL; ++argp)
argvbuf.push_back(*argp);
argvbuf.push_back(NULL);
argv = argvbuf.data();
argc = argvbuf.size() - 1;
#endif

int result;

#if defined(__unix__) || defined(__APPLE__)
Expand Down
33 changes: 22 additions & 11 deletions tools/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,26 @@ add_dependencies(ret0 not)
llvm_test_run(EXECUTABLE "$<TARGET_FILE:not>" "$<TARGET_FILE:not>" "$<TARGET_FILE:ret0>")
llvm_add_test_for_target(ret0)

# Check that expected crashes are handled correctly.
llvm_test_executable_no_test(abrt abort.c)
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'
Copy link
Contributor

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.

Copy link
Contributor Author

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).

# spawns a subprocess outside the emulator and the check_env test
# runs the host python interpreter under the emulator for the target.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

if(NOT(TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER))
Copy link
Contributor

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?

Suggested change
if(NOT(TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER))
if(TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER)

Copy link
Contributor Author

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).

# Check that expected crashes are handled correctly.
llvm_test_executable_no_test(abrt abort.c)
add_dependencies(abrt not)
llvm_test_run(EXECUTABLE "$<TARGET_FILE:not>" "--crash" "$<TARGET_FILE:abrt>")
llvm_add_test_for_target(abrt)

# Check that not passes environment variables to the called executable.
find_package(Python COMPONENTS Interpreter)
llvm_test_executable_no_test(check_env check_env.c)
add_dependencies(check_env not)
llvm_test_run(EXECUTABLE ${Python_EXECUTABLE} "%b/test/test_not.py" "$<TARGET_FILE:not>" "$<TARGET_FILE:check_env>")
llvm_add_test_For_target(check_env)
# Check that not passes environment variables to the called executable.
find_package(Python COMPONENTS Interpreter)
llvm_test_executable_no_test(check_env check_env.c)
add_dependencies(check_env not)
llvm_test_run(EXECUTABLE ${Python_EXECUTABLE} "%b/test/test_not.py" "$<TARGET_FILE:not>" "$<TARGET_FILE:check_env>")
llvm_add_test_For_target(check_env)
else()
# Check that expected crashes are handled correctly under user-mode emulation.
llvm_test_executable_no_test(abrt abort.c)
add_dependencies(abrt not-spawning-emulator)
llvm_test_run(EXECUTABLE "$<TARGET_FILE:not-spawning-emulator>" "--crash" "$<TARGET_FILE:abrt>")
llvm_add_test_for_target(abrt)
endif()