diff --git a/MODULE.bazel b/MODULE.bazel index a2ab28c..8f9b557 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -79,6 +79,34 @@ bazel_dep(name = "rules_cc", version = "0.1.1") ############################################################################### bazel_dep(name = "rules_shell", version = "0.6.0") +############################################################################### +# +# Container dependencies +# +############################################################################### +bazel_dep(name = "rules_oci", version = "1.8.0") + +oci = use_extension("@rules_oci//oci:extensions.bzl", "oci") + +# Declare external images you need to pull, for example: +oci.pull( + name = "ubuntu_24_04", + digest = "sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30", + image = "ubuntu", + platforms = ["linux/amd64"], + tag = "24.04", +) + +# For each oci.pull call, repeat the "name" here to expose them as dependencies. +use_repo(oci, "ubuntu_24_04") + +############################################################################### +# +# Packaging dependencies +# +############################################################################### +bazel_dep(name = "rules_pkg", version = "1.0.1") + ############################################################################### # # Score custom modules loading @@ -97,5 +125,10 @@ git_repository( name = "dlt_daemon", branch = "master", build_file = "//third_party/dlt:dlt_daemon.BUILD", + patch_args = ["-p1"], + patches = [ + "//third_party/dlt:0000-initialize-global-vars.patch", + "//third_party/dlt:0001-enable-multicast-udp.patch", + ], remote = "https://github.com/draganbjedov/dlt-daemon.git", ) diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index 51896dd..1b539c9 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel @@ -75,7 +75,7 @@ oci = use_extension("@rules_oci//oci:extensions.bzl", "oci") # Declare external images you need to pull, for example: oci.pull( - name = "ubuntu_24_04", + name = "ubuntu_24_04_examples", digest = "sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30", image = "ubuntu", platforms = ["linux/amd64"], @@ -83,7 +83,7 @@ oci.pull( ) # For each oci.pull call, repeat the "name" here to expose them as dependencies. -use_repo(oci, "ubuntu_24_04") +use_repo(oci, "ubuntu_24_04_examples") ############################################################################### # diff --git a/examples/examples/docker/BUILD b/examples/examples/docker/BUILD index b3d20bf..580a022 100644 --- a/examples/examples/docker/BUILD +++ b/examples/examples/docker/BUILD @@ -14,7 +14,7 @@ load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball") oci_image( name = "image", - base = "@ubuntu_24_04", + base = "@ubuntu_24_04_examples", tars = [ "//examples/cpp:example-app-pkg", ], diff --git a/itf/plugins/plugins.bzl b/itf/plugins/plugins.bzl index ce226b4..2055afa 100644 --- a/itf/plugins/plugins.bzl +++ b/itf/plugins/plugins.bzl @@ -59,7 +59,5 @@ dlt = py_itf_plugin( "@score_itf//third_party/dlt:dlt-receive", ], tags = [ - "local", - "manual", ], ) diff --git a/test/BUILD b/test/BUILD index 92b6e5c..cdd89b3 100644 --- a/test/BUILD +++ b/test/BUILD @@ -39,8 +39,14 @@ py_itf_test( srcs = [ "test_dlt.py", ], + args = [ + "--docker-image-bootstrap=$(location //test/resources:image_tarball)", + "--docker-image=score_itf_examples:latest", + ], + data = ["//test/resources:image_tarball"], plugins = [ dlt, + docker, ], ) diff --git a/test/resources/BUILD b/test/resources/BUILD new file mode 100644 index 0000000..5aa8a45 --- /dev/null +++ b/test/resources/BUILD @@ -0,0 +1,55 @@ +# ******************************************************************************* +# Copyright (c) 2026 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* +load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +pkg_tar( + name = "dlt-bins-pkg", + srcs = [ + "@score_itf//third_party/dlt:dlt-adaptor-stdin", + "@score_itf//third_party/dlt:dlt-daemon", + "@score_itf//third_party/dlt:dlt-receive", + ], + package_dir = "usr/bin", +) + +pkg_tar( + name = "dlt-conf-pkg", + srcs = [ + "@score_itf//third_party/dlt:dlt-daemon-conf", + ], + package_dir = "etc", +) + +pkg_tar( + name = "dlt-pkg", + deps = [ + ":dlt-bins-pkg", + ":dlt-conf-pkg", + ], +) + +oci_image( + name = "image", + base = "@ubuntu_24_04", + tars = [ + ":dlt-pkg", + ], +) + +oci_tarball( + name = "image_tarball", + image = ":image", + repo_tags = ["score_itf_examples:latest"], + visibility = ["//test:__pkg__"], +) diff --git a/test/test_dlt.py b/test/test_dlt.py index b08778a..be74312 100644 --- a/test/test_dlt.py +++ b/test/test_dlt.py @@ -10,12 +10,13 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* +import pytest import time from itf.plugins.dlt.dlt_receive import DltReceive, Protocol -def test_dlt(dlt_config): +def test_dlt_standard_config(target, dlt_config): with DltReceive( protocol=Protocol.UDP, host_ip=dlt_config.host_ip, @@ -26,7 +27,7 @@ def test_dlt(dlt_config): time.sleep(1) -def test_dlt_custom_config(dlt_config): +def test_dlt_custom_config(target, dlt_config): with DltReceive( protocol=Protocol.UDP, host_ip="127.0.0.1", @@ -40,3 +41,71 @@ def test_dlt_custom_config(dlt_config): binary_path=dlt_config.dlt_receive_path, ): time.sleep(1) + + +def get_container_ip(target): + target.reload() + return target.attrs["NetworkSettings"]["Networks"]["bridge"]["IPAddress"] + + +def get_docker_network_gateway(target): + target.reload() + return target.attrs["NetworkSettings"]["Networks"]["bridge"]["Gateway"] + + +def test_dlt_direct_tcp(target, dlt_config, caplog): + ipaddress = get_container_ip(target) + target.exec_run(f"/usr/bin/dlt-daemon -d") + + with DltReceive( + protocol=Protocol.TCP, + target_ip=ipaddress, + print_to_stdout=True, + logger_name="fixed_dlt_receive", + binary_path=dlt_config.dlt_receive_path, + ): + for i in range(10): + target.exec_run(f'/bin/sh -c "echo message{i} | /usr/bin/dlt-adaptor-stdin"') + + target.exec_run(f'/bin/sh -c "echo This is a secret message | /usr/bin/dlt-adaptor-stdin"') + + for i in range(10): + target.exec_run(f'/bin/sh -c "echo message{i} | /usr/bin/dlt-adaptor-stdin"') + + captured_logs = [] + for record in caplog.records: + if record.name == "fixed_dlt_receive": + if "This is a secret message" in record.getMessage(): + break + else: + pytest.fail("Expected DLT message was not received") + + +def test_dlt_multicast_udp(target, dlt_config, caplog): + ipaddress = get_container_ip(target) + gateway = get_docker_network_gateway(target) + target.exec_run(f"/usr/bin/dlt-daemon -d") + + with DltReceive( + protocol=Protocol.UDP, + host_ip="172.17.0.1", + multicast_ips=["224.0.0.1"], + print_to_stdout=True, + logger_name="fixed_dlt_receive", + binary_path=dlt_config.dlt_receive_path, + ): + for i in range(10): + target.exec_run(f'/bin/sh -c "echo message{i} | /usr/bin/dlt-adaptor-stdin"') + + target.exec_run(f'/bin/sh -c "echo This is a secret message | /usr/bin/dlt-adaptor-stdin"') + + for i in range(10): + target.exec_run(f'/bin/sh -c "echo message{i} | /usr/bin/dlt-adaptor-stdin"') + + captured_logs = [] + for record in caplog.records: + if record.name == "fixed_dlt_receive": + if "This is a secret message" in record.getMessage(): + break + else: + pytest.fail("Expected DLT message was not received") diff --git a/third_party/dlt/0000-initialize-global-vars.patch b/third_party/dlt/0000-initialize-global-vars.patch new file mode 100644 index 0000000..f88d967 --- /dev/null +++ b/third_party/dlt/0000-initialize-global-vars.patch @@ -0,0 +1,32 @@ +diff --git a/src/offlinelogstorage/dlt_offline_logstorage.c b/src/offlinelogstorage/dlt_offline_logstorage.c +index edf7b23..c9b9be0 100644 +--- a/src/offlinelogstorage/dlt_offline_logstorage.c ++++ b/src/offlinelogstorage/dlt_offline_logstorage.c +@@ -41,6 +41,11 @@ + #define GENERAL_BASE_NAME "General" + /* Hash map functions */ + ++/* logstorage max cache */ ++unsigned int g_logstorage_cache_max; ++/* current logstorage cache size */ ++unsigned int g_logstorage_cache_size; ++ + static int dlt_logstorage_hash_create(int num_entries, struct hsearch_data *htab) + { + memset(htab, 0, sizeof(*htab)); +diff --git a/src/offlinelogstorage/dlt_offline_logstorage.h b/src/offlinelogstorage/dlt_offline_logstorage.h +index df232b7..9b6122b 100644 +--- a/src/offlinelogstorage/dlt_offline_logstorage.h ++++ b/src/offlinelogstorage/dlt_offline_logstorage.h +@@ -125,9 +125,9 @@ + #define DLT_OFFLINE_LOGSTORAGE_IS_STRATEGY_SET(S, s) ((S) & (s)) + + /* logstorage max cache */ +-unsigned int g_logstorage_cache_max; ++extern unsigned int g_logstorage_cache_max; + /* current logstorage cache size */ +-unsigned int g_logstorage_cache_size; ++extern unsigned int g_logstorage_cache_size; + + typedef struct + { diff --git a/third_party/dlt/0001-enable-multicast-udp.patch b/third_party/dlt/0001-enable-multicast-udp.patch new file mode 100644 index 0000000..712f52e --- /dev/null +++ b/third_party/dlt/0001-enable-multicast-udp.patch @@ -0,0 +1,20 @@ +diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf +index 736f417..363cb0e 100644 +--- a/src/daemon/dlt.conf ++++ b/src/daemon/dlt.conf +@@ -183,12 +183,12 @@ PrintASCII = 1 + # Connect with DLT Viewer UDP option to get messages by UDP socket. + + # Activate UDP multicast streaming by setting this option to 1 (Default: OFF) +-# udpStreamActive = 0 ++udpStreamActive = 1 + + # Multicast/Broadcast address to which the daemon send the messages + # Parameter is only used if udpStreamActive = 1. Only IPv4 is supported. +-# udpStreamIP = 224.0.0.1 ++udpStreamIP = 224.0.0.1 + + # UDP port to which the daemon send the messages. + # Parameter is only used if udpStreamActive = 1. +-# udpStreamPort = 3491 ++udpStreamPort = 3490 diff --git a/third_party/dlt/BUILD b/third_party/dlt/BUILD index 142c745..2dadec3 100644 --- a/third_party/dlt/BUILD +++ b/third_party/dlt/BUILD @@ -17,3 +17,27 @@ alias( "//visibility:public", ], ) + +alias( + name = "dlt-adaptor-stdin", + actual = "@dlt_daemon//:dlt-adaptor-stdin", + visibility = [ + "//visibility:public", + ], +) + +alias( + name = "dlt-daemon", + actual = "@dlt_daemon//:dlt-daemon", + visibility = [ + "//visibility:public", + ], +) + +alias( + name = "dlt-daemon-conf", + actual = "@dlt_daemon//:dlt-daemon-conf", + visibility = [ + "//visibility:public", + ], +) diff --git a/third_party/dlt/dlt_daemon.BUILD b/third_party/dlt/dlt_daemon.BUILD index 1e5e4a9..5ff9fa2 100644 --- a/third_party/dlt/dlt_daemon.BUILD +++ b/third_party/dlt/dlt_daemon.BUILD @@ -12,48 +12,21 @@ # ******************************************************************************* load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") -filegroup( - name = "fg_dlt_headers", - srcs = glob([ - "include/**/*.h", - ]), -) - -filegroup( - name = "fg_dlt_receive_SRCS", - srcs = ["src/console/dlt-receive.c"], -) - -cc_library( - name = "dlt_headers", - hdrs = [":fg_dlt_headers"], - features = ["third_party_warnings"], - includes = ["include"], -) - cc_library( name = "dlt-library", - srcs = glob( - [ - "src/shared/**/*.c", - "src/shared/**/*.h", - "src/lib/**/*.c", - "src/lib/**/*.h", - "include/**/*.h", - ], - ) + [ + srcs = glob([ + "src/shared/**/*.c", + "src/shared/**/*.h", + "src/lib/**/*.c", + "src/lib/**/*.h", + ]) + [ "src/daemon/dlt-daemon_cfg.h", ], - hdrs = [":fg_dlt_headers"], - copts = [ - "-pthread", - ], + hdrs = glob(["include/**/*.h"]), defines = [ "_GNU_SOURCE", ], - features = ["third_party_warnings"], includes = [ - "include", "include/dlt", "src/daemon", "src/lib", @@ -63,32 +36,76 @@ cc_library( "-pthread", "-lrt", ], +) + +cc_binary( + name = "dlt-receive", + srcs = ["src/console/dlt-receive.c"], deps = [ - ":dlt_headers", + ":dlt-library", ], - alwayslink = True, + visibility = ["//visibility:public"], ) cc_binary( - name = "libdlt.so", - features = ["third_party_warnings"], - linkshared = True, - visibility = ["//visibility:public"], + name = "dlt-adaptor-stdin", + srcs = [ + "src/adaptor/dlt-adaptor-stdin.c", + ], deps = [ ":dlt-library", ], + visibility = ["//visibility:public"], ) cc_binary( - name = "dlt-receive", - srcs = [":fg_dlt_receive_SRCS"], - features = [ - "treat_warnings_as_errors", - "strict_warnings", - "additional_warnings", + name = "dlt-daemon", + srcs = glob([ + "include/**/*.h", + "src/daemon/*.h", + "src/gateway/*.h", + "src/lib/**/*.h", + "src/offlinelogstorage/*.h", + "src/shared/**/*.h", + ]) + [ + "src/daemon/dlt-daemon.c", + "src/daemon/dlt_daemon_client.c", + "src/daemon/dlt_daemon_common.c", + "src/daemon/dlt_daemon_connection.c", + "src/daemon/dlt_daemon_event_handler.c", + "src/daemon/dlt_daemon_offline_logstorage.c", + "src/daemon/dlt_daemon_serial.c", + "src/daemon/dlt_daemon_socket.c", + "src/daemon/dlt_daemon_unix_socket.c", + "src/gateway/dlt_gateway.c", + "src/lib/dlt_client.c", + "src/offlinelogstorage/dlt_offline_logstorage.c", + "src/offlinelogstorage/dlt_offline_logstorage_behavior.c", + "src/shared/dlt_common.c", + "src/shared/dlt_config_file_parser.c", + "src/shared/dlt_offline_trace.c", + "src/shared/dlt_shm.c", + "src/shared/dlt_user_shared.c", + ], + defines = [ + "_GNU_SOURCE", + 'CONFIGURATION_FILES_DIR=\\"/etc\\"', + ], + includes = [ + "include/dlt", + "src/daemon", + "src/gateway", + "src/lib", + "src/offlinelogstorage", + "src/shared", ], visibility = ["//visibility:public"], - deps = [ - ":dlt-library", +) + +filegroup( + name = "dlt-daemon-conf", + srcs = [ + "src/daemon/dlt.conf", ], + visibility = ["//visibility:public"], )