[CRIU] [PATCH] app-emu: Add job test
Pavel Emelyanov
xemul at parallels.com
Tue Oct 23 14:03:04 EDT 2012
On 10/23/2012 09:13 PM, Andrey Wagin wrote:
> We can create another zdtm test. App tests should be executed manually, so it's not good in this case.
Not _should_. They should be executed automatically, I'd think about this possibility instead.
> On Oct 23, 2012 7:40 PM, "Pavel Emelyanov" <xemul at parallels.com<mailto:xemul at parallels.com>> wrote:
> On 10/23/2012 11:35 AM, Andrey Vagin wrote:
>> What do you think about test/zdtm/live/static/jobctl00.c
>>
>> Why cannot it be a part of zdtm?
>
> We need test for --shell-job option. The zdtm test you point out
> tests different thing.
>
>> On Mon, Oct 22, 2012 at 08:18:34PM +0400, Cyrill Gorcunov wrote:
>>>
>>> For tty migration testing.
>>>
>>> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org<mailto:gorcunov at openvz.org>>
>>> ---
>>> test/app-emu/job/Makefile | 10 +++++
>>> test/app-emu/job/job.c | 90 +++++++++++++++++++++++++++++++++++++++++++++
>>> test/app-emu/job/job.exp | 51 +++++++++++++++++++++++++
>>> test/app-emu/job/run.sh | 3 +
>>> 4 files changed, 154 insertions(+), 0 deletions(-)
>>> create mode 100644 test/app-emu/job/Makefile
>>> create mode 100644 test/app-emu/job/job.c
>>> create mode 100755 test/app-emu/job/job.exp
>>> create mode 100644 test/app-emu/job/run.sh
>>>
>>
>>> diff --git a/test/app-emu/job/Makefile b/test/app-emu/job/Makefile
>>> new file mode 100644
>>> index 0000000..e8d572b
>>> --- /dev/null
>>> +++ b/test/app-emu/job/Makefile
>>> @@ -0,0 +1,10 @@
>>> +all: job
>>> +
>>> +%.o: %.c
>>> + gcc -c $< -o $@
>>> +
>>> +job: job.o
>>> + gcc -o $@ job.o
>>> +
>>> +clean:
>>> + rm -f *.o job
>>> diff --git a/test/app-emu/job/job.c b/test/app-emu/job/job.c
>>> new file mode 100644
>>> index 0000000..e01480a
>>> --- /dev/null
>>> +++ b/test/app-emu/job/job.c
>>> @@ -0,0 +1,90 @@
>>> +#include <stdlib.h>
>>> +#include <stdio.h>
>>> +#include <unistd.h>
>>> +
>>> +#include <sys/types.h>
>>> +#include <sys/stat.h>
>>> +#include <sys/ioctl.h>
>>> +
>>> +#include <fcntl.h>
>>> +#include <string.h>
>>> +#include <termios.h>
>>> +
>>> +#include <signal.h>
>>> +
>>> +#include <dirent.h>
>>> +
>>> +int main(int argc, char *argv[])
>>> +{
>>> + int pid, gid, sid;
>>> + int tty_sid, tty_gid;
>>> + int fd = fileno(stdout);
>>> + char buf[32];
>>> + int c = 0;
>>> + struct dirent *de;
>>> + DIR *fd_dir;
>>> +
>>> + if (!isatty(fd)) {
>>> + printf("stdout is not tty\n");
>>> + return -1;
>>> + }
>>> +
>>> + pid = getpid();
>>> + gid = getgid();
>>> + sid = getsid(pid);
>>> +
>>> + printf("pid %d gid %d sid %d\n",
>>> + pid, gid, sid);
>>> +
>>> + snprintf(buf, sizeof(buf), "/proc/%d/fd", pid);
>>> + fd_dir = opendir(buf);
>>> + if (!fd_dir) {
>>> + printf("cant open %s\n", buf);
>>> + return -1;
>>> + }
>>> +
>>> + while ((de = readdir(fd_dir))) {
>>> + int _fd;
>>> + if (!strcmp(de->d_name, "."))
>>> + continue;
>>> + if (!strcmp(de->d_name, ".."))
>>> + continue;
>>> +
>>> + _fd = atoi(de->d_name);
>>> + if (_fd > 2 && _fd != fd && isatty(_fd)) {
>>> + close(_fd);
>>> + printf("Closed %d\n", _fd);
>>> + }
>>> + }
>>> + closedir(fd_dir);
>>> +
>>> + if (ioctl(fd, TIOCGSID, &tty_sid) < 0) {
>>> + printf("cant obtain sid on stdout\n");
>>> + return -1;
>>> + }
>>> + printf("stdout sid = %d\n", tty_sid);
>>> +
>>> + if (ioctl(fd, TIOCGPGRP, &tty_gid) < 0) {
>>> + printf("cant obtain gid on stdout\n");
>>> + return -1;
>>> + }
>>> + printf("stdout gid = %d\n", tty_gid);
>>> +
>>> + printf("READY\n");
>>> +
>>> + c = 0;
>>> + while (1) {
>>> + sleep(1);
>>> + if (c++ > 10) {
>>> + printf("Too long for restore\n");
>>> + exit(-1);
>>> + }
>>> +
>>> + if (getsid(pid) != sid) {
>>> + printf("ALIVE\n");
>>> + break;
>>> + }
>>> + }
>>> +
>>> + return 0;
>>> +}
>>> diff --git a/test/app-emu/job/job.exp b/test/app-emu/job/job.exp
>>> new file mode 100755
>>> index 0000000..cf743e8
>>> --- /dev/null
>>> +++ b/test/app-emu/job/job.exp
>>> @@ -0,0 +1,51 @@
>>> +#!/usr/bin/expect
>>> +
>>> +exec rm -rf ./dump
>>> +exec mkdir ./dump
>>> +
>>> +system echo "-1" > ./dump/pid.pid
>>> +
>>> +set current [fork]
>>> +switch $current {
>>> + -1 {
>>> + puts "Fork failed."
>>> + exit -1
>>> + }
>>> + 0 {
>>> + set timeout 5
>>> + spawn ./job
>>> + set pid [exp_pid]
>>> + expect "READY" {
>>> + puts "READY"
>>> + } timeout {
>>> + puts "FAIL: Timed out on ready"
>>> + exit -1
>>> + }
>>> + system ../../../crtools dump -v 4 -D ./dump -o dump.log -j -t $pid
>>> + system echo "$pid" > ./dump/pid.pid
>>> + exit 0
>>> + }
>>> + default {
>>> + sleep 2
>>> + set timeout 5
>>> +
>>> + set ::pidfile [open ./dump/pid.pid r]
>>> + set pid [gets $::pidfile]
>>> +
>>> + if {$pid == -1} {
>>> + puts "FAIL: Invalid pid read"
>>> + exit -1
>>> + }
>>> +
>>> + spawn ../../../crtools restore -v 4 -D ./dump -o restore.log -j -t $pid
>>> +
>>> + expect "ALIVE" {
>>> + puts "PASS"
>>> + } timeout {
>>> + puts "FAIL: Timed out"
>>> + exit -1
>>> + }
>>> +
>>> + exit 0
>>> + }
>>> +}
>>> diff --git a/test/app-emu/job/run.sh b/test/app-emu/job/run.sh
>>> new file mode 100644
>>> index 0000000..1d1e0ea
>>> --- /dev/null
>>> +++ b/test/app-emu/job/run.sh
>>> @@ -0,0 +1,3 @@
>>> +#!/bin/sh
>>> +
>>> +exec expect ./job.exp
>>
>>> _______________________________________________
>>> CRIU mailing list
>>> CRIU at openvz.org<mailto:CRIU at openvz.org>
>>> https://openvz.org/mailman/listinfo/criu
>>
>> .
>>
>
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org<mailto:CRIU at openvz.org>
> https://openvz.org/mailman/listinfo/criu
> .
>
More information about the CRIU
mailing list