summaryrefslogtreecommitdiffstats
path: root/tests/ebpf
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 02:57:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 02:57:58 +0000
commitbe1c7e50e1e8809ea56f2c9d472eccd8ffd73a97 (patch)
tree9754ff1ca740f6346cf8483ec915d4054bc5da2d /tests/ebpf
parentInitial commit. (diff)
downloadnetdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.tar.xz
netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.zip
Adding upstream version 1.44.3.upstream/1.44.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ebpf')
-rw-r--r--tests/ebpf/README.md1
-rw-r--r--tests/ebpf/ebpf.d.conf28
-rw-r--r--tests/ebpf/ebpf_thread_function.sh.in52
-rw-r--r--tests/ebpf/sync_tester.c120
4 files changed, 201 insertions, 0 deletions
diff --git a/tests/ebpf/README.md b/tests/ebpf/README.md
new file mode 100644
index 00000000..86e3dd87
--- /dev/null
+++ b/tests/ebpf/README.md
@@ -0,0 +1 @@
+The file `sync_tester.c` can be used to fill all dimensions present in synchronization submenu.
diff --git a/tests/ebpf/ebpf.d.conf b/tests/ebpf/ebpf.d.conf
new file mode 100644
index 00000000..4b781d53
--- /dev/null
+++ b/tests/ebpf/ebpf.d.conf
@@ -0,0 +1,28 @@
+[global]
+ ebpf load mode = entry
+ apps = yes
+ cgroups = no
+ update every = 5
+ pid table size = 32768
+ btf path = /sys/kernel/btf/
+ maps per core = yes
+ life time = 300
+
+[ebpf programs]
+ cachestat = no
+ dcstat = no
+ disk = no
+ fd = no
+ filesystem = no
+ hardirq = no
+ mdflush = no
+ mount = no
+ oomkill = no
+ process = no
+ shm = no
+ socket = no
+ softirq = no
+ sync = no
+ swap = no
+ vfs = no
+ network connections = no
diff --git a/tests/ebpf/ebpf_thread_function.sh.in b/tests/ebpf/ebpf_thread_function.sh.in
new file mode 100644
index 00000000..dd1e7b6e
--- /dev/null
+++ b/tests/ebpf/ebpf_thread_function.sh.in
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+netdata_ebpf_test_functions() {
+ echo "QUERYING: ${1}"
+ curl -k -o /tmp/ebpf_netdata_test_functions.txt "${1}"
+ TEST=$?
+ if [ $TEST -ne 0 ]; then
+ echo "Cannot request run a for ${1}. See '/tmp/ebpf_netdata_test_functions.txt' for more details."
+ exit 1
+ fi
+
+ grep "${2}" /tmp/ebpf_netdata_test_functions.txt >/dev/null
+ TEST=$?
+ if [ $TEST -ne 0 ]; then
+ echo "Cannot find ${2} in the output. See '/tmp/ebpf_netdata_test_functions.txt' for more details.."
+ exit 1
+ fi
+
+ rm /tmp/ebpf_netdata_test_functions.txt
+}
+
+MURL="http://127.0.0.1:19999"
+INTERVAL=60
+
+if [ -n "$1" ]; then
+ MURL="$1"
+fi
+
+# Check function loaded
+netdata_ebpf_test_functions "${MURL}/api/v1/functions" "ebpf_thread"
+
+# Check function help
+netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread%20help" "allows user to control eBPF threads"
+
+#Test default request
+netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread" "columns"
+
+#Test thread requests . The mdflush is not enabled, because it is not present in all distributions by default.
+#Socket is not in the list, because it will have a complete refactory with next PR
+for THREAD in "cachestat" "dc" "disk" "fd" "filesystem" "hardirq" "mount" "oomkill" "process" "shm" "softirq" "sync" "swap" "vfs" ;
+do
+ echo "TESTING ${THREAD}"
+ netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread%20enable:${THREAD}:${INTERVAL}%20thread:${THREAD}"
+ sleep 17
+ netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread%20thread:${THREAD}" "running"
+ sleep 17
+ netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread%20disable:${THREAD}"
+ sleep 6
+ netdata_ebpf_test_functions "${MURL}/api/v1/function?function=ebpf_thread%20thread:${THREAD}" "stopped"
+ sleep 6
+done
+
diff --git a/tests/ebpf/sync_tester.c b/tests/ebpf/sync_tester.c
new file mode 100644
index 00000000..373c85c6
--- /dev/null
+++ b/tests/ebpf/sync_tester.c
@@ -0,0 +1,120 @@
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+
+#define _GNU_SOURCE /* See feature_test_macros(7) */
+#define __USE_GNU
+#include <fcntl.h>
+#include <unistd.h>
+
+void test_sync_file_range(char *output, char *text, size_t length)
+{
+ int fd = open (output, O_WRONLY | O_CREAT | O_APPEND, 0660);
+ if (fd < 0 ) {
+ perror("Cannot get page size");
+ return;
+ }
+
+ int i;
+ size_t offset = 0;
+ for ( i = 0 ; i < 10000; i++ ) {
+ write(fd, text, length);
+ sync_file_range(fd, offset, length, SYNC_FILE_RANGE_WRITE);
+ offset += length;
+ }
+
+ close(fd);
+ sleep(5);
+}
+
+// test based on IBM example https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/apis/msync.htm
+void test_msync(char *output, char *text, size_t length)
+{
+ int pagesize = sysconf(_SC_PAGE_SIZE);
+ if (pagesize < 0) {
+ perror("Cannot get page size");
+ return;
+ }
+
+ int fd = open(output, (O_CREAT | O_TRUNC | O_RDWR), (S_IRWXU | S_IRWXG | S_IRWXO));
+ if (fd < 0 ) {
+ perror("Cannot open file");
+ return;
+ }
+
+ off_t lastoffset = lseek( fd, pagesize, SEEK_SET);
+ ssize_t written = write(fd, " ", 1);
+ if ( written != 1 ) {
+ perror("Write error. ");
+ close(fd);
+ return;
+ }
+
+ off_t my_offset = 0;
+ void *address = mmap(NULL, pagesize, PROT_WRITE, MAP_SHARED, fd, my_offset);
+
+ if ( address == MAP_FAILED ) {
+ perror("Map error. ");
+ close(fd);
+ return;
+ }
+
+ (void) strcpy( (char*) address, text);
+
+ if ( msync( address, pagesize, MS_SYNC) < 0 ) {
+ perror("msync failed with error:");
+ }
+
+ close(fd);
+ sleep(5);
+}
+
+void test_synchronization(char *output, char *text, size_t length, int (*fcnt)(int))
+{
+ int fd = open (output, O_WRONLY | O_CREAT | O_APPEND, 0660);
+ if (fd < 0 ) {
+ perror("Cannot get page size");
+ return;
+ }
+
+ int i;
+ for ( i = 0 ; i < 10000; i++ )
+ write(fd, text, length);
+
+ fcnt(fd);
+ close(fd);
+
+ sleep(5);
+}
+
+void remove_files(char **files) {
+ size_t i = 0;
+ while (files[i]) {
+ unlink(files[i]);
+ i++;
+ }
+}
+
+int main()
+{
+ char *default_text = { "This is a simple example to test a PR. The sleep is used to create different peaks on charts.\n" };
+ char *files[] = { "fsync.txt", "fdatasync.txt", "syncfs.txt", "msync.txt", "sync_file_range.txt", NULL };
+ size_t length = strlen(default_text);
+ test_synchronization(files[0], default_text, length, fsync);
+ test_synchronization(files[1], default_text, length, fdatasync);
+ test_synchronization(files[2], default_text, length, syncfs);
+
+ test_msync(files[3], default_text, length);
+
+ test_sync_file_range(files[4], default_text, length);
+
+ sync();
+
+ remove_files(files);
+
+ return 0;
+}