-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test/other: add test for action-script
Signed-off-by: Radostin Stoyanov <[email protected]>
- Loading branch information
Showing
6 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
img-dir-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
run: | ||
@make -C .. loop | ||
./run.sh | ||
|
||
.PHONY: run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
touch action-hook-"$CRTOOLS_SCRIPT_ACTION" | ||
|
||
vars=("E1" "E2" "E3" "E4") | ||
|
||
for var in "${vars[@]}" | ||
do | ||
if [ -n "${!var}" ]; then | ||
echo "${!var}" > "action-env-$var" | ||
fi | ||
done | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/bin/bash | ||
|
||
set -ebm | ||
|
||
# shellcheck source=test/others/env.sh | ||
source ../env.sh || exit 1 | ||
|
||
SELFDIR="$(dirname "$(readlink -f "$0")")" | ||
SCRIPT="$SELFDIR/action-script.sh" | ||
IMGDIR="$SELFDIR/img-dir-$$" | ||
|
||
rm -rf "$IMGDIR" | ||
mkdir "$IMGDIR" | ||
|
||
trap "cleanup" QUIT TERM INT HUP EXIT | ||
|
||
function cleanup() | ||
{ | ||
if [[ -n "$PID" ]]; then | ||
kill -9 "$PID" | ||
fi | ||
} | ||
|
||
PID=$(../loop) | ||
if ! $CRIU dump -v4 -o dump.log -t "$PID" -D "$IMGDIR" --action-script "$SCRIPT" --action-env E1=A --action-env E2=B; then | ||
echo "Failed to checkpoint process $PID" | ||
cat dump.log | ||
kill -9 "$PID" | ||
exit 1 | ||
fi | ||
|
||
if ! $CRIU restore -v4 -o restore.log -D "$IMGDIR" -d --pidfile test.pidfile --action-script "$SCRIPT" --action-env E3=C --action-env E4=D; then | ||
echo "CRIU restore failed" | ||
echo FAIL | ||
exit 1 | ||
fi | ||
|
||
PID=$(cat "$IMGDIR"/test.pidfile) | ||
|
||
found_missing_file=false | ||
hooks=("pre-dump" "post-dump" "pre-restore" "pre-resume" "post-restore" "post-resume") | ||
|
||
for hook in "${hooks[@]}" | ||
do | ||
if [ ! -e "$IMGDIR/action-hook-$hook" ]; then | ||
echo "ERROR: action-hook-$hook does not exist" | ||
found_missing_file=true | ||
fi | ||
done | ||
|
||
if [ "$found_missing_file" = true ]; then | ||
exit 1 | ||
fi | ||
|
||
found_mismatch=false | ||
vars=("E1:A" "E2:B" "E3:C" "E4:D") | ||
|
||
for var in "${vars[@]}" | ||
do | ||
IFS=':' read -r file expected <<< "$var" | ||
actual=$(< "$IMGDIR/action-env-$file") | ||
|
||
if [ "$actual" != "$expected" ]; then | ||
echo "ERROR: action-env-$file does not contain '$expected'." | ||
found_mismatch=true | ||
fi | ||
done | ||
|
||
if [ "$found_mismatch" = true ]; then | ||
exit 1 | ||
fi | ||
|
||
rm -rf "$IMGDIR" | ||
exit 0 |