util: Avoid bad ascii[1] in volutil_GetPartitionID If the caller gives "/vicep" or "vicep" to volutil_GetPartitionID(), we'll strlcpy() an empty string into ascii[], setting ascii[0] to 0. Then we check the value of ascii[1], which is uninitialized. This doesn't result in any bad behavior, because we then immediately check the value of ascii[0] (which is 0), and return -1. But reading the uninitialized ascii[1] triggers errors in tools like valgrind, and is possibly fragile for future code changes. To avoid this, make sure ascii[] is initialized at the start of the function, and check if we have copied an empty string into ascii[]. While we are here, also add tests in volutil-t for invalid "vicep*" strings, to match the existing tests for invalid "/vicep*" strings. Change-Id: I724f893d4bb6421b955c1c89629ab9f277be98bc Reviewed-on: https://gerrit.openafs.org/15526 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Add unit tests for rx_atomic.h Add tests for our rx_atomic macros to make sure they do what they say they do (e.g. rx_atomic_inc() adds 1). Also add a simple test running a bunch of atomic ops in multiple threads, to try to check that the operations are actually atomic. Change-Id: I6e776f280eaf547e9862ceed9798d0d43773fa2c Reviewed-on: https://gerrit.openafs.org/15279 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Avoid plain printf in auth/superuser-t If we're reporting an error, we should be printing to stderr. If we're printing informational data, we should be using diag() to try to avoid interfering with the TAP data. Change all printf() calls into one of those two options. Change-Id: I2e0d577e0c32efa539ed486190dbaca23bd0487f Reviewed-on: https://gerrit.openafs.org/14866 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Improve fork/waitpid error handling A couple of places in our test code aren't handling errors from fork() or waitpid() properly. We don't expect to ever hit errors for these, but sysbail() in this case, so they don't fail silently. Change-Id: I1c548f93f4d4ac4344032d7847470b04319386f2 Reviewed-on: https://gerrit.openafs.org/14865 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Put tmp dirs in objdir, not /tmp Currently, all tests that use afstest_mkdtemp() generate a temporary dir in /tmp, which is removed when the test is done (unless MAKECHECK isn't set, or the test prematurely exits/crashes). The /tmp dir on a system may not be the best choice; it may be limited in size, and it's visible to other users, which is annoying if we are littering the dir with afs_XXXXXX dirs if broken tests are running during development. Instead, use a tmp dir in the objdir of the current build (specifically, tests/tmp/). Since this is the same dir we're building the tree in, we must be able to write to it and it should have plenty of space. And it will almost certainly get cleaned up eventually, even with broken tests, since it will get removed when the build tree is inevitably removed. While we're doing this, run the paths from afstest_src_path and afstest_obj_path through realpath(), so our tmp paths (and other paths) look a little cleaner, and don't look like /home/user/openafs/tests/../tests/tmp/foo. Change-Id: I6633f58ac1f6ef34e33b51cc19d3bff7a4f3fdb0 Reviewed-on: https://gerrit.openafs.org/14864 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Add test keys in afstest_BuildTestConfig Change afstest_BuildTestConfig to add the local keys into the generated config dir, unless the info->skipkeys is set. This just makes afstest_BuildTestConfig a little easier to use for the common case of generating a fully-usable config dir with usable keys (only some callers want to skip generating keys in order to test key-populating functionality). Change-Id: I1ce9d062ea30c391a93562fc90bc18997de75383 Reviewed-on: https://gerrit.openafs.org/14835 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Check for vlserver startup Currently, afstest_StartVLServer waits for a fixed amount of time (5 seconds) for the vlserver to startup. This means each test that runs a vlserver takes at least 5 seconds, which adds up very quickly when new tests are added for vlserver functionality. Instead of waiting 5 seconds each time, change afstest_StartVLServer to check if the vlserver has started up, and to wait a much shorter time if it hasn't finished starting up yet. Specifically, wait until the "Starting AFS vlserver" message appears in VLLog, and the UBIK_RECHAVEDB recovery state bit is set. This allows vlserver-based tests to run much more quickly. Change-Id: I74015670a301980e6d89b3149ed9f2a6c1a40523 Reviewed-on: https://gerrit.openafs.org/14804 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Introduce afstest_MyHostAddr Several places resolve the local hostname into an IP address. Consolidate these into a single function (gethostaddr), and add the function afstest_MyHostAddr, which caches the IP and bails if we can't resolve our hostname. Change-Id: I7f71cd136796e4395c639eed8dd8eb19a7b9beec Reviewed-on: https://gerrit.openafs.org/14802 Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Add existing-database test for pt_util Our current tests for pt_util use pt_util to generate a prdb, and then check the output of pt_util against that created database. Add a new test that runs pt_util against an existing database (with the same test data), to make sure that pt_util is still using the same db format. Change-Id: I4dbe7f3b5080ee6ff1f9509992b5686fc8381da0 Reviewed-on: https://gerrit.openafs.org/14801 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
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: Use real tempfile in pt_util-t Use a real call to File::Temp::tempfile to generate our temporary filename, instead of creating a somewhat predictable filename based on our pid. Change-Id: Icb585c04e088b1fa37dffb6d92fc41cdb14874c7 Reviewed-on: https://gerrit.openafs.org/14799 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-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: Generalize temp dir management Currently, afstest_BuildTestConfig calls afstest_mkdtemp (our thin wrapper around mkdtemp) to create its temporary config dir. We may want to make new tests, though, that create a temp dir for other purposes. To make that easier, move a little more code into afstest_mkdtemp, so the caller doesn't need to construct the template. To allow callers to clean up such temporary dirs, change afstest_UnlinkTestConfig into a more general function, afstest_rmdtemp. Allow this new function to remove all files in a dir, not just files one-level-deep. To avoid needing to write our own traversal and removal logic, just run 'rm -rf' via a new function, afstest_systemlp(). Move these temp dir-related functions from config.c into files.c, since they are no longer specific to config dirs. Change-Id: I16750a2f30e98c9ca2e14dfb7d3fc9bc5d456e8d Reviewed-on: https://gerrit.openafs.org/14632 Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Introduce is_command() Add a new function (is_command), to help implementing tests that involve running a command. This works like is_string(), except the string value we compare against is the output of the provided command, and we also check the exit code of the command. Convert the existing execl() call in volser/vos-t to use this new function. Change-Id: I4a75b1a0333e608da6a6cd69838350116a2503a9 Reviewed-on: https://gerrit.openafs.org/14040 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Introduce afstest_*_path() Currently, several of our tests contain logic to locate files (via srcdir or objdir), based on the C_TAP_SOURCE/BUILD environment variables. This logic is duplicated in several places, so consolidate the code into a couple of new functions: afstest_src_path and afstest_obj_path. Update all callers to use these new functions. Change-Id: I67a5e5d7f8fd7a1edb55a45e52d877ac41f9a2ea Reviewed-on: https://gerrit.openafs.org/14319 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
tests: Introduce afstest_asprintf Add a thin wrapper around asprintf, called afstest_asprintf (and afstest_vasprintf), which does its own error checking. This just helps makes tests a little less cluttered when needing to construct strings. Adapt all asprintf callers in 'tests' to use the wrapper. Change-Id: I6c4ae5b72af827e2c4c66ecfc57f152855b1d401 Reviewed-on: https://gerrit.openafs.org/14620 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
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: Avoid WTERMSIG($?) in rx/perf-t Currently, tests/rx/perf-t calls functions like WIFSIGNALED and WTERMSIG on $?. However, functions like WTERMSIG expect the native exit status code (that is, ${^CHILD_ERROR_NATIVE}). The $? var (aka $CHILD_ERROR), is a synthetic value calculated by perl that stores the term sig in the lowest 7 bits, and the exit code in the second-lowest 8 bits. For most modern platforms, these two values tend to be the same. But on modern AIX (and some other weird platforms, like VMS and BeOS), the exit status integer is encoded differently. On AIX specifically, the term sig is in the third-lowest 8 bits, so a process exiting on signal 15 would result in an exit status (${^CHILD_ERROR_NATIVE}) of 0xf000f, but $? would be just 0xf. Calling WTERMSIG on 0xf000f returns 0xf, but calling WTERMSIG on 0xf returns 0x0. All of this means that running rx/perf-t causes the final test to fail with "Server died with signal 0" (even when the process was killed by signal 15), which is rather confusing. To fix this, call WTERMSIG et al with ${^CHILD_ERROR_NATIVE} instead of $?. Create a local var so we don't need to spell out ${^CHILD_ERROR_NATIVE} so many times. Change-Id: I3c27642fcaf17c320a94caf57d3665d4b6a4a76e Reviewed-on: https://gerrit.openafs.org/14706 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Add missing va_end in cmd/command-t Every va_start call is supposed to be paired with a matching va_end call, but 'checkList' is missing any call to va_end. This doesn't currently seem to cause any visible problems, but add the matching va_end to avoid potential future issues. Change-Id: I569618823f39f4da5b1787cc49c5509d8ea37528 Reviewed-on: https://gerrit.openafs.org/14704 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
tests: Avoid verbose output for 'make check V=0' For "pretty" V=0 builds, change 'make check' to run 'runtests' in non-verbose mode, so we just get a summary of test results, instead of the raw test output. Without V=0, the default is unchanged, so we still print out all test output by default. Change-Id: I554f9d32ed5a9cd27e83fef6245af589d91e801f Reviewed-on: https://gerrit.openafs.org/14619 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>