1#!/bin/bash 2 3[ -f testing.sh ] && . testing.sh 4 5#testing "name" "command" "result" "infile" "stdin" 6 7# For reproducibility: UTC and umask 0002 8 9OLDTZ="$TZ" 10export TZ=utc 11OLDUMASK=$(umask) 12umask 0002 13 14# 3888 bytes, most of PATH_MAX 15LONG=abcdefghijklmnopqrstuvwxyz0123456789 16LONG=$LONG$LONG$LONG$LONG$LONG$LONG$LONG$LONG$LONG 17LONG=$LONG$LONG$LONG$LONG$LONG$LONG 18LONG=$LONG$LONG 19 20# Reproducible tarballs: override ownership and timestamp. Also amount of 21# trailing NUL padding varies (1024 bytes is minimum, gnu/dammit does more) 22# so look at first 3 512-byte frames when analyzing header content. 23 24TAR='tar c --owner root --group root --mtime @1234567890' 25SUM='head -c $((3*512)) | sha1sum | sed "s/ .*//"' 26[ -n "$TARHD" ] && SUM="tee >(hd >&2) | $SUM" 27LST='tar tv | sed "s/[ \t][ \t]*/ /g"' 28 29touch file 30testing "create file" "$TAR file | $SUM" \ 31 "fecaecba936e604bb115627a6ef4db7c7a3a8f81\n" "" "" 32 33testing "pass file" "$TAR file | $LST" \ 34 "-rw-rw-r-- root/root 0 2009-02-13 23:31 file\n" "" "" 35 36# The kernel has two hardwired meaningful UIDs: 0 (root) and 65534 (nobody). 37# (Technically changeable via /proc/sys/*/overflowuid but nobody ever does) 38skipnot id nobody >/dev/null 39testing "pass user" "tar -c --owner nobody --group root --mtime @0 file | $LST" \ 40 "-rw-rw-r-- nobody/root 0 1970-01-01 00:00 file\n" "" "" 41skipnot grep nobody /etc/group >/dev/null 42testing "pass group" "tar c --owner root --group nobody --mtime @0 file | $LST" \ 43 "-rw-rw-r-- root/nobody 0 1970-01-01 00:00 file\n" "" "" 44 45touch -t 198701231234.56 file 46testing "pass mtime" \ 47 "tar c --owner root --group root file | tar tv --full-time | sed 's/[ \t][ \t]*/ /g'" \ 48 "-rw-rw-r-- root/root 0 1987-01-23 12:34:56 file\n" "" "" 49 50mkdir dir 51testing "create dir" "$TAR dir | $SUM" \ 52 "05739c423d7d4a7f12b3dbb7c94149acb2bb4f8d\n" "" "" 53 54testing "pass dir" "$TAR dir | $LST" \ 55 "drwxrwxr-x root/root 0 2009-02-13 23:31 dir/\n" "" "" 56 57# note: does _not_ include dir entry in archive, just file 58touch dir/file 59testing "create file in dir" "$TAR dir/file | $SUM" \ 60 "2d7b96c7025987215f5a41f10eaa84311160afdb\n" "" "" 61 62# Tests recursion without worrying about content order 63testing "create dir and dir/file" "$TAR dir | $SUM" \ 64 "0bcc8005a3e07eb63c9b735267aecc5b774795d7\n" "" "" 65 66testing "pass dir/file" "$TAR dir | $LST" \ 67 "drwxrwxr-x root/root 0 2009-02-13 23:31 dir/\n-rw-rw-r-- root/root 0 2009-02-13 23:31 dir/file\n" "" "" 68 69# / and .. only stripped from name, not symlink target. 70ln -s ../name.././.. dir/link 71testing "create symlink" "$TAR dir/link | $SUM" \ 72 "7324cafbd9aeec5036b6efc54d741f11528aeb10\n" "" "" 73 74# Also two explicit targets 75ln dir/file dir/hardlink 76testing "create hardlink" "$TAR dir/file dir/hardlink | $SUM" \ 77 "c5383651f8c03ec0fe15e8a9e28a4e8e5273990d\n" "" "" 78 79ln dir/link dir/hlink 80testing "create hardlink to symlink" "$TAR dir/link dir/hlink | $SUM" \ 81 "3bc16f8fb6fc8b05f691da8caf989a70ee99284a\n" "" "" 82 83skipnot mkfifo dir/fifo 84testing "create dir/fifo" "$TAR dir/fifo | $SUM" \ 85 "bd1365db6e8ead4c813333f9666994c1899924d9\n" "" "" 86 87# test L and K records 88 89# 4+96=100 (biggest short name), 4+97=101 (shortest long name) 90touch dir/${LONG:1:96} dir/${LONG:1:97} 91testing "create longfilename" "$TAR dir/${LONG:1:97} dir/${LONG:1:96} | $SUM" \ 92 "08af4f9d8b7f4b2f6c264689efe42a4159314708\n" "" "" 93 94# this expects devtmpfs values 95 96testing "pass /dev/null" \ 97 "tar c --mtime @0 /dev/null 2>/dev/null | $LST" \ 98 "crw-rw-rw- root/root 1,3 1970-01-01 00:00 dev/null\n" "" "" 99 100testing "pass /dev/loop0" \ 101 "tar c --numeric-owner --mtime @0 /dev/loop0 2>/dev/null | $LST" \ 102 "brw-rw---- 0/6 7,0 1970-01-01 00:00 dev/loop0\n" "" "" 103 104skipnot mknod dir/char c 12 34 105testing "create char2" "$TAR /dev/null | $SUM" \ 106 "" "" "" 107 108#testing "create block" "$TAR /dev/ 109 110skipnot mknod dir/block b 56 78 111testing "create dir/block" "$TAR dir/block | $SUM" \ 112 "" "" "" 113 114skipnot chown nobody dir/file 115testing "ownership" "$TAR dir/block | $SUM" \ 116 "blat" "" "" 117 118TZ="$OLDTZ" 119umask $OLDUMASK 120unset LONG TAR SUM OLDUMASK OLDTZ LST 121