671a77bcef5014e850f52d064c44ee5bf2263afc
[xfstests-dev.git] / tests / xfs / 122
1 #! /bin/bash
2 # FS QA Test No. 122
3 #
4 # pv#952498
5 # Keep an eye on some of the xfs type sizes
6 # Motivation from differing ondisk types for 32 and 64 bit word versions.
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #
24 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
35
36 # get standard environment
37 . ./common/rc
38
39 # real QA test starts here
40 _supported_fs xfs
41 _supported_os Linux
42 _require_command "$INDENT_PROG" indent
43
44 rm -f $seqres.full
45
46 # filter out known changes to xfs type sizes
47 _type_size_filter()
48 {
49         # lazy SB adds __be32 agf_btreeblks - pv960372
50         if [ "$($MKFS_XFS_PROG 2>&1 | grep -c lazy-count )" == "0" ]; then
51                 perl -ne '
52 s/sizeof\( xfs_agf_t \) = 60/sizeof( xfs_agf_t ) = <SIZE>/;
53                 print;'
54         else
55                 perl -ne '
56 s/sizeof\( xfs_agf_t \) = 64/sizeof( xfs_agf_t ) = <SIZE>/;
57                 print;'
58         fi
59 }
60
61 # filter out known changes to xfs type names
62 _type_name_filter()
63 {
64         sed -e 's/xfs_bmbt_rec_64_t/xfs_bmbt_rec_t/'
65 }
66
67 _attribute_filter()
68 {
69         sed -e 's/__attribute__ *[(][(]packed[)][)]//' \
70             -e 's/__arch_pack//'
71 }
72
73 cprog=$tmp.get_structs.c
74 oprog=$tmp.get_structs
75 progout=$tmp.output
76 keyfile=$tmp.keys
77
78 cat >$cprog <<EOF
79 #define _GNU_SOURCE
80 #include <stdio.h>
81 EOF
82 for hdr in /usr/include/xfs/xfs*.h; do
83         echo "#include <$(echo "$hdr" | sed -e 's|/usr/include/||g')>" >> $cprog
84 done
85
86 # missing:
87 # xfs_attr_shortform_t
88 # xfs_trans_header_t
89
90 cat >$tmp.ignore <<EOF
91 xfs_buf_log_format_t
92 xfs_attr3_icleaf_hdr
93 xfs_da3_icnode_hdr
94 xfs_dir3_icfree_hdr
95 xfs_dir3_icleaf_hdr
96 xfs_name
97 xfs_owner_info
98 xfs_refcount_irec
99 xfs_rmap_irec
100 xfs_alloctype_t
101 xfs_buf_cancel_t
102 xfs_bmbt_rec_32_t
103 xfs_swapext_t
104 xfs_dirops_t
105 xfs_efi_log_item_t
106 xfs_efd_log_item_t
107 xfs_iocore_t
108 xfs_ihash_t
109 xfs_chashlist_t
110 xfs_chash_t
111 xfs_iptr_t
112 xfs_dmops_t
113 xfs_qmops_t
114 xfs_ioops_t
115 xfs_mod_sb_t
116 xfs_dqtrx_t
117 xfs_dqtrxops_t
118 xfs_ail_t
119 xfs_ail_entry_t
120 xfs_item_ops_t
121 xfs_log_busy_slot_t
122 xfs_log_busy_chunk_t
123 xfs_inode_log_format_t
124 xfs_efi_log_format_t
125 xfs_efd_log_format_t
126 xfs_perag_busy_t
127 xfs_perag_t
128 xfs_alloc_arg_t
129 xfs_attr_list_context_t
130 xfs_attr_sf_sort_t
131 xfs_bmbt_irec_t
132 xfs_bmbt_rec_host_t
133 xfs_bmap_free_item_t
134 xfs_bmap_free_t
135 xfs_bmalloca_t
136 xfs_btree_cur_t
137 xfs_buf_log_item_t
138 xfs_buf_log_format_v1_t
139 xfs_da_args_t
140 xfs_dabuf_t
141 xfs_da_state_blk_t
142 xfs_da_state_path_t
143 xfs_da_state_t
144 xfs_dinode_t
145 xfs_dircook_t
146 xfs_dir2_block_t
147 xfs_dir2_data_entry_t
148 xfs_dir2_data_union_t
149 xfs_dir2_data_t
150 xfs_dir2_put_args_t
151 xfs_dir_put_args_t
152 xfs_dir_sf_sort_t
153 xfs_extent_t
154 xfs_ext_irec_t
155 xfs_extdelta_t
156 xfs_flock64_t
157 xfs_fsop_geom_v1_t
158 xfs_growfs_data_t
159 xfs_growfs_rt_t
160 xfs_bstime_t
161 xfs_bstat_t
162 xfs_fsop_bulkreq_t
163 xfs_icsb_cnts_t
164 xfs_icdinode_t
165 xfs_ictimestamp_t
166 xfs_inobt_rec_incore_t
167 xfs_inogrp_t
168 xfs_fid2_t
169 xfs_fsop_handlereq_t
170 xfs_fsop_setdm_handlereq_t
171 xfs_fsop_attrlist_handlereq_t
172 xfs_attr_multiop_t
173 xfs_fsop_attrmulti_handlereq_t
174 xfs_imap_t
175 xfs_ifork_t
176 xfs_inode_t
177 xfs_inode_log_item_t
178 xfs_log_iovec_t
179 xfs_log_callback_t
180 xfs_metablock_t
181 xfs_mount_t
182 xfs_sb_t
183 xfs_log_item_t
184 xfs_log_item_desc_t
185 xfs_log_item_chunk_t
186 xfs_trans_t
187 xfs_dirent_t
188 xfs_fsop_getparents_handlereq_t
189 xfs_dinode_core_t
190 struct xfs_iext_cursor
191 EOF
192
193 echo 'int main(int argc, char *argv[]) {' >>$cprog
194
195 #
196 # Printfs of typedef sizes
197 #
198 cat /usr/include/xfs/xfs*.h | indent |\
199 _attribute_filter |\
200 egrep '(} *xfs_.*_t|^struct xfs_[a-z0-9_]*$)' |\
201 egrep -v -f $tmp.ignore |\
202 sed -e 's/^.*}[[:space:]]*//g' -e 's/;.*$//g' -e 's/_t, /_t\n/g' |\
203 sort | uniq |\
204 awk '{printf("printf(\"sizeof(%s) = \\%zu\\n\", sizeof(%s));\n", $0, $0);}' |\
205 cat >> $cprog
206
207 #
208 # Look at offsets of key ones which differ in lengths
209 #
210
211 # xfs_sb_t
212 cat /usr/include/xfs/xfs*.h | indent |\
213 awk '
214    /typedef struct xfs_sb/ { structon = 1; next }
215    structon && $2 ~ /^sb_/ { sub(/[;,]/,"",$2)
216                              printf("printf(\"offsetof(xfs_sb_t, %s) = \\%zu\\n\", offsetof(xfs_sb_t, %s));", $2, $2); next}
217    structon && /}/ { structon = 0; next}
218 '>>$cprog
219
220 echo 'return 0; }' >>$cprog
221
222 # create and run program
223 cc -o $oprog $cprog >> $seqres.full 2>&1 || \
224   _notrun "Could not compile test program (see end of $seqres.full)"
225 $oprog | _type_size_filter | _type_name_filter > $progout
226
227 # Find all the items that only exist in the golden output
228 comm -23 <(grep '=' $0.out | sed -e 's/ =.*$//g' | LC_COLLATE=POSIX sort) \
229          <(sed -e 's/ =.*$//g' < $progout | LC_COLLATE=POSIX sort) > $keyfile
230
231 # Copy those items to the program output
232 grep -F -f $keyfile $0.out >> $progout
233
234 LC_COLLATE=POSIX sort $progout
235
236 status=0