Skip to content

Commit 3d22639

Browse files
committed
update test multithreading
1 parent beaaf03 commit 3d22639

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

projects/rocprofiler-sdk/tests/bin/attachment-test/attachment_test.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@
2727
#include <csignal>
2828
#include <cstdlib>
2929
#include <iostream>
30+
#include <sstream>
3031
#include <string>
3132
#include <thread>
3233
#include <vector>
3334

3435
// Signal handler - handles signal without affecting execution
36+
namespace
37+
{
38+
int signal_received = 0;
3539
void
3640
signal_handler(int signum)
3741
{
38-
std::cout << "Attachment test process " << getpid() << " received signal " << signum << "\n";
42+
signal_received = signum;
3943
}
44+
} // namespace
4045

4146
/* Macro for checking GPU API return values */
4247
#define HIP_ASSERT(call) \
@@ -86,8 +91,13 @@ execute_kernels(const size_t tid, const size_t device_id)
8691
}
8792

8893
// Run kernels in a loop for a while
89-
std::cout << "Starting kernel execution loop for thread " << tid << " on device " << device_id
90-
<< "...\n";
94+
{
95+
// compose string first to avoid multithreaded handling of cout << operator
96+
std::stringstream msg;
97+
msg << "Starting kernel execution loop for thread " << tid << " on device " << device_id
98+
<< "...\n";
99+
std::cout << msg.str();
100+
}
91101
const int num_iterations = 30;
92102

93103
for(int iter = 0; iter < num_iterations; ++iter)
@@ -143,8 +153,13 @@ execute_kernels(const size_t tid, const size_t device_id)
143153
std::this_thread::sleep_for(std::chrono::milliseconds(500));
144154
}
145155

146-
std::cout << "Kernel execution loop completed for thread " << tid << " on device " << device_id
147-
<< "...\n";
156+
{
157+
// compose string first to avoid multithreaded handling of cout << operator
158+
std::stringstream msg;
159+
msg << "Kernel execution loop completed for thread " << tid << " on device " << device_id
160+
<< "...\n";
161+
std::cout << msg.str();
162+
}
148163

149164
HIP_ASSERT(hipStreamDestroy(stream));
150165
// Cleanup
@@ -191,7 +206,7 @@ main(int argc, char** argv)
191206
if(ndevices > device_count)
192207
{
193208
std::cout << "Using " << device_count << " HIP devices instead of the requested "
194-
<< ndevices << "\n";
209+
<< ndevices << std::endl;
195210
ndevices = device_count;
196211
}
197212

@@ -205,6 +220,11 @@ main(int argc, char** argv)
205220
for(auto& itr : _threads)
206221
itr.join();
207222

223+
if(signal_received)
224+
{
225+
std::cout << "Attachment test process " << getpid() << " received signal "
226+
<< signal_received << std::endl;
227+
}
208228
std::cout << "Attachment test app finished" << std::endl;
209229

210230
return 0;

projects/rocprofiler-sdk/tests/rocattach/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ set_tests_properties(
8181
ENVIRONMENT
8282
"${rocattach-test-env}"
8383
PASS_REGULAR_EXPRESSION
84-
"Attachment test process [0-9]+ received signal [0-9]+"
84+
"Attachment test process [0-9]+ received signal 28"
8585
FAIL_REGULAR_EXPRESSION
8686
"${ROCPROFILER_DEFAULT_FAIL_REGEX}"
8787
DISABLED

0 commit comments

Comments
 (0)