2024-03-21 21:38:11 +00:00
|
|
|
# NOTE(Qyriad): This file is one big slab of boilerplate.
|
|
|
|
# Lix's current unit test organization is scattered and entagled.
|
|
|
|
# Each of the test-support libraries could theoretically be a somewhat self-contained
|
|
|
|
# subdir(), but literally nothing else can. Each of the tests have dependencies on other
|
|
|
|
# test support libraries, and so do their support libraries.
|
|
|
|
# Each of the tests have dependencies on their own andother test support libraries,
|
|
|
|
# and so do their support libraries, and they have entangled dependencies on Lix's mainline
|
|
|
|
# lib* targets as well.
|
|
|
|
# The only boilerplate reduction I really could do here is throw everything in big nested dictionaries
|
|
|
|
# and dynamically generate and refer to targets based on abstracted specs, but without user-defined
|
|
|
|
# functions, the result would be way less readable than just a bit of copypasta.
|
|
|
|
# It's only ~200 lines; better to just refactor the tests themselves which we'll want to do anyway.
|
|
|
|
|
2024-06-18 06:47:51 +00:00
|
|
|
default_test_env = {
|
2024-10-05 02:13:20 +00:00
|
|
|
'ASAN_OPTIONS': 'detect_leaks=0:halt_on_error=1:abort_on_error=1:print_summary=1:dump_instruction_bytes=1',
|
|
|
|
# Prevents loading global configuration file in /etc/nix/nix.conf in tests 😱
|
|
|
|
'NIX_CONF_DIR': '/var/empty',
|
|
|
|
# Prevent loading user configuration files in tests
|
|
|
|
'NIX_USER_CONF_FILES': '',
|
2024-06-18 06:47:51 +00:00
|
|
|
}
|
|
|
|
|
2024-03-21 21:38:11 +00:00
|
|
|
libutil_test_support_sources = files(
|
|
|
|
'libutil-support/tests/cli-literate-parser.cc',
|
|
|
|
'libutil-support/tests/hash.cc',
|
|
|
|
'libutil-support/tests/terminal-code-eater.cc',
|
2024-08-26 16:28:14 +00:00
|
|
|
'libutil-support/tests/test-data.cc',
|
2024-03-21 21:38:11 +00:00
|
|
|
)
|
|
|
|
libutil_test_support = library(
|
2024-05-17 00:04:05 +00:00
|
|
|
'lixutil-test-support',
|
2024-03-21 21:38:11 +00:00
|
|
|
libutil_test_support_sources,
|
|
|
|
dependencies : [
|
|
|
|
liblixutil,
|
|
|
|
# TODO(Qyriad): libutil tests really should not depend on libexpr...
|
|
|
|
liblixexpr,
|
|
|
|
rapidcheck,
|
|
|
|
boehm,
|
|
|
|
],
|
2024-11-19 20:51:21 +00:00
|
|
|
include_directories : include_directories('libutil-support'),
|
2024-03-21 21:38:11 +00:00
|
|
|
)
|
|
|
|
liblixutil_test_support = declare_dependency(
|
|
|
|
include_directories : include_directories('libutil-support'),
|
|
|
|
link_with : libutil_test_support,
|
|
|
|
)
|
|
|
|
|
|
|
|
libutil_tests_sources = files(
|
2024-09-23 22:21:16 +00:00
|
|
|
'libutil/async-collect.cc',
|
2024-09-23 22:21:16 +00:00
|
|
|
'libutil/async-semaphore.cc',
|
2024-03-21 21:38:11 +00:00
|
|
|
'libutil/canon-path.cc',
|
2024-07-05 13:52:55 +00:00
|
|
|
'libutil/checked-arithmetic.cc',
|
2024-03-21 21:38:11 +00:00
|
|
|
'libutil/chunked-vector.cc',
|
|
|
|
'libutil/closure.cc',
|
|
|
|
'libutil/compression.cc',
|
|
|
|
'libutil/config.cc',
|
2024-03-28 23:26:42 +00:00
|
|
|
'libutil/escape-string.cc',
|
2024-03-19 17:02:22 +00:00
|
|
|
'libutil/generator.cc',
|
2024-03-21 21:38:11 +00:00
|
|
|
'libutil/git.cc',
|
|
|
|
'libutil/hash.cc',
|
|
|
|
'libutil/hilite.cc',
|
|
|
|
'libutil/json-utils.cc',
|
|
|
|
'libutil/logging.cc',
|
|
|
|
'libutil/lru-cache.cc',
|
2024-03-09 22:00:43 +00:00
|
|
|
'libutil/paths-setting.cc',
|
2024-03-21 21:38:11 +00:00
|
|
|
'libutil/pool.cc',
|
|
|
|
'libutil/references.cc',
|
2024-03-21 14:54:41 +00:00
|
|
|
'libutil/serialise.cc',
|
2024-03-21 21:38:11 +00:00
|
|
|
'libutil/suggestions.cc',
|
|
|
|
'libutil/tests.cc',
|
|
|
|
'libutil/url.cc',
|
2024-05-01 00:11:14 +00:00
|
|
|
'libutil/url-name.cc',
|
2024-03-21 21:38:11 +00:00
|
|
|
'libutil/xml-writer.cc',
|
|
|
|
)
|
|
|
|
|
|
|
|
libutil_tester = executable(
|
2024-05-17 00:04:05 +00:00
|
|
|
'liblixutil-tests',
|
2024-03-21 21:38:11 +00:00
|
|
|
libutil_tests_sources,
|
|
|
|
dependencies : [
|
2024-06-18 06:47:51 +00:00
|
|
|
libasanoptions,
|
2024-03-21 21:38:11 +00:00
|
|
|
rapidcheck,
|
|
|
|
gtest,
|
|
|
|
boehm,
|
|
|
|
liblixutil,
|
2024-05-30 23:10:10 +00:00
|
|
|
liblixexpr_mstatic,
|
2024-03-21 21:38:11 +00:00
|
|
|
liblixutil_test_support,
|
2024-03-27 03:09:43 +00:00
|
|
|
nlohmann_json,
|
2024-09-23 22:21:16 +00:00
|
|
|
kj,
|
2024-03-21 21:38:11 +00:00
|
|
|
],
|
2024-06-06 18:46:26 +00:00
|
|
|
cpp_pch : cpp_pch,
|
2024-03-21 21:38:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
'libutil-unit-tests',
|
|
|
|
libutil_tester,
|
|
|
|
args : tests_args,
|
2024-06-18 06:47:51 +00:00
|
|
|
env : default_test_env + {
|
2024-03-21 21:38:11 +00:00
|
|
|
'_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'tests/unit/libutil/data',
|
|
|
|
},
|
|
|
|
suite : 'check',
|
|
|
|
protocol : 'gtest',
|
|
|
|
verbose : true,
|
|
|
|
)
|
|
|
|
|
|
|
|
libstore_test_support_sources = files(
|
|
|
|
'libstore-support/tests/derived-path.cc',
|
|
|
|
'libstore-support/tests/outputs-spec.cc',
|
|
|
|
'libstore-support/tests/path.cc',
|
|
|
|
)
|
|
|
|
|
|
|
|
libstore_test_support = library(
|
2024-05-17 00:04:05 +00:00
|
|
|
'lixstore-test-support',
|
2024-03-21 21:38:11 +00:00
|
|
|
libstore_test_support_sources,
|
|
|
|
dependencies : [
|
|
|
|
liblixutil_test_support,
|
|
|
|
liblixutil,
|
|
|
|
liblixstore,
|
|
|
|
rapidcheck,
|
|
|
|
boehm,
|
|
|
|
],
|
|
|
|
include_directories : include_directories(
|
|
|
|
'libstore-support',
|
|
|
|
),
|
2024-06-06 18:46:26 +00:00
|
|
|
cpp_pch : cpp_pch,
|
2024-03-21 21:38:11 +00:00
|
|
|
)
|
|
|
|
liblixstore_test_support = declare_dependency(
|
|
|
|
include_directories : include_directories('libstore-support'),
|
|
|
|
link_with : libstore_test_support,
|
|
|
|
)
|
|
|
|
|
|
|
|
libstore_tests_sources = files(
|
|
|
|
'libstore/common-protocol.cc',
|
|
|
|
'libstore/derivation.cc',
|
|
|
|
'libstore/derived-path.cc',
|
|
|
|
'libstore/downstream-placeholder.cc',
|
2024-05-03 23:39:06 +00:00
|
|
|
'libstore/filetransfer.cc',
|
2024-03-21 21:38:11 +00:00
|
|
|
'libstore/machines.cc',
|
|
|
|
'libstore/nar-info-disk-cache.cc',
|
|
|
|
'libstore/outputs-spec.cc',
|
|
|
|
'libstore/path.cc',
|
|
|
|
'libstore/references.cc',
|
|
|
|
'libstore/serve-protocol.cc',
|
|
|
|
'libstore/worker-protocol.cc',
|
|
|
|
)
|
|
|
|
|
|
|
|
libstore_tester = executable(
|
2024-05-17 00:04:05 +00:00
|
|
|
'liblixstore-tests',
|
2024-03-21 21:38:11 +00:00
|
|
|
libstore_tests_sources,
|
|
|
|
dependencies : [
|
2024-06-18 06:47:51 +00:00
|
|
|
libasanoptions,
|
2024-03-21 21:38:11 +00:00
|
|
|
liblixstore_test_support,
|
|
|
|
liblixutil_test_support,
|
2024-05-30 23:10:10 +00:00
|
|
|
liblixstore_mstatic,
|
2024-03-21 21:38:11 +00:00
|
|
|
liblixutil,
|
|
|
|
rapidcheck,
|
|
|
|
gtest,
|
2024-03-27 03:09:43 +00:00
|
|
|
nlohmann_json,
|
2024-03-21 21:38:11 +00:00
|
|
|
],
|
2024-06-06 18:46:26 +00:00
|
|
|
cpp_pch : cpp_pch,
|
2024-03-21 21:38:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
'libstore-unit-tests',
|
|
|
|
libstore_tester,
|
|
|
|
args : tests_args,
|
2024-06-18 06:47:51 +00:00
|
|
|
env : default_test_env + {
|
2024-03-21 21:38:11 +00:00
|
|
|
'_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'tests/unit/libstore/data',
|
|
|
|
},
|
|
|
|
suite : 'check',
|
|
|
|
protocol : 'gtest',
|
|
|
|
verbose : true,
|
|
|
|
)
|
|
|
|
|
|
|
|
libexpr_test_support_sources = files(
|
|
|
|
'libexpr-support/tests/value/context.cc',
|
|
|
|
)
|
|
|
|
|
|
|
|
libexpr_test_support = library(
|
2024-05-17 00:04:05 +00:00
|
|
|
'lixexpr-test-support',
|
2024-03-21 21:38:11 +00:00
|
|
|
libexpr_test_support_sources,
|
|
|
|
dependencies : [
|
|
|
|
liblixstore_test_support,
|
|
|
|
liblixstore,
|
|
|
|
liblixutil,
|
|
|
|
liblixexpr,
|
|
|
|
rapidcheck,
|
|
|
|
],
|
|
|
|
include_directories : include_directories(
|
|
|
|
'libexpr-support',
|
|
|
|
),
|
2024-06-06 18:46:26 +00:00
|
|
|
cpp_pch : cpp_pch,
|
2024-03-21 21:38:11 +00:00
|
|
|
)
|
|
|
|
liblixexpr_test_support = declare_dependency(
|
|
|
|
include_directories : include_directories('libexpr-support'),
|
|
|
|
link_with : libexpr_test_support,
|
|
|
|
)
|
|
|
|
|
|
|
|
libexpr_tests_sources = files(
|
|
|
|
'libexpr/derived-path.cc',
|
|
|
|
'libexpr/error_traces.cc',
|
|
|
|
'libexpr/flakeref.cc',
|
|
|
|
'libexpr/json.cc',
|
|
|
|
'libexpr/primops.cc',
|
|
|
|
'libexpr/search-path.cc',
|
|
|
|
'libexpr/trivial.cc',
|
2024-06-24 20:33:12 +00:00
|
|
|
'libexpr/expr-print.cc',
|
2024-03-21 21:38:11 +00:00
|
|
|
'libexpr/value/context.cc',
|
|
|
|
'libexpr/value/print.cc',
|
|
|
|
)
|
|
|
|
|
|
|
|
libexpr_tester = executable(
|
2024-05-17 00:04:05 +00:00
|
|
|
'liblixexpr-tests',
|
2024-03-21 21:38:11 +00:00
|
|
|
libexpr_tests_sources,
|
|
|
|
dependencies : [
|
2024-06-18 06:47:51 +00:00
|
|
|
libasanoptions,
|
2024-03-21 21:38:11 +00:00
|
|
|
liblixexpr_test_support,
|
|
|
|
liblixstore_test_support,
|
2024-05-30 23:10:10 +00:00
|
|
|
liblixstore_mstatic,
|
2024-03-21 21:38:11 +00:00
|
|
|
liblixutil,
|
2024-05-30 23:10:10 +00:00
|
|
|
liblixexpr_mstatic,
|
|
|
|
liblixfetchers_mstatic,
|
2024-03-21 21:38:11 +00:00
|
|
|
rapidcheck,
|
|
|
|
boehm,
|
|
|
|
gtest,
|
2024-03-27 03:09:43 +00:00
|
|
|
nlohmann_json,
|
2024-03-21 21:38:11 +00:00
|
|
|
],
|
2024-06-06 18:46:26 +00:00
|
|
|
cpp_pch : cpp_pch,
|
2024-03-21 21:38:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
'libexpr-unit-tests',
|
|
|
|
libexpr_tester,
|
|
|
|
args : tests_args,
|
2024-06-18 06:47:51 +00:00
|
|
|
env : default_test_env + {
|
2024-03-21 21:38:11 +00:00
|
|
|
'_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'tests/unit/libexpr/data',
|
|
|
|
},
|
|
|
|
suite : 'check',
|
|
|
|
protocol : 'gtest',
|
|
|
|
verbose : true,
|
|
|
|
)
|
2024-05-21 18:10:24 +00:00
|
|
|
|
|
|
|
libcmd_tester = executable(
|
|
|
|
'liblixcmd-tests',
|
|
|
|
files('libcmd/args.cc'),
|
|
|
|
dependencies : [
|
2024-06-18 06:47:51 +00:00
|
|
|
libasanoptions,
|
2024-05-21 18:10:24 +00:00
|
|
|
liblixcmd,
|
|
|
|
liblixutil,
|
|
|
|
liblixmain,
|
2024-05-30 23:10:10 +00:00
|
|
|
liblixexpr_mstatic,
|
|
|
|
liblixstore_mstatic,
|
2024-05-21 18:10:24 +00:00
|
|
|
gtest,
|
|
|
|
boost,
|
|
|
|
],
|
2024-06-06 18:46:26 +00:00
|
|
|
cpp_pch : cpp_pch,
|
2024-05-21 18:10:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
'libcmd-unit-tests',
|
|
|
|
libcmd_tester,
|
|
|
|
args : tests_args,
|
2024-06-18 06:47:51 +00:00
|
|
|
env : default_test_env + {
|
2024-05-21 18:10:24 +00:00
|
|
|
# No special meaning here, it's just a file laying around that is unlikely to go anywhere
|
|
|
|
# any time soon.
|
2024-11-19 20:51:21 +00:00
|
|
|
'_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'lix/legacy/buildenv.nix',
|
2024-06-01 09:59:16 +00:00
|
|
|
# Use a temporary home directory for the unit tests.
|
|
|
|
# Otherwise, /homeless-shelter is created in the single-user sandbox, and functional tests will fail.
|
|
|
|
# TODO(alois31): handle TMPDIR properly (meson can't, and setting HOME in the test is too late)…
|
|
|
|
'HOME': '/tmp/nix-test/libcmd-unit-tests',
|
2024-05-21 18:10:24 +00:00
|
|
|
},
|
|
|
|
suite : 'check',
|
|
|
|
protocol : 'gtest',
|
|
|
|
)
|
2024-06-20 04:12:24 +00:00
|
|
|
|
main: log stack traces for std::terminate
These stack traces kind of suck for the reasons mentioned on the
CppTrace page here (no symbols for inline functions is a major one):
https://github.com/jeremy-rifkin/cpptrace
I would consider using CppTrace if it were packaged, but to be honest, I
think that the more reasonable option is actually to move entirely to
out-of-process crash handling and symbolization.
The reason for this is that if you want to generate anything of
substance on SIGSEGV or really any deadly signal, you are stuck in
async-signal-safe land, which is not a place to be trying to run a
symbolizer. LLVM does it anyway, probably carefully, and chromium *can*
do it on debug builds but in general uses crashpad:
https://source.chromium.org/chromium/chromium/src/+/main:base/debug/stack_trace_posix.cc;l=974;drc=82dff63dbf9db05e9274e11d9128af7b9f51ceaa;bpv=1;bpt=1
However, some stack traces are better than *no* stack traces when we get
mystery exceptions falling out the bottom of the program. I've also
promoted the path for "mystery exceptions falling out the bottom of the
program" to hard crash and generate a core dump because although there's
been some months since the last one of these, these are nonetheless
always *atrociously* diagnosed.
We can't improve the crash handling further until either we use Crashpad
(which involves more C++ deps, no thanks) or we put in the ostensibly
work in progress Rust minidump infrastructure, in which case we need to
finish full support for Rust in libutil first.
Sample report:
Lix crashed. This is a bug. We would appreciate if you report it at https://git.lix.systems/lix-project/lix/issues with the following information included:
Exception: std::runtime_error: lol
Stack trace:
0# nix::printStackTrace() in /home/jade/lix/lix3/build/src/nix/../libutil/liblixutil.so
1# 0x000073C9862331F2 in /home/jade/lix/lix3/build/src/nix/../libmain/liblixmain.so
2# 0x000073C985F2E21A in /nix/store/p44qan69linp3ii0xrviypsw2j4qdcp2-gcc-13.2.0-lib/lib/libstdc++.so.6
3# 0x000073C985F2E285 in /nix/store/p44qan69linp3ii0xrviypsw2j4qdcp2-gcc-13.2.0-lib/lib/libstdc++.so.6
4# nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) in /home/jade/lix/lix3/build/src/nix/../libmain/liblixmain.so
5# 0x00005CF65B6B048B in /home/jade/lix/lix3/build/src/nix/nix
6# 0x000073C985C8810E in /nix/store/dbcw19dshdwnxdv5q2g6wldj6syyvq7l-glibc-2.39-52/lib/libc.so.6
7# __libc_start_main in /nix/store/dbcw19dshdwnxdv5q2g6wldj6syyvq7l-glibc-2.39-52/lib/libc.so.6
8# 0x00005CF65B610335 in /home/jade/lix/lix3/build/src/nix/nix
Change-Id: I1a9f6d349b617fd7145a37159b78ecb9382cb4e9
2024-08-25 04:11:30 +00:00
|
|
|
libmain_tests_sources = files(
|
|
|
|
'libmain/crash.cc',
|
|
|
|
'libmain/progress-bar.cc',
|
|
|
|
)
|
|
|
|
|
2024-06-20 04:12:24 +00:00
|
|
|
libmain_tester = executable(
|
|
|
|
'liblixmain-tests',
|
main: log stack traces for std::terminate
These stack traces kind of suck for the reasons mentioned on the
CppTrace page here (no symbols for inline functions is a major one):
https://github.com/jeremy-rifkin/cpptrace
I would consider using CppTrace if it were packaged, but to be honest, I
think that the more reasonable option is actually to move entirely to
out-of-process crash handling and symbolization.
The reason for this is that if you want to generate anything of
substance on SIGSEGV or really any deadly signal, you are stuck in
async-signal-safe land, which is not a place to be trying to run a
symbolizer. LLVM does it anyway, probably carefully, and chromium *can*
do it on debug builds but in general uses crashpad:
https://source.chromium.org/chromium/chromium/src/+/main:base/debug/stack_trace_posix.cc;l=974;drc=82dff63dbf9db05e9274e11d9128af7b9f51ceaa;bpv=1;bpt=1
However, some stack traces are better than *no* stack traces when we get
mystery exceptions falling out the bottom of the program. I've also
promoted the path for "mystery exceptions falling out the bottom of the
program" to hard crash and generate a core dump because although there's
been some months since the last one of these, these are nonetheless
always *atrociously* diagnosed.
We can't improve the crash handling further until either we use Crashpad
(which involves more C++ deps, no thanks) or we put in the ostensibly
work in progress Rust minidump infrastructure, in which case we need to
finish full support for Rust in libutil first.
Sample report:
Lix crashed. This is a bug. We would appreciate if you report it at https://git.lix.systems/lix-project/lix/issues with the following information included:
Exception: std::runtime_error: lol
Stack trace:
0# nix::printStackTrace() in /home/jade/lix/lix3/build/src/nix/../libutil/liblixutil.so
1# 0x000073C9862331F2 in /home/jade/lix/lix3/build/src/nix/../libmain/liblixmain.so
2# 0x000073C985F2E21A in /nix/store/p44qan69linp3ii0xrviypsw2j4qdcp2-gcc-13.2.0-lib/lib/libstdc++.so.6
3# 0x000073C985F2E285 in /nix/store/p44qan69linp3ii0xrviypsw2j4qdcp2-gcc-13.2.0-lib/lib/libstdc++.so.6
4# nix::handleExceptions(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>) in /home/jade/lix/lix3/build/src/nix/../libmain/liblixmain.so
5# 0x00005CF65B6B048B in /home/jade/lix/lix3/build/src/nix/nix
6# 0x000073C985C8810E in /nix/store/dbcw19dshdwnxdv5q2g6wldj6syyvq7l-glibc-2.39-52/lib/libc.so.6
7# __libc_start_main in /nix/store/dbcw19dshdwnxdv5q2g6wldj6syyvq7l-glibc-2.39-52/lib/libc.so.6
8# 0x00005CF65B610335 in /home/jade/lix/lix3/build/src/nix/nix
Change-Id: I1a9f6d349b617fd7145a37159b78ecb9382cb4e9
2024-08-25 04:11:30 +00:00
|
|
|
libmain_tests_sources,
|
2024-06-20 04:12:24 +00:00
|
|
|
dependencies : [
|
|
|
|
liblixmain,
|
|
|
|
liblixexpr,
|
|
|
|
liblixutil,
|
|
|
|
liblixstore,
|
|
|
|
gtest,
|
|
|
|
boost,
|
|
|
|
],
|
|
|
|
cpp_pch : cpp_pch,
|
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
'libmain-unit-tests',
|
|
|
|
libmain_tester,
|
|
|
|
args : tests_args,
|
2024-06-18 06:47:51 +00:00
|
|
|
env : default_test_env,
|
2024-06-20 04:12:24 +00:00
|
|
|
suite : 'check',
|
|
|
|
protocol : 'gtest',
|
|
|
|
)
|