]>
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_
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
);
34 _db_print(const char *format
,...)
36 LOCAL_ARRAY(char, f
, BUFSIZ
);
41 va_start(args1
, format
);
42 va_start(args2
, format
);
43 va_start(args3
, format
);
45 snprintf(f
, BUFSIZ
, "%s| %s",
46 "stub time", //debugLogTime(squid_curtime),
49 _db_print_stderr(f
, args2
);
57 _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
) {
69 debug (0,0) ("Fatal: %s",message
);
74 fatal(const char *message
) {
75 debug (0,0) ("Fatal: %s",message
);
81 fatalvf(const char *fmt
, va_list args
) {
82 static char fatal_str
[BUFSIZ
];
83 vsnprintf(fatal_str
, sizeof(fatal_str
), fmt
, args
);
87 /* printf-style interface for fatal */
89 fatalf(const char *fmt
,...) {
97 debug_trap(const char *message
) {
101 int Debug::TheDepth
= 0;
104 Debug::getDebugOut() {
105 assert(TheDepth
>= 0);
108 assert(CurrentDebug
);
109 *CurrentDebug
<< std::endl
<< "reentrant debuging " << TheDepth
<< "-{";
111 assert(!CurrentDebug
);
112 CurrentDebug
= new std::ostringstream();
113 // set default formatting flags
114 CurrentDebug
->setf(std::ios::fixed
);
115 CurrentDebug
->precision(2);
117 return *CurrentDebug
;
121 Debug::finishDebug() {
122 assert(TheDepth
>= 0);
123 assert(CurrentDebug
);
125 *CurrentDebug
<< "}-" << TheDepth
<< std::endl
;
127 assert(TheDepth
== 1);
128 _db_print("%s\n", CurrentDebug
->str().c_str());
136 Debug::xassert(const char *msg
, const char *file
, int line
) {
139 *CurrentDebug
<< "assertion failed: " << file
<< ":" << line
<<
140 ": \"" << msg
<< "\"";
145 std::ostringstream
*Debug::CurrentDebug (NULL
);
147 MemAllocator
*dlink_node_pool
= NULL
;
151 if (dlink_node_pool
== NULL
)
152 dlink_node_pool
= memPoolCreate("Dlink list nodes", sizeof(dlink_node
));
154 /* where should we call memPoolDestroy(dlink_node_pool); */
155 return static_cast<dlink_node
*>(dlink_node_pool
->alloc());
158 /* the node needs to be unlinked FIRST */
160 dlinkNodeDelete(dlink_node
* m
) {
164 dlink_node_pool
->free(m
);
168 dlinkAdd(void *data
, dlink_node
* m
, dlink_list
* list
) {
171 m
->next
= list
->head
;
174 list
->head
->prev
= m
;
178 if (list
->tail
== NULL
)
183 dlinkAddAfter(void *data
, dlink_node
* m
, dlink_node
* n
, dlink_list
* list
) {
191 assert(list
->tail
== n
);
199 dlinkAddTail(void *data
, dlink_node
* m
, dlink_list
* list
) {
202 m
->prev
= list
->tail
;
205 list
->tail
->next
= m
;
209 if (list
->head
== NULL
)
214 dlinkDelete(dlink_node
* m
, dlink_list
* list
) {
216 m
->next
->prev
= m
->prev
;
219 m
->prev
->next
= m
->next
;
222 list
->head
= m
->next
;
225 list
->tail
= m
->prev
;
227 m
->next
= m
->prev
= NULL
;
231 ctx_enter(const char *descr
) {