From: Cyril H. <su...@li...> - 2013-04-24 07:24:44
|
The branch, master, has been updated via db02e96d6424303e36b1fba58f35f636e7f7830b (commit) via 633e4acdbebac27a2e8fb5c0eeebd795ef742d9b (commit) via d753c212a8eed4f0fd9af12cf35d878205810549 (commit) from 4758cb19e6ffad42ba3b026938f9f63e85ac6d9f (commit) - Log ----------------------------------------------------------------- commit db02e96d6424303e36b1fba58f35f636e7f7830b Author: Wanlong Gao <gao...@cn...> Date: Wed Apr 24 14:03:21 2013 +0800 syscalls/accept4_01: code cleanups Cleanup the code. Signed-off-by: Wanlong Gao <gao...@cn...> commit 633e4acdbebac27a2e8fb5c0eeebd795ef742d9b Author: Wanlong Gao <gao...@cn...> Date: Wed Apr 24 14:03:21 2013 +0800 syscalls/accept01: code cleanups Cleanup the code. Signed-off-by: Wanlong Gao <gao...@cn...> commit d753c212a8eed4f0fd9af12cf35d878205810549 Author: Wanlong Gao <gao...@cn...> Date: Wed Apr 24 14:03:21 2013 +0800 syscalls/abort01: code cleanups Cleanup the code. Signed-off-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/abort/abort01.c | 85 ++++++----------- testcases/kernel/syscalls/accept/accept01.c | 80 +++++++--------- testcases/kernel/syscalls/accept4/accept4_01.c | 122 ++++++------------------ 3 files changed, 97 insertions(+), 190 deletions(-) diff --git a/testcases/kernel/syscalls/abort/abort01.c b/testcases/kernel/syscalls/abort/abort01.c index 369d1a8..f302eed 100644 --- a/testcases/kernel/syscalls/abort/abort01.c +++ b/testcases/kernel/syscalls/abort/abort01.c @@ -1,6 +1,8 @@ /* - * * Copyright (c) International Business Machines Corp., 2002 + * 01/02/2003 Port to LTP av...@us... + * 11/11/2002: Ported to LTP Suite by Ananda + * 06/30/2001 Port to Linux nsh...@us... * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,25 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* 01/02/2003 Port to LTP av...@us... */ -/* 06/30/2001 Port to Linux nsh...@us... */ - -/* - * NAME - * abort - * - * CALLS - * abort(3) - * - * ALGORITHM + /* ALGORITHM * Fork child. Have child abort, check return status. * * RESTRICTIONS * The ulimit for core file size must be greater than 0. - * - * CHANGE LOG: - * Nov 11 2002: Ported to LTP Suite by Ananda - * */ #include <sys/types.h> @@ -46,40 +34,18 @@ #include <stdlib.h> #include <unistd.h> -/***** LTP Port *****/ #include "test.h" #include "usctest.h" -#define ITER 3 -#define FAILED 0 -#define PASSED 1 +#define NUM 3 char *TCID = "abort01"; - -int local_flag = PASSED; -int block_number; -FILE *temp; int TST_TOTAL = 1; -void setup(void) -{ - temp = stderr; - tst_tmpdir(); -} - -void cleanup(void) -{ - unlink("core"); - tst_rmdir(); -} +static void setup(void); +static void cleanup(void); +static void do_child(); +static int instress(); -int instress(); -void setup(); -int forkfail(); -void do_child(); - -/*************/ - -/*--------------------------------------------------------------*/ int main(int argc, char *argv[]) { register int i; @@ -89,12 +55,12 @@ int main(int argc, char *argv[]) #ifdef WCOREDUMP int core; - core = 0; #endif ex = sig = 0; - if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) + msg = parse_opts(argc, argv, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); #ifdef UCLINUX maybe_run_child(&do_child, ""); @@ -102,9 +68,9 @@ int main(int argc, char *argv[]) setup(); - for (i = 0; i < ITER; i++) { - - if ((kidpid = FORK_OR_VFORK()) == 0) { + for (i = 0; i < NUM; i++) { + kidpid = FORK_OR_VFORK(); + if (kidpid == 0) { #ifdef UCLINUX if (self_exec(argv[0], "")) { if (!instress()) { @@ -144,13 +110,13 @@ int main(int argc, char *argv[]) tst_brkm(TFAIL, cleanup, "Child did not dump core; exit code = %d, " "signal = %d", ex, sig); - } else if (core != -1) + } else if (core != -1) { tst_resm(TPASS, "abort dumped core"); + } #endif - - if (sig == SIGIOT) + if (sig == SIGIOT) { tst_resm(TPASS, "abort raised SIGIOT"); - else { + } else { tst_brkm(TFAIL, cleanup, "Child did not raise SIGIOT (%d); exit code = %d, " "signal = %d", SIGIOT, ex, sig); @@ -162,14 +128,25 @@ int main(int argc, char *argv[]) tst_exit(); } -void do_child() +static void setup(void) +{ + tst_tmpdir(); +} + +static void cleanup(void) +{ + unlink("core"); + tst_rmdir(); +} + +static void do_child() { abort(); fprintf(stderr, "\tchild - abort failed.\n"); exit(1); } -int instress() +static int instress() { tst_resm(TINFO, "System resources may be too low; fork(), select() etc are likely to fail."); diff --git a/testcases/kernel/syscalls/accept/accept01.c b/testcases/kernel/syscalls/accept/accept01.c index 453fe00..5d523d4 100644 --- a/testcases/kernel/syscalls/accept/accept01.c +++ b/testcases/kernel/syscalls/accept/accept01.c @@ -1,6 +1,7 @@ /* * * Copyright (c) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,27 +19,8 @@ */ /* - * Test Name: accept01 - * - * Test Description: + * Description: * Verify that accept() returns the proper errno for various failure cases - * - * Usage: <for command-line> - * accept01 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * None. - * */ #include <stdio.h> @@ -63,8 +45,14 @@ int s; /* socket descriptor */ struct sockaddr_in sin0, fsin1; socklen_t sinlen; -void setup(void), setup0(void), setup1(void), setup2(void), setup3(void), -cleanup(void), cleanup0(void), cleanup1(void); +static void setup(void); +static void cleanup(void); +static void setup0(void); +static void cleanup0(void); +static void setup1(void); +static void cleanup1(void); +static void setup2(void); +static void setup3(void); struct test_case_t { /* test case structure */ int domain; /* PF_INET, PF_UNIX, ... */ @@ -92,12 +80,14 @@ struct test_case_t { /* test case structure */ (socklen_t *) 1, -1, EINVAL, setup1, cleanup1, "invalid salen"}, { PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&fsin1, - &sinlen, -1, EINVAL, setup2, cleanup1, "invalid salen"}, { + &sinlen, -1, EINVAL, setup2, cleanup1, + "invalid salen"}, { PF_INET, SOCK_STREAM, 0, (struct sockaddr *)&fsin1, &sinlen, -1, EINVAL, setup3, cleanup1, "no queued connections"}, { -PF_INET, SOCK_DGRAM, 0, (struct sockaddr *)&fsin1, - &sinlen, -1, EOPNOTSUPP, setup1, cleanup1, "UDP accept"},}; + PF_INET, SOCK_DGRAM, 0, (struct sockaddr *)&fsin1, + &sinlen, -1, EOPNOTSUPP, setup1, cleanup1, + "UDP accept"},}; int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]); @@ -108,7 +98,8 @@ int main(int ac, char *av[]) int lc; char *msg; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) + msg = parse_opts(ac, av, NULL, NULL); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); @@ -138,11 +129,12 @@ int main(int ac, char *av[]) tdat[testno].cleanup(); } } + cleanup(); tst_exit(); } -void setup(void) +static void setup(void) { TEST_PAUSE; @@ -154,12 +146,12 @@ void setup(void) sin0.sin_addr.s_addr = INADDR_ANY; } -void cleanup(void) +static void cleanup(void) { TEST_CLEANUP; } -void setup0(void) +static void setup0(void) { if (tdat[testno].experrno == EBADF) s = 400; /* anything not an open file */ @@ -167,12 +159,12 @@ void setup0(void) tst_brkm(TBROK | TERRNO, cleanup, "error opening /dev/null"); } -void cleanup0(void) +static void cleanup0(void) { s = -1; } -void setup1(void) +static void setup1(void) { s = socket(tdat[testno].domain, tdat[testno].type, tdat[testno].proto); if (s < 0) { @@ -186,25 +178,25 @@ void setup1(void) sinlen = sizeof(fsin1); } -void setup3(void) -{ - int one = 1; - - setup1(); - if (ioctl(s, FIONBIO, &one) < 0) { - tst_brkm(TBROK, cleanup, "socket ioctl failed for accept " - "test %d: %s", testno, strerror(errno)); - } -} - -void cleanup1(void) +static void cleanup1(void) { (void)close(s); s = -1; } -void setup2(void) +static void setup2(void) { setup1(); /* get a socket in s */ sinlen = 1; /* invalid s */ } + +static void setup3(void) +{ + int one = 1; + + setup1(); + if (ioctl(s, FIONBIO, &one) < 0) { + tst_brkm(TBROK, cleanup, "socket ioctl failed for accept " + "test %d: %s", testno, strerror(errno)); + } +} diff --git a/testcases/kernel/syscalls/accept4/accept4_01.c b/testcases/kernel/syscalls/accept4/accept4_01.c index 6e6f017..2629b1f 100644 --- a/testcases/kernel/syscalls/accept4/accept4_01.c +++ b/testcases/kernel/syscalls/accept4/accept4_01.c @@ -1,42 +1,24 @@ -/******************************************************************************/ -/* */ -/* Copyright (C) 2008, Linux Foundation, */ -/* written by Michael Kerrisk <mtk...@gm...> */ -/* */ -/* Licensed under the GNU GPLv2 or later. */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/******************************************************************************/ - -/******************************************************************************/ -/* */ -/* File: accept4_01.c */ -/* */ -/* Description: This will test the newly introduced syscall accept4() */ -/* */ -/* Total Tests: 4 */ -/* */ -/* Test Name: accept4_01 */ -/* */ -/* Author: Michael Kerrisk <mtk...@gm...> */ -/* */ -/* History: Created - Nov 17 2008 - Michael <mtk...@gm...> */ -/* Initial Porting to LTP */ -/* - Nov 17 2008 - Subrata <su...@li...> */ -/* */ -/******************************************************************************/ +/* + * + * Copyright (C) 2008, Linux Foundation, + * written by Michael Kerrisk <mtk...@gm...> + * Initial Porting to LTP by Subrata <su...@li...> + * + * Licensed under the GNU GPLv2 or later. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ #define _GNU_SOURCE #include <unistd.h> @@ -58,7 +40,6 @@ #define die(msg) tst_brkm(TBROK|TERRNO, cleanup, msg) -/**********************************************************************/ /* The following is what we need until glibc gets a wrapper for accept4() */ @@ -82,62 +63,21 @@ char *TCID = "accept04_01"; int TST_TOTAL = 1; -/* Extern Global Functions */ -/******************************************************************************/ -/* */ -/* Function: cleanup */ -/* */ -/* Description: Performs all one time clean up for this test on successful */ -/* completion, premature exit or failure. Closes all temporary */ -/* files, removes all temporary directories exits the test with */ -/* appropriate return code by calling tst_exit() function. */ -/* */ -/* Input: None. */ -/* */ -/* Output: None. */ -/* */ -/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ -/* On success - Exits calling tst_exit(). With '0' return code. */ -/* */ -/******************************************************************************/ -/* We would need this for many more reasons in future */ -extern void cleanup() +static void setup(void) { - - TEST_CLEANUP; - tst_rmdir(); - + TEST_PAUSE; + tst_tmpdir(); } -/* Local Functions */ -/******************************************************************************/ -/* */ -/* Function: setup */ -/* */ -/* Description: Performs all one time setup for this test. This function is */ -/* typically used to capture signals, create temporary dirs */ -/* and temporary files that may be used in the course of this */ -/* test. */ -/* */ -/* Input: None. */ -/* */ -/* Output: None. */ -/* */ -/* Return: On failure - Exits by calling cleanup(). */ -/* On success - returns 0. */ -/* */ -/******************************************************************************/ -void setup() +static void cleanup(void) { - /* Capture signals if any */ - /* Create temporary directories */ - TEST_PAUSE; - tst_tmpdir(); + TEST_CLEANUP; + tst_rmdir(); } -#if !(__GLIBC_PREREQ(2,10)) +#if !(__GLIBC_PREREQ(2, 10)) static int -accept4_01(int fd, struct sockaddr *sockaddr, socklen_t * addrlen, int flags) +accept4_01(int fd, struct sockaddr *sockaddr, socklen_t *addrlen, int flags) { #ifdef DEBUG tst_resm(TINFO, "Calling accept4(): flags = %x", flags); @@ -169,8 +109,6 @@ accept4_01(int fd, struct sockaddr *sockaddr, socklen_t * addrlen, int flags) } #endif -/**********************************************************************/ - static void do_test(int lfd, struct sockaddr_in *conn_addr, int closeonexec_flag, int nonblock_flag) @@ -192,7 +130,7 @@ do_test(int lfd, struct sockaddr_in *conn_addr, die("Connect Error"); addrlen = sizeof(struct sockaddr_in); -#if !(__GLIBC_PREREQ(2,10)) +#if !(__GLIBC_PREREQ(2, 10)) acceptfd = accept4_01(lfd, (struct sockaddr *)&claddr, &addrlen, closeonexec_flag | nonblock_flag); #else hooks/post-receive -- ltp |