Skip to content

Commit

Permalink
Use pkill to kill running daemons after tests
Browse files Browse the repository at this point in the history
Should hopefully fix issues with lingering daemon processes causing buildbot
workers to become unusable.

Automatically detect which pkill command-line options are supported by your
Unix variant in the Perl and CMake buildsystems, and use them.
  • Loading branch information
qris committed Dec 4, 2017
1 parent 16f0d63 commit 85beed5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
36 changes: 28 additions & 8 deletions infrastructure/cmake/CMakeLists.txt
Expand Up @@ -71,13 +71,6 @@ function(move_file_if_exists source_file dest_file)
endif()
endfunction()

foreach(file_to_configure ${files_to_configure})
configure_file("${base_dir}/${file_to_configure}.in" "${base_dir}/${file_to_configure}.out" @ONLY)
replace_file_if_different(
"${base_dir}/${file_to_configure}"
"${base_dir}/${file_to_configure}.out")
endforeach()

# If BOXBACKUP_VERSION is defined when running CMake (as the AppVeyor config does), use it
# as-is, since it contains the full version number, branch, and platform (Win32/Win64):
if(BOXBACKUP_VERSION)
Expand Down Expand Up @@ -480,7 +473,7 @@ move_file_if_exists(
"${boxconfig_cmake_h_dir}/BoxConfig.cmake.h.bak")

foreach(m4_filename boxbackup_tests.m4 ax_check_mount_point.m4 ax_func_syscall.m4)
file(STRINGS "${base_dir}/infrastructure/m4/${m4_filename}" m4_functions REGEX "^ *(AC|AX|BOX)_[A-Z_]+\\(.*\\)$")
file(STRINGS "${base_dir}/infrastructure/m4/${m4_filename}" m4_functions REGEX "^ *(AC|AX|AS|BOX)_[A-Z_]+\\(.*\\)$")
foreach(m4_function ${m4_functions})
if(DEBUG)
message(STATUS "Processing m4_function: ${m4_function}")
Expand Down Expand Up @@ -580,6 +573,26 @@ foreach(m4_filename boxbackup_tests.m4 ax_check_mount_point.m4 ax_func_syscall.m
add_definitions("${flag}")
endif()
endif()
elseif(m4_function MATCHES "^ *BOX_TRY_COMMAND\\(\\[(.+)\\], *\\[(.+)\\]\\)$")
set(test_command ${CMAKE_MATCH_1})
set(variable_name ${CMAKE_MATCH_2})

if(DEBUG)
message(STATUS "Processing BOX_TRY_COMMAND: ${test_command} -> ${variable_name}")
endif()

# http://stackoverflow.com/questions/5272781/what-is-common-way-to-split-string-into-list-with-cmake
string(REPLACE " " ";" test_command_arglist "${test_command}")
string(REPLACE "\\$$" "$$" test_command_arglist "${test_command_arglist}")

execute_process(COMMAND ${test_command_arglist} RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET)
if(${result} EQUAL 0)
set(${variable_name} 1)
endif()

if(DEBUG)
message(STATUS "Processing BOX_TRY_COMMAND: ${test_command} => ${result}")
endif()
endif()
endforeach()

Expand All @@ -597,6 +610,13 @@ foreach(header_file ${detect_header_files})
file(APPEND "${boxconfig_h_file}" "#cmakedefine HAVE_${platform_var_name}\n")
endforeach()

foreach(file_to_configure ${files_to_configure})
configure_file("${base_dir}/${file_to_configure}.in" "${base_dir}/${file_to_configure}.out" @ONLY)
replace_file_if_different(
"${base_dir}/${file_to_configure}"
"${base_dir}/${file_to_configure}.out")
endforeach()

if(NOT HAVE_PCREPOSIX_H)
message(FATAL_ERROR "pcreposix.h not found even though PCRE was apparently detected?!")
endif()
Expand Down
15 changes: 15 additions & 0 deletions infrastructure/m4/boxbackup_tests.m4
Expand Up @@ -390,4 +390,19 @@ AC_ARG_WITH([debugger],
[use this debugger in t-gdb scripts to debug tests @<:@default=lldb if present, otherwise gdb@:>@])],
[],
[with_debugger=$default_debugger])

AC_SUBST([with_debugger])
# Reduce command execution testing to a one-liner, needed for CMake to parse them
AC_DEFUN([BOX_TRY_COMMAND],
[AC_MSG_CHECKING([$1])
AS_IF(_AC_RUN_LOG_STDERR([$1 >/dev/null], [true]),
[AS_VAR_SET([$2], [1])
AC_MSG_RESULT([yes])]
[AC_MSG_RESULT([no])])
rm conftest.err
])

BOX_TRY_COMMAND([pkill -0 -l \$$], [pkill_supports_option_l])
BOX_TRY_COMMAND([pkill -0 -s0 \$$], [pkill_supports_option_s0])
AC_SUBST([pkill_supports_option_l])
AC_SUBST([pkill_supports_option_s0])
17 changes: 14 additions & 3 deletions infrastructure/makebuildenv.pl.in
Expand Up @@ -533,6 +533,19 @@ for my $mod (@implicit_deps, @modules)
$library_targets{$mod} = $target_is_library;
}

my $pkill_command = 'pkill';

if('@pkill_supports_option_l@')
{
$pkill_command .= ' -l';
}


if('@pkill_supports_option_s0@')
{
$pkill_command .= ' -s0';
}

# Now loop over them again, generating makefile instructions etc.
for my $mod (@implicit_deps, @modules)
{
Expand Down Expand Up @@ -570,9 +583,7 @@ __E
print TESTFILE <<__E;
kill_process()
{
test -r testfiles/\$1.pid \\
&& kill -0 `cat testfiles/\$1.pid` \\
&& kill `cat testfiles/\$1.pid`
$pkill_command -U `id -u` \$1
}
__E
}
Expand Down

0 comments on commit 85beed5

Please sign in to comment.