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