Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 May 2017 23:31:59 +0000 (UTC)
From:      Ngie Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r319014 - stable/10/tools/regression/geom_gpt
Message-ID:  <201705272331.v4RNVxkw070122@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Sat May 27 23:31:59 2017
New Revision: 319014
URL: https://svnweb.freebsd.org/changeset/base/319014

Log:
  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.

Added:
  stable/10/tools/regression/geom_gpt/Makefile
     - copied, changed from r317292, head/tools/regression/geom_gpt/Makefile
  stable/10/tools/regression/geom_gpt/gctl_test.t
     - copied, changed from r317291, head/tools/regression/geom_gpt/gctl_test.t
  stable/10/tools/regression/geom_gpt/gctl_test_helper.c
     - copied, changed from r317291, head/tools/regression/geom_gpt/gctl_test_helper.c
Deleted:
  stable/10/tools/regression/geom_gpt/gctl.t
  stable/10/tools/regression/geom_gpt/test.c
Modified:
Directory Properties:
  stable/10/   (props changed)

Copied and modified: stable/10/tools/regression/geom_gpt/Makefile (from r317292, head/tools/regression/geom_gpt/Makefile)
==============================================================================
--- head/tools/regression/geom_gpt/Makefile	Sat Apr 22 20:15:47 2017	(r317292, copy source)
+++ stable/10/tools/regression/geom_gpt/Makefile	Sat May 27 23:31:59 2017	(r319014)
@@ -3,6 +3,9 @@
 PROG=	gctl_test_helper
 MAN=
 
-LIBADD+=	geom
+DPADD+=	${LIBGEOM}
+LDADD+=	-lgeom
+
+WARNS?=	6
 
 .include <bsd.prog.mk>

Copied and modified: stable/10/tools/regression/geom_gpt/gctl_test.t (from r317291, head/tools/regression/geom_gpt/gctl_test.t)
==============================================================================
--- head/tools/regression/geom_gpt/gctl_test.t	Sat Apr 22 20:06:11 2017	(r317291, copy source)
+++ stable/10/tools/regression/geom_gpt/gctl_test.t	Sat May 27 23:31:59 2017	(r319014)
@@ -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/gctl_test_helper.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;

Copied and modified: stable/10/tools/regression/geom_gpt/gctl_test_helper.c (from r317291, head/tools/regression/geom_gpt/gctl_test_helper.c)
==============================================================================
--- head/tools/regression/geom_gpt/gctl_test_helper.c	Sat Apr 22 20:06:11 2017	(r317291, copy source)
+++ stable/10/tools/regression/geom_gpt/gctl_test_helper.c	Sat May 27 23:31:59 2017	(r319014)
@@ -28,6 +28,8 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
+#include <assert.h>
+#include <err.h>
 #include <errno.h>
 #include <limits.h>
 #include <stdio.h>
@@ -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 **va
 	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++], &param, &value, &len)) {
+	for (; optind < argc; optind++) {
+		parse_retval = parse(argv[optind], &param, &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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705272331.v4RNVxkw070122>