subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 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 */ |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 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 */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 17 | /* */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 20 | /* */ |
| 21 | /* File: add_key02.c */ |
| 22 | /* */ |
| 23 | /* Description: This tests the add_key() syscall */ |
| 24 | /* */ |
| 25 | /* Usage: <for command-line> */ |
| 26 | /* add_key02 [-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: 1 */ |
| 35 | /* */ |
| 36 | /* Test Name: add_key02 */ |
| 37 | /* History: Porting from Crackerjack to LTP is done by */ |
| 38 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 39 | /******************************************************************************/ |
| 40 | |
| 41 | #include <stdio.h> |
| 42 | #include <errno.h> |
| 43 | #include <linux/keyctl.h> |
| 44 | |
| 45 | /* Harness Specific Include Files. */ |
| 46 | #include "test.h" |
| 47 | #include "usctest.h" |
| 48 | #include "linux_syscall_numbers.h" |
| 49 | |
| 50 | /* Extern Global Variables */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 51 | |
| 52 | /* Global Variables */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 53 | char *TCID = "add_key02"; /* Test program identifier. */ |
| 54 | int testno; |
| 55 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 56 | |
| 57 | /* Extern Global Functions */ |
| 58 | /******************************************************************************/ |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 59 | /* */ |
| 60 | /* Function: cleanup */ |
| 61 | /* */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 62 | /* Description: Performs all one time clean up for this test on successful */ |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 63 | /* completion, premature exit or failure. Closes all temporary */ |
| 64 | /* files, removes all temporary directories exits the test with */ |
| 65 | /* appropriate return code by calling tst_exit() function. */ |
| 66 | /* */ |
| 67 | /* Input: None. */ |
| 68 | /* */ |
| 69 | /* Output: None. */ |
| 70 | /* */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 71 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 72 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 73 | /* */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 74 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 75 | extern void cleanup() |
| 76 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 77 | |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 78 | TEST_CLEANUP; |
| 79 | tst_rmdir(); |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* Local Functions */ |
| 83 | /******************************************************************************/ |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 84 | /* */ |
| 85 | /* Function: setup */ |
| 86 | /* */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 87 | /* Description: Performs all one time setup for this test. This function is */ |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 88 | /* typically used to capture signals, create temporary dirs */ |
| 89 | /* and temporary files that may be used in the course of this */ |
| 90 | /* test. */ |
| 91 | /* */ |
| 92 | /* Input: None. */ |
| 93 | /* */ |
| 94 | /* Output: None. */ |
| 95 | /* */ |
| 96 | /* Return: On failure - Exits by calling cleanup(). */ |
| 97 | /* On success - returns 0. */ |
| 98 | /* */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 99 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 100 | void setup() |
| 101 | { |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 102 | /* Capture signals if any */ |
| 103 | /* Create temporary directories */ |
| 104 | TEST_PAUSE; |
| 105 | tst_tmpdir(); |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | struct test_case_t { |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 109 | char *type; |
| 110 | char *desc; |
| 111 | void *payload; |
| 112 | int plen; |
| 113 | int exp_errno; |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 114 | } test_cases[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 115 | { |
| 116 | "user", "firstkey", NULL, 1, EINVAL} |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | int test_count = sizeof(test_cases) / sizeof(struct test_case_t); |
| 120 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 121 | int main(int ac, char **av) |
| 122 | { |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 123 | int i; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 124 | int lc; |
| 125 | char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 126 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 127 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 128 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 129 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 130 | setup(); |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 131 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 132 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 133 | Tst_count = 0; |
| 134 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 135 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 136 | for (i = 0; i < test_count; i++) { |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 137 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 138 | /* Call add_key. */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 139 | TEST(ltp_syscall(__NR_add_key, |
| 140 | test_cases[i].type, |
| 141 | test_cases[i].desc, |
| 142 | test_cases[i].payload, |
| 143 | test_cases[i].plen, |
| 144 | KEY_SPEC_USER_KEYRING)); |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 145 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 146 | if (TEST_RETURN != -1) { |
| 147 | tst_resm(TINFO, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 148 | "add_key passed unexpectedly"); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 149 | } else { |
| 150 | |
| 151 | if (errno == test_cases[i].exp_errno) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 152 | tst_resm(TINFO | TTERRNO, |
| 153 | "called add_key() " |
| 154 | "with wrong args got " |
| 155 | "EXPECTED errno"); |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 156 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 157 | tst_resm(TFAIL | TTERRNO, |
| 158 | "called add_key() " |
| 159 | "with wrong args got " |
| 160 | "UNEXPECTED errno"); |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 161 | } |
| 162 | |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 163 | } |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 164 | |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 165 | } |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 166 | |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 167 | } |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 168 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 169 | } |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 170 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 171 | cleanup(); |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 172 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 173 | } |