Skip to content

Commit 9e35931

Browse files
feat(wasm): validate pipeline with Docker E2E CI and 15 Juliet cases
- Add e2e-wasm job to GitHub Actions (build + run integration tests inside Docker) - Install WABT/wasi-sdk in CI and symlink KLEE runtime/compiler-rt files - Add MAP2CHECK_DYNAMIC_LINK CMake option for shared-library builds - Restore WasmRuntimeStubs as default build target when wasm-rt.h is present - Fix entrypoint regex in test_wasm_entrypoint.sh for hex-encoded names - Update Juliet compile script to 15 CWE-121/122/124/126/127 cases - Add wasm_results_v2.csv: 15/15 FALSE with 290s timeout - Update skill and migration docs with actual WASM status
1 parent 604323a commit 9e35931

10 files changed

Lines changed: 211 additions & 53 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,88 @@ jobs:
191191
# Known: BTree.c:276 off-by-one (tracked for fix in Phase 2)
192192
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=0"
193193
run: cd build && ctest --output-on-failure
194+
195+
# ===========================================================
196+
# Job 4: WASM End-to-End Tests (Docker)
197+
# ===========================================================
198+
# Runs the full pipeline inside the published map2check-dev image,
199+
# which already contains LLVM 16 + KLEE 3.1 + WABT + wasi-sdk.
200+
# This catches regressions that unit tests miss (KLEE flags,
201+
# isRequired, target function, wasm-rt linking, etc.).
202+
e2e-wasm:
203+
name: WASM E2E Tests (Docker)
204+
runs-on: ubuntu-22.04
205+
timeout-minutes: 45
206+
needs: [build-and-test]
207+
208+
steps:
209+
- name: Checkout
210+
uses: actions/checkout@v4
211+
with:
212+
submodules: recursive
213+
214+
- name: Free disk space
215+
run: |
216+
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
217+
sudo docker image prune -a -f || true
218+
219+
- name: Pull map2check-dev image
220+
run: docker pull ghcr.io/hbgit/map2check-dev:latest
221+
222+
- name: Build + install Map2Check in container
223+
run: |
224+
docker run --rm \
225+
-v "${{ github.workspace }}:/workspace" \
226+
-w /workspace \
227+
-e CC=/usr/bin/clang-16 \
228+
-e CXX=/usr/bin/clang++-16 \
229+
ghcr.io/hbgit/map2check-dev:latest bash -c '
230+
# Install WABT + wasi-sdk (published image lacks them)
231+
if [ ! -f /opt/wabt-1.0.41/include/wasm-rt.h ]; then
232+
wget -q "https://github.com/WebAssembly/wabt/releases/download/1.0.41/wabt-1.0.41-linux-x64.tar.gz" -O /tmp/wabt.tar.gz
233+
tar xzf /tmp/wabt.tar.gz -C /opt && rm /tmp/wabt.tar.gz
234+
ln -sf /opt/wabt-1.0.41/bin/wasm2c /usr/local/bin/wasm2c
235+
fi
236+
if [ ! -d /opt/wasi-sdk-33.0-x86_64-linux ]; then
237+
wget -q "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-33/wasi-sdk-33.0-x86_64-linux.tar.gz" -O /tmp/wasi-sdk.tar.gz
238+
tar xzf /tmp/wasi-sdk.tar.gz -C /opt && rm /tmp/wasi-sdk.tar.gz
239+
fi
240+
241+
# Build and install to a release-style layout
242+
rm -rf build_e2e install_e2e
243+
mkdir -p build_e2e && cd build_e2e
244+
cmake .. -G Ninja \
245+
-DLLVM_DIR=/usr/lib/llvm-16/lib/cmake/llvm \
246+
-DENABLE_TEST=ON \
247+
-DMAP2CHECK_DYNAMIC_LINK=ON \
248+
-DCMAKE_INSTALL_PREFIX=/workspace/install_e2e
249+
ninja
250+
ninja install
251+
252+
# Symlink KLEE runtime + compiler-rt files missing from install rules
253+
mkdir -p /workspace/install_e2e/lib/klee
254+
ln -sf /opt/klee/lib/klee/runtime /workspace/install_e2e/lib/klee/runtime
255+
ln -sf /usr/lib/llvm-16/lib/clang /workspace/install_e2e/lib/clang
256+
'
257+
258+
- name: Run WASM integration tests
259+
run: |
260+
docker run --rm \
261+
-v "${{ github.workspace }}:/workspace" \
262+
-w /workspace \
263+
-e MAP2CHECK_PATH=/workspace/install_e2e \
264+
-e WASI_SDK_PATH=/opt/wasi-sdk-33.0-x86_64-linux \
265+
ghcr.io/hbgit/map2check-dev:latest bash -c '
266+
# Ensure WABT + wasi-sdk are available in this fresh container
267+
if [ ! -f /opt/wabt-1.0.41/include/wasm-rt.h ]; then
268+
wget -q "https://github.com/WebAssembly/wabt/releases/download/1.0.41/wabt-1.0.41-linux-x64.tar.gz" -O /tmp/wabt.tar.gz
269+
tar xzf /tmp/wabt.tar.gz -C /opt && rm /tmp/wabt.tar.gz
270+
ln -sf /opt/wabt-1.0.41/bin/wasm2c /usr/local/bin/wasm2c
271+
fi
272+
if [ ! -d /opt/wasi-sdk-33.0-x86_64-linux ]; then
273+
wget -q "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-33/wasi-sdk-33.0-x86_64-linux.tar.gz" -O /tmp/wasi-sdk.tar.gz
274+
tar xzf /tmp/wasi-sdk.tar.gz -C /opt && rm /tmp/wasi-sdk.tar.gz
275+
fi
276+
bash tests/integration/test_wasm_pipeline.sh
277+
bash tests/integration/test_wasm_entrypoint.sh
278+
'

