test.c revision 150308
1150305Smarcel/*-
2150305Smarcel * Copyright (c) 2005 Marcel Moolenaar
3150305Smarcel * All rights reserved.
4150305Smarcel *
5150305Smarcel * Redistribution and use in source and binary forms, with or without
6150305Smarcel * modification, are permitted provided that the following conditions
7150305Smarcel * are met:
8150305Smarcel *
9150305Smarcel * 1. Redistributions of source code must retain the above copyright
10150305Smarcel *    notice, this list of conditions and the following disclaimer.
11150305Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12150305Smarcel *    notice, this list of conditions and the following disclaimer in the
13150305Smarcel *    documentation and/or other materials provided with the distribution.
14150305Smarcel *
15150305Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16150305Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17150305Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18150305Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19150305Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20150305Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21150305Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22150305Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23150305Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24150305Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25150305Smarcel */
26150305Smarcel
27150305Smarcel#include <sys/cdefs.h>
28150305Smarcel__FBSDID("$FreeBSD: head/tools/regression/geom_gpt/test.c 150308 2005-09-19 06:51:57Z marcel $");
29150305Smarcel
30150305Smarcel#include <errno.h>
31150305Smarcel#include <libgeom.h>
32150305Smarcel#include <limits.h>
33150305Smarcel#include <stdio.h>
34150305Smarcel#include <stdlib.h>
35150305Smarcel#include <string.h>
36150305Smarcel#include <unistd.h>
37150305Smarcel
38150305Smarcelint verbose;
39150305Smarcel
40150305Smarcelstatic void
41150305Smarcelusage()
42150305Smarcel{
43150305Smarcel	fprintf(stdout, "usage: %s [-v] param ...\n", getprogname());
44150305Smarcel	exit(1);
45150305Smarcel}
46150305Smarcel
47150305Smarcelstatic int
48150305Smarcelparse(char *arg, char **param, char **value)
49150305Smarcel{
50150305Smarcel	char *e;
51150305Smarcel
52150305Smarcel	*param = arg;
53150305Smarcel	e = strchr(arg, '=');
54150305Smarcel	if (e != NULL) {
55150305Smarcel		*e = '\0';
56150305Smarcel		*value = e + 1;
57150305Smarcel	} else
58150305Smarcel		*value = NULL;
59150305Smarcel	return (0);
60150305Smarcel}
61150305Smarcel
62150305Smarcelint main(int argc, char *argv[])
63150305Smarcel{
64150305Smarcel	struct gctl_req *req;
65150308Smarcel	char *param, *value;
66150305Smarcel	const char *s;
67150305Smarcel	int c;
68150305Smarcel
69150305Smarcel	req = gctl_get_handle();
70150305Smarcel	gctl_ro_param(req, "class", -1, "GPT");
71150305Smarcel
72150308Smarcel	while ((c = getopt(argc, argv, "v")) != -1) {
73150305Smarcel		switch (c) {
74150305Smarcel		case 'v':
75150305Smarcel			verbose = 1;
76150305Smarcel			break;
77150305Smarcel		case '?':
78150305Smarcel		default:
79150305Smarcel			usage();
80150305Smarcel			/* NOTREACHED */
81150305Smarcel			break;
82150305Smarcel		}
83150305Smarcel	}
84150305Smarcel
85150308Smarcel	while (optind < argc) {
86150308Smarcel		parse(argv[optind++], &param, &value);
87150308Smarcel		if (value != NULL)
88150308Smarcel			gctl_ro_param(req, param, -1, value);
89150308Smarcel	}
90150308Smarcel
91150305Smarcel	if (verbose)
92150305Smarcel		gctl_dump(req, stdout);
93150305Smarcel
94150305Smarcel	s = gctl_issue(req);
95150305Smarcel	if (s != NULL)
96150305Smarcel		printf("FAIL %s\n", s);
97150305Smarcel	else
98150305Smarcel		printf("PASS\n");
99150305Smarcel	gctl_free(req);
100150305Smarcel	return (0);
101150305Smarcel}
102