]>
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.
10 /* AYJ: the debug stuff here should really be in a stub_debug.cc file for tests to link */
12 /* for correct pre-definitions of debug objects */
13 /* and stream headers */
16 FILE *debug_log
= NULL
;
19 xassert(const char *msg
, const char *file
, int line
)
21 std::cout
<< "Assertion failed: (" << msg
<< ") at " << file
<< ":" << line
<< std::endl
;
25 int Debug::Levels
[MAX_DEBUG_SECTIONS
];
29 _db_print_stderr(const char *format
, va_list args
);
32 _db_print(const char *format
,...)
34 LOCAL_ARRAY(char, f
, BUFSIZ
);
39 va_start(args1
, format
);
40 va_start(args2
, format
);
41 va_start(args3
, format
);
43 snprintf(f
, BUFSIZ
, "%s| %s",
44 "stub time", //debugLogTime(squid_curtime),
47 _db_print_stderr(f
, args2
);
55 _db_print_stderr(const char *format
, va_list args
)
58 // if (opt_debug_stderr < Debug::level)
63 vfprintf(stderr
, format
, args
);
67 fatal_dump(const char *message
)
69 fprintf(stderr
, "Fatal: %s",message
);
74 fatal(const char *message
)
76 fprintf(stderr
, "Fatal: %s", message
);
82 fatalvf(const char *fmt
, va_list args
)
84 static char fatal_str
[BUFSIZ
];
85 vsnprintf(fatal_str
, sizeof(fatal_str
), fmt
, args
);
89 /* printf-style interface for fatal */
91 fatalf(const char *fmt
,...)
100 debug_trap(const char *message
)
105 int Debug::TheDepth
= 0;
110 assert(TheDepth
>= 0);
113 assert(CurrentDebug
);
114 *CurrentDebug
<< std::endl
<< "reentrant debuging " << TheDepth
<< "-{";
116 assert(!CurrentDebug
);
117 CurrentDebug
= new std::ostringstream();
118 // set default formatting flags
119 CurrentDebug
->setf(std::ios::fixed
);
120 CurrentDebug
->precision(2);
122 return *CurrentDebug
;
128 assert(TheDepth
>= 0);
129 assert(CurrentDebug
);
131 *CurrentDebug
<< "}-" << TheDepth
<< std::endl
;
133 assert(TheDepth
== 1);
134 _db_print("%s\n", CurrentDebug
->str().c_str());
142 Debug::xassert(const char *msg
, const char *file
, int line
)
146 *CurrentDebug
<< "assertion failed: " << file
<< ":" << line
<<
147 ": \"" << msg
<< "\"";
152 std::ostringstream
*Debug::CurrentDebug(NULL
);
154 MemAllocator
*dlink_node_pool
= NULL
;
159 if (dlink_node_pool
== NULL
)
160 dlink_node_pool
= memPoolCreate("Dlink list nodes", sizeof(dlink_node
));
162 /* where should we call memPoolDestroy(dlink_node_pool); */
163 return static_cast<dlink_node
*>(dlink_node_pool
->alloc());
166 /* the node needs to be unlinked FIRST */
168 dlinkNodeDelete(dlink_node
* m
)
173 dlink_node_pool
->freeOne(m
);
177 dlinkAdd(void *data
, dlink_node
* m
, dlink_list
* list
)
181 m
->next
= list
->head
;
184 list
->head
->prev
= m
;
188 if (list
->tail
== NULL
)
193 dlinkAddAfter(void *data
, dlink_node
* m
, dlink_node
* n
, dlink_list
* list
)
202 assert(list
->tail
== n
);
210 dlinkAddTail(void *data
, dlink_node
* m
, dlink_list
* list
)
214 m
->prev
= list
->tail
;
217 list
->tail
->next
= m
;
221 if (list
->head
== NULL
)
226 dlinkDelete(dlink_node
* m
, dlink_list
* list
)
229 m
->next
->prev
= m
->prev
;
232 m
->prev
->next
= m
->next
;
235 list
->head
= m
->next
;
238 list
->tail
= m
->prev
;
240 m
->next
= m
->prev
= NULL
;
244 ctx_enter(const char *descr
)
253 const char* SkipBuildPrefix(const char* path
)