Add a libvirt/KVM test environment and fix the gcc-12 warning it found
build / build (clang, ) (push) Failing after 6s
build / build (gcc, ) (push) Failing after 6s
build / build (gcc, --enable-io-failure-emulation) (push) Failing after 6s
build / build (gcc, --enable-warnings) (push) Failing after 5s

The VM harness (tests/vm/) builds and exercises the tools on real Debian and
Alpine guests, driving the serial console (no sshd/cloud-init dependency).

Results on Debian 12 (glibc 2.36, gcc 12.2): 12/12 checks pass, 0 warnings
with -Wall -Wextra, including a real 128M -> 256M resize and the rollback
save/restore/reject paths.

Results on Alpine 3.20 (musl 1.2.5): the build cannot start. configure stops
at "reiserfsprogs requires a method to add printf modifiers" because
reiserfscore/prints.c depends on glibc's register_printf_specifier(3) and
<printf.h>, which musl does not provide. This is pre-existing and out of
scope here; measured at 341 use sites across 20+ files, all routed through
reiserfs_warning()/reiserfs_info(). Documented in tests/vm/RESULTS.md.

Fix the one real defect the harness surfaced:

fsck/semantic_check.c: check_check_regular_file() is called with NULL for
new_ih (line 466), so the block that would fill *new_ih is unreachable and
check_semantic_pass() never returns RELOCATED through that path. The
"case RELOCATED:" arm still reads relocated_ih.ih_key, which gcc 12.2
reports as "may be used uninitialized" (-Wmaybe-uninitialized); gcc 16 does
not, because it proves the path dead. Zero-initialise the struct and say why.

Verified: 0 warnings on gcc 12.2 after the change, and the Debian battery
stays at 12/12.
This commit is contained in:
lgcosta committed 2026-11-12 00:11:31 -03:00
1 parent 293e6a7280
commit 5a7382185b
8 files changed
+628 -1

No files matched your search

+85
View File
@@ -0,0 +1,85 @@
# Ambiente de testes em VM
Este documento descreve o ambiente de validação do reiserfsprogs em máquinas
virtuais (libvirt/KVM), usado para exercitar o build e as ferramentas em
distribuições diferentes da máquina de desenvolvimento.
O ambiente é **efêmero**: as VMs ficam em `/var/tmp/vmtest` e não fazem parte
do repositório. Os scripts que o reproduzem estão em `tests/vm/`.
## Requisitos do host
| Componente | Verificação |
|---|---|
| KVM | `ls -l /dev/kvm` |
| libvirt (user session) | `virsh -c qemu:///session list --all` |
| `virt-install`, `qemu-img` | `which virt-install qemu-img` |
| `guestfs-tools` (offline) | `which virt-customize` |
| `mkisofs` ou `xorriso` | `which mkisofs xorriso` |
No Fedora: `sudo dnf install libvirt-daemon-kvm qemu-kvm virt-install
guestfs-tools genisoimage`.
O ambiente usa **qemu:///session** (sem root). Não requer a rede `default`
do libvirt: a conectividade vem do backend `passt` em modo *user*.
## Topologia
```mermaid
graph LR
H[host] -->|qemu:///session| D[rfs-debian<br/>Debian 12 · gcc]
H -->|qemu:///session| A[rfs-alpine<br/>Alpine 3.20 · gcc/musl]
D -->|passt :2222| S[ssh opcional]
A -->|passt| S
H -->|attach-disk| V[vdb: fontes + run_tests.sh]
```
Cada VM recebe:
* imagem cloud (qcow2) redimensionada para 8 GiB;
* um disco de dados `vdb` (ext4) com `rfs-src.tar.gz` e `run_tests.sh`;
* acesso por **console serial** (pty do libvirt), que é o canal de
automação usado — independente de rede.
## Por que console serial e não SSH
Nas imagens cloud o `sshd` demora a subir e o `cloud-init` nem sempre aplica
a senha (o datasource NoCloud exige rótulo `cidata` e o CD precisa estar no
Barramento certo). O console serial está disponível assim que o getty sobe e
é suficiente para: autenticar, copiar arquivos (já estão no `vdb`) e rodar
qualquer comando. Por isso o `tests/vm/guestcmd.py` dirige o pty.
## Ciclo de uso
```sh
cd tests/vm
# 1. preparar imagens e VMs (uma vez)
./setup_env.sh
# 2. rodar a bateria em uma VM
./run_in_vm.sh rfs-alpine
./run_in_vm.sh rfs-debian
# 3. destruir tudo
./teardown_env.sh
```
## O que a bateria cobre (`tests/vm/run_tests.sh`)
Executado **dentro** do guest, sobre o código extraído do `vdb`:
1. `autogen.sh && configure --enable-warnings && make -j` — build limpo;
2. contagem de warnings (esperado: 0);
3. `mkreiserfs` em imagem de 64 MiB;
4. `reiserfsck --check` (esperado: *No corruptions found*);
5. `debugreiserfs -S` (superblock consistente);
6. `reiserfstune -l` (troca de label);
7. `resize_reiserfs` 128 MiB → 256 MiB;
8. `reiserfsck` pós-resize;
9. rollback: `-R` grava, `--rollback-fsck-changes` restaura, arquivo
inválido é rejeitado.
## Resultados obtidos
Ver `tests/vm/RESULTS.md`.