#!/bin/sh # Bateria de testes do reiserfsprogs, executada DENTRO do guest. # Espera receber o codigo-fonte em $SRC (padrao: /root/rfs). # # Uso (dentro da VM): # SRC=/root/rfs sh run_tests.sh set -u SRC=${SRC:-/root/rfs} PASS=0 FAIL=0 ok() { echo "PASS: $1"; PASS=$((PASS + 1)); } bad() { echo "FAIL: $1"; FAIL=$((FAIL + 1)); } cd "$SRC" || { echo "FAIL: $SRC nao existe"; exit 1; } echo "=== ambiente ===" uname -srm echo "CC=${CC:-cc}" ${CC:-cc} --version 2>/dev/null | head -1 || echo "sem ${CC:-cc}" ldd --version 2>&1 | head -1 echo echo "=== 1. bootstrap + build com -Wall -Wextra ===" make distclean >/dev/null 2>&1 if ./autogen.sh >/tmp/ag.log 2>&1 && ./configure --enable-warnings >/tmp/cfg.log 2>&1 \ && make -j"$(nproc 2>/dev/null || echo 2)" >/tmp/mk.log 2>&1; then ok "autogen.sh + configure + make" else bad "build" echo "--- configure ---"; tail -15 /tmp/cfg.log echo "--- make ---"; tail -25 /tmp/mk.log echo echo "RESULTADO: $PASS passaram, $FAIL falharam" exit 1 fi # grep -c retorna 1 quando nao ha ocorrencias; capturar so a primeira linha WARN=$(grep -c "warning:" /tmp/mk.log 2>/dev/null | head -1) WARN=${WARN:-0} if [ "$WARN" = "0" ]; then ok "0 warnings com -Wall -Wextra" else bad "$WARN warnings" grep "warning:" /tmp/mk.log | head -10 fi echo echo "=== 2. mkfs ===" rm -f /tmp/t.img dd if=/dev/zero of=/tmp/t.img bs=1M count=64 status=none 2>/dev/null if ./mkreiserfs/mkreiserfs -f -q -l TESTVOL /tmp/t.img >/dev/null 2>&1; then ok "mkreiserfs" else bad "mkreiserfs" fi echo echo "=== 3. reiserfsck --check ===" if ./fsck/reiserfsck --check -f -q -y /tmp/t.img 2>&1 | grep -q "No corruptions found"; then ok "reiserfsck --check" else bad "reiserfsck --check" fi echo echo "=== 4. debugreiserfs -S ===" if ./debugreiserfs/debugreiserfs -S /tmp/t.img 2>&1 | grep -q "Filesystem state: consistent"; then ok "debugreiserfs -S" else bad "debugreiserfs -S" fi echo echo "=== 5. reiserfstune -l ===" if ./tune/reiserfstune -l NEWLABEL -f /tmp/t.img >/dev/null 2>&1; then ok "reiserfstune -l" else bad "reiserfstune -l" fi echo echo "=== 6. resize 128M -> 256M ===" rm -f /tmp/big.img dd if=/dev/zero of=/tmp/big.img bs=1M count=128 status=none 2>/dev/null ./mkreiserfs/mkreiserfs -f -q /tmp/big.img >/dev/null 2>&1 truncate -s 256M /tmp/big.img if ./resize_reiserfs/resize_reiserfs -s +128M -f /tmp/big.img 2>&1 \ | grep -q "Resizing finished successfully"; then ok "resize_reiserfs" else bad "resize_reiserfs" fi echo echo "=== 7. fsck pos-resize ===" if ./fsck/reiserfsck --check -f -q -y /tmp/big.img 2>&1 | grep -q "No corruptions found"; then ok "fsck apos resize" else bad "fsck apos resize" fi echo echo "=== 8. rollback (save/restore/reject) ===" cp /tmp/t.img /tmp/rb.img rm -f /tmp/rb.dat ./fsck/reiserfsck --fix-fixable -y -q -R /tmp/rb.dat /tmp/rb.img >/dev/null 2>&1 if [ -f /tmp/rb.dat ]; then ok "rollback file criado" else bad "rollback file nao criado" fi if ./fsck/reiserfsck --rollback-fsck-changes -y -q -R /tmp/rb.dat /tmp/rb.img 2>&1 \ | grep -q "blocks restored"; then ok "rollback-fsck-changes" else bad "rollback-fsck-changes" fi head -c 100 /dev/urandom > /tmp/rollback-invalido.dat if ./fsck/reiserfsck --rollback-fsck-changes -y -q -R /tmp/rollback-invalido.dat /tmp/rb.img 2>&1 \ | grep -q "does not look like a rollback file"; then ok "rollback com magic invalida rejeitado" else bad "rollback com magic invalida aceito" fi if ./fsck/reiserfsck --rollback-fsck-changes -y -q -R /tmp/nao-existe.dat /tmp/rb.img 2>&1 \ | grep -q "Cannot stat rollback file"; then ok "rollback inexistente rejeitado" else bad "rollback inexistente aceito" fi echo echo "RESULTADO: $PASS passaram, $FAIL falharam" [ "$FAIL" -eq 0 ]