- CMDLINE_PROCESS
-#endif
- }
-
- /* Set TMPDIR to specified test directory. */
- if (test_dir != NULL)
- {
- setenv ("TMPDIR", test_dir, 1);
-
- if (chdir (test_dir) < 0)
- {
- perror ("chdir");
- exit (1);
- }
- }
- else
- {
- test_dir = getenv ("TMPDIR");
- if (test_dir == NULL || test_dir[0] == '\0')
- test_dir = "/tmp";
- }
-
- /* Make sure we see all message, even those on stdout. */
- setvbuf (stdout, NULL, _IONBF, 0);
-
- /* make sure temporary files are deleted. */
- atexit (delete_temp_files);
-
- /* Correct for the possible parameters. */
- argv[optind - 1] = argv[0];
- argv += optind - 1;
- argc -= optind - 1;
-
- /* Call the initializing function, if one is available. */
-#ifdef PREPARE
- PREPARE (argc, argv);
-#endif
-
- /* If we are not expected to fork run the function immediately. */
- if (direct)
- return TEST_FUNCTION;
-
- /* Set up the test environment:
- - prevent core dumps
- - set up the timer
- - fork and execute the function. */
-
- pid = fork ();
- if (pid == 0)
- {
- /* This is the child. */
-#ifdef RLIMIT_CORE
- /* Try to avoid dumping core. */
- struct rlimit core_limit;
- core_limit.rlim_cur = 0;
- core_limit.rlim_max = 0;
- setrlimit (RLIMIT_CORE, &core_limit);
-#endif
-
-#ifdef RLIMIT_DATA
- /* Try to avoid eating all memory if a test leaks. */
- struct rlimit data_limit;
- if (getrlimit (RLIMIT_DATA, &data_limit) == 0)
- {
- if (TEST_DATA_LIMIT == RLIM_INFINITY)
- data_limit.rlim_cur = data_limit.rlim_max;
- else if (data_limit.rlim_cur > (rlim_t) TEST_DATA_LIMIT)
- data_limit.rlim_cur = MIN ((rlim_t) TEST_DATA_LIMIT,
- data_limit.rlim_max);
- if (setrlimit (RLIMIT_DATA, &data_limit) < 0)
- perror ("setrlimit: RLIMIT_DATA");
- }
- else
- perror ("getrlimit: RLIMIT_DATA");
-#endif
-
- /* We put the test process in its own pgrp so that if it bogusly
- generates any job control signals, they won't hit the whole build. */
- setpgid (0, 0);
-
- /* Execute the test function and exit with the return value. */
- exit (TEST_FUNCTION);
- }
- else if (pid < 0)
- {
- perror ("Cannot fork test program");
- exit (1);
- }
-
- /* Set timeout. */
-#ifndef TIMEOUT
- /* Default timeout is two seconds. */
-# define TIMEOUT 2
-#endif
- signal (SIGALRM, timeout_handler);
- alarm (TIMEOUT);
-
- /* Wait for the regular termination. */
- termpid = TEMP_FAILURE_RETRY (waitpid (pid, &status, 0));
- if (termpid == -1)
- {
- printf ("Waiting for test program failed: %m\n");
- exit (1);
- }
- if (termpid != pid)