Commit 16c7adec authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm: add two test cases for tty-s

* check, that pseudoterminals are restored
* check, that a control terminal is restred
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 24074a9d
...@@ -48,6 +48,8 @@ TST_NOFILE = \ ...@@ -48,6 +48,8 @@ TST_NOFILE = \
inotify00 \ inotify00 \
uptime_grow \ uptime_grow \
session00 \ session00 \
pty00 \
tty00 \
# jobctl00 \ # jobctl00 \
TST_FILE = \ TST_FILE = \
......
#define _XOPEN_SOURCE
#include <stdlib.h>
#include "zdtmtst.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <termios.h>
#include <signal.h>
const char *test_doc = "Check, that pseudoterminals are restored";
const char *test_author = "Andrey Vagin <avagin@openvz.org>";
int main(int argc, char ** argv)
{
int fdm, fds, ret;
char *slavename;
char buf[10];
const char teststr[] = "hello\n";
test_init(argc, argv);
fdm = open("/dev/ptmx", O_RDWR);
if (fdm == -1) {
err("open(%s) failed", "/dev/ptmx");
return 1;
}
grantpt(fdm);
unlockpt(fdm);
slavename = ptsname(fdm);
fds = open(slavename, O_RDWR);
if (fds == -1) {
err("open(%s) failed", slavename);
return 1;
}
/* Try to reproduce a deadlock */
if (dup2(fdm, 101) != 101) {
err("dup( , 101) failed");
return 1;
}
close(fdm);
fdm = 101;
if (dup2(fds, 100) != 100) {
err("dup( , 100) failed");
return 1;
}
close(fds);
fds = 100;
test_daemon();
test_waitsig();
signal(SIGHUP, SIG_IGN);
/* Check connectivity */
ret = write(fdm, teststr, sizeof(teststr) - 1);
if (ret != sizeof(teststr) - 1) {
err("write(fdm) failed");
return 1;
}
ret = read(fds, buf, sizeof(teststr) - 1);
if (ret != sizeof(teststr) - 1) {
err("read(fds) failed");
return 1;
}
if (strncmp(teststr, buf, sizeof(teststr) - 1)) {
fail("data mismatch");
return 1;
}
close(fdm);
close(fds);
pass();
return 0;
}
#define _XOPEN_SOURCE
#include <stdlib.h>
#include "zdtmtst.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <termios.h>
#include <sys/ioctl.h>
const char *test_doc = "Check that a control terminal is restored";
const char *test_author = "Andrey Vagin <avagin@openvz.org>";
static int sighup = 0;
static void sighup_handler(int signo)
{
test_msg("SIGHUP is here\n");
sighup = 1;
}
int main(int argc, char ** argv)
{
int fdm, fds, status;
char *slavename;
pid_t pid;
test_init(argc, argv);
fdm = open("/dev/ptmx", O_RDWR);
if (fdm == -1) {
err("Can't open a master pseudoterminal");
return 1;
}
grantpt(fdm);
unlockpt(fdm);
slavename = ptsname(fdm);
pid = test_fork();
if (pid < 0) {
err("fork() failed");
return 1;
}
if (pid == 0) {
close(fdm);
signal(SIGHUP, sighup_handler);
if (setsid() == -1)
return 1;
/* set up a controlling terminal */
fds = open(slavename, O_RDWR);
if (fds == -1) {
err("Can't open a slave pseudoterminal %s", slavename);
return 1;
}
if (ioctl(fdm, TIOCSCTTY, 1) < 0) {
err("Can't setup a controlling terminal");
return 1;
}
close(fds);
test_waitsig();
if (sighup)
return 0;
return 1;
}
test_daemon();
test_waitsig();
close(fdm);
if (kill(pid, SIGTERM) == -1) {
err("kill failed");
return 1;
}
pid = waitpid(pid, &status, 0);
if (pid < 0)
return 1;
if (WIFEXITED(status)) {
if (WEXITSTATUS(status)) {
fail("The child returned %d", WEXITSTATUS(status));
return 1;
}
} else
err("The child has been killed by %d", WTERMSIG(status));
pass();
return 0;
}
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