void tst_resm(int ttype, char *tmesg, [arg ...])
void tst_resm_hexd(int ttype, const void *buf, size_t size, char *tmesg, [arg ...])
void tst_brkm(int ttype, void (*func)(), char *tmesg, [arg ...])
void tst_flush()
void tst_exit()
int tst_environ()
extern int tst_count; extern int tst_range;
The TCID and TST_TOTAL global variables are externed in the library, and MUST be defined/initialized by tests using the library. TCID must be set to the Test Case IDentifier, and TST_TOTAL must be set to the total number of test cases that will be reported.
The other global variables are available as externs to tests linked with tst_res.o. tst_count is the running count of the number of test results that have been reported so far. The library initializes it to 0, and it should not be modified by the test. The details are described below under the appropriate functions.
10 ttype test result type; one of TPASS, TFAIL, TBROK, TCONF, TWARN, or TINFO (explained below).
10 fname pointer to a character string holding the name of a file whose contents will be printed on a new line following tmesg. If this pointer is NULL, it is ignored.
10 tmesg, [arg ...] pointer to a character string containing a message explaining the test result. This character string can contain percent-sign conversion specifications as in printf(3C) with corresponding arg arguments following the tmesg argument. NOTE: These routines use static space internally to hold the expanded message. The maximum size allowed for an expanded message is 2048 bytes.
10 func pointer to a function which performs either the cleanup necessary prior to exiting the test or some function executed at the end of each iteration of a loop.
10 buf pointer to a buffer whose contents will be printed in hexadecimal format.
10 size size of the buffer.
10 TPASS The test case produced expected results.
10 TFAIL The test case produced unexpected results.
10 TBROK A resource needed to execute the test case was not available (e.g. a temporary file could not be opened).
10 TCONF The test case was not appropriate for the current hardware or software configuration (e.g. MLS was not enabled).
10 TWARN The testing procedure caused undesirable side effects that did not affect test results (e.g. a temporary file could not be removed after all test results were recorded).
10 TINFO An informative message about the execution of the test that does not correspond to a test case result and does not indicate a problem.
tst_brk() and tst_brkm() are used to report results for all test cases remaining in the test, and then call a cleanup function. The only result types that are valid for these functions are: TFAIL, TBROK, and TCONF. When called with a ttype of TFAIL or TBROK, one result of the specified ttype will be printed, followed by results of type TBROK for the remaining test cases. When called with a ttype of TCONF, the specified ttype will be printed for all remaining test cases. If func is not NULL, tst_brk() and tst_brkm() will call func after all results have been printed. If the call to func returns, tst_brk() and tst_brkm() will then call tst_exit(). If func is NULL, tst_brk() and tst_brkm() return to the caller after all results have been printed. If tst_brk() is called with a fname argument, the contents of the file will only be printed for the first reported result. tst_brk() takes the fname argument whereas tst_brkm() does not.
tst_flush() is used to print any results pending because of CONDENSE or NOPASS modes (described below), and flushes the output stream.
tst_exit() is used to allow tests to exit with a meaningful exit value. A bit is set in the exit value for each of the non passing test case result types (TFAIL, TBROK, and TWARN) encountered by the library. Thus any bit which is set in the exit value indicates that the corresponding result flag was used at least once in the test run.
The current bit fields for the result types are as follows:
10 TPASS 0000 /* .... .... */
10 TFAIL 0001 /* .... ...1 */
10 TBROK 0002 /* .... ..1. */
10 TWARN 0004 /* .... .1.. */
10 TINFO 0020 /* ...1 .... */
10 TCONF 0040 /* ..1. .... */
NOTE: TPASS and TINFO do not have an effect on the test program exit status.
tst_environ() is used to ensure that results reported by this library will go to the original stdout, even if the test changes the original stdout to another file, or closes it. A test may want to do this in order to redirect output that normally goes to stdout (e.g. printf() output) to a file. tst_environ() returns 0 upon successful completion, and -1 if it encountered any problems.
15 VERBOSE A test result output line is generated for each test result. This is the default mode.
15 CONDENSE Consecutive, identical PASS, FAIL, BROK, CONF, and RETR test results are condensed into one output line. The test case number field contains the range of results involved. WARN and INFO output lines are not condensed, but printed as usual.
15 NOPASS All PASS, CONF, INFO, and RETR output lines are discarded (i.e. not printed), and consecutive, identical FAIL and BROK output lines are condensed as in CONDENSE mode. WARN output lines are printed as usual.
15 DISCARD All output lines are discarded.
#include "test.h" char *TCID = "tsttcs01"; /* set test case identifier */ int TST_TOTAL = 15; /* set total number of test results */ main() { . . /* a successful test result */ tst_resm(TPASS, "what was tested"); . . /* break all remaining test results */ tst_brkm(TBROK, cleanup, "what didn't work"); /* or */ tst_brk(TBROK, file, cleanup, "what didn't work"); . . /* exit after all test results have been passed to tst_res */ tst_exit(); }
Sample output:
tsttcs01 1 PASS : Able to create MAXUP processes tsttcs01 2 FAIL : Too many processes (MAXUP+1) created tsttcs01 3 BROK : tabinfo(PROCTAB, &tbs) failed; errno = 13: Permission denied
A WARN result message will be printed if any of the following occur:
If an invalid test type is specified.
If tst_count is negative.
If one of the tst_brk[m]() routines is called with a test type other than TFAIL, TBROK, TCONF.
If there are any problems opening/reading/writing the contents of fname.
The programmer is free to alter the value of tst_count causing possible test result order problems.