From 888214a8bdeb7447c48434fe90267795c3d5f7f3 Mon Sep 17 00:00:00 2001 From: tribby Date: Sun, 8 Feb 1998 23:47:18 +0000 Subject: [PATCH] Original GNO code for kill tests from Dave Tribby --- bin/kill/tests/Makefile | 10 +++ bin/kill/tests/dotests | 100 ++++++++++++++++++++++++++++ bin/kill/tests/fulltests | 29 ++++++++ bin/kill/tests/handlesigs.c | 122 ++++++++++++++++++++++++++++++++++ bin/kill/tests/handlesigs.rez | 30 +++++++++ bin/kill/tests/signame.list | 2 + bin/kill/tests/signames.list | 31 +++++++++ bin/kill/tests/sigout.list | 28 ++++++++ 8 files changed, 352 insertions(+) create mode 100644 bin/kill/tests/Makefile create mode 100644 bin/kill/tests/dotests create mode 100644 bin/kill/tests/fulltests create mode 100644 bin/kill/tests/handlesigs.c create mode 100644 bin/kill/tests/handlesigs.rez create mode 100644 bin/kill/tests/signame.list create mode 100644 bin/kill/tests/signames.list create mode 100644 bin/kill/tests/sigout.list diff --git a/bin/kill/tests/Makefile b/bin/kill/tests/Makefile new file mode 100644 index 0000000..8a62e3b --- /dev/null +++ b/bin/kill/tests/Makefile @@ -0,0 +1,10 @@ +# +# This makefile is intended for use with dmake(1) on Apple IIGS +# $Id: Makefile,v 1.1 1998/02/08 23:47:08 tribby Exp $ +# +# Created by Dave Tribby, January 1998 + +PROG= handlesigs + +CFLAGS = -v +.INCLUDE : /src/gno/prog.mk diff --git a/bin/kill/tests/dotests b/bin/kill/tests/dotests new file mode 100644 index 0000000..a6b6e66 --- /dev/null +++ b/bin/kill/tests/dotests @@ -0,0 +1,100 @@ +# Tests for kill command; invoked by command file "fulltests" +# Written by Dave Tribby (January 1998) +# $Id: dotests,v 1.1 1998/02/08 23:47:10 tribby Exp $ + +# Location of the kill command to be tested +set testcmd="../kill" + +# Record starting time +echo -n "Testing command $testcmd beginning at" +date + +set cmp="sigout.list" +set dest="/tmp/$cmp" +set cmdname="/tmp/testsigs" +set testprog="./handlesigs" +echo "Starting process ($testprog) that will handle signals" +echo "### NOTE: The non-error tests cannot be run because gsh will not" +echo "### put the test program ($testprog) in the background." +echo "### The following steps do work if run manually..." +echo "### $testprog $testcmd $cmdname > $dest & " +echo "### sleep 10" +### echo "Sending all legal signals to $testprog via script $cmdname" +echo "### chtyp -l exec $cmdname" +echo "### $cmdname" +### echo "Checking results against control file $cmp (no differences expected)" +echo "### cmp $cmp $dest" +### echo " Completion status = $status" +echo "### Completion status = cannot run test from gsh ###" +echo "" + +set cmp="signame.list" +set dest="/tmp/$cmp" +echo "Getting list of legal signal names" +$testcmd -l > $dest +echo "Checking results against control file $cmp (no differences expected)" +cmp $cmp $dest +echo " Completion status = $status" +echo "" + +set cmp="signames.list" +set dest="/tmp/$cmp" +echo "Getting list of legal signal names, one at a time" +$testcmd -l 1 > $dest +$testcmd -l 2 >> $dest +$testcmd -l 3 >> $dest +$testcmd -l 4 >> $dest +$testcmd -l 5 >> $dest +$testcmd -l 6 >> $dest +$testcmd -l 7 >> $dest +$testcmd -l 8 >> $dest +$testcmd -l 9 >> $dest +$testcmd -l 10 >> $dest +$testcmd -l 11 >> $dest +$testcmd -l 12 >> $dest +$testcmd -l 13 >> $dest +$testcmd -l 14 >> $dest +$testcmd -l 15 >> $dest +$testcmd -l 16 >> $dest +$testcmd -l 17 >> $dest +$testcmd -l 18 >> $dest +$testcmd -l 19 >> $dest +$testcmd -l 20 >> $dest +$testcmd -l 21 >> $dest +$testcmd -l 22 >> $dest +$testcmd -l 23 >> $dest +$testcmd -l 24 >> $dest +$testcmd -l 25 >> $dest +$testcmd -l 26 >> $dest +$testcmd -l 27 >> $dest +$testcmd -l 28 >> $dest +$testcmd -l 29 >> $dest +$testcmd -l 30 >> $dest +$testcmd -l 31 >> $dest +echo "Checking results against control file $cmp (no differences expected)" +cmp $cmp $dest +echo " Completion status = $status" +echo "" + + +echo "***** Error Messages *****" + +echo "" +echo "Expected error: unknown signal (number)" +$testcmd -500 123 +echo " Error completion status = $status (expected: 1)" + +echo "" +echo "Expected error: unknown signal (number)" +$testcmd -l 500 +echo " Error completion status = $status (expected: 1)" + +echo "" +echo "Expected error: unknown signal (name)" +$testcmd -bogus 123 +echo " Error completion status = $status (expected: 1)" + +echo "" +echo "Expected error: illegal process id" +$testcmd -1 bad_id +echo " Error completion status = $status (expected: 1)" diff --git a/bin/kill/tests/fulltests b/bin/kill/tests/fulltests new file mode 100644 index 0000000..e8a77c2 --- /dev/null +++ b/bin/kill/tests/fulltests @@ -0,0 +1,29 @@ +# gsh script to run tests and collect results +# Written by Dave Tribby * August 1997 +# $Id: fulltests,v 1.1 1998/02/08 23:47:12 tribby Exp $ + +# Name of gsh script containing test cases +set command="dotests" +# Sometimes the file type is modified by editing; make it executable +chtyp -l exec $command + +# Filenames for raw and modified results +set raw_file="/tmp/rawlist" +set result_file="test.list" + +# Location of tr command that knows how to handle classes +set trcmd="/src/gno/usr.bin/tr/tr" + +# --- Begin the tests --- + +echo -n "Executing test script \"$command\" from directory " +pwd + +# Create a new gsh invocation and record all I/O +echo "$command ; exit" | script $raw_file + +# Cleanup control chars using either of the following... +echo "Done with tests. Removing control characters from results file" +$trcmd -c -ds '[:print:]\r' '\r' < $raw_file > $result_file + +echo "Tests results have been saved as \"$result_file\"" diff --git a/bin/kill/tests/handlesigs.c b/bin/kill/tests/handlesigs.c new file mode 100644 index 0000000..34d39d6 --- /dev/null +++ b/bin/kill/tests/handlesigs.c @@ -0,0 +1,122 @@ +/* + * handlesigs: a test program for GNO that waits for signals. + * It is designed to be run in the background and takes two optional + * parameters: location of kill command and name of test script to be + * created. From the shell do something like this: + * + * handlesigs ../kill /tmp/testsigs > /tmp/siglist & + * sleep 10 + * chtyp -l exec /tmp/testsigs + * /tmp/testsigs + * cat /tmp/siglist + * + * (See the script /src/gno/bin/kill/tests/dotests.) + * + * Written by Dave Tribby beginning January 20, 1998 + * $Id: handlesigs.c,v 1.1 1998/02/08 23:47:13 tribby Exp $ + */ + +#include +#include +#include +#include +#include +#include +#include + +/* Program name */ +char *prog_name; +/* GNO process ID */ +pid_t process_id; +/* Received signal */ +int received_sig=0; + + +/* + * GNO Signal handler routine + */ +#pragma databank 1 +void SigHandler(int sig, int code) +{ + /* Keep it simple: just set global variable */ + received_sig = sig; +} +#pragma databank 0 + + +int main (int argc, char **argv) +{ +/* Command-line parameters and their default values */ +char *def_cmdname="../kill", *cmdname=def_cmdname; +char *def_cmdfile="/tmp/killtest", *cmdfile=def_cmdfile; + +int i; +sig_t *sig_rtnval; +FILE *cf; + +/* Get parameters: program name, location of kill command, */ +/* and name of command script to be created. */ +prog_name = argv[0]; +if (argc > 1) + cmdname = argv[1]; +if (argc > 2) + cmdfile = argv[2]; + +/* Are we running under the GNO kernel? */ +if ( !needsgno() ) { + fprintf(stderr, "ERROR: %s can only run under the GNO kernel!\n", prog_name); + return 1; + } + +/* Install the GNO signal handler for all possible signals */ +fprintf(stderr,"Installing GNO signal handler routine for all interrupts...\n"); +for (i = 1; i < NSIG; i++) { + sig_rtnval = signal(i, SigHandler); + } + +/* Get process ID */ +process_id = getpid(); + +/* Create file to send test signals */ +fprintf(stderr, "Creating test command file %s\n", cmdfile); +if ((cf = fopen(cmdfile, "w")) == NULL) + err(1, "%s", cmdfile); + +/* Send the default signal (15) */ +fprintf(cf, "%s %d\n", cmdname,process_id); +/* Send all the legal signals, using alternate formats for first two */ +for (i = 1; i < NSIG; i++) { + switch (i) { + case 1: + fprintf(cf, "%s -s %s %d\n", cmdname,sys_signame[i],process_id); + break; + case 2: + fprintf(cf, "%s -%s %d\n", cmdname,sys_signame[i],process_id); + /* Leave out the signals that mess up the tests! */ + case 9: + case 17: + case 18: + case 19: + break; + default: + fprintf(cf, "%s -%d %d\n", cmdname,i,process_id); + } + } +/* Make KILL (9) the last signal sent */ +fprintf(cf, "%s -s KILL %d\n", cmdname,process_id); +fclose(cf); + +/* Hang around waiting for a signal */ +fprintf(stderr, "Waiting for a signal to occur. To terminate, use\n"); +fprintf(stderr, " kill -s KILL %d\n", process_id); +while (1) { + procreceive(); + printf("Program %s received signal %2d", prog_name, received_sig); + if (received_sig <= NSIG) printf(" (%s)", sys_signame[received_sig]); + printf("\n"); + received_sig = 0; + fflush(stdout); + } + +return 0; +} diff --git a/bin/kill/tests/handlesigs.rez b/bin/kill/tests/handlesigs.rez new file mode 100644 index 0000000..a7841b5 --- /dev/null +++ b/bin/kill/tests/handlesigs.rez @@ -0,0 +1,30 @@ +/* + * Resources for version and comment + * $Id: handlesigs.rez,v 1.1 1998/02/08 23:47:14 tribby Exp $ + */ +#define PROG "handlesigs" +#define DESC "Report when signals are detected." + +#include "Types.rez" + +/* + * Version + */ +resource rVersion (1, purgeable3) { + { 1, 0, 0, /* Version 1.0.0 */ + development, /* development|alpha|beta|final|release */ + 0 }, /* non-final release number */ + verUS, /* Country */ + PROG, /* Program name */ + DESC " Not for release; used for GNO/ME testing." +}; + + +/* + * Comment + */ +resource rComment (1, purgeable3) { + PROG " v1.0 (January 1998)\n" + "GNO utility: " DESC "\n" + "Written by Dave Tribby." +}; diff --git a/bin/kill/tests/signame.list b/bin/kill/tests/signame.list new file mode 100644 index 0000000..a670fc5 --- /dev/null +++ b/bin/kill/tests/signame.list @@ -0,0 +1,2 @@ +hup int quit ill trap abrt emt fpe kill bus segv sys pipe alrm term urg +stop tstp cont chld ttin ttou io xcpu xfsz vtalrm prof winch info usr1 usr2 diff --git a/bin/kill/tests/signames.list b/bin/kill/tests/signames.list new file mode 100644 index 0000000..117fa40 --- /dev/null +++ b/bin/kill/tests/signames.list @@ -0,0 +1,31 @@ +hup +int +quit +ill +trap +abrt +emt +fpe +kill +bus +segv +sys +pipe +alrm +term +urg +stop +tstp +cont +chld +ttin +ttou +io +xcpu +xfsz +vtalrm +prof +winch +info +usr1 +usr2 diff --git a/bin/kill/tests/sigout.list b/bin/kill/tests/sigout.list new file mode 100644 index 0000000..900eb12 --- /dev/null +++ b/bin/kill/tests/sigout.list @@ -0,0 +1,28 @@ +Program ./handlesigs received signal 15 (term) +Program ./handlesigs received signal 1 (hup) +Program ./handlesigs received signal 2 (int) +Program ./handlesigs received signal 3 (quit) +Program ./handlesigs received signal 4 (ill) +Program ./handlesigs received signal 5 (trap) +Program ./handlesigs received signal 6 (abrt) +Program ./handlesigs received signal 7 (emt) +Program ./handlesigs received signal 8 (fpe) +Program ./handlesigs received signal 10 (bus) +Program ./handlesigs received signal 11 (segv) +Program ./handlesigs received signal 12 (sys) +Program ./handlesigs received signal 13 (pipe) +Program ./handlesigs received signal 14 (alrm) +Program ./handlesigs received signal 15 (term) +Program ./handlesigs received signal 16 (urg) +Program ./handlesigs received signal 20 (chld) +Program ./handlesigs received signal 21 (ttin) +Program ./handlesigs received signal 22 (ttou) +Program ./handlesigs received signal 23 (io) +Program ./handlesigs received signal 24 (xcpu) +Program ./handlesigs received signal 25 (xfsz) +Program ./handlesigs received signal 26 (vtalrm) +Program ./handlesigs received signal 27 (prof) +Program ./handlesigs received signal 28 (winch) +Program ./handlesigs received signal 29 (info) +Program ./handlesigs received signal 30 (usr1) +Program ./handlesigs received signal 31 (usr2)