‎.opencode/skills/map2check-sbseg2026/SKILL.md‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ When you ask about a topic not covered below, I will read the relevant chapter f
4848
| 4 | ~~WASM PoC E2E (1.7.3)~~ | ~~Alta~~ | ~~Seção WASM~~ | ✅ **Concluído** |
4949
| 5 | ~~WASM MemoryTrackPass (1.7.4)~~ | ~~Alta~~ | ~~PoC E2E~~ | ✅ **Concluído** |
5050
| 6 | ~~WASM CLI --wasm (1.7.5)~~ | ~~Alta~~ | ~~1.7.4~~ | ✅ **Concluído** |
51-
| 7 | ~~WASM Juliet benchmarks (1.7.6)~~ | ~~Média~~ | ~~1.7.5~~ | ✅ **Concluído** |
52-
| 8 | ~~WASM seção artigo (1.7.7)~~ | ~~Média~~ | ~~1.7.6~~ | ✅ **Concluído** |
51+
| 7 | WASM Juliet benchmarks (1.7.6) | Média | 1.7.5 | ✅ Concluído — 15 casos, 15/15 FALSE (com timeout 290s) |
52+
| 8 | WASM seção artigo (1.7.7) | Média | 1.7.6 | 🟡 Em andamento — texto base no artigo, falta figura final |
5353
| 9 | Gravação do vídeo técnico | **Média** | Seção 5 (Demonstração) | usuário |
5454
| 10 | Validação do build por terceiro (CTA) | **Baixa** | Checklist de artefato | usuário |
5555
| 11 | Ajustes do orientador no artigo | **Alta** | Submissão | usuário |
@@ -61,7 +61,7 @@ When you ask about a topic not covered below, I will read the relevant chapter f
6161
| **Disponibilidade** | Repositório público + Docker image (GHCR) |
6262
| **Funcionalidade** | Build passa + 7/7 unit tests + 9/9 passes carregando |
6363
| **Reprodutibilidade** | Dockerfile.dev (Ubuntu 22.04) + scripts de benchmark |
64-
| **Sustentabilidade** | CI/CD (GitHub Actions), static analysis (clang-tidy, cppcheck), sanitizers (ASAN/UBSAN/TSAN), docs atualizados |
64+
| **Sustentabilidade** | CI/CD (GitHub Actions): build, unit tests, static analysis, sanitizers, e novo job E2E com Docker; docs atualizados |
6565

6666
## 📊 Consolidated Data
6767

