From patchwork Thu Oct 14 01:25:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanglianjie X-Patchwork-Id: 1540751 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HVBZK6rcJz9sPB for ; Thu, 14 Oct 2021 12:26:33 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CB2F63C1301 for ; Thu, 14 Oct 2021 03:26:29 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 325893C1301 for ; Thu, 14 Oct 2021 03:26:01 +0200 (CEST) Received: from smtpbgsg1.qq.com (smtpbgsg1.qq.com [54.254.200.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 5EB3C601234 for ; Thu, 14 Oct 2021 03:25:59 +0200 (CEST) X-QQ-mid: bizesmtp39t1634174740t26gb9qf Received: from localhost.localdomain (unknown [58.240.82.166]) by esmtp6.qq.com (ESMTP) with id ; Thu, 14 Oct 2021 09:25:36 +0800 (CST) X-QQ-SSF: 0140000000200040D000B00A0000000 X-QQ-FEAT: kN/DyDq8KNaS/3OqKywgdcJc4FLhEkz9FeklpSWOa0MnMTwRMZvmLV9fSvpRu 8yTjlkkxPYT6Wjl+jIps3U+XWA9dC34Hyt921LlrVPurvkZG3x2gzHalVlH/xgxgbWjmEMJ i2L33EEBpjPMINJOxj4AgWTfNJ9O86BTyghkDuTDm7Vl+E2QxQ+dUQXAqy76hsogI+VTUIV X0ONpJRLl1gGT9x1G0p3hK1flkF/PtzpQpNRKAt6vYdEgUD84trdzw4TKWBnJxXcYNcrkGL FPtAkdlErwvzSD55gUocEkHEASWoQ3NBJ9aI+wRrYqbKmf1NJ31/a0de53SMr09AiZMkH39 d/6OEDWm4Zq11+xURw= X-QQ-GoodBg: 2 From: zhanglianjie To: ltp@lists.linux.it Date: Thu, 14 Oct 2021 09:25:29 +0800 Message-Id: <20211014012533.18205-1-zhanglianjie@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign1 X-QQ-Bgrelay: 1 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v4 1/5] syscalls/clone02: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: zhanglianjie --- 2.20.1 diff --git a/testcases/kernel/syscalls/clone/clone02.c b/testcases/kernel/syscalls/clone/clone02.c index 42eea135a..cb973fdc8 100644 --- a/testcases/kernel/syscalls/clone/clone02.c +++ b/testcases/kernel/syscalls/clone/clone02.c @@ -1,468 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. * Copyright (c) 2012 Wanlong Gao - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * */ -/* - * TEST1 - * ----- - * Call clone() with all resources shared. - * - * CHILD: - * modify the shared resources - * return 1 on success - * PARENT: - * wait for child to finish - * verify that the shared resourses are modified - * return 1 on success - * If parent & child returns successfully - * test passed - * else - * test failed + +/*\ + * [Description] + * TEST1 + * - call clone() with all resources shared. + * - child modify the shared resources. + * - parent wait for child to finish. + * - verify that the shared resourses are modified. + * - if the parent shared resource is modified, then pass. * * TEST2 - * ----- - * Call clone() with no resources shared. - * - * CHILD: - * modify the resources in child's address space - * return 1 on success - * PARENT: - * wait for child to finish - * verify that the parent's resourses are not modified - * return 1 on success - * If parent & child returns successfully - * test passed - * else - * test failed + * - call clone() with no resources shared. + * - modify the resources in child's address space. + * - parent wait for child to finish. + * - verify that the parent's resourses are not modified. + * - if the parent shared resource are modified, then pass. */ -#if defined UCLINUX && !__THROW -/* workaround for libc bug */ -#define __THROW -#endif - #define _GNU_SOURCE -#include -#include -#include -#include -#include #include -#include "test.h" -#include "safe_macros.h" +#include +#include +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "clone_platform.h" +#define TESTFILE "testfile" +#define TESTDIR "testdir" #define FLAG_ALL (CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|SIGCHLD) #define FLAG_NONE SIGCHLD #define PARENT_VALUE 1 #define CHILD_VALUE 2 -#define TRUE 1 -#define FALSE 0 - -#include "clone_platform.h" - -static void setup(void); -static int test_setup(void); -static void cleanup(void); -static void test_cleanup(void); -static int child_fn(); -static int parent_test1(void); -static int parent_test2(void); -static int test_VM(void); -static int test_FS(void); -static int test_FILES(void); -static int test_SIG(void); -static int modified_VM(void); -static int modified_FS(void); -static int modified_FILES(void); -static int modified_SIG(void); -static void sig_child_defined_handler(int); -static void sig_default_handler(); static int fd_parent; -static char file_name[25]; static int parent_variable; -static char cwd_parent[FILENAME_MAX]; +static char *cwd_parent; static int parent_got_signal, child_pid; - -char *TCID = "clone02"; - -struct test_case_t { - int flags; - int (*parent_fn) (); -} test_cases[] = { - { - FLAG_ALL, parent_test1}, { - FLAG_NONE, parent_test2} +static void *child_stack; +static char cwd_child[FILENAME_MAX]; + +static char *res_name[] = { + [1] = "CLONE_VM", + [2] = "CLONE_FS", + [4] = "CLONE_FILES", + [8] = "CLONE_SIGHAND", }; -int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); - -int main(int ac, char **av) -{ - - int lc; - void *child_stack; - int status, i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - child_stack = malloc(CHILD_STACK_SIZE); - if (child_stack == NULL) - tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - for (i = 0; i < TST_TOTAL; ++i) { - if (test_setup() != 0) { - tst_resm(TWARN, "test_setup() failed, skipping this test case"); - continue; - } - - /* Test the system call */ - TEST(ltp_clone(test_cases[i].flags, child_fn, NULL, - CHILD_STACK_SIZE, child_stack)); - - /* check return code */ - if (TEST_RETURN == -1) { - tst_resm(TFAIL | TTERRNO, "clone() failed"); - /* Cleanup & continue with next test case */ - test_cleanup(); - continue; - } - - /* Wait for child to finish */ - if ((wait(&status)) == -1) { - tst_resm(TWARN | TERRNO, - "wait failed; skipping testcase"); - /* Cleanup & continue with next test case */ - test_cleanup(); - continue; - } - - if (WTERMSIG(status)) - tst_resm(TWARN, "child exitied with signal %d", - WTERMSIG(status)); - - /* - * Check the return value from child function and - * parent function. If both functions returned - * successfully, test passed, else failed - */ - if (WIFEXITED(status) && WEXITSTATUS(status) == 0 && - test_cases[i].parent_fn()) - tst_resm(TPASS, "Test Passed"); - else - tst_resm(TFAIL, "Test Failed"); - - /* Do test specific cleanup */ - test_cleanup(); - } - } - - free(child_stack); - - cleanup(); - tst_exit(); -} - -static void setup(void) +static void sig_child_defined_handler(int pid LTP_ATTRIBUTE_UNUSED) { - tst_sig(FORK, DEF_HANDLER, cleanup); - TEST_PAUSE; - tst_tmpdir(); - - /* Get unique file name for each child process */ - if ((sprintf(file_name, "parent_file_%ld", syscall(__NR_gettid))) <= 0) - tst_brkm(TBROK | TERRNO, cleanup, "sprintf() failed"); + TEST(tst_syscall(__NR_gettid)); + if (TST_RET == child_pid) + tst_res(TWARN, "Child got SIGUSR2 signal"); + else + parent_got_signal = 1; } -static void cleanup(void) +static void modify_resources(void) { - if (unlink(file_name) == -1) - tst_resm(TWARN | TERRNO, "unlink(%s) failed", file_name); - tst_rmdir(); -} + struct sigaction new_act; -static int test_setup(void) -{ + parent_variable = CHILD_VALUE; - struct sigaction def_act; + close(fd_parent); - /* Save current working directory of parent */ - if (getcwd(cwd_parent, sizeof(cwd_parent)) == NULL) { - tst_resm(TWARN | TERRNO, "getcwd() failed in test_setup()"); - return -1; - } + SAFE_CHDIR(cwd_child); - /* - * Set value for parent_variable in parent, which will be - * changed by child in test_VM(), for testing CLONE_VM flag - */ - parent_variable = PARENT_VALUE; + new_act.sa_handler = sig_child_defined_handler; + new_act.sa_flags = SA_RESTART; + SAFE_SIGEMPTYSET(&new_act.sa_mask); - /* - * Open file from parent, which will be closed by - * child in test_FILES(), used for testing CLONE_FILES flag - */ - fd_parent = open(file_name, O_CREAT | O_RDWR, 0777); - if (fd_parent == -1) { - tst_resm(TWARN | TERRNO, "open() failed in test_setup()"); - return -1; - } + SAFE_SIGACTION(SIGUSR2, &new_act, NULL); + SAFE_KILL(getppid(), SIGUSR2); +} - /* - * set parent_got_signal to FALSE, used for testing - * CLONE_SIGHAND flag - */ - parent_got_signal = FALSE; +static int verify_resources(void) +{ + char buff[20]; + char cwd[FILENAME_MAX]; - /* Setup signal handler for SIGUSR2 */ - def_act.sa_handler = sig_default_handler; - def_act.sa_flags = SA_RESTART; - sigemptyset(&def_act.sa_mask); + unsigned int changed = 0; - if (sigaction(SIGUSR2, &def_act, NULL) == -1) { - tst_resm(TWARN | TERRNO, "sigaction() failed in test_setup()"); - return -1; - } + if (parent_variable == CHILD_VALUE) + changed |= CLONE_VM; - return 0; -} + if (((read(fd_parent, buff, sizeof(buff))) == -1) && (errno == EBADF)) + changed |= CLONE_FS; + else + SAFE_CLOSE(fd_parent); -static void test_cleanup(void) -{ + SAFE_GETCWD(cwd, sizeof(cwd)); + if (strcmp(cwd, cwd_parent)) + changed |= CLONE_FILES; - /* Restore parent's working directory */ - SAFE_CHDIR(cleanup, cwd_parent); + if (parent_got_signal) + changed |= CLONE_SIGHAND; + return changed; } -static int child_fn(void) +static void sig_parent_default_handler(int pid LTP_ATTRIBUTE_UNUSED) { - /* save child pid */ - child_pid = syscall(__NR_gettid); - - if (test_VM() == 0 && test_FILES() == 0 && test_FS() == 0 && - test_SIG() == 0) - _exit(0); - _exit(1); } -static int parent_test1(void) +static int child_fn(void *arg LTP_ATTRIBUTE_UNUSED) { + TEST(tst_syscall(__NR_gettid)); + child_pid = TST_RET; - /* - * For first test case (with all flags set), all resources are - * shared between parent and child. So whatever changes made by - * child should get reflected in parent also. modified_*() - * functions check this. All of them should return 1 for - * parent_test1() to return 1 - */ - - if (modified_VM() && modified_FILES() && modified_FS() && - modified_SIG()) - return 0; - return -1; + modify_resources(); + _exit(0); } -static int parent_test2(void) +static void reset_resources(void) { + struct sigaction def_act; - /* - * For second test case (with no resouce shared), all of the - * modified_*() functions should return 0 for parent_test2() - * to return 1 - */ - if (modified_VM() || modified_FILES() || modified_FS() || - modified_SIG()) - return 0; + parent_variable = PARENT_VALUE; + fd_parent = SAFE_OPEN(TESTFILE, O_CREAT | O_RDWR, 0777); + parent_got_signal = 0; + SAFE_CHDIR(cwd_parent); - return -1; + def_act.sa_handler = sig_parent_default_handler; + def_act.sa_flags = SA_RESTART; + SAFE_SIGEMPTYSET(&def_act.sa_mask); + SAFE_SIGACTION(SIGUSR2, &def_act, NULL); } -/* - * test_VM() - function to change parent_variable from child's - * address space. If CLONE_VM flag is set, child shares - * the memory space with parent so this will be visible - * to parent also. - */ - -static int test_VM(void) -{ - parent_variable = CHILD_VALUE; - return 0; -} +struct tcase { + unsigned long flags; + char *desc; +} tcases[] = { + {FLAG_ALL, "clone() with all resources shared"}, + {FLAG_NONE, "clone() with all no resources shared"} +}; -/* - * test_FILES() - This function closes a file descriptor opened by - * parent. If CLONE_FILES flag is set, the parent and - * the child process share the same file descriptor - * table. so this affects the parent also - */ -static int test_FILES(void) +static void verify_clone(unsigned int tc) { - if (close(fd_parent) == -1) { - tst_resm(TWARN | TERRNO, "close failed in test_FILES"); - return -1; - } - return 0; -} + unsigned int flag; + unsigned int i; -/* - * test_FS() - This function changes the current working directory - * of the child process. If CLONE_FS flag is set, this - * will be visible to parent also. - */ -static int test_FS(void) -{ - char *test_tmpdir; - int rval; - - test_tmpdir = tst_get_tmpdir(); - if (test_tmpdir == NULL) { - tst_resm(TWARN | TERRNO, "tst_get_tmpdir failed"); - rval = -1; - } else if (chdir(test_tmpdir) == -1) { - tst_resm(TWARN | TERRNO, "chdir failed in test_FS"); - rval = -1; - } else { - rval = 0; - } + tst_res(TINFO, "%s", tcases[tc].desc); - free(test_tmpdir); - return rval; -} + reset_resources(); -/* - * test_SIG() - This function changes the signal handler for SIGUSR2 - * signal for child. If CLONE_SIGHAND flag is set, this - * affects parent also. - */ -static int test_SIG(void) -{ + TST_EXP_PID_SILENT(ltp_clone(tcases[tc].flags, child_fn, NULL, + CHILD_STACK_SIZE, child_stack)); - struct sigaction new_act; + if (!TST_PASS) + return; - new_act.sa_handler = sig_child_defined_handler; - new_act.sa_flags = SA_RESTART; - sigemptyset(&new_act.sa_mask); + tst_reap_children(); - /* Set signal handler to sig_child_defined_handler */ - if (sigaction(SIGUSR2, &new_act, NULL) == -1) { - tst_resm(TWARN | TERRNO, "signal failed in test_SIG"); - return -1; - } + flag = verify_resources(); - /* Send SIGUSR2 signal to parent */ - if (kill(getppid(), SIGUSR2) == -1) { - tst_resm(TWARN | TERRNO, "kill failed in test_SIG"); - return -1; + for (i = CLONE_VM; i <= CLONE_SIGHAND; i <<= 1) { + if (tcases[tc].flags == FLAG_ALL) { + if (flag & i) + tst_res(TPASS, "The resource %s of the parent process has changed", res_name[i >> 8]); + else + tst_res(TFAIL, "The resource %s of the parent process has not changed", res_name[i >> 8]); + } else { + if (flag & i) + tst_res(TFAIL, "The resource %s of the parent process has changed", res_name[i >> 8]); + else + tst_res(TPASS, "The resource %s of the parent process has not changed", res_name[i >> 8]); + } } - - return 0; -} - -/* - * modified_VM() - This function is called by parent process to check - * whether child's modification to parent_variable - * is visible to parent - */ - -static int modified_VM(void) -{ - - if (parent_variable == CHILD_VALUE) - /* child has modified parent_variable */ - return 1; - - return 0; } -/* - * modified_FILES() - This function checks for file descriptor table - * modifications done by child - */ -static int modified_FILES(void) +static void cleanup(void) { - char buff[20]; - - if (((read(fd_parent, buff, sizeof(buff))) == -1) && (errno == EBADF)) - /* Child has closed this file descriptor */ - return 1; - - /* close fd_parent */ - if ((close(fd_parent)) == -1) - tst_resm(TWARN | TERRNO, "close() failed in modified_FILES()"); - - return 0; + SAFE_CHDIR(cwd_parent); + SAFE_UNLINK(TESTFILE); + free(cwd_parent); } -/* - * modified_FS() - This function checks parent's current working directory - * to see whether its modified by child or not. - */ -static int modified_FS(void) +static void setup(void) { - char cwd[FILENAME_MAX]; - - if ((getcwd(cwd, sizeof(cwd))) == NULL) - tst_resm(TWARN | TERRNO, "getcwd() failed"); - - if (!(strcmp(cwd, cwd_parent))) - /* cwd hasn't changed */ - return 0; - - return 1; -} + struct sigaction def_act; -/* - * modified_SIG() - This function checks whether child has changed - * parent's signal handler for signal, SIGUSR2 - */ -static int modified_SIG(void) -{ + /* Save current working directory of parent */ + cwd_parent = tst_get_tmpdir(); - if (parent_got_signal) - /* - * parent came through sig_child_defined_handler() - * this means child has changed parent's handler - */ - return 1; + /* + * Set value for parent_variable in parent, which will be + * changed by child for testing CLONE_VM flag + */ + parent_variable = PARENT_VALUE; - return 0; -} + /* + * Open file from parent, which will be closed by + * child, used for testing CLONE_FILES flag + */ + fd_parent = SAFE_OPEN(TESTFILE, O_CREAT | O_RDWR, 0777); -/* - * sig_child_defined_handler() - Signal handler installed by child - */ -static void sig_child_defined_handler(int pid) -{ - if ((syscall(__NR_gettid)) == child_pid) - /* Child got signal, give warning */ - tst_resm(TWARN, "Child got SIGUSR2 signal"); - else - parent_got_signal = TRUE; -} + /* + * set parent_got_signal to 0, used for testing + * CLONE_SIGHAND flag + */ + parent_got_signal = 0; -/* sig_default_handler() - Default handler for parent */ -static void sig_default_handler(void) -{ -} + def_act.sa_handler = sig_parent_default_handler; + def_act.sa_flags = SA_RESTART; + SAFE_SIGEMPTYSET(&def_act.sa_mask); + SAFE_SIGACTION(SIGUSR2, &def_act, NULL); + + SAFE_MKDIR(TESTDIR, 0777); + sprintf(cwd_child, "%s/%s", cwd_parent, TESTDIR); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .tcnt = ARRAY_SIZE(tcases), + .test = verify_clone, + .bufs = (struct tst_buffers []) { + {&child_stack, .size = CHILD_STACK_SIZE}, + }, + .needs_tmpdir = 1, +}; From patchwork Thu Oct 14 01:25:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanglianjie X-Patchwork-Id: 1540752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HVBZm4H2Gz9sPB for ; Thu, 14 Oct 2021 12:26:56 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C71D73C12AD for ; Thu, 14 Oct 2021 03:26:53 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id C53E23C0B90 for ; Thu, 14 Oct 2021 03:26:51 +0200 (CEST) Received: from smtpbgsg1.qq.com (smtpbgsg1.qq.com [54.254.200.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 953581A017C2 for ; Thu, 14 Oct 2021 03:26:49 +0200 (CEST) X-QQ-mid: bizesmtp39t1634174745txa8f2sf Received: from localhost.localdomain (unknown [58.240.82.166]) by esmtp6.qq.com (ESMTP) with id ; Thu, 14 Oct 2021 09:25:41 +0800 (CST) X-QQ-SSF: 0140000000200040D000B00A0000000 X-QQ-FEAT: lC5HeAtE+yb+CFINW3PwIK/2tR4ON6VxDohsZjKzbD6Uy2NswR6Jo9SrAKhCW X+1Z9G8Qi8MeTJI0CgzRhDOa7ovQiupabSpM1Yn5R+WGH5Qqh2vMKzrWsTbZ2KO4HD2EKgz uE8s/r/ZzdwF+BQqEiEj6fDBBy1+C3dXCmlQlhTCma5wQFkmnGN5u9pE2Nfiiwvrs0QzaI7 DW8rYtbWqOlDCpentSNN+sdhu0MgH6yjFtvyYTEetid3BjJFhhmVn5xA18hKuGngpaw0Wg4 ENc4Vv+70MfEC3c9pxM8koMiDzXo7vgtX6Mo9AsloKupkM2mAVb26RjN7J8bW8ZUVRR9lkG McFTYY8qMaXEmg70ZJjdz7NOfuNhiyahyH7+lvO X-QQ-GoodBg: 2 From: zhanglianjie To: ltp@lists.linux.it Date: Thu, 14 Oct 2021 09:25:30 +0800 Message-Id: <20211014012533.18205-2-zhanglianjie@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211014012533.18205-1-zhanglianjie@uniontech.com> References: <20211014012533.18205-1-zhanglianjie@uniontech.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign5 X-QQ-Bgrelay: 1 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v4 2/5] syscalls/clone03: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: zhanglianjie --- 2.20.1 diff --git a/testcases/kernel/syscalls/clone/clone03.c b/testcases/kernel/syscalls/clone/clone03.c index f4216ead8..70c37d495 100644 --- a/testcases/kernel/syscalls/clone/clone03.c +++ b/testcases/kernel/syscalls/clone/clone03.c @@ -1,147 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. * Copyright (c) 2012 Wanlong Gao - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * */ -/* + +/*\ + * [Description] * Check for equality of pid of child & return value of clone(2) - * Test: - * Open a pipe. - * Loop if the proper options are given. - * Call clone(2) called without SIGCHLD - * - * CHILD: - * writes the pid to pipe - * PARENT: - * reads child'd pid from pipe - * if child's pid == return value from clone(2) - * Test passed - * else - * test failed */ - -#if defined UCLINUX && !__THROW -/* workaround for libc bug */ -#define __THROW -#endif - -#include -#include -#include -#include "test.h" - +#include +#include +#include "tst_test.h" #include "clone_platform.h" -static void setup(void); -static void cleanup(void); -static int child_fn(); - -static int pfd[2]; - -char *TCID = "clone03"; -int TST_TOTAL = 1; +static void *child_stack; +static int *child_pid; -int main(int ac, char **av) +static int child_fn(void *arg LTP_ATTRIBUTE_UNUSED) { + *child_pid = getpid(); + exit(0); +} - int lc; - void *child_stack; - char buff[10]; - int child_pid, status; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - /* Allocate stack for child */ - child_stack = malloc(CHILD_STACK_SIZE); - if (child_stack == NULL) - tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - if ((pipe(pfd)) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "pipe failed"); - - TEST(ltp_clone(SIGCHLD, child_fn, NULL, CHILD_STACK_SIZE, - child_stack)); - - if (TEST_RETURN == -1) - tst_brkm(TFAIL | TTERRNO, cleanup, "clone() failed"); - - /* close write end from parent */ - if ((close(pfd[1])) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "close(pfd[1]) failed"); - - /* Read pid from read end */ - if ((read(pfd[0], buff, sizeof(buff))) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "read from pipe failed"); - - /* Close read end from parent */ - if ((close(pfd[0])) == -1) - tst_resm(TWARN | TERRNO, "close(pfd[0]) failed"); - - /* Get child's pid from pid string */ - child_pid = atoi(buff); +static void verify_clone(void) +{ - if (TEST_RETURN == child_pid) - tst_resm(TPASS, "Test passed"); - else - tst_resm(TFAIL, "Test failed"); + TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, child_fn, NULL, CHILD_STACK_SIZE, + child_stack)); - if ((wait(&status)) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "wait failed, status: %d", status); - } + if (!TST_PASS) + return; - free(child_stack); + tst_reap_children(); - cleanup(); - tst_exit(); + TST_EXP_VAL(TST_RET, *child_pid, "pid(%d)", *child_pid); } static void setup(void) { - tst_sig(FORK, DEF_HANDLER, cleanup); - TEST_PAUSE; + child_pid = SAFE_MMAP(NULL, sizeof(*child_pid), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); } static void cleanup(void) { + if (child_pid) + SAFE_MUNMAP(child_pid, sizeof(*child_pid)); } -static int child_fn(void) -{ - char pid[10]; - - /* Close read end from child */ - if ((close(pfd[0])) == -1) - perror("close(pfd[0]) failed"); - - sprintf(pid, "%d", getpid()); - - /* Write pid string to pipe */ - if ((write(pfd[1], pid, sizeof(pid))) == -1) - perror("write to pipe failed"); - - /* Close write end of pipe from child */ - if ((close(pfd[1])) == -1) - perror("close(pfd[1]) failed"); - - exit(1); -} +static struct tst_test test = { + .setup = setup, + .test_all = verify_clone, + .bufs = (struct tst_buffers []) { + {&child_stack, .size = CHILD_STACK_SIZE}, + {}, + }, + .cleanup = cleanup, +}; From patchwork Thu Oct 14 01:25:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanglianjie X-Patchwork-Id: 1540748 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HVBYl6pHcz9sPB for ; Thu, 14 Oct 2021 12:26:03 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 94A263C12F8 for ; Thu, 14 Oct 2021 03:26:00 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 8F1D93C0B90 for ; Thu, 14 Oct 2021 03:25:58 +0200 (CEST) Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 70B45201128 for ; Thu, 14 Oct 2021 03:25:54 +0200 (CEST) X-QQ-mid: bizesmtp39t1634174747t2anz27a Received: from localhost.localdomain (unknown [58.240.82.166]) by esmtp6.qq.com (ESMTP) with id ; Thu, 14 Oct 2021 09:25:46 +0800 (CST) X-QQ-SSF: 0140000000200040D000B00A0000000 X-QQ-FEAT: 0VgNaGdhy9id1dE1vi/KVwarrnS2Etpv9JwGEgYyBBWLLtePdOFYfQBlbfPSM M/NFzAQeXVwfYxaPGyyaxy4vMT/ha8jI5HwVqN+dp9gO5EW03Oi5mgCWZnyBHZivW/g/uXR pVWcrpT712kdtqplfMep1SlBOsuFyGMNFfPRzrLe9fQgWX7U/tCTQHhTrE9fmu42iyfeUh4 6n8wIho2BJMoD6Y9GR5fIA50HKYtS+YZHFX7nrLonposP2NljYz3i5OjgXFaQEtex9flgS1 E3KyuKyJFVzwOB/7QdnL30Y4BEgtsOEy/qv03GFewa5Vc8TRQST4q70pIpGH4yvzJTCTDI3 JGUZTUAjqFg0R7UaED2J0JxjVEQGQ== X-QQ-GoodBg: 2 From: zhanglianjie To: ltp@lists.linux.it Date: Thu, 14 Oct 2021 09:25:31 +0800 Message-Id: <20211014012533.18205-3-zhanglianjie@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211014012533.18205-1-zhanglianjie@uniontech.com> References: <20211014012533.18205-1-zhanglianjie@uniontech.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign1 X-QQ-Bgrelay: 1 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v4 3/5] syscalls/clone05: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: zhanglianjie --- 2.20.1 diff --git a/testcases/kernel/syscalls/clone/clone05.c b/testcases/kernel/syscalls/clone/clone05.c index 494b772dd..69816ece6 100644 --- a/testcases/kernel/syscalls/clone/clone05.c +++ b/testcases/kernel/syscalls/clone/clone05.c @@ -1,103 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. * Copyright (c) 2012 Wanlong Gao * Copyright (c) 2012 Cyril Hrubis - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * */ -/* +/*\ + * [Description] * Call clone() with CLONE_VFORK flag set. verify that * execution of parent is suspended until child finishes */ #define _GNU_SOURCE -#include +#include #include -#include -#include "test.h" +#include "tst_test.h" #include "clone_platform.h" -char *TCID = "clone05"; -int TST_TOTAL = 1; - -static void setup(void); -static void cleanup(void); -static int child_fn(void *); +static volatile int child_exited; +static void *child_stack; -static int child_exited = 0; - -int main(int ac, char **av) +static int child_fn(void *unused LTP_ATTRIBUTE_UNUSED) { + int i; - int lc, status; - void *child_stack; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - child_stack = malloc(CHILD_STACK_SIZE); - if (child_stack == NULL) - tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - TEST(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL, - CHILD_STACK_SIZE, child_stack)); - - if ((TEST_RETURN != -1) && (child_exited)) - tst_resm(TPASS, "Test Passed"); - else - tst_resm(TFAIL, "Test Failed"); - - if ((wait(&status)) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "wait failed, status: %d", status); - - child_exited = 0; + for (i = 0; i < 100; i++) { + sched_yield(); + usleep(1000); } - free(child_stack); - - cleanup(); - tst_exit(); + child_exited = 1; + _exit(0); } -static void setup(void) +static void verify_clone(void) { - tst_sig(FORK, DEF_HANDLER, cleanup); + child_exited = 0; + + TST_EXP_PID_SILENT(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL, + CHILD_STACK_SIZE, child_stack), "clone with vfork"); - TEST_PAUSE; -} + if (!TST_PASS) + return; -static void cleanup(void) -{ + TST_EXP_VAL(child_exited, 1); } -static int child_fn(void *unused __attribute__((unused))) -{ - int i; - - /* give the kernel scheduler chance to run the parent */ - for (i = 0; i < 100; i++) { - sched_yield(); - usleep(1000); - } - - child_exited = 1; - _exit(1); -} +static struct tst_test test = { + .test_all = verify_clone, + .bufs = (struct tst_buffers []) { + {&child_stack, .size = CHILD_STACK_SIZE}, + {}, + }, +}; From patchwork Thu Oct 14 01:25:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanglianjie X-Patchwork-Id: 1540749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HVBYx4h4wz9sPB for ; Thu, 14 Oct 2021 12:26:13 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CAD5C3C12B6 for ; Thu, 14 Oct 2021 03:26:10 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 0E6523C0B90 for ; Thu, 14 Oct 2021 03:25:57 +0200 (CEST) Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 0562D1000BD4 for ; Thu, 14 Oct 2021 03:25:54 +0200 (CEST) X-QQ-mid: bizesmtp39t1634174750t4x3doai Received: from localhost.localdomain (unknown [58.240.82.166]) by esmtp6.qq.com (ESMTP) with id ; Thu, 14 Oct 2021 09:25:48 +0800 (CST) X-QQ-SSF: 0140000000200040D000B00A0000000 X-QQ-FEAT: jfdGVjI73+QwJrYKFkpRkwor651op69BxGalbMaipUHWZT5XRSotFZ2RZugDt 3TD92vO6haMfDbRhWIstQBNXsGuIxaZkEMvC9Ta4EHeoOhIAjhE1z5cTkQHq/DoP5jpkgrb aEMH7bFUBNURiF1cPwrv3yilPeRqeqtO4P9Dix6tIcdkMO//kCuFRh7EiTIKmcJqAGCmixc jJt9OUmZK1eSISqr8iP0HUV6yIBcRebFm8WEMlluDuGq6DBiBn29qIM9lLbaM3F3uT66eiW zCcEgZW6bIb3vpSet6RpBMGa03Z5mDL3XOZNXxxXT+3NiVAZFzGZ0XoN7wV3X+CsqhVHUpu 3fX4QZviY1MtEC1u7Eia7+5fUMSLfKNzXw4KCMG X-QQ-GoodBg: 2 From: zhanglianjie To: ltp@lists.linux.it Date: Thu, 14 Oct 2021 09:25:32 +0800 Message-Id: <20211014012533.18205-4-zhanglianjie@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211014012533.18205-1-zhanglianjie@uniontech.com> References: <20211014012533.18205-1-zhanglianjie@uniontech.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign7 X-QQ-Bgrelay: 1 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v4 4/5] syscalls/clone06: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: zhanglianjie --- 2.20.1 diff --git a/testcases/kernel/syscalls/clone/clone06.c b/testcases/kernel/syscalls/clone/clone06.c index 99e7f3864..8337b5d90 100644 --- a/testcases/kernel/syscalls/clone/clone06.c +++ b/testcases/kernel/syscalls/clone/clone06.c @@ -1,140 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. * Copyright (c) 2012 Wanlong Gao - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * */ -/* - * Test to verify inheritance of environment variables by child. +/*\ + * [Description] + * Test to verify inheritance of environment variables by child. */ -#if defined UCLINUX && !__THROW -/* workaround for libc bug */ -#define __THROW -#endif - -#include +#include +#include #include -#include -#include -#include "test.h" +#include "tst_test.h" #include "clone_platform.h" #define MAX_LINE_LENGTH 256 +#define ENV_VAL "LTP test variable value" +#define ENV_ID "LTP_CLONE_TEST" -static void setup(void); -static void cleanup(void); -static int child_environ(); - -static int pfd[2]; +static void *child_stack; -char *TCID = "clone06"; -int TST_TOTAL = 1; - -int main(int ac, char **av) +static int child_environ(void *arg LTP_ATTRIBUTE_UNUSED) { - - int lc, status; - void *child_stack; - char *parent_env; - char buff[MAX_LINE_LENGTH]; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - child_stack = malloc(CHILD_STACK_SIZE); - if (child_stack == NULL) - tst_brkm(TBROK, cleanup, "Cannot allocate stack for child"); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - if ((pipe(pfd)) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "pipe() failed"); - - TEST(ltp_clone(SIGCHLD, child_environ, NULL, CHILD_STACK_SIZE, - child_stack)); - - if (TEST_RETURN == -1) - tst_brkm(TFAIL | TTERRNO, cleanup, "clone failed"); - - /* close write end from parent */ - if ((close(pfd[1])) == -1) - tst_resm(TWARN | TERRNO, "close(pfd[1]) failed"); - - /* Read env var from read end */ - if ((read(pfd[0], buff, sizeof(buff))) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "read from pipe failed"); - - /* Close read end from parent */ - if ((close(pfd[0])) == -1) - tst_resm(TWARN | TERRNO, "close(pfd[0]) failed"); - - parent_env = getenv("TERM") ? : ""; - - if ((strcmp(buff, parent_env)) == 0) - tst_resm(TPASS, "Test Passed"); - else - tst_resm(TFAIL, "Test Failed"); - - if ((wait(&status)) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "wait failed, status: %d", status); + const char *env_val = getenv(ENV_ID); + if (!env_val) { + tst_res(TFAIL, "Variable " ENV_ID " not defined in child"); + exit(-1); } - free(child_stack); + if (strcmp(env_val, ENV_VAL)) { + tst_res(TFAIL, "Variable value is different"); + exit(-1); + } + + tst_res(TPASS, "The environment variables of the child and the parent are the same "); - cleanup(); - tst_exit(); + exit(0); } -static void setup(void) +static void verify_clone(void) { - tst_sig(FORK, DEF_HANDLER, cleanup); - TEST_PAUSE; -} + TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, child_environ, NULL, CHILD_STACK_SIZE, + child_stack)); -static void cleanup(void) -{ + if (!TST_PASS) + return; + + tst_reap_children(); } -/* - * Function executed by child. - * Gets the value for environment variable,TERM & - * writes it to a pipe. - */ -static int child_environ(void) +static void setup(void) { - - char var[MAX_LINE_LENGTH]; - - /* Close read end from child */ - if ((close(pfd[0])) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "close(pfd[0]) failed"); - - if ((sprintf(var, "%s", getenv("TERM") ? : "")) < 0) - tst_resm(TWARN | TERRNO, "sprintf() failed"); - - if ((write(pfd[1], var, MAX_LINE_LENGTH)) == -1) - tst_resm(TWARN | TERRNO, "write to pipe failed"); - - /* Close write end of pipe from child */ - if ((close(pfd[1])) == -1) - tst_resm(TWARN | TERRNO, "close(pfd[1]) failed"); - - exit(0); + SAFE_SETENV(ENV_ID, ENV_VAL, 0); } + +static struct tst_test test = { + .setup = setup, + .test_all = verify_clone, + .bufs = (struct tst_buffers []) { + {&child_stack, .size = CHILD_STACK_SIZE}, + {}, + }, +}; From patchwork Thu Oct 14 01:25:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanglianjie X-Patchwork-Id: 1540750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HVBZ70rSdz9sPB for ; Thu, 14 Oct 2021 12:26:23 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9B0883C12A9 for ; Thu, 14 Oct 2021 03:26:20 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 571393C12CF for ; Thu, 14 Oct 2021 03:26:00 +0200 (CEST) Received: from smtpbg516.qq.com (smtpbg516.qq.com [203.205.250.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 6C33A14013A5 for ; Thu, 14 Oct 2021 03:25:57 +0200 (CEST) X-QQ-mid: bizesmtp39t1634174752tnur10j7 Received: from localhost.localdomain (unknown [58.240.82.166]) by esmtp6.qq.com (ESMTP) with id ; Thu, 14 Oct 2021 09:25:51 +0800 (CST) X-QQ-SSF: 0140000000200040D000B00A0000000 X-QQ-FEAT: jfdGVjI73+SdQ5BqPkUEZLp/coFRC7kp52qVKlk3oxnEFtXyCobyYNP6b4hBe p6Xa/kuk/r2oQzIzpA6DvcoY7Y3s8piVwlMepdYrvn0FzIxifO4rjHy9wYSoECnsHjl9Scd dIjb11GeQurWqPuaIl8BC13pekm6tiB3Z8YYLsYp6Qm+AQFNgMuzgMLgZhfnxBD2dgVnTLP Yz/Hw7hJtWRdADOEDsT1bLhN6MifjRgYAu+qZQ9ICsOVLjncjSSWaHKISf3HEdYcmMWKYrQ fVWd3QBC+bjmOHrTvM/l61fwnVHdbE0+qivS0beZL7QNHmxg0fiKFXIeQzOH459IvIQnXKB wnHoOp5GMOAclxT3rLHvOfXJT2CsQ== X-QQ-GoodBg: 2 From: zhanglianjie To: ltp@lists.linux.it Date: Thu, 14 Oct 2021 09:25:33 +0800 Message-Id: <20211014012533.18205-5-zhanglianjie@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211014012533.18205-1-zhanglianjie@uniontech.com> References: <20211014012533.18205-1-zhanglianjie@uniontech.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign1 X-QQ-Bgrelay: 1 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v4 5/5] syscalls/clone07: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: zhanglianjie --- 2.20.1 diff --git a/testcases/kernel/syscalls/clone/clone07.c b/testcases/kernel/syscalls/clone/clone07.c index 4b2e04ee7..2c5931907 100644 --- a/testcases/kernel/syscalls/clone/clone07.c +++ b/testcases/kernel/syscalls/clone/clone07.c @@ -1,128 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) International Business Machines Corp., 2003. * Copyright (c) 2012 Wanlong Gao - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ -/* - * This is a test for a glibc bug for the clone(2) system call. */ -#if defined UCLINUX && !__THROW -/* workaround for libc bug */ -#define __THROW -#endif +/*\ + * [Description] + * Test for a libc bug where exitting child function by returning from + * it caused SIGSEGV. + */ -#include #include -#include -#include "test.h" +#include +#include +#include "tst_test.h" +#include "lapi/syscalls.h" #include "clone_platform.h" -#define TRUE 1 -#define FALSE 0 - -static void setup(); -static int do_child(); +static void *child_stack; -char *TCID = "clone07"; -int TST_TOTAL = 1; - -static void sigsegv_handler(int); -static void sigusr2_handler(int); -static int child_pid; -static int fail = FALSE; - -int main(int ac, char **av) +static int do_child(void *arg LTP_ATTRIBUTE_UNUSED) { - - int lc, status; - void *child_stack; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - child_stack = malloc(CHILD_STACK_SIZE); - if (child_stack == NULL) - tst_brkm(TBROK, NULL, - "Cannot allocate stack for child"); - - child_pid = ltp_clone(SIGCHLD, do_child, NULL, - CHILD_STACK_SIZE, child_stack); - - if (child_pid < 0) - tst_brkm(TBROK | TERRNO, NULL, "clone failed"); - - if ((wait(&status)) == -1) - tst_brkm(TBROK | TERRNO, NULL, - "wait failed, status: %d", status); - - free(child_stack); - } - - if (fail == FALSE) - tst_resm(TPASS, - "Use of return() in child did not cause SIGSEGV"); - else - tst_resm(TFAIL, "Use of return() in child caused SIGSEGV"); - - tst_exit(); + return 0; } -static void setup(void) +static void verify_clone(void) { - struct sigaction def_act; - struct sigaction act; + int status; + pid_t pid = 0; - TEST_PAUSE; + TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, + child_stack)); - act.sa_handler = sigsegv_handler; - act.sa_flags = SA_RESTART; - sigemptyset(&act.sa_mask); - if ((sigaction(SIGSEGV, &act, NULL)) == -1) - tst_resm(TWARN | TERRNO, - "sigaction() for SIGSEGV failed in test_setup()"); + if (!TST_PASS) + return; - /* Setup signal handler for SIGUSR2 */ - def_act.sa_handler = sigusr2_handler; - def_act.sa_flags = SA_RESTART | SA_RESETHAND; - sigemptyset(&def_act.sa_mask); + SAFE_WAITPID(pid, &status, 0); - if ((sigaction(SIGUSR2, &def_act, NULL)) == -1) - tst_resm(TWARN | TERRNO, - "sigaction() for SIGUSR2 failed in test_setup()"); -} - -static int do_child(void) -{ - return 0; -} + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) + tst_res(TPASS, "Using return() in child will not cause abnormal exit"); + else + tst_res(TFAIL, "Using return() in child will cause abnormal exit"); -static void sigsegv_handler(int sig) -{ - if (child_pid == 0) { - kill(getppid(), SIGUSR2); - _exit(42); - } + if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) + tst_res(TFAIL, "Use of return() in child caused SIGSEGV"); } -/* sig_default_handler() - Default handler for parent */ -static void sigusr2_handler(int sig) -{ - if (child_pid != 0) - fail = TRUE; -} +static struct tst_test test = { + .test_all = verify_clone, + .bufs = (struct tst_buffers []) { + {&child_stack, .size = CHILD_STACK_SIZE}, + {}, + }, +};