From 1f03e79a893e48ab0d95b1d55c4b74e6647e67dd Mon Sep 17 00:00:00 2001 From: nvt-se Date: Fri, 12 Dec 2008 10:28:11 +0000 Subject: [PATCH] added a simple garbage collection test. --- examples/sky/test-coffee.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/examples/sky/test-coffee.c b/examples/sky/test-coffee.c index 207bd7a36..03d5756c0 100755 --- a/examples/sky/test-coffee.c +++ b/examples/sky/test-coffee.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * $Id: test-coffee.c,v 1.4 2008/11/24 10:59:40 nvt-se Exp $ + * $Id: test-coffee.c,v 1.5 2008/12/12 10:28:11 nvt-se Exp $ */ /** @@ -54,7 +54,33 @@ AUTOSTART_PROCESSES(&testcoffee_process); /*---------------------------------------------------------------------------*/ static int -run_consistency_test(void) +coffee_gc_test(void) +{ + int i; + + cfs_remove("alpha"); + cfs_remove("beta"); + + + for (i = 0; i < 100; i++) { + if (i & 1) { + if(cfs_coffee_reserve("alpha", random_rand() & 0xffff) < 0) { + return -i; + } + cfs_remove("beta"); + } else { + if(cfs_coffee_reserve("beta", 93171) < 0) { + return -1; + } + cfs_remove("alpha"); + } + } + + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +coffee_file_test(void) { int error; int wfd, rfd, afd; @@ -280,7 +306,8 @@ PROCESS_THREAD(testcoffee_process, ev, data) { PROCESS_BEGIN(); - printf("Coffee consistency test: %d\n", run_consistency_test()); + printf("Coffee consistency test: %d\n", coffee_file_test()); + printf("Coffee garbage collection test: %d\n", coffee_gc_test()); PROCESS_END(); }