]>
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_
13 /* AYJ: the debug stuff here should really be in a stub_debug.cc file for tests to link */
15 /* for correct pre-definitions of debug objects */
18 FILE *debug_log
= NULL
;
21 xassert(const char *msg
, const char *file
, int line
)
23 std::cout
<< "Assertion failed: (" << msg
<< ") at " << file
<< ":" << line
<< std::endl
;
27 int Debug::Levels
[MAX_DEBUG_SECTIONS
];
31 _db_print_stderr(const char *format
, va_list args
);
35 _db_print(const char *format
,...)
40 const char *format
= NULL
;
43 LOCAL_ARRAY(char, f
, BUFSIZ
);
56 va_start(args1
, format
);
58 va_start(args2
, format
);
60 va_start(args3
, format
);
64 format
= va_arg(args1
, const char *);
68 snprintf(f
, BUFSIZ
, "%s| %s",
69 "stub time", //debugLogTime(squid_curtime),
72 _db_print_stderr(f
, args2
);
86 _db_print_stderr(const char *format
, va_list args
) {
88 // if (opt_debug_stderr < Debug::level)
93 vfprintf(stderr
, format
, args
);
97 fatal_dump(const char *message
) {
98 debug (0,0) ("Fatal: %s",message
);
103 fatal(const char *message
) {
104 debug (0,0) ("Fatal: %s",message
);
110 fatalvf(const char *fmt
, va_list args
) {
111 static char fatal_str
[BUFSIZ
];
112 vsnprintf(fatal_str
, sizeof(fatal_str
), fmt
, args
);
116 /* printf-style interface for fatal */
119 fatalf(const char *fmt
,...) {
127 const char *fmt
= NULL
;
129 fmt
= va_arg(args
, char *);
137 debug_trap(const char *message
) {
141 int Debug::TheDepth
= 0;
144 Debug::getDebugOut() {
145 assert(TheDepth
>= 0);
148 assert(CurrentDebug
);
149 *CurrentDebug
<< std::endl
<< "reentrant debuging " << TheDepth
<< "-{";
151 assert(!CurrentDebug
);
152 CurrentDebug
= new std::ostringstream();
153 // set default formatting flags
154 CurrentDebug
->setf(std::ios::fixed
);
155 CurrentDebug
->precision(2);
157 return *CurrentDebug
;
161 Debug::finishDebug() {
162 assert(TheDepth
>= 0);
163 assert(CurrentDebug
);
165 *CurrentDebug
<< "}-" << TheDepth
<< std::endl
;
167 assert(TheDepth
== 1);
168 _db_print("%s\n", CurrentDebug
->str().c_str());
176 Debug::xassert(const char *msg
, const char *file
, int line
) {
179 *CurrentDebug
<< "assertion failed: " << file
<< ":" << line
<<
180 ": \"" << msg
<< "\"";
185 std::ostringstream
*Debug::CurrentDebug (NULL
);
187 MemAllocator
*dlink_node_pool
= NULL
;
191 if (dlink_node_pool
== NULL
)
192 dlink_node_pool
= memPoolCreate("Dlink list nodes", sizeof(dlink_node
));
194 /* where should we call memPoolDestroy(dlink_node_pool); */
195 return static_cast<dlink_node
*>(dlink_node_pool
->alloc());
198 /* the node needs to be unlinked FIRST */
200 dlinkNodeDelete(dlink_node
* m
) {
204 dlink_node_pool
->free(m
);
208 dlinkAdd(void *data
, dlink_node
* m
, dlink_list
* list
) {
211 m
->next
= list
->head
;
214 list
->head
->prev
= m
;
218 if (list
->tail
== NULL
)
223 dlinkAddAfter(void *data
, dlink_node
* m
, dlink_node
* n
, dlink_list
* list
) {
231 assert(list
->tail
== n
);
239 dlinkAddTail(void *data
, dlink_node
* m
, dlink_list
* list
) {
242 m
->prev
= list
->tail
;
245 list
->tail
->next
= m
;
249 if (list
->head
== NULL
)
254 dlinkDelete(dlink_node
* m
, dlink_list
* list
) {
256 m
->next
->prev
= m
->prev
;
259 m
->prev
->next
= m
->next
;
262 list
->head
= m
->next
;
265 list
->tail
= m
->prev
;
267 m
->next
= m
->prev
= NULL
;
271 ctx_enter(const char *descr
) {