<commit_before>#!/bin/bash

exit_cleanup () {
	if [ "x${LOCAL_PHS_PID}" != "x" ]; then
		kill -TERM ${LOCAL_PHS_PID}
	fi
	return 0
}

set -x
CRIU_PATH="../../../criu/"
CRIU_TESTS="${CRIU_PATH}/test/zdtm/"
WDIR="$(pwd)/wdir"
PH=$(realpath ../../p.haul)
PHS=$(realpath ../../p.haul-service)
PHSSH=$(realpath ../../p.haul-ssh)

# setup EXIT trap
trap exit_cleanup EXIT

# process command line options
while [ "${#}" -gt 0 ]; do
	case $1 in
	"--local")
		LOCAL_PHS="true"
		;;
	esac
	shift
done

rm -rf "$WDIR"
mkdir "$WDIR"

# run local p.haul server in background if --local option specified
if [ "x${LOCAL_PHS}" == "xtrue" ]; then
	echo "Run local p.haul service"
	${PHS} &> "/tmp/phs.log" &
	if [ ${?} -ne 0 ]; then
		echo "Can't run local p.haul service"
		exit 1
	fi
	LOCAL_PHS_PID=$!
fi

make ct_init
if ! ./ct_init "${WDIR}/ct.log" "${WDIR}/init.pid" ./ct_init.py ${CRIU_TESTS} tests; then
	echo "Start FAIL"
	exit 1
fi

PID=$(cat "${WDIR}/init.pid")
echo "Tests started at ${PID}"

export PATH="${PATH}:${CRIU_PATH}"
which criu

echo "Migrating"
if [ "x${LOCAL_PHS}" == "xtrue" ]; then
	${PH} pid ${PID} "127.0.0.1" -v=4 --keep-images \
		--dst-rpid "${WDIR}/init2.pid" --img-path "${WDIR}"
else
	${PHSSH} --ssh-ph-exec ${PH} --ssh-phs-exec ${PHS} pid ${PID} "127.0.0.1" \
		-v=4 --keep-images --dst-rpid "${WDIR}/init2.pid" --img-path "${WDIR}"
fi

if [ ${?} -ne 0 ]; then
	echo "Migration failed"
	kill -TERM ${PID}
	exit 1
fi

PID=$(cat "${WDIR}/init2.pid")

echo "Checking results, new pid ${PID}"
kill -TERM ${PID}
WTM=1
while kill -0 ${PID}; do
	echo "Waiting to die"
	sleep ".${WTM}"
	[ $WTM -lt 9 ] && ((WTM++))<commit_msg>p.haul: adapt zdtm test to new p.haul usage semantics<commit_after>#!/bin/bash

exit_cleanup () {
	if [ "x${LOCAL_PHS_PID}" != "x" ]; then
		kill -TERM ${LOCAL_PHS_PID}
	fi
	return 0
}

set -x
CRIU_PATH="../../../criu/"
CRIU_TESTS="${CRIU_PATH}/test/zdtm/"
WDIR="$(pwd)/wdir"
PH=$(realpath ../../p.haul)
PHS=$(realpath ../../p.haul-service)
PHWRAP=$(realpath ../../p.haul-wrap)
PHSSH=$(realpath ../../p.haul-ssh)

# setup EXIT trap
trap exit_cleanup EXIT

# process command line options
while [ "${#}" -gt 0 ]; do
	case $1 in
	"--local")
		LOCAL_PHS="true"
		;;
	esac
	shift
done

rm -rf "$WDIR"
mkdir "$WDIR"

# run local p.haul server in background if --local option specified
if [ "x${LOCAL_PHS}" == "xtrue" ]; then
	echo "Run local p.haul service"
	${PHWRAP} service &> "/tmp/phs.log" &
	if [ ${?} -ne 0 ]; then
		echo "Can't run local p.haul service"
		exit 1
	fi
	LOCAL_PHS_PID=$!
fi

make ct_init
if ! ./ct_init "${WDIR}/ct.log" "${WDIR}/init.pid" ./ct_init.py ${CRIU_TESTS} tests; then
	echo "Start FAIL"
	exit 1
fi

PID=$(cat "${WDIR}/init.pid")
echo "Tests started at ${PID}"

export PATH="${PATH}:${CRIU_PATH}"
which criu

echo "Migrating"
if [ "x${LOCAL_PHS}" == "xtrue" ]; then
	${PHWRAP} client "127.0.0.1" pid ${PID} -v=4 --keep-images \
		--dst-rpid "${WDIR}/init2.pid" --img-path "${WDIR}"
else
	${PHSSH} --ssh-ph-exec ${PH} --ssh-ph-wrap-exec ${PHWRAP} \
		--ssh-phs-exec ${PHS} --ssh-phs-wrap-exec ${PHWRAP} \
		"127.0.0.1" pid ${PID} -v=4 --keep-images \
		--dst-rpid "${WDIR}/init2.pid" --img-path "${WDIR}"
fi

if [ ${?} -ne 0 ]; then
	echo "Migration failed"
	kill -TERM ${PID}
	exit 1
fi

PID=$(cat "${WDIR}/init2.pid")

echo "Checking results, new pid ${PID}"
kill -TERM ${PID}
WTM=1
while kill -0 ${PID}; do
	echo "Waiting to die"
	sleep ".${WTM}"
	[ $WTM -lt 9 ] && ((WTM++))
{'fraction_non_alphanumeric': 0.22949389179755672, 'fraction_numerical': 0.016288539848749273, 'mean_word_length': 3.282689912826899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '460346', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1461, 'n_words': 385}