Skip to contentSkip to conversation

make check infrastructure for xen/ directory

PATCH In review Tony Breeds 1 participant 1 message Dec 9, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 make check infrastructure for xen/ directory

----- Forwarded message from Rusty Russell <[email protected]> -----

To: Tony Breeds <[email protected]>
From: Rusty Russell <[email protected]>
Subject: [PATCH 2/3] make check infrastructure for xen/ directory
Date: Fri, 09 Dec 2005 16:46:27 +1100

This introduces some fake xen core components and headers, so we can test each C source file in xen/common in isolation. The behaviour of the functions is controlled by the test code, and it also contains extra sanity checks (eg. memory leaks, locks held, irqs disabled).

xen/test/fake-include.h +237 -0
diff -urN --exclude=.hg --exclude='*~' --exclude='*.aux' xen-unstable.hg-mainline/xen/test/fake-include.h xen-unstable.hg-check/xen/test/fake-include.h
@@ -0,0 +1,237 @@
+#ifndef _XEN_TEST_FAKE_INCLUDE
+#define _XEN_TEST_FAKE_INCLUDE
+
+#if (ULONG_MAX >> (CHAR_BIT*4)) == 0
+#define BITS_PER_LONG (CHAR_BIT*4)
+#elif (ULONG_MAX >> (CHAR_BIT*8)) == 0
+#define BITS_PER_LONG (CHAR_BIT*8)
+#else
+#error Cannot determine BITS_PER_LONG
+#endif
+
+#define BITS_TO_LONGS(bits) \
+    (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
+#define DECLARE_BITMAP(name,bits) \
+    unsigned long name[BITS_TO_LONGS(bits)]
+
+/* FIXME: Get rid of EXPORT_SYMBOL */
+#define EXPORT_SYMBOL(sym)
+
+#define __user
+
+#define BUG_ON(x) assert(!(x))
+#define ASSERT(x) assert(x)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+#define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64)
+#define MAX_EVTCHNS        NR_EVENT_CHANNELS
+#define EVTCHNS_PER_BUCKET 128
+#define NR_EVTCHN_BUCKETS  (MAX_EVTCHNS / EVTCHNS_PER_BUCKET)
+
+#include "../include/xen/list.h"
+#include "../include/public/xen.h"
+
+unsigned int hweight32(unsigned int w);
+
+/* Linux-style typedefs */
+typedef int64_t s64;
+typedef uint64_t u64;
+typedef int32_t s32;
+typedef uint32_t u32;
+typedef int16_t s16;
+typedef uint16_t u16;
+typedef int8_t s8;
+typedef uint8_t u8;
+
+typedef int64_t s_time_t;
+
+typedef struct {
+	struct list_head _list;
+	const char *_name;
+	int _l;
+} spinlock_t;
+typedef struct {
+	struct list_head _list;
+	const char *_name;
+	unsigned int _w; unsigned int _r;
+} rwlock_t;
+
+#define __cacheline_aligned
+#define unlikely(x) (x)
+#define xmalloc(type)	((type *)fake_xmalloc(sizeof(type), __FILE__, __LINE__))
+#define xmalloc_array(type, num) ((type *)fake_xmalloc(sizeof(type) * (num), __FILE__, __LINE__))
+void *fake_xmalloc(size_t size, const char *file, int line);
+void fake_xfree(void *p);
+#define xfree(p) fake_xfree(p)
+
+#define for_each_online_cpu(i) for ((i) = 0; (i) < NR_CPUS; (i)++)
+
+extern void printk(const char *format, ...)
+__attribute__ ((format (printf, 1, 2)));
+#define printf printk
+
+/* FIXME: Not used in Xen */
+#define __init
+
+#define NR_CPUS 2
+#define NR_PIRQS 256
+
+s_time_t NOW(void);
+
+void cpu_raise_softirq(unsigned int cpu, unsigned int nr);
+int smp_processor_id(void);
+
+typedef void keyhandler_t(unsigned char key);
+void register_keyhandler(unsigned char key, keyhandler_t *handler,
+			 char *desc);
+
+#define __stringify_1(x)	#x
+#define __stringify(x)		__stringify_1(x)
+
+void spin_lock_init(spinlock_t *lock);
+void _spin_lock_irq(spinlock_t *lock, const char *name);
+void spin_unlock_irq(spinlock_t *lock);
+#define spin_lock_irqsave(lock, flags) \
+	_spin_lock_irqsave((lock), &(flags), __stringify(lock))
+void _spin_lock_irqsave(spinlock_t *lock, unsigned long *flags,
+			const char *name);
+void spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags);
+void _spin_lock(spinlock_t *lock, const char *name);
+void spin_unlock(spinlock_t *lock);
+void _spin_lock_recursive(spinlock_t *lock, const char *name);
+void spin_unlock_recursive(spinlock_t *lock);
+#define spin_lock(lock) _spin_lock(lock, __stringify(lock))
+#define spin_lock_recursive(lock) \
+	_spin_lock_recursive(lock, __stringify(lock))
+#define spin_lock_irq(lock) _spin_lock_irq((lock), __stringify(lock))
+#define SPIN_LOCK_UNLOCKED ((spinlock_t){ ._l = 88 })
+
+void _write_lock(rwlock_t *lock, const char *name);
+void _read_lock(rwlock_t *lock, const char *name);
+#define write_lock(lock) _write_lock((lock), __stringify(lock))
+#define read_lock(lock) _read_lock((lock), __stringify(lock))
+void write_unlock(rwlock_t *lock);
+void read_unlock(rwlock_t *lock);
+
+#define copy_from_user(to, from, n) \
+	fake_copy_from_user((to), (from), (n), __FILE__, __LINE__)
+unsigned long fake_copy_from_user(void *to, const void __user *from,
+				  unsigned n, const char *file, int line);
+#define copy_to_user(to, from, n) \
+	fake_copy_to_user((to), (from), (n), __FILE__, __LINE__)
+unsigned long fake_copy_to_user(void __user *to, const void *from,
+				unsigned n, const char *file, int line);
+
+#define prefetch(x) (0)
+
+#define __initcall(x) 
+
+typedef unsigned long cpumask_t;
+#define CPUMAP_RUNANYWHERE 0xFFFFFFFF
+
+typedef struct { int _val; } atomic_t;
+void atomic_set(atomic_t *a, int i);
+#define _atomic_set(a, i) atomic_set(&(a), (i))
+int atomic_read(atomic_t *a);
+#define _atomic_read(a) atomic_read(&(a))
+void atomic_inc(atomic_t *v);
+int atomic_dec_and_test(atomic_t *a);
+atomic_t atomic_compareandswap(atomic_t old, atomic_t new, atomic_t *v);
+unsigned int __cmpxchg(volatile void *ptr, 
+		       unsigned long old, 
+		       unsigned long new, 
+		       int size);
+
+void set_bit(int bit, void *addr);
+void clear_bit(int bit, void *addr);
+int test_bit(int bit, void *addr);
+int test_and_set_bit(int bit, void *addr);
+int test_and_clear_bit(int bit, void *addr);
+
+struct domain {
+	domid_t          domain_id;
+	spinlock_t       big_lock;
+	shared_info_t   *shared_info;
+	atomic_t         refcnt;
+	void            *ssid;
+	unsigned long    domain_flags;
+	int              shutdown_code;
+	struct list_head page_list;
+	struct list_head xenpage_list;
+	spinlock_t       page_alloc_lock;
+	struct domain   *next_in_list;
+	struct domain   *next_in_hashbucket;
+	struct vcpu     *vcpu[MAX_VIRT_CPUS];
+	cpumask_t        cpumask;
+	unsigned long    vm_assist;
+	struct evtchn   *evtchn[NR_EVTCHN_BUCKETS];
+	spinlock_t       evtchn_lock;
+	u16              pirq_to_evtchn[NR_PIRQS];
+	unsigned int     tot_pages;
+	unsigned int     max_pages;
+	xen_domain_handle_t handle;
+	u32              pirq_mask[NR_PIRQS/32];
+};
+
+struct vcpu {
+	int              vcpu_id;
+	int              processor;
+	struct domain   *domain;
+	struct vcpu     *next_in_list;
+	atomic_t         pausecnt;
+	unsigned long    vcpu_flags;
+	u16              virq_to_evtchn[NR_VIRQS];
+	s_time_t         cpu_time;
+	cpumap_t         cpumap;
+};
+
+struct cpu_info {
+    struct cpu_user_regs guest_cpu_user_regs;
+    unsigned int         processor_id;
+    struct vcpu         *current_ed;
+};
+
+/* evntchn state values */
+#define ECS_FREE         0
+#define ECS_RESERVED     1
+#define ECS_UNBOUND      2
+#define ECS_INTERDOMAIN  3
+#define ECS_PIRQ         4
+#define ECS_VIRQ         5
+#define ECS_IPI          6
+
+struct evtchn
+{
+    u16 state;
+    u16 notify_vcpu_id;
+    union {
+        struct {
+            domid_t remote_domid;
+        } unbound;
+        struct {
+            u16            remote_port;
+            struct domain *remote_dom;
+        } interdomain;
+        u16 pirq;
+        u16 virq;
+    } u;
+};
+
+extern struct vcpu *current;
+void domain_destruct(struct domain *d);
+void put_domain(struct domain *d);
+int get_domain(struct domain *d);
+int IS_PRIV(struct domain *d);
+
+struct domain *find_domain_by_id(domid_t dom);
+
+void put_domain(struct domain *d);
+
+#define IDLE_DOMAIN_ID   (0x7FFFU)
+#define is_idle_task(_d) (test_bit(_DOMF_idle_domain, &(_d)->domain_flags))
+
+#define RW_LOCK_UNLOCKED ((rwlock_t) { ._r = 0, ._w = 0 })
+#define rwlock_init(x)	do { *(x) = RW_LOCK_UNLOCKED; } while(0)
+
+#define always_inline
+#endif /* _XEN_TEST_FAKE_INCLUDE */
xen/test/fake-support.h +81 -0

81 lines not on this page · raw message

xen/test/fake.c +671 -0

671 lines not on this page · 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!