summaryrefslogtreecommitdiff
path: root/lib/util/tests
AgeCommit message (Collapse)AuthorFilesLines
2023-01-10lib: Remove idtree from samba_util.hVolker Lendecke1-0/+1
No need to recompile the world when only a few files need this. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2022-12-01util: add stable sort functionsDouglas Bagnall1-0/+317
Sometimes (e.g. in lzxpress Huffman encoding, and in some of our tests: c.f. https://lists.samba.org/archive/samba-technical/2018-March/126010.html) we want a stable sort algorithm (meaning one that retains the previous order of items that compare equal). The GNU libc qsort() is *usually* stable, in that it first tries to use a mergesort but reverts to quicksort if the necessary allocations fail. That has led Samba developers to unthinkingly assume qsort() is stable which is not the case on many platforms, and might not always be on GNU/Linuxes either. This adds four functions. stable_sort() sorts an array, and requires an auxiliary working array of the same size. stable_sort_talloc() takes a talloc context so it ca create a working array and call stable_sort(). stable_sort_r() takes an opaque context blob that gets passed to the compare function, like qsort_r() and ldb_qsort(). And stable_sort_talloc_r() rounds out the quadrant. These are LGPL so that the can be used in ldb, which has problems with unstable sort. The tests are borrowed and extended from test_ldb_qsort.c. When sorting non-trivial structs this is roughly as fast as GNU qsort, but GNU qsort has optimisations for small items, using direct assignments of rather than memcpy where the size allows the item to be cast as some kind of int. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-06-17util/debug: share classname table with testsDouglas Bagnall1-63/+7
The executables generated from lib/util/tests/test_logging.c are used by the samba.tests.logfiles tests to test logging with various smb.confs that assign classes to various files at different levels etc. Previously test_logging.c had its own version of the table; now it shares one with debug.c We put the table in a sub-directory (lib/util/debug-classes/), because adding local_include=True to the wscript_build stanza causes the compiler confusion between <time.h> and lib/util/time.h. Note: there are still two other lists of the class names, in python/samba/tests/logfiles.py and docs-xml/smbdotconf/logging/loglevel.xml. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-17tests: rename logging test sourceDouglas Bagnall1-0/+0
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-17tests: adapt logging test for s3.Douglas Bagnall1-3/+8
There is one knownfail, where it seems an smb.conf like log file = foo log level = 2 tdb:2@baa ldb:3 will send the ldb logs to 'baa' instead of 'foo' (i.e., the last opened log file, rather than the default log file). Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-17tests: test source4 cmdline/smb.conf log levelDouglas Bagnall1-0/+197
The 'log level' line in smb.conf allows messages from different log classes to be sent to different places, but we have not tested that this works. Now we do, somewhat. The test involves running a special binary based on a stripped down source4/samba/server.c that just starts up, parses the command line and a given smb.conf, then logs messages from multiple classes and exits. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-09lib/util: Add test of mem_equal_const_time()Joseph Sutton1-0/+22
Ensure that it gives the correct results for comparing two memory regions. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-09lib/util: Add test of data_blob_equal_const_time()Joseph Sutton1-0/+47
Ensure that it gives the correct results for comparing two data blobs. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-05-02lib/util: add tests for data_blob_append() with the resulting blob length=0Stefan Metzmacher1-0/+26
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15050 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-10-28lib: add a test for null_nttime(NTTIME_THAW)Ralph Boehme1-0/+1
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14127 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-10-28lib: update null_nttime() of -1: -1 is NTTIME_FREEZERalph Boehme1-1/+1
NTTIME_FREEZE is not a nil sentinel value, instead it implies special, yet unimplemented semantics. Callers must deal with those values specifically and null_nttime() must not lie about their nature. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14127 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-10-28lib: use NTTIME_FREEZE in a null_nttime() testRalph Boehme1-1/+1
No change in behaviour. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14127 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-10-28lib: fix null_nttime() testsRalph Boehme1-1/+1
The test was checking -1 twice: torture_assert(tctx, null_nttime(-1), "-1"); torture_assert(tctx, null_nttime(-1), "-1"); The first line was likely supposed to test the value "0". BUG: https://bugzilla.samba.org/show_bug.cgi?id=14127 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-10-08lib: add sys_block_align[_truncate]()Ralph Boehme1-0/+68
This implements MS-FSA algorithms BlockAlign() and BlockAlignTruncate(). Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-06-30lib: add sys_io_ranges_overlap()Ralph Boehme1-0/+110
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12033 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-06-18torture: talloc_string_sub tests for utf-8 brevityDouglas Bagnall1-0/+58
If we allow overly long UTF-8 sequences (in the tests, encoding '\0' as 2, 3, or 4 bytes), it might be possible for bad strings to slip through. We fail. But wait for the next commit. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14684 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-05-11lib: Add str_list_add_printf()Volker Lendecke1-2/+27
Build up execv argument lists Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-04-16lib/util: fix timespec normalizationPhilipp Gesang1-0/+53
When fixing up timespec structs, negative values for the ns part should be taken into account. Also, the range for a valid ns part is [0, 1000000000), not [0, 1000000000]. Signed-off-by: Philipp Gesang <philipp.gesang@intra2net.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-03-10lib/util: Replace buggy string_sub_talloc() with talloc_string_sub() in lib/utilAndrew Bartlett1-7/+7
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14658 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Wed Mar 10 08:06:25 UTC 2021 on sn-devel-184
2021-03-09lib: Align integer typesVolker Lendecke1-2/+3
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-02-03lib:util: Add cache oversize test for memcacheAndreas Schneider1-0/+39
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14625 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2021-02-03lib:util: Add basic memcache unit testAndreas Schneider1-0/+122
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14625 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2021-01-06lib:util: Add directory_create_or_exists_recursive()Andreas Schneider1-5/+111
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14601 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2020-11-13s4-torture: test file_line_parse as wellGünther Deschner1-0/+31
Guenther Signed-off-by: Guenther Deschner <gd@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Günther Deschner <gd@samba.org> Autobuild-Date(master): Fri Nov 13 17:47:33 UTC 2020 on sn-devel-184
2020-08-24lib/util: Move cleanup for unit test in teardown functionChristof Schmitt1-3/+9
Where to call rmdir does not matter, but that should avoid the TOCTOU warning from CID 1466194 and might be slightly cleaner. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Mon Aug 24 03:10:09 UTC 2020 on sn-devel-184
2020-08-24lib/util: Remove wrong return statement in unit testChristof Schmitt1-2/+0
Fixes CID 1466195 Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-08-24lib/util: Fix cleanup in unit testChristof Schmitt1-1/+1
Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-08-16util: Add cmocka unit test for directory_create_or_existsChristof Schmitt1-0/+234
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14166 Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Sun Aug 16 07:06:59 UTC 2020 on sn-devel-184
2020-08-03lib: relicense smb_strtoul(l) under LGPLv3Ralph Boehme1-0/+1
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Mon Aug 3 22:21:04 UTC 2020 on sn-devel-184
2020-06-29util: fix build on AIX by fixing the order of replace.h includeBjoern Jacke1-1/+1
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14422 Signed-off-by: Bjoern Jacke <bjacke@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Björn Jacke <bjacke@samba.org> Autobuild-Date(master): Mon Jun 29 18:19:04 UTC 2020 on sn-devel-184
2020-05-15lib:util: Add test for path_expand_tilde()Andreas Schneider1-0/+127
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14370 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2020-05-04CVE-2020-10704: lib util asn1: Add ASN.1 max tree depthGary Lockyer1-1/+1
Add maximum parse tree depth to the call to asn1_init, which will be used to limit the depth of the ASN.1 parse tree. Credit to OSS-Fuzz REF: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20454 BUG: https://bugzilla.samba.org/show_bug.cgi?id=14334 Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-02-21lib:util: Add test to verify old and new macros are the sameAndreas Schneider1-0/+273
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-02-21lib:util: Add bytearray.hAndreas Schneider1-0/+435
This is an implementation which doesn't have undefined behavior problems. It casts correctly that calculations are don in the correct integer space. Also the naming is less confusing than what we have in byteorder.h. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-09-01Spelling fixes s/avaiable/available/Mathieu Parent1-1/+1
Signed-off-by: Mathieu Parent <math.parent@gmail.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-09-01Spelling fixes s/hierachy/hierarchy/Mathieu Parent1-1/+1
Signed-off-by: Mathieu Parent <math.parent@gmail.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-08tfork: Free memory in torture test to satisfy sanitizerSwen Schillig1-0/+3
Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Matthias Dieter Wallnöfer <mdw@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Thu Aug 8 11:33:32 UTC 2019 on sn-devel-184
2019-08-08util: Free memory in genrand torture test to satisfy sanitizerSwen Schillig1-0/+2
Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Matthias Dieter Wallnöfer <mdw@samba.org>
2019-06-30tests-util: Adding test to verify "allow no conversion" flagSwen Schillig1-0/+33
The internal string conversion routines smb_strtoul(l) return an error if the provided string could not be converted to an integer. This can be the case if the string is empty or if it starts with non-numeric characters which cannot be converted. The standard C library, however, does allow this and simply returns 0 as the converted value. If this behaviour is wanted, it can be enabled by using the "SMB_STR_ALLOW_NO_CONVERSION" flag. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Sun Jun 30 12:47:24 UTC 2019 on sn-devel-184
2019-06-30tests-util: Adding test to verify "full-string-conversion" flagSwen Schillig1-0/+28
The standard string to integer conversion routines stop at the first character which cannot be converted to a number. However, if such a character is found, it is not considered an error. With the flag "SMB_STR_FULL_STR_CONV" enabled, an error will be returned if the string could not be converted entirely. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2019-06-30tests-util: Adding test to verify "allow-negative" flagSwen Schillig1-0/+38
The standard string to integer conversion routines allow strings with a leading "-" to indicate a negative number. However, the returned value is always an unsigned value representing the bit-pattern of this negative value. Typically, this behaviour is NOT wanted and therefore the standard behavior of the internal smb_strtoul(l) return an erros in such situations. It can be enabled though by using the flag SMB_STR_ALLOW_NEGATIVE. This test verifies the correct processing. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2019-06-30lib: Update all consumers of strtoul_err(), strtoull_err() to new APISwen Schillig1-36/+36
Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2019-06-30tests-util: Adding test to verify "no-conversion" detectionSwen Schillig1-0/+28
The standard string to integer conversion routines return zero if a string was to be converted which did not reflect a number. It is not flag'ed as an error. The wrapper functions strtoul_err() and strtoull_err() are expected to exactly do this. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2019-06-30tests-util: Adding test to verify negative "number" detectionSwen Schillig1-0/+37
Verify that a string representing a negative number is throwing an error. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2019-06-30tests-util: Adding strtoul(l)_err() test leaving errno untouchedSwen Schillig1-0/+29
The wrapper functions strtoul_err() and strtoull_err() trigger other functions/routines which modify errno. However, callers of those wrapper functions expect errno to be unchanged. This test verifies the expectation. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2019-06-04lib/util/tests: clang fix Value stored to 'lines' is never read warningNoel Power1-1/+1
Fixes lib/util/tests/file.c:153:2: warning: Value stored to 'lines' is never read <--[clang] Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Andreas Schneider <asn@samba.org>
2019-05-19Fix uClibc build on 64bit platforms by including stdint.hFabrice Fontaine1-0/+1
Fixes an error detected by buildroot autobuilders: http://autobuild.buildroot.net/results/573/573e2268e205e10d1352fa81122d8f225fdb4575/build-end.log /home/rclinux/rc-buildroot-test/scripts/instance-1/output/host/mips64el-buildroot-linux-uclibc/sysroot/usr/include/stdint.h:122:27: error: conflicting types for 'uintptr_t' typedef unsigned long int uintptr_t; ^ In file included from ../lib/ldb/tests/ldb_msg.c:17:0: ../third_party/cmocka/cmocka.h:126:28: note: previous declaration of 'uintptr_t' was here typedef unsigned int uintptr_t; The define __WORDSIZE is missing when cmocka.h decides how to define uintptr_t, this patch includes stdint.h when needed. Patch sent upstream: https://lists.samba.org/archive/samba-technical/2018-January/125306.html [updated for samba-4.8.4, v2 sent upstream https://lists.samba.org/archive/samba-technical/2018-August/129732.html, updated for samba-4.9.1] Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de> [Retrieved from: https://git.buildroot.net/buildroot/tree/package/samba4/0003-Fix-uClibc-build-on-64bit-platforms-by-including-std.patch] Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Reviewed-by: Ralph Böhme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2019-05-17lib:util: Add a test for byteorder.hAndreas Schneider1-0/+435
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Fri May 17 20:44:36 UTC 2019 on sn-devel-184
2019-05-16lib:util: Fix tfork return value if sigprocmask failsRikard Falkeborn1-1/+1
Returning a non-zero value from a function with bool as return value is the same as returning true. Change the return value to false if sigprocmask or pthread_sigmask fails to indicate failure. Detected with the help of cppcheck. Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Thu May 16 19:08:29 UTC 2019 on sn-devel-184
2019-04-03lib:util: Add test for talloc_keep_secret()Andreas Schneider1-0/+94
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlet <abartlet@samba.org>