Skip to content

Commit

Permalink
tests: add 2 new tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <andrea.terzolo@polito.it>
  • Loading branch information
Andreagit97 committed Mar 15, 2023
1 parent 29fe699 commit 0c03f22
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions userspace/libsinsp/test/table/event_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <sinsp.h>

/* These numbers must be updated when we add new events */
#define SYSCALL_EVENTS_NUM 344
#define SYSCALL_EVENTS_NUM 346
#define TRACEPOINT_EVENTS_NUM 6
#define METAEVENTS_NUM 19
#define PLUGIN_EVENTS_NUM 1
Expand Down Expand Up @@ -101,14 +101,59 @@ TEST(event_table, check_unique_events_syscall_category)
case EC_SCHEDULER:
case EC_INTERNAL:
break;

/* If we fall here it means that some events have more than one syscall category! */
default:
goto end;
break;
}
}
}

end:
ASSERT_EQ(event_num, PPM_EVENT_MAX);
}

TEST(events, check_event_names)
{
std::map<std::string, int> event_names_count;

for(int evt = 0; evt < PPM_EVENT_MAX; evt++)
{
if(libsinsp::events::is_old_version_event((ppm_event_code)evt))
{
continue;
}

event_names_count[scap_get_event_info_table()[evt].name]++;
}

for(const auto& evt : event_names_count)
{
/* NA occurrences should be equal to unknown events number, so more than 2 */
if(evt.first.compare("NA") != 0)
{
/* all events that use exit and enter events should have `evt.second == 2`
* while events paired with a `NA` event should have `evt.second == 1`
*/
ASSERT_TRUE(evt.second <= 2) << "[fail] " << evt.first << " = " << evt.second << std::endl;
}
}
}

TEST(events, check_usage_of_EC_UNKNOWN_flag)
{
/* Every time an event is marked with the `EC_UNKNOWN` flag we should use `NA` as its name */
std::string unknown_name = "NA";
for(int evt = 0; evt < PPM_EVENT_MAX; evt++)
{
if(unknown_name.compare(scap_get_event_info_table()[evt].name) == 0)
{
ASSERT_TRUE(libsinsp::events::is_unknown_event((ppm_event_code)evt)) << "[fail] event " << evt << " should have the EC_UNKNOWN flag";
}

if(libsinsp::events::is_unknown_event((ppm_event_code)evt))
{
ASSERT_TRUE(unknown_name.compare(scap_get_event_info_table()[evt].name) == 0) << "[fail] event " << evt << " should have NA as its name";
}
}
}

0 comments on commit 0c03f22

Please sign in to comment.