summaryrefslogtreecommitdiff
path: root/lib/util/tests
AgeCommit message (Collapse)AuthorFilesLines
2019-01-28lib:util: Use C99 initializer in tfork testAndreas Schneider1-2/+12
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2018-12-19lib/util: Count a trailing line that doesn't end in a newlineMartin Schwenke1-0/+152
If the final line of a file does not contain a newline then it isn't included in the line count. Change i to point to the next slot in the array instead of the current one. This means that that the current line won't be thrown away if no newline is seen. Without changing i to unsigned int, the -O3 --picky -developer build fails with: [ 745/4136] Compiling lib/util/util_file.c ==> /builds/samba-team/devel/samba/samba-o3.stderr <== ../../lib/util/util_file.c: In function ‘file_lines_parse’: ../../lib/util/util_file.c:251:8: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow] while (i > 0 && ret[i-1][0] == 0) { ^ cc1: all warnings being treated as errors BUG: https://bugzilla.samba.org/show_bug.cgi?id=13717 Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Wed Dec 19 08:08:28 CET 2018 on sn-devel-144
2018-11-28tfork: add a README how to run test torture test under valgrindRalph Boehme1-0/+22
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Wed Nov 28 15:57:43 CET 2018 on sn-devel-144
2018-11-28tfork: add a suppresssions file for drdRalph Boehme1-0/+14
drd reports: initialized twice: cond 0x514f188 at 0x4C3A399: pthread_cond_init_intercept (drd_pthread_intercepts.c:1022) by 0x4C3A399: pthread_cond_init@* (drd_pthread_intercepts.c:1030) by 0x50F3FF3: tfork_atfork_child (tfork.c:250) by 0x9A4B95D: fork (fork.c:204) by 0x50F4834: tfork_start_waiter_and_worker (tfork.c:581) by 0x50F4CDB: tfork_create (tfork.c:780) by 0x2F7469: tfork_thread (tfork.c:431) by 0x4C358F8: vgDrd_thread_wrapper (drd_pthread_intercepts.c:444) by 0x8D46593: start_thread (pthread_create.c:463) by 0x9A7EE6E: clone (clone.S:95) cond 0x514f188 was first observed at: at 0x4C3A399: pthread_cond_init_intercept (drd_pthread_intercepts.c:1022) by 0x4C3A399: pthread_cond_init@* (drd_pthread_intercepts.c:1030) by 0x50F413A: tfork_global_initialize (tfork.c:287) by 0x8D4DEA6: __pthread_once_slow (pthread_once.c:116) by 0x4C377FD: pthread_once_intercept (drd_pthread_intercepts.c:800) by 0x4C377FD: pthread_once (drd_pthread_intercepts.c:806) by 0x50F4C0E: tfork_create (tfork.c:743) by 0x2F7469: tfork_thread (tfork.c:431) by 0x4C358F8: vgDrd_thread_wrapper (drd_pthread_intercepts.c:444) by 0x8D46593: start_thread (pthread_create.c:463) by 0x9A7EE6E: clone (clone.S:95) This is intentional, the reinit is in a child process. Cf the comment in tfork.c. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2018-11-28tfork: add a suppresssions file for helgrindRalph Boehme1-0/+32
tfork_atexit_unknown[1|2]: No idea what triggers this, definitely not tfork itself. tfork_pthread_get_specific: Helgrind reports: Possible data race during read of size 4 at 0x5141304 by thread #3 Locks held: none at 0x50E602E: tfork_global_get (tfork.c:301) by 0x50E69B1: tfork_create (tfork.c:737) by 0x2F7419: tfork_thread (tfork.c:431) by 0x4C35AC5: mythread_wrapper (hg_intercepts.c:389) by 0x8D38593: start_thread (pthread_create.c:463) by 0x9A70E6E: clone (clone.S:95) This conflicts with a previous write of size 4 by thread #2 Locks held: none at 0x8D3F7B7: pthread_key_create (pthread_key_create.c:41) by 0x50E5F79: tfork_global_initialize (tfork.c:280) by 0x8D3FEA6: __pthread_once_slow (pthread_once.c:116) by 0x50E6999: tfork_create (tfork.c:728) by 0x2F7419: tfork_thread (tfork.c:431) by 0x4C35AC5: mythread_wrapper (hg_intercepts.c:389) by 0x8D38593: start_thread (pthread_create.c:463) by 0x9A70E6E: clone (clone.S:95) Location 0x5141304 is 0 bytes inside global var "tfork_global_key" declared at tfork.c:122 This is nonsense, tfork_global_get() calls pthread_getspecific, so we're looking at the pthread_key_create()/pthread_[g|s]etspecific() API here which works with threads by design. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2018-11-28tfork/test: ensure all threads start with SIGCHLD unblockedRalph Boehme1-0/+17
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2018-09-15torture: Remove unnecesssary #include <fcntl.h>Christof Schmitt1-1/+0
This is now provided through system/filesys.h. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-08-31lib: Fix the build on FreeBSDVolker Lendecke1-0/+1
FreeBSD needs to explicitly #include <unistd.h> for geteuid() and close() Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Fri Aug 31 18:42:31 CEST 2018 on sn-devel-144
2018-08-30torture: Add test for directory_create_or_existChristof Schmitt1-0/+60
Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Christof Schmitt <cs@samba.org> Autobuild-Date(master): Thu Aug 30 21:19:31 CEST 2018 on sn-devel-144
2018-05-17lib:util: Fix parameter aliasing in tfork testAndreas Schneider1-5/+2
../lib/util/tests/tfork.c:483:24: error: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Werror=restrict] ret = pthread_create(&threads[i], ^~~~~~~~~~~ ../lib/util/tests/tfork.c:486:10: (void *)&threads[i]); ~~~~~~~~~~~~~~~~~~~ BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Guenther Deschner <gd@samba.org>
2018-04-03lib/util: remove unused '#include <sys/syscall.h>' from tests/tfork.cStefan Metzmacher1-1/+0
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13342 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-03-02tests: Add basic ms_fnmatch unit testDavid Disseldorp1-0/+113
Pair-Programmed-With: Andreas Schneider <asn@samba.org> Signed-off-by: David Disseldorp <ddiss@samba.org> Signed-off-by: Andreas Schneider <asn@samba.org>
2018-02-22util/tests: add rfc1738 cmocka testsDouglas Bagnall1-0/+411
These don't pass yet. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2017-09-16tests util/tfork: Tests for status and event fdGary Lockyer1-0/+251
Add tests to ensure that: - The event_fd becomes readable once the worker process has terminated - That the event_fd is not closed by the tfork code. - If this is done in tevent code and the event fde has not been freed, "Bad talloc magic value - " errors can result. - That the status call does not block if the parent process launches more than one child process. - The status file descriptor for a child is passed to the subsequent children. These processes hold the FD open, so that closing the fd does not make the read end go readable, and the process calling status blocks. Bug: https://bugzilla.samba.org/show_bug.cgi?id=13037 Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2017-07-03lib/util: add more tfork testsRalph Boehme1-0/+438
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2017-07-03lib/util: adjust loglevel in tfork test with samba_runcmd_send()Ralph Boehme1-1/+1
No change in behaviour, this just ensures stdout and stderror are logged with log level 0. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2017-07-03lib/util: enhanced tfork()Ralph Boehme1-31/+32
This function is a solution to the problem of fork() requiring special preperations in the caller to handle SIGCHLD signals and to reap the child by wait()ing for it. Instead, tfork provides a pollable file descriptor. The caller gets the file descriptor by calling tfork_event_fd() on the handle returned from tfork_create() and the caller can then get the status of the child with a call to tfork_status(). tfork avoids raising SIGCHLD signals in the caller by installing a temporary SIGCHLD handler from inside tfork_create() and tfork_status(). The termination signal of other child processes not created with tfork() is forwarded to the existing signal handler if any. There's one thing this thing can't protect us against and that is if a process installs a SIGCHLD handler from one thread while another thread is running inside tfork_create() or tfork_status() and the signal handler doesn't forward signals for exitted childs it didn't fork, ie our childs. Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Ralph Boehme <slow@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org>
2017-05-02lib: FreeBSD needs sys/wait.h for WIFEXITEDVolker Lendecke1-0/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Tue May 2 21:14:22 CEST 2017 on sn-devel-144
2017-04-20lib/util: add a test for samba_runcmd_send()Ralph Boehme1-0/+36
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2017-04-20lib/util: add a test for tfork()Ralph Boehme1-0/+102
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2017-03-29lib/util: Add functions to escape log lines but not break all non-asciiGary Lockyer1-0/+90
We do not want to turn every non-ascii username into a pile of hex, so we instead focus on avoding newline insertion attacks and other low control chars Pair-programmed-by: Andrew Bartlett <abartlet@samba.org> Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2017-02-09binsearch: make BINARY_ARRAY_SEARCH_GTE compare against a pointerDouglas Bagnall1-2/+7
This is in preparation for improvements in our handling of linked attributes where we make changes to the pointer in the process of comparing it (for caching purposes). Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2016-06-20torture: Add tests for trim_string()Martin Schwenke1-0/+376
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Ralph Boehme <slow@samba.org>
2016-03-09util/tests: add test for BINARY_ARRAY_SEARCH_V macroDouglas Bagnall1-0/+24
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2016-03-09util/binsearch: macro for greater than or equal searchDouglas Bagnall1-0/+144
Sometimes you want to find the place where an item would be in a sorted list, whether or not it is actually there. The BINARY_ARRAY_SEARCH_GTE macro takes an extra 'next' pointer argument over the other binsearch macros. This will end up pointing to the next element in the case where there is not an exact match, or NULL when there is. That is, searching the list { 2, 3, 4, 4, 9} with a standard integer compare should give the following results: search term *result *next 1 - 2 3 3 - 4 4 [1] - 7 - 9 9 9 - 10 - - [2] Notes [1] There are two fours, but you will always get the first one. [2] The both NULL case means the search term is beyond the last list item. You can safely use the same pointer for both 'result' and 'next', if you don't care to distinguish between the 'greater-than' and 'equals' cases. There is a torture test for this. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
2016-03-01lib/util: Add strv_util.[ch] containing new function strv_split()Martin Schwenke1-0/+149
strv_split() adds to a strv by splitting a string on separators. Tests included. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
2016-02-29lib/util: Add tests for strv_addn()Martin Schwenke1-2/+34
Also some other minor test cleanups. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Mon Feb 29 15:18:17 CET 2016 on sn-devel-144
2016-02-26lib/util: Add tests for strvMartin Schwenke1-0/+169
These are blackbox tests against most of the API. It would be possible to write tests that check the internals of the strv are as expected but that probably doesn't add much value. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Jeremy Allison <jra@samba.org>
2016-02-06dlist: remove unneeded type argument from DLIST_CONCATENATE()Michael Adam1-1/+1
Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2016-02-06dlist: remove unneeded argument from DLIST_DEMOTE()Michael Adam1-1/+1
Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2016-02-06dlist: remove unneeded type argument from DLIST_ADD_END()Michael Adam1-2/+2
Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2016-01-06asn1: Remove a reference to asn1_data internalsVolker Lendecke1-2/+4
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-10-13Rely on /dev/urandomVolker Lendecke1-12/+0
This removes quite a bit of code. All reasonable systems have /dev/urandom these days. Linux, Solaris and the BSDs do. In case we find a system without /dev/urandom, we will have to go hunting in other libraries. The main reason for this is speed: On Ubuntu 14.04 doing direct reads from /dev/urandom is 2-3 times faster than our md4 based code. On virtualized FreeBSD 10 the difference is even larger. My first approach was to use fopen/fread. It was even faster, but less than twice as fast. So I thought we could save the additional complexity when having to deal with throwing away buffers when forking and the additional memory footprint per process. With this simple generate_random_buffer it will be easier to adapt new syscalls to get randomness. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Tue Oct 13 04:25:39 CEST 2015 on sn-devel-104
2015-10-13lib: Add a little tool to perftest generate_random_buffer()Volker Lendecke1-0/+39
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2015-08-21lib: Remove unused parmlist codeVolker Lendecke1-107/+0
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2015-04-21lib: Fix a few CIDs for Resource LeakVolker Lendecke1-5/+10
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
2014-11-14lib/util/tests: avoid some compiler warningsStefan Metzmacher2-25/+50
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2014-09-26lib: util: asn1 tests. Check every asn1 return.Jeremy Allison1-5/+9
Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
2014-04-02lib/util/tests: add missing #include "torture/local/proto.h"Stefan Metzmacher10-0/+10
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2013-02-04lib/util: improve check_password_quality() to handle utf8Stefan Metzmacher1-1/+4
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
2011-06-11s3-param Remove 'time offset' from smb.confAndrew Bartlett1-18/+0
This strange parameter is apparently very rarely used, and it seems to me that on modern networks, if clients don't have correct clocks and DST offsets, that many other things (Kerberos) start to fail pretty quickly, and time and DST tables tend to be internet delivered anyway. Autobuild-User: Andrew Bartlett <abartlet@samba.org> Autobuild-Date: Sat Jun 11 03:54:45 CEST 2011 on sn-devel-104
2011-05-24lib/util Add Volker's asn1_Integer test into code that runs in 'make test'Andrew Bartlett1-0/+94
The comfychair test harness isn't hooked up, and with the current infrustructure C code is better tested directly here. Andrew Bartlett
2011-05-04Fix simple uses of safe_strcpy -> strlcpy. Easy ones where we just remove -1.Jeremy Allison1-5/+5
2011-05-03s4: fix arguments to safe_strcpy()Andrew Bartlett1-5/+5
Found by the s3-derivied safe_strcpy() macro. Andrew Bartlett
2011-01-20lib/util: add tests for anonymous_shared_allocate/free()Stefan Metzmacher1-0/+70
metze Autobuild-User: Stefan Metzmacher <metze@samba.org> Autobuild-Date: Thu Jan 20 06:25:03 CET 2011 on sn-devel-104
2010-12-21lib/util/asn1.c - remove the "const" specifier from OIDMatthias Dieter Wallnöfer1-2/+2
There is no reason to have it "const" since it's an allocated thing.
2010-12-11s4-smbtorture: Make test names lowercase and dot-separated.Jelmer Vernooij10-12/+11
This is consistent with the test names used by selftest, should make the names less confusing and easier to integrate with other tools. Autobuild-User: Jelmer Vernooij <jelmer@samba.org> Autobuild-Date: Sat Dec 11 04:16:13 CET 2010 on sn-devel-104
2010-12-06Revert "lib/util:tests/time.c - "test_timestring" - fix it on Solaris"Matthias Dieter Wallnöfer1-5/+2
This reverts commit 654e0102ddb0acaaf45fb55c15818722235fcc9f. This should better be handled by the replace library. Autobuild-User: Matthias Dieter Wallnöfer <mdw@samba.org> Autobuild-Date: Mon Dec 6 12:17:31 CET 2010 on sn-devel-104
2010-12-05lib/util:tests/time.c - "test_timestring" - fix it on SolarisMatthias Dieter Wallnöfer1-3/+5
Solaris returns "Thu Jan 01" and not "Thu Jan 1" - therefore proof for both. Autobuild-User: Matthias Dieter Wallnöfer <mdw@samba.org> Autobuild-Date: Sun Dec 5 23:09:13 CET 2010 on sn-devel-104
2010-10-22asn1_tests: Implement negative unit-tests for ber_write_OID_String()Kamen Mazdrashki1-0/+22