Skip to content

Commit

Permalink
zdtm: Add tests for pidfd restore
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Shirvankar <[email protected]>
  • Loading branch information
h0lyalg0rithm committed Oct 12, 2023
1 parent defd37a commit 6256538
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
4 changes: 1 addition & 3 deletions criu/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ int check_img_inventory(bool restore)
int ret = -1;
struct cr_img *img;
InventoryEntry *he;
int loaded;

img = open_image(CR_FD_INVENTORY, O_RSTR);
if (!img)
return -1;

loaded = pb_read_one(img, &he, PB_INVENTORY);
if (loaded < 0)
if (pb_read_one(img, &he, PB_INVENTORY) < 0)
goto out_close;

if (!he->has_fdinfo_per_id || !he->fdinfo_per_id) {
Expand Down
2 changes: 1 addition & 1 deletion criu/include/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
#define BPFMAP_FILE_MAGIC 0x57506142 /* Alapayevsk */
#define BPFMAP_DATA_MAGIC 0x64324033 /* Arkhangelsk */
#define APPARMOR_MAGIC 0x59423047 /* Nikolskoye */
#define PIDFD_MAGIC 0x59423447
#define PIDFD_MAGIC 0x52253735 /* Livny */

#define IFADDR_MAGIC RAW_IMAGE_MAGIC
#define ROUTE_MAGIC RAW_IMAGE_MAGIC
Expand Down
1 change: 1 addition & 0 deletions test/zdtm/static/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ TST_NOFILE := \
sigtrap \
sigtrap01 \
change_mnt_context \
pidfd00 \
# jobctl00 \
PKG_CONFIG ?= pkg-config
Expand Down
64 changes: 64 additions & 0 deletions test/zdtm/static/pidfd00.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <poll.h>

#include "zdtmtst.h"

static int pidfd_open(pid_t pid, unsigned int flags)
{
return syscall(SYS_pidfd_open, pid, flags);
}

const char *test_doc = "Pidfd ";
const char *test_author = "Suraj Shirvankar <[email protected]>";

int main(int argc, char **argv)
{
int pidfd, errcode = 42;
int status;
int ret;
struct pollfd pollfd;

test_init(argc, argv);

pidfd = pidfd_open(1, 0);
if (pidfd == -1) {
perror("Couldnt open pidfd");
exit(1);
}

test_daemon();
test_waitsig();

pollfd.fd = pidfd;
pollfd.events = POLLIN;

ret = poll(&pollfd, 1, -1);
if (ret == -1) {
pr_perror("Poll error");
fail();
}

if (pollfd.revents & POLLIN) {
if (read(pidfd, &status, sizeof(status)) != sizeof(status)) {
fail("pidfd read error");
}
if (status == errcode) {
printf("Status code is %d", status);
pass();
} else {
fail("Exit code mismatch");
}
}

return 0;
}

0 comments on commit 6256538

Please sign in to comment.