check: allow '-e testid' to exclude a single test
[xfstests-dev.git] / dmapi / src / suite2 / src / region_test.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 #include <sys/types.h>
8
9 #include <lib/hsm.h>
10 #include <lib/errtest.h>
11
12 #include <getopt.h>
13 #include <string.h>
14
15
16 /*---------------------------------------------------------------------------
17
18 Manual test for the DMAPI functions dm_set_region() and dm_get_region().
19
20 The command line is:
21
22         region_test [-Rv] [-s sid] [-l len] [-o offset] ls_path directory 
23
24 where 
25    -R
26         reuse the existing test file
27    pathname
28       is the name of a file
29    ls_path
30       is the path to a specific copy of ls, important only for its size
31    sid
32       is the session ID whose events you you are interested in.
33 ----------------------------------------------------------------------------*/
34
35 #define NELEM   1
36
37 #ifndef linux
38 extern  char    *sys_errlist[];
39 #endif
40 extern  int     optind;
41 extern  char    *optarg;
42
43
44 char    *Progname;
45
46
47 static void
48 usage(void)
49 {
50         fprintf(stderr, "usage:\t%s [-Rv] [-s sid] [-l len] [-o offset] ls_path pathname\n", Progname);
51         exit(1);
52 }
53
54
55 int
56 main(
57         int     argc, 
58         char    **argv)
59 {
60         dm_sessid_t     sid = DM_NO_SESSION;
61         char            *dir_name = NULL;
62         char            *ls_path = NULL;
63         char            command[1024];
64         char            test_file[128];
65         int             opt;
66         int             Vflag = 0;
67         dm_region_t     region = { 0, 0, 0 };
68         char            *name;
69         int             reuse_file = 0;
70         void            *hanp;
71         size_t           hlen;
72         dm_boolean_t    exactflag;
73
74         Progname = strrchr(argv[0], '/');
75         if (Progname) {
76                 Progname++;
77         } else {
78                 Progname = argv[0];
79         }
80
81         /* Crack and validate the command line options. */
82
83         while ((opt = getopt(argc, argv, "vo:l:s:R")) != EOF) {
84                 switch (opt) {
85                 case 'v':
86                         Vflag++;
87                         break;
88                 case 'R':
89                         reuse_file++;
90                         break;
91                 case 'o':
92                         region.rg_offset = atol(optarg);
93                         break;
94                 case 'l':
95                         region.rg_size = atol(optarg);
96                         break;
97                 case 's':
98                         sid = atol(optarg);
99                         break;
100                 case '?':
101                         usage();
102                 }
103         }
104         if (optind + 2 > argc)
105                 usage();
106         ls_path = argv[optind];
107         dir_name = argv[optind+1];
108
109         if (dm_init_service(&name) == -1)  {
110                 fprintf(stderr, "Can't initialize the DMAPI\n");
111                 exit(1);
112         }
113         if (sid == DM_NO_SESSION)
114                 find_test_session(&sid);
115
116         sprintf(test_file, "%s/DMAPI_test_file", dir_name);
117         if( !reuse_file ){
118                 sprintf(command, "cp %s %s\n", ls_path, test_file); 
119                 system(command);
120         }
121
122         if (dm_path_to_handle(test_file, &hanp, &hlen)) {
123                 fprintf(stderr, "can't get handle for file %s\n", test_file);
124                 exit(1);
125         }
126
127         region.rg_flags = DM_REGION_READ | DM_REGION_WRITE | DM_REGION_TRUNCATE;
128         if( dm_set_region( sid, hanp, hlen, DM_NO_TOKEN, NELEM,
129                           &region, &exactflag ) ){
130                 fprintf(stderr, "dm_set_region failed, err=%d\n", errno);
131                 dm_handle_free(hanp,hlen);
132                 exit(1);
133         }
134         if( exactflag == DM_FALSE )
135                 fprintf(stderr, "exact flag was false\n");
136
137         dm_handle_free(hanp, hlen);
138         exit(0);
139 }