5dd9e6695d577bf2414619714f2e4e41700d921e
[xfstests-dev.git] / dmapi / src / suite1 / cmd / struct_test.c
1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3  * 
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  * 
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * 
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  * 
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  * 
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  * 
26  * http://www.sgi.com 
27  * 
28  * For further information regarding this notice, see: 
29  * 
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32         
33 #include <stddef.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36
37 #ifdef linux
38 #include <dmapi.h>
39 #else
40 #include <sys/dmi.h>
41 #endif
42
43 /* The purpose of this test is to make sure that each field in each structure
44    defined in dmi.h is properly aligned so that there is no dead space, and
45    that the sizes and offsets of those fields remain constant no matter what
46    mode the program is compiled with, i.e. -32, -n32 or -64.
47
48    Run the program with no parameters.  If everything is correct, no message
49    will start with the word "ERROR:".  Compile and run the test in each of
50    the three mods and diff the outputs.  They must all be identical.
51
52    Note: this test cannot detect the addition of new structures to dmi.h, so
53    it will have to periodically be compared with dmi.h manually to ensure that
54    all the structures are still being validated!
55 */
56
57 #define S_START(struct_name)    { offset = 0; s_name = #struct_name; }
58
59 #define S_NEXT(struct_name, field_name) \
60 { \
61         struct_name     X; \
62  \
63         f_name = #field_name; \
64         printf("field %s.%s offset is %d\n", s_name, f_name, offset); \
65         if (offsetof(struct_name, field_name) != offset) { \
66                 printf("ERROR: field %s should be %d\n", \
67                         #struct_name "." #field_name, \
68                         offsetof(struct_name, field_name)); \
69         } \
70         offset = offsetof(struct_name, field_name) + sizeof(X.field_name); \
71 }
72
73 #define S_END(struct_name) \
74 { \
75         printf("struct %s size is %d\n", s_name, offset); \
76         if (sizeof(struct_name) != offset) { \
77                 printf("ERROR: struct %s should be %d\n", \
78                         s_name, sizeof(struct_name)); \
79         } \
80 }
81
82
83 char *Progname;
84
85 int main(
86         int     argc,
87         char    **argv)
88 {
89         char    *s_name = NULL;
90         char    *f_name = NULL;
91         int     offset = 0;
92
93
94         S_START(dm_vardata_t);
95         S_NEXT(dm_vardata_t, vd_offset);
96         S_NEXT(dm_vardata_t, vd_length);
97         S_END(dm_vardata_t);
98
99
100         S_START(dm_attrname_t);
101         S_NEXT(dm_attrname_t, an_chars);
102         S_END(dm_attrname_t);
103
104
105         S_START(dm_attrlist_t);
106         S_NEXT(dm_attrlist_t,   _link);
107         S_NEXT(dm_attrlist_t, al_name);
108         S_NEXT(dm_attrlist_t, al_data);
109         S_END(dm_attrlist_t);
110
111
112         S_START(dm_dispinfo_t);
113         S_NEXT(dm_dispinfo_t, _link);
114         S_NEXT(dm_dispinfo_t, di_pad1);
115         S_NEXT(dm_dispinfo_t, di_fshandle);
116         S_NEXT(dm_dispinfo_t, di_eventset);
117         S_END(dm_dispinfo_t);
118
119
120         S_START(dm_eventmsg_t);
121         S_NEXT(dm_eventmsg_t, _link);
122         S_NEXT(dm_eventmsg_t, ev_type);
123         S_NEXT(dm_eventmsg_t, ev_token);
124         S_NEXT(dm_eventmsg_t, ev_sequence);
125         S_NEXT(dm_eventmsg_t, ev_data);
126         S_END(dm_eventmsg_t);
127
128
129         S_START(dm_cancel_event_t);
130         S_NEXT(dm_cancel_event_t, ce_sequence);
131         S_NEXT(dm_cancel_event_t, ce_token);
132         S_END(dm_cancel_event_t);
133
134
135         S_START(dm_data_event_t);
136         S_NEXT(dm_data_event_t, de_handle);
137         S_NEXT(dm_data_event_t, de_offset);
138         S_NEXT(dm_data_event_t, de_length);
139         S_END(dm_data_event_t);
140
141
142         S_START(dm_destroy_event_t);
143         S_NEXT(dm_destroy_event_t, ds_handle);
144         S_NEXT(dm_destroy_event_t, ds_attrname);
145         S_NEXT(dm_destroy_event_t, ds_attrcopy);
146         S_END(dm_destroy_event_t);
147
148
149         S_START(dm_mount_event_t);
150         S_NEXT(dm_mount_event_t, me_mode);
151         S_NEXT(dm_mount_event_t, me_handle1);
152         S_NEXT(dm_mount_event_t, me_handle2);
153         S_NEXT(dm_mount_event_t, me_name1);
154         S_NEXT(dm_mount_event_t, me_name2);
155         S_NEXT(dm_mount_event_t, me_roothandle);
156         S_END(dm_mount_event_t);
157
158
159         S_START(dm_namesp_event_t);
160         S_NEXT(dm_namesp_event_t, ne_mode);
161         S_NEXT(dm_namesp_event_t, ne_handle1);
162         S_NEXT(dm_namesp_event_t, ne_handle2);
163         S_NEXT(dm_namesp_event_t, ne_name1);
164         S_NEXT(dm_namesp_event_t, ne_name2);
165         S_NEXT(dm_namesp_event_t, ne_retcode);
166         S_END(dm_namesp_event_t);
167
168
169         S_START(dm_extent_t);
170         S_NEXT(dm_extent_t, ex_type);
171         S_NEXT(dm_extent_t, ex_pad1);
172         S_NEXT(dm_extent_t, ex_offset);
173         S_NEXT(dm_extent_t, ex_length);
174         S_END(dm_extent_t);
175
176
177         S_START(dm_fileattr_t);
178         S_NEXT(dm_fileattr_t, fa_mode);
179         S_NEXT(dm_fileattr_t, fa_uid);
180         S_NEXT(dm_fileattr_t, fa_gid);
181         S_NEXT(dm_fileattr_t, fa_atime);
182         S_NEXT(dm_fileattr_t, fa_mtime);
183         S_NEXT(dm_fileattr_t, fa_ctime);
184         S_NEXT(dm_fileattr_t, fa_dtime);
185         S_NEXT(dm_fileattr_t, fa_pad1);
186         S_NEXT(dm_fileattr_t, fa_size);
187         S_END(dm_fileattr_t);
188
189
190         S_START(dm_inherit_t);
191         S_NEXT(dm_inherit_t, ih_name);
192         S_NEXT(dm_inherit_t, ih_filetype);
193         S_END(dm_inherit_t);
194
195
196         S_START(dm_region_t);
197         S_NEXT(dm_region_t, rg_offset);
198         S_NEXT(dm_region_t, rg_size);
199         S_NEXT(dm_region_t, rg_flags);
200         S_NEXT(dm_region_t, rg_pad1);
201         S_END(dm_region_t);
202
203
204         S_START(dm_stat_t);
205         S_NEXT(dm_stat_t, _link);
206         S_NEXT(dm_stat_t, dt_handle);
207         S_NEXT(dm_stat_t, dt_compname);
208         S_NEXT(dm_stat_t, dt_nevents);
209         S_NEXT(dm_stat_t, dt_emask);
210         S_NEXT(dm_stat_t, dt_pers);
211         S_NEXT(dm_stat_t, dt_pmanreg);
212         S_NEXT(dm_stat_t, dt_dtime);
213         S_NEXT(dm_stat_t, dt_change);
214         S_NEXT(dm_stat_t, dt_pad1);
215
216         S_NEXT(dm_stat_t, dt_dev);
217         S_NEXT(dm_stat_t, dt_ino);
218         S_NEXT(dm_stat_t, dt_mode);
219         S_NEXT(dm_stat_t, dt_nlink);
220         S_NEXT(dm_stat_t, dt_uid);
221         S_NEXT(dm_stat_t, dt_gid);
222         S_NEXT(dm_stat_t, dt_rdev);
223         S_NEXT(dm_stat_t, dt_pad2);
224         S_NEXT(dm_stat_t, dt_size);
225         S_NEXT(dm_stat_t, dt_atime);
226         S_NEXT(dm_stat_t, dt_mtime);
227         S_NEXT(dm_stat_t, dt_ctime);
228         S_NEXT(dm_stat_t, dt_blksize);
229         S_NEXT(dm_stat_t, dt_blocks);
230
231         S_NEXT(dm_stat_t, dt_pad3);
232         S_NEXT(dm_stat_t, dt_fstype);
233
234         S_NEXT(dm_stat_t, dt_xfs_igen);
235         S_NEXT(dm_stat_t, dt_xfs_xflags);
236         S_NEXT(dm_stat_t, dt_xfs_extsize);
237         S_NEXT(dm_stat_t, dt_xfs_extents);
238         S_NEXT(dm_stat_t, dt_xfs_aextents);
239         S_NEXT(dm_stat_t, dt_xfs_dmstate);
240         S_END(dm_stat_t);
241
242
243         S_START(dm_xstat_t);
244         S_NEXT(dm_xstat_t, dx_statinfo);
245         S_NEXT(dm_xstat_t, dx_attrdata);
246         S_END(dm_xstat_t);
247         exit(0);
248 }