1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * 3f08c3bdfSopenharmony_ci * Copyright (C) Bull S.A. 2005 4f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2004 5f08c3bdfSopenharmony_ci * 6f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify 7f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 8f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 9f08c3bdfSopenharmony_ci * (at your option) any later version. 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 12f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 13f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14f08c3bdfSopenharmony_ci * the GNU General Public License for more details. 15f08c3bdfSopenharmony_ci * 16f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 17f08c3bdfSopenharmony_ci * along with this program; if not, write to the Free Software 18f08c3bdfSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19f08c3bdfSopenharmony_ci */ 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci/********************************************************** 22f08c3bdfSopenharmony_ci * 23f08c3bdfSopenharmony_ci * TEST IDENTIFIER : fcntl27 24f08c3bdfSopenharmony_ci * 25f08c3bdfSopenharmony_ci * EXECUTED BY : anyone 26f08c3bdfSopenharmony_ci * 27f08c3bdfSopenharmony_ci * TEST TITLE : Basic test for fcntl(2) using F_SETLEASE & F_RDLCK argument. 28f08c3bdfSopenharmony_ci * 29f08c3bdfSopenharmony_ci * TEST CASE TOTAL : 1 30f08c3bdfSopenharmony_ci * 31f08c3bdfSopenharmony_ci * WALL CLOCK TIME : 1 32f08c3bdfSopenharmony_ci * 33f08c3bdfSopenharmony_ci * CPU TYPES : ALL 34f08c3bdfSopenharmony_ci * 35f08c3bdfSopenharmony_ci * AUTHOR : Jacky Malcles 36f08c3bdfSopenharmony_ci * 37f08c3bdfSopenharmony_ci * TEST CASES 38f08c3bdfSopenharmony_ci * 39f08c3bdfSopenharmony_ci * 1.) fcntl(2) returns...(See Description) 40f08c3bdfSopenharmony_ci * 41f08c3bdfSopenharmony_ci * INPUT SPECIFICATIONS 42f08c3bdfSopenharmony_ci * The standard options for system call tests are accepted. 43f08c3bdfSopenharmony_ci * (See the parse_opts(3) man page). 44f08c3bdfSopenharmony_ci * 45f08c3bdfSopenharmony_ci * OUTPUT SPECIFICATIONS 46f08c3bdfSopenharmony_ci * 47f08c3bdfSopenharmony_ci * DURATION 48f08c3bdfSopenharmony_ci * Terminates - with frequency and infinite modes. 49f08c3bdfSopenharmony_ci * 50f08c3bdfSopenharmony_ci * SIGNALS 51f08c3bdfSopenharmony_ci * Uses SIGUSR1 to pause before test if option set. 52f08c3bdfSopenharmony_ci * (See the parse_opts(3) man page). 53f08c3bdfSopenharmony_ci * 54f08c3bdfSopenharmony_ci * RESOURCES 55f08c3bdfSopenharmony_ci * None 56f08c3bdfSopenharmony_ci * 57f08c3bdfSopenharmony_ci * ENVIRONMENTAL NEEDS 58f08c3bdfSopenharmony_ci * No run-time environmental needs. 59f08c3bdfSopenharmony_ci * 60f08c3bdfSopenharmony_ci * SPECIAL PROCEDURAL REQUIREMENTS 61f08c3bdfSopenharmony_ci * None 62f08c3bdfSopenharmony_ci * 63f08c3bdfSopenharmony_ci * INTERCASE DEPENDENCIES 64f08c3bdfSopenharmony_ci * None 65f08c3bdfSopenharmony_ci * 66f08c3bdfSopenharmony_ci * DETAILED DESCRIPTION 67f08c3bdfSopenharmony_ci * This is a Phase I test for the fcntl(2) system call. It is intended 68f08c3bdfSopenharmony_ci * to provide a limited exposure of the system call, for now. It 69f08c3bdfSopenharmony_ci * should/will be extended when full functional tests are written for 70f08c3bdfSopenharmony_ci * fcntl(2). 71f08c3bdfSopenharmony_ci * 72f08c3bdfSopenharmony_ci * Setup: 73f08c3bdfSopenharmony_ci * Setup signal handling. 74f08c3bdfSopenharmony_ci * Pause for SIGUSR1 if option specified. 75f08c3bdfSopenharmony_ci * 76f08c3bdfSopenharmony_ci * Test: 77f08c3bdfSopenharmony_ci * Loop if the proper options are given. 78f08c3bdfSopenharmony_ci * Execute system call 79f08c3bdfSopenharmony_ci * Check return code, if system call failed (return=-1) 80f08c3bdfSopenharmony_ci * Log the errno and Issue a FAIL message. 81f08c3bdfSopenharmony_ci * Otherwise, Issue a PASS message. 82f08c3bdfSopenharmony_ci * 83f08c3bdfSopenharmony_ci * Cleanup: 84f08c3bdfSopenharmony_ci * Print errno log and/or timing stats if options given 85f08c3bdfSopenharmony_ci * 86f08c3bdfSopenharmony_ci * 87f08c3bdfSopenharmony_ci *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ 88f08c3bdfSopenharmony_ci 89f08c3bdfSopenharmony_ci#include <sys/types.h> 90f08c3bdfSopenharmony_ci#include <sys/stat.h> 91f08c3bdfSopenharmony_ci#include <fcntl.h> 92f08c3bdfSopenharmony_ci#include <unistd.h> 93f08c3bdfSopenharmony_ci#include <errno.h> 94f08c3bdfSopenharmony_ci#include <string.h> 95f08c3bdfSopenharmony_ci#include <signal.h> 96f08c3bdfSopenharmony_ci#include "test.h" 97f08c3bdfSopenharmony_ci 98f08c3bdfSopenharmony_civoid setup(); 99f08c3bdfSopenharmony_civoid cleanup(); 100f08c3bdfSopenharmony_ci 101f08c3bdfSopenharmony_cichar *TCID = "fcntl27"; 102f08c3bdfSopenharmony_ciint TST_TOTAL = 1; 103f08c3bdfSopenharmony_ci 104f08c3bdfSopenharmony_cichar fname[255]; 105f08c3bdfSopenharmony_ciint fd; 106f08c3bdfSopenharmony_ci 107f08c3bdfSopenharmony_ciint main(int ac, char **av) 108f08c3bdfSopenharmony_ci{ 109f08c3bdfSopenharmony_ci int lc, expected_result = -1; 110f08c3bdfSopenharmony_ci /*************************************************************** 111f08c3bdfSopenharmony_ci * parse standard options 112f08c3bdfSopenharmony_ci ***************************************************************/ 113f08c3bdfSopenharmony_ci tst_parse_opts(ac, av, NULL, NULL); 114f08c3bdfSopenharmony_ci 115f08c3bdfSopenharmony_ci /*************************************************************** 116f08c3bdfSopenharmony_ci * perform global setup for test 117f08c3bdfSopenharmony_ci ***************************************************************/ 118f08c3bdfSopenharmony_ci setup(); 119f08c3bdfSopenharmony_ci 120f08c3bdfSopenharmony_ci expected_result = -1; 121f08c3bdfSopenharmony_ci 122f08c3bdfSopenharmony_ci /*************************************************************** 123f08c3bdfSopenharmony_ci * check looping state if -c option given 124f08c3bdfSopenharmony_ci ***************************************************************/ 125f08c3bdfSopenharmony_ci for (lc = 0; TEST_LOOPING(lc); lc++) { 126f08c3bdfSopenharmony_ci 127f08c3bdfSopenharmony_ci tst_count = 0; 128f08c3bdfSopenharmony_ci 129f08c3bdfSopenharmony_ci#ifdef F_SETLEASE 130f08c3bdfSopenharmony_ci /* 131f08c3bdfSopenharmony_ci * Call fcntl(2) with F_SETLEASE & F_RDLCK argument on fname 132f08c3bdfSopenharmony_ci */ 133f08c3bdfSopenharmony_ci TEST(fcntl(fd, F_SETLEASE, F_RDLCK)); 134f08c3bdfSopenharmony_ci 135f08c3bdfSopenharmony_ci /* check return code */ 136f08c3bdfSopenharmony_ci if (TEST_RETURN == expected_result) { 137f08c3bdfSopenharmony_ci tst_resm(TPASS, 138f08c3bdfSopenharmony_ci "fcntl(fd, F_SETLEASE, F_RDLCK) succeeded"); 139f08c3bdfSopenharmony_ci } else { 140f08c3bdfSopenharmony_ci tst_resm(TFAIL, "fcntl(%s, F_SETLEASE, F_RDLCK)" 141f08c3bdfSopenharmony_ci " failed with errno %d : %s", fname, 142f08c3bdfSopenharmony_ci TEST_ERRNO, strerror(TEST_ERRNO)); 143f08c3bdfSopenharmony_ci } 144f08c3bdfSopenharmony_ci#else 145f08c3bdfSopenharmony_ci tst_resm(TINFO, "F_SETLEASE not defined, skipping test"); 146f08c3bdfSopenharmony_ci#endif 147f08c3bdfSopenharmony_ci } 148f08c3bdfSopenharmony_ci 149f08c3bdfSopenharmony_ci /*************************************************************** 150f08c3bdfSopenharmony_ci * cleanup and exit 151f08c3bdfSopenharmony_ci ***************************************************************/ 152f08c3bdfSopenharmony_ci cleanup(); 153f08c3bdfSopenharmony_ci tst_exit(); 154f08c3bdfSopenharmony_ci 155f08c3bdfSopenharmony_ci} 156f08c3bdfSopenharmony_ci 157f08c3bdfSopenharmony_ci/*************************************************************** 158f08c3bdfSopenharmony_ci * setup() - performs all ONE TIME setup for this test. 159f08c3bdfSopenharmony_ci ***************************************************************/ 160f08c3bdfSopenharmony_civoid setup(void) 161f08c3bdfSopenharmony_ci{ 162f08c3bdfSopenharmony_ci 163f08c3bdfSopenharmony_ci tst_sig(NOFORK, DEF_HANDLER, cleanup); 164f08c3bdfSopenharmony_ci 165f08c3bdfSopenharmony_ci TEST_PAUSE; 166f08c3bdfSopenharmony_ci 167f08c3bdfSopenharmony_ci tst_tmpdir(); 168f08c3bdfSopenharmony_ci 169f08c3bdfSopenharmony_ci sprintf(fname, "tfile_%d", getpid()); 170f08c3bdfSopenharmony_ci if ((fd = open(fname, O_RDWR | O_CREAT, 0777)) == -1) { 171f08c3bdfSopenharmony_ci tst_brkm(TBROK, cleanup, 172f08c3bdfSopenharmony_ci "open(%s, O_RDWR|O_CREAT,0777) Failed, errno=%d : %s", 173f08c3bdfSopenharmony_ci fname, errno, strerror(errno)); 174f08c3bdfSopenharmony_ci } 175f08c3bdfSopenharmony_ci} 176f08c3bdfSopenharmony_ci 177f08c3bdfSopenharmony_ci/*************************************************************** 178f08c3bdfSopenharmony_ci * cleanup() - performs all ONE TIME cleanup for this test at 179f08c3bdfSopenharmony_ci * completion or premature exit. 180f08c3bdfSopenharmony_ci ***************************************************************/ 181f08c3bdfSopenharmony_civoid cleanup(void) 182f08c3bdfSopenharmony_ci{ 183f08c3bdfSopenharmony_ci 184f08c3bdfSopenharmony_ci /* close the file we've had open */ 185f08c3bdfSopenharmony_ci if (close(fd) == -1) { 186f08c3bdfSopenharmony_ci tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno, 187f08c3bdfSopenharmony_ci strerror(errno)); 188f08c3bdfSopenharmony_ci } 189f08c3bdfSopenharmony_ci 190f08c3bdfSopenharmony_ci tst_rmdir(); 191f08c3bdfSopenharmony_ci 192f08c3bdfSopenharmony_ci} 193