$Id: usctest.3,v 1.2 2000/08/31 18:40:28 nstraz Exp $ Copyright (c) 2000 Silicon Graphics, Inc. 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. Further, this software is distributed without any warranty that it is free of the rightful claim of any third person regarding infringement or the like. Any license provided herein, whether implied or otherwise, applies only to this software file. Patent licenses, if any, provided herein do not apply to combinations of this program with other software, or any other product whatsoever. You should have received a copy of the GNU General Public License along with this program; if not, write the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, Mountain View, CA 94043, or: http://www.sgi.com For further information regarding this notice, see: http://oss.sgi.com/projects/GenInfo/NoticeExplan/ USCTEST 3 01/21/2011 "Linux Test Project"
NAME
usctest - macros and libraries for common functions in system call tests
SYNOPSIS
Routines:
char *
parse_opts(...)
Macros
TEST_PAUSE
TEST(syscall)
TEST_CALLER(syscall, pid)
.br
TEST_VOID(syscall)
TEST_CLEANUP
TEST_LOOPING(counter)
TEST_ERROR_LOG(errno)
TEST_EXP_ENOS(array)
Global Variable(s) (see parse_opts(3) for complete list):
int TEST_RETURN; /* set by the TEST macro to the return code from syscall */
int TEST_ERRNO; /* set by the TEST macro to the value of errno after syscall returns */
/* All STD_* variables referenced below are set by the parse_opts(3) routine. */
DESCRIPTION
The TEST_PAUSE macro checks if the global variable STD_PAUSE is set. If so, it
pauses for a SIGUSR1 before continuing execution. The signal handler used does nothing.
After the signal is processed, the previous action is replaced for SIGUSR1.
The TEST(syscall) macro executes (syscall) and times its execution.
It saves the max time, min time, accumulated time, and
execution count, if STD_TIMING_ON is set.
TheTEST_CALLER(syscall, pid) macro executes (syscall) and times its execution.
It saves the max time, min time, accumulated time, and
execution count, if STD_TIMING_ON is set and if pid is equal to the current pid.
.sp
The TEST_VOID(syscall) macro works exactly the same as the TEST()
macro except that it does NOT set the global TEST_RETURN. It is intended
to be used with system calls that do not have a return value.
The TEST_CLEANUP macro prints timing statistics,
accumulated through the TEST macro, if STD_TIMING_ON is set. Also, prints the errno return
counts as logged by the TEST_ERROR_LOG macro, if STD_ERR_LOG is set. TEST_CLEANUP uses
tst_resm(3) to output this information.
The TEST_LOOPING(counter) macro checks counter against
the global variable STD_LOOP_COUNTER. If counter is less than STD_LOOP_COUNTER or STD_INFINITE
is set, it returns TRUE.
The TEST_ERROR_LOG macro records the return of errno as unexpected, unless the option to
turn it off is specified on the command line.
The TEST_EXP_ENOS(array) macro sets an internal flag for each errno in array, indicating
that the errno is expected at some point in the test. This is used by the TEST_CLEANUP macro to determine
which errnos are expected when printing the log. The array must be zero terminated.
The parse_opts routine parses the command line (see parse_opts(3)). All STD_* global
variables used are set by the parse_opts(3) routine.
EXAMPLES
Below is a partial template of a system call test using these routines, macros, and global variables.
void setup(void)
{
TEST_PAUSE; /* Pause if option specified */
}
void cleanup(void)
{
TEST_CLEANUP;
}
int main(int argc, char *argv[])
{
int lc;
char *msg;
int exp_enos[]={EACCESS, 0};
TEST_EXP_ENOS(exp_enos); /* set expected errnos */
setup(); /* execute setup */
/* parse options */
msg = parse_opts(ac, av, NULL, NULL);
/* Check parse_opts return */
for (lc=0; TEST_LOOPING(lc); lc++) {
TEST(open("file", O_RDWR))
if (TEST_RETURN == -1) {
TEST_ERROR_LOG(TEST_ERRNO)
/* BREAK test case, or whatever... */
}
}
cleanup();
tst_exit();
}
"SEE ALSO"
parse_opts(3).
"RETURN VALUES"
The TEST_LOOPING macro evaluates to TRUE (1) or FALSE (0), and is intended for
use in while or for loops. The TEST macro places the return value from
syscall in the global variable TEST_RETURN and the errno in the global
variable TEST_ERRNO. The TEST_PAUSE, TEST_CLEANUP,
TEST_ERROR_LOG, and TEST_EXP_ENOS macros do not have any return
values.