From ccf52d99d27e8dd88e594809d3ab7aab1efc8b8b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 10 Nov 2006 15:06:15 +0000 Subject: [PATCH] Minor style updates. --- src/tests/userprog/no-vm/multi-oom.c | 105 +++++++++++++-------------- 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/src/tests/userprog/no-vm/multi-oom.c b/src/tests/userprog/no-vm/multi-oom.c index 75cad14..6a4472d 100644 --- a/src/tests/userprog/no-vm/multi-oom.c +++ b/src/tests/userprog/no-vm/multi-oom.c @@ -1,19 +1,18 @@ -/* - * Recursively executes itself until the child fails to execute. - * We expect that at least 30 copies can run. - * - * We count how many children your kernel was able to execute - * before it fails to start a new process. We require that, - * if a process doesn't actually get to start, exec() must - * return -1, not a valid PID. - * - * We repeat this process 10 times, checking that your kernel - * allows for the same level of depth every time. - * - * In addition, some processes will spawn children that terminate - * abnormally after allocating some resources. - * - * Written by Godmar Back +/* Recursively executes itself until the child fails to execute. + We expect that at least 30 copies can run. + + We count how many children your kernel was able to execute + before it fails to start a new process. We require that, + if a process doesn't actually get to start, exec() must + return -1, not a valid PID. + + We repeat this process 10 times, checking that your kernel + allows for the same level of depth every time. + + In addition, some processes will spawn children that terminate + abnormally after allocating some resources. + + Written by Godmar Back */ #include @@ -33,50 +32,50 @@ const char *test_name = "multi-oom"; enum child_termination_mode { RECURSE, CRASH }; /* Spawn a recursive copy of ourselves, passing along instructions - * for the child. */ + for the child. */ static pid_t spawn_child (int c, enum child_termination_mode mode) { char child_cmd[128]; - snprintf (child_cmd, sizeof child_cmd, + 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. */ +/* 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. */ + /* 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. */ + in some abnormal way. */ static int NO_INLINE consume_some_resources_and_die (int seed) { consume_some_resources (); random_init (seed); - int * PHYS_BASE = (int *)0xC0000000; + int *PHYS_BASE = (int *)0xC0000000; switch (random_ulong () % 5) { case 0: - * (int *) NULL = 42; + *(int *) NULL = 42; case 1: - return * (int *) NULL; + return *(int *) NULL; case 2: return *PHYS_BASE; @@ -95,16 +94,16 @@ consume_some_resources_and_die (int seed) } /* 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. - */ + 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[]) +main (int argc, char *argv[]) { int n; @@ -113,8 +112,8 @@ main (int argc, char *argv[]) if (is_at_root) msg ("begin"); - /* if -k is passed, crash this process. */ - if (argc > 2 && !strcmp(argv[2], "-k")) + /* If -k is passed, crash this process. */ + if (argc > 2 && !strcmp(argv[2], "-k")) { consume_some_resources_and_die (n); NOT_REACHED (); @@ -128,26 +127,26 @@ main (int argc, char *argv[]) pid_t child_pid; /* Spawn a child that will be abnormally terminated. - * To speed the test up, do this only for processes - * spawned at a certain depth. */ + To speed the test up, do this only for processes + spawned at a certain depth. */ if (n > EXPECTED_DEPTH_TO_PASS/2) { child_pid = spawn_child (n + 1, CRASH); - if (child_pid != -1) + if (child_pid != -1) { if (wait (child_pid) != -1) fail ("crashed child should return -1."); } - /* if spawning this child failed, so should - * the next spawn_child below. */ + /* If spawning this child failed, so should + the next spawn_child below. */ } /* Now spawn the child that will recurse. */ child_pid = spawn_child (n + 1, RECURSE); /* If maximum depth is reached, return result. */ - if (child_pid == -1) - return n; + if (child_pid == -1) + return n; /* Else wait for child to report how deeply it was able to recurse. */ int reached_depth = wait (child_pid); @@ -155,15 +154,13 @@ main (int argc, char *argv[]) fail ("wait returned -1."); /* Record the depth reached during the first run; on subsequent - * runs, fail if those runs do not match the depth achieved on the - * first run. */ + runs, fail if those runs do not match the depth achieved on the + first run. */ if (i == 0) expected_depth = reached_depth; else if (expected_depth != reached_depth) - { - fail ("after run %d/%d, expected depth %d, actual depth %d.", - i, howmany, expected_depth, reached_depth); - } + fail ("after run %d/%d, expected depth %d, actual depth %d.", + i, howmany, expected_depth, reached_depth); ASSERT (expected_depth == reached_depth); } -- 2.30.2