-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Roberto Scolaro <[email protected]>
- Loading branch information
1 parent
7c60d90
commit 6435dbd
Showing
18 changed files
with
1,845 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/* | ||
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. | ||
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 "sys_call_test.h" | ||
|
||
#include <gtest/gtest.h> | ||
#include <sys/stat.h> | ||
|
||
#include <libsinsp/sinsp.h> | ||
|
||
TEST_F(sys_call_test, can_consume_a_capture_file) | ||
{ | ||
int callnum = 0; | ||
|
||
event_filter_t filter = [&](sinsp_evt* evt) | ||
{ | ||
std::string evt_name(evt->get_name()); | ||
return evt_name.find("stat") != std::string::npos && | ||
m_tid_filter(evt) && evt->get_direction() == SCAP_ED_OUT; | ||
}; | ||
|
||
run_callback_t test = [](concurrent_object_handle<sinsp> inspector_handle) | ||
{ | ||
struct stat sb; | ||
for(int i = 0; i < 100; i++) | ||
{ | ||
stat("/tmp", &sb); | ||
} | ||
}; | ||
|
||
captured_event_callback_t callback = [&](const callback_param& param) { callnum++; }; | ||
ASSERT_NO_FATAL_FAILURE({ event_capture::run(test, callback, filter); }); | ||
EXPECT_EQ(100, callnum); | ||
|
||
sinsp inspector; | ||
sinsp_evt* event; | ||
|
||
const ::testing::TestInfo* const test_info = | ||
::testing::UnitTest::GetInstance()->current_test_info(); | ||
auto filename = std::string(LIBSINSP_TEST_CAPTURES_PATH) + test_info->test_case_name() + "_" + | ||
test_info->name() + ".scap"; | ||
inspector.open_savefile(filename); | ||
callnum = 0; | ||
int32_t res; | ||
while((res = inspector.next(&event)) != SCAP_EOF) | ||
{ | ||
ASSERT_EQ(SCAP_SUCCESS, res); | ||
std::string evt_name(event->get_name()); | ||
if(evt_name.find("stat") != std::string::npos && | ||
m_tid_filter(event) && event->get_direction() == SCAP_ED_OUT) | ||
{ | ||
callnum++; | ||
} | ||
} | ||
|
||
ASSERT_EQ(SCAP_EOF, res); | ||
ASSERT_EQ(100, callnum); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
test/libsinsp_e2e/resources/docker/health_dockerfiles/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
foreach( | ||
dockerfile | ||
Dockerfile.healthcheck | ||
Dockerfile.healthcheck_shell | ||
Dockerfile.healthcheck_cmd_overlap | ||
Dockerfile.healthcheck_liveness | ||
Dockerfile.healthcheck_readiness | ||
Dockerfile.no_healthcheck | ||
Dockerfile.none_healthcheck | ||
) | ||
|
||
configure_file( | ||
${CMAKE_CURRENT_SOURCE_DIR}/${dockerfile} ${CMAKE_CURRENT_BINARY_DIR}/${dockerfile} | ||
COPYONLY | ||
) | ||
|
||
endforeach(dockerfile) |
3 changes: 3 additions & 0 deletions
3
test/libsinsp_e2e/resources/docker/health_dockerfiles/Dockerfile.healthcheck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM busybox | ||
RUN cp /bin/true /bin/ut-health-check | ||
HEALTHCHECK --interval=0.5s CMD ["/bin/ut-health-check"] |
2 changes: 2 additions & 0 deletions
2
test/libsinsp_e2e/resources/docker/health_dockerfiles/Dockerfile.healthcheck_cmd_overlap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM busybox | ||
HEALTHCHECK --interval=0.5s CMD ["/bin/sh", "-c", "/bin/sleep 10"] |
8 changes: 8 additions & 0 deletions
8
test/libsinsp_e2e/resources/docker/health_dockerfiles/Dockerfile.healthcheck_liveness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM busybox | ||
RUN cp /bin/true /bin/ut-health-check | ||
|
||
# This container runs a docker healthcheck, but due to the | ||
# annotation.... label, it gets interpretated as if it were a k8s | ||
# liveness check. | ||
HEALTHCHECK --interval=0.5s CMD ["/bin/ut-health-check"] | ||
LABEL annotation.kubectl.kubernetes.io/last-applied-configuration="{\"apiVersion\":\"v1\",\"kind\":\"Pod\",\"metadata\":{\"annotations\":{},\"name\":\"mysql-app\",\"namespace\":\"default\"},\"spec\":{\"containers\":[{\"env\":[{\"name\":\"MYSQL_ROOT_PASSWORD\",\"value\":\"no\"}],\"image\":\"mstemm/mysql:healthcheck\",\"livenessProbe\":{\"exec\":{\"command\":[\"/bin/ut-health-check\"]},\"initialDelaySeconds\":5,\"periodSeconds\":5},\"name\":\"mysql\"}]}}\n" |
8 changes: 8 additions & 0 deletions
8
test/libsinsp_e2e/resources/docker/health_dockerfiles/Dockerfile.healthcheck_readiness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM busybox | ||
RUN cp /bin/true /bin/ut-health-check | ||
|
||
# This container runs a docker healthcheck, but due to the | ||
# annotation.... label, it gets interpretated as if it were a k8s | ||
# readiness check. | ||
HEALTHCHECK --interval=0.5s CMD ["/bin/ut-health-check"] | ||
LABEL annotation.kubectl.kubernetes.io/last-applied-configuration="{\"apiVersion\":\"v1\",\"kind\":\"Pod\",\"metadata\":{\"annotations\":{},\"name\":\"mysql-app\",\"namespace\":\"default\"},\"spec\":{\"containers\":[{\"env\":[{\"name\":\"MYSQL_ROOT_PASSWORD\",\"value\":\"no\"}],\"image\":\"mstemm/mysql:healthcheck\",\"readinessProbe\":{\"exec\":{\"command\":[\"/bin/ut-health-check\"]},\"initialDelaySeconds\":5,\"periodSeconds\":5},\"name\":\"mysql\"}]}}\n" |
3 changes: 3 additions & 0 deletions
3
test/libsinsp_e2e/resources/docker/health_dockerfiles/Dockerfile.healthcheck_shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM busybox | ||
RUN cp /bin/true /bin/ut-health-check | ||
HEALTHCHECK --interval=0.5s CMD /bin/ut-health-check |
1 change: 1 addition & 0 deletions
1
test/libsinsp_e2e/resources/docker/health_dockerfiles/Dockerfile.no_healthcheck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM busybox:latest |
2 changes: 2 additions & 0 deletions
2
test/libsinsp_e2e/resources/docker/health_dockerfiles/Dockerfile.none_healthcheck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM busybox:latest | ||
HEALTHCHECK NONE |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/python2 | ||
# coding: utf-8 -*- | ||
import socket | ||
import os, os.path | ||
import time | ||
import sys | ||
|
||
PAYLOAD = "0123456789QWERTYUIOPASDFGHJKLZXCVBNM" | ||
NAME = "/tmp/python_unix_sockets_example" | ||
|
||
if sys.argv[1] == 'server': | ||
if os.path.exists(NAME): | ||
os.remove(NAME) | ||
|
||
server = socket.socket( socket.AF_UNIX, socket.SOCK_STREAM ) | ||
server.bind(NAME) | ||
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) | ||
|
||
print "STARTED" | ||
server.listen(5) | ||
|
||
connect, address = server.accept() | ||
resp = connect.recv( 1024 ) | ||
connect.send(resp) | ||
connect.close() | ||
server.close() | ||
os.remove(NAME) | ||
|
||
else: | ||
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) | ||
|
||
if os.path.exists(NAME): | ||
client = socket.socket( socket.AF_UNIX, socket.SOCK_STREAM ) | ||
client.connect(NAME) | ||
|
||
print "STARTED" | ||
|
||
client.send(PAYLOAD) | ||
resp = client.recv(1024) | ||
client.close() | ||
|
||
else: | ||
print >> sys.stderr, "Couldn't Connect!" |
Oops, something went wrong.