1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify 6f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 7f08c3bdfSopenharmony_ci * the Free Software Foundation; either version 2 of the License, or 8f08c3bdfSopenharmony_ci * (at your option) any later version. 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 11f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 12f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13f08c3bdfSopenharmony_ci * the GNU General Public License for more details. 14f08c3bdfSopenharmony_ci * 15f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 16f08c3bdfSopenharmony_ci * along with this program; if not, write to the Free Software 17f08c3bdfSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18f08c3bdfSopenharmony_ci */ 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_ci/* 21f08c3bdfSopenharmony_ci * NAME 22f08c3bdfSopenharmony_ci * semget06.c 23f08c3bdfSopenharmony_ci * 24f08c3bdfSopenharmony_ci * DESCRIPTION 25f08c3bdfSopenharmony_ci * semget06 - test for EINVAL error 26f08c3bdfSopenharmony_ci * 27f08c3bdfSopenharmony_ci * ALGORITHM 28f08c3bdfSopenharmony_ci * loop if that option was specified 29f08c3bdfSopenharmony_ci * call semget() using two different invalid cases - too many and too 30f08c3bdfSopenharmony_ci * few primitive semaphores 31f08c3bdfSopenharmony_ci * check the errno value 32f08c3bdfSopenharmony_ci * issue a PASS message if we get EINVAL 33f08c3bdfSopenharmony_ci * otherwise, the tests fails 34f08c3bdfSopenharmony_ci * issue a FAIL message 35f08c3bdfSopenharmony_ci * call cleanup 36f08c3bdfSopenharmony_ci * 37f08c3bdfSopenharmony_ci * USAGE: <for command-line> 38f08c3bdfSopenharmony_ci * semget06 [-c n] [-e] [-i n] [-I x] [-P x] [-t] 39f08c3bdfSopenharmony_ci * where, -c n : Run n copies concurrently. 40f08c3bdfSopenharmony_ci * -e : Turn on errno logging. 41f08c3bdfSopenharmony_ci * -i n : Execute test n times. 42f08c3bdfSopenharmony_ci * -I x : Execute test for x seconds. 43f08c3bdfSopenharmony_ci * -P x : Pause for x seconds between iterations. 44f08c3bdfSopenharmony_ci * -t : Turn on syscall timing. 45f08c3bdfSopenharmony_ci * 46f08c3bdfSopenharmony_ci * HISTORY 47f08c3bdfSopenharmony_ci * 03/2001 - Written by Wayne Boyer 48f08c3bdfSopenharmony_ci * 49f08c3bdfSopenharmony_ci * RESTRICTIONS 50f08c3bdfSopenharmony_ci * none 51f08c3bdfSopenharmony_ci */ 52f08c3bdfSopenharmony_ci 53f08c3bdfSopenharmony_ci#include "ipcsem.h" 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_cichar *TCID = "semget06"; 56f08c3bdfSopenharmony_ciint TST_TOTAL = 2; 57f08c3bdfSopenharmony_ci 58f08c3bdfSopenharmony_ci#define LARGENUM 1024 * 32 59f08c3bdfSopenharmony_ci#define SMALLNUM -1 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_ciint sem_id_1 = -1; 62f08c3bdfSopenharmony_ci 63f08c3bdfSopenharmony_ciint num_sems[] = { LARGENUM, SMALLNUM }; 64f08c3bdfSopenharmony_ci 65f08c3bdfSopenharmony_ciint main(int ac, char **av) 66f08c3bdfSopenharmony_ci{ 67f08c3bdfSopenharmony_ci int lc; 68f08c3bdfSopenharmony_ci int i; 69f08c3bdfSopenharmony_ci 70f08c3bdfSopenharmony_ci tst_parse_opts(ac, av, NULL, NULL); 71f08c3bdfSopenharmony_ci 72f08c3bdfSopenharmony_ci setup(); /* global setup */ 73f08c3bdfSopenharmony_ci 74f08c3bdfSopenharmony_ci /* The following loop checks looping state if -i option given */ 75f08c3bdfSopenharmony_ci 76f08c3bdfSopenharmony_ci for (lc = 0; TEST_LOOPING(lc); lc++) { 77f08c3bdfSopenharmony_ci /* reset tst_count in case we are looping */ 78f08c3bdfSopenharmony_ci tst_count = 0; 79f08c3bdfSopenharmony_ci 80f08c3bdfSopenharmony_ci /* loop through the test cases */ 81f08c3bdfSopenharmony_ci 82f08c3bdfSopenharmony_ci for (i = 0; i < TST_TOTAL; i++) { 83f08c3bdfSopenharmony_ci TEST(semget(semkey, num_sems[i], 84f08c3bdfSopenharmony_ci IPC_CREAT | IPC_EXCL | SEM_RA)); 85f08c3bdfSopenharmony_ci 86f08c3bdfSopenharmony_ci if (TEST_RETURN != -1) { 87f08c3bdfSopenharmony_ci sem_id_1 = TEST_RETURN; 88f08c3bdfSopenharmony_ci tst_resm(TFAIL, "call succeeded"); 89f08c3bdfSopenharmony_ci continue; 90f08c3bdfSopenharmony_ci } 91f08c3bdfSopenharmony_ci 92f08c3bdfSopenharmony_ci switch (TEST_ERRNO) { 93f08c3bdfSopenharmony_ci case EINVAL: 94f08c3bdfSopenharmony_ci tst_resm(TPASS, "expected failure - errno " 95f08c3bdfSopenharmony_ci "= %d : %s", TEST_ERRNO, 96f08c3bdfSopenharmony_ci strerror(TEST_ERRNO)); 97f08c3bdfSopenharmony_ci break; 98f08c3bdfSopenharmony_ci default: 99f08c3bdfSopenharmony_ci tst_resm(TFAIL, "unexpected error - %d : %s", 100f08c3bdfSopenharmony_ci TEST_ERRNO, strerror(TEST_ERRNO)); 101f08c3bdfSopenharmony_ci break; 102f08c3bdfSopenharmony_ci } 103f08c3bdfSopenharmony_ci } 104f08c3bdfSopenharmony_ci } 105f08c3bdfSopenharmony_ci 106f08c3bdfSopenharmony_ci cleanup(); 107f08c3bdfSopenharmony_ci 108f08c3bdfSopenharmony_ci tst_exit(); 109f08c3bdfSopenharmony_ci} 110f08c3bdfSopenharmony_ci 111f08c3bdfSopenharmony_ci/* 112f08c3bdfSopenharmony_ci * setup() - performs all the ONE TIME setup for this test. 113f08c3bdfSopenharmony_ci */ 114f08c3bdfSopenharmony_civoid setup(void) 115f08c3bdfSopenharmony_ci{ 116f08c3bdfSopenharmony_ci 117f08c3bdfSopenharmony_ci tst_sig(NOFORK, DEF_HANDLER, cleanup); 118f08c3bdfSopenharmony_ci 119f08c3bdfSopenharmony_ci TEST_PAUSE; 120f08c3bdfSopenharmony_ci 121f08c3bdfSopenharmony_ci /* 122f08c3bdfSopenharmony_ci * Create a temporary directory and cd into it. 123f08c3bdfSopenharmony_ci * This helps to ensure that a unique msgkey is created. 124f08c3bdfSopenharmony_ci * See libs/libltpipc/libipc.c for more information. 125f08c3bdfSopenharmony_ci */ 126f08c3bdfSopenharmony_ci tst_tmpdir(); 127f08c3bdfSopenharmony_ci 128f08c3bdfSopenharmony_ci /* get an IPC resource key */ 129f08c3bdfSopenharmony_ci semkey = getipckey(); 130f08c3bdfSopenharmony_ci} 131f08c3bdfSopenharmony_ci 132f08c3bdfSopenharmony_ci/* 133f08c3bdfSopenharmony_ci * cleanup() - performs all the ONE TIME cleanup for this test at completion 134f08c3bdfSopenharmony_ci * or premature exit. 135f08c3bdfSopenharmony_ci */ 136f08c3bdfSopenharmony_civoid cleanup(void) 137f08c3bdfSopenharmony_ci{ 138f08c3bdfSopenharmony_ci /* if it exists, remove the semaphore resource */ 139f08c3bdfSopenharmony_ci rm_sema(sem_id_1); 140f08c3bdfSopenharmony_ci 141f08c3bdfSopenharmony_ci tst_rmdir(); 142f08c3bdfSopenharmony_ci 143f08c3bdfSopenharmony_ci} 144