[LTP] [PATCH] syscalls/fork03: Convert into new api
Petr Vorel
pvorel@suse.cz
Wed Jun 21 14:44:23 CEST 2023
Hi Xu,
...
> #include <sys/types.h>
nit: I don't think this is needed
> +#include <unistd.h>
> #include <sys/wait.h>
> -#include <stdio.h>
> -#include "test.h"
...
> +#include <stdlib.h>
> +#include "tst_test.h"
...
> + pid1 = SAFE_FORK();
> + if (!pid1) {
> + /* child uses some cpu time slices */
> + for (i = 1; i < 32767; i++) {
> + fl1 = 0.000001;
> + fl1 = fl2 = 0.000001;
> + fl1 = fl1 * 10.0;
> + fl2 = fl1 / 1.232323;
> + fl1 = fl2 - fl2;
> + fl1 = fl2;
> }
> + if (!pid1)
> + exit(0);
> + else
> + exit(1);
nit: maybe just
exit(!!pid1);
Reviewed-by: Petr Vorel <pvorel@suse.cz>
I suggest further tiny space cleanups.
You can download it or use diff below.
https://github.com/pevik/ltp/raw/4788c24a97c2f0885a2da3a8930f27d2f15f93d3/testcases/kernel/syscalls/fork/fork03.c
Kind regards,
Petr
diff --git testcases/kernel/syscalls/fork/fork03.c testcases/kernel/syscalls/fork/fork03.c
index 072f12797..9f04c113b 100644
--- testcases/kernel/syscalls/fork/fork03.c
+++ testcases/kernel/syscalls/fork/fork03.c
@@ -1,20 +1,18 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) International Business Machines Corp., 2001
- *
- * AUTHOR
- * 07/2001 Ported by Wayne Boyer
+ * Copyright (c) Linux Test Project, 2003-2023
+ * Author: 2001 Ported by Wayne Boyer
*/
/*\
*[Description]
*
* Check that child process can use a large text space and do a large number
- * of operations. In this situation, Check for pid == 0 in child and check
- * for pid > 0 in parent after wait.
+ * of operations. In this situation, check for PID == 0 in child and check
+ * for PID > 0 in parent after wait.
*/
-#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
@@ -36,22 +34,23 @@ static void verify_fork(void)
fl1 = fl2 - fl2;
fl1 = fl2;
}
- if (!pid1)
- exit(0);
- else
- exit(1);
+
+ exit(!!pid1);
}
- tst_res(TINFO, "process id in parent of child from fork : %d", pid1);
+ tst_res(TINFO, "process id in parent of child from fork: %d", pid1);
pid2 = SAFE_WAIT(&status);
+
if (pid1 != pid2) {
- tst_res(TFAIL, "pids don't match : %d vs %d", pid1, pid2);
+ tst_res(TFAIL, "pids don't match: %d vs %d", pid1, pid2);
return;
}
+
if ((status >> 8) != 0) {
tst_res(TFAIL, "child exited with failure");
return;
}
+
tst_res(TPASS, "test PASSED");
}
More information about the ltp
mailing list