blob: 591fa0cab53bebca3b42798a98b04519991adc53 [file] [log] [blame]
subrata_modakc5013552009-05-21 18:10:50 +00001/******************************************************************************/
yaberauneyaba5adbc2009-11-24 07:50:52 +00002/* Copyright (c) Crackerjack Project., 2007 */
3/* */
subrata_modakc5013552009-05-21 18:10:50 +00004/* 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 */
yaberauneyaba5adbc2009-11-24 07:50:52 +00006/* 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 Gao4548c6c2012-10-19 18:03:36 +080016/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
yaberauneyaba5adbc2009-11-24 07:50:52 +000017/* */
subrata_modakc5013552009-05-21 18:10:50 +000018/******************************************************************************/
19/******************************************************************************/
yaberauneyaba5adbc2009-11-24 07:50:52 +000020/* */
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_modakc5013552009-05-21 18:10:50 +000039/******************************************************************************/
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_modakc5013552009-05-21 18:10:50 +000051
52/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080053char *TCID = "add_key02"; /* Test program identifier. */
54int testno;
55int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modakc5013552009-05-21 18:10:50 +000056
57/* Extern Global Functions */
58/******************************************************************************/
yaberauneyaba5adbc2009-11-24 07:50:52 +000059/* */
60/* Function: cleanup */
61/* */
subrata_modakc5013552009-05-21 18:10:50 +000062/* Description: Performs all one time clean up for this test on successful */
yaberauneyaba5adbc2009-11-24 07:50:52 +000063/* 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_modakc5013552009-05-21 18:10:50 +000071/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
yaberauneyaba5adbc2009-11-24 07:50:52 +000072/* On success - Exits calling tst_exit(). With '0' return code. */
73/* */
subrata_modakc5013552009-05-21 18:10:50 +000074/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +080075extern void cleanup()
76{
Garrett Cooper2c282152010-12-16 00:55:50 -080077
yaberauneyaba5adbc2009-11-24 07:50:52 +000078 TEST_CLEANUP;
79 tst_rmdir();
subrata_modakc5013552009-05-21 18:10:50 +000080}
81
82/* Local Functions */
83/******************************************************************************/
yaberauneyaba5adbc2009-11-24 07:50:52 +000084/* */
85/* Function: setup */
86/* */
subrata_modakc5013552009-05-21 18:10:50 +000087/* Description: Performs all one time setup for this test. This function is */
yaberauneyaba5adbc2009-11-24 07:50:52 +000088/* 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_modakc5013552009-05-21 18:10:50 +000099/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800100void setup()
101{
yaberauneyaba5adbc2009-11-24 07:50:52 +0000102 /* Capture signals if any */
103 /* Create temporary directories */
104 TEST_PAUSE;
105 tst_tmpdir();
subrata_modakc5013552009-05-21 18:10:50 +0000106}
107
108struct test_case_t {
yaberauneyaba5adbc2009-11-24 07:50:52 +0000109 char *type;
110 char *desc;
111 void *payload;
112 int plen;
113 int exp_errno;
subrata_modakc5013552009-05-21 18:10:50 +0000114} test_cases[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800115 {
116 "user", "firstkey", NULL, 1, EINVAL}
subrata_modakc5013552009-05-21 18:10:50 +0000117};
118
119int test_count = sizeof(test_cases) / sizeof(struct test_case_t);
120
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121int main(int ac, char **av)
122{
Garrett Cooper43088e12010-12-13 23:30:59 -0800123 int i;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200124 int lc;
125 char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -0800126
Garrett Cooper43088e12010-12-13 23:30:59 -0800127 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Coopera9e49f12010-12-16 10:54:03 -0800128 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modakc5013552009-05-21 18:10:50 +0000129
Garrett Cooper43088e12010-12-13 23:30:59 -0800130 setup();
subrata_modakc5013552009-05-21 18:10:50 +0000131
Garrett Cooper43088e12010-12-13 23:30:59 -0800132 for (lc = 0; TEST_LOOPING(lc); ++lc) {
133 Tst_count = 0;
134 for (testno = 0; testno < TST_TOTAL; ++testno) {
subrata_modakc5013552009-05-21 18:10:50 +0000135
Wanlong Gao354ebb42012-12-07 10:10:04 +0800136 for (i = 0; i < test_count; i++) {
yaberauneyaba5adbc2009-11-24 07:50:52 +0000137
Garrett Cooper43088e12010-12-13 23:30:59 -0800138 /* Call add_key. */
Jan Stancek359980f2013-02-15 10:16:05 +0100139 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));
yaberauneyaba5adbc2009-11-24 07:50:52 +0000145
Garrett Cooper43088e12010-12-13 23:30:59 -0800146 if (TEST_RETURN != -1) {
147 tst_resm(TINFO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800148 "add_key passed unexpectedly");
Garrett Cooper43088e12010-12-13 23:30:59 -0800149 } else {
150
151 if (errno == test_cases[i].exp_errno) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800152 tst_resm(TINFO | TTERRNO,
153 "called add_key() "
154 "with wrong args got "
155 "EXPECTED errno");
yaberauneyaba5adbc2009-11-24 07:50:52 +0000156 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800157 tst_resm(TFAIL | TTERRNO,
158 "called add_key() "
159 "with wrong args got "
160 "UNEXPECTED errno");
yaberauneyaba5adbc2009-11-24 07:50:52 +0000161 }
162
subrata_modakc5013552009-05-21 18:10:50 +0000163 }
subrata_modakc5013552009-05-21 18:10:50 +0000164
yaberauneyaba5adbc2009-11-24 07:50:52 +0000165 }
subrata_modakc5013552009-05-21 18:10:50 +0000166
yaberauneyaba5adbc2009-11-24 07:50:52 +0000167 }
subrata_modakc5013552009-05-21 18:10:50 +0000168
Garrett Cooper43088e12010-12-13 23:30:59 -0800169 }
yaberauneyaba5adbc2009-11-24 07:50:52 +0000170
Garrett Cooper43088e12010-12-13 23:30:59 -0800171 cleanup();
yaberauneyaba5adbc2009-11-24 07:50:52 +0000172 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700173}