]>
git.ipfire.org Git - thirdparty/squid.git/blob - test-suite/test_tools.cc
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_
11 /* AYJ: the debug stuff here should really be in a stub_debug.cc file for tests to link */
13 /* for correct pre-definitions of debug objects */
14 /* and stream headers */
17 FILE *debug_log
= NULL
;
20 xassert(const char *msg
, const char *file
, int line
)
22 std::cout
<< "Assertion failed: (" << msg
<< ") at " << file
<< ":" << line
<< std::endl
;
26 int Debug::Levels
[MAX_DEBUG_SECTIONS
];
30 _db_print_stderr(const char *format
, va_list args
);
33 _db_print(const char *format
,...)
35 LOCAL_ARRAY(char, f
, BUFSIZ
);
40 va_start(args1
, format
);
41 va_start(args2
, format
);
42 va_start(args3
, format
);
44 snprintf(f
, BUFSIZ
, "%s| %s",
45 "stub time", //debugLogTime(squid_curtime),
48 _db_print_stderr(f
, args2
);
56 _db_print_stderr(const char *format
, va_list args
)
59 // if (opt_debug_stderr < Debug::level)
64 vfprintf(stderr
, format
, args
);
68 fatal_dump(const char *message
)
70 debug (0,0) ("Fatal: %s",message
);
75 fatal(const char *message
)
77 debug (0,0) ("Fatal: %s",message
);
83 fatalvf(const char *fmt
, va_list args
)
85 static char fatal_str
[BUFSIZ
];
86 vsnprintf(fatal_str
, sizeof(fatal_str
), fmt
, args
);
90 /* printf-style interface for fatal */
92 fatalf(const char *fmt
,...)
101 debug_trap(const char *message
)
106 int Debug::TheDepth
= 0;
111 assert(TheDepth
>= 0);
114 assert(CurrentDebug
);
115 *CurrentDebug
<< std::endl
<< "reentrant debuging " << TheDepth
<< "-{";
117 assert(!CurrentDebug
);
118 CurrentDebug
= new std::ostringstream();
119 // set default formatting flags
120 CurrentDebug
->setf(std::ios::fixed
);
121 CurrentDebug
->precision(2);
123 return *CurrentDebug
;
129 assert(TheDepth
>= 0);
130 assert(CurrentDebug
);
132 *CurrentDebug
<< "}-" << TheDepth
<< std::endl
;
134 assert(TheDepth
== 1);
135 _db_print("%s\n", CurrentDebug
->str().c_str());
143 Debug::xassert(const char *msg
, const char *file
, int line
)
147 *CurrentDebug
<< "assertion failed: " << file
<< ":" << line
<<
148 ": \"" << msg
<< "\"";
153 std::ostringstream
*Debug::CurrentDebug (NULL
);
155 MemAllocator
*dlink_node_pool
= NULL
;
160 if (dlink_node_pool
== NULL
)
161 dlink_node_pool
= memPoolCreate("Dlink list nodes", sizeof(dlink_node
));
163 /* where should we call memPoolDestroy(dlink_node_pool); */
164 return static_cast<dlink_node
*>(dlink_node_pool
->alloc());
167 /* the node needs to be unlinked FIRST */
169 dlinkNodeDelete(dlink_node
* m
)
174 dlink_node_pool
->free(m
);
178 dlinkAdd(void *data
, dlink_node
* m
, dlink_list
* list
)
182 m
->next
= list
->head
;
185 list
->head
->prev
= m
;
189 if (list
->tail
== NULL
)
194 dlinkAddAfter(void *data
, dlink_node
* m
, dlink_node
* n
, dlink_list
* list
)
203 assert(list
->tail
== n
);
211 dlinkAddTail(void *data
, dlink_node
* m
, dlink_list
* list
)
215 m
->prev
= list
->tail
;
218 list
->tail
->next
= m
;
222 if (list
->head
== NULL
)
227 dlinkDelete(dlink_node
* m
, dlink_list
* list
)
230 m
->next
->prev
= m
->prev
;
233 m
->prev
->next
= m
->next
;
236 list
->head
= m
->next
;
239 list
->tail
= m
->prev
;
241 m
->next
= m
->prev
= NULL
;
245 ctx_enter(const char *descr
)
254 const char* SkipBuildPrefix(const char* path
)