Skip to content

Commit f86c704

Browse files
committed
Add test for perf syscall events
1 parent ba98763 commit f86c704

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

tests/tests_profiler.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,15 @@ DEFINE_TEST(test_perf_bus_cycles) {
251251
// INSTRUMENT_PERF: unknown counter name — must throw a profilerError on first use
252252
DEFINE_TEST(test_perf_unknown_counter) {
253253
INSTRUMENT_FUNCTION();
254-
bool caught = false;
255254
try {
256255
INSTRUMENT_PERF("this-counter-does-not-exist");
257256
#ifdef _WIN32
258257
throw profiler::profilerError("INSTRUMENT_PERF: unsupported counter 'this-counter-does-not-exist'");
259258
#endif
260259
} catch (const profiler::profilerError &) {
261-
caught = true;
260+
return;
262261
}
263-
if (!caught)
264-
throw std::runtime_error("Expected profilerError for unknown perf counter");
262+
throw std::runtime_error("Expected profilerError for unknown perf counter");
265263
}
266264

267265
// INSTRUMENT_PERF: perf counters read from multiple threads concurrently
@@ -286,6 +284,31 @@ DEFINE_TEST(test_perf_multithreaded) {
286284
t.join();
287285
}
288286

287+
// INSTRUMENT_PERF: syscall tracepoint — count write() calls between two sample points
288+
DEFINE_TEST(test_perf_syscall_write) {
289+
INSTRUMENT_FUNCTION();
290+
INSTRUMENT_PERF("syscall:write");
291+
for (int i = 0; i < 5; ++i) {
292+
std::cerr.write("x", 1);
293+
std::cerr.flush();
294+
}
295+
INSTRUMENT_PERF("syscall:write");
296+
}
297+
298+
// INSTRUMENT_PERF: syscall tracepoint — unknown syscall name must throw profilerError
299+
DEFINE_TEST(test_perf_syscall_unknown) {
300+
INSTRUMENT_FUNCTION();
301+
try {
302+
INSTRUMENT_PERF("syscall:this-syscall-does-not-exist");
303+
#ifdef _WIN32
304+
throw profiler::profilerError("INSTRUMENT_PERF: unknown syscall 'syscall:this-syscall-does-not-exist'");
305+
#endif
306+
} catch (const profiler::profilerError &) {
307+
return;
308+
}
309+
throw std::runtime_error("Expected profilerError for unknown syscall tracepoint");
310+
}
311+
289312
// ============================================================
290313
// Entry point
291314
// ============================================================

0 commit comments

Comments
 (0)