]>
git.ipfire.org Git - thirdparty/squid.git/blob - test-suite/test_tools.cc
2 * $Id: test_tools.cc,v 1.11 2008/02/26 18:52:54 rousskov Exp $
5 // XXX: This file is made of large pieces of src/debug.cc and src/tools.cc
6 // with only a few minor modifications. TODO: redesign or delete.
8 #define _SQUID_EXTERNNEW_
14 xassert(const char *msg
, const char *file
, int line
)
16 std::cout
<< "Assertion failed: (" << msg
<< ") at " << file
<< ":" << line
<< std::endl
;
20 int Debug::Levels
[MAX_DEBUG_SECTIONS
];
24 _db_print_stderr(const char *format
, va_list args
);
28 _db_print(const char *format
,...)
33 const char *format
= NULL
;
36 LOCAL_ARRAY(char, f
, BUFSIZ
);
49 va_start(args1
, format
);
51 va_start(args2
, format
);
53 va_start(args3
, format
);
57 format
= va_arg(args1
, const char *);
61 snprintf(f
, BUFSIZ
, "%s| %s",
62 "stub time", //debugLogTime(squid_curtime),
65 _db_print_stderr(f
, args2
);
79 _db_print_stderr(const char *format
, va_list args
) {
81 // if (opt_debug_stderr < Debug::level)
86 vfprintf(stderr
, format
, args
);
90 fatal_dump(const char *message
) {
91 debug (0,0) ("Fatal: %s",message
);
96 fatal(const char *message
) {
97 debug (0,0) ("Fatal: %s",message
);
103 fatalvf(const char *fmt
, va_list args
) {
104 static char fatal_str
[BUFSIZ
];
105 vsnprintf(fatal_str
, sizeof(fatal_str
), fmt
, args
);
109 /* printf-style interface for fatal */
112 fatalf(const char *fmt
,...) {
120 const char *fmt
= NULL
;
122 fmt
= va_arg(args
, char *);
130 debug_trap(const char *message
) {
134 int Debug::TheDepth
= 0;
137 Debug::getDebugOut() {
138 assert(TheDepth
>= 0);
141 assert(CurrentDebug
);
142 *CurrentDebug
<< std::endl
<< "reentrant debuging " << TheDepth
<< "-{";
144 assert(!CurrentDebug
);
145 CurrentDebug
= new std::ostringstream();
146 // set default formatting flags
147 CurrentDebug
->setf(std::ios::fixed
);
148 CurrentDebug
->precision(2);
150 return *CurrentDebug
;
154 Debug::finishDebug() {
155 assert(TheDepth
>= 0);
156 assert(CurrentDebug
);
158 *CurrentDebug
<< "}-" << TheDepth
<< std::endl
;
160 assert(TheDepth
== 1);
161 _db_print("%s\n", CurrentDebug
->str().c_str());
169 Debug::xassert(const char *msg
, const char *file
, int line
) {
172 *CurrentDebug
<< "assertion failed: " << file
<< ":" << line
<<
173 ": \"" << msg
<< "\"";
178 std::ostringstream
*Debug::CurrentDebug (NULL
);
180 MemAllocator
*dlink_node_pool
= NULL
;
184 if (dlink_node_pool
== NULL
)
185 dlink_node_pool
= memPoolCreate("Dlink list nodes", sizeof(dlink_node
));
187 /* where should we call memPoolDestroy(dlink_node_pool); */
188 return static_cast<dlink_node
*>(dlink_node_pool
->alloc());
191 /* the node needs to be unlinked FIRST */
193 dlinkNodeDelete(dlink_node
* m
) {
197 dlink_node_pool
->free(m
);
201 dlinkAdd(void *data
, dlink_node
* m
, dlink_list
* list
) {
204 m
->next
= list
->head
;
207 list
->head
->prev
= m
;
211 if (list
->tail
== NULL
)
216 dlinkAddAfter(void *data
, dlink_node
* m
, dlink_node
* n
, dlink_list
* list
) {
224 assert(list
->tail
== n
);
232 dlinkAddTail(void *data
, dlink_node
* m
, dlink_list
* list
) {
235 m
->prev
= list
->tail
;
238 list
->tail
->next
= m
;
242 if (list
->head
== NULL
)
247 dlinkDelete(dlink_node
* m
, dlink_list
* list
) {
249 m
->next
->prev
= m
->prev
;
252 m
->prev
->next
= m
->next
;
255 list
->head
= m
->next
;
258 list
->tail
= m
->prev
;
260 m
->next
= m
->prev
= NULL
;
264 ctx_enter(const char *descr
) {