Skip to content

Commit

Permalink
cleanup(tests): move some scap file tests under the right directory
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 committed Aug 9, 2024
1 parent 686dfc0 commit a828ecd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 39 deletions.
3 changes: 0 additions & 3 deletions userspace/libsinsp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ configure_file (

file(GLOB_RECURSE TEST_PLUGINS ${CMAKE_CURRENT_SOURCE_DIR}/plugins/*.cpp)

add_definitions(-DRESOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/resources")

if(NOT WIN32)
file(GLOB_RECURSE SINSP_PARSERS_SUITE ${CMAKE_CURRENT_SOURCE_DIR}/parsers/*.cpp)

Expand Down Expand Up @@ -119,7 +117,6 @@ set(LIBSINSP_UNIT_TESTS_SOURCES
state.ut.cpp
dns_manager.ut.cpp
eventformatter.ut.cpp
savefile.ut.cpp
sinsp_metrics.ut.cpp
thread_table.ut.cpp
ifinfo.ut.cpp
Expand Down
1 change: 1 addition & 0 deletions userspace/libsinsp/test/helpers/scap_file_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.

#include <libsinsp/sinsp.h>
#include <libsinsp/event.h>
#include <libsinsp_test_var.h>

namespace scap_file_test_helpers
{
Expand Down
2 changes: 2 additions & 0 deletions userspace/libsinsp/test/libsinsp_test_var.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

// Absolute path to the scap files dir
#define LIBSINSP_TEST_SCAP_FILES_DIR "${CMAKE_BINARY_DIR}/scap_files/"

#define LIBSINSP_TMP_TEST_SCAP_FILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources/"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2023 The Falco Authors.
Copyright (C) 2024 The Falco Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -18,22 +18,22 @@ limitations under the License.

#include <libsinsp/sinsp.h>
#include <libsinsp/sinsp_cycledumper.h>

#include <helpers/scap_file_helpers.h>
#include <gtest/gtest.h>

using namespace std;

#ifdef __x86_64__
TEST(savefile, proclist)
TEST(scap_file, filter)
{
sinsp inspector;
inspector.open_savefile(RESOURCE_DIR "/sample.scap");
{
// Check the dimension of the table before the filtering
sinsp inspector;
inspector.open_savefile(LIBSINSP_TMP_TEST_SCAP_FILES_DIR "/sample.scap");

ASSERT_EQ(inspector.m_thread_manager->get_thread_count(), 94);
}
ASSERT_EQ(inspector.m_thread_manager->get_thread_count(), 94);
}

TEST(savefile, filter)
{
char filtered_scap[] = "filtered.XXXXXX.scap";

int filtered_fd = mkstemps(filtered_scap, strlen(".scap"));
Expand All @@ -43,10 +43,9 @@ TEST(savefile, filter)
{
sinsp inspector;
inspector.set_filter("proc.name=ifplugd");
inspector.open_savefile(RESOURCE_DIR "/sample.scap");
inspector.open_savefile(LIBSINSP_TMP_TEST_SCAP_FILES_DIR "/sample.scap");

auto dumper = std::make_unique<sinsp_cycledumper>(&inspector, filtered_scap,
0, 0, 0, 0, true);
auto dumper = std::make_unique<sinsp_cycledumper>(&inspector, filtered_scap, 0, 0, 0, 0, true);

int32_t res;
sinsp_evt* evt;
Expand All @@ -58,8 +57,7 @@ TEST(savefile, filter)
{
dumper->dump(evt);
}
}
while(res != SCAP_EOF);
} while(res != SCAP_EOF);

dumper->close();
inspector.close();
Expand All @@ -78,17 +76,11 @@ TEST(savefile, filter)
int n_opens = 0;
int n_closes = 0;

void open_cb()
{
n_opens +=1;
}
void open_cb() { n_opens += 1; }

void close_cb()
{
n_closes += 1;
}
void close_cb() { n_closes += 1; }

TEST(savefile, cycledumper_num_events)
TEST(scap_file, cycledumper_num_events)
{
char capture_scap[] = "capture.XXXXXX.scap";
int events_per_capture = 100;
Expand All @@ -102,12 +94,12 @@ TEST(savefile, cycledumper_num_events)

{
sinsp inspector;
inspector.open_savefile(RESOURCE_DIR "/sample.scap");
inspector.open_savefile(LIBSINSP_TMP_TEST_SCAP_FILES_DIR "/sample.scap");

auto dumper = std::make_unique<sinsp_cycledumper>(&inspector, capture_scap,
0, 0, 0, events_per_capture, true);
auto dumper = std::make_unique<sinsp_cycledumper>(&inspector, capture_scap, 0, 0, 0, events_per_capture,
true);

std::vector<std::function<void()>> open_cbs = {std::bind(&open_cb)};
std::vector<std::function<void()>> open_cbs = {std::bind(&open_cb)};
std::vector<std::function<void()>> close_cbs = {std::bind(&close_cb)};

dumper->set_callbacks(open_cbs, close_cbs);
Expand All @@ -122,8 +114,7 @@ TEST(savefile, cycledumper_num_events)
{
dumper->dump(evt);
}
}
while(res != SCAP_EOF);
} while(res != SCAP_EOF);

dumper->close();
inspector.close();
Expand All @@ -135,7 +126,7 @@ TEST(savefile, cycledumper_num_events)
unlink(capture_scap);
}

TEST(savefile, cycledumper_seconds)
TEST(scap_file, cycledumper_seconds)
{
char capture_scap[] = "capture.XXXXXX.scap";
int seconds_per_capture = 1;
Expand All @@ -149,12 +140,12 @@ TEST(savefile, cycledumper_seconds)

{
sinsp inspector;
inspector.open_savefile(RESOURCE_DIR "/sample.scap");
inspector.open_savefile(LIBSINSP_TMP_TEST_SCAP_FILES_DIR "/sample.scap");

auto dumper = std::make_unique<sinsp_cycledumper>(&inspector, capture_scap,
0, seconds_per_capture, 0, 0, true);
auto dumper = std::make_unique<sinsp_cycledumper>(&inspector, capture_scap, 0, seconds_per_capture, 0,
0, true);

std::vector<std::function<void()>> open_cbs = {std::bind(&open_cb)};
std::vector<std::function<void()>> open_cbs = {std::bind(&open_cb)};
std::vector<std::function<void()>> close_cbs = {std::bind(&close_cb)};

dumper->set_callbacks(open_cbs, close_cbs);
Expand All @@ -169,8 +160,7 @@ TEST(savefile, cycledumper_seconds)
{
dumper->dump(evt);
}
}
while(res != SCAP_EOF);
} while(res != SCAP_EOF);

dumper->close();
inspector.close();
Expand Down

0 comments on commit a828ecd

Please sign in to comment.