summaryrefslogtreecommitdiff
path: root/ctdb/tests/src
AgeCommit message (Collapse)AuthorFilesLines
2025-07-28ctdb-tests: Fix CID 1659221 - Error handling issues (CHECKED_RETURN)Martin Schwenke1-1/+4
Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Anoop C S <anoopcs@samba.org> Autobuild-User(master): Anoop C S <anoopcs@samba.org> Autobuild-Date(master): Mon Jul 28 06:45:51 UTC 2025 on atb-devel-224
2025-07-28ctdb-tests: Fix CID 1373387 - Time of check time of use (TOCTOU)Martin Schwenke1-4/+4
Coverity doesn't like the fopen(3) after stat(2). This is test code that runs in a simple test environment, so this doesn't really matter. However, reorder the code to put the stat(2) after the fopen(3). This means that the test still does all the same checks and it should now make Coverity happy. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Anoop C S <anoopcs@samba.org>
2025-07-22ctdb-tests: Add tests for tunables directory loadingMartin Schwenke1-3/+37
The missing 2nd file testcase becomes the missing directory testcase, because you can't easily have both. See the comment in tunable_test.c. Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2025-07-22ctdb-tests: Allow tunables unit test to process a second fileMartin Schwenke1-2/+10
The second file is optional. Make $tfile the default to avoid having to update all of the single file testcases. Add test cases for second file. Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2025-07-22ctdb-tests: Add logging support to the tunables unit testMartin Schwenke1-0/+4
Make tunable_test respect CTDB_DEBUGLEVEL. Using test_options.[ch] would be overkill here. This means including logging.c - we can't link to the subsystem containing logging.c because the file being tested (tunable.c) is part of that subsystem. Support logging in the test script. tunable_ok() builds the logging output for the good path. Set the debug level to NOTICE and update expected results for individual failure path tests. Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2025-07-22ctdb-common: Require separate initialisation of tunable defaultsMartin Schwenke1-0/+2
Dropping this from ctdb_tunable_load_file() allows that function to be called multiple times for different files. The caller sets the defaults. In the test script, factor out the handling of a single tunables file in a similar way. Ignoring missing/unreadable files is OK because this function will only be called for test successes (hence "ok" in the name). There will never be existing, unreadable files. The code being tested ignores missing files, so do that here too. Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2024-10-07ctdb-tests: Add test code for ctdb_sys_have_ip()Martin Schwenke1-0/+23
Do not add any automated test cases because they will always be racy. This allows manual testing of the function. Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: John Mulligan <jmulligan@redhat.com> Reviewed-by: Anoop C S <anoopcs@samba.org>
2024-08-06ctdb-tests: add USENODESCOMMAND directive to fake ctdbJohn Mulligan1-2/+15
Add a single line USENODESCOMMAND directive to the fake ctdb in order to enable use of a nodes script instead of a nodes file. For simplicity the fake ctdb always uses `nodes.sh` in the CTDB_BASE. Signed-off-by: John Mulligan <jmulligan@redhat.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
2024-08-06ctdb-conf: add boolean arg for verbosity when loading configJohn Mulligan1-3/+3
In a future commit we will add support for loading the config file from the `ctdb` command line tool. Prior to this change the config file load func always called D_NOTICE that causes the command to emit new text and thus break all the tests that rely on the specific test output (not to mention something users could notice). This change plumbs a new `verbose` argument into some of the config file loading functions. Generally, all existing functions will have verbose set to true to match the existing behavior. Future callers of this function can set it to false in order to avoid emitting the extra text. Signed-off-by: John Mulligan <jmulligan@redhat.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
2024-07-23ctdb-tests: Use ctdb_read_nodes() in the fake ctdbdMartin Schwenke1-103/+4
Remove unused copy of ctdb_read_nodes_file(). Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Anoop C S <anoopcs@samba.org>
2024-07-23ctdb-protocol: Move definition of CTDB_PORT to protocolMartin Schwenke1-2/+0
Users of CTDB_PORT will all pick up the new definition. Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Anoop C S <anoopcs@samba.org>
2024-07-17ctdb-tests: Correctly handle adding a deleted node at the endMartin Schwenke1-11/+17
The current fake_ctdbd code for reloading the nodes file overruns the allocation when adding a deleted node at the end. This is a very unlikely case, but it might as well work. Check the size of the internal node map when marking a node deleted. Also, update the code that adds a node to correctly set the deleted flag when appropriate. The included test case tests this. Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Guenther Deschner <gd@samba.org> Autobuild-User(master): Günther Deschner <gd@samba.org> Autobuild-Date(master): Wed Jul 17 00:06:53 UTC 2024 on atb-devel-224
2024-06-28ctdb-conf: Move conf.[ch] to conf/ subdirectoryMartin Schwenke1-1/+1
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Guenther Deschner <gd@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org>
2024-04-16ctdb: Remove common/line.[ch]Volker Lendecke1-102/+0
This was an implementation of getline(3), use that instead. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Martin Schwenke <mschwenke@ddn.com>
2024-04-16lib: Give lib/util/util_file.c its own header fileVolker Lendecke1-0/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Martin Schwenke <mschwenke@ddn.com>
2024-03-06ctdb-server: Implement CTDB_CONTROL_START_IPREALLOCATEVinit Agnihotri1-0/+19
Trigger a "startipreallocate" event, but only if in RUNNING runstate. "startipreallocate" is intended to allow an NFS server to be put into grace on all nodes before any locks are released as part of releaseip during failover. If node A is leader and initiates a takeover run then node B may be connected/active but may not have completed startup. In this case, the attempt to put NFS-Ganesha into grace on node B will fail, startipreallocate will fail, and the node will be banned. Signed-off-by: Vinit Agnihotri <vagnihotri@ddn.com> Reviewed-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Volker Lendecke <vl@samba.org>
2024-03-06ctdb-protocol: Add new control CTDB_CONTROL_START_IPREALLOCATEVinit Agnihotri2-1/+12
Signed-off-by: Vinit Agnihotri <vagnihotri@ddn.com> Reviewed-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Volker Lendecke <vl@samba.org>
2024-02-29ctdb-tests: Limit red-black tree test to 5s of random insertsMartin Schwenke1-3/+11
rb_test_001.sh runs for 60s even though rb_tree.c is almost never modified. This generally extends test time by an unreasonable amount of time. Add an optional timeout (in seconds) argument to rb_test, defaulting to 60, and pass 5 from rb_test_001.sh. If anyone ever significantly updates rb_tree.c then they can run rb_test directly with its default 60s timeout... or for as long as they like. Reported-by: Volker Lendecke <vl@samba.org> Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Thu Feb 29 13:20:40 UTC 2024 on atb-devel-224
2024-02-19ctdb-protocol: Add missing push support for new controlsMartin Schwenke2-1/+34
CTDB_CONTROL_TCP_CLIENT_DISCONNECTED and CTDB_CONTROL_TCP_CLIENT_PASSED were added in commits c6602b686b4e50d93272667ef86d3904181fb1ab and 037e8e449deb136ad5ed5e4de05439411b545b6d. They were missing test support for the packet push/pull. While adding the testing (for completeness, before adding another new control) I noticed that the push functionality was absent. This adds that, along with the test support. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15580 Signed-off-by: Martin Schwenke <mschwenke@ddn.com> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Mon Feb 19 10:21:48 UTC 2024 on atb-devel-224
2023-10-10ctdb: Reduce indentation in get_tunable_values()Volker Lendecke1-18/+21
Use an early return tvals; review with "git sh -b". Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2023-10-10ctdb: Fix whitespaceVolker Lendecke1-3/+3
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2023-03-24ctdb:tests: Fix code spellingAndreas Schneider8-13/+13
Best reviewed with: `git show --word-diff` Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Martin Schwenke <mschwenke@ddn.com>
2022-08-01ctdb-common: CID 1507498: Control flow issues (DEADCODE)Martin Schwenke1-0/+11
Fix typo in error checking. While here adjust the bottom of the range, making errno 0 invalid. Add corresponding test cases using an alternative syntax for errno packets (#nnn[;] - trailing ';' is optional). Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Mon Aug 1 09:19:55 UTC 2022 on sn-devel-184
2022-07-28ctdb-tests: Add tests for cluster mutex I/O timeoutMartin Schwenke1-0/+98
Block the locker helper child by taking a lock on the 2nd byte of the lock file. This will cause a ping timeout if the process is blocked for long enough. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Martin Schwenke <martins@samba.org> Autobuild-Date(master): Thu Jul 28 11:10:54 UTC 2022 on sn-devel-184
2022-07-28ctdb-tests: Terminate event loop if lock is no longer heldMartin Schwenke1-1/+1
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-07-28ctdb-tests: Add tests for trivial FD monitoringMartin Schwenke2-0/+776
tmon_ping_test covers complex 2-way interaction between processes using tmon_ping_send(), including via a socketpair(). tmon_test covers the more general functionality of tmon_send() but uses a simpler 1-way harness with wide coverage. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-07-22ctdb-build: Add missing dependency on tallocMartin Schwenke1-0/+1
The include isn't strictly necessary, since it is included via common/reqid.c anyway. However, it is a useful hint. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Fri Jul 22 17:01:00 UTC 2022 on sn-devel-184
2022-07-22ctdb-common: Use POSIX if_nameindex() to check interface existenceMartin Schwenke1-8/+10
This works as an unprivileged user, so avoids unnecessary errors when running in test mode (and not as root): 2022-02-18T12:21:12.436491+11:00 node.0 ctdbd[6958]: ctdb_sys_check_iface_exists: Failed to open raw socket 2022-02-18T12:21:12.436534+11:00 node.0 ctdbd[6958]: ctdb_sys_check_iface_exists: Failed to open raw socket 2022-02-18T12:21:12.436557+11:00 node.0 ctdbd[6958]: ctdb_sys_check_iface_exists: Failed to open raw socket 2022-02-18T12:21:12.436577+11:00 node.0 ctdbd[6958]: ctdb_sys_check_iface_exists: Failed to open raw socket The corresponding porting test would now become pointless because it would just confirm that "fake" does not exist. Attempt to make it useful by using a less likely name than "fake" and attempting to detect the loopback interface. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-06-28ctdb-tests: Add runstate handling to fake ctdbdVinit Agnihotri1-1/+42
Signed-off-by: Vinit Agnihotri <vagnihotri@ddn.com> Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-06-28ctdb-tests: Return error on empty fake ctdbd configuration blocksMartin Schwenke1-4/+23
These would be unintended errors. The block should be omitted to keep the default value. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-05-03ctdb-tests: Add backtrace on abort to some testsMartin Schwenke2-0/+8
These are easier to debug with a backtrace. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Tue May 3 10:13:23 UTC 2022 on sn-devel-184
2022-05-03ctdb-tests: Provide a method to dump the stack on abortMartin Schwenke2-0/+62
Some tests make generous use of assert() and it can be difficult to guess the cause of failures without resorting to GDB. This provides some help. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-04-06ctdb-tests: Add unit tests for tunables codeMartin Schwenke1-0/+71
This aims to test ctdb_tunable_load_file() but also exercises ctdb_tunable_names() and ctdb_tunable_get_value(). ctdb_tunable_set_value() is indirectly exercised via ctdb_tunable_load_file(). Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-02-23ctdb-tests: Fix missing #include for sigaction(2)Martin Schwenke1-0/+1
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-02-23ctdb-tests: Dump a stack trace on abortMartin Schwenke1-0/+3
Debugging a test failure here without GDB is not possible. Dumping a stack trace gives a good hint. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-02-14ctdb-tests: Iterate protocol tests internallyMartin Schwenke5-44/+32
Instead of repeatedly running a test binary. Run time for these tests reduces from ~90s to ~75s. When run under valgrind, the run time for protocol_test_001.sh reduces from ~390s to <1s. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Mon Feb 14 04:32:29 UTC 2022 on sn-devel-184
2022-02-14ctdb-tests: Add iteration support for protocol testsMartin Schwenke2-0/+75
The current method of repeatedly running a binary has huge overhead, especially with valgrind. protocol_test_iterate_tag() allows output that is usually used for hinting where a test failure occurred to be replaced with a tag stored in a buffer, which is printed on test failure. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-01-17ctdb-protocol: Drop marshalling for {GET,SET}_RECMASTER controlsMartin Schwenke1-26/+0
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-01-17ctdb-daemon: Drop implementation of {GET,SET}_RECMASTER controlsMartin Schwenke1-21/+0
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-01-17ctdb-tests: Add leader broadcasts to fake_ctdbdMartin Schwenke1-0/+49
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-01-17ctdb-tests: Implement srvid_handler for dispatching messagesAmitay Isaacs1-1/+67
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
2022-01-17ctdb-protocol: Add CTDB_SRVID_LEADERMartin Schwenke3-0/+4
CTDB_SRVID_LEADER will be regularly broadcast to all connected nodes by the leader. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-01-17ctdb-common: Separate sock_daemon's SIGHUP and SIGUSR1 handlingMartin Schwenke1-2/+98
SIGHUP is for reopening logs, SIGUSR1 is for reconfigure. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2022-01-13ctdb-protocol: Print IPv6 sockets with RFC5952 "[2001:db8::1]:80" notationMartin Schwenke1-15/+15
RFC5952 says the existing style is not recommended and the [] style should be employed. There are more optimised ways of adding the square brackets but they tend to be uglier. Parsing IPv6 sockets without [] is now tested indirectly by parsing examples in both styles and comparing the results. Signed-off-by: Martin Schwenke <martin@meltin.net> Signed-off-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Thu Jan 13 17:02:21 UTC 2022 on sn-devel-184
2022-01-13ctdb-tests: Add extra IPv6 socket parsing testsMartin Schwenke1-0/+19
Add tests to confirm that square brackets are handled and that IPv4-mapped IPv6 addresses are parsed as expected. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
2021-09-09ctdb_daemon: Implement controls DISABLE_NODE/ENABLE_NODEMartin Schwenke1-0/+54
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14784 Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2021-09-09ctdb-protocol: Add marshalling for controls DISABLE_NODE/ENABLE_NODEMartin Schwenke2-1/+25
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14784 Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
2021-05-18ctdb: Fix a crash in run_proc_signal_handler()Volker Lendecke1-1/+1
If a script times out the caller can talloc_free() the script_list output of run_event_recv, which talloc_free's proc->output from run_proc.c as well. If the script generates further output after the timeout and then exits after a while, the SIGCHLD handler in the eventd tries to read into proc->output, which was already free'ed. Fix this by not doing just a talloc_steal but a talloc_move. This way proc_read_handler() called from run_proc_signal_handler() does not try to realloc the stale reference to proc->output but gets a NULL reference. I don't really know how to do a knownfail in ctdb, so this commit actually activates catching the signal by waiting long enough for 22.bar to exit and generate the SIGCHLD. Bug: https://bugzilla.samba.org/show_bug.cgi?id=14475 Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2021-05-18ctdb: Wait for SIGCHLD if script timed outVolker Lendecke1-0/+22
Bug: https://bugzilla.samba.org/show_bug.cgi?id=14475 Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2021-05-18ctdb: Introduce a helper variable in run_event_test.cVolker Lendecke1-2/+2
Bug: https://bugzilla.samba.org/show_bug.cgi?id=14475 Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>