aboutsummaryrefslogtreecommitdiff
path: root/test-skeleton.c
diff options
context:
space:
mode:
Diffstat (limited to 'test-skeleton.c')
-rw-r--r--test-skeleton.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/test-skeleton.c b/test-skeleton.c
index 5bb5c44c16..39c6073c73 100644
--- a/test-skeleton.c
+++ b/test-skeleton.c
@@ -18,6 +18,7 @@
Boston, MA 02111-1307, USA. */
#include <getopt.h>
+#include <search.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -52,6 +53,39 @@ static int pid;
/* Directory to place temporary files in. */
static const char *test_dir;
+/* List of temporary files. */
+struct name_list
+{
+ struct qelem q;
+ const char *name;
+} *name_list;
+
+/* Add temporary files in list. */
+void
+add_temp_file (const char *name)
+{
+ struct name_list *newp = (struct name_list *) calloc (sizeof (*newp), 1);
+ if (newp != NULL)
+ {
+ newp->name = name;
+ if (name_list == NULL)
+ name_list = (struct name_list *) &newp->q;
+ else
+ insque (newp, name_list);
+ }
+}
+
+/* Delete all temporary files. */
+void
+delete_temp_files (void)
+{
+ while (name_list != NULL)
+ {
+ remove (name_list->name);
+ name_list = (struct name_list *) name_list->q.q_forw;
+ }
+}
+
/* Timeout handler. We kill the child and exit with an error. */
void
timeout_handler (int sig __attribute__ ((unused)))
@@ -114,11 +148,20 @@ main (int argc, char *argv[])
exit (1);
}
}
+ else
+ {
+ test_dir = getenv ("TMPDIR");
+ if (test_dir == NULL || test_dir[0] == '\0')
+ test_dir = "/tmp";
+ }
/* If we are not expected to fork run the function immediately. */
if (direct)
return TEST_FUNCTION;
+ /* make sure temporary files are deleted. */
+ atexit (delete_temp_files);
+
/* Set up the test environment:
- prevent core dumps
- set up the timer
@@ -166,8 +209,12 @@ main (int argc, char *argv[])
#endif
if (WTERMSIG (status) != EXPECTED_SIGNAL)
{
- fprintf (stderr, "Incorrect signal from child: got `%s', need `%s'\n",
- strsignal (WTERMSIG (status)), strsignal (EXPECTED_SIGNAL));
+ if (EXPECTED_SIGNAL != 0)
+ fprintf (stderr, "Incorrect signal from child: got `%s', need `%s'\n",
+ strsignal (WTERMSIG (status)), strsignal (EXPECTED_SIGNAL));
+ else
+ fprintf (stderr, "Incorrect signal from child: got `%s'\n",
+ strsignal (WTERMSIG (status)));
exit (1);
}