osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ci/+/41155?usp=email )
Change subject: scripts/wrapper_core_bt_on_error: new script
......................................................................
scripts/wrapper_core_bt_on_error: new script
Add a wrapper script that runs a given program, and checks the exit
code. If it is not 0, and a core file appears, then load the coredump in
gdb and display its backtrace.
Change-Id: I9673abf3ae3b154505ea09237d37d7da4bf5d57f
---
A scripts/wrapper_core_bt_on_error.sh
1 file changed, 38 insertions(+), 0 deletions(-)
Approvals:
fixeria: Looks good to me, but someone else must approve
Jenkins Builder: Verified
daniel: Looks good to me, approved
diff --git a/scripts/wrapper_core_bt_on_error.sh b/scripts/wrapper_core_bt_on_error.sh
new file mode 100755
index 0000000..ca1eaef
--- /dev/null
+++ b/scripts/wrapper_core_bt_on_error.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Copyright 2025 sysmocom - s.f.m.c. GmbH
+# SPDX-License-Identifier: GPL-3.0-or-later
+# Run a program and check for coredumps if it does not exit with 0. If there
+# are any coredumps, then show the backtrace.
+msg() {
+ echo "[wrapper_core_bt_on_error] $@"
+}
+
+if [ $# -lt 1 ]; then
+ echo "usage: wrapper_core_bt_on_error.sh PROGRAM [ARG1 [ARG2 […]]]"
+ exit 1
+fi
+
+ulimit -c unlimited
+
+"$@"
+RC=$?
+
+if [ "$RC" != 0 ]; then
+ for i in $(find -name 'core' -type f); do
+ msg "Found coredump: $i"
+ execfn="$(file "$i" | grep -P -o "execfn: '.*?'" | cut -d "'" -f 2)"
+ if [ -z "$execfn" ] || ! [ -e "$execfn" ]; then
+ msg "Failed to get execfn, ignoring..."
+ continue
+ fi
+
+ echo
+ gdb --batch \
+ "$execfn" \
+ "$i" \
+ -ex bt \
+ | tee "$i.backtrace"
+ echo
+ done
+ exit $RC
+fi
--
To view, visit https://gerrit.osmocom.org/c/osmo-ci/+/41155?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: I9673abf3ae3b154505ea09237d37d7da4bf5d57f
Gerrit-Change-Number: 41155
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ci/+/41154?usp=email )
Change subject: testenv-coredump-helper: remove
......................................................................
testenv-coredump-helper: remove
After looking at this again, it makes more sense to keep
/proc/sys/kernel/core_pattern as "core" on build4 and build5, which we
use for jenkins jobs instead of installing systemd's coredumpctl and
making all coredumps go through that. The motivation for using
coredumpctl in testenv was that lots of developers may have it already
installed (though I'm not sure about that anymore), and that it gives a
nice API for retrieving the related executable name to a coredump
instead of having to parse the output of e.g. "file".
Using coredumpctl had the disadvantage that coredumps for all other
jobs, such as the master-builds are also caught by that and cannot be
easily placed in the workspace directory. I have started implementing
this by extending testenv-coredump-helper to communicate through a
socket and mounting that socket inside docker containers running
contrib/jenkins.sh (host -> lxc -> docker), and it works, but this
complexity is not useful here.
Instead the related patch will make testenv pick the core files when
coredumpctl is not available, and read the path from "file", making
testenv-coredump-helper obsolete.
Related: osmo-ttcn3-hacks Ia765b01432e4cb4cd36c45de874b966e3ebf55bc
Change-Id: I2959c6e6d97d5691ee2a4ae5d49a351eb5811f10
---
D ansible/roles/testenv-coredump-helper/README.md
D ansible/roles/testenv-coredump-helper/files/testenv-coredump-helper.py
D ansible/roles/testenv-coredump-helper/files/testenv-coredump-helper.service
D ansible/roles/testenv-coredump-helper/handlers/main.yml
D ansible/roles/testenv-coredump-helper/tasks/main.yml
M ansible/setup-build-host.yml
6 files changed, 0 insertions(+), 210 deletions(-)
Approvals:
daniel: Looks good to me, but someone else must approve
fixeria: Looks good to me, but someone else must approve
osmith: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/ansible/roles/testenv-coredump-helper/README.md b/ansible/roles/testenv-coredump-helper/README.md
deleted file mode 100644
index d27f457..0000000
--- a/ansible/roles/testenv-coredump-helper/README.md
+++ /dev/null
@@ -1,49 +0,0 @@
-# testenv-coredump-helper
-
-A simple webserver to make Osmocom related coredumps available in LXCs.
-
-## Architecture
-
-```
-.-----------------------------------------------------------------------------.
-| build host (build4) .--------------------------.|
-| | LXC (deb12build-ansible) ||
-| | ||
-| shell | HTTP ||
-| coredumpctl --------- testenv-coredump-helper ------------- testenv ||
-| |__________________________||
-|_____________________________________________________________________________|
-```
-
-## What this script does
-
-This role installs a systemd service running the script in
-`files/testenv-coredump-helper.py`, which runs a HTTP server on port `8042` of
-the `lxcbr0`'s IP (e.g. `10.0.3.1`) on the build host. The IP is detected
-dynamically as it is random on each build host.
-
-The HTTP server provides one GET endpoint `/core`. When it is requested (by
-testenv running inside the LXC), the script runs `coredumpctl` with parameters
-to check for any coredump within the last three seconds that was created for
-any Osmocom specific program (starting with `osmo-*` or `open5gs-*`).
-
-* If no matching coredump was found, it returns HTTP status code `404`.
-
-* If a matching coredump was found, it returns HTTP status code `200`, sends
- the path to the executable in an `X-Executable-Path` header and sends the
- coredump itself as body.
-
-The coredump and path to the executable are retrieved from `coredumpctl`. The
-coredump is stored in a temporary file for the duration of the transfer.
-
-## Client implementation
-
-The clientside implementation is in `osmo-ttcn3-hacks.git`,
-`_testenv/testenv/coredump.py` in the `get_from_coredumpctl_lxc_host()`
-function.
-
-## Maximum coredump size
-
-The `testenv-coredump-helper` script does not limit the size of the coredump,
-however a maximum size that `systemd-coredump` accepts can be configured in
-`/etc/systemd/coredump.conf`.
diff --git a/ansible/roles/testenv-coredump-helper/files/testenv-coredump-helper.py b/ansible/roles/testenv-coredump-helper/files/testenv-coredump-helper.py
deleted file mode 100644
index a56bd0f..0000000
--- a/ansible/roles/testenv-coredump-helper/files/testenv-coredump-helper.py
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/usr/bin/env python3
-# Copyright 2025 sysmocom - s.f.m.c. GmbH
-# SPDX-License-Identifier: GPL-3.0-or-later
-# Simple webserver to make Osmocom related coredumps available in LXCs. See
-# ../README.md and OS#6769 for details.
-import datetime
-import fnmatch
-import http.server
-import json
-import os
-import shutil
-import signal
-import socket
-import socketserver
-import subprocess
-import sys
-import tempfile
-
-
-NETDEV = "lxcbr0"
-IP_PATTERN = "10.0.*"
-PORT = 8042
-
-
-def find_lxc_ip():
- cmd = ["ip", "-j", "-o", "-4", "addr", "show", "dev", NETDEV]
- p = subprocess.run(cmd, capture_output=True, text=True, check=True)
- ret = json.loads(p.stdout)[0]["addr_info"][0]["local"]
- if not fnmatch.fnmatch(ret, IP_PATTERN):
- print(f"ERROR: IP doesn't match pattern {IP_PATTERN}: {ret}")
- sys.exit(1)
- return ret
-
-
-def executable_is_relevant(exe):
- basename = os.path.basename(exe)
- patterns = [
- "open5gs-*",
- "osmo-*",
- ]
-
- for pattern in patterns:
- if fnmatch.fnmatch(basename, pattern):
- return True
-
- return False
-
-
-class CustomRequestHandler(http.server.SimpleHTTPRequestHandler):
- def do_GET(self):
- if self.path == "/core":
- # Check for any coredump within last 3 seconds
- since = (datetime.datetime.now() - datetime.timedelta(seconds=3)).strftime("%Y-%m-%d %H:%M:%S")
- cmd = ["coredumpctl", "-q", "-S", since, "--json=short", "-n1"]
-
- p = subprocess.run(cmd, capture_output=True, text=True)
- if p.returncode != 0:
- self.send_error(404, "No coredump found")
- return None
-
- # Check if the coredump executable is from osmo-*, open5gs-*, etc.
- coredump = json.loads(p.stdout)[0]
- if not executable_is_relevant(coredump["exe"]):
- self.send_error(404, "No coredump found")
- return None
-
- # Put coredump into a temporary file and return it
- with tempfile.TemporaryDirectory() as tmpdirname:
- core_path = os.path.join(tmpdirname, "core")
- cmd = [
- "coredumpctl",
- "dump",
- "-q",
- "-S",
- since,
- "-o",
- core_path,
- str(coredump["pid"]),
- coredump["exe"],
- ]
- subprocess.run(cmd, stdout=subprocess.DEVNULL, check=True)
-
- with open(core_path, "rb") as f:
- self.send_response(200)
- self.send_header("X-Executable-Path", coredump["exe"])
- self.end_headers()
- self.wfile.write(f.read())
- else:
- self.send_error(404, "File Not Found")
-
-
-def signal_handler(sig, frame):
- sys.exit(0)
-
-
-def main():
- if not shutil.which("coredumpctl"):
- print("ERROR: coredumpctl not found!")
- sys.exit(1)
-
- ip = os.environ.get("LXC_HOST_IP") or find_lxc_ip()
- print(f"Listening on {ip}:{PORT}")
- signal.signal(signal.SIGINT, signal_handler)
- with socketserver.TCPServer((ip, PORT), CustomRequestHandler, False) as httpd:
- httpd.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- httpd.server_bind()
- httpd.server_activate()
- httpd.serve_forever()
-
-
-if __name__ == "__main__":
- main()
diff --git a/ansible/roles/testenv-coredump-helper/files/testenv-coredump-helper.service b/ansible/roles/testenv-coredump-helper/files/testenv-coredump-helper.service
deleted file mode 100644
index ef5a851..0000000
--- a/ansible/roles/testenv-coredump-helper/files/testenv-coredump-helper.service
+++ /dev/null
@@ -1,12 +0,0 @@
-[Unit]
-Description=testenv coredump helper
-After=lxc.service
-
-[Service]
-Environment="PYTHONUNBUFFERED=1"
-Type=simple
-Restart=always
-ExecStart=/opt/testenv-coredump-helper/testenv-coredump-helper
-
-[Install]
-WantedBy=multi-user.target
diff --git a/ansible/roles/testenv-coredump-helper/handlers/main.yml b/ansible/roles/testenv-coredump-helper/handlers/main.yml
deleted file mode 100644
index 0f7ef57..0000000
--- a/ansible/roles/testenv-coredump-helper/handlers/main.yml
+++ /dev/null
@@ -1,5 +0,0 @@
----
-- name: restart testenv-coredump-helper
- service:
- name: testenv-coredump-helper
- state: restarted
diff --git a/ansible/roles/testenv-coredump-helper/tasks/main.yml b/ansible/roles/testenv-coredump-helper/tasks/main.yml
deleted file mode 100644
index 9ff2769..0000000
--- a/ansible/roles/testenv-coredump-helper/tasks/main.yml
+++ /dev/null
@@ -1,31 +0,0 @@
----
-- name: install coredumpctl
- apt:
- name:
- - systemd-coredump
- cache_valid_time: 3600
- update_cache: yes
-
-- name: mkdir /opt/testenv-coredump-helper
- ansible.builtin.file:
- path: /opt/testenv-coredump-helper
- state: directory
-
-- name: install testenv-coredump-helper
- ansible.builtin.copy:
- src: testenv-coredump-helper.py
- dest: /opt/testenv-coredump-helper/testenv-coredump-helper
- mode: '0755'
- notify: restart testenv-coredump-helper
-
-- name: install testenv-coredump-helper service
- ansible.builtin.copy:
- src: testenv-coredump-helper.service
- dest: /etc/systemd/system/testenv-coredump-helper.service
- mode: '0644'
- notify: restart testenv-coredump-helper
-
-- name: enable testenv-coredump-helper service
- ansible.builtin.systemd_service:
- name: testenv-coredump-helper
- enabled: true
diff --git a/ansible/setup-build-host.yml b/ansible/setup-build-host.yml
index d1d9874..ed8def5 100644
--- a/ansible/setup-build-host.yml
+++ b/ansible/setup-build-host.yml
@@ -18,4 +18,3 @@
update_cache: yes
roles:
- name: apt-allow-relinfo-change
- - name: testenv-coredump-helper
--
To view, visit https://gerrit.osmocom.org/c/osmo-ci/+/41154?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: I2959c6e6d97d5691ee2a4ae5d49a351eb5811f10
Gerrit-Change-Number: 41154
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/41151?usp=email )
Change subject: testenv: run daemons with 'ulimit -c unlimited'
......................................................................
testenv: run daemons with 'ulimit -c unlimited'
Prepare to support getting core files without having systemd-coredump
installed, as we plan to uninstall it from the jenkins servers to make
retrieving coredumps for other jobs feasible again.
When starting daemons, set the maximum core file size to unlimited.
Otherwise it might be at 0, resulting in no core files getting
generated.
I have considered using resource.setrlimit() on the python process
instead, but this wouldn't work when spawning the daemons inside the
podman container.
Change-Id: Ideaf0386c8d6111c2634f276f926e976023ff511
---
M _testenv/testenv/daemons.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
daniel: Looks good to me, approved
fixeria: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/_testenv/testenv/daemons.py b/_testenv/testenv/daemons.py
index d4804d0..3a38850 100644
--- a/_testenv/testenv/daemons.py
+++ b/_testenv/testenv/daemons.py
@@ -53,7 +53,7 @@
pipe = f"2>&1 | tee {shlex.quote(log)}"
else:
pipe = f">{shlex.quote(log)} 2>&1"
- cmd = ["sh", "-c", f"{program} {pipe}"]
+ cmd = ["sh", "-c", f"ulimit -c unlimited; {program} {pipe}"]
env = {}
if testenv.args.io_uring:
--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/41151?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Ideaf0386c8d6111c2634f276f926e976023ff511
Gerrit-Change-Number: 41151
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>