Repository navigation
build(test): wire every test suite into the build and run it in CI - #8
Conversation
0fc03e3 to
ca6d076
Compare
DrSergei
left a comment
There was a problem hiding this comment.
- Configure hard-fails by default when test deps are missing (behavior change) — PSEUDO_ENABLE_TESTS defaults ON, and cmake/LLVMTestingLibs.cmake:26 now FATAL_ERRORs if the LLVM package doesn't export testing libs. A plain cmake -B build against a distro LLVM without LLVMTestingSupport (and no -DPSEUDO_LLVM_SOURCE_DIR) now fails configure instead of skipping tests. Likely intentional (README notes it), but tests ON by default makes the plugin-only path fail. Consider defaulting tests OFF, or only hard-erroring when tests were explicitly requested.
- PSEUDO_ENABLE_FUZZER is cached and won't track PSEUDO_ENABLE_TESTS — derived default in CMakeLists.txt:106, but option() caches on first configure. Reconfiguring a build dir from tests ON → OFF leaves the fuzzer ON, still adding fuzzer (which links LLVMFuzzerCLI). Fresh dirs unaffected; gate the subdirectory on both options or drop the derived default.
- charinfo::InfoTable fallback still uses selectany — the same /Zc:inline COMDAT-dropping mechanism the commit fixed for LSPError::ID/CodeCompleteOptions::DefaultRankingModel also applies to PluginSymbols.cpp:67. If the reported unresolved externals were accurate this is fine, but worth confirming it isn't a third Windows plugin link error. (Unverifiable without an MSVC build.)
- CI caches the LLVM tree before building test utilities (minor) — "Build LLVM test utilities" runs after "Save Clangd cache" in all three jobs (ci.yml:71–81, 191–201, 319–330), so FileCheck/not/count/LLVMFuzzerCLI get rebuilt every run. Correct, just wasted work; reorder or bump the cache key.
|
Thanks for the careful read, all four points were on target. Addressed in the updated commit:
|
4bb3582 to
de59706
Compare
|
Follow-up on point 4: the first run after the key bump showed the cache fallback path had never actually worked. |
DrSergei
left a comment
There was a problem hiding this comment.
- PSEUDO_ENABLE_TESTS can default ON then hard-fail on missing clangDaemon — medium
CMakeLists.txt:117-118 enables tests by default when LLVMTestingSupport exists or an llvm-project tree is found, but never checks for the clangDaemon target. unittests/CMakeLists.txt:41-47 turns a missing clangDaemon into FATAL_ERROR.
Realistic path: CLANGD_INCLUDE_DIRS points inside a source checkout (so the plugin builds), which auto-derives PSEUDO_LLVM_SOURCE_DIR at CMakeLists.txt:83-84 → tests default ON. If the find_package LLVM/Clang is a distro/Homebrew package that does not export clangDaemon, a plain configure now aborts. This contradicts the comment at CMakeLists.txt:113-116 ("a plain configure ... still builds the plugin") and regresses the prior if(TARGET clangDaemon) silent skip. Fix: add the clangDaemon condition to the default check, or downgrade the missing-target case to a warning/skip. - PSEUDO_LLVM_SOURCE_DIR embedded in a C++ literal without normalization — low (Windows only)
CMakeLists.txt:83-84 normalizes auto-derived paths via get_filename_component(... ABSOLUTE), but a user/env-supplied path (CMakeLists.txt:82) is not normalized. It is pasted into a string literal at unittests/clangd/CMakeLists.txt:93. On Windows, -DPSEUDO_LLVM_SOURCE_DIR="C:\llvm-project" produces invalid escape sequences (\l, \p), corrupting the value used by findRepoSourceFile. Affects only users who set the variable explicitly on Windows; run it through get_filename_component(... ABSOLUTE) or file(TO_CMAKE_PATH ...) first.
Overall, LGTM
ArcsinX
left a comment
There was a problem hiding this comment.
Summary of Review Findings
Thanks for wiring all the test suites and enabling CI testing across platforms. The CI configuration and object library decoupling look very solid.
However, there are several configure regressions and portability issues that need to be addressed before merging (so withholding approval for now):
-
Configure Hard-Fail on Missing
clangDaemon(CMakeLists.txt:118&unittests/CMakeLists.txt:42):PSEUDO_ENABLE_TESTSdefaults toONwheneverPSEUDO_LLVM_SOURCE_DIRis set or auto-detected (e.g. whenCLANGD_INCLUDE_DIRSpoints inside anllvm-projectcheckout).- If building against an installed LLVM distribution package (such as Homebrew LLVM or distro packages),
clangDaemonis not exported. unittests/CMakeLists.txt:42raises aFATAL_ERROR, breaking standard plugin builds (cmake -B build) and regressing the previous gracefulif(TARGET clangDaemon)behavior.- Recommendation: Check for
TARGET clangDaemonwhen computingPSEUDO_ENABLE_TESTS_DEFAULTor downgradeunittests/CMakeLists.txt:42to skipPseudoModuleTestswith a status message while still allowingClangPseudoTestsand lit tests to build.
-
Unescaped Windows Path in C++ String Literal (
CMakeLists.txt:88&unittests/clangd/CMakeLists.txt:93):- Unlike
CLANGD_INCLUDE_DIRSwhich is normalized viaget_filename_component(... ABSOLUTE),PSEUDO_LLVM_SOURCE_DIRis not normalized when provided via-DPSEUDO_LLVM_SOURCE_DIR=...or$ENV{PSEUDO_LLVM_SOURCE_DIR}. - In
unittests/clangd/CMakeLists.txt:93, it is passed directly intotarget_compile_definitions(PseudoModuleTests PRIVATE PSEUDO_LLVM_SOURCE_DIR="${PSEUDO_LLVM_SOURCE_DIR}"). - On Windows, raw backslashes expand into invalid escape sequences (e.g.,
\l,) insidePseudoModuleTests.cpp:3164, leading to compilation errors or corrupted path lookups. - Recommendation: Normalize
PSEUDO_LLVM_SOURCE_DIRwithget_filename_component(PSEUDO_LLVM_SOURCE_DIR "${PSEUDO_LLVM_SOURCE_DIR}" ABSOLUTE)after discovery.
- Unlike
-
target_include_directories(... PUBLIC ...)onIMPORTEDTargets (cmake/LLVMTestingLibs.cmake:59):- In
pseudo_require_llvm_testing_libs(),target_include_directories(${target} PUBLIC ...)will fail with a fatal CMake error ifLLVMTestingSupportwas already an imported target from the LLVM package (CMake forbidsPUBLIC/PRIVATEon imported targets). - Recommendation: Only set include directories for targets in
missingthat were built from source in this function.
- In
-
Hard
FATAL_ERRORfor Clangd Test Support Sources (unittests/clangd/CMakeLists.txt:20):- If
CLANGD_INCLUDE_DIRSpoints to clangd headers from an installation withoutunittests/test sources, the build hard-fails. - Recommendation: Gracefully skip
PseudoModuleTestsinstead of aborting the entire build.
- If
-
file(GLOB_RECURSE)on Static File Paths (unittests/clangd/CMakeLists.txt:31):- Uses
GLOB_RECURSEon static paths. WhenLLVM_BINARY_DIRis empty in standalone builds, this checks root paths/tools/.... Useif(EXISTS ...)instead.
- Uses
-
Missing
-fno-rtti//GR-onclangd_pseudoMODULE Target (clangd/CMakeLists.txt:53):target_compile_options(... PRIVATE -fno-rtti)was applied only toobj.clangd_pseudo. The MODULE targetclangd_pseudocompilesPluginSymbols.cppwith RTTI enabled, causing a mismatch with LLVM and the rest of the plugin.
-
Literal
@SHLIBDIR@and@LLVM_LIBS_DIR@in Test Shim (test/Unit/lit.cfg.py:18-20):- (Existing file, not touched in this PR)
test/Unit/lit.cfg.pysetsconfig.environment[shlibpath_var]using literal string"@SHLIBDIR@"and"@LLVM_LIBS_DIR@"instead ofconfig.shlibdirandconfig.llvm_libs_dir. Consider fixing this in a follow-up or along with this PR.
- (Existing file, not touched in this PR)
CI never executed a test: LLVM was built with LLVM_INCLUDE_TESTS=OFF, so unittests/ skipped itself when LLVMTestingSupport was missing, the build step hid that behind `|| true`, PseudoModuleTests was never compiled, and test/, fuzzer/ and benchmarks/ were not referenced from the root CMake and linked target names that no longer exist. - Add cmake/LLVMTestingLibs.cmake: build llvm_gtest, llvm_gtest_main, LLVMTestingSupport and LLVMTestingAnnotations from an llvm-project source tree (PSEUDO_LLVM_SOURCE_DIR, derived from CLANGD_INCLUDE_DIRS) when the LLVM package does not export them. PSEUDO_ENABLE_TESTS defaults to ON when these dependencies are found and OFF otherwise, so a plain configure still builds the plugin; with tests ON, a missing dependency is a configure error instead of a silent skip. - Compile the module sources into obj.clangd_pseudo, shared by the plugin and PseudoModuleTests, and build PseudoModuleTests with clangd's own test scaffolding (TestFS, TestTU, SyncAPI, LSPClient, TestIndex, Annotations) and a generated Features.inc. - Move the definitions that exist only because the plugin is loaded into an unmodified clangd (Windows fallbacks for LSPError::ID, DefaultRankingModel and charinfo::InfoTable, the weak ErrorInfoBase typeinfo, the ABI-check variable) into clangd/PluginSymbols.cpp, compiled only into the MODULE target; linked next to the real clangDaemon.lib they were duplicate definitions. They are plain definitions, not selectany: /Zc:inline drops COMDAT data unreferenced in its translation unit. - Wire test/ (lit, run from the source tree's lit.py), fuzzer/ and benchmarks/ into the root build. The fuzzer builds with the tests (the lit suite uses it) or with PSEUDO_ENABLE_FUZZER on its own. Set LLVM_RUNTIME_OUTPUT_INTDIR so the lit config can find built tools. Find Python once at the root: add_lit_target builds its command from Python3_EXECUTABLE, which a find_package inside tool/ left unset in test/, so Windows ran lit.py through the file association, detached, and reported success without running anything. - Order the clang libraries after the Pseudo libraries on the test link lines, as tool/CMakeLists.txt already does: libPseudo.a uses clang::Lexer and GNU ld resolves static archives in a single pass. - Fix PseudoModuleTests against unmodified clangd: the registry test checks the registry entry and iterates fromRegistry() (which uses the untyped add, so get<>() can never find the module); ClangdServer-driven tests point the module at the mock file system like their siblings do; the pseudo-only test no longer expects clangd to skip its AST build; the source-parsing tests take the llvm-project path from the build; a path comparison normalizes separators for Windows. - CI: build FileCheck, not, count and LLVMFuzzerCLI as part of the cached clangd build (cache key v2), run `ninja check-clang-pseudo` on Linux, macOS and Windows, remove `|| true` and the skip branch, enable tests on Windows. Normalize CLANGD_INCLUDE_DIRS to a CMake-style path: a native Windows path with backslashes is re-parsed as escape sequences by LLVM's macro-based add_unittest. - README: correct the build/test commands and document the test dependencies and the new options. Verified locally against Homebrew LLVM 23.1.0 with llvmorg-23.1.0 sources: check-clang-pseudo runs 148 tests (30 lit cases, ClangPseudoTests 46, PseudoModuleTests 72), all passing.
de59706 to
1af9e11
Compare
|
Second round addressed in the updated commit (still a single commit):
Local run: 148/148 on the full suite, plus the skip path verified by configuring against a clangd tree without |
ArcsinX
left a comment
There was a problem hiding this comment.
LGTM! All previous review comments have been properly addressed, the configure fallback/skip logic is clean and robust, and the test suite passes across Linux, macOS, and Windows.
Closes #3.
Problem
CI never executed a test. LLVM was built with
LLVM_INCLUDE_TESTS=OFF, sounittests/returned early whenLLVMTestingSupportwas missing, the build step hid that behind|| true,PseudoModuleTests(72 tests) was never compiled, andtest/,fuzzer/andbenchmarks/were not referenced from the root CMake and linked target names that no longer exist.Changes
cmake/LLVMTestingLibs.cmake: buildsllvm_gtest,llvm_gtest_main,LLVMTestingSupportandLLVMTestingAnnotationsfrom an llvm-project source tree when the LLVM package does not export them. The tree is derived fromCLANGD_INCLUDE_DIRSor set withPSEUDO_LLVM_SOURCE_DIR.PSEUDO_ENABLE_TESTSdefaults to ON when these dependencies are found and OFF otherwise, so a plain configure still builds the plugin; with tests ON, a missing dependency is a configure error instead of a silent skip.obj.clangd_pseudo, linked by bothclangd_pseudo(MODULE) andPseudoModuleTests. The test also compiles clangd's own scaffolding (TestFS,TestTU,SyncAPI,LSPClient,TestIndex,Annotations) and gets aFeatures.inc, reused from the LLVM build tree when present and configured from the template otherwise.clangd/PluginSymbols.cpp: the definitions that exist only because the plugin is loaded into an unmodified clangd (Windows fallbacks forLSPError::ID,DefaultRankingModel,charinfo::InfoTable; the weakErrorInfoBasetypeinfo; the ABI-check variable) move out ofPseudoModule.cppinto a file compiled only into the MODULE target. Linked next to the realclangDaemon.libthey were duplicate definitions. They are plain definitions rather thanselectany, since/Zc:inlinedrops COMDAT data that nothing in the same translation unit references.test/,fuzzer/,benchmarks/are wired into the root build, with target names corrected. The fuzzer builds with the tests (the lit suite uses it) or on its own withPSEUDO_ENABLE_FUZZER; benchmarks are behindPSEUDO_ENABLE_BENCHMARKS. Lit runs from the source tree'slit.py;LLVM_RUNTIME_OUTPUT_INTDIRis set so the lit config can find built tools. Python is found once at the root, becauseadd_lit_targetbuilds its command fromPython3_EXECUTABLEandfind_packageresults are directory-scoped.tool/CMakeLists.txtalready does, sincelibPseudo.ausesclang::Lexerand GNU ld resolves static archives in a single pass.PseudoModuleTestsfixes against unmodified clangd (four tests encoded behaviour only a forked clangd could satisfy):fromRegistry(), since upstream's untypedaddmakesget<>()unreachable;ClangdServer-driven tests callsetFSForTesting, as seventeen sibling tests already do;FileCheck,not,countandLLVMFuzzerCLIas part of the cached clangd build (cache key v2), runsninja check-clang-pseudoon Linux, macOS and Windows, removes|| trueand the skip branch, enables tests on Windows.CLANGD_INCLUDE_DIRSis normalized to a CMake-style path, since a native Windows path with backslashes is re-parsed as escape sequences by LLVM's macro-basedadd_unittest.Verification
Local, against Homebrew LLVM 23.1.0 with
llvmorg-23.1.0sources, from a clean build directory:ClangPseudoTestsPseudoModuleTestscheck-clang-pseudoAlso checked: configuring without an llvm-project tree fails with a clear message, and
-DPSEUDO_ENABLE_TESTS=OFFstill configures.On CI, each platform's
check-clang-pseudostep prints the lit summary with the test count, so a job is green only when the suite ran.