0001
0002
0003 #define _GNU_SOURCE
0004 #include <sched.h>
0005 #include <test_progs.h>
0006 #include <time.h>
0007 #include <sys/mman.h>
0008 #include <sys/syscall.h>
0009 #include "fexit_sleep.lskel.h"
0010
0011 static int do_sleep(void *skel)
0012 {
0013 struct fexit_sleep_lskel *fexit_skel = skel;
0014 struct timespec ts1 = { .tv_nsec = 1 };
0015 struct timespec ts2 = { .tv_sec = 10 };
0016
0017 fexit_skel->bss->pid = getpid();
0018 (void)syscall(__NR_nanosleep, &ts1, NULL);
0019 (void)syscall(__NR_nanosleep, &ts2, NULL);
0020 return 0;
0021 }
0022
0023 #define STACK_SIZE (1024 * 1024)
0024 static char child_stack[STACK_SIZE];
0025
0026 void test_fexit_sleep(void)
0027 {
0028 struct fexit_sleep_lskel *fexit_skel = NULL;
0029 int wstatus, duration = 0;
0030 pid_t cpid;
0031 int err, fexit_cnt;
0032
0033 fexit_skel = fexit_sleep_lskel__open_and_load();
0034 if (CHECK(!fexit_skel, "fexit_skel_load", "fexit skeleton failed\n"))
0035 goto cleanup;
0036
0037 err = fexit_sleep_lskel__attach(fexit_skel);
0038 if (CHECK(err, "fexit_attach", "fexit attach failed: %d\n", err))
0039 goto cleanup;
0040
0041 cpid = clone(do_sleep, child_stack + STACK_SIZE, CLONE_FILES | SIGCHLD, fexit_skel);
0042 if (CHECK(cpid == -1, "clone", "%s\n", strerror(errno)))
0043 goto cleanup;
0044
0045
0046 while (READ_ONCE(fexit_skel->bss->fentry_cnt) != 2);
0047 fexit_cnt = READ_ONCE(fexit_skel->bss->fexit_cnt);
0048 if (CHECK(fexit_cnt != 1, "fexit_cnt", "%d", fexit_cnt))
0049 goto cleanup;
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 close(fexit_skel->progs.nanosleep_fentry.prog_fd);
0062 close(fexit_skel->progs.nanosleep_fexit.prog_fd);
0063 fexit_sleep_lskel__detach(fexit_skel);
0064
0065
0066 kill(cpid, 9);
0067
0068 if (CHECK(waitpid(cpid, &wstatus, 0) == -1, "waitpid", "%s\n", strerror(errno)))
0069 goto cleanup;
0070 if (CHECK(WEXITSTATUS(wstatus) != 0, "exitstatus", "failed"))
0071 goto cleanup;
0072
0073
0074
0075
0076 fexit_cnt = READ_ONCE(fexit_skel->bss->fexit_cnt);
0077 if (CHECK(fexit_cnt != 1, "fexit_cnt", "%d", fexit_cnt))
0078 goto cleanup;
0079
0080 cleanup:
0081 fexit_sleep_lskel__destroy(fexit_skel);
0082 }