Deleted Added
full compact
test.c (150308) test.c (157621)
1/*-
1/*-
2 * Copyright (c) 2005 Marcel Moolenaar
2 * Copyright (c) 2005, 2006 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/tools/regression/geom_gpt/test.c 150308 2005-09-19 06:51:57Z marcel $");
28__FBSDID("$FreeBSD: head/tools/regression/geom_gpt/test.c 157621 2006-04-10 04:07:20Z marcel $");
29
29
30#include <sys/param.h>
30#include <errno.h>
31#include <libgeom.h>
32#include <limits.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36#include <unistd.h>
37
31#include <errno.h>
32#include <libgeom.h>
33#include <limits.h>
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include <unistd.h>
38
39struct retval {
40 struct retval *retval;
41 const char *param;
42 char *value;
43};
44
45struct retval *retval;
38int verbose;
39
40static void
41usage()
42{
46int verbose;
47
48static void
49usage()
50{
43 fprintf(stdout, "usage: %s [-v] param ...\n", getprogname());
51 fprintf(stdout, "usage: %s [-v] param[:len][=value] ...\n",
52 getprogname());
44 exit(1);
45}
46
47static int
53 exit(1);
54}
55
56static int
48parse(char *arg, char **param, char **value)
57parse(char *arg, char **param, char **value, int *len)
49{
58{
50 char *e;
59 char *e, *colon, *equal;
51
60
61 if (*arg == '\0')
62 return (EINVAL);
63
64 colon = strchr(arg, ':');
65 equal = strchr(arg, '=');
66 if (colon == NULL && equal == NULL)
67 return (EINVAL);
68 if (colon == arg || equal == arg)
69 return (EINVAL);
70 if (colon != NULL && equal != NULL && equal < colon)
71 return (EINVAL);
72
73 if (colon != NULL)
74 *colon++ = '\0';
75 if (equal != NULL)
76 *equal++ = '\0';
77
52 *param = arg;
78 *param = arg;
53 e = strchr(arg, '=');
54 if (e != NULL) {
55 *e = '\0';
56 *value = e + 1;
57 } else
58 *value = NULL;
79 if (colon != NULL) {
80 /* Length specification. This parameter is RW. */
81 if (*colon == '\0')
82 return (EINVAL);
83 *len = strtol(colon, &e, 0);
84 if (*e != '\0')
85 return (EINVAL);
86 if (*len <= 0 || *len > PATH_MAX)
87 return (EINVAL);
88 *value = malloc(*len);
89 if (*value == NULL)
90 return (ENOMEM);
91 memset(*value, 0, *len);
92 if (equal != NULL) {
93 if (strlen(equal) >= PATH_MAX)
94 return (ENOMEM);
95 strcpy(*value, equal);
96 }
97 } else {
98 /* This parameter is RO. */
99 *len = -1;
100 if (*equal == '\0')
101 return (EINVAL);
102 *value = equal;
103 }
104
59 return (0);
60}
61
62int main(int argc, char *argv[])
63{
105 return (0);
106}
107
108int main(int argc, char *argv[])
109{
110 struct retval *rv;
64 struct gctl_req *req;
65 char *param, *value;
66 const char *s;
111 struct gctl_req *req;
112 char *param, *value;
113 const char *s;
67 int c;
114 int c, len;
68
69 req = gctl_get_handle();
70 gctl_ro_param(req, "class", -1, "GPT");
71
72 while ((c = getopt(argc, argv, "v")) != -1) {
73 switch (c) {
74 case 'v':
75 verbose = 1;
76 break;
77 case '?':
78 default:
79 usage();
80 /* NOTREACHED */
81 break;
82 }
83 }
84
85 while (optind < argc) {
115
116 req = gctl_get_handle();
117 gctl_ro_param(req, "class", -1, "GPT");
118
119 while ((c = getopt(argc, argv, "v")) != -1) {
120 switch (c) {
121 case 'v':
122 verbose = 1;
123 break;
124 case '?':
125 default:
126 usage();
127 /* NOTREACHED */
128 break;
129 }
130 }
131
132 while (optind < argc) {
86 parse(argv[optind++], &param, &value);
87 if (value != NULL)
88 gctl_ro_param(req, param, -1, value);
133 if (!parse(argv[optind++], &param, &value, &len)) {
134 if (len > 0) {
135 rv = malloc(sizeof(struct retval));
136 rv->param = param;
137 rv->value = value;
138 rv->retval = retval;
139 retval = rv;
140 gctl_rw_param(req, param, len, value);
141 } else
142 gctl_ro_param(req, param, -1, value);
143 }
89 }
90
91 if (verbose)
92 gctl_dump(req, stdout);
93
94 s = gctl_issue(req);
144 }
145
146 if (verbose)
147 gctl_dump(req, stdout);
148
149 s = gctl_issue(req);
95 if (s != NULL)
150 if (s == NULL) {
151 printf("PASS");
152 while (retval != NULL) {
153 rv = retval->retval;
154 printf(" %s=%s", retval->param, retval->value);
155 free(retval->value);
156 free(retval);
157 retval = rv;
158 }
159 printf("\n");
160 } else
96 printf("FAIL %s\n", s);
161 printf("FAIL %s\n", s);
97 else
98 printf("PASS\n");
162
99 gctl_free(req);
100 return (0);
101}
163 gctl_free(req);
164 return (0);
165}