From c9c9e501553961b110b63f73513a758ba9bef921 Mon Sep 17 00:00:00 2001 From: Guru Prasad Srinivasa Date: Thu, 10 Mar 2016 17:28:47 -0500 Subject: [PATCH] Updated forkbomb to better detect success Previously, we were relying on subpage allocator failing to signal that forkbomb was succeeding. However, there are cases where the subpage allocator never fails but the test is still progressing fine. This commit moves the secure print into forkbomb itself and changes the test constraints to ensure that forkbomb runs for a certain amount of time without crashing --- kern/vm/kmalloc.c | 7 +------ test161/commands/asst2.tc | 9 ++++++--- test161/tests/stability/forkbomb.t | 7 +++++++ userland/testbin/forkbomb/forkbomb.c | 12 ++++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/kern/vm/kmalloc.c b/kern/vm/kmalloc.c index b4c4f3a..f38dc37 100644 --- a/kern/vm/kmalloc.c +++ b/kern/vm/kmalloc.c @@ -994,12 +994,7 @@ subpage_kmalloc(size_t sz prpage = alloc_kpages(1); if (prpage==0) { /* Out of memory. */ - kprintf("kmalloc: Subpage allocator couldn't get a page\n"); - static int already_printed = 0; - if(!already_printed) { - already_printed = 1; - secprintf(SECRET, "out of memory", "kmalloc"); - } + silent("kmalloc: Subpage allocator couldn't get a page\n"); return NULL; } KASSERT(prpage % PAGE_SIZE == 0); diff --git a/test161/commands/asst2.tc b/test161/commands/asst2.tc index f1647cb..475fd28 100644 --- a/test161/commands/asst2.tc +++ b/test161/commands/asst2.tc @@ -22,9 +22,12 @@ templates: timesout: yes timeout: 15.0 output: - - text: "kmalloc" - external: true - trusted: true + - text: "/testbin/forkbomb: SUCCESS" + - text: "/testbin/forkbomb: SUCCESS" + - text: "/testbin/forkbomb: SUCCESS" + - text: "/testbin/forkbomb: SUCCESS" + - text: "/testbin/forkbomb: SUCCESS" + - name: kmalloc output: - text: "kmalloc: out of memory" diff --git a/test161/tests/stability/forkbomb.t b/test161/tests/stability/forkbomb.t index 63ec9ce..f20814c 100644 --- a/test161/tests/stability/forkbomb.t +++ b/test161/tests/stability/forkbomb.t @@ -6,5 +6,12 @@ sys161: ram: 2M monitor: progresstimeout: 40.0 + user: + enablemin: true + min: 0.001 + max: 1.0 + kernel: + enablemin: true + min: 0.2 --- p /testbin/forkbomb diff --git a/userland/testbin/forkbomb/forkbomb.c b/userland/testbin/forkbomb/forkbomb.c index 6db265b..f1c919c 100644 --- a/userland/testbin/forkbomb/forkbomb.c +++ b/userland/testbin/forkbomb/forkbomb.c @@ -49,6 +49,10 @@ #include #include +#include +#include + +#define TEST_DURATION 10 static volatile int pid; @@ -57,9 +61,17 @@ main(void) { int i; + time_t start_time_s, time_now_s; + unsigned long start_time_ns, time_now_ns; + __time(&start_time_s, &start_time_ns); while (1) { fork(); + __time(&time_now_s, &time_now_ns); + if(time_now_s - start_time_s > TEST_DURATION) { + success(TEST161_SUCCESS, SECRET, "/testbin/forkbomb"); + } + pid = getpid(); /* Make sure each fork has its own address space. */