File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed
Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -716,10 +716,18 @@ function(gfortran_add_execute_test expect_error main others fflags ldflags)
716716 gfortran_make_working_dir("${target} " working_dir)
717717 get_filename_component (working_dir_name "${working_dir} " NAME )
718718
719+ # When running in a emulator, use the version of 'not' that will
720+ # spawn the subprocess under that emulator as well.
721+ if (TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER)
722+ set (NOT_HELPER "not-spawning-emulator" )
723+ else ()
724+ set (NOT_HELPER "not" )
725+ endif ()
726+
719727 llvm_test_executable_no_test(${target} ${main} ${others} )
720728 if (expect_error)
721729 llvm_test_run(
722- EXECUTABLE "%b/not --crash %S/${target} "
730+ EXECUTABLE "%b/${NOT_HELPER} --crash %S/${target} "
723731 WORKDIR "%S/${working_dir_name} " )
724732 else ()
725733 llvm_test_run(WORKDIR "%S/${working_dir_name} " )
Original file line number Diff line number Diff line change @@ -41,3 +41,18 @@ else()
4141endif ()
4242
4343add_executable (not ${CMAKE_CURRENT_SOURCE_DIR} /not .cpp)
44+
45+ if (TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER)
46+ # Because 'not' spawns a subprocess for its argument, it needs to know about the
47+ # emulator when running in user-mode emulation. This is not needed when using 'not' to
48+ # verify outputs, only when using it to execute a test binary, which is why this
49+ # definition is only added to the 'not-target' target.
50+ separate_arguments (TEST_SUITE_RUN_UNDER_AS_LIST NATIVE_COMMAND ${TEST_SUITE_RUN_UNDER} )
51+ set (AS_STRINGLITS "" )
52+ foreach (arg ${TEST_SUITE_RUN_UNDER_AS_LIST} )
53+ set (AS_STRINGLITS "${AS_STRINGLITS} \t\" ${arg} \" ,\n " )
54+ endforeach ()
55+ add_executable (not -spawning-emulator ${CMAKE_CURRENT_SOURCE_DIR} /not .cpp)
56+ target_compile_definitions (not -spawning-emulator PUBLIC "-DTEST_SUITE_RUN_UNDER=${AS_STRINGLITS} " )
57+ unset (AS_STRINGLITS)
58+ endif ()
Original file line number Diff line number Diff line change 2929#include < sys/wait.h>
3030#endif
3131
32+ #ifdef TEST_SUITE_RUN_UNDER
33+ #include < vector>
34+ #endif
35+
3236int main (int argc, char * const * argv) {
3337 bool expectCrash = false ;
3438
@@ -54,6 +58,19 @@ int main(int argc, char* const* argv) {
5458 if (argc == 0 )
5559 return 1 ;
5660
61+ #ifdef TEST_SUITE_RUN_UNDER
62+ // In case of user-mode emulation, before spawning a new subprocess, the
63+ // emulator needs to be preprended to the argv vector for the child.
64+ // TEST_SUITE_RUN_UNDER will be defined to a comma-separated list of
65+ // string litterals.
66+ std::vector<char *> argvbuf = {TEST_SUITE_RUN_UNDER};
67+ for (char *const *argp = argv; *argp != NULL ; ++argp)
68+ argvbuf.push_back (*argp);
69+ argvbuf.push_back (NULL );
70+ argv = argvbuf.data ();
71+ argc = argvbuf.size () - 1 ;
72+ #endif
73+
5774 int result;
5875
5976#if defined(__unix__) || defined(__APPLE__)
Original file line number Diff line number Diff line change @@ -29,4 +29,10 @@ if(NOT(TEST_SUITE_USER_MODE_EMULATION AND TEST_SUITE_RUN_UNDER))
2929 add_dependencies (check_env not )
3030 llvm_test_run(EXECUTABLE ${Python_EXECUTABLE} "%b/test/test_not.py" "$<TARGET_FILE:not>" "$<TARGET_FILE:check_env>" )
3131 llvm_add_test_For_target(check_env)
32+ else ()
33+ # Check that expected crashes are handled correctly under user-mode emulation.
34+ llvm_test_executable_no_test(abrt abort.c)
35+ add_dependencies (abrt not -spawning-emulator)
36+ llvm_test_run(EXECUTABLE "$<TARGET_FILE:not-spawning-emulator>" "--crash" "$<TARGET_FILE:abrt>" )
37+ llvm_add_test_for_target(abrt)
3238endif ()
You can’t perform that action at this time.
0 commit comments