2 #include <ThreadedTestCase.h>
12 BThreadedTestCase::BThreadedTestCase(string name
, string progressSeparator
)
15 , fProgressSeparator(progressSeparator
)
16 , fUpdateLock(new BLocker())
22 BThreadedTestCase::~BThreadedTestCase() {
27 for (map
<thread_id
, ThreadSubTestInfo
*>::iterator i
= fNumberMap
.begin();
28 i
!= fNumberMap
.end(); i
++)
37 BThreadedTestCase::NextSubTest() {
38 // Find out what thread we're in
39 thread_id id
= find_thread(NULL
);
42 // Acquire the update lock
43 BAutolock
lock(fUpdateLock
);
44 map
<thread_id
, ThreadSubTestInfo
*>::iterator i
= fNumberMap
.find(id
);
45 if (i
!= fNumberMap
.end() && i
->second
) {
46 // Handle multi-threaded case
47 ThreadSubTestInfo
*info
= i
->second
;
49 sprintf(num
, "%" B_PRId32
"", info
->subTestNum
++);
50 string str
= string("[") + info
->name
+ fProgressSeparator
+ num
52 fUpdateList
.push_back(str
);
57 // Handle single-threaded case
58 BTestCase::NextSubTest();
64 BThreadedTestCase::Outputf(const char *str
, ...) {
65 if (BTestShell::GlobalBeVerbose()) {
66 // Figure out if this is a multithreaded test or not
67 thread_id id
= find_thread(NULL
);
68 bool isSingleThreaded
;
70 BAutolock
lock(fUpdateLock
);
71 isSingleThreaded
= fNumberMap
.find(id
) == fNumberMap
.end();
73 if (isSingleThreaded
) {
83 // FIXME Need a longer string? Change the constant or change the
85 vsprintf(msg
, str
, args
);
88 // Acquire the update lock and post our update
89 BAutolock
lock(fUpdateLock
);
90 fUpdateList
.push_back(string(msg
));
99 BThreadedTestCase::InitThreadInfo(thread_id id
, string threadName
) {
100 BAutolock
lock(fUpdateLock
); // Lock the number map
101 map
<thread_id
, ThreadSubTestInfo
*>::iterator i
= fNumberMap
.find(id
);
102 if (i
!= fNumberMap
.end() && i
->second
) {
103 i
->second
->name
= threadName
;
104 i
->second
->subTestNum
= 0;
107 ThreadSubTestInfo
*info
= new ThreadSubTestInfo();
108 info
->name
= threadName
;
109 info
->subTestNum
= 0;
110 fNumberMap
[id
] = info
;
117 BThreadedTestCase::RegisterForUse() {
128 BThreadedTestCase::UnregisterForUse() {
135 BThreadedTestCase::AcquireUpdateList() {
143 BThreadedTestCase::ReleaseUpdateList() {
144 fUpdateLock
->Unlock();