Debian Codegraph @

tests/README

raw
1 # rsyslog testbench quick reference
2
3 This directory houses the rsyslog Automake test suite. The
4 [`tests/AGENTS.md`](./AGENTS.md) file gives AI agents authoring guidance and
5 conventions; this README focuses on operators and contributors who need to run
6 the suite.
7
8 Most scripts validate a single module, but complex end-to-end scenarios are
9 welcome. For a minimal example, examine `rtinit.c`, which performs a simple
10 runtime init/deinit cycle.
11
12 The `tests/` subtree is the single Automake-owned test area for rsyslog. The
13 shell-driven testbench remains here, and fast C unit-test sources for isolated
14 helpers are organized in [`tests/unit/`](./unit/README.md) but are built and
15 run by [`tests/Makefile.am`](./Makefile.am).
16
17 ## Quickstart
18
19 Bootstrap the build tree before attempting to run tests:
20
21 ```sh
22 ./autogen.sh
23 ./configure --enable-testbench
24 make -j$(nproc)
25 make check
26 ```
27
28 `make check` compiles the helper binaries, prepares fixtures, and then executes
29 the entire suite, including the unit tests sourced from `tests/unit/`. Use
30 <kbd>Ctrl</kbd>+<kbd>C</kbd> to stop an ongoing run.
31
32 ## Running individual scenarios
33
34 ```
35 make <test-name>.log
36 ```
37
38 For example, `make imfile-basic.log` produces `imfile-basic.log` and
39 `imfile-basic.trs`. Remove those files before re-running to clear cached
40 results. When you need Automake’s logging but do not want to type the `.log`
41 suffix, use:
42
43 ```
44 make check TESTS='imfile-basic.sh'
45 ```
46
47 You can also execute scripts directly (`./tests/imfile-basic.sh`) for quicker
48 iteration, though Automake will not capture transcripts.
49
50 To run the linkedlist unit test through the shared harness from the repository
51 root:
52
53 ```
54 make check TESTS='runtime_unit_linkedlist'
55 ```
56
57 ## Harness conventions
58
59 - Include `diag.sh` at the top of every shell test using the POSIX `.` command: `. "$srcdir/diag.sh"`.
60 - Prefer helpers such as `cmp_exact` and `require_plugin` over ad-hoc shell so
61 diagnostics stay consistent. See `tests/AGENTS.md` for a longer checklist.
62 - Name Valgrind-enabled wrappers with the `-vg.sh` suffix and Helgrind-enabled
63 scripts with `-vgthread.sh`. `tests/timereported-utc-vg.sh` illustrates how to
64 include the base scenario using the `.` command rather than duplicating it and
65 how to trim emitted messages when a slow test would otherwise become
66 prohibitively long under Valgrind. Some legacy wrappers predate this pattern;
67 follow the newer style when adding or refactoring coverage.
68
69 ## Environment setup snippets
70
71 ### MariaDB/MySQL
72
73 ```
74 echo "create user 'rsyslog'@'localhost' identified by 'testbench';" | mysql -u root
75 mysql -u root < ../plugins/ommysql/createDB.sql
76 echo "grant all on Syslog.* to 'rsyslog'@'localhost';" | mysql -u root
77 ```
78
79 ### openSUSE tips
80
81 Use the graphical `yast2` tool to adjust hostname and firewall rules. SSH
82 access is disabled in the firewall by default.
83
84 ## Debugging aids
85
86 To pause a test and attach a debugger, add the following guard:
87
88 ```sh
89 . "$srcdir/diag.sh" startup
90 if [ -n "${USE_GDB:-}" ]; then
91 echo "attach gdb here"
92 sleep 54321 || :
93 fi
94 ```
95
96 Run the scenario in the background, wait for the prompt, and attach GDB:
97
98 ```
99 USE_GDB=1 make mytest.sh.log &
100 tail -f mytest.sh.log # wait for "attach gdb here"
101 gdb ../tools/rsyslogd <rsyslogd-pid>
102 ```
103
104 After continuing in GDB, terminate the `sleep` with `pkill -f 54321` (or locate
105 the PID via `ps -ef | grep 54321`).
106
107 ## Core dump analysis
108
109 The harness can inspect core dumps automatically. Ensure the operating system
110 allows them to be written:
111
112 1. Set `ulimit -c unlimited` (you might need to adjust `/etc/security/limits.conf`
113 to raise `soft core unlimited`).
114 2. Confirm `/proc/sys/kernel/core_pattern` is set to `core`. Systemd-based
115 distributions often redirect cores elsewhere; revert to the classic format
116 with `sudo bash -c 'echo core > /proc/sys/kernel/core_pattern'`.
117
118 Avoid applying these tweaks on production hosts.