Skip to content

Commit 5952507

Browse files
FedeDPpoiana
authored andcommitted
chore(userspace/libsinsp): properly ASSERT callback parameters.
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
1 parent 74b585a commit 5952507

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

userspace/libsinsp/test/classes/sinsp_observer.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ class test_observer : public sinsp_observer {
3535
const char* data,
3636
uint32_t original_len,
3737
uint32_t len) override {
38-
std::cerr << "[ ] read = " << evt->get_name() << " fd " << fdinfo->m_fd << " data "
39-
<< data << std::endl;
38+
ASSERT_EQ(evt->get_num(), 5);
39+
ASSERT_EQ(fdinfo->m_fd, 4);
40+
ASSERT_STREQ(data, "hello");
4041
m_read_ctr++;
4142
}
4243

@@ -57,27 +58,26 @@ class test_observer : public sinsp_observer {
5758
sinsp_fdinfo* new_fdinfo) override {}
5859

5960
void on_file_open(sinsp_evt* evt, const std::string& fullpath, uint32_t flags) override {
60-
std::cerr << "[ ] open = " << evt->get_name() << " path " << fullpath << std::endl;
61+
ASSERT_EQ(evt->get_num(), 4);
62+
ASSERT_EQ(fullpath, "/home/file.txt");
6163
m_open_ctr++;
6264
}
6365
void on_error(sinsp_evt* evt) override {}
6466
void on_erase_fd(erase_fd_params* params) override {
65-
// Test that sanitizer does not complain about these ones, ie that params pointer is correct
66-
std::cerr << "[ ] closed fd = " << params->m_fd << " at " << params->m_ts
67-
<< " tid " << params->m_tinfo->m_tid << std::endl;
67+
ASSERT_EQ(params->m_fd, 4);
68+
ASSERT_EQ(params->m_tinfo->m_tid, 1);
6869
m_close_ctr++;
6970
}
7071
void on_socket_shutdown(sinsp_evt* evt) override {}
7172
void on_execve(sinsp_evt* evt) override {
72-
// Test that sanitizer does not complain about these ones, ie that evt pointer is correct
73-
std::cerr << "[ ] execve = " << evt->get_name() << std::endl;
73+
ASSERT_EQ(evt->get_num(),
74+
3); // (we create both execve enter and exit; the callback is called on the exit)
7475
m_execve_ctr++;
7576
}
7677

7778
void on_clone(sinsp_evt* evt, sinsp_threadinfo* newtinfo, int64_t tid_collision) override {
78-
// Test that sanitizer does not complain about these ones, ie that evt pointer is correct
79-
std::cerr << "[ ] clone = " << evt->get_name() << " created " << newtinfo->m_tid
80-
<< std::endl;
79+
ASSERT_EQ(evt->get_num(), 1); // first event created
80+
ASSERT_EQ(newtinfo->m_tid, 22);
8181
m_clone_ctr++;
8282
}
8383

@@ -137,7 +137,7 @@ TEST_F(sinsp_with_test_input, sinsp_observer) {
137137
ASSERT_EQ(observer.get_close_ctr(), 0);
138138

139139
std::string data = "hello";
140-
uint32_t size = data.size();
140+
uint32_t size = data.size() + 1; // null terminator
141141
add_event_advance_ts(increasing_ts(),
142142
INIT_TID,
143143
PPME_SYSCALL_READ_X,

0 commit comments

Comments
 (0)