From 07fce9036026bf8847e0b35eec969a1b89ddae63 Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Tue, 25 Jun 2019 16:17:56 +0000 Subject: [PATCH] build: includes for tests Co-Authored-by: Lorenzo Fontana Signed-off-by: Leonardo Di Donato --- tests/CMakeLists.txt | 19 ++++++++-- tests/engine/test_ruleset.cpp | 67 +++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 tests/engine/test_ruleset.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 91ea35d366a..1e0e370b56e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,7 +16,8 @@ # limitations under the License. # set(FALCO_TESTS_SOURCES - test_base.cpp) + test_base.cpp + engine/test_ruleset.cpp) set(FALCO_TESTED_LIBRARIES falco_engine) @@ -31,11 +32,23 @@ if(FALCO_BUILD_TESTS) add_executable(falco_test ${FALCO_TESTS_SOURCES}) - target_link_libraries(falco_test PUBLIC ${FALCO_TESTED_LIBRARIES} catch) + target_link_libraries(falco_test PUBLIC ${FALCO_TESTED_LIBRARIES} catch) + target_include_directories(falco_test PUBLIC + "${SYSDIG_DIR}/userspace/libsinsp/third-party/jsoncpp" + "${SYSDIG_DIR}/userspace/libscap" + "${SYSDIG_DIR}/userspace/libsinsp" + "${LUAJIT_INCLUDE}" + "${NJSON_INCLUDE}" + "${CURL_INCLUDE_DIR}" + "${TBB_INCLUDE_DIR}" + "${LUAJIT_INCLUDE}" + "${NJSON_INCLUDE}" + "${PROJECT_SOURCE_DIR}/userspace/engine" + ) include(CTest) include(Catch) catch_discover_tests(falco_test) - add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS falco_test) + add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS falco_test) endif() diff --git a/tests/engine/test_ruleset.cpp b/tests/engine/test_ruleset.cpp new file mode 100644 index 00000000000..024b8106be4 --- /dev/null +++ b/tests/engine/test_ruleset.cpp @@ -0,0 +1,67 @@ +/* +Copyright (C) 2016-2019 Draios Inc dba Sysdig. + +This file is part of falco. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include +#include "ruleset.h" + +TEST_CASE("vectors can be sized and resized", "[vector]") +{ + auto rs = new falco_ruleset(); + + SECTION("adding ...") + { + std::string s = "string"; + std::set tagset = {"a", "b", "c"}; + std::set evtset = {1, 2, 3}; + rs->add(s, tagset, evtset, nullptr); + } + + // std::vector v(5); + + // REQUIRE(v.size() == 5); + // REQUIRE(v.capacity() >= 5); + + // SECTION("resizing bigger changes size and capacity") + // { + // v.resize(10); + + // REQUIRE(v.size() == 10); + // REQUIRE(v.capacity() >= 10); + // } + // SECTION("resizing smaller changes size but not capacity") + // { + // v.resize(0); + + // REQUIRE(v.size() == 0); + // REQUIRE(v.capacity() >= 5); + // } + // SECTION("reserving bigger changes capacity but not size") + // { + // v.reserve(10); + + // REQUIRE(v.size() == 5); + // REQUIRE(v.capacity() >= 10); + // } + // SECTION("reserving smaller does not change size or capacity") + // { + // v.reserve(0); + + // REQUIRE(v.size() == 5); + // REQUIRE(v.capacity() >= 5); + // } +}