1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
summary: Ensure that the process-control interface works.
details: |
The process-control interface allows a snap to control other processes via signals
and nice.
A snap which defines the process-control plug must be shown in the interfaces list.
The plug must not be auto-connected on install and, as usual, must be able to be
reconnected.
A snap declaring a plug on this interface must be able to kill other processes. Currently
this test does not check the priority change capability of the interface, will be
extended later.
prepare: |
echo "Given a snap declaring a plug on the process-control interface is installed"
"$TESTSTOOLS"/snaps-state install-local process-control-consumer
execute: |
echo "The interface is disconnected by default"
snap interfaces -i process-control | MATCH -- '- +process-control-consumer:process-control'
echo "When the plug is connected"
snap connect process-control-consumer:process-control
echo "Then the snap is able to kill an existing process"
sleep 5m &
pid=$!
kill -s 0 "$pid"
process-control-consumer.signal SIGTERM "$pid"
retry -n 10 not kill -s 0 "$pid"
if [ "$(snap debug confinement)" = partial ] ; then
exit
fi
echo "When the plug is disconnected"
snap disconnect process-control-consumer:process-control
echo "Then the snap is not able to kill an existing process"
sleep 5m &
pid=$!
tests.cleanup defer "kill $pid 2>/dev/null || true"
if process-control-consumer.signal SIGTERM "$pid" 2> process-kill.error; then
echo "Expected permission error accessing killing a process with disconnected plug"
exit 1
fi
MATCH "Permission denied" < process-kill.error
kill -s 0 "$pid"
# Test passed, clean (kill) process now
tests.cleanup pop
|