Cyril Hrubis | 2c97e1d | 2014-08-19 09:46:47 +0200 | [diff] [blame] | 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 Foundation, * |
| 16 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 17 | * * |
| 18 | ******************************************************************************/ |
| 19 | |
| 20 | /* |
| 21 | * Basic test for the add_key() syscall. |
| 22 | * |
| 23 | * History: Porting from Crackerjack to LTP is done by |
| 24 | * Manas Kumar Nayak maknayak@in.ibm.com> |
| 25 | */ |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 26 | |
Cyril Hrubis | 7c631b2 | 2014-08-19 09:50:06 +0200 | [diff] [blame] | 27 | #include "config.h" |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | #include <errno.h> |
Cyril Hrubis | 7c631b2 | 2014-08-19 09:50:06 +0200 | [diff] [blame] | 30 | #ifdef HAVE_LINUX_KEYCTL_H |
| 31 | # include <linux/keyctl.h> |
| 32 | #endif |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 33 | #include "test.h" |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 34 | #include "linux_syscall_numbers.h" |
| 35 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 36 | char *TCID = "add_key02"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 37 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 38 | int TST_TOTAL = 1; |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 39 | |
Cyril Hrubis | 7c631b2 | 2014-08-19 09:50:06 +0200 | [diff] [blame] | 40 | #ifdef HAVE_LINUX_KEYCTL_H |
| 41 | |
Cyril Hrubis | 2c97e1d | 2014-08-19 09:46:47 +0200 | [diff] [blame] | 42 | static void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 43 | { |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 44 | tst_rmdir(); |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Cyril Hrubis | 2c97e1d | 2014-08-19 09:46:47 +0200 | [diff] [blame] | 47 | static void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 48 | { |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 49 | TEST_PAUSE; |
| 50 | tst_tmpdir(); |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | struct test_case_t { |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 54 | char *type; |
| 55 | char *desc; |
| 56 | void *payload; |
| 57 | int plen; |
| 58 | int exp_errno; |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 59 | } test_cases[] = { |
Cyril Hrubis | 2c97e1d | 2014-08-19 09:46:47 +0200 | [diff] [blame] | 60 | {"user", "firstkey", NULL, 1, EINVAL} |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
Cyril Hrubis | 2c97e1d | 2014-08-19 09:46:47 +0200 | [diff] [blame] | 63 | int test_count = ARRAY_SIZE(test_cases); |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 64 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 65 | int main(int ac, char **av) |
| 66 | { |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 67 | int i; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 68 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 69 | const char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 70 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 71 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 72 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 73 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 74 | setup(); |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 75 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 76 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 77 | tst_count = 0; |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 78 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 79 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 80 | for (i = 0; i < test_count; i++) { |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 81 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 82 | /* Call add_key. */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 83 | TEST(ltp_syscall(__NR_add_key, |
| 84 | test_cases[i].type, |
| 85 | test_cases[i].desc, |
| 86 | test_cases[i].payload, |
| 87 | test_cases[i].plen, |
| 88 | KEY_SPEC_USER_KEYRING)); |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 89 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 90 | if (TEST_RETURN != -1) { |
| 91 | tst_resm(TINFO, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 92 | "add_key passed unexpectedly"); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 93 | } else { |
| 94 | |
| 95 | if (errno == test_cases[i].exp_errno) { |
Cyril Hrubis | 2c97e1d | 2014-08-19 09:46:47 +0200 | [diff] [blame] | 96 | tst_resm(TPASS | TTERRNO, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 97 | "called add_key() " |
| 98 | "with wrong args got " |
| 99 | "EXPECTED errno"); |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 100 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 101 | tst_resm(TFAIL | TTERRNO, |
| 102 | "called add_key() " |
| 103 | "with wrong args got " |
| 104 | "UNEXPECTED errno"); |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 105 | } |
| 106 | |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 107 | } |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 108 | |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 109 | } |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 110 | |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 111 | } |
subrata_modak | c501355 | 2009-05-21 18:10:50 +0000 | [diff] [blame] | 112 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 113 | } |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 114 | |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 115 | cleanup(); |
yaberauneya | ba5adbc | 2009-11-24 07:50:52 +0000 | [diff] [blame] | 116 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 117 | } |
Cyril Hrubis | 7c631b2 | 2014-08-19 09:50:06 +0200 | [diff] [blame] | 118 | #else |
| 119 | int main(void) |
| 120 | { |
| 121 | tst_brkm(TCONF, NULL, "linux/keyctl.h was missing upon compilation."); |
| 122 | } |
| 123 | #endif /* HAVE_LINUX_KEYCTL_H */ |