tests: Introduce afstest.pm Create a perl module for some generic common code for our tests written in perl: afstest.pm. With this commit, the module just contains a couple of functions to calculate paths in our src and obj trees (src_path(), obj_path()), analogous to afstest_src_path and afstest_obj_path in our C helper library, libafstest_common.la. Convert all existing perl test code that uses C_TAP_SOURCE/C_TAP_BUILD to use these new functions. Change-Id: I5e4d45e3d2d59449bbfc426476cb29b710c73bc1 Reviewed-on: https://gerrit.openafs.org/14800 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Remove check/test/tests subdir targets Since commit a62de618 (Build util tests properly with make check), running 'make check' in tests/ also runs 'make check' in each of the tests subdirectories, which builds the tests in that dir. (And the same goes for 'make test' and 'make tests'.) This does ensure that the tests are built before we run them, but it's a bit strange to build the tests under 'make check', a target that usually runs tests. We do this in the top-level tests dir to make sure that the tests are built, but this purpose is served by the existing 'make all' target. So to reduce some duplication of logic, and reduce the number of targets the subdirs need to implement, just have 'make check' depend on 'make all', so we know the tests are built when we go to run them. Change-Id: I2fcbe88daeeae94cd7ef7a4a8326c4b56fadee5a Reviewed-on: https://gerrit.openafs.org/14636 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Introduce libafstest_common Currently, a few tests use the code in tests/common/ by linking individual object files in there in addition to the test code (e.g. linking ../common/config.o along with superuser-t.o). This convention makes it very obnoxious to move code around in tests/common/, since any users need to update their link lines. It also makes it difficult for code in tests/common/ to make use of functions in other tests/common/ files. To fix this, just build all of the objects in tests/common/ into a convenience library, called libafstest_common, and link the relevant tests against that. Link a few requisite libraries (roken, rfc3961) in libafstest_common, so each individual test doesn't need to link against them. Also link the TAP library itself in libafstest_common, so tests don't have to explicitly link against it separately. To do this, convert it into a libtool library, libafstest_tap.la. Change-Id: I9c031c164efee20201336edcbfaff429e1d231b7 Reviewed-on: https://gerrit.openafs.org/14318 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Introduce 'make check TESTS=test/name' Currently 'make check' always runs all tests. We can run individual tests manually, but doing so is a bit cumbersome to do under the same environment as 'make check', since doing so means running something like this: $ MAKECHECK=1 $(abs_top_srcdir)/tests/libwrap @TOP_OBJDIR@/lib \ ./runtests opr/fmt util/ktime To make it easier to run single tests introduce a way of calling 'make check' like this: $ make check TESTS='opr/fmt util/ktime' Which will run the same commands as 'make check', but will run runtests with only the specified tests, instead of running the default list. Some makefiles currently use a "TESTS" or "tests" variable to list their test binaries; rename them all to "BINS" to avoid conflicting with this new use for "TESTS" and to make our makefiles a little more consistent. Change-Id: I427f83be0d4571794644a97123bcd1f32427bd05 Reviewed-on: https://gerrit.openafs.org/14317 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Accommodate c-tap-harness 4.7 The SOURCE and BUILD environment variables have been changed to C_TAP_SOURCE and C_TAP_BUILD in the new version of c-tap-harness. The runtests command syntax has changed as well. Convert all of the old SOURCE and BUILD environment variables to the new C_TAP_SOURCE and C_TAP_BUILD names. Add the required -l command line option to specify the test list. Add the new runtests -v option to run the tests in verbose mode to make it easier to see which tests failed. Change-Id: I209a6dc13d6cd1507519234fce1564fc4641e70b Reviewed-on: https://gerrit.openafs.org/14295 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Skip SIGBUS test on FreeBSD Currently, 'softsig-helper -buserror' causes a SIGBUS on most platforms, but can result in SIGSEGV on FreeBSD by default (at least on 11.3-RELEASE). Skip the test on FreeBSD, until we can provide a more reliable way to generate SIGBUS. Note that when the sysctl machdep.prot_fault_translation is set to 1, 'softsig-helper -buserror' generates a SIGBUS instead of SIGSEGV, suggesting that generating a SIGBUS here is the old 'compat' behavior. When machdep.prot_fault_translation is 0 (the default), the code path in the FreeBSD kernel that dictates whether to send a SIGBUS or SIGSEGV in this situation depends on some autodetection heuristics, and so may produce different results depending on FreeBSD releases or even compiler settings (due to detection of ABI based on some ELF notes in the relevant binary). For some details on this sysctl, see <https://www.freebsd.org/news/status/report-2019-07-2019-09.html#Signals-delivered-on-unhandled-Page-Faults> or the FreeBSD source code. In 11.3-RELEASE, the decision to issue a SIGBUS or SIGSEGV can be found around sys/amd64/amd64/trap.c:355. Change-Id: Ib75b43cc12302532ee87a3744fc364424f2a3ca6 Reviewed-on: https://gerrit.openafs.org/14145 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Run perl via 'env' The 'perl' binary may not be /usr/bin/perl, depending on the system. For example, on modern FreeBSD it tends to be /usr/local/bin/perl instead. To avoid relying on perl to be in a specific location, just run via /usr/bin/env instead, so we pick up perl from $PATH instead. Change-Id: Ic8dc247c82342ff79dfa80426c489ccb8e3e1450 Reviewed-on: https://gerrit.openafs.org/14144 Tested-by: Andrew Deason <adeason@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
opr: Allow non-2^x for n_buckets in opr_cache_init Currently, opr_cache_init requires that opts->n_buckets is a power of 2 (since our underlying opr_dict requires this). However, callers may want to pick a number of buckets based on some other value. Requiring each caller to calculate the nearest power-of-2 is annoying, so instead just have opr_cache_init itself calculate a nearby power of 2. That is, with this commit, opts->n_buckets is allowed to not be a power of 2; when it's not a power of 2, opr_cache_init will calculate the next highest power of 2 and use that as the number of buckets. Change-Id: Icd3c56c1fe0733e3dac964ea9a98ff7b436254e6 Reviewed-on: https://gerrit.openafs.org/14122 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Add cache-t to .gitignore in tests/opr Commit 48fbb45 (opr: Introduce opr_cache) added a new test (cache-t), but did not update the .gitignore file for it. Change-Id: I6de6130257a62f495ac942c05937eb109ce84a75 Reviewed-on: https://gerrit.openafs.org/14102 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
opr: Introduce opr_cache Add a simple general-purpose in-memory cache implementation, called opr_cache. Keys and values are simple flat opaque buffers (no complex nested structures allowed), hashing is done with jhash, and cache eviction is mostly random with some LRU bias. Partly based off a different implementation by mbarbosa@sinenomine.net. Change-Id: I16b5988947ff603dfe31613cd7be3908a69264e5 Reviewed-on: https://gerrit.openafs.org/13884 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Fix most tests for objdir builds Fix a few miscellaneous issues with building and running our tests in objdir builds: - Our C tests use -I$(srcdir)/../.. in the CFLAGS, so we can #include <tests/tap/basic.h>. However, basic.h actually gets copied from src/external/c-tap-harness/tests/tap/ to tests/tap/ during the build, and so basic.h is available in the objdir, not srcdir. For objdir builds, this causes building the tests to fail with failing to find basic.h. Fix this to use TOP_OBJDIR as the include path instead. - Our 'make check' in tests/ tries to run ./libwrap; but our cwd will be in the objdir for objdir builds, and libwrap is a script in our srcdir. Fix this to run libwrap from the srcdir path. - In tests/opr/softsig-t, it tries to find the 'softsig-helper' binary in the same dir as 'softsig-t'. However, softsig-t is just a script in the srcdir, but softsig-helper is a binary built in the objdir. Fix this to use the BUILD env var provided by the tests wrapper, by default. Change-Id: Iff642613bfc88d0d7e348660dc62f59e6fa8af75 Reviewed-on: https://gerrit.openafs.org/13939 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
opr: Make opr_jhash_opaque consistent with opr_jhash Change-Id: I42e1030f8c841dcb974476012a774b91c87d3fb0 Reviewed-on: https://gerrit.openafs.org/12494 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Tested-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests/opr/softsig-t: Avoid hanging due to intermediate sh -c If the build directory happened to contain shell metacharacters, like the ~ in /build/openafs-vb8tid/openafs-1.8.0~pre1 used by the Debian builders, Perl was running softsig-helper via an intermediate sh -c, which would then intercept the signals we tried to send to softsig-helper. Use the list syntax to avoid this sh -c. Change-Id: I054b9c8f606e197accb414bfe3f89719255c62c4 Reviewed-on: https://gerrit.openafs.org/12488 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: fix signo to signame lookup in opr/softsig tests Fix the loop condition when scanning the signal number to name table to convert a signal number to a name. Instead of looping sizeof(size_t) times, loop for the number of elements in the table. This bug was masked on 64 bit-platforms, since the signal number to name table table currently has 8 elements, which is coincidently the same as sizeof(size_t) on 64-bit platforms. The bug becomes apparent on 32-bit systems; only the first 4 elements of the table are checked. Example error output before this fix: $ cd tests $ ./libwrap ../lib ./runtests -o opr/softsig 1..11 ok 1 ok 2 ok 3 ok 4 ok 5 not ok 6 # Failed test in ./opr/softsig-t at line 57. # got: 'Received UNK # ' # expected: 'Received TERM # ' not ok 7 # Failed test in ./opr/softsig-t at line 60. # got: 'Received UNK # ' # expected: 'Received USR1 # ' not ok 8 # Failed test in ./opr/softsig-t at line 63. # got: 'Received UNK # ' # expected: 'Received USR2 # ' ok 9 - Helper exited on KILL signal. ok 10 - Helper exited on SEGV signal. ok 11 # skip Skipping buserror test; SIGBUS constant is not defined. # Looks like you failed 3 tests of 11. Change-Id: I863cc9f3650c4a5e9ac9159d90e063b986a8460a Reviewed-on: https://gerrit.openafs.org/12367 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
test: skip buserror test when SIGBUS is not defined in perl POSIX module Older versions of the perl POSIX module do not define the SIGBUS symbol, which causes the opr/softsig-t perl test to fail to compile. Instead of trying to defined SIGBUS, which may be platform dependent, skip the buserror unit test on these older platforms. Change-Id: Ib8cfd77215ea43566e9d47b501d4989556b83734 Reviewed-on: http://gerrit.openafs.org/12186 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: give the full path to the softsig test helper program In order to start the softsig test helper properly, the full path of this program is necessary. FIXES 132246 Change-Id: I4e9ff1e62a0b82078338eeaf0d4368ac1b35dccc Reviewed-on: http://gerrit.openafs.org/11977 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Tested-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests/opr/jhash-t.c: Fix unsigned constant warning Resolves this warning on 32-bit GCC: jhash-t.c: In function ‘main’: jhash-t.c:60:4: warning: this decimal constant is unsigned only in ISO C90 is_int(3704403432, opr_jhash(test, 2, 0), ^ jhash-t.c:62:4: warning: this decimal constant is unsigned only in ISO C90 is_int(3704403432, opr_jhash_int2(test[0], test[1], 0), ^ Change-Id: Ie3ab0f5aacdc719fa63f32e545b5863ec351f5eb Reviewed-on: http://gerrit.openafs.org/11961 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests/opr/time-t.c: Use labs instead of abs for long argument Resolves this warning with clang: time-t.c:46:8: warning: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value] ok(abs(osTime - osNow) < 2, "opr_time_Now returns a reasonable value"); ^ time-t.c:46:8: note: use function 'labs' instead ok(abs(osTime - osNow) < 2, "opr_time_Now returns a reasonable value"); ^~~ labs Change-Id: Ib98069e1349161d936c8ada0e69f9b33d2f71ce3 Reviewed-on: http://gerrit.openafs.org/11965 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: fix typo in softsig test helper Change-Id: I74183a04b54b70bf3593a53fdb5f164cbd6c3b98 Reviewed-on: http://gerrit.openafs.org/11893 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Chas Williams <3chas3@gmail.com> Reviewed-by: Perry Ruiter <pruiter@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
opr: Add new softsig implementation Signals and pthreaded applications are a poor match. OpenAFS has had the softsig system (currently in src/util/softsig.c) in an attempt to alleviate some of these problems. However, that implementation itself has a number of problems. It uses signal functions that are unsafe in pthreaded applications, and uses pthread_kill within its signal handlers. Over the years it has been responsible for a number of portability bugs. The old implementation continues to receive signals in the main thread of the application. However, the handler code is run within a seperate signal handler thread. When the main thread receives a signal a stub handler is invoked, which simply pthread_kill()s the signal handler thread. The new implementation simplifies things by only receiving signals in the handler thread. It uses only pthread-compatible signal functions, and invokes no code from within async signal handlers. A complete test suite is supplied. Change-Id: I4bac68c2f853f1e7578b54ddced3833a97dd3f82 Reviewed-on: http://gerrit.openafs.org/6947 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Chas Williams <3chas3@gmail.com> Reviewed-by: Daria Brashear <shadow@your-file-system.com>