Skip to content

Commit

Permalink
test: add list of tests, which should be executed for all drivers
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Vagin <[email protected]>
  • Loading branch information
avagin committed Nov 19, 2014
1 parent 574b322 commit 0b5a113
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
17 changes: 12 additions & 5 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
include ../Makefile.config

COMMON_TESTS = vz_create_exec vz_net_veth vz_enter

LOCAL_TESTS = ct_create ct_enter ct_proc ct_root ct_root_enter \
ct_create_exec ct_cgroup_basic ct_net_host \
ct_net_veth ct_private_subdir \
ct_ext_mount ct_private_subdir_ns \
ct_cgroup_sub ct_service ct_kill_nons ct_pid_enter \
ct_userns ct_caps

VZ_TESTS = vz_create_exec vz_net_veth vz_enter \
vz_cgroup_memory vz_cgroup_cpu vz_cgroup_blkio
VZ_TESTS = vz_cgroup_memory vz_cgroup_cpu vz_cgroup_blkio

TESTS = $(LOCAL_TESTS) $(VZ_TESTS)
TESTS = $(LOCAL_TESTS) $(VZ_TESTS) $(COMMON_TESTS)

PIGS = file_piggy

Expand All @@ -25,6 +26,7 @@ LDFLAGS = -Wl,--no-as-needed \
-lct -L../src/ -Wl,-rpath,'$$ORIGIN/../src' \
-lnl-route-3 -lnl-3 -L$(LIBNLDIR) -Wl,-rpath,'$$ORIGIN/$(LIBNLDIR)'

COMMON_OUTS = $(COMMON_TESTS:%=%.out)
LOCAL_OUTS = $(LOCAL_TESTS:%=%.out)
VZ_OUTS = $(VZ_TESTS:%=%.out)

Expand Down Expand Up @@ -53,6 +55,7 @@ clean: cleanouts
rm -f $(TESTS)
rm -f $(PIGS)
rm -f $(OBJS)
rm -rf root

%.o: %.c
$(CC) -c $(CFLAGS) $^ -o $@
Expand All @@ -67,10 +70,14 @@ $(1).out: $(1)
endef
$(foreach t, $(TESTS), $(eval $(call gen-out,$(t))))

run-local: cleanouts $(PIGS) $(LOCAL_OUTS)
run-local: cleanouts root $(PIGS) $(LOCAL_OUTS) $(COMMON_OUTS)

run-vz: cleanouts $(VZ_OUTS)
run-vz: cleanouts root $(VZ_OUTS) $(COMMON_OUTS)

run: cleanouts $(PIGS) $(OUTS)

root:
mkdir root
curl http://images.linuxcontainers.org/images/ubuntu/utopic/amd64/default/20141119_03:49/rootfs.tar.xz | tar -JxC root

.PHONY: all local vz clean run run-local run-vz
2 changes: 1 addition & 1 deletion test/vz_create_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "test.h"

#define FS_ROOT "/"
#define FS_ROOT "root"
int main(int argc, char *argv[])
{
libct_session_t s;
Expand Down
37 changes: 32 additions & 5 deletions test/vz_enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
#include <stdlib.h>
#include <libct.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/sched.h>
#include <sys/types.h>
#include <sys/wait.h>

#include "test.h"

#define FS_ROOT "/"
#define FS_ROOT "root"
int main(int argc, char *argv[])
{
libct_session_t s;
ct_handler_t ct;
ct_process_desc_t p;
char *sleep_a[] = { "sleep", "60", NULL};
char *ls_a[] = { "ls", "/root/work/libct/test", NULL};
char *sleep_a[] = { "cat", NULL};
char *ls_a[] = { "sh", "-c", "echo ok", NULL};
int fds[] = {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO};
int pfd[2], tfd[2], status;
char buf[10];
pid_t pid;

s = libct_session_open_local();
ct = libct_container_create(s, "1339");
Expand All @@ -28,11 +34,32 @@ int main(int argc, char *argv[])
CLONE_NEWNET |
CLONE_NEWPID);

if (libct_container_spawn_execvfds(ct, p, "/bin/sleep", sleep_a, fds) <= 0)
if (pipe(pfd))
goto err;

if (libct_container_enter_execvfds(ct, p, "/bin/ls", ls_a, fds) <= 0)
fds[0] = pfd[0];
fcntl(pfd[1], F_SETFD, FD_CLOEXEC);
if (libct_container_spawn_execvfds(ct, p, "/bin/cat", sleep_a, fds) <= 0)
goto err;
close(pfd[0]);

if (pipe(tfd))
goto err;

fds[0] = STDIN_FILENO;
fds[1] = tfd[1];
fcntl(pfd[0], F_SETFD, FD_CLOEXEC);
pid = libct_container_enter_execvfds(ct, p, "/bin/sh", ls_a, fds);
if (pid <= 0)
goto err;
close(tfd[1]);

if (read(tfd[0], buf, sizeof(buf)) != 3)
goto err;

waitpid(pid, &status, 0);

close(pfd[1]);

libct_container_wait(ct);
libct_container_destroy(ct);
Expand Down
2 changes: 1 addition & 1 deletion test/vz_net_veth.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define VETH_HOST_NAME "hveth0"
#define VETH_CT_NAME "cveth0"

#define FS_ROOT "/"
#define FS_ROOT "root"
int main(int argc, char *argv[])
{
libct_session_t s;
Expand Down

0 comments on commit 0b5a113

Please sign in to comment.