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)
716
716
gfortran_make_working_dir ("${target} " working_dir )
717
717
get_filename_component (working_dir_name "${working_dir} " NAME )
718
718
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
+
719
727
llvm_test_executable_no_test (${target} ${main} ${others} )
720
728
if (expect_error )
721
729
llvm_test_run (
722
- EXECUTABLE "%b/not --crash %S/${target} "
730
+ EXECUTABLE "%b/${NOT_HELPER} --crash %S/${target} "
723
731
WORKDIR "%S/${working_dir_name} " )
724
732
else ()
725
733
llvm_test_run (WORKDIR "%S/${working_dir_name} " )
Original file line number Diff line number Diff line change @@ -41,3 +41,18 @@ else()
41
41
endif ()
42
42
43
43
add_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 29
29
#include < sys/wait.h>
30
30
#endif
31
31
32
+ #ifdef TEST_SUITE_RUN_UNDER
33
+ #include < vector>
34
+ #endif
35
+
32
36
int main (int argc, char * const * argv) {
33
37
bool expectCrash = false ;
34
38
@@ -54,6 +58,19 @@ int main(int argc, char* const* argv) {
54
58
if (argc == 0 )
55
59
return 1 ;
56
60
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
+
57
74
int result;
58
75
59
76
#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))
29
29
add_dependencies (check_env not )
30
30
llvm_test_run (EXECUTABLE ${Python_EXECUTABLE} "%b/test/test_not.py" "$<TARGET_FILE:not>" "$<TARGET_FILE:check_env>" )
31
31
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 )
32
38
endif ()
You can’t perform that action at this time.
0 commit comments