Skip to content

Commit 36d5c3f

Browse files
acervmetan-ucw
authored andcommitted
Remove ltp_clone_quick usage from pidns suite
Replaced ltp_clone_quick with SAFE_CLONE inside the pidns testing suite. Fixed also errors in pidns0[12] where in previous patches we used CLONE_NEWNS instead of CLONE_NEWPID. Signed-off-by: Andrea Cervesato <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Reviwed-by: Cyril Hrubis <[email protected]>
1 parent afb30d8 commit 36d5c3f

File tree

5 files changed

+74
-49
lines changed

5 files changed

+74
-49
lines changed

testcases/kernel/containers/pidns/pidns01.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/*\
99
* [Description]
1010
*
11-
* Clone a process with CLONE_NEWNS flag and check:
11+
* Clone a process with CLONE_NEWPID flag and check:
1212
*
1313
* - child process ID must be 1
1414
* - parent process ID must be 0
@@ -17,29 +17,33 @@
1717
#include "tst_test.h"
1818
#include "lapi/sched.h"
1919

20-
static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
20+
static void child_func(void)
2121
{
2222
pid_t cpid, ppid;
2323

2424
cpid = getpid();
2525
ppid = getppid();
2626

27-
TST_EXP_PASS(cpid == 1);
28-
TST_EXP_PASS(ppid == 0);
29-
30-
return 0;
27+
TST_EXP_EQ_LI(cpid, 1);
28+
TST_EXP_EQ_LI(ppid, 0);
3129
}
3230

3331
static void run(void)
3432
{
35-
int ret;
33+
const struct tst_clone_args args = { CLONE_NEWPID, SIGCHLD };
3634

37-
ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
38-
if (ret < 0)
39-
tst_brk(TBROK | TERRNO, "clone failed");
35+
if (!SAFE_CLONE(&args)) {
36+
child_func();
37+
return;
38+
}
4039
}
4140

4241
static struct tst_test test = {
4342
.test_all = run,
4443
.needs_root = 1,
44+
.forks_child = 1,
45+
.needs_kconfigs = (const char *[]) {
46+
"CONFIG_PID_NS",
47+
NULL,
48+
},
4549
};

testcases/kernel/containers/pidns/pidns02.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/*\
88
* [Description]
99
*
10-
* Clone a process with CLONE_NEWNS flag and check:
10+
* Clone a process with CLONE_NEWPID flag and check:
1111
*
1212
* - child session ID must be 1
1313
* - parent process group ID must be 1
@@ -16,29 +16,34 @@
1616
#include "tst_test.h"
1717
#include "lapi/sched.h"
1818

19-
static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
19+
static void child_func(void)
2020
{
21-
pid_t sid, pgid;
21+
TST_EXP_EQ_LI(getsid(0), 0);
22+
TST_EXP_EQ_LI(getpgid(0), 0);
2223

23-
sid = getsid(0);
24-
pgid = getpgid(0);
24+
tst_res(TINFO, "setsid()");
25+
SAFE_SETSID();
2526

26-
TST_EXP_PASS(sid == 1);
27-
TST_EXP_PASS(pgid == 1);
28-
29-
return 0;
27+
TST_EXP_EQ_LI(getsid(0), 1);
28+
TST_EXP_EQ_LI(getpgid(0), 1);
3029
}
3130

3231
static void run(void)
3332
{
34-
int ret;
33+
const struct tst_clone_args args = { CLONE_NEWPID, SIGCHLD };
3534

36-
ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
37-
if (ret < 0)
38-
tst_brk(TBROK | TERRNO, "clone failed");
35+
if (!SAFE_CLONE(&args)) {
36+
child_func();
37+
return;
38+
}
3939
}
4040

4141
static struct tst_test test = {
4242
.test_all = run,
4343
.needs_root = 1,
44+
.forks_child = 1,
45+
.needs_kconfigs = (const char *[]) {
46+
"CONFIG_PID_NS",
47+
NULL,
48+
},
4449
};

testcases/kernel/containers/pidns/pidns03.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#define PROCDIR "proc"
1919

20-
static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
20+
static void child_func(void)
2121
{
2222
char proc_self[10];
2323

@@ -28,8 +28,6 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
2828
SAFE_UMOUNT(PROCDIR);
2929

3030
TST_EXP_PASS(strcmp(proc_self, "1"), PROCDIR"/self contains 1:");
31-
32-
return 0;
3331
}
3432

3533
static void setup(void)
@@ -45,17 +43,23 @@ static void cleanup(void)
4543

4644
static void run(void)
4745
{
48-
int ret;
46+
const struct tst_clone_args args = { CLONE_NEWPID, SIGCHLD };
4947

50-
ret = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_func, NULL);
51-
if (ret < 0)
52-
tst_brk(TBROK | TERRNO, "clone failed");
48+
if (!SAFE_CLONE(&args)) {
49+
child_func();
50+
return;
51+
}
5352
}
5453

5554
static struct tst_test test = {
5655
.test_all = run,
5756
.setup = setup,
5857
.cleanup = cleanup,
5958
.needs_root = 1,
59+
.forks_child = 1,
6060
.needs_tmpdir = 1,
61+
.needs_kconfigs = (const char *[]) {
62+
"CONFIG_PID_NS",
63+
NULL,
64+
},
6165
};

testcases/kernel/containers/pidns/pidns12.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void child_signal_handler(LTP_ATTRIBUTE_UNUSED int sig, siginfo_t *si, LT
2525
sig_pid = si->si_pid;
2626
}
2727

28-
static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
28+
static void child_func(void)
2929
{
3030
struct sigaction sa;
3131

@@ -41,27 +41,33 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
4141
TST_CHECKPOINT_WAKE_AND_WAIT(0);
4242

4343
TST_EXP_EQ_LI(sig_pid, 0);
44-
45-
return 0;
4644
}
4745

4846
static void run(void)
4947
{
50-
int ret;
48+
const struct tst_clone_args args = { CLONE_NEWPID, SIGCHLD };
49+
int pid;
5150

52-
ret = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_func, NULL);
53-
if (ret < 0)
54-
tst_brk(TBROK | TERRNO, "clone failed");
51+
pid = SAFE_CLONE(&args);
52+
if (!pid) {
53+
child_func();
54+
return;
55+
}
5556

5657
TST_CHECKPOINT_WAIT(0);
5758

58-
SAFE_KILL(ret, SIGUSR1);
59+
SAFE_KILL(pid, SIGUSR1);
5960

6061
TST_CHECKPOINT_WAKE(0);
6162
}
6263

6364
static struct tst_test test = {
6465
.test_all = run,
6566
.needs_root = 1,
67+
.forks_child = 1,
6668
.needs_checkpoints = 1,
69+
.needs_kconfigs = (const char *[]) {
70+
"CONFIG_PID_NS",
71+
NULL,
72+
},
6773
};

testcases/kernel/containers/pidns/pidns20.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void child_signal_handler(LTP_ATTRIBUTE_UNUSED int sig, siginfo_t *si, LT
2626
signals++;
2727
}
2828

29-
static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
29+
static void child_func(void)
3030
{
3131
struct sigaction sa;
3232
sigset_t newset;
@@ -37,7 +37,7 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
3737

3838
if (cpid != 1 || ppid != 0) {
3939
tst_res(TFAIL, "Got unexpected result of cpid=%d ppid=%d", cpid, ppid);
40-
return 0;
40+
return;
4141
}
4242

4343
SAFE_SIGEMPTYSET(&newset);
@@ -56,36 +56,42 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
5656

5757
if (signals != 1) {
5858
tst_res(TFAIL, "Received %d signals", signals);
59-
return 0;
59+
return;
6060
}
6161

6262
if (last_signo != SIGUSR1) {
6363
tst_res(TFAIL, "Received %s signal", tst_strsig(last_signo));
64-
return 0;
64+
return;
6565
}
6666

6767
tst_res(TPASS, "Received SIGUSR1 signal after unblock");
68-
69-
return 0;
7068
}
7169

7270
static void run(void)
7371
{
74-
int ret;
72+
const struct tst_clone_args args = { CLONE_NEWPID, SIGCHLD };
73+
int pid;
7574

76-
ret = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_func, NULL);
77-
if (ret < 0)
78-
tst_brk(TBROK | TERRNO, "clone failed");
75+
pid = SAFE_CLONE(&args);
76+
if (!pid) {
77+
child_func();
78+
return;
79+
}
7980

8081
TST_CHECKPOINT_WAIT(0);
8182

82-
SAFE_KILL(ret, SIGUSR1);
83+
SAFE_KILL(pid, SIGUSR1);
8384

8485
TST_CHECKPOINT_WAKE(0);
8586
}
8687

8788
static struct tst_test test = {
8889
.test_all = run,
8990
.needs_root = 1,
91+
.forks_child = 1,
9092
.needs_checkpoints = 1,
93+
.needs_kconfigs = (const char *[]) {
94+
"CONFIG_PID_NS",
95+
NULL,
96+
},
9197
};

0 commit comments

Comments
 (0)