Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / am-utils / dist / scripts / test-attrcache.in
blob061308b42dbebcbd9b81869785b817ce5b3defe6
1 #!/bin/sh
2 # Script to test the attribute cache behavior of the local OS client.
3 # If this script fails, it means that Amd cannot turn off the attrcache
4 # reliably on this host, and Amd therefore may not run reliably. See
5 # the README.attrcache file distributed with this am-utils.
6 # -Erez Zadok, September 29, 2005
8 # set PATH (must install am-utils first)
9 prefix=@prefix@
10 exec_prefix=@exec_prefix@
11 PATH=@sbindir@:@bindir@:/usr/ucb:/usr/bin:/bin:${PATH}
12 export PATH
14 # test if amd is running
15 amq -p > /dev/null 2>&1
16 if test $? = 0
17 then
18 echo "### Amd already running... please shutdown Amd first"
19 exit 1
22 mapfile="/tmp/amd.testmap.$$"
23 logfile="/var/log/amd"
24 delay=1
25 a=/a
27 CreateMap1 () {
28 echo "### Creating correct map"
29 cat - >$mapfile <<EOF
30 a type:=link;fs:=/tmp/a
31 EOF
34 CreateMap2 () {
35 echo "### Creating weird map"
36 cat - >$mapfile <<EOF
37 a type:=link;fs:=/tmp/b
38 EOF
41 StopAMD () {
42 ctl-amd stop
43 # do not delete files we may need to use to debug Amd
44 # rm -f /tmp/a /tmp/b $mapfile $logfile
47 touch /tmp/a
48 touch /tmp/b
50 CreateMap1
51 echo amd -x all -D all -r -l $logfile $a $mapfile -cache:=mapdefault,sync
52 amd -x all -D all -r -l $logfile $a $mapfile -cache:=mapdefault,sync
53 sleep 3 # give amd chance to start properly
54 amq
55 inode_a=`ls -lLi /tmp/a | awk '{print $1}'`
56 inode_b=`ls -lLi /tmp/b | awk '{print $1}'`
57 ls -lLi $a/a
58 ls -lLi $a/b
59 ls -l $mapfile
61 # how many times to try until we call it a success...
62 maxtry=10
63 while test $maxtry -gt 0
65 echo "$maxtry tries left ..."
66 let maxtry=maxtry-1
67 amq
68 CreateMap1
69 sleep $delay
71 ls -l $mapfile
72 echo "### looking at a... should get a"
73 ino=`ls -lLi $a/a | awk '{print $1}'`
74 if test -z "$ino"
75 then
76 ls -li $a/a
77 amq
78 amq -m
79 stat $a
80 echo "a link does not exist!"
81 StopAMD
82 exit 1
84 if test $ino -ne $inode_a
85 then
86 ls -li $a/a
87 amq
88 amq -m
89 stat $a
90 echo "a link does not point to A!"
91 StopAMD
92 exit 1
95 # Here is the main trick we try: force amd to flush one entry, then
96 # change the amd map on disk, and then see if the kernel will have
97 # flushed the attribute cache; if it did, then Amd will see the
98 # correctly changed map entry.
100 amq -u $a/a
101 sleep $delay
102 stat $a
104 CreateMap2
105 sleep $delay
107 ls -l $mapfile
108 echo "### looking at a... should get b"
109 ino=`ls -lLi $a/a | awk '{print $1}'`
110 if test -z "$ino"
111 then
112 ls -li $a/a
114 amq -m
115 stat $a
116 echo "a link does not exist!"
117 StopAMD
118 exit 1
120 if test $ino -ne $inode_b
121 then
122 ls -li $a/a
124 amq -m
125 stat $a
126 echo "a link does not point to B!"
127 StopAMD
128 exit 1
131 amq -u $a/a
132 sleep $delay
133 stat $a
134 done
135 StopAMD