11.3SriastradPROG= vndcompress 21.6SriastradSRCS= main.c offtab.c utils.c vndcompress.c vnduncompress.c 31.3Sriastrad 41.3SriastradLINKS= ${BINDIR}/vndcompress ${BINDIR}/vnduncompress 51.3SriastradMLINKS= vndcompress.1 vnduncompress.1 61.1Shubertf 71.3SriastradDPADD+= ${LIBZ} 81.1ShubertfLDADD+= -lz 91.1Shubertf 101.8SriastradWARNS= 5 111.8Sriastrad 121.1Shubertf.include <bsd.prog.mk> 131.3Sriastrad 141.3SriastradTESTFILES+= oneblock 151.3SriastradXFAIL+= oneblock.in-outx 161.3SriastradXFAIL+= oneblock.cl2-cl2x 171.3Sriastradoneblock.in: 181.3Sriastrad head -c 512 < /usr/share/dict/words > ${.TARGET}.tmp \ 191.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 201.3Sriastrad 211.3SriastradTESTFILES+= tenblock 221.3SriastradXFAIL+= tenblock.in-outx 231.3SriastradXFAIL+= tenblock.cl2-cl2x 241.3Sriastradtenblock.in: 251.3Sriastrad head -c 5120 < /usr/share/dict/words > ${.TARGET}.tmp \ 261.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 271.3Sriastrad 281.3SriastradTESTFILES+= smallfile 291.3SriastradXFAIL+= smallfile.in-outx 301.3SriastradXFAIL+= smallfile.cl2-cl2x 311.3Sriastradsmallfile.in: 321.3Sriastrad head -c 12345 < /usr/share/dict/words > ${.TARGET}.tmp \ 331.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 341.3Sriastrad 351.3SriastradCHECKS+= check-pipe 361.3SriastradCLEANFILES+= smallfile.cl2pipe 371.3Sriastradcheck-pipe: .PHONY smallfile.cl2 smallfile.cl2pipe 381.3Sriastrad cmp ${.ALLSRC} 391.3Sriastradsmallfile.cl2pipe: smallfile.in vndcompress 401.3Sriastrad head -c 54321 < /usr/share/dict/words \ 411.3Sriastrad | ./vndcompress -l 12345 /dev/stdin ${.TARGET}.tmp \ 421.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 431.3Sriastrad 441.3SriastradTESTFILES+= onechunk 451.3Sriastradonechunk.in: 461.3Sriastrad head -c 65536 < /usr/share/dict/words > ${.TARGET}.tmp \ 471.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 481.3Sriastrad 491.3SriastradTESTFILES+= tenchunk 501.3Sriastradtenchunk.in: 511.3Sriastrad head -c 655360 < /usr/share/dict/words > ${.TARGET}.tmp \ 521.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 531.3Sriastrad 541.3SriastradTESTFILES+= extrablock 551.3SriastradXFAIL+= extrablock.in-outx 561.3SriastradXFAIL+= extrablock.cl2-cl2x 571.3Sriastradextrablock.in: 581.3Sriastrad head -c $$((65536 + 512)) < /usr/share/dict/words > ${.TARGET}.tmp \ 591.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 601.3Sriastrad 611.3SriastradTESTFILES+= medfile 621.3SriastradXFAIL+= medfile.in-outx 631.3SriastradXFAIL+= medfile.cl2-cl2x 641.3Sriastradmedfile.in: 651.3Sriastrad head -c 123456 < /usr/share/dict/words > ${.TARGET}.tmp \ 661.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 671.3Sriastrad 681.3SriastradTESTFILES+= onetinyblock 691.3SriastradBLOCKSIZE.onetinyblock= 512 701.3Sriastradonetinyblock.in: 711.3Sriastrad head -c 512 < /usr/share/dict/words > ${.TARGET}.tmp \ 721.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 731.3Sriastrad 741.3SriastradTESTFILES+= tentinyblock 751.3SriastradBLOCKSIZE.tentinyblock= 512 761.3Sriastradtentinyblock.in: 771.3Sriastrad head -c 5120 < /usr/share/dict/words > ${.TARGET}.tmp \ 781.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 791.3Sriastrad 801.14Sriastrad# Make sure we can restart from a pipe. 811.3SriastradCHECKS+= check-pipe-restart 821.3SriastradCLEANFILES+= piperestart.in piperestart.in.tmp 831.3SriastradCLEANFILES+= piperestart.cl2 piperestart.cl2.tmp 841.3SriastradCLEANFILES+= piperestart.cl2restart piperestart.cl2restart.tmp 851.3SriastradCLEANFILES+= piperestart.cl2part piperestart.cl2part.tmp 861.3Sriastradcheck-pipe-restart: .PHONY piperestart.cl2 piperestart.cl2restart 871.3Sriastrad cmp ${.ALLSRC} 881.3Sriastradpiperestart.cl2restart: piperestart.cl2part vndcompress 891.3Sriastrad cp piperestart.cl2part ${.TARGET}.tmp \ 901.3Sriastrad && head -c 700000 < /usr/share/dict/words \ 911.14Sriastrad | ./vndcompress -l 655360 -k 1 -r -R /dev/stdin ${.TARGET}.tmp \ 921.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 931.9Sriastrad# The following rule uses ; and not && on purpose: vndcompress is 941.9Sriastrad# supposed to fail (and it is even OK to interrupt!) so we can restart 951.9Sriastrad# and fill in the rest. 961.3Sriastradpiperestart.cl2part: vndcompress 971.3Sriastrad head -c 600000 < /usr/share/dict/words \ 981.3Sriastrad | ./vndcompress -l 655360 -k 1 /dev/stdin ${.TARGET}.tmp; \ 991.3Sriastrad mv -f ${.TARGET}.tmp ${.TARGET} 1001.3Sriastradpiperestart.in: 1011.3Sriastrad head -c 655360 < /usr/share/dict/words > ${.TARGET}.tmp \ 1021.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1031.3Sriastrad 1041.14Sriastrad# Make sure we can restart from a pipe even if the original start was 1051.14Sriastrad# corrupted, as long as we don't pass -R. 1061.14SriastradCHECKS+= check-pipe-badstart 1071.14SriastradCLEANFILES+= pipebadstart.in pipebadstart.in.tmp 1081.14SriastradCLEANFILES+= pipebadstart.cl2 pipebadstart.cl2.tmp 1091.14SriastradCLEANFILES+= pipebadstart.cl2restart pipebadstart.cl2restart.tmp 1101.14SriastradCLEANFILES+= pipebadstart.cl2part pipebadstart.cl2part.tmp 1111.14Sriastradcheck-pipe-badstart: .PHONY pipebadstart.cl2 pipebadstart.cl2restart 1121.14Sriastrad cmp ${.ALLSRC} 1131.14Sriastradpipebadstart.cl2restart: pipebadstart.cl2part vndcompress 1141.14Sriastrad cp pipebadstart.cl2part ${.TARGET}.tmp \ 1151.14Sriastrad && head -c 700000 < /usr/share/dict/words \ 1161.14Sriastrad | ./vndcompress -l 655360 -k 1 -r /dev/stdin ${.TARGET}.tmp \ 1171.14Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1181.14Sriastradpipebadstart.cl2part: 1191.14Sriastrad touch ${.TARGET} 1201.14Sriastradpipebadstart.in: 1211.14Sriastrad head -c 655360 < /usr/share/dict/words > ${.TARGET}.tmp \ 1221.14Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1231.14Sriastrad 1241.14Sriastrad# Make sure we can `restart' even if there's nothing there. 1251.14SriastradCHECKS+= check-pipe-falsestart 1261.14SriastradCLEANFILES+= pipefalsestart.in pipefalsestart.in.tmp 1271.14SriastradCLEANFILES+= pipefalsestart.cl2 pipefalsestart.cl2.tmp 1281.14SriastradCLEANFILES+= pipefalsestart.cl2restart pipefalsestart.cl2restart.tmp 1291.14Sriastradcheck-pipe-falsestart: .PHONY pipefalsestart.cl2 pipefalsestart.cl2restart 1301.14Sriastrad cmp ${.ALLSRC} 1311.14Sriastradpipefalsestart.cl2restart: vndcompress 1321.14Sriastrad rm -f ${.TARGET}.tmp \ 1331.14Sriastrad && head -c 700000 < /usr/share/dict/words \ 1341.14Sriastrad | ./vndcompress -l 655360 -k 1 -r /dev/stdin ${.TARGET}.tmp \ 1351.14Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1361.14Sriastradpipefalsestart.in: 1371.14Sriastrad head -c 655360 < /usr/share/dict/words > ${.TARGET}.tmp \ 1381.14Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1391.14Sriastrad 1401.14Sriastrad# Make sure we can restart from a file, simulated with `-p'. 1411.3SriastradCHECKS+= check-part 1421.14SriastradCLEANFILES+= part.orig part.orig.tmp 1431.14SriastradCLEANFILES+= part.cl2part part.cl2part.tmp 1441.14SriastradCLEANFILES+= part.cl2 part.cl2.tmp 1451.14SriastradCLEANFILES+= part.out part.out.tmp 1461.3Sriastradcheck-part: .PHONY part.orig part.out 1471.3Sriastrad cmp part.orig part.out 1481.3Sriastradpart.cl2: part.orig part.cl2part vndcompress 1491.3Sriastrad cp part.cl2part ${.TARGET}.tmp \ 1501.14Sriastrad && ./vndcompress -b 512 -r -R part.orig ${.TARGET}.tmp \ 1511.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1521.3Sriastradpart.cl2part: part.orig vndcompress 1531.12Sriastrad ./vndcompress -b 512 -p 10 part.orig ${.TARGET}.tmp \ 1541.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1551.3Sriastradpart.orig: 1561.3Sriastrad head -c 12345 < /usr/share/dict/words > ${.TARGET}.tmp \ 1571.3Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1581.3Sriastrad 1591.14Sriastrad# Make sure we can `restart' even if there's nothing there. 1601.14SriastradCHECKS+= check-falsestart 1611.14SriastradCLEANFILES+= falsestart.in falsestart.in.tmp 1621.14SriastradCLEANFILES+= falsestart.cl2 falsestart.cl2.tmp 1631.14SriastradCLEANFILES+= falsestart.cl2restart falsestart.cl2restart.tmp 1641.14Sriastradcheck-falsestart: .PHONY falsestart.cl2 falsestart.cl2restart 1651.14Sriastrad cmp ${.ALLSRC} 1661.14Sriastradfalsestart.cl2restart: vndcompress falsestart.in 1671.14Sriastrad rm -f ${.TARGET}.tmp \ 1681.14Sriastrad && ./vndcompress -r falsestart.in ${.TARGET}.tmp \ 1691.14Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1701.14Sriastradfalsestart.in: 1711.14Sriastrad head -c 655360 < /usr/share/dict/words > ${.TARGET}.tmp \ 1721.14Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1731.14Sriastrad 1741.10SriastradTESTFILES+= smallwindow 1751.10Sriastradsmallwindow.in: 1761.10Sriastrad head -c 655360 < /usr/share/dict/words > ${.TARGET}.tmp \ 1771.10Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1781.10Sriastradsmallwindow.cl2: smallwindow.in 1791.10Sriastrad ./vndcompress -w 1 ${.IMPSRC} ${.TARGET}.tmp \ 1801.10Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1811.10Sriastradsmallwindow.out: smallwindow.cl2 1821.10Sriastrad ./vndcompress -w 1 -d ${.IMPSRC} ${.TARGET}.tmp \ 1831.10Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 1841.10Sriastrad 1851.10SriastradCHECKS+= check-pipewindow 1861.10Sriastradcheck-pipewindow: smallwindow.cl2 1871.10Sriastrad @echo '# expecting failure...' 1881.10Sriastrad if cat smallwindow.cl2 | ./vndcompress -w 1 -d /dev/stdin /dev/null; \ 1891.10Sriastrad then \ 1901.10Sriastrad echo 'unexpected pass!' && exit 1; \ 1911.10Sriastrad fi 1921.10Sriastrad 1931.11Sriastrad# The following two tests try to ensure a limited window size means 1941.11Sriastrad# limited memory allocation. They don't work very well. The virtual 1951.11Sriastrad# address space rlimit (ulimit -v, RLIMIT_AS) must cover the stack size 1961.11Sriastrad# that is allocated automatically for the process, which varies from 1971.11Sriastrad# machine architecture to machine architecture (the kernel's MAXSSIZ 1981.11Sriastrad# parameter), as well as any shared libraries that get loaded in and 1991.11Sriastrad# other auxiliary crud the loader or libc might allocate. 2001.11Sriastrad# 2011.11Sriastrad# In principle, the overhead from that and the program image should be 2021.11Sriastrad# constant, and the only substantial memory allocation performed by 2031.11Sriastrad# vndcompress should be w*8 bytes or (n/b)*8, where w is the window 2041.11Sriastrad# size if specified, n is the size of the input, and b is the block 2051.11Sriastrad# size. 2061.11Sriastrad# 2071.11Sriastrad# We could perhaps do an exponential growth and then binary search on 2081.11Sriastrad# the virtual address space limit to determine the overhead, but that's 2091.11Sriastrad# more trouble than I care to do in a makefile right now. Currently 2101.11Sriastrad# this is calibrated for NetBSD/amd64 6, where 128 MB of virtual 2111.11Sriastrad# address space is allocated for the stack. (Note `ulimit -v' takes a 2121.11Sriastrad# number of kilobytes, not a number of bytes.) Since this is not 2131.11Sriastrad# reliable, however, these are commented out. 2141.11Sriastrad 2151.11Sriastrad#CHECKS+= check-ulimit 2161.11Sriastrad#check-ulimit: 2171.11Sriastrad# @echo '# expecting failure...' 2181.11Sriastrad# if head -c $$((64 * 1024 * 1024)) < /dev/zero \ 2191.11Sriastrad# | (ulimit -v $$((139 * 1024)) && \ 2201.13Sriastrad# ./vndcompress -w 0 -l 64m -b 512 /dev/stdin /dev/null); then \ 2211.11Sriastrad# echo 'unexpected pass!' && exit 1; \ 2221.11Sriastrad# fi 2231.11Sriastrad# 2241.11Sriastrad#CHECKS+= check-ulimit-window 2251.11Sriastrad#check-ulimit-window: 2261.11Sriastrad# head -c $$((64 * 1024 * 1024)) < /dev/zero \ 2271.11Sriastrad# | (ulimit -v $$((139 * 1024)) && \ 2281.12Sriastrad# ./vndcompress -w 8192 -l 64m -b 512 /dev/stdin /dev/null) 2291.10Sriastrad 2301.3SriastradTESTSUFFIXES+= in cl2 cl2x out outx 2311.3Sriastrad 2321.3SriastradTESTFORMS+= cl2 cl2x 2331.3SriastradTESTFORMS+= in out 2341.3SriastradTESTFORMS+= in outx 2351.3Sriastrad 2361.3Sriastrad.for testfile in ${TESTFILES} 2371.3Sriastrad. for suffix in ${TESTSUFFIXES} 2381.3SriastradCLEANFILES+= ${testfile}.${suffix} 2391.3SriastradCLEANFILES+= ${testfile}.${suffix}.tmp 2401.3Sriastrad. endfor 2411.3Sriastrad. for left right in ${TESTFORMS} 2421.3SriastradCHECKS.${testfile}+= check-${testfile}.${left}-${right} 2431.3Sriastradcheck-${testfile}.${left}-${right}: .PHONY \ 2441.3Sriastrad ${testfile}.${left} ${testfile}.${right} 2451.3Sriastrad. if empty(XFAIL:M${testfile}.${left}-${right}) 2461.3Sriastrad cmp ${testfile}.${left} ${testfile}.${right} 2471.3Sriastrad. else 2481.3Sriastrad @echo '# expecting failure...' \ 2491.3Sriastrad && echo 'cmp ${testfile}.${left} ${testfile}.${right}' \ 2501.3Sriastrad && if cmp ${testfile}.${left} ${testfile}.${right}; then \ 2511.3Sriastrad echo 'unexpected pass!' \ 2521.3Sriastrad && exit 1; \ 2531.3Sriastrad fi 2541.3Sriastrad. endif 2551.3Sriastrad. endfor 2561.3Sriastradcheck-${testfile}: ${CHECKS.${testfile}} 2571.3SriastradCHECKS+= check-${testfile} 2581.3Sriastrad.endfor 2591.3Sriastrad 2601.3Sriastradcheck: .PHONY ${CHECKS} 2611.3Sriastrad 2621.3Sriastrad.SUFFIXES: .cl2 .cl2x .in .out .outx 2631.3Sriastrad 2641.10Sriastrad# XXX These tests should automatically try different window sizes, but 2651.10Sriastrad# that is tricky to express in make. 2661.10Sriastrad 2671.3Sriastrad.in.cl2: vndcompress 2681.7Sriastrad ./vndcompress ${.IMPSRC} ${.TARGET}.tmp ${BLOCKSIZE.${.PREFIX}} \ 2691.7Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 2701.3Sriastrad 2711.3Sriastrad.in.cl2x: 2721.7Sriastrad vndcompress ${.IMPSRC} ${.TARGET}.tmp ${BLOCKSIZE.${.PREFIX}} \ 2731.7Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 2741.3Sriastrad 2751.3Sriastrad.cl2.out: vndcompress 2761.7Sriastrad ./vndcompress -d ${.IMPSRC} ${.TARGET}.tmp \ 2771.7Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 2781.3Sriastrad 2791.3Sriastrad.cl2.outx: 2801.7Sriastrad vnduncompress ${.IMPSRC} ${.TARGET}.tmp \ 2811.7Sriastrad && mv -f ${.TARGET}.tmp ${.TARGET} 282