Commit 4eb37687 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

app-emu: Add job test

For tty migration testing.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent eb9b1ab2
all: job
%.o: %.c
gcc -c $< -o $@
job: job.o
gcc -o $@ job.o
clean:
rm -f *.o job
#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;
}
#!/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
}
}
#!/bin/sh
exec expect ./job.exp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment