keyctl01.c revision 5c8fc01200ab5fedc1a1c4cb0989e6bfe1fc0c47
1/******************************************************************************/ 2/* Copyright (c) Crackerjack Project., 2007 */ 3/* */ 4/* This program is free software; you can redistribute it and/or modify */ 5/* it under the terms of the GNU General Public License as published by */ 6/* the Free Software Foundation; either version 2 of the License, or */ 7/* (at your option) any later version. */ 8/* */ 9/* This program is distributed in the hope that it will be useful, */ 10/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 11/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ 12/* the GNU General Public License for more details. */ 13/* */ 14/* You should have received a copy of the GNU General Public License */ 15/* along with this program; if not, write to the Free Software */ 16/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 17/* */ 18/******************************************************************************/ 19/******************************************************************************/ 20/* */ 21/* File: keyctl01.c */ 22/* */ 23/* Description: This tests the keyctl() syscall */ 24/* Manipulate the kernel's key management facility */ 25/* Usage: <for command-line> */ 26/* keyctl01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ 27/* where, -c n : Run n copies concurrently. */ 28/* -e : Turn on errno logging. */ 29/* -i n : Execute test n times. */ 30/* -I x : Execute test for x seconds. */ 31/* -P x : Pause for x seconds between iterations. */ 32/* -t : Turn on syscall timing. */ 33/* */ 34/* Total Tests: 2 */ 35/* */ 36/* Test Name: keyctl01 */ 37/* History: Porting from Crackerjack to LTP is done by */ 38/* Manas Kumar Nayak maknayak@in.ibm.com> */ 39/******************************************************************************/ 40 41#include <stdio.h> 42#include <errno.h> 43#include <linux/keyctl.h> 44/* Harness Specific Include Files. */ 45#include "test.h" 46#include "usctest.h" 47#include "linux_syscall_numbers.h" 48 49/* Extern Global Variables */ 50extern int Tst_count; /* counter for tst_xxx routines. */ 51extern char *TESTDIR; /* temporary dir created by tst_tmpdir() */ 52 53/* Global Variables */ 54char *TCID = "keyctl01"; /* Test program identifier.*/ 55int testno; 56int TST_TOTAL = 2; /* total number of tests in this file. */ 57 58/* Extern Global Functions */ 59/******************************************************************************/ 60/* */ 61/* Function: cleanup */ 62/* */ 63/* Description: Performs all one time clean up for this test on successful */ 64/* completion, premature exit or failure. Closes all temporary */ 65/* files, removes all temporary directories exits the test with */ 66/* appropriate return code by calling tst_exit() function. */ 67/* */ 68/* Input: None. */ 69/* */ 70/* Output: None. */ 71/* */ 72/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ 73/* On success - Exits calling tst_exit(). With '0' return code. */ 74/* */ 75/******************************************************************************/ 76extern void cleanup() { 77 /* Remove tmp dir and all files in it */ 78 TEST_CLEANUP; 79 tst_rmdir(); 80 81 /* Exit with appropriate return code. */ 82 tst_exit(); 83} 84 85/* Local Functions */ 86/******************************************************************************/ 87/* */ 88/* Function: setup */ 89/* */ 90/* Description: Performs all one time setup for this test. This function is */ 91/* typically used to capture signals, create temporary dirs */ 92/* and temporary files that may be used in the course of this */ 93/* test. */ 94/* */ 95/* Input: None. */ 96/* */ 97/* Output: None. */ 98/* */ 99/* Return: On failure - Exits by calling cleanup(). */ 100/* On success - returns 0. */ 101/* */ 102/******************************************************************************/ 103void setup() { 104 /* Capture signals if any */ 105 /* Create temporary directories */ 106 TEST_PAUSE; 107 tst_tmpdir(); 108} 109 110int main(int ac, char **av) { 111 int lc; /* loop counter */ 112 char *msg; /* message returned from parse_opts */ 113 114 /* parse standard options */ 115 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ 116 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); 117 tst_exit(); 118 } 119 120 setup(); 121 122 /* Check looping state if -i option given */ 123 for (lc = 0; TEST_LOOPING(lc); ++lc) { 124 Tst_count = 0; 125 for (testno = 0; testno < TST_TOTAL; ++testno) { 126 TEST(syscall(258, KEYCTL_GET_KEYRING_ID, KEY_SPEC_USER_SESSION_KEYRING)); //call keyctl() and Ask for a keyring's ID 127 if(TEST_RETURN != -1) { 128 tst_resm(TPASS,"KEYCTL_GET_KEYRING_ID succeed"); 129 /* cleanup(); */ 130 } 131 else { 132 tst_resm(TFAIL, "(%s failed) KEYCTL_GET_KEYRING_ID fail with - errno = %d : %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO)); 133 cleanup(); 134 tst_exit(); 135 } 136 137 138 TEST(syscall(288, KEYCTL_REVOKE, "MyKey")); //call keyctl() 139 if(TEST_RETURN != -1) { 140 tst_resm(TFAIL,"KEYTL_REVOKE succeededs, but should fail"); 141 cleanup(); 142 tst_exit(); 143 } 144 else { 145 if(TEST_ERRNO == ENOKEY) //Check for correct error no. 146 //if no matching key was found or an invalid key was specified. 147 { 148 tst_resm(TPASS,"KEYCTL_REVOKE got expected errno:%ld",TEST_ERRNO); 149 cleanup(); 150 }else{ 151 tst_resm(TFAIL,"KEYCTL_REVOKE got unexpected errno:%ld", TEST_ERRNO); 152 cleanup(); 153 tst_exit(); 154 } 155 } 156 157 } 158 } 159 tst_exit(); 160} 161 162