Commit ed3405cf authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

zdtm: Add cmdlinenv00 test case

To test restore of commandline, envirion
and auxv vector.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Acked-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 701142b2
...@@ -24,6 +24,7 @@ $ZP/streaming/pipe_shared00 ...@@ -24,6 +24,7 @@ $ZP/streaming/pipe_shared00
$ZP/transition/file_read $ZP/transition/file_read
$ZP/transition/fork $ZP/transition/fork
$ZP/static/zombie00 $ZP/static/zombie00
$ZP/static/cmdlinenv00
$ZP/static/socket_listen" $ZP/static/socket_listen"
CRTOOLS=`pwd`/`dirname $0`/../crtools CRTOOLS=`pwd`/`dirname $0`/../crtools
......
...@@ -27,6 +27,7 @@ TST_NOFILE = \ ...@@ -27,6 +27,7 @@ TST_NOFILE = \
pipe00 \ pipe00 \
pthread00 \ pthread00 \
vdso00 \ vdso00 \
cmdlinenv00 \
# jobctl00 \ # jobctl00 \
TST_FILE = \ TST_FILE = \
...@@ -95,6 +96,9 @@ $(TST_FILE:%=%.pid): %.pid: % ...@@ -95,6 +96,9 @@ $(TST_FILE:%=%.pid): %.pid: %
$(TST_DIR:%=%.pid): %.pid: % $(TST_DIR:%=%.pid): %.pid: %
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.test $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.test
cmdlinenv00.pid: cmdlinenv00
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --arg1=arg1 --arg2=arg2 --arg3=arg3
env00.pid: env00 env00.pid: env00
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --envname=ENV_00_TEST $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --envname=ENV_00_TEST
umask00.pid: umask00 umask00.pid: umask00
......
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "zdtmtst.h"
const char *test_doc = "Test that env/cmdline/auxv restored well\n";
const char *test_author = "Cyrill Gorcunov <gorcunov@openvz.org";
static char *arg1, *arg2, *arg3;
TEST_OPTION(arg1, string, "arg1", 1);
TEST_OPTION(arg2, string, "arg2", 1);
TEST_OPTION(arg3, string, "arg3", 1);
static void read_from_proc(const char *path, char *buf, size_t size)
{
size_t r, ret;
int fd;
fd = open(path, O_RDONLY);
if (fd < 0) {
fail("Can't open cmdline\n");
exit(1);
}
while (r < size) {
ret = read(fd, buf + r, size - r);
if (ret < 0) {
err("Read failed");
exit(1);
} else if (ret == 0) {
break;
}
r += ret;
}
close(fd);
}
int main(int argc, char *argv[])
{
char cmdline_orig[4096];
char cmdline[4096];
char env_orig[4096];
char env[4096];
char auxv_orig[1024];
char auxv[1024];
memset(cmdline_orig, 0, sizeof(cmdline_orig));
memset(cmdline, 0, sizeof(cmdline));
memset(env_orig, 0, sizeof(env_orig));
memset(env, 0, sizeof(env));
memset(auxv_orig, 0, sizeof(auxv_orig));
memset(auxv, 0, sizeof(auxv));
test_init(argc, argv);
read_from_proc("/proc/self/cmdline", cmdline_orig, sizeof(cmdline_orig));
read_from_proc("/proc/self/environ", env_orig, sizeof(env_orig));
read_from_proc("/proc/self/auxv", auxv_orig, sizeof(auxv_orig));
test_msg("old cmdline: %s\n", cmdline_orig);
test_msg("old environ: %s\n", env_orig);
test_daemon();
test_waitsig();
read_from_proc("/proc/self/cmdline", cmdline, sizeof(cmdline));
read_from_proc("/proc/self/environ", env, sizeof(env));
read_from_proc("/proc/self/auxv", auxv, sizeof(auxv));
test_msg("new cmdline: %s\n", cmdline);
test_msg("new environ: %s\n", env);
if (strncmp(cmdline_orig, cmdline, sizeof(cmdline_orig))) {
fail("cmdline corrupted on restore");
exit(1);
}
if (strncmp(env_orig, env, sizeof(env_orig))) {
fail("envirion corrupted on restore");
exit(1);
}
if (memcmp(auxv_orig, auxv, sizeof(auxv_orig))) {
fail("auxv corrupted on restore");
exit(1);
}
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