|
From: <ro...@us...> - 2002-12-30 18:07:17
|
Update of /cvsroot/ltp/ltp/testcases/kernel/syscalls/iopl
In directory sc8-pr-cvs1:/tmp/cvs-serv31395/iopl
Added Files:
Makefile iopl01.c iopl02.c
Log Message:
Added iopl() tests by Subhab Biswas <sub...@wi...>
--- NEW FILE: Makefile ---
#
# Copyright (c) International Business Machines Corp., 2001
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
###########################################################################
# name of file : Makefile #
###########################################################################
CFLAGS+= -I../../../../include -Wall -g
LOADLIBES+= -L../../../../lib -lltp
SRCS=$(wildcard *.c)
TARGETS=$(patsubst %.c,%,$(SRCS))
all: $(TARGETS)
install:
@for i in $(TARGETS); do ln -f $$i ../../../bin/$$i ; done
clean:
rm -f $(TARGETS)
--- NEW FILE: iopl01.c ---
/*
* Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc., 59
* Temple Place - Suite 330, Boston MA 02111-1307, USA.
*
*/
/**********************************************************
*
* TEST IDENTIFIER : iopl01
*
* EXECUTED BY : superuser
*
* TEST TITLE : Basic test for iopl(2)
*
* TEST CASE TOTAL : 4
*
* AUTHOR : Subhab Biswas <sub...@wi...>
*
* SIGNALS
* Uses SIGUSR1 to pause before test if option set.
* (See the parse_opts(3) man page).
*
* DESCRIPTION
* This is a Phase I test for the iopl(2) system call.
* It is intended to provide a limited exposure of the system call.
*
* Setup:
* Setup signal handling.
* Test caller is superuser
* Pause for SIGUSR1 if option specified.
*
* Test:
* Loop if the proper options are given.
* Execute system call
* Check return code, if system call failed (return=-1)
* Issue FAIL message with errno.
* Otherwise, Issue PASS message.
*
* Cleanup:
* Print errno log and/or timing stats if options given
*
* USAGE: <for command-line>
* iopl01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
* where, -c n : Run n copies concurrently.
* -e : Turn on errno logging.
* -h : Show help screen
* -f : Turn off functional testing
* -i n : Execute test n times.
* -I x : Execute test for x seconds.
* -p : Pause for SIGUSR1 before starting
* -P x : Pause for x seconds between iterations.
* -t : Turn on syscall timing.
*
****************************************************************/
#include <errno.h>
#include <unistd.h>
#include <sys/io.h>
#include "test.h"
#include "usctest.h"
static void setup();
static void cleanup();
char *TCID = "iopl01"; /* Test program identifier. */
int TST_TOTAL = 4; /* Total number of test cases. */
extern int Tst_count; /* Test Case counter for tst_* routines */
int level; /* I/O privilege level of the process */
int
main(int ac, char **av)
{
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
/* parse standard options */
if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL))
!= (char *)NULL) {
tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
}
/* perform global setup for test */
setup();
/* check looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* reset Tst_count in case we are looping. */
Tst_count = 0;
/*
* Test the system call for possible privelege levels.
* As the privelge level for a normal process is 0,
* start by setting/changing the level to 0.
*/
for (level = 0; level < TST_TOTAL; ++level) {
TEST(iopl(level));
if (TEST_RETURN == -1) {
tst_resm(TFAIL, "iopl() failed for level %d, "
"errno=%d : %s", level,
TEST_ERRNO, strerror(TEST_ERRNO));
} else {
tst_resm(TPASS, "iopl() passed for level %d, "
"returned %d", level,
TEST_RETURN);
}
}
} /* End for TEST_LOOPING */
/* cleanup and exit */
cleanup();
/*NOTREACHED*/
return 0;
} /* End main */
/* setup() - performs all ONE TIME setup for this test */
void
setup()
{
/* capture signals */
tst_sig(NOFORK, DEF_HANDLER, cleanup);
/* Check whether we are root */
if (geteuid() != 0) {
tst_brkm(TBROK, tst_exit, "Must be root for this test!");
/*NOTREACHED*/
}
/* Pause if that option was specified */
TEST_PAUSE;
} /* End setup() */
/*
*cleanup() - performs all ONE TIME cleanup for this test at
* completion or premature exit.
*/
void
cleanup()
{
/*
* back to I/O privilege for normal process.
*/
if (iopl(0) == -1) {
tst_resm(TWARN, "iopl() cleanup failed");
}
/*
* print timing stats if that option was specified.
* print errno log if that option was specified.
*/
TEST_CLEANUP;
/* exit with return code appropriate for results */
tst_exit();
} /* End cleanup() */
--- NEW FILE: iopl02.c ---
/*
* Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write the Free Software Foundation, Inc., 59
* Temple Place - Suite 330, Boston MA 02111-1307, USA.
*
*/
/**********************************************************
*
* TEST IDENTIFIER : iopl02
*
* EXECUTED BY : superuser
*
* TEST TITLE : Tests for error conditions
*
* TEST CASE TOTAL : 2
*
* AUTHOR : Subhab Biwas <sub...@wi...>
*
* SIGNALS
* Uses SIGUSR1 to pause before test if option set.
* (See the parse_opts(3) man page).
*
* DESCRIPTION
* Verify that
* 1) iopl(2) returns -1 and sets errno to EINVAL for privilege
* level greater than 3.
* 2) iopl(2) returns -1 and sets errno to EPERM if the current
* user is not the super-user.
*
* Setup:
* Setup signal handling.
* Test caller is superuser
* Set expected errnos for logging
* Pause for SIGUSR1 if option specified.
*
* Test:
* Loop if the proper options are given.
* Execute system call
* Check return code and error number, if matching,
* Issue PASS message
* Otherwise,
* Issue FAIL message
* Perform testcase specific cleanup (if needed)
*
* Cleanup:
* Print errno log and/or timing stats if options given
*
* USAGE: <for command-line>
* iopl02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
* where, -c n : Run n copies concurrently.
* -e : Turn on errno logging.
* -h : Show help screen
* -f : Turn off functional testing
* -i n : Execute test n times.
* -I x : Execute test for x seconds.
* -p : Pause for SIGUSR1 before starting
* -P x : Pause for x seconds between iterations.
* -t : Turn on syscall timing.
*
****************************************************************/
#include <errno.h>
#include <unistd.h>
#include <sys/io.h>
#include <pwd.h>
#include "test.h"
#include "usctest.h"
#define INVALID_LEVEL 4 /* Invalid privilege level */
#define EXP_RET_VAL -1
static void setup();
static int setup1(void);
static void cleanup1();
static void cleanup();
char *TCID = "iopl02"; /* Test program identifier. */
extern int Tst_count; /* Test Case counter for tst_* routines */
static int exp_enos[] = {EINVAL, EPERM, 0};
static char nobody_uid[] = "nobody";
struct passwd *ltpuser;
struct test_cases_t {
int level; /* I/O privilege level */
char *desc; /* test case description */
int exp_errno; /* expected error number */
} test_cases[] = {
{ INVALID_LEVEL, "Invalid privilege level", EINVAL },
{ 1, "Non super-user", EPERM }
};
int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
int
main(int ac, char **av)
{
int lc, i; /* loop counter */
char *msg; /* message returned from parse_opts */
/* parse standard options */
if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL))
!= (char *)NULL) {
tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
}
/* perform global setup for test */
setup();
/* check looping state if -i option given */
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* reset Tst_count in case we are looping. */
Tst_count = 0;
for (i = 0; i < TST_TOTAL; ++i) {
if (i == 1) {
/* setup Non super-user for second test */
if (setup1()) {
/* setup1() failed, skip this test */
continue;
}
}
/*
* Call iopl(2)
*/
TEST(iopl(test_cases[i].level));
if ((TEST_RETURN == EXP_RET_VAL) &&
(TEST_ERRNO == test_cases[i].exp_errno)) {
tst_resm(TPASS, "Expected failure for %s, "
"errno: %d", test_cases[i].desc,
TEST_ERRNO);
} else {
tst_resm(TFAIL, "Unexpected results for %s ; "
"returned %d (expected %d), errno %d "
"(expected errno %d)",
test_cases[i].desc,
TEST_RETURN, EXP_RET_VAL,
TEST_ERRNO, test_cases[i].exp_errno);
}
TEST_ERROR_LOG(TEST_ERRNO);
if (i == 1) {
/* revert back to super user */
cleanup1();
}
}
} /* End for TEST_LOOPING */
/* cleanup and exit */
cleanup();
/*NOTREACHED*/
return 0;
} /* End main */
/* setup1() - set up non-super user for second test case */
int
setup1(void)
{
/* switch to "nobody" user */
if (seteuid(ltpuser->pw_uid) == -1) {
tst_resm(TWARN, "Failed to set effective"
"uid to %d", ltpuser->pw_uid);
return 1;
}
return 0;
}
/* cleanup1() - reset to super user for first test case */
void
cleanup1()
{
/* reset user as root */
if (seteuid(0) == -1) {
tst_brkm(TBROK, tst_exit, "Failed to set uid as root");
}
}
/* setup() - performs all ONE TIME setup for this test */
void
setup()
{
/* capture signals */
tst_sig(NOFORK, DEF_HANDLER, cleanup);
/* Check whether we are root */
if (geteuid() != 0) {
tst_brkm(TBROK, tst_exit, "Must be root for this test!");
}
/* Check if "nobody" user id exists */
if ((ltpuser = getpwnam(nobody_uid)) == NULL) {
tst_brkm(TBROK, tst_exit, "\"nobody\" user id doesn't exist");
}
/* Set up the expected error numbers for -e option */
TEST_EXP_ENOS(exp_enos);
/* Pause if that option was specified */
TEST_PAUSE;
} /* End setup() */
/*
*cleanup() - performs all ONE TIME cleanup for this test at
* completion or premature exit.
*/
void
cleanup()
{
/*
* print timing stats if that option was specified.
* print errno log if that option was specified.
*/
TEST_CLEANUP;
/* exit with return code appropriate for results */
tst_exit();
} /* End cleanup() */
|