Skip to content

Commit

Permalink
Get references to generated pwait binary working
Browse files Browse the repository at this point in the history
  • Loading branch information
diazona committed Mar 25, 2024
1 parent 48b9a05 commit 02cb246
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ jobs:
c_compiler:
- gcc
- clang
include:
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++

steps:
- uses: actions/checkout@v4
Expand All @@ -51,7 +44,6 @@ jobs:
run: >
cmake
-B ${{steps.strings.outputs.build-output-dir}}
-DCMAKE_CXX_COMPILER=${{matrix.cpp_compiler}}
-DCMAKE_C_COMPILER=${{matrix.c_compiler}}
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-S ${{github.workspace}}
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(pwait)
cmake_minimum_required(VERSION 3.15)

cmake_minimum_required(VERSION 2.8)
project(pwait)

enable_testing()

Expand Down
9 changes: 2 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cmake_minimum_required(VERSION 3.15)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

include(CheckSymbolExists)
Expand All @@ -7,12 +9,5 @@ configure_file(config.h.in config.h)
add_executable(pwait pwait.c)
target_link_libraries(pwait cap)

add_custom_target(
pwait-setcap
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND sudo setcap cap_sys_ptrace+ep "${CMAKE_CURRENT_BINARY_DIR}/pwait"
)
add_dependencies(pwait-setcap pwait)

install(TARGETS pwait RUNTIME DESTINATION bin)
install(CODE "execute_process(COMMAND sudo setcap cap_sys_ptrace+ep pwait WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)")
12 changes: 11 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
cmake_minimum_required(VERSION 3.22)

add_test(
NAME test_pwait
NAME pwait-setcap
COMMAND sudo setcap cap_sys_ptrace+ep "$<TARGET_FILE:pwait>"
)
set_tests_properties(pwait-setcap PROPERTIES FIXTURES_SETUP pwait-setcap-fixture)

add_test(
NAME test-pwait
COMMAND "${CMAKE_CURRENT_LIST_DIR}/test_pwait.sh"
)
set_tests_properties(test-pwait PROPERTIES ENVIRONMENT PWAIT=$<TARGET_FILE:pwait>)
set_tests_properties(test-pwait PROPERTIES FIXTURES_REQUIRED pwait-setcap-fixture)
6 changes: 3 additions & 3 deletions test/test_pwait.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ start_sleep_and_exit() {
# and then store pwait's exit code in the variable pwait_exit_code.
run_pwait() {
local pid="${1?:Missing PID}"
printf "Invoking pwait on target pid %d\n" "$pid"
printf "Invoking %s on target pid %d\n" "$PWAIT" "$pid"
set +e
pwait "$pid"
"$PWAIT" "$pid"
pwait_exit_code="$?"
set -e
}
Expand Down Expand Up @@ -118,7 +118,7 @@ test_pwait_and_target_exit_times() {
trap "rm -rf '$tmpdir'" RETURN
( /usr/bin/time --format "%e" sleep "$delay" >"$tmpdir/sleep-time.txt" ) &
background_pid="$!"
/usr/bin/time --format "%e" pwait "$background_pid" >"$tmpdir/pwait-time.txt"
/usr/bin/time --format "%e" "$PWAIT" "$background_pid" >"$tmpdir/pwait-time.txt"

assert "cmp '$tmpdir/sleep-time.txt' '$tmpdir/pwait-time.txt'" "pwait and target process finished at different times"

Expand Down

0 comments on commit 02cb246

Please sign in to comment.