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 Sep 6, 2023
1 parent defd37a commit 0d46cc3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
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
63 changes: 63 additions & 0 deletions test/zdtm/static/pidfd00.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#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 0d46cc3

Please sign in to comment.