blob: 038c3ef1cd8d33c077cbc64169c421725961dd26 [file] [log] [blame]
Cyril Hrubis2c97e1d2014-08-19 09:46:47 +02001/******************************************************************************
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_modakc5013552009-05-21 18:10:50 +000026
Cyril Hrubis7c631b22014-08-19 09:50:06 +020027#include "config.h"
subrata_modakc5013552009-05-21 18:10:50 +000028#include <stdio.h>
29#include <errno.h>
Cyril Hrubis7c631b22014-08-19 09:50:06 +020030#ifdef HAVE_LINUX_KEYCTL_H
31# include <linux/keyctl.h>
32#endif
subrata_modakc5013552009-05-21 18:10:50 +000033#include "test.h"
subrata_modakc5013552009-05-21 18:10:50 +000034#include "linux_syscall_numbers.h"
35
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020036char *TCID = "add_key02";
Wanlong Gao354ebb42012-12-07 10:10:04 +080037int testno;
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020038int TST_TOTAL = 1;
subrata_modakc5013552009-05-21 18:10:50 +000039
Cyril Hrubis7c631b22014-08-19 09:50:06 +020040#ifdef HAVE_LINUX_KEYCTL_H
41
Cyril Hrubis2c97e1d2014-08-19 09:46:47 +020042static void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080043{
yaberauneyaba5adbc2009-11-24 07:50:52 +000044 tst_rmdir();
subrata_modakc5013552009-05-21 18:10:50 +000045}
46
Cyril Hrubis2c97e1d2014-08-19 09:46:47 +020047static void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080048{
yaberauneyaba5adbc2009-11-24 07:50:52 +000049 TEST_PAUSE;
50 tst_tmpdir();
subrata_modakc5013552009-05-21 18:10:50 +000051}
52
53struct test_case_t {
yaberauneyaba5adbc2009-11-24 07:50:52 +000054 char *type;
55 char *desc;
56 void *payload;
57 int plen;
58 int exp_errno;
subrata_modakc5013552009-05-21 18:10:50 +000059} test_cases[] = {
Cyril Hrubis2c97e1d2014-08-19 09:46:47 +020060 {"user", "firstkey", NULL, 1, EINVAL}
subrata_modakc5013552009-05-21 18:10:50 +000061};
62
Cyril Hrubis2c97e1d2014-08-19 09:46:47 +020063int test_count = ARRAY_SIZE(test_cases);
subrata_modakc5013552009-05-21 18:10:50 +000064
Wanlong Gao354ebb42012-12-07 10:10:04 +080065int main(int ac, char **av)
66{
Garrett Cooper43088e12010-12-13 23:30:59 -080067 int i;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020068 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020069 const char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -080070
Garrett Cooper43088e12010-12-13 23:30:59 -080071 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Coopera9e49f12010-12-16 10:54:03 -080072 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modakc5013552009-05-21 18:10:50 +000073
Garrett Cooper43088e12010-12-13 23:30:59 -080074 setup();
subrata_modakc5013552009-05-21 18:10:50 +000075
Garrett Cooper43088e12010-12-13 23:30:59 -080076 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080077 tst_count = 0;
Garrett Cooper43088e12010-12-13 23:30:59 -080078 for (testno = 0; testno < TST_TOTAL; ++testno) {
subrata_modakc5013552009-05-21 18:10:50 +000079
Wanlong Gao354ebb42012-12-07 10:10:04 +080080 for (i = 0; i < test_count; i++) {
yaberauneyaba5adbc2009-11-24 07:50:52 +000081
Garrett Cooper43088e12010-12-13 23:30:59 -080082 /* Call add_key. */
Jan Stancek359980f2013-02-15 10:16:05 +010083 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));
yaberauneyaba5adbc2009-11-24 07:50:52 +000089
Garrett Cooper43088e12010-12-13 23:30:59 -080090 if (TEST_RETURN != -1) {
91 tst_resm(TINFO,
Wanlong Gao354ebb42012-12-07 10:10:04 +080092 "add_key passed unexpectedly");
Garrett Cooper43088e12010-12-13 23:30:59 -080093 } else {
94
95 if (errno == test_cases[i].exp_errno) {
Cyril Hrubis2c97e1d2014-08-19 09:46:47 +020096 tst_resm(TPASS | TTERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +080097 "called add_key() "
98 "with wrong args got "
99 "EXPECTED errno");
yaberauneyaba5adbc2009-11-24 07:50:52 +0000100 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800101 tst_resm(TFAIL | TTERRNO,
102 "called add_key() "
103 "with wrong args got "
104 "UNEXPECTED errno");
yaberauneyaba5adbc2009-11-24 07:50:52 +0000105 }
106
subrata_modakc5013552009-05-21 18:10:50 +0000107 }
subrata_modakc5013552009-05-21 18:10:50 +0000108
yaberauneyaba5adbc2009-11-24 07:50:52 +0000109 }
subrata_modakc5013552009-05-21 18:10:50 +0000110
yaberauneyaba5adbc2009-11-24 07:50:52 +0000111 }
subrata_modakc5013552009-05-21 18:10:50 +0000112
Garrett Cooper43088e12010-12-13 23:30:59 -0800113 }
yaberauneyaba5adbc2009-11-24 07:50:52 +0000114
Garrett Cooper43088e12010-12-13 23:30:59 -0800115 cleanup();
yaberauneyaba5adbc2009-11-24 07:50:52 +0000116 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700117}
Cyril Hrubis7c631b22014-08-19 09:50:06 +0200118#else
119int main(void)
120{
121 tst_brkm(TCONF, NULL, "linux/keyctl.h was missing upon compilation.");
122}
123#endif /* HAVE_LINUX_KEYCTL_H */