From 9552b8fb5e4bd7d4288591e33b8784fb8614b8d2 Mon Sep 17 00:00:00 2001 From: ngie Date: Sat, 27 May 2017 23:31:51 +0000 Subject: MFC r317290,r317291,r317292,r317293,r317294,r317295,r317304,r317306,r317307,r317308,r317309: r317290: Fix -Wimplicit-function-declaration compilation warning by moving libgeom.h #include below the stdio.h #include. gctl_dump(3) needs stdio.h, per reasoning noted in r317289. PR: 218809 r317291: Rename gctl.t to gctl_test.t and test.c to gctl_test_helper.c This is being done to reduce ambiguity and to make the tests more portable in the future to other locations in the source tree. r317292: gctl_test.t: use make to compile gctl_test_helper instead of calling cc directly r317293: gctl_test_helper: apply polish - Staticize variables to fix warnings. - Sprinkle asserts around for calls that can fail - Apply style(9) for main(..) definition. - ANSIify usage(..) definition. r317294: Bump WARNS to 6 per previous commits which fixed warnings Tested with: clang (4.0), gcc (4.2.1, 6.3.0) r317295: The GPT class no longer exists; use the PART class instead r317304: gctl_test_helper: add diagnostic output for parse_retval(..) This will help end-users better diagnose issues with the function. r317306: gctl_test.t: minor tweaks - Declare $count with the `my` scope operator to permit `use strict`. - Add `use strict`. - Use `use warnings` instead of using `-w` in the shebang. - Don't unlink $cmd when done (prevents unnecessary rebuilding). - Improve the error message when running with insufficient permissions, e.g., non-root. r317307: Use verb=delete not verb=remove The `remove` verb hasn't been present in geom_part*(4) for well over a decade, if ever. I couldn't find any references to it in ^/stable/5 at least, which is around the timeframe that this test was written. r317308: gctl_test.t: more tweaks to try and update the code and get it functional (again?) - Make the logfile for $out be built off the basename for $cmd, instead of $cmd. (r317292 broke this assumption). - Rename $mntpt to $mntpt_prefix for clarity, as this variable is a prefix for mountpoints. - Reindent the umount directive block while here to match the rest of the code. r317309: gctl_test.t: improve error reporting with mdcfg and mount directives If the commands had failed previously, it would press on and result in a series of cascading failures. Fail early and continue on to the next case instead of executing additional commands after a previously failed series of steps. --- tools/regression/geom_gpt/Makefile | 10 ++ tools/regression/geom_gpt/gctl.t | 207 ------------------------- tools/regression/geom_gpt/gctl_test.t | 218 +++++++++++++++++++++++++++ tools/regression/geom_gpt/gctl_test_helper.c | 173 +++++++++++++++++++++ tools/regression/geom_gpt/test.c | 165 -------------------- 5 files changed, 401 insertions(+), 372 deletions(-) create mode 100644 tools/regression/geom_gpt/Makefile delete mode 100644 tools/regression/geom_gpt/gctl.t create mode 100644 tools/regression/geom_gpt/gctl_test.t create mode 100644 tools/regression/geom_gpt/gctl_test_helper.c delete mode 100644 tools/regression/geom_gpt/test.c diff --git a/tools/regression/geom_gpt/Makefile b/tools/regression/geom_gpt/Makefile new file mode 100644 index 0000000..92d1f02 --- /dev/null +++ b/tools/regression/geom_gpt/Makefile @@ -0,0 +1,10 @@ +# $FreeBSD$ + +PROG= gctl_test_helper +MAN= + +LIBADD+= geom + +WARNS?= 6 + +.include diff --git a/tools/regression/geom_gpt/gctl.t b/tools/regression/geom_gpt/gctl.t deleted file mode 100644 index f99e6d8..0000000 --- a/tools/regression/geom_gpt/gctl.t +++ /dev/null @@ -1,207 +0,0 @@ -#!/usr/bin/env perl -w -# -# Copyright (c) 2005, 2006 Marcel Moolenaar -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# $FreeBSD$ - -my $srcdir = `dirname $0`; -chomp $srcdir; - -my $cmd = "/tmp/gctl-$$"; -my $out = "$cmd.out"; -my $disk = "/tmp/disk-$$"; -my $mntpt = "/tmp/mount-$$"; - -my %steps = ( - "000" => "gctl", - "001" => "gctl verb=bogus", - "010" => "gctl verb=create", - "011" => "gctl verb=create provider=bogus", - "020" => "mdcfg create pristine", - "021" => "gctl verb=create provider=%dev% entries=-1", - "022" => "gctl verb=create provider=%dev% entries=128", - "023" => "gctl verb=create provider=%dev%", - "024" => "gctl verb=modify geom=%dev%", - "025" => "conf", - "030" => "gctl verb=add", - "031" => "gctl verb=add geom=bogus", - "032" => "gctl verb=add geom=%dev%", - "033" => "gctl verb=add geom=%dev% type=bogus", - "034" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace", - "035" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=1", - "036" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=34", - "037" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=34 end=12345678", - "038" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=162 end=417 entry=129", - "039" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=162 end=417 entry:8=5", - "040" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=34 end=161 entry=5", - "041" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=34 end=546", - "042" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=162 end=417", - "043" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=100 end=300", - "044" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=300 end=500", - "045" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=34 end=161 entry:8", - "046" => "gctl verb=add geom=%dev% type=d2bd4509-c4ff-11da-b4cc-00306e39b62f start=418 end=546 entry:8", - "047" => "conf", - "050" => "gctl verb=remove geom=%dev% entry=5", - "051" => "gctl verb=remove geom=%dev% entry=2", - "052" => "gctl verb=remove geom=%dev% entry=1", - "053" => "gctl verb=remove geom=%dev% entry=1", - "054" => "conf", - "060" => "gctl verb=add geom=%dev% type=516e7cb6-6ecf-11d6-8ff8-00022d09712b start=34 end=546 entry:8=1", - "061" => "mount %dev%p1", - "062" => "gctl verb=remove geom=%dev% entry=1", - "063" => "umount %dev%p1", - "064" => "gctl verb=remove geom=%dev% entry=1", - "065" => "conf", - "100" => "mdcfg destroy", - "110" => "mdcfg create corrupted", - "111" => "gctl verb=add geom=%dev%", - "120" => "mdcfg destroy", -); - -my %result = ( - "000" => "FAIL Verb missing", - "001" => "FAIL 22 verb 'bogus'", - "010" => "FAIL 87 provider", - "011" => "FAIL 22 provider 'bogus'", - "020" => "", - "021" => "FAIL 22 entries -1", - "022" => "PASS", - "023" => "FAIL 17 geom '%dev%'", - "024" => "FAIL 87 entry", - "025" => "b1856477950e5786898c8f01361196cf", - "030" => "FAIL 87 geom", - "031" => "FAIL 22 geom 'bogus'", - "032" => "FAIL 87 type", - "033" => "FAIL 22 type 'bogus'", - "034" => "FAIL 87 start", - "035" => "FAIL 22 start 1", - "036" => "FAIL 87 end", - "037" => "FAIL 22 end 12345678", - "038" => "FAIL 22 entry 129", - "039" => "PASS entry=5", - "040" => "FAIL 17 entry 5", - "041" => "FAIL 28 start/end 34/546", - "042" => "FAIL 28 start/end 162/417", - "043" => "FAIL 28 start/end 100/300", - "044" => "FAIL 28 start/end 300/500", - "045" => "PASS entry=1", - "046" => "PASS entry=2", - "047" => "50783a39eecfc62a29db24381e12b9d8", - "050" => "PASS", - "051" => "PASS", - "052" => "PASS", - "053" => "FAIL 2 entry 1", - "054" => "b1856477950e5786898c8f01361196cf", - "060" => "PASS", - "061" => "PASS", - "062" => "FAIL 16", - "063" => "PASS", - "064" => "PASS", - "065" => "b1856477950e5786898c8f01361196cf", - "100" => "", - "110" => "", - "111" => "FAIL 6 geom '%dev%'", - "120" => "", -); - -my $verbose = ""; -if (exists $ENV{'TEST_VERBOSE'}) { - $verbose = "-v"; -} - -# Compile the driver... -my $st = system("cc -o $cmd -g $srcdir/test.c -lgeom"); -if ($st != 0) { - print "1..0 # SKIP error compiling test.c\n"; - exit 0; -} - -# Make sure we have permission to use gctl... -if (`$cmd` =~ "^FAIL Permission denied") { - print "1..0 # SKIP not enough permission\n"; - unlink $cmd; - exit 0; -} - -$count = keys (%steps); -print "1..$count\n"; - -my $nr = 1; -my $dev = "n/a"; -foreach my $key (sort keys %steps) { - my ($action, $args) = split(/ /, $steps{$key}, 2); - my $res = $result{$key}; - $args = "" if (not defined $args); - $args =~ s/%dev%/$dev/g; - $res =~ s/%dev%/$dev/g; - - if ($action =~ "^gctl") { - system("$cmd $verbose $args | tee $out 2>&1"); - $st = `tail -1 $out`; - if ($st =~ "^$res") { - print "ok $nr \# gctl($key)\n"; - } else { - print "not ok $nr \# gctl($key) - $st\n"; - } - unlink $out; - } elsif ($action =~ "^mdcfg") { - if ($args =~ "^create") { - system("dd if=/dev/zero of=$disk count=1024 2>&1"); - if ($args =~ "corrupted") { - system("gpt create -p $disk"); - } - $dev = `mdconfig -a -t vnode -f $disk`; - chomp $dev; - } elsif ($args =~ "^destroy") { - $dev =~ s/md/-u /g; - system("mdconfig -d $dev"); - unlink $disk; - $dev = "n/a"; - } - print "ok $nr \# mdcfg($key)\n"; - } elsif ($action =~ "^conf") { - system("sysctl -b kern.geom.conftxt | grep -a $dev | sed -e s:$disk:DISK:g -e s:$dev:DEV:g | sort | md5 -p | tee $out 2>&1"); - $st = `tail -1 $out`; - if ($st =~ "^$res") { - print "ok $nr \# conf($key)\n"; - } else { - print "not ok $nr \# conf($key) - $st\n"; - } - unlink $out; - } elsif ($action =~ "^mount") { - system("mkdir $mntpt-$args"); - system("newfs $args"); - system("mount -t ufs /dev/$args $mntpt-$args"); - print "ok $nr \# mount($key)\n"; - } elsif ($action =~ "^umount") { - system("umount $mntpt-$args"); - system("rmdir $mntpt-$args"); - print "ok $nr \# umount($key)\n"; - } - $nr += 1; -} - -unlink $cmd; -exit 0; diff --git a/tools/regression/geom_gpt/gctl_test.t b/tools/regression/geom_gpt/gctl_test.t new file mode 100644 index 0000000..4161b96 --- /dev/null +++ b/tools/regression/geom_gpt/gctl_test.t @@ -0,0 +1,218 @@ +#!/usr/bin/env perl +# +# Copyright (c) 2005, 2006 Marcel Moolenaar +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# $FreeBSD$ + +use strict; +use warnings; + +use File::Basename; + +my $disk = "/tmp/disk-$$"; +my $mntpt_prefix = "/tmp/mount-$$"; + +my %steps = ( + "000" => "gctl", + "001" => "gctl verb=bogus", + "010" => "gctl verb=create", + "011" => "gctl verb=create provider=bogus", + "020" => "mdcfg create pristine", + "021" => "gctl verb=create provider=%dev% entries=-1", + "022" => "gctl verb=create provider=%dev% entries=128", + "023" => "gctl verb=create provider=%dev%", + "024" => "gctl verb=modify geom=%dev%", + "025" => "conf", + "030" => "gctl verb=add", + "031" => "gctl verb=add geom=bogus", + "032" => "gctl verb=add geom=%dev%", + "033" => "gctl verb=add geom=%dev% type=bogus", + "034" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace", + "035" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=1", + "036" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=34", + "037" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=34 end=12345678", + "038" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=162 end=417 entry=129", + "039" => "gctl verb=add geom=%dev% type=ed0101b0-2a71-11da-ba81-003048416ace start=162 end=417 entry:8=5", + "040" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=34 end=161 entry=5", + "041" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=34 end=546", + "042" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=162 end=417", + "043" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=100 end=300", + "044" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=300 end=500", + "045" => "gctl verb=add geom=%dev% type=83d34ed5-c4ff-11da-b65b-000347c5d7f3 start=34 end=161 entry:8", + "046" => "gctl verb=add geom=%dev% type=d2bd4509-c4ff-11da-b4cc-00306e39b62f start=418 end=546 entry:8", + "047" => "conf", + "050" => "gctl verb=remove geom=%dev% entry=5", + "051" => "gctl verb=remove geom=%dev% entry=2", + "052" => "gctl verb=remove geom=%dev% entry=1", + "053" => "gctl verb=remove geom=%dev% entry=1", + "054" => "conf", + "060" => "gctl verb=add geom=%dev% type=516e7cb6-6ecf-11d6-8ff8-00022d09712b start=34 end=546 entry:8=1", + "061" => "mount %dev%p1", + "062" => "gctl verb=delete geom=%dev% entry=1", + "063" => "umount %dev%p1", + "064" => "gctl verb=delete geom=%dev% entry=1", + "065" => "conf", + "100" => "mdcfg destroy", + "110" => "mdcfg create corrupted", + "111" => "gctl verb=add geom=%dev%", + "120" => "mdcfg destroy", +); + +my %result = ( + "000" => "FAIL Verb missing", + "001" => "FAIL 22 verb 'bogus'", + "010" => "FAIL 87 provider", + "011" => "FAIL 22 provider 'bogus'", + "020" => "", + "021" => "FAIL 22 entries -1", + "022" => "PASS", + "023" => "FAIL 17 geom '%dev%'", + "024" => "FAIL 87 entry", + "025" => "b1856477950e5786898c8f01361196cf", + "030" => "FAIL 87 geom", + "031" => "FAIL 22 geom 'bogus'", + "032" => "FAIL 87 type", + "033" => "FAIL 22 type 'bogus'", + "034" => "FAIL 87 start", + "035" => "FAIL 22 start 1", + "036" => "FAIL 87 end", + "037" => "FAIL 22 end 12345678", + "038" => "FAIL 22 entry 129", + "039" => "PASS entry=5", + "040" => "FAIL 17 entry 5", + "041" => "FAIL 28 start/end 34/546", + "042" => "FAIL 28 start/end 162/417", + "043" => "FAIL 28 start/end 100/300", + "044" => "FAIL 28 start/end 300/500", + "045" => "PASS entry=1", + "046" => "PASS entry=2", + "047" => "50783a39eecfc62a29db24381e12b9d8", + "050" => "PASS", + "051" => "PASS", + "052" => "PASS", + "053" => "FAIL 2 entry 1", + "054" => "b1856477950e5786898c8f01361196cf", + "060" => "PASS", + "061" => "PASS", + "062" => "FAIL 16", + "063" => "PASS", + "064" => "PASS", + "065" => "b1856477950e5786898c8f01361196cf", + "100" => "", + "110" => "", + "111" => "FAIL 6 geom '%dev%'", + "120" => "", +); + +my $verbose = ""; +if (exists $ENV{'TEST_VERBOSE'}) { + $verbose = "-v"; +} + +# Compile the driver... +my $st = system("make obj && make all"); +if ($st != 0) { + print "1..0 # SKIP error compiling test.c\n"; + exit 0; +} +chomp(my $cmd = `make '-V\${.OBJDIR}/\${PROG}'`); + +my $out = basename($cmd) . ".out"; + +# Make sure we have permission to use gctl... +if (`$cmd` =~ "^FAIL Permission denied") { + print "1..0 # SKIP insufficient permissions\n"; + unlink $cmd; + exit 0; +} + +my $count = keys (%steps); +print "1..$count\n"; + +my $nr = 1; +my $dev = "n/a"; +foreach my $key (sort keys %steps) { + my ($action, $args) = split(/ /, $steps{$key}, 2); + my $res = $result{$key}; + $args = "" if (not defined $args); + $args =~ s/%dev%/$dev/g; + $res =~ s/%dev%/$dev/g; + + if ($action =~ "^gctl") { + my $errmsg = ""; + system("$cmd $verbose $args | tee $out 2>&1"); + chomp($st = `tail -1 $out`); + if ($st ne $res) { + $errmsg = "\"$st\" (actual) != \"$res\" (expected)\n"; + } + printf("%sok $nr \# gctl($key)%s\n", + ($errmsg eq "" ? "" : "not "), + ($errmsg eq "" ? "" : " - $errmsg")); + unlink $out; + } elsif ($action =~ "^mdcfg") { + if ($args =~ "^create") { + system("dd if=/dev/zero of=$disk count=1024 2>&1"); + if ($args =~ "corrupted") { + system("gpt create -p $disk"); + } + $dev = `mdconfig -a -t vnode -f $disk`; + chomp $dev; + } elsif ($args =~ "^destroy") { + $dev =~ s/md/-u /g; + system("mdconfig -d $dev"); + unlink $disk; + $dev = "n/a"; + } + print "ok $nr \# mdcfg($key)\n"; + } elsif ($action =~ "^conf") { + system("sysctl -b kern.geom.conftxt | grep -a $dev | sed -e s:$disk:DISK:g -e s:$dev:DEV:g | sort | md5 -p | tee $out 2>&1"); + $st = `tail -1 $out`; + if ($st =~ "^$res") { + print "ok $nr \# conf($key)\n"; + } else { + print "not ok $nr \# conf($key) - $st\n"; + } + unlink $out; + } elsif ($action =~ "^mount") { + my $errmsg = ""; + mkdir("$mntpt_prefix-$args"); + if (system("newfs /dev/$args") == 0) { + if (system("mount /dev/$args $mntpt_prefix-$args") != 0) { + $errmsg = "mount failed"; + } + } else { + $errmsg = "newfs failed"; + } + printf("%sok $nr # mount($key)%s\n", + ($errmsg eq "" ? "" : "not "), + ($errmsg eq "" ? "" : " - $errmsg")); + } elsif ($action =~ "^umount") { + system("umount $mntpt_prefix-$args"); + system("rmdir $mntpt_prefix-$args"); + print "ok $nr \# umount($key)\n"; + } + $nr += 1; +} +exit 0; diff --git a/tools/regression/geom_gpt/gctl_test_helper.c b/tools/regression/geom_gpt/gctl_test_helper.c new file mode 100644 index 0000000..48440d0 --- /dev/null +++ b/tools/regression/geom_gpt/gctl_test_helper.c @@ -0,0 +1,173 @@ +/*- + * Copyright (c) 2005, 2006 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct retval { + struct retval *retval; + const char *param; + char *value; +}; + +static struct retval *retval; +static int verbose; + +static void +usage(void) +{ + fprintf(stdout, "usage: %s [-v] param[:len][=value] ...\n", + getprogname()); + exit(1); +} + +static int +parse(char *arg, char **param, char **value, int *len) +{ + char *e, *colon, *equal; + + if (*arg == '\0') + return (EINVAL); + + colon = strchr(arg, ':'); + equal = strchr(arg, '='); + if (colon == NULL && equal == NULL) + return (EINVAL); + if (colon == arg || equal == arg) + return (EINVAL); + if (colon != NULL && equal != NULL && equal < colon) + return (EINVAL); + + if (colon != NULL) + *colon++ = '\0'; + if (equal != NULL) + *equal++ = '\0'; + + *param = arg; + if (colon != NULL) { + /* Length specification. This parameter is RW. */ + if (*colon == '\0') + return (EINVAL); + *len = strtol(colon, &e, 0); + if (*e != '\0') + return (EINVAL); + if (*len <= 0 || *len > PATH_MAX) + return (EINVAL); + *value = malloc(*len); + if (*value == NULL) + return (ENOMEM); + memset(*value, 0, *len); + if (equal != NULL) { + if (strlen(equal) >= PATH_MAX) + return (ENOMEM); + strcpy(*value, equal); + } + } else { + /* This parameter is RO. */ + *len = -1; + if (*equal == '\0') + return (EINVAL); + *value = equal; + } + + return (0); +} + +int +main(int argc, char *argv[]) +{ + struct retval *rv; + struct gctl_req *req; + char *param, *value; + const char *s; + int c, len, parse_retval; + + req = gctl_get_handle(); + assert(req != NULL); + gctl_ro_param(req, "class", -1, "PART"); + + while ((c = getopt(argc, argv, "v")) != -1) { + switch (c) { + case 'v': + verbose = 1; + break; + case '?': + default: + usage(); + /* NOTREACHED */ + break; + } + } + + for (; optind < argc; optind++) { + parse_retval = parse(argv[optind], ¶m, &value, &len); + if (parse_retval == 0) { + if (len > 0) { + rv = malloc(sizeof(struct retval)); + assert(rv != NULL); + rv->param = param; + rv->value = value; + rv->retval = retval; + retval = rv; + gctl_rw_param(req, param, len, value); + } else + gctl_ro_param(req, param, -1, value); + } else + warnc(parse_retval, "failed to parse argument (%s)", + argv[optind]); + } + + if (verbose) + gctl_dump(req, stdout); + + s = gctl_issue(req); + if (s == NULL) { + printf("PASS"); + while (retval != NULL) { + rv = retval->retval; + printf(" %s=%s", retval->param, retval->value); + free(retval->value); + free(retval); + retval = rv; + } + printf("\n"); + } else + printf("FAIL %s\n", s); + + gctl_free(req); + return (0); +} diff --git a/tools/regression/geom_gpt/test.c b/tools/regression/geom_gpt/test.c deleted file mode 100644 index d750d30..0000000 --- a/tools/regression/geom_gpt/test.c +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * Copyright (c) 2005, 2006 Marcel Moolenaar - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include - -struct retval { - struct retval *retval; - const char *param; - char *value; -}; - -struct retval *retval; -int verbose; - -static void -usage() -{ - fprintf(stdout, "usage: %s [-v] param[:len][=value] ...\n", - getprogname()); - exit(1); -} - -static int -parse(char *arg, char **param, char **value, int *len) -{ - char *e, *colon, *equal; - - if (*arg == '\0') - return (EINVAL); - - colon = strchr(arg, ':'); - equal = strchr(arg, '='); - if (colon == NULL && equal == NULL) - return (EINVAL); - if (colon == arg || equal == arg) - return (EINVAL); - if (colon != NULL && equal != NULL && equal < colon) - return (EINVAL); - - if (colon != NULL) - *colon++ = '\0'; - if (equal != NULL) - *equal++ = '\0'; - - *param = arg; - if (colon != NULL) { - /* Length specification. This parameter is RW. */ - if (*colon == '\0') - return (EINVAL); - *len = strtol(colon, &e, 0); - if (*e != '\0') - return (EINVAL); - if (*len <= 0 || *len > PATH_MAX) - return (EINVAL); - *value = malloc(*len); - if (*value == NULL) - return (ENOMEM); - memset(*value, 0, *len); - if (equal != NULL) { - if (strlen(equal) >= PATH_MAX) - return (ENOMEM); - strcpy(*value, equal); - } - } else { - /* This parameter is RO. */ - *len = -1; - if (*equal == '\0') - return (EINVAL); - *value = equal; - } - - return (0); -} - -int main(int argc, char *argv[]) -{ - struct retval *rv; - struct gctl_req *req; - char *param, *value; - const char *s; - int c, len; - - req = gctl_get_handle(); - gctl_ro_param(req, "class", -1, "GPT"); - - while ((c = getopt(argc, argv, "v")) != -1) { - switch (c) { - case 'v': - verbose = 1; - break; - case '?': - default: - usage(); - /* NOTREACHED */ - break; - } - } - - while (optind < argc) { - if (!parse(argv[optind++], ¶m, &value, &len)) { - if (len > 0) { - rv = malloc(sizeof(struct retval)); - rv->param = param; - rv->value = value; - rv->retval = retval; - retval = rv; - gctl_rw_param(req, param, len, value); - } else - gctl_ro_param(req, param, -1, value); - } - } - - if (verbose) - gctl_dump(req, stdout); - - s = gctl_issue(req); - if (s == NULL) { - printf("PASS"); - while (retval != NULL) { - rv = retval->retval; - printf(" %s=%s", retval->param, retval->value); - free(retval->value); - free(retval); - retval = rv; - } - printf("\n"); - } else - printf("FAIL %s\n", s); - - gctl_free(req); - return (0); -} -- cgit v1.1