Commit 5cea861d authored by Pavel Emelyanov's avatar Pavel Emelyanov

test: Add test for notifications via libcriu

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 4562c3df
all: test_sub test_self all: test_sub test_self test_notify
.PHONY: all .PHONY: all
run: all run: all
...@@ -16,9 +16,15 @@ test_self: test_self.o lib.o ...@@ -16,9 +16,15 @@ test_self: test_self.o lib.o
test_self.o: test_self.c test_self.o: test_self.c
gcc -c $^ -I ../../lib -o $@ gcc -c $^ -I ../../lib -o $@
test_notify: test_notify.o lib.o
gcc $^ -L ../../lib -lcriu -o $@
test_notify.o: test_notify.c
gcc -c $^ -I ../../lib -o $@
lib.o: lib.c lib.o: lib.c
gcc -c $^ -I ../../lib -o $@ gcc -c $^ -I ../../lib -o $@
clean: clean:
rm -rf test_sub test_sub.o test_self test_sub.o rm -rf test_sub test_sub.o test_self test_sub.o test_notify test_notify.o
.PHONY: clean .PHONY: clean
...@@ -37,6 +37,7 @@ function run_test { ...@@ -37,6 +37,7 @@ function run_test {
run_test test_sub run_test test_sub
run_test test_self run_test test_self
run_test test_notify
echo "== Stopping service" echo "== Stopping service"
kill -TERM $(cat wdir/s/pidfile) kill -TERM $(cat wdir/s/pidfile)
......
#include "criu.h"
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include "lib.h"
#define SUCC_ECODE 42
static int actions_called = 0;
static int notify(char *action)
{
printf("ACTION: %s\n", action);
actions_called++;
return 0;
}
int main(int argc, char **argv)
{
int pid, ret, fd, p[2];
printf("--- Start loop ---\n");
pipe(p);
pid = fork();
if (pid < 0) {
perror("Can't");
return -1;
}
if (!pid) {
printf(" `- loop: initializing\n");
if (setsid() < 0)
exit(1);
close(0);
close(1);
close(2);
close(p[0]);
ret = SUCC_ECODE;
write(p[1], &ret, sizeof(ret));
close(p[1]);
while (1)
sleep(1);
exit(SUCC_ECODE);
}
close(p[1]);
/* Wait for kid to start */
ret = -1;
read(p[0], &ret, sizeof(ret));
if (ret != SUCC_ECODE) {
printf("Error starting loop\n");
goto err;
}
/* Wait for pipe to get closed, then dump */
read(p[0], &ret, 1);
close(p[0]);
printf("--- Dump loop ---\n");
criu_init_opts();
criu_set_service_address(argv[1]);
criu_set_pid(pid);
criu_set_log_file("dump.log");
criu_set_log_level(4);
criu_set_notify_cb(notify);
fd = open(argv[2], O_DIRECTORY);
criu_set_images_dir_fd(fd);
ret = criu_dump();
if (ret < 0) {
what_err_ret_mean(ret);
kill(pid, SIGKILL);
goto err;
}
printf(" `- Dump succeeded\n");
ret = 0;
err:
waitpid(pid, NULL, 0);
if (ret || !actions_called) {
printf("FAIL (%d/%d)\n", ret, actions_called);
return 1;
}
printf(" `- Success (%d actions)\n", actions_called);
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