test: make unit tests relocatable and add an "install-tests" make target#5298
test: make unit tests relocatable and add an "install-tests" make target#5298keszybz merged 3 commits intosystemd:masterfrom
Conversation
|
Note that even with this, |
|
I don't quite understand how you plan this to work for installed tests. (I'm assuming that this eventually is supposed to lead to #5257.) It would be nice to have the installed tests work without an environment variable. So the tests should compile in the installation path, and when running from the build directory, the env var could be used, i.e. the opposite of what this patch does, afaiu. |
|
@keszybz: Right now this allows me to run A more generic solution would be to also install the test data files. Then we don't need an env var at all, but tests should simply look in a dir relative to their own path (dirname of |
|
I wonder whether it would make sense to support I see a couple of packages in Debian already following that scheme: |
This seems to be very specific to graphical applications. Some parts don't apply to us. But we might follow at least the fs-layout that they suggest, and add more compatibility later on. There's also a wider question of converting our output to TAP. I think it would make a lot of sense, allowing us to get better reporting from our tests, but it's a great undertaking. |
I played around with that, and that's a bit ugly. E. g. builddir/ |
|
Just to clarify, this matches what I said in #5298 (comment)? |
|
Mostly, just that I don't want to compile in an absolute installation path either. I still think relative path names are nicer, but they need to be overridden by env vars for running tests in the build tree. |
|
Agreed, relative paths are better. |
381f286 to
925d268
Compare
|
Reworked as above, and I also added a and things Just Work™. |
src/shared/tests.c
Outdated
| } | ||
|
|
||
| const char* get_exe_relative_testdata_dir(void) | ||
| { |
Makefile.am
Outdated
| if [ -x .libs/$$f ]; then \ | ||
| install -m 755 .libs/$$f $(DESTDIR)/$(testsdir); \ | ||
| else \ | ||
| install -m 755 $$f $(DESTDIR)/$(testsdir); \ |
There was a problem hiding this comment.
If -D is used below, it should be used here too.
| test-libudev-sym | ||
|
|
||
| .PHONY: install-tests | ||
| install-tests: $(tests) $(TEST_DATA_FILES) |
There was a problem hiding this comment.
Hm, that's problematic.
We have --enable-tests=unsafe. I think it's reasonable to enable this during package build (since it usually happens in a throw-away environment), but then those tests are installed intermingled with the other ones. Also, the result of install-tests depends on this configure option, but I don't think it should.
Maybe the extra tests should be installed into $(testsdir)/{unsafe,manual}?
There was a problem hiding this comment.
I think this PR is safe wrt. that. Regardless of whether you enable or disable unsafe tests, they don't get installed. Check this in Makefile.am:
noinst_PROGRAMS = $(manual_tests) $(tests) $(unsafe_tests)
TESTS = $(tests)
if ENABLE_UNSAFE_TESTS
TESTS += \
……………………$(unsafe_tests)
endif
but the install-tests target only works over $(tests), not $(TESTS).
That said, I'm fine with installing those into $(testsdir)/{unsafe,manual} in addition (or that could be a separate PR).
There was a problem hiding this comment.
Oh, right. I think we should install unsafe tests, because they're precisely the kind you want to run in a throw-away build environment, but you are right that this can be a separate PR.
Moe test-resolve's test data from src/resolve/test-data to
test/test-resolve/ to be consistent with test/test-{execute,path}/. This
will make it easier to make the tests relocatable.
It is useful to package test-* binaries and run them as root under autopkgtest or manually on particular machines. They currently have a built-in hardcoded absolute path to their test data, which does not work when running the test programs from any other path than the original build directory. By default, make the tests look for their data in <test_exe_directory>/testdata/ so that they can be called from any directory (provided that the corresponding test data is installed correctly). As we don't have a fixed static path in the build tree (as build and source tree are independent), set $TEST_DIR with "make check" to point to <srcdir>/test/, as we previously did with an automake variable.
Add a new "install-tests" make target that installs our unit test-* executables and their test data files into /usr/lib/systemd/tests/. This is useful for packaging the tests to run them with root privileges or in CI. Fixes systemd#5257
925d268 to
4f8425b
Compare
| static char testdir[PATH_MAX]; | ||
|
|
||
| assert_se(readlink_and_make_absolute("/proc/self/exe", &exedir) >= 0); | ||
| assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", dirname(exedir)) > 0); |
There was a problem hiding this comment.
Not sure I understand how does it work
./libtool --mode=execute ./test-engine
...
Assertion 'r == 0' failed at src/test/test-engine.c:62, function main(). Aborting.
Aborted (core dumped)
strace shows:
stat("/home/vagrant/systemd/.libs/testdata", 0x7ffd852cece0) = -1 ENOENT (No such file or directory)
i.e. make valgrind-tests is broken
|
"make install-tests" fails if srcdir != builddir as the test data files are not found. |
It is useful to package test-* binaries and run them as root under
autopkgtest or manually on particular machines. They currently have a
built-in hardcoded absolute path to their test data, which does not work
when running the test programs from any other path than the original
build directory.
Add a new "install-tests" make target that installs our unit test-* executables and their test data files into /usr/lib/systemd/tests/.
Today I added a new autopkgtest to CI which runs all (automatic) unit tests as root. This has uncovered a few issues like the arch specific seccomp failures, so let's start to gate on all of them. However, 7 tests fail due to their hardcoded
TEST_DIRand thus are blacklisted in the test. With this PR we can enable them.