Skip to content

Commit a09877c

Browse files
committed
Add memory leak and corruption tests with valgrind
1 parent 306bf1c commit a09877c

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

test/test.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,50 @@ test_large_random_and_fallback || exit 1
341341
test_duplicate_names_listing || exit 1
342342
test_space_in_name || exit 1
343343
test_large_file || exit 1
344+
345+
# Memory leak tests with Valgrind
346+
check_valgrind() {
347+
command -v valgrind >/dev/null 2>&1 || { echo "Valgrind not found, skipping memory leak tests"; return 1; }
348+
return 0
349+
}
350+
351+
test_valgrind_extract() {
352+
if ! check_valgrind; then return 0; fi
353+
init
354+
echo "[***] Testing extractions under Valgrind"
355+
$MZ -c test.zip hello.txt world.txt -z1
356+
mkdir data
357+
cd data
358+
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 --quiet $MZ -x ../test.zip || error "Valgrind detected leaks in extraction"
359+
cd ..
360+
fini
361+
}
362+
363+
test_valgrind_corrupted() {
364+
if ! check_valgrind; then return 0; fi
365+
init
366+
echo "[***] Testing corrupted archive under Valgrind"
367+
$MZ -c test.zip hello.txt world.txt -z1
368+
dd if=test.zip of=corrupted.zip bs=1 count=100 2>/dev/null
369+
mkdir data
370+
cd data
371+
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 --quiet $MZ -x ../corrupted.zip 2>/dev/null || true
372+
cd ..
373+
fini
374+
}
375+
376+
test_valgrind_cycle() {
377+
if ! check_valgrind; then return 0; fi
378+
init
379+
echo "[***] Testing compression/decompression cycle under Valgrind"
380+
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 --quiet $MZ -c test.zip hello.txt world.txt -z1 || error "Valgrind detected leaks in compression"
381+
mkdir data
382+
cd data
383+
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 --quiet $MZ -x ../test.zip || error "Valgrind detected leaks in extraction"
384+
cd ..
385+
fini
386+
}
387+
388+
test_valgrind_extract || exit 1
389+
test_valgrind_corrupted || exit 1
390+
test_valgrind_cycle || exit 1

0 commit comments

Comments
 (0)