@@ -98,12 +98,14 @@ WASM Pipeline:
9898
WasmRuntimeStubs:✅ KLEE-friendly (calloc/free), wasm_rt_trap → map2check_error
9999
Wrapper auto: ✅ generateWasmWrapperStatic() — main() → wasm bridge
100100
Bounds check: ✅ Per-allocation via dlmalloc interception (w2c_*_dlmalloc/dlfree)
101-
3/3 heap Juliet FALSE, 12 stack UNK (gap documentado)
102-
Juliet benchmarks:✅ 15 casos (CWE-121 a 127), 3 FALSE heap, 12 UNK stack
103-
Integration tests:✅ tests/integration/test_wasm_{pipeline,entrypoint}.sh
104-
Seção no artigo: ✅ Sec 4 + tabela + explicação do gap linear memory
101+
implementado e validado
102+
Juliet benchmarks:✅ 15 casos (CWE-121/122/124/126/127), 15/15 FALSE
103+
timeout 110s → UNKNOWN; timeout 290s → FALSE
104+
Integration tests:✅ tests/integration/test_wasm_{pipeline,entrypoint}.sh (3/3 + 3/3)
105+
Seção no artigo: 🟡 Texto base em main.tex, figura pipeline pendente
105106
KLEE E2E: ✅ Pipeline completo: .wasm → LLVM IR → Passes → KLEE → FALSE
106107
CI build: ✅ find_path corrigido, WasmRuntimeStubs opcional
108+
CI E2E: ✅ Novo job e2e-wasm executa integração dentro do Docker
107109
```
108110

109111
## 🖼️ Figure Inventory
@@ -149,7 +151,7 @@ O mapeamento torna resultados de verificação formal acionáveis para times de
149151
**Não é fracasso, é sinal de onde investir.** Causas: timeout 300s insuficiente, path exploration do KLEE não otimizada, solver SMT (Z3) sem tuning. Cada ponto percentual reduzido de UNKNOWN é ganho real de cobertura.
150152

151153
### Testes Unitários são Necessários mas Insuficientes
152-
**7/7 unit tests passando e 3 bugs críticos escaparam.** Os bugs (KLEE flags, isRequired, target function) só foram detectados por smoke tests manuais. **Testes de integração E2E (compile → instrument → link → execute) no CI são indispensáveis.**
154+
**7/7 unit tests passando e 3 bugs críticos escaparam.** Os bugs (KLEE flags, isRequired, target function) só foram detectados por smoke tests manuais. **Testes de integração E2E (compile → instrument → link → execute) no CI são indispensáveis.** No WASM, 8 commits consecutivos de "fix(ci)" tentaram fazer o CI passar sem executar KLEE; o job `e2e-wasm` baseado em Docker foi criado justamente para quebrar esse ciclo.
153155

154156
### WASM como Próximo Vetor de Growth
155157
**Pipeline LLVM 16 estendido para WebAssembly.** Memory safety em runtimes WASM (Wasmtime, Wasmer) é uma nova classe de bugs. Feature implementada e funcional — NÃO é trabalho futuro, aparece no paper com resultados da Juliet.

‎.opencode/skills/map2check-sbseg2026/chapters/ch04-ciberseguranca.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ O Map2Check 2026 foi validado no TestComp 2026 (Heap: 594 tasks, score 57, 56 bu
2626
- **Smoke test validado**: `array-1.c` → TRUE (VERIFICATION SUCCEEDED), `array-2.c` → FALSE + counter-example `nondet_int → 31763`
2727
- **WASM pipeline**: `.wasm → wasm2c (WABT 1.0.41) → .c → clang-16 → .bc → passes → KLEE`
2828
- **wasi-sdk 33.0**: toolchain para compilar C → WASM com target `wasm32-wasip1`
29+
- **Per-allocation bounds check WASM**: MemoryTrackPass intercepta `w2c_*_dlmalloc`/`dlfree` e injeta `map2check_wasm_check_access` em loads/stores
30+
- **Juliet WASM**: 15 casos validados (CWE-121/122/124/126/127); 15/15 FALSE com timeout 290s
31+
- **Linear memory gap**: heap detectável via dlmalloc; stack/globals sem alocador visível → inviável no MVP (mas Juliet stack/underread também foram detectados)
2932

3033
## Mental Models
3134
- Use **UNKNOWN como KPI de engenharia**: 45.6% não é fracasso, é direcionamento — timeout tuning, estratégias de solver, path exploration heuristics
@@ -37,6 +40,7 @@ O Map2Check 2026 foi validado no TestComp 2026 (Heap: 594 tasks, score 57, 56 bu
3740
- **Confiar apenas em unit tests**: 7/7 passando e ainda assim 3 inconsistências NPM escaparam → testes E2E são indispensáveis
3841
- **Usar gráfico de pizza sem baseline**: comparar TRUE/FALSE/UNKNOWN sem baseline de concorrente não agrega — usar tabela numérica
3942
- **Tratar WASM como "trabalho futuro"**: pipeline funcional (lifting validado), feature em desenvolvimento ativo — reportar como contribuição em andamento
43+
- **Fazer o CI passar sem executar KLEE**: 8 commits consecutivos adaptando include paths e tornando WasmRuntimeStubs opcional deram green checkmark, mas não validaram o pipeline real — job Docker E2E necessário
4044

4145
## 3 Inconsistências Corrigidas na Migração
4246

@@ -66,8 +70,10 @@ Counter-example: nondet_int() → 31763, line 19, main
6670
1. TestComp 2026 Heap: 594 tasks, score 57, 56 bugs reais (9.4% FALSE), 45.6% UNKNOWN
6771
2. Mapeamento CWE: 5 propriedades SV-COMP → 5 CWEs + técnica empregada — acionável por times AppSec
6872
3. 3 inconsistências NPM corrigidas: KLEE flags, passes ignorados, target function — indetectáveis por unit tests
69-
4. WASM: pipeline funcional (wasm2c 1.0.41 + wasi-sdk 33.0), lifting validado, passes em adaptação
70-
5. Smoke tests canônicos (`array-1.c` TRUE, `array-2.c` FALSE) validam pipeline E2E em segundos
73+
4. WASM: pipeline funcional (wasm2c 1.0.41 + wasi-sdk 33.0), lifting validado, per-allocation bounds check implementado
74+
5. Juliet WASM: 15 casos (CWE-121/122/124/126/127), 15/15 FALSE com timeout 290s
75+
6. Timeout é KPI de engenharia: 110s → UNKNOWN, 290s → FALSE nos casos Juliet WASM
76+
7. Smoke tests canônicos (`array-1.c` TRUE, `array-2.c` FALSE) validam pipeline E2E em segundos
7177

7278
## Connects To
7379
- **Ch 3**: Arquitetura — cada pass da seção 3 mapeia para CWE e resultado TestComp

‎CMakeLists.txt‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ option(SKIP_KLEE "Don't use KLEE" OFF)
77
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)
10+
option(MAP2CHECK_DYNAMIC_LINK "Link dynamically (required when KLEE/Z3 are only available as shared libraries)" OFF)
1011

1112
set(CMAKE_CXX_STANDARD 17)
1213
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -23,10 +24,17 @@ if(MAP2CHECK_ENABLE_SANITIZERS)
2324
# ASan requires dynamic linking — skip static config
2425
set(Map2Check_MODE "SHARED")
2526
else()
26-
# --- Static linking configuration ---
27-
set(Map2Check_MODE "STATIC")
28-
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
29-
set(CMAKE_EXE_LINKER_FLAGS "-Bstatic -static-libgcc -static-libstdc++")
27+
if(MAP2CHECK_DYNAMIC_LINK)
28+
# --- Dynamic linking configuration ---
29+
# Use this when dependencies (Z3, STP, KLEE) are only available as .so
30+
set(Map2Check_MODE "SHARED")
31+
message(STATUS "Dynamic linking enabled (MAP2CHECK_DYNAMIC_LINK=ON)")
32+
else()
33+
# --- Static linking configuration ---
34+
set(Map2Check_MODE "STATIC")
35+
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
36+
set(CMAKE_EXE_LINKER_FLAGS "-Bstatic -static-libgcc -static-libstdc++")
37+
endif()
3038
endif()
3139

3240
# --- Core dependencies ---

0 commit comments

Comments
 (0)