test.c revision 150308
1/*-
2 * Copyright (c) 2005 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.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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 $");
29
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
38int verbose;
39
40static void
41usage()
42{
43	fprintf(stdout, "usage: %s [-v] param ...\n", getprogname());
44	exit(1);
45}
46
47static int
48parse(char *arg, char **param, char **value)
49{
50	char *e;
51
52	*param = arg;
53	e = strchr(arg, '=');
54	if (e != NULL) {
55		*e = '\0';
56		*value = e + 1;
57	} else
58		*value = NULL;
59	return (0);
60}
61
62int main(int argc, char *argv[])
63{
64	struct gctl_req *req;
65	char *param, *value;
66	const char *s;
67	int c;
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) {
86		parse(argv[optind++], &param, &value);
87		if (value != NULL)
88			gctl_ro_param(req, param, -1, value);
89	}
90
91	if (verbose)
92		gctl_dump(req, stdout);
93
94	s = gctl_issue(req);
95	if (s != NULL)
96		printf("FAIL %s\n", s);
97	else
98		printf("PASS\n");
99	gctl_free(req);
100	return (0);
101}
102