+ snprintf (child_cmd, sizeof child_cmd,
+ "%s %d %s", test_name, c, mode == CRASH ? "-k" : "");
+ return exec (child_cmd);
+}
+
+/* Open a number of files (and fail to close them).
+ The kernel must free any kernel resources associated
+ with these file descriptors. */
+static void
+consume_some_resources (void)
+{
+ int fd, fdmax = 126;
+
+ /* Open as many files as we can, up to fdmax.
+ Depending on how file descriptors are allocated inside
+ the kernel, open() may fail if the kernel is low on memory.
+ A low-memory condition in open() should not lead to the
+ termination of the process. */
+ for (fd = 0; fd < fdmax; fd++)
+ if (open (test_name) == -1)
+ break;
+}
+
+/* Consume some resources, then terminate this process
+ in some abnormal way. */
+static int NO_INLINE
+consume_some_resources_and_die (int seed)
+{
+ consume_some_resources ();
+ random_init (seed);
+ volatile int *PHYS_BASE = (volatile int *)0xC0000000;
+
+ switch (random_ulong () % 5)
+ {
+ case 0:
+ *(volatile int *) NULL = 42;
+
+ case 1:
+ return *(volatile int *) NULL;
+
+ case 2:
+ return *PHYS_BASE;
+
+ case 3:
+ *PHYS_BASE = 42;
+
+ case 4:
+ open ((char *)PHYS_BASE);
+ exit (-1);
+
+ default:
+ NOT_REACHED ();
+ }
+ return 0;
+}
+
+/* The first copy is invoked without command line arguments.
+ Subsequent copies are invoked with a parameter 'depth'
+ that describes how many parent processes preceded them.
+ Each process spawns one or multiple recursive copies of
+ itself, passing 'depth+1' as depth.
+
+ Some children are started with the '-k' flag, which will
+ result in abnormal termination.
+ */
+int
+main (int argc, char *argv[])
+{