Home | History | Annotate | Download | only in query_module
      1 /*
      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
     13  * with this program; if not, write the Free Software Foundation, Inc.,
     14  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     15  *
     16  */
     17 /**********************************************************
     18  *
     19  *    TEST IDENTIFIER   : query_module02
     20  *
     21  *    EXECUTED BY       : anyone
     22  *
     23  *    TEST TITLE        : Checking error conditions for query_module(2)
     24  *
     25  *    TEST CASE TOTAL   : 5
     26  *
     27  *    AUTHOR            : Madhu T L <madhu.tarikere (at) wipro.com>
     28  *
     29  *    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.
     43  *	5. query_module(2) returns -1 and sets errno to ENAMETOOLONG for long
     44  *	   module name.
     45  *
     46  *	Setup:
     47  *	  Setup signal handling.
     48  *	  Initialize  long module name
     49  *	  Set expected errnos for logging
     50  *	  Pause for SIGUSR1 if option specified.
     51  *
     52  *	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
     59  *
     60  *	Cleanup:
     61  *	  Print errno log and/or timing stats if options given
     62  *
     63  * 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.
     74  *
     75  ****************************************************************/
     76 
     77 #include <errno.h>
     78 #include <pwd.h>
     79 #include <sys/types.h>
     80 #include <unistd.h>
     81 #include <limits.h>
     82 #include <asm/atomic.h>
     83 #include <linux/module.h>
     84 #include "test.h"
     85 
     86 #ifndef PAGE_SIZE
     87 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
     88 #endif
     89 
     90 #define NULLMODNAME	""
     91 #define LONGMODNAMECHAR	'm'	/* Arbitrarily selected */
     92 #define MODNAMEMAX	(PAGE_SIZE + 1)
     93 #define EXP_RET_VAL	-1
     94 #define QM_INVALID	(QM_INFO + 100)
     95 
     96 struct 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;
    103 };
    104 
    105 char *TCID = "query_module02";
    106 
    107 static char longmodname[MODNAMEMAX];
    108 static int testno;
    109 static char out_buf[PAGE_SIZE];
    110 static size_t ret_size;
    111 
    112 static void setup(void);
    113 static void cleanup(void);
    114 
    115 static struct test_case_t tdat[] = {
    116 
    117 	{"dummy_mod", QM_REFS, (void *)out_buf, sizeof(out_buf), ENOENT,
    118 	 "results for non-existing module"}
    119 	,
    120 
    121 	{NULL, QM_INVALID, (void *)out_buf, sizeof(out_buf), EINVAL,
    122 	 "results for invalid which argument"}
    123 	,
    124 
    125 	{NULL, QM_REFS, (void *)out_buf, sizeof(out_buf), EINVAL,
    126 	 "results for NULL module name and valid which argument"}
    127 	,
    128 
    129 	{NULLMODNAME, QM_REFS, (void *)out_buf, sizeof(out_buf), EINVAL,
    130 	 "results for null terminated (zero lenght) module name"}
    131 	,
    132 
    133 	{longmodname, QM_REFS, (void *)out_buf, sizeof(out_buf), ENAMETOOLONG,
    134 	 "results for long module name"}
    135 	,
    136 };
    137 
    138 int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
    139 
    140 int main(int argc, char **argv)
    141 {
    142 	int lc;
    143 
    144 	tst_parse_opts(argc, argv, NULL, NULL);
    145 
    146 	setup();
    147 
    148 	for (lc = 0; TEST_LOOPING(lc); lc++) {
    149 		/* reset tst_count in case we are looping */
    150 		tst_count = 0;
    151 
    152 		for (testno = 0; testno < TST_TOTAL; ++testno) {
    153 
    154 			TEST(query_module(tdat[testno].modname,
    155 					  tdat[testno].which, tdat[testno].buf,
    156 					  tdat[testno].bufsize, &ret_size));
    157 			if ((TEST_RETURN == EXP_RET_VAL) &&
    158 			    (TEST_ERRNO == tdat[testno].experrno)) {
    159 				tst_resm(TPASS, "Expected %s, errno: %d",
    160 					 tdat[testno].desc, TEST_ERRNO);
    161 			} else {
    162 				tst_resm(TFAIL, "Unexpected %s ; returned"
    163 					 " %d (expected %d), errno %d (expected"
    164 					 " %d)", tdat[testno].desc,
    165 					 TEST_RETURN, EXP_RET_VAL,
    166 					 TEST_ERRNO, tdat[testno].experrno);
    167 			}
    168 		}
    169 	}
    170 	cleanup();
    171 
    172 	tst_exit();
    173 }
    174 
    175 /*
    176  * setup()
    177  *	performs all ONE TIME setup for this test
    178  */
    179 void setup(void)
    180 {
    181 
    182 	tst_sig(FORK, DEF_HANDLER, cleanup);
    183 
    184 	if (tst_kvercmp(2, 5, 48) >= 0)
    185 		tst_brkm(TCONF, NULL, "This test will not work on "
    186 			 "kernels after 2.5.48");
    187 
    188 	/* Initialize longmodname to LONGMODNAMECHAR character */
    189 	memset(longmodname, LONGMODNAMECHAR, MODNAMEMAX - 1);
    190 
    191 	/* Pause if that option was specified
    192 	 * TEST_PAUSE contains the code to fork the test with the -c option.
    193 	 */
    194 	TEST_PAUSE;
    195 }
    196 
    197 /*
    198  * cleanup()
    199  *	performs all ONE TIME cleanup for this test at
    200  *	completion or premature exit
    201  */
    202 void cleanup(void)
    203 {
    204 
    205 }
    206