blob: 2dae56c55ffc58cc4e3a9de1c614afa989b8733b [file] [log] [blame]
subrata_modaka97f1162009-01-16 10:24:56 +00001/******************************************************************************/
2/* */
3/* Copyright (c) Ulrich Drepper <drepper@redhat.com> */
4/* Copyright (c) International Business Machines Corp., 2009 */
5/* */
6/* This program is free software; you can redistribute it and/or modify */
7/* it under the terms of the GNU General Public License as published by */
8/* the Free Software Foundation; either version 2 of the License, or */
9/* (at your option) any later version. */
10/* */
11/* This program is distributed in the hope that it will be useful, */
12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
14/* the GNU General Public License for more details. */
15/* */
16/* You should have received a copy of the GNU General Public License */
17/* along with this program; if not, write to the Free Software */
18/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19/* */
20/******************************************************************************/
21/******************************************************************************/
22/* */
23/* File: socket03.c */
24/* */
25/* Description: This Program tests the new system call introduced in 2.6.27. */
26/* Ulrich´s comment as in: */
27/* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=77d2720059618b9b6e827a8b73831eb6c6fad63c */
28/* */
29/* Usage: <for command-line> */
30/* socket03 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
31/* where, -c n : Run n copies concurrently. */
32/* -e : Turn on errno logging. */
33/* -i n : Execute test n times. */
34/* -I x : Execute test for x seconds. */
35/* -P x : Pause for x seconds between iterations. */
36/* -t : Turn on syscall timing. */
37/* */
38/* Total Tests: 1 */
39/* */
40/* Test Name: socket03 */
41/* */
42/* Author: Ulrich Drepper <drepper@redhat.com> */
43/* */
44/* History: Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com> */
45/* Ported to LTP */
46/* - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com> */
47/******************************************************************************/
48#include <fcntl.h>
49#include <pthread.h>
50#include <stdio.h>
51#include <unistd.h>
52#include <netinet/in.h>
53#include <sys/socket.h>
54#include <sys/syscall.h>
55
56/* Harness Specific Include Files. */
57#include "test.h"
58#include "usctest.h"
59
subrata_modak8d4fee72009-01-27 14:48:38 +000060#ifndef SOCK_NONBLOCK
61# define SOCK_NONBLOCK O_NONBLOCK
62#endif
subrata_modaka97f1162009-01-16 10:24:56 +000063
64/* Extern Global Variables */
Garrett Cooper2c282152010-12-16 00:55:50 -080065extern int Tst_count;
subrata_modak56207ce2009-03-23 13:35:39 +000066extern char *TESTDIR; /* temporary dir created by tst_tmpdir() */
subrata_modaka97f1162009-01-16 10:24:56 +000067
68/* Global Variables */
subrata_modak56207ce2009-03-23 13:35:39 +000069char *TCID = "socket03"; /* test program identifier. */
70int testno;
71int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modaka97f1162009-01-16 10:24:56 +000072
73/* Extern Global Functions */
74/******************************************************************************/
75/* */
76/* Function: cleanup */
77/* */
78/* Description: Performs all one time clean up for this test on successful */
79/* completion, premature exit or failure. Closes all temporary */
80/* files, removes all temporary directories exits the test with */
81/* appropriate return code by calling tst_exit() function. */
82/* */
83/* Input: None. */
84/* */
85/* Output: None. */
86/* */
87/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
88/* On success - Exits calling tst_exit(). With '0' return code. */
89/* */
90/******************************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +000091extern void cleanup()
92{
Garrett Cooper2c282152010-12-16 00:55:50 -080093
subrata_modak56207ce2009-03-23 13:35:39 +000094 TEST_CLEANUP;
95 tst_rmdir();
subrata_modaka97f1162009-01-16 10:24:56 +000096
subrata_modaka97f1162009-01-16 10:24:56 +000097}
98
99/* Local Functions */
100/******************************************************************************/
101/* */
102/* Function: setup */
103/* */
104/* Description: Performs all one time setup for this test. This function is */
105/* typically used to capture signals, create temporary dirs */
106/* and temporary files that may be used in the course of this */
107/* test. */
108/* */
109/* Input: None. */
110/* */
111/* Output: None. */
112/* */
113/* Return: On failure - Exits by calling cleanup(). */
114/* On success - returns 0. */
115/* */
116/******************************************************************************/
subrata_modak56207ce2009-03-23 13:35:39 +0000117void setup()
118{
119 /* Capture signals if any */
120 /* Create temporary directories */
121 TEST_PAUSE;
122 tst_tmpdir();
subrata_modaka97f1162009-01-16 10:24:56 +0000123}
124
subrata_modak56207ce2009-03-23 13:35:39 +0000125int main(int argc, char *argv[])
126{
127 int fd, fl;
128 int lc; /* loop counter */
129 char *msg; /* message returned from parse_opts */
subrata_modaka97f1162009-01-16 10:24:56 +0000130
subrata_modak56207ce2009-03-23 13:35:39 +0000131 /* Parse standard options given to run the test. */
Garrett Cooper53740502010-12-16 00:04:01 -0800132<<<<<<< HEAD
Garrett Cooper45e285d2010-11-22 12:19:25 -0800133 msg = parse_opts(argc, argv, NULL, NULL);
Garrett Cooper53740502010-12-16 00:04:01 -0800134=======
subrata_modak56207ce2009-03-23 13:35:39 +0000135 msg = parse_opts(argc, argv, (option_t *) NULL, NULL);
Garrett Cooper53740502010-12-16 00:04:01 -0800136>>>>>>> master
Garrett Cooper45e285d2010-11-22 12:19:25 -0800137 if (msg != NULL) {
subrata_modak56207ce2009-03-23 13:35:39 +0000138 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
139 tst_exit();
140 }
141 if ((tst_kvercmp(2, 6, 27)) < 0) {
142 tst_resm(TCONF,
143 "This test can only run on kernels that are 2.6.27 and higher");
144 tst_exit();
145 }
146 setup();
subrata_modaka97f1162009-01-16 10:24:56 +0000147
subrata_modak56207ce2009-03-23 13:35:39 +0000148 for (lc = 0; TEST_LOOPING(lc); ++lc) {
149 Tst_count = 0;
150 for (testno = 0; testno < TST_TOTAL; ++testno) {
151 fd = socket(PF_INET, SOCK_STREAM, 0);
152 if (fd == -1) {
153 tst_resm(TFAIL, "socket(0) failed");
154 cleanup();
155 tst_exit();
156 }
157 fl = fcntl(fd, F_GETFL);
158 if (fl == -1) {
159 tst_brkm(TBROK, cleanup, "fcntl failed");
160 tst_exit();
161 }
162 if (fl & O_NONBLOCK) {
163 tst_resm(TFAIL,
164 "socket(0) set non-blocking mode");
165 cleanup();
166 tst_exit();
167 }
168 close(fd);
subrata_modaka97f1162009-01-16 10:24:56 +0000169
subrata_modak56207ce2009-03-23 13:35:39 +0000170 fd = socket(PF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
171 if (fd == -1) {
172 tst_resm(TFAIL, "socket(SOCK_NONBLOCK) failed");
173 cleanup();
174 tst_exit();
175 }
176 fl = fcntl(fd, F_GETFL);
177 if (fl == -1) {
178 tst_brkm(TBROK, cleanup, "fcntl failed");
179 tst_exit();
180 }
181 if ((fl & O_NONBLOCK) == 0) {
182 tst_resm(TFAIL,
183 "socket(SOCK_NONBLOCK) does not set non-blocking mode");
184 cleanup();
185 tst_exit();
186 }
187 close(fd);
188 tst_resm(TPASS, "socket(SOCK_NONBLOCK) PASSED");
189 cleanup();
190 }
191 }
192 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800193}