Skip to content

Commit 49954ad

Browse files
Merge pull request #57 from hbgit/feat/castle-juliet-baseline
Bring the Test-Comp conformance work into develop (follow-up to #55/#56)
2 parents 350ddbb + 6eecbda commit 49954ad

51 files changed

Lines changed: 5896 additions & 160 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 150 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@
1111
name: CI
1212

1313
on:
14+
# Push cobre só as branches de integração. O filtro antigo listava 'feat-*'
15+
# com hífen, que nunca casou com a convenção real (feat/castle-juliet-baseline,
16+
# feat/testcomp-conformance) -- então nenhum push de branch era verificado, e
17+
# todo run verde até aqui veio do gatilho pull_request.
18+
#
19+
# Branches de feature ficam cobertas pelo pull_request abaixo, e não por push,
20+
# para não disparar dois runs idênticos a cada push numa branch com PR aberta.
1421
push:
15-
branches: [develop, main, master, 'feat-*']
16-
pull_request:
1722
branches: [develop, main, master]
23+
# Inclui feat/** como ALVO para que PRs empilhadas sejam verificadas. Sem isso
24+
# uma PR cuja base é outra branch de feature não dispara nada -- a #56 abriu
25+
# com um único check -- e os gates de regressão que ela própria adiciona nunca
26+
# rodariam nela.
27+
pull_request:
28+
branches: [develop, main, master, 'feat/**']
1829

1930
jobs:
2031
# ===========================================================
@@ -351,6 +362,143 @@ jobs:
351362
bash tests/integration/test_castle_regression.sh
352363
bash tests/integration/test_main_argv.sh
353364
bash tests/integration/test_modes.sh
365+
bash tests/integration/test_add_invariants.sh
366+
bash tests/integration/test_test_suite_emission.sh
367+
'
368+
369+
# ===========================================================
370+
# Job: Invariants — o contrato do --add-invariants
371+
# ===========================================================
372+
# Roda o MESMO teste em qualquer estado em que a imagem esteja. Enquanto a
373+
# imagem publicada não trouxer o Clam, ele afirma que a flag falha alto
374+
# (issue #54). Quando a imagem passar a trazê-lo, o mesmo teste afirma que a
375+
# flag tem sucesso E injeta verifier.assume. A linha CAPABILITY no log diz
376+
# qual contrato foi verificado, então a volta da capacidade fica visível em
377+
# vez de inferida.
378+
#
379+
# Nenhum check vermelho é estacionado de propósito: um check que se espera
380+
# vermelho passa a ser ignorado, e aí ninguém percebe o dia em que fica verde.
381+
invariants-clam:
382+
name: Invariants (Clam)
383+
runs-on: ubuntu-22.04
384+
timeout-minutes: 25
385+
needs: [build-and-test]
386+
387+
steps:
388+
- name: Checkout
389+
uses: actions/checkout@v4
390+
with:
391+
submodules: recursive
392+
393+
- name: Free disk space
394+
run: |
395+
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
396+
sudo docker image prune -a -f || true
397+
398+
- name: Pull map2check-dev image
399+
run: docker pull ghcr.io/hbgit/map2check-dev:latest
400+
401+
- name: Build with -DENABLE_CLAM=ON
402+
run: |
403+
docker run --rm \
404+
-u root \
405+
-v "${{ github.workspace }}:/workspace" \
406+
-w /workspace \
407+
-e CC=/usr/bin/clang-16 \
408+
-e CXX=/usr/bin/clang++-16 \
409+
ghcr.io/hbgit/map2check-dev:latest bash -c '
410+
rm -rf build_clam_ci install_clam_ci
411+
mkdir -p build_clam_ci && cd build_clam_ci
412+
cmake .. -G Ninja \
413+
-DLLVM_DIR=/usr/lib/llvm-16/lib/cmake/llvm \
414+
-DENABLE_CLAM=ON \
415+
-DMAP2CHECK_DYNAMIC_LINK=ON \
416+
-DCMAKE_INSTALL_PREFIX=/workspace/install_clam_ci
417+
ninja
418+
ninja install
419+
mkdir -p /workspace/install_clam_ci/lib/klee
420+
ln -sf /opt/klee/lib/klee/runtime /workspace/install_clam_ci/lib/klee/runtime
421+
ln -sf /usr/lib/llvm-16/lib/clang /workspace/install_clam_ci/lib/clang
422+
'
423+
424+
- name: Assert the --add-invariants contract
425+
run: |
426+
docker run --rm \
427+
-u root \
428+
-v "${{ github.workspace }}:/workspace" \
429+
-w /workspace \
430+
-e MAP2CHECK_PATH=/workspace/install_clam_ci \
431+
ghcr.io/hbgit/map2check-dev:latest bash -c '
432+
bash tests/integration/test_add_invariants.sh
433+
'
434+
435+
# ===========================================================
436+
# Job: Test-Comp conformance — o validador oficial
437+
# ===========================================================
438+
# Afirma que uma suíte emitida REPRODUZ o bug, que é o que a competição
439+
# pontua. A validade estrutural do XML é afirmada à parte, pelo
440+
# test_test_suite_emission.sh no job do CASTLE — uma suíte pode ser
441+
# perfeitamente bem formada e valer zero ponto.
442+
#
443+
# Note que o TestCov sai com código 0 tanto quando cobre quanto quando não
444+
# cobre; o veredito está na linha "Result:". Ver
445+
# tests/testcomp/NOTES-testcov-output.md.
446+
testcov-gate:
447+
name: Test-Comp Validation (TestCov)
448+
runs-on: ubuntu-22.04
449+
timeout-minutes: 25
450+
needs: [build-and-test]
451+
452+
steps:
453+
- name: Checkout
454+
uses: actions/checkout@v4
455+
with:
456+
submodules: recursive
457+
458+
- name: Free disk space
459+
run: |
460+
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
461+
sudo docker image prune -a -f || true
462+
463+
- name: Pull map2check-dev image
464+
run: docker pull ghcr.io/hbgit/map2check-dev:latest
465+
466+
- name: Build + install Map2Check in container
467+
run: |
468+
docker run --rm \
469+
-u root \
470+
-v "${{ github.workspace }}:/workspace" \
471+
-w /workspace \
472+
-e CC=/usr/bin/clang-16 \
473+
-e CXX=/usr/bin/clang++-16 \
474+
ghcr.io/hbgit/map2check-dev:latest bash -c '
475+
rm -rf build_testcov_ci install_testcov_ci
476+
mkdir -p build_testcov_ci && cd build_testcov_ci
477+
cmake .. -G Ninja \
478+
-DLLVM_DIR=/usr/lib/llvm-16/lib/cmake/llvm \
479+
-DMAP2CHECK_DYNAMIC_LINK=ON \
480+
-DCMAKE_INSTALL_PREFIX=/workspace/install_testcov_ci
481+
ninja
482+
ninja install
483+
mkdir -p /workspace/install_testcov_ci/lib/klee
484+
ln -sf /opt/klee/lib/klee/runtime /workspace/install_testcov_ci/lib/klee/runtime
485+
ln -sf /usr/lib/llvm-16/lib/clang /workspace/install_testcov_ci/lib/clang
486+
'
487+
488+
- name: Run TestCov over the conformance corpus
489+
run: |
490+
docker run --rm \
491+
-u root \
492+
-v "${{ github.workspace }}:/workspace" \
493+
-w /workspace \
494+
-e MAP2CHECK_PATH=/workspace/install_testcov_ci \
495+
-e KEEP_WORK=1 \
496+
ghcr.io/hbgit/map2check-dev:latest bash -c '
497+
# zip for the suite archive, gcc/lcov for coverage measurement.
498+
apt-get update -qq
499+
apt-get install -y -qq python3-pip zip gcc lcov
500+
pip3 install --quiet testcov
501+
bash tests/testcomp/run_testcov_suite.sh
354502
'
355503
356504
# ===========================================================

‎.gitignore‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,21 @@ tests/castle/results/
9191
tests/castle/results_v*/
9292
tests/juliet/results*/
9393
tests/baseline-logs/
94+
95+
# Clam invariants build (Phase B)
96+
build_clam_ci/
97+
install_clam_ci/
98+
build_clam/
99+
install_clam/
100+
build_ut/
101+
install_ut/
102+
build_testcov_ci/
103+
install_testcov_ci/
104+
105+
# Local agent tooling and scratch material: ai-memory skill installs, editor
106+
# agent configs, CLAUDE.md backups and the local Test-Comp planning document.
107+
# Same reasoning as test-comp2026/ above -- preparation material, not product.
108+
.agents/
109+
.claude/
110+
.opencode/
111+
CLAUDE.md.bak-*

‎CLAUDE.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ ninja && ninja install
5252
| `ENABLE_TEST` | OFF | Build GTest unit tests |
5353
| `REGRESSION` | OFF | Download regression test benchmarks |
5454
| `MAP2CHECK_ENABLE_SANITIZERS` | OFF | Enable ASan + UBSan (forces dynamic linking) |
55+
| `ENABLE_CLAM` | OFF | Enable `--add-invariants` via Clam (needs Clam in the image) |
56+
57+
`Dockerfile.dev` builds **Clam `dev16`** (the renamed crab-llvm) into `/opt/clam`. It
58+
supplies the abstract-interpretation invariants behind `--add-invariants`, which is
59+
refused with exit code 3 unless the build was configured with `-DENABLE_CLAM=ON` *and*
60+
the driver is present at `$CLAM_DIR/bin/clam.py`. It is opt-in because an unsound
61+
invariant produces a wrong TRUE rather than an error — see
62+
[the dependency review](docs/reports/2026-08-16-crabllvm-review.md).
5563

5664
Enabling sanitizers switches from static to shared linking and enables `-fsanitize=address,undefined -fno-omit-frame-pointer -g`.
5765

‎CMakeLists.txt‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ option(REGRESSION "Prepare Regression Tests" OFF)
88
option(ENABLE_TEST "Build all tests" OFF)
99
option(MAP2CHECK_ENABLE_SANITIZERS "Enable AddressSanitizer + UndefinedBehaviorSanitizer for testing" OFF)
1010
option(MAP2CHECK_DYNAMIC_LINK "Link dynamically (required when KLEE/Z3 are only available as shared libraries)" OFF)
11+
option(ENABLE_CLAM "Enable --add-invariants via Clam (requires Clam dev16 installed, see docs/reports/2026-08-16-crabllvm-review.md)" OFF)
1112

1213
set(CMAKE_CXX_STANDARD 17)
1314
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -38,6 +39,23 @@ else()
3839
set(CMAKE_EXE_LINKER_FLAGS "-Bstatic -static-libgcc -static-libstdc++")
3940
endif()
4041

42+
# --- Abstract-interpretation invariants (Clam, formerly crab-llvm) ---
43+
# Off by default, and deliberately so: an unsound invariant does not raise an
44+
# error, it produces a wrong TRUE. Under KLEE klee_assume() prunes a reachable
45+
# state; under LibFuzzer nondet_assume() calls pthread_exit() and the execution
46+
# disappears. Promoting this to a default needs the differential evidence
47+
# described in docs/reports/2026-08-16-crabllvm-review.md.
48+
#
49+
# Clam is a subprocess tool, not a linked library, so this only records intent.
50+
# The binary still checks at run time that the driver is actually installed --
51+
# neither condition implies the other.
52+
if(ENABLE_CLAM)
53+
add_compile_definitions(MAP2CHECK_ENABLE_CLAM)
54+
message(STATUS "Clam invariants: ENABLED (--add-invariants available)")
55+
else()
56+
message(STATUS "Clam invariants: disabled (-DENABLE_CLAM=ON to enable)")
57+
endif()
58+
4159
# --- Core dependencies ---
4260
include(cmake/FindClang.cmake)
4361
include(cmake/FindBoost.cmake)

‎Dockerfile.dev‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,64 @@ ENV LD_LIBRARY_PATH="/opt/klee/lib"
131131
# ============================================================
132132
# No extra install needed — available via clang-16 -fsanitize=fuzzer
133133

134+
# ============================================================
135+
# 7b. Clam (formerly crab-llvm) — abstract-interpretation invariants
136+
# ============================================================
137+
# Clam rewrites the bitcode, inserting verifier.assume(inv) calls that
138+
# NonDetPass rewrites to map2check_crab_assume and the runtime forwards to
139+
# klee_assume. Branch dev16 targets LLVM 16, which is this image's LLVM.
140+
#
141+
# Built here rather than as a CMake ExternalProject: it is a subprocess tool,
142+
# not a linked library, and building it per configure would add tens of minutes
143+
# to every clean Map2Check build for a capability that is off by default
144+
# (-DENABLE_CLAM=ON). See docs/reports/2026-08-16-crabllvm-review.md.
145+
#
146+
# libzstd-dev is required, not optional: LLVM 16 from apt.llvm.org exports
147+
# zstd::libzstd_shared, so Clam's find_package(LLVM) fails outright without it.
148+
# libflint-dev is NOT needed -- that belongs to the PPLite domain, and no
149+
# optional domain is enabled here: --crab-track=num uses the default interval
150+
# domain, so LDD, Apron, Elina and PPLite would all be dead weight.
151+
RUN apt-get update && apt-get install -y \
152+
libmpfr-dev \
153+
libzstd-dev \
154+
libcurl4-openssl-dev \
155+
&& rm -rf /var/lib/apt/lists/*
156+
157+
# CLAM_INCLUDE_TESTS=OFF: Clam's own lit suite needs `lit` from pip and adds
158+
# build time for tests of a dependency, not of Map2Check.
159+
#
160+
# The crab / extra / build / install sequence is Clam's documented one. Each
161+
# target downloads and installs a dependency (Crab, then sea-dsa and
162+
# llvm-seahorn); the cmake re-run between them re-reads the cache so the next
163+
# step can see what the previous one produced.
164+
RUN git clone --depth 1 -b dev16 https://github.com/seahorn/clam.git /tmp/clam && \
165+
cd /tmp/clam && mkdir build && cd build && \
166+
CLAM_CFG="-DCMAKE_BUILD_TYPE=Release -DCLAM_LLVM_VERSION=16 \
167+
-DCLAM_INCLUDE_TESTS=OFF \
168+
-DLLVM_DIR=/usr/lib/llvm-16/lib/cmake/llvm \
169+
-DCMAKE_INSTALL_PREFIX=/opt/clam" && \
170+
cmake .. $CLAM_CFG && \
171+
cmake --build . --target crab && cmake .. $CLAM_CFG && \
172+
cmake --build . --target extra && cmake .. $CLAM_CFG && \
173+
cmake --build . -j$(nproc) && \
174+
cmake --build . --target install && \
175+
rm -rf /tmp/clam
176+
177+
ENV CLAM_DIR=/opt/clam
178+
179+
# Fail the image build if Clam cannot inject invariants. The flag combination
180+
# below is measured, not assumed: --llvm-pp-loops and --crab-promote-assume
181+
# were both in the legacy crab-llvm invocation and both defeat injection (the
182+
# first drops it to zero, the second rewrites verifier.assume into the
183+
# llvm.assume intrinsic that NonDetPass does not match). A silent zero here is
184+
# what kept --add-invariants dead for years.
185+
RUN printf 'int main(){int i=0,s=0;while(i<10){s+=i;i++;}return s;}\n' > /tmp/clamcheck.c && \
186+
/opt/clam/bin/clam.py -o /tmp/clamcheck.bc -m 64 -g --crab-inter \
187+
--crab-track=num --crab-opt=add-invariants \
188+
--crab-opt-invariants-loc=block-entry /tmp/clamcheck.c && \
189+
test "$(llvm-dis-16 -o - /tmp/clamcheck.bc | grep -c 'verifier\.assume')" -gt 0 && \
190+
echo "Clam injects invariants: OK" && rm -f /tmp/clamcheck.c /tmp/clamcheck.bc
191+
134192
# ============================================================
135193
# 8. WABT (WebAssembly Binary Toolkit) — wasm2c, wasm2wat, wasm-ld
136194
# ============================================================

‎cmake/FindCrabLlvm.cmake‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)