lix/tests/unit/meson.build

292 lines
7.1 KiB
Meson
Raw Normal View History

# 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.
default_test_env = {
'ASAN_OPTIONS': 'detect_leaks=0:halt_on_error=1:abort_on_error=1:print_summary=1:dump_instruction_bytes=1'
}
libutil_test_support_sources = files(
'libutil-support/tests/cli-literate-parser.cc',
'libutil-support/tests/hash.cc',
'libutil-support/tests/terminal-code-eater.cc',
'libutil-support/tests/test-data.cc',
)
libutil_test_support = library(
'lixutil-test-support',
libutil_test_support_sources,
dependencies : [
liblixutil,
# TODO(Qyriad): libutil tests really should not depend on libexpr...
liblixexpr,
rapidcheck,
boehm,
],
include_directories : include_directories('libutil-support', '../../src'),
)
liblixutil_test_support = declare_dependency(
include_directories : include_directories('libutil-support'),
link_with : libutil_test_support,
)
libutil_tests_sources = files(
'libutil/canon-path.cc',
'libutil/checked-arithmetic.cc',
'libutil/chunked-vector.cc',
'libutil/closure.cc',
'libutil/compression.cc',
'libutil/config.cc',
'libutil/escape-string.cc',
'libutil/generator.cc',
'libutil/git.cc',
'libutil/hash.cc',
'libutil/hilite.cc',
'libutil/json-utils.cc',
'libutil/logging.cc',
'libutil/lru-cache.cc',
'libutil/paths-setting.cc',
'libutil/pool.cc',
'libutil/references.cc',
'libutil/serialise.cc',
'libutil/suggestions.cc',
'libutil/tests.cc',
'libutil/url.cc',
'libutil/url-name.cc',
'libutil/xml-writer.cc',
)
libutil_tester = executable(
'liblixutil-tests',
libutil_tests_sources,
dependencies : [
libasanoptions,
rapidcheck,
gtest,
boehm,
liblixutil,
liblixexpr_mstatic,
liblixutil_test_support,
nlohmann_json,
],
cpp_pch : cpp_pch,
)
test(
'libutil-unit-tests',
libutil_tester,
args : tests_args,
env : default_test_env + {
'_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(
'lixstore-test-support',
libstore_test_support_sources,
dependencies : [
liblixutil_test_support,
liblixutil,
liblixstore,
rapidcheck,
boehm,
],
include_directories : include_directories(
'libstore-support',
),
cpp_pch : cpp_pch,
)
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',
'libstore/filetransfer.cc',
'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(
'liblixstore-tests',
libstore_tests_sources,
dependencies : [
libasanoptions,
liblixstore_test_support,
liblixutil_test_support,
liblixstore_mstatic,
liblixutil,
rapidcheck,
gtest,
nlohmann_json,
],
cpp_pch : cpp_pch,
)
test(
'libstore-unit-tests',
libstore_tester,
args : tests_args,
env : default_test_env + {
'_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(
'lixexpr-test-support',
libexpr_test_support_sources,
dependencies : [
liblixstore_test_support,
liblixstore,
liblixutil,
liblixexpr,
rapidcheck,
],
include_directories : include_directories(
'libexpr-support',
),
cpp_pch : cpp_pch,
)
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',
'libexpr/expr-print.cc',
'libexpr/value/context.cc',
'libexpr/value/print.cc',
)
libexpr_tester = executable(
'liblixexpr-tests',
libexpr_tests_sources,
dependencies : [
libasanoptions,
liblixexpr_test_support,
liblixstore_test_support,
liblixstore_mstatic,
liblixutil,
liblixexpr_mstatic,
liblixfetchers_mstatic,
rapidcheck,
boehm,
gtest,
nlohmann_json,
],
cpp_pch : cpp_pch,
)
test(
'libexpr-unit-tests',
libexpr_tester,
args : tests_args,
env : default_test_env + {
'_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'tests/unit/libexpr/data',
},
suite : 'check',
protocol : 'gtest',
verbose : true,
)
libcmd_tester = executable(
'liblixcmd-tests',
files('libcmd/args.cc'),
dependencies : [
libasanoptions,
liblixcmd,
liblixutil,
liblixmain,
liblixexpr_mstatic,
liblixstore_mstatic,
gtest,
boost,
],
cpp_pch : cpp_pch,
)
test(
'libcmd-unit-tests',
libcmd_tester,
args : tests_args,
env : default_test_env + {
# No special meaning here, it's just a file laying around that is unlikely to go anywhere
# any time soon.
'_NIX_TEST_UNIT_DATA': meson.project_source_root() / 'src/nix-env/buildenv.nix',
# 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',
},
suite : 'check',
protocol : 'gtest',
)
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',
)
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,
dependencies : [
liblixmain,
liblixexpr,
liblixutil,
liblixstore,
gtest,
boost,
],
cpp_pch : cpp_pch,
)
test(
'libmain-unit-tests',
libmain_tester,
args : tests_args,
env : default_test_env,
suite : 'check',
protocol : 'gtest',
)