Some "make check" tests for xen/common
PATCH 3/3 Some "make check" tests for xen/common
----- Forwarded message from Rusty Russell <[email protected]> -----
To: Tony Breeds <[email protected]>
From: Rusty Russell <[email protected]>
Subject: [PATCH 3/3] Some "make check" tests for xen/common
Date: Fri, 09 Dec 2005 16:47:43 +1100
Some of these tests could probably be improved, but this is a first cut. Not all the files are tested yet, just enough to know we're on the right track.
xen/common/test/test_ac_timer.c +241 -0
@@ -0,0 +1,241 @@ +/* Tests for timers. +Copyright (C) 2005 Rusty Russell IBM Corporation + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include <assert.h> +#include <stdint.h> +#include <string.h> +#include <limits.h> +#include <sys/types.h> +#include <errno.h> +#include <stdlib.h> +#include <stdarg.h> +#include <stdio.h> + +#include "fake-support.h" + +#define AC_TIMER_SOFTIRQ 0 +typedef void (*softirq_handler )(void ); +static softirq_handler _test_handler; +static inline void open_softirq (int nr,softirq_handler handler) +{ +test_cond (nr ==AC_TIMER_SOFTIRQ ); + _test_handler = handler; +} + +#include "../../include/xen/ac_timer.h" +#include "../ac_timer.c" + +#define TEST_NUM_TIMERS 10 + +struct test_timer +{ +struct ac_timer timer; +unsigned int timer_count; +unsigned long expiry; +}; +static struct test_timer _test_timers[TEST_NUM_TIMERS ]; + +static void _test_timer (void *data) +{ +struct test_timer *t = data; + + t->timer_count++; + +/* Previous timer should have gone off before us. */ +if (t != _test_timers) +test_cond (t[-1 ].timer_count == t[0 ].timer_count); + +/* Should be about the right time. */ +test_cond (t->expiry <NOW () +TIMER_SLOP ); +} + +static int _test_reprogram =1 ; +static int _test_reprogram_timeout =1 ; +int reprogram_ac_timer (s_time_t timeout) +{ + _test_reprogram_timeout = timeout; +return _test_reprogram; +} + +static s_time_t _test_now =0 ; +s_time_t NOW (void ) +{ +return _test_now; +} + +static int _test_selfadd =1 ; +static void _test_timer_selfadd (void *data) +{ +if (_test_selfadd) +set_ac_timer (data, _test_now +TIMER_SLOP *2 ); +} + +static int _test_smp_processor_id =0 ; +int smp_processor_id (void ) +{ +return _test_smp_processor_id; +} + +void printk (const char *fmt, ...) +{ +va_list arglist; + +va_start (arglist, fmt); +vfprintf (stderr, fmt, arglist); +va_end (arglist); +} + +int main (int argc,char *argv[]) +{ +unsigned int i; +struct ac_timer timer; + +parse_test_args (argc, argv); +register_suppression ("../ac_timer.c" ,128 ); + +/* Initialize first. */ +ac_timer_init (); + +/* Self-adding timer should work. */ + _test_now =0 ; +init_ac_timer (&timer, _test_timer_selfadd, &timer,0 ); + fake_expect_xmalloc =1 ; +set_ac_timer (&timer,1 ); + _test_now =1 ; +_test_handler (); +test_cond (active_ac_timer (&timer)); +/* Timer should still be running. */ +test_cond (_test_reprogram_timeout !=0 ); + _test_selfadd =0 ; + _test_now =LONG_MAX ; +_test_handler (); +test_cond (!active_ac_timer (&timer)); +/* Timer should be stopped. */ +test_cond (_test_reprogram_timeout ==0 ); + +/* Adding timer on other CPU should work. */ + _test_now =0 ; +init_ac_timer (&timer, _test_timer_selfadd, &timer,1 ); + fake_expect_xmalloc =1 ; +set_ac_timer (&timer,1 ); +test_cond (active_ac_timer (&timer)); +/* Wrong CPU, will do nothing. */ +_test_handler (); +test_cond (active_ac_timer (&timer)); + _test_smp_processor_id =1 ; +_test_handler (); +test_cond (!active_ac_timer (&timer)); + _test_smp_processor_id =0 ; + +/* Create them in expiry order, with +/- 1.. */ +for (i =0 ; i <TEST_NUM_TIMERS ; i++) { + _test_timers[i].timer_count =0 ; +init_ac_timer (&_test_timers[i].timer, _test_timer, + &_test_timers[i],0 ); + _test_timers[i].expiry + =LONG_MAX /(TEST_NUM_TIMERS /3 +1 )*((i+3 )/3 ) + i%3 ; + } + +/* Add them all. */ +for (i =0 ; i <TEST_NUM_TIMERS ; i++) +set_ac_timer (&_test_timers[i].timer, _test_timers[i].expiry); +/* They can be re-added (noop) */ +for (i =0 ; i <TEST_NUM_TIMERS ; i++) +set_ac_timer (&_test_timers[i].timer, _test_timers[i].expiry); + +/* Delete in random order then re-add. */ +for (i =0 ; i <TEST_NUM_TIMERS /2 ; i++) +rem_ac_timer (&_test_timers[i*2 ].timer); +for (i =0 ; i <TEST_NUM_TIMERS /2 ; i++) +rem_ac_timer (&_test_timers[i*2 +1 ].timer); +for (i =0 ; i <TEST_NUM_TIMERS ; i++) +test_cond (!active_ac_timer (&_test_timers[i].timer)); + +for (i =0 ; i <TEST_NUM_TIMERS ; i++) +set_ac_timer (&_test_timers[i].timer, _test_timers[i].expiry); + +for (i =0 ; i <TEST_NUM_TIMERS ; i++) +test_cond (active_ac_timer (&_test_timers[i].timer)); + +/* Expire them in order. */ + _test_now =0 ; +for (i =1 ; i <=TEST_NUM_TIMERS /3 ; i++) { + _test_now =LONG_MAX /(TEST_NUM_TIMERS /3 +1 )*i; +_test_handler (); + } + _test_now =LONG_MAX ; +_test_handler (); + +/* They must have all gone off */ +for (i =0 ; i <TEST_NUM_TIMERS ; i++) { +test_cond (!active_ac_timer (&_test_timers[i].timer)); +test_cond (_test_timers[i].timer_count ==1 ); + } + +/* Add them in backwards order. */ +for (i =0 ; i <TEST_NUM_TIMERS ; i++) +set_ac_timer (&_test_timers[TEST_NUM_TIMERS -1 -i].timer, + _test_timers[TEST_NUM_TIMERS -1 -i].expiry); + +for (i =0 ; i <TEST_NUM_TIMERS ; i++) +test_cond (active_ac_timer (&_test_timers[i].timer)); + +/* Expire them in order. */ + _test_now =0 ; +for (i =1 ; i <=TEST_NUM_TIMERS /3 ; i++) { + _test_now =LONG_MAX /(TEST_NUM_TIMERS /3 +1 )*i; +_test_handler (); + } + _test_now =LONG_MAX ; +_test_handler (); + +/* They must have all gone off */ +for (i =0 ; i <TEST_NUM_TIMERS ; i++) { +test_cond (!active_ac_timer (&_test_timers[i].timer)); +test_cond (_test_timers[i].timer_count ==2 ); + } + +/* Add them in "random" order. */ +test_cond (TEST_NUM_TIMERS %2 ==0 ); +for (i =0 ; i <TEST_NUM_TIMERS /2 ; i++) +set_ac_timer (&_test_timers[i*2 ].timer, + _test_timers[i*2 ].expiry); + +for (i =0 ; i <TEST_NUM_TIMERS /2 ; i++) +set_ac_timer (&_test_timers[i*2 +1 ].timer, + _test_timers[i*2 +1 ].expiry); + +for (i =0 ; i <TEST_NUM_TIMERS ; i++) +test_cond (active_ac_timer (&_test_timers[i].timer)); + +/* Expire them in order. */ + _test_now =0 ; +for (i =1 ; i <=TEST_NUM_TIMERS /3 ; i++) { + _test_now =LONG_MAX /(TEST_NUM_TIMERS /3 +1 )*i; +_test_handler (); + } + _test_now =LONG_MAX ; +_test_handler (); + +/* They must have all gone off */ +for (i =0 ; i <TEST_NUM_TIMERS ; i++) { +test_cond (!active_ac_timer (&_test_timers[i].timer)); +test_cond (_test_timers[i].timer_count ==3 ); + } + +return 0 ; +}
xen/common/test/test_acm_ops.c +192 -0
192 lines not on this page · raw message
xen/common/test/test_bitmap.c +344 -0
344 lines not on this page · raw message
xen/common/test/test_dom0_ops.c +644 -0
644 lines not on this page · raw message
xen/common/test/test_domain.c +832 -0
832 lines not on this page · raw message
xen/common/test/test_event_channel.c +768 -0
747 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 8 lines
ccontrol: http://freshmeat.net/projects/ccontrol ----- End forwarded message ----- Yours Tony linux.conf.au http://linux.conf.au/ || http://lca2006.linux.org.au/ Jan 23-28 2006 The Australian Linux Technical Conference!
Part of the diff is not shown here. View the raw message.
Hi Tony,
I've been trying out the make check/fullcheck and I'm very impressed! I hope it gets pulled into the tree soon.
Two suggestions though, for patches this large, it would help to either attach it to the original mail or provide a url to it. inlining is nice for review but a pain to pull out and apply to a tree.
Also, with the latest unstable (8311:53cff3f88e45) the patches fail to build (on xen/common/test/test_event_channel.c) because it cannot find the include file <public/event_channel.h> in the #include "../event_channel.c". I was able to work around this by adding -I../../include to the build rule in the Makefile.
Otherwise, this stuff rocks!
Regards,
Anthony Liguori
Quoted 16 lines · Tony Breeds
Signed-off-by Tony Breeds <[email protected]>----- Forwarded message from Rusty Russell <[email protected]> -----
To: Tony Breeds <[email protected]>
From: Rusty Russell <[email protected]>
Subject: [PATCH 3/3] Some "make check" tests for xen/common
Date: Fri, 09 Dec 2005 16:47:43 +1100Some of these tests could probably be improved, but this is a first cut. Not all the files are tested yet, just enough to know we're on the right track.
Signed-off-by Rusty Russell <[email protected]>
Quoted 1 line · Anthony Liguori
Hi Tony,
Hi Anthony,
Quoted 6 lines
I've been trying out the make check/fullcheck and I'm very impressed! I hope it gets pulled into the tree soon.
Two suggestions though, for patches this large, it would help to either attach it to the original mail or provide a url to it. inlining is nice for review but a pain to pull out and apply to a tree.
Will do for next time.
Quoted 5 lines
Also, with the latest unstable (8311:53cff3f88e45) the patches fail to build (on
xen/common/test/test_event_channel.c) because it cannot find the include file <public/event_channel.h> in the #include "../event_channel.c". I was able to work around this by adding -I../../include to the build rule in theMakefile.
Thanks for the feedback.
There was a typo in patch 1/3. It created public/event_chnnel.h instead of public/event_channel.h.
Sorry.
The patch below can be applied on top of the other 3 to build a working test.
xen/test/Makefile renamed from xen/test/Makefile~ +1 -1
@@ -1,4 +1,4 @@ -LINKS:=asm/types.h asm/uaccess.h asm/system.h asm/desc.h xen/config.h xen/types.h xen/errno.h xen/bitmap.h xen/bitops.h xen/lib.h xen/spinlock.h xen/time.h xen/string.h xen/init.h xen/sched.h xen/smp.h xen/perfc.h xen/softirq.h xen/ac_timer.h xen/keyhandler.h xen/mm.h public/acm.h public/acm_ops.h xen/event.h xen/trace.h xen/console.h asm/shadow.h public/sched_ctl.h acm/acm_hooks.h xen/domain.h xen/domain_page.h asm/debugger.h public/dom0_ops.h public/sched.h public/vcpu.h xen/irq.h asm/current.h public/xen.h public/event_chnnel.h +LINKS:=asm/types.h asm/uaccess.h asm/system.h asm/desc.h xen/config.h xen/types.h xen/errno.h xen/bitmap.h xen/bitops.h xen/lib.h xen/spinlock.h xen/time.h xen/string.h xen/init.h xen/sched.h xen/smp.h xen/perfc.h xen/softirq.h xen/ac_timer.h xen/keyhandler.h xen/mm.h public/acm.h public/acm_ops.h xen/event.h xen/trace.h xen/console.h asm/shadow.h public/sched_ctl.h acm/acm_hooks.h xen/domain.h xen/domain_page.h asm/debugger.h public/dom0_ops.h public/sched.h public/vcpu.h xen/irq.h asm/current.h public/xen.h public/event_channel.h clean:
Yours Tony
linux.conf.au http://linux.conf.au/ || http://lca2006.linux.org.au/
Jan 23-28 2006 The Australian Linux Technical Conference!