Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added support for sampling up to a given number of iterations or until a threshold...
[simgrid.git] / include / xbt / cunit.h
1 /* cunit - A little C Unit facility                                         */
2
3 /* Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 /* This is partially inspirated from the OSSP ts (Test Suite Library)       */
10
11 #ifndef _XBT_CUNIT_H_
12 #define _XBT_CUNIT_H_
13
14 #include "xbt/sysdep.h"         /* XBT_GNU_PRINTF */
15 #include "xbt/ex.h"
16
17 SG_BEGIN_DECL()
18
19 /* test suite object type */
20 typedef struct s_xbt_test_suite *xbt_test_suite_t;
21
22 /* test object type */
23 typedef struct s_xbt_test_unit *xbt_test_unit_t;
24
25 /* test callback function type */
26 typedef void (*ts_test_cb_t) (void);
27
28 /* test suite operations */
29 XBT_PUBLIC(xbt_test_suite_t) xbt_test_suite_new(const char *name,
30                                                 const char *fmt, ...);
31 XBT_PUBLIC(xbt_test_suite_t) xbt_test_suite_by_name(const char *name,
32                                                     const char *fmt, ...);
33 XBT_PUBLIC(void) xbt_test_suite_dump(xbt_test_suite_t suite);
34 XBT_PUBLIC(void) xbt_test_suite_push(xbt_test_suite_t suite,
35                                      const char *name, ts_test_cb_t func,
36                                      const char *fmt, ...);
37
38 /* Run all the specified tests. what_to_do allows to disable some tests.
39  * It is a coma (,) separated list of directives. They are applied from left to right.
40  *
41  * Each of them of form:
42  * 
43  * [-|+]suitename[:unitname[:testname]]
44  * 
45  * * First char: 
46  *   if it's a '-', the directive disables something
47  *   if it's a '+', the directive enables something
48  *   By default, everything is enabled, but you can disable a suite and reenable some parts
49  * * Suitename: the suite on which the directive acts
50  * * unitname: if given, the unit on which the directive acts. If not, acts on any units.
51  * * testname: if given, the test on which the directive acts. If not, acts on any tests.
52  */
53
54 XBT_PUBLIC(int) xbt_test_run(char *selection);
55 /* Show information about the selection of tests */
56 XBT_PUBLIC(void) xbt_test_dump(char *selection);
57 /* Cleanup the mess */
58 XBT_PUBLIC(void) xbt_test_exit(void);
59
60 /* test operations */
61 XBT_PUBLIC(void) _xbt_test_add(const char *file, int line, const char *fmt,
62                                ...) _XBT_GNUC_PRINTF(3, 4);
63 #define xbt_test_add0(fmt)           _xbt_test_add(__FILE__,__LINE__,fmt)
64 #define xbt_test_add1(fmt,a)         _xbt_test_add(__FILE__,__LINE__,fmt,a)
65 #define xbt_test_add2(fmt,a,b)       _xbt_test_add(__FILE__,__LINE__,fmt,a,b)
66 #define xbt_test_add3(fmt,a,b,c)     _xbt_test_add(__FILE__,__LINE__,fmt,a,b,c)
67 #define xbt_test_add4(fmt,a,b,c,d)   _xbt_test_add(__FILE__,__LINE__,fmt,a,b,c,d)
68 #define xbt_test_add5(fmt,a,b,c,d,e) _xbt_test_add(__FILE__,__LINE__,fmt,a,b,c,d,e)
69
70 XBT_PUBLIC(void) _xbt_test_fail(const char *file, int line,
71                                 const char *fmt, ...) _XBT_GNUC_PRINTF(3,
72                                                                        4);
73 #define xbt_test_fail0(fmt)           _xbt_test_fail(__FILE__, __LINE__, fmt)
74 #define xbt_test_fail1(fmt,a)         _xbt_test_fail(__FILE__, __LINE__, fmt,a)
75 #define xbt_test_fail2(fmt,a,b)       _xbt_test_fail(__FILE__, __LINE__, fmt,a,b)
76 #define xbt_test_fail3(fmt,a,b,c)     _xbt_test_fail(__FILE__, __LINE__, fmt,a,b,c)
77 #define xbt_test_fail4(fmt,a,b,c,d)   _xbt_test_fail(__FILE__, __LINE__, fmt,a,b,c,d)
78 #define xbt_test_fail5(fmt,a,b,c,d,e) _xbt_test_fail(__FILE__, __LINE__, fmt,a,b,c,d,e)
79
80 #define xbt_test_assert0(cond,fmt)           if(!(cond)) xbt_test_fail0(fmt)
81 #define xbt_test_assert1(cond,fmt,a)         if(!(cond)) xbt_test_fail1(fmt,a)
82 #define xbt_test_assert2(cond,fmt,a,b)       if(!(cond)) xbt_test_fail2(fmt,a,b)
83 #define xbt_test_assert3(cond,fmt,a,b,c)     if(!(cond)) xbt_test_fail3(fmt,a,b,c)
84 #define xbt_test_assert4(cond,fmt,a,b,c,d)   if(!(cond)) xbt_test_fail4(fmt,a,b,c,d)
85 #define xbt_test_assert5(cond,fmt,a,b,c,d,e) if(!(cond)) xbt_test_fail5(fmt,a,b,c,d,e)
86 #define xbt_test_assert(cond)                xbt_test_assert0(cond,#cond)
87
88 XBT_PUBLIC(void) _xbt_test_log(const char *file, int line, const char *fmt,
89                                ...) _XBT_GNUC_PRINTF(3, 4);
90 #define xbt_test_log0(fmt)           _xbt_test_log(__FILE__, __LINE__, fmt)
91 #define xbt_test_log1(fmt,a)         _xbt_test_log(__FILE__, __LINE__, fmt,a)
92 #define xbt_test_log2(fmt,a,b)       _xbt_test_log(__FILE__, __LINE__, fmt,a,b)
93 #define xbt_test_log3(fmt,a,b,c)     _xbt_test_log(__FILE__, __LINE__, fmt,a,b,c)
94 #define xbt_test_log4(fmt,a,b,c,d)   _xbt_test_log(__FILE__, __LINE__, fmt,a,b,c,d)
95 #define xbt_test_log5(fmt,a,b,c,d,e) _xbt_test_log(__FILE__, __LINE__, fmt,a,b,c,d,e)
96
97 XBT_PUBLIC(void) xbt_test_exception(xbt_ex_t e);
98
99 XBT_PUBLIC(void) xbt_test_expect_failure(void);
100 XBT_PUBLIC(void) xbt_test_skip(void);
101
102 /* test suite short-cut macros */
103 #define XBT_TEST_UNIT(name,func,title)    \
104     void func(void);  /*prototype*/       \
105     void func(void)
106
107 SG_END_DECL()
108 #endif                          /* _TS_H_ */