From e2ab736c33c8f2e273d4ff27f5f9eb7f454b08b4 Mon Sep 17 00:00:00 2001 From: ngie Date: Sat, 27 May 2017 23:31:59 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.freebsd.org/base/stable/10@319014 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- tools/regression/geom_gpt/Makefile | 11 ++++ .../geom_gpt/{gctl.t => gctl_test.t} | 61 +++++++++++-------- .../geom_gpt/{test.c => gctl_test_helper.c} | 28 ++++++--- 3 files changed, 65 insertions(+), 35 deletions(-) create mode 100644 tools/regression/geom_gpt/Makefile rename tools/regression/geom_gpt/{gctl.t => gctl_test.t} (85%) rename tools/regression/geom_gpt/{test.c => gctl_test_helper.c} (88%) diff --git a/tools/regression/geom_gpt/Makefile b/tools/regression/geom_gpt/Makefile new file mode 100644 index 000000000..c00376ca7 --- /dev/null +++ b/tools/regression/geom_gpt/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +PROG= gctl_test_helper +MAN= + +DPADD+= ${LIBGEOM} +LDADD+= -lgeom + +WARNS?= 6 + +.include diff --git a/tools/regression/geom_gpt/gctl.t b/tools/regression/geom_gpt/gctl_test.t similarity index 85% rename from tools/regression/geom_gpt/gctl.t rename to tools/regression/geom_gpt/gctl_test.t index f99e6d858..4161b968d 100644 --- a/tools/regression/geom_gpt/gctl.t +++ b/tools/regression/geom_gpt/gctl_test.t @@ -1,4 +1,4 @@ -#!/usr/bin/env perl -w +#!/usr/bin/env perl # # Copyright (c) 2005, 2006 Marcel Moolenaar # All rights reserved. @@ -26,13 +26,13 @@ # # $FreeBSD$ -my $srcdir = `dirname $0`; -chomp $srcdir; +use strict; +use warnings; + +use File::Basename; -my $cmd = "/tmp/gctl-$$"; -my $out = "$cmd.out"; my $disk = "/tmp/disk-$$"; -my $mntpt = "/tmp/mount-$$"; +my $mntpt_prefix = "/tmp/mount-$$"; my %steps = ( "000" => "gctl", @@ -70,9 +70,9 @@ my %steps = ( "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", + "062" => "gctl verb=delete geom=%dev% entry=1", "063" => "umount %dev%p1", - "064" => "gctl verb=remove geom=%dev% entry=1", + "064" => "gctl verb=delete geom=%dev% entry=1", "065" => "conf", "100" => "mdcfg destroy", "110" => "mdcfg create corrupted", @@ -132,20 +132,23 @@ if (exists $ENV{'TEST_VERBOSE'}) { } # Compile the driver... -my $st = system("cc -o $cmd -g $srcdir/test.c -lgeom"); +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 not enough permission\n"; + print "1..0 # SKIP insufficient permissions\n"; unlink $cmd; exit 0; } -$count = keys (%steps); +my $count = keys (%steps); print "1..$count\n"; my $nr = 1; @@ -158,13 +161,15 @@ foreach my $key (sort keys %steps) { $res =~ s/%dev%/$dev/g; if ($action =~ "^gctl") { + my $errmsg = ""; 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"; + 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") { @@ -191,17 +196,23 @@ foreach my $key (sort keys %steps) { } 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"; + 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-$args"); - system("rmdir $mntpt-$args"); - print "ok $nr \# umount($key)\n"; + system("umount $mntpt_prefix-$args"); + system("rmdir $mntpt_prefix-$args"); + print "ok $nr \# umount($key)\n"; } $nr += 1; } - -unlink $cmd; exit 0; diff --git a/tools/regression/geom_gpt/test.c b/tools/regression/geom_gpt/gctl_test_helper.c similarity index 88% rename from tools/regression/geom_gpt/test.c rename to tools/regression/geom_gpt/gctl_test_helper.c index d750d30e8..48440d037 100644 --- a/tools/regression/geom_gpt/test.c +++ b/tools/regression/geom_gpt/gctl_test_helper.c @@ -28,13 +28,15 @@ __FBSDID("$FreeBSD$"); #include +#include +#include #include -#include #include #include #include #include #include +#include struct retval { struct retval *retval; @@ -42,11 +44,11 @@ struct retval { char *value; }; -struct retval *retval; -int verbose; +static struct retval *retval; +static int verbose; static void -usage() +usage(void) { fprintf(stdout, "usage: %s [-v] param[:len][=value] ...\n", getprogname()); @@ -105,16 +107,18 @@ parse(char *arg, char **param, char **value, int *len) return (0); } -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { struct retval *rv; struct gctl_req *req; char *param, *value; const char *s; - int c, len; + int c, len, parse_retval; req = gctl_get_handle(); - gctl_ro_param(req, "class", -1, "GPT"); + assert(req != NULL); + gctl_ro_param(req, "class", -1, "PART"); while ((c = getopt(argc, argv, "v")) != -1) { switch (c) { @@ -129,10 +133,12 @@ int main(int argc, char *argv[]) } } - while (optind < argc) { - if (!parse(argv[optind++], ¶m, &value, &len)) { + 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; @@ -140,7 +146,9 @@ int main(int argc, char *argv[]) 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) -- 2.45.0