1*cf5a6c84SAndroid Build Coastguard Worker#!/bin/bash 2*cf5a6c84SAndroid Build Coastguard Worker 3*cf5a6c84SAndroid Build Coastguard Worker[ -f testing.sh ] && . testing.sh 4*cf5a6c84SAndroid Build Coastguard Worker 5*cf5a6c84SAndroid Build Coastguard Worker# ext stores extended attributes in a way that makes all the numbers in the 6*cf5a6c84SAndroid Build Coastguard Worker# tests below incorrect. 7*cf5a6c84SAndroid Build Coastguard Worker# TODO: include a read-only ext file system that we can mount for the tests? 8*cf5a6c84SAndroid Build Coastguard Workerif [ "$(stat --format %C . 2>/dev/null)" != "?" ]; then 9*cf5a6c84SAndroid Build Coastguard Worker echo "$SHOWSKIP: du (SELinux extended attributes present)" 10*cf5a6c84SAndroid Build Coastguard Worker return 2>/dev/null 11*cf5a6c84SAndroid Build Coastguard Worker exit 12*cf5a6c84SAndroid Build Coastguard Workerfi 13*cf5a6c84SAndroid Build Coastguard Worker 14*cf5a6c84SAndroid Build Coastguard Worker# darwin stores empty directories in the inode itself, making all the numbers 15*cf5a6c84SAndroid Build Coastguard Worker# in the tests below 0. (TODO this is not the right fix.) 16*cf5a6c84SAndroid Build Coastguard Workerif [ "$(uname)" == "Darwin" ]; then 17*cf5a6c84SAndroid Build Coastguard Worker echo "$SHOWSKIP: du (Darwin stores empty directories in inode)" 18*cf5a6c84SAndroid Build Coastguard Worker return 2>/dev/null 19*cf5a6c84SAndroid Build Coastguard Worker exit 20*cf5a6c84SAndroid Build Coastguard Workerfi 21*cf5a6c84SAndroid Build Coastguard Worker 22*cf5a6c84SAndroid Build Coastguard Worker#testing "name" "command" "result" "infile" "stdin" 23*cf5a6c84SAndroid Build Coastguard Worker 24*cf5a6c84SAndroid Build Coastguard Worker# we only test with -k since getting POSIX version is variable 25*cf5a6c84SAndroid Build Coastguard Worker# POSIXLY_CORRECT is sometimes needed, sometimes -P is needed, 26*cf5a6c84SAndroid Build Coastguard Worker# while -k is the default on most Linux systems 27*cf5a6c84SAndroid Build Coastguard Worker 28*cf5a6c84SAndroid Build Coastguard Workermkdir -p du_test/test du_2/foo 29*cf5a6c84SAndroid Build Coastguard Workertesting "(no options)" "du -k du_test" "4\tdu_test/test\n8\tdu_test\n" "" "" 30*cf5a6c84SAndroid Build Coastguard Workertesting "-s" "du -k -s du_test" "8\tdu_test\n" "" "" 31*cf5a6c84SAndroid Build Coastguard Workerln -s ../du_2 du_test/xyz 32*cf5a6c84SAndroid Build Coastguard Worker# "du shall count the size of the symbolic link" 33*cf5a6c84SAndroid Build Coastguard Worker# The tests assume that like for most POSIX systems symbolic 34*cf5a6c84SAndroid Build Coastguard Worker# links are stored directly in the inode so that the 35*cf5a6c84SAndroid Build Coastguard Worker# allocated file space is zero. 36*cf5a6c84SAndroid Build Coastguard Workertesting "counts symlinks without following" "du -ks du_test" "8\tdu_test\n" "" "" 37*cf5a6c84SAndroid Build Coastguard Workertesting "-L follows symlinks" "du -ksL du_test" "16\tdu_test\n" "" "" 38*cf5a6c84SAndroid Build Coastguard Workerln -s . du_test/up 39*cf5a6c84SAndroid Build Coastguard Workertesting "-L avoid endless loop" "du -ksL du_test" "16\tdu_test\n" "" "" 40*cf5a6c84SAndroid Build Coastguard Workerrm du_test/up 41*cf5a6c84SAndroid Build Coastguard Worker# if -H and -L are specified, the last takes priority 42*cf5a6c84SAndroid Build Coastguard Workertesting "-HL follows symlinks" "du -ksHL du_test" "16\tdu_test\n" "" "" 43*cf5a6c84SAndroid Build Coastguard Workertesting "-H does not follow unspecified symlinks" "du -ksH du_test" "8\tdu_test\n" "" "" 44*cf5a6c84SAndroid Build Coastguard Workertesting "-LH does not follow unspecified symlinks" "du -ksLH du_test" "8\tdu_test\n" "" "" 45*cf5a6c84SAndroid Build Coastguard Workertesting "-H follows specified symlinks" "du -ksH du_test/xyz" "8\tdu_test/xyz\n" "" "" 46*cf5a6c84SAndroid Build Coastguard Worker 47*cf5a6c84SAndroid Build Coastguard Workerrm -rf du_test du_2 48