blob: f2e69949d5b3e810601717695f48afd10307f21e [file] [log] [blame]
plars5f30b5d2003-03-12 20:40:32 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars5f30b5d2003-03-12 20:40:32 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
plars5f30b5d2003-03-12 20:40:32 +000019 * TEST IDENTIFIER : query_module02
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
plars5f30b5d2003-03-12 20:40:32 +000021 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
plars5f30b5d2003-03-12 20:40:32 +000023 * TEST TITLE : Checking error conditions for query_module(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
plars5f30b5d2003-03-12 20:40:32 +000025 * TEST CASE TOTAL : 5
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
plars5f30b5d2003-03-12 20:40:32 +000027 * AUTHOR : Madhu T L <madhu.tarikere@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
plars5f30b5d2003-03-12 20:40:32 +000029 * SIGNALS
30 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
32 *
33 * DESCRIPTION
34 * Verify that,
35 * 1. query_module(2) returns -1 and sets errno to ENOENT for non-existing
36 * module.
37 * 2. query_module(2) returns -1 and sets errno to EINVAL for invalid
38 * which argument.
39 * 3. query_module(2) returns -1 and sets errno to EINVAL for NULL
40 * module name and valid which argument.
41 * 4. query_module(2) returns -1 and sets errno to EINVAL, if module
42 * name parameter is null terminated (zero length) string.
subrata_modak4bb656a2009-02-26 12:02:09 +000043 * 5. query_module(2) returns -1 and sets errno to ENAMETOOLONG for long
plars5f30b5d2003-03-12 20:40:32 +000044 * module name.
subrata_modak4bb656a2009-02-26 12:02:09 +000045 *
plars5f30b5d2003-03-12 20:40:32 +000046 * Setup:
47 * Setup signal handling.
48 * Initialize long module name
49 * Set expected errnos for logging
50 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000051 *
plars5f30b5d2003-03-12 20:40:32 +000052 * Test:
53 * Loop if the proper options are given.
54 * Execute system call
55 * Check return code and error number, if matching,
56 * Issue PASS message
57 * Otherwise,
58 * Issue FAIL message
subrata_modak4bb656a2009-02-26 12:02:09 +000059 *
plars5f30b5d2003-03-12 20:40:32 +000060 * Cleanup:
61 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000062 *
plars5f30b5d2003-03-12 20:40:32 +000063 * USAGE: <for command-line>
64 * query_module02 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t]
65 * where, -c n : Run n copies concurrently.
66 * -e : Turn on errno logging.
67 * -f : Turn off functional testing
68 * -h : Show help screen
69 * -i n : Execute test n times.
70 * -I x : Execute test for x seconds.
71 * -p : Pause for SIGUSR1 before starting
72 * -P x : Pause for x seconds between iterations.
73 * -t : Turn on syscall timing.
subrata_modak4bb656a2009-02-26 12:02:09 +000074 *
plars5f30b5d2003-03-12 20:40:32 +000075 ****************************************************************/
76
77#include <errno.h>
78#include <pwd.h>
79#include <sys/types.h>
subrata_modak024988b2008-09-24 12:55:33 +000080#include <unistd.h>
81#include <limits.h>
plars5f30b5d2003-03-12 20:40:32 +000082#include <asm/atomic.h>
83#include <linux/module.h>
84#include "test.h"
plars5f30b5d2003-03-12 20:40:32 +000085
subrata_modak4bb656a2009-02-26 12:02:09 +000086#ifndef PAGE_SIZE
subrata_modak024988b2008-09-24 12:55:33 +000087#define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
88#endif
89
plars5f30b5d2003-03-12 20:40:32 +000090#define NULLMODNAME ""
Wanlong Gao354ebb42012-12-07 10:10:04 +080091#define LONGMODNAMECHAR 'm' /* Arbitrarily selected */
plars5f30b5d2003-03-12 20:40:32 +000092#define MODNAMEMAX (PAGE_SIZE + 1)
93#define EXP_RET_VAL -1
94#define QM_INVALID (QM_INFO + 100)
95
Wanlong Gao354ebb42012-12-07 10:10:04 +080096struct test_case_t { /* test case structure */
97 char *modname;
98 int which;
99 void *buf;
100 size_t bufsize;
101 int experrno; /* expected errno */
102 char *desc;
plars5f30b5d2003-03-12 20:40:32 +0000103};
104
105char *TCID = "query_module02";
Wanlong Gao354ebb42012-12-07 10:10:04 +0800106
plars5f30b5d2003-03-12 20:40:32 +0000107static char longmodname[MODNAMEMAX];
108static int testno;
109static char out_buf[PAGE_SIZE];
110static size_t ret_size;
111
112static void setup(void);
113static void cleanup(void);
114
Wanlong Gao354ebb42012-12-07 10:10:04 +0800115static struct test_case_t tdat[] = {
plars5f30b5d2003-03-12 20:40:32 +0000116
Wanlong Gao354ebb42012-12-07 10:10:04 +0800117 {"dummy_mod", QM_REFS, (void *)out_buf, sizeof(out_buf), ENOENT,
118 "results for non-existing module"}
119 ,
plars5f30b5d2003-03-12 20:40:32 +0000120
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121 {NULL, QM_INVALID, (void *)out_buf, sizeof(out_buf), EINVAL,
122 "results for invalid which argument"}
123 ,
plars5f30b5d2003-03-12 20:40:32 +0000124
Wanlong Gao354ebb42012-12-07 10:10:04 +0800125 {NULL, QM_REFS, (void *)out_buf, sizeof(out_buf), EINVAL,
126 "results for NULL module name and valid which argument"}
127 ,
plars5f30b5d2003-03-12 20:40:32 +0000128
Wanlong Gao354ebb42012-12-07 10:10:04 +0800129 {NULLMODNAME, QM_REFS, (void *)out_buf, sizeof(out_buf), EINVAL,
130 "results for null terminated (zero lenght) module name"}
131 ,
plars5f30b5d2003-03-12 20:40:32 +0000132
Wanlong Gao354ebb42012-12-07 10:10:04 +0800133 {longmodname, QM_REFS, (void *)out_buf, sizeof(out_buf), ENAMETOOLONG,
134 "results for long module name"}
135 ,
plars5f30b5d2003-03-12 20:40:32 +0000136};
137
138int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
139
Wanlong Gao354ebb42012-12-07 10:10:04 +0800140int main(int argc, char **argv)
plars5f30b5d2003-03-12 20:40:32 +0000141{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200142 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200143 const char *msg;
plars5f30b5d2003-03-12 20:40:32 +0000144
Cyril Hrubiscf0d6262014-09-23 14:03:31 +0200145 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -0800146 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars5f30b5d2003-03-12 20:40:32 +0000147 }
148
149 setup();
150
plars5f30b5d2003-03-12 20:40:32 +0000151 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800152 /* reset tst_count in case we are looping */
153 tst_count = 0;
plars5f30b5d2003-03-12 20:40:32 +0000154
155 for (testno = 0; testno < TST_TOTAL; ++testno) {
156
157 TEST(query_module(tdat[testno].modname,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800158 tdat[testno].which, tdat[testno].buf,
159 tdat[testno].bufsize, &ret_size));
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800160 if ((TEST_RETURN == EXP_RET_VAL) &&
Wanlong Gao354ebb42012-12-07 10:10:04 +0800161 (TEST_ERRNO == tdat[testno].experrno)) {
plars5f30b5d2003-03-12 20:40:32 +0000162 tst_resm(TPASS, "Expected %s, errno: %d",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800163 tdat[testno].desc, TEST_ERRNO);
plars5f30b5d2003-03-12 20:40:32 +0000164 } else {
165 tst_resm(TFAIL, "Unexpected %s ; returned"
Wanlong Gao354ebb42012-12-07 10:10:04 +0800166 " %d (expected %d), errno %d (expected"
167 " %d)", tdat[testno].desc,
168 TEST_RETURN, EXP_RET_VAL,
169 TEST_ERRNO, tdat[testno].experrno);
plars5f30b5d2003-03-12 20:40:32 +0000170 }
171 }
172 }
173 cleanup();
174
Garrett Cooper2c282152010-12-16 00:55:50 -0800175 tst_exit();
plars5f30b5d2003-03-12 20:40:32 +0000176}
177
plars5f30b5d2003-03-12 20:40:32 +0000178/*
179 * setup()
180 * performs all ONE TIME setup for this test
181 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800182void setup(void)
plars5f30b5d2003-03-12 20:40:32 +0000183{
Garrett Cooper2c282152010-12-16 00:55:50 -0800184
plars5f30b5d2003-03-12 20:40:32 +0000185 tst_sig(FORK, DEF_HANDLER, cleanup);
186
Wanlong Gao354ebb42012-12-07 10:10:04 +0800187 if (tst_kvercmp(2, 5, 48) >= 0)
Garrett Cooper53740502010-12-16 00:04:01 -0800188 tst_brkm(TCONF, NULL, "This test will not work on "
Wanlong Gao354ebb42012-12-07 10:10:04 +0800189 "kernels after 2.5.48");
plars5f30b5d2003-03-12 20:40:32 +0000190
191 /* Initialize longmodname to LONGMODNAMECHAR character */
192 memset(longmodname, LONGMODNAMECHAR, MODNAMEMAX - 1);
193
plars5f30b5d2003-03-12 20:40:32 +0000194 /* Pause if that option was specified
195 * TEST_PAUSE contains the code to fork the test with the -c option.
196 */
197 TEST_PAUSE;
198}
199
200/*
201 * cleanup()
202 * performs all ONE TIME cleanup for this test at
203 * completion or premature exit
204 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800205void cleanup(void)
plars5f30b5d2003-03-12 20:40:32 +0000206{
plars5f30b5d2003-03-12 20:40:32 +0000207
Chris Dearmanec6edca2012-10-17 19:54:01 -0700208}