Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(tests): add tests for event result #1913

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions userspace/libsinsp/test/events_evt.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
#include <gtest/gtest.h>

#include <sinsp_with_test_input.h>
#include <sinsp_errno.h>
#include "test_utils.h"

TEST_F(sinsp_with_test_input, event_category)
Expand Down Expand Up @@ -57,6 +58,47 @@ TEST_F(sinsp_with_test_input, event_category)
ASSERT_EQ(get_field_as_string(evt, "evt.num"), "4");
}

TEST_F(sinsp_with_test_input, event_res)
{
add_default_init_thread();

open_inspector();

sinsp_evt * evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_EPOLL_CREATE_E, 1, (uint32_t)-1);
EXPECT_FALSE(field_has_value(evt, "evt.res"));

evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_EPOLL_CREATE_X, 1, (int64_t)-SE_EINVAL);

EXPECT_EQ(get_field_as_string(evt, "evt.res"), "EINVAL");
EXPECT_EQ(get_field_as_string(evt, "evt.rawres"), "-22");
EXPECT_TRUE(eval_filter(evt, "evt.rawres < 0"));
EXPECT_EQ(get_field_as_string(evt, "evt.failed"), "true");
EXPECT_EQ(get_field_as_string(evt, "evt.count.error"), "1");

evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_EPOLL_CREATE_E, 1, (uint32_t) 100);
evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_EPOLL_CREATE_X, 1, (uint64_t) 0);

EXPECT_EQ(get_field_as_string(evt, "evt.res"), "SUCCESS");
EXPECT_EQ(get_field_as_string(evt, "evt.rawres"), "0");
EXPECT_EQ(get_field_as_string(evt, "evt.failed"), "false");

evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_OPEN_E, 3, "/tmp/the_file.txt", 0, 0);
evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_OPEN_X, 6, (int64_t)123, "/tmp/the_file.txt", 0, 0, 0, (uint64_t) 0);

EXPECT_EQ(get_field_as_string(evt, "evt.res"), "SUCCESS");
EXPECT_EQ(get_field_as_string(evt, "evt.rawres"), "123");
EXPECT_EQ(get_field_as_string(evt, "evt.failed"), "false");

evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_OPEN_E, 3, "/tmp/the_file.txt", 0, 0);
evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_OPEN_X, 6, (int64_t)-SE_EACCES, "/tmp/the_file.txt", 0, 0, 0, (uint64_t) 0);

EXPECT_EQ(get_field_as_string(evt, "evt.res"), "EACCES");
EXPECT_EQ(get_field_as_string(evt, "evt.rawres"), std::to_string(-SE_EACCES).c_str());
EXPECT_EQ(get_field_as_string(evt, "evt.failed"), "true");
EXPECT_EQ(get_field_as_string(evt, "evt.count.error"), "1");
EXPECT_EQ(get_field_as_string(evt, "evt.count.error.file"), "1");
}

TEST_F(sinsp_with_test_input, event_hostname)
{
#ifdef __linux__
Expand Down
Loading