mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-04 08:15:37 +00:00
zdtm: Test for UTS namespace
Plus a small infrastructure change to fork a test task in a desired namespace. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
committed by
Cyrill Gorcunov
parent
98f4c2e4de
commit
dcd64e9d10
19
test/zdtm.sh
19
test/zdtm.sh
@@ -28,6 +28,9 @@ $ZP/static/zombie00
|
|||||||
$ZP/static/cmdlinenv00
|
$ZP/static/cmdlinenv00
|
||||||
$ZP/static/socket_listen"
|
$ZP/static/socket_listen"
|
||||||
|
|
||||||
|
NS_TEST_LIST="\
|
||||||
|
$ZP/static/utsname"
|
||||||
|
|
||||||
CRTOOLS=`pwd`/`dirname $0`/../crtools
|
CRTOOLS=`pwd`/`dirname $0`/../crtools
|
||||||
|
|
||||||
run_test()
|
run_test()
|
||||||
@@ -43,13 +46,13 @@ run_test()
|
|||||||
dump_path=`pwd`"/"$ddump
|
dump_path=`pwd`"/"$ddump
|
||||||
mkdir -p $ddump
|
mkdir -p $ddump
|
||||||
ls -l /proc/$pid/fd/
|
ls -l /proc/$pid/fd/
|
||||||
setsid $CRTOOLS dump -D $ddump -o dump.log -t $pid || return 1
|
setsid $CRTOOLS dump -D $ddump -o dump.log -t $pid $2 || return 1
|
||||||
while :; do
|
while :; do
|
||||||
killall -9 $tname &> /dev/null || break;
|
killall -9 $tname &> /dev/null || break;
|
||||||
echo Waiting...
|
echo Waiting...
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
setsid $CRTOOLS restore -D $ddump -o restore.log -d -t $pid || return 2
|
setsid $CRTOOLS restore -D $ddump -o restore.log -d -t $pid $2 || return 2
|
||||||
ls -l /proc/$pid/fd/
|
ls -l /proc/$pid/fd/
|
||||||
make -C $tdir $tname.out
|
make -C $tdir $tname.out
|
||||||
for i in `seq 50`; do
|
for i in `seq 50`; do
|
||||||
@@ -65,12 +68,20 @@ cd `dirname $0` || exit 1
|
|||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
for t in $TEST_LIST; do
|
for t in $TEST_LIST; do
|
||||||
run_test $t || exit 1
|
run_test $t "" || exit 1
|
||||||
|
done
|
||||||
|
for t in $NS_TEST_LIST; do
|
||||||
|
run_test $t "-n" || exit 1
|
||||||
done
|
done
|
||||||
elif [ "$1" == "-l" ]; then
|
elif [ "$1" == "-l" ]; then
|
||||||
echo $TEST_LIST | sed -e "s#$ZP/##g" -e 's/ /\n/g'
|
echo $TEST_LIST | sed -e "s#$ZP/##g" -e 's/ /\n/g'
|
||||||
|
echo $NS_TEST_LIST | sed -e "s#$ZP/##g" -e 's/ /\n/g'
|
||||||
else
|
else
|
||||||
run_test $ZP/$1 && exit 0
|
if echo "$NS_TEST_LIST" | fgrep -q "$1" ; then
|
||||||
|
run_test "$ZP/$1" "-n" && exit 0
|
||||||
|
else
|
||||||
|
run_test "$ZP/$1" && exit 0
|
||||||
|
fi
|
||||||
result=$?
|
result=$?
|
||||||
echo "====================== ERROR ======================"
|
echo "====================== ERROR ======================"
|
||||||
if [ $result == 1 ]; then
|
if [ $result == 1 ]; then
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include "zdtmtst.h"
|
#include "zdtmtst.h"
|
||||||
|
|
||||||
@@ -153,6 +154,113 @@ void test_init(int argc, char **argv)
|
|||||||
srand48(time(NULL)); /* just in case we need it */
|
srand48(time(NULL)); /* just in case we need it */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define STACK_SIZE (8 * 4096)
|
||||||
|
|
||||||
|
struct zdtm_clone_arg {
|
||||||
|
int pidf;
|
||||||
|
void (*fn)(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
static int do_test_fn(void *_arg)
|
||||||
|
{
|
||||||
|
struct zdtm_clone_arg *ca = _arg;
|
||||||
|
struct sigaction sa;
|
||||||
|
|
||||||
|
/* record the test pid to remember the ownership of the pidfile */
|
||||||
|
master_pid = getpid();
|
||||||
|
|
||||||
|
fclose(ca->pidf);
|
||||||
|
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_handler = SIG_DFL;
|
||||||
|
if (sigaction(SIGCHLD, &sa, NULL)) {
|
||||||
|
err("Can't reset SIGCHLD handler: %m\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setsid() < 0) {
|
||||||
|
err("Can't become session group leader: %m\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
srand48(time(NULL)); /* just in case we need it */
|
||||||
|
|
||||||
|
ca->fn();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_init_ns(int argc, char **argv, unsigned long clone_flags, void (*fn)(void))
|
||||||
|
{
|
||||||
|
extern void parseargs(int, char **);
|
||||||
|
|
||||||
|
pid_t pid;
|
||||||
|
static FILE *pidf;
|
||||||
|
struct sigaction sa = {
|
||||||
|
.sa_handler = sig_hand,
|
||||||
|
};
|
||||||
|
struct zdtm_clone_arg ca;
|
||||||
|
void *stack;
|
||||||
|
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
|
||||||
|
if (sigaction(SIGTERM, &sa, NULL)) {
|
||||||
|
fprintf(stderr, "Can't set SIGTERM handler: %m\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sigaction(SIGCHLD, &sa, NULL)) {
|
||||||
|
fprintf(stderr, "Can't set SIGCHLD handler: %m\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
parseargs(argc, argv);
|
||||||
|
|
||||||
|
setup_outfile();
|
||||||
|
redir_stdfds();
|
||||||
|
|
||||||
|
pidf = fopen(pidfile, "wx");
|
||||||
|
if (!pidf) {
|
||||||
|
err("Can't create pid file %s: %m\n", pidfile);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
stack = mmap(NULL, STACK_SIZE, PROT_WRITE | PROT_READ,
|
||||||
|
MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS, -1, 0);
|
||||||
|
if (stack == MAP_FAILED) {
|
||||||
|
err("Can't map stack\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ca.pidf = pidf;
|
||||||
|
ca.fn = fn;
|
||||||
|
pid = clone(do_test_fn, stack + STACK_SIZE, clone_flags | SIGCHLD, &ca);
|
||||||
|
if (pid < 0) {
|
||||||
|
err("Daemonizing failed: %m\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* parent will exit when the child is ready */
|
||||||
|
test_waitsig();
|
||||||
|
|
||||||
|
if (sig_received == SIGCHLD) {
|
||||||
|
int ret;
|
||||||
|
waitpid(pid, &ret, 0);
|
||||||
|
|
||||||
|
if (WIFEXITED(ret)) {
|
||||||
|
err("Test exited with unexpectedly with code %d\n", WEXITSTATUS(ret));
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (WIFSIGNALED(ret)) {
|
||||||
|
err("Test exited on unexpected signal %d\n", WTERMSIG(ret));
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(pidf, "%d\n", pid);
|
||||||
|
fclose(pidf);
|
||||||
|
_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
void test_daemon()
|
void test_daemon()
|
||||||
{
|
{
|
||||||
pid_t ppid;
|
pid_t ppid;
|
||||||
|
@@ -5,6 +5,12 @@
|
|||||||
|
|
||||||
/* set up test */
|
/* set up test */
|
||||||
extern void test_init(int argc, char **argv);
|
extern void test_init(int argc, char **argv);
|
||||||
|
extern void test_init_ns(int argc, char **argv, unsigned long clone_flags, void (*fn)(void));
|
||||||
|
|
||||||
|
#ifndef CLONE_NEWUTS
|
||||||
|
#define CLONE_NEWUTS 0x04000000
|
||||||
|
#endif
|
||||||
|
|
||||||
/*wrapper for fork: init log offset*/
|
/*wrapper for fork: init log offset*/
|
||||||
extern int test_fork();
|
extern int test_fork();
|
||||||
/* finish setting up the test, write out pid file, and go to background */
|
/* finish setting up the test, write out pid file, and go to background */
|
||||||
|
@@ -28,6 +28,7 @@ TST_NOFILE = \
|
|||||||
pthread00 \
|
pthread00 \
|
||||||
vdso00 \
|
vdso00 \
|
||||||
cmdlinenv00 \
|
cmdlinenv00 \
|
||||||
|
utsname \
|
||||||
# jobctl00 \
|
# jobctl00 \
|
||||||
|
|
||||||
TST_FILE = \
|
TST_FILE = \
|
||||||
|
Reference in New Issue
Block a user