[01/12] test-scripts: test migration scripts
diff mbox

Message ID 20151113213650.31124.16817.stgit@birch.djwong.org
State New
Headers show

Commit Message

Darrick J. Wong Nov. 13, 2015, 9:36 p.m. UTC
Add two scripts: "nextid" finds the next available test ID number in a
group, and "mvtest" relocates a test, fixes the golden output, and
moves the group entry for that test.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 mvtest |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 nextid |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+)
 create mode 100755 mvtest
 create mode 100755 nextid



--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Dave Chinner Nov. 16, 2015, 8:58 p.m. UTC | #1
On Fri, Nov 13, 2015 at 01:36:50PM -0800, Darrick J. Wong wrote:
> Add two scripts: "nextid" finds the next available test ID number in a
> group, and "mvtest" relocates a test, fixes the golden output, and
> moves the group entry for that test.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  mvtest |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  nextid |   35 +++++++++++++++++++++++++++++++++++

These should be placed in the "tools" directory.

>  create mode 100755 mvtest
>  create mode 100755 nextid
> 
> 
> diff --git a/mvtest b/mvtest
> new file mode 100755
> index 0000000..b5406d1
> --- /dev/null
> +++ b/mvtest
> @@ -0,0 +1,58 @@
> +#!/bin/sh
> +
> +# Renumber a test
> +
> +if [ -z "$1" ] || [ "$1" = "--help" ]; then
> +	echo "Usage: $0 path_to_test new_path_to_test"
> +	exit 1
> +fi
> +
> +src="$1"
> +dest="$2"
> +
> +die() {
> +	echo "$@"
> +	exit 1
> +}
> +
> +nsort() {
> +	sort -g < "$1" > "$2"
> +}
> +
> +append() {
> +	out="$1"
> +	shift
> +	echo "$@" >> "${out}"
> +}
> +
> +test "${src}" != "${dest}" || die "Test \"${src}\" is the same as dest."
> +test -e "tests/${src}" || die "Test \"${src}\" does not exist."
> +test ! -e "tests/${dest}" || die "Test \"${src}\" already exists."
> +
> +sid="$(basename "${src}")"
> +did="$(basename "${dest}")"
> +
> +sgroup="$(basename "$(dirname "tests/${src}")")"
> +dgroup="$(basename "$(dirname "tests/${dest}")")"
> +
> +sgroupfile="tests/${sgroup}/group"
> +dgroupfile="tests/${sgroup}/group"
> +
> +$DBG git mv "tests/${src}" "tests/${dest}"

$DBG?

....
> +$DBG sed -e "/^${sid}.*$/d" -i "${sgroupfile}"
> +$DBG cp "${dgroupfile}" "${dgroupfile}.new"
> +$DBG append "${dgroupfile}.new" "${newgrpline}"
> +$DBG nsort "${dgroupfile}.new" "${dgroupfile}"

What does this do to comments in the group file?

...

> diff --git a/nextid b/nextid
> new file mode 100755
> index 0000000..285b549
> --- /dev/null
> +++ b/nextid
> @@ -0,0 +1,35 @@
> +#!/bin/sh
> +
> +# Given a group name, find the next available test number.
> +
> +if [ -z "$1" ] || [ "$1" = "--help" ]; then
> +	echo "Usage: $0 groupname[/start_looking_at_this_number]"
> +	exit 1
> +fi
> +
> +die() {
> +	echo "$@"
> +	exit 1
> +}
> +
> +if [ "$(basename "$1")" != "$1" ]; then
> +	group="$(dirname "$1")"
> +	id="$(basename "$1")"
> +else
> +	group="$1"
> +	id=1
> +fi
> +test -e "tests/${group}/group" || die "Unknown group \"${group}\"."
> +
> +while test "${id}" -lt 1000; do
> +	name="$(printf "%.03d" "${id}")"
> +	if [ ! -e "tests/${group}/${name}" ]; then
> +		echo "${group}/${name}"
> +		exit 0
> +	fi
> +	id=$((id + 1))
> +done
> +
> +echo "No free IDs less than ${id} in group \"${group}\"."

So the "new" script does this differently, by reading the group
file and looking for the first non-contiguous ID in the file. It
doesn't need scan ID limits because EOF triggers that. Wouldn't it
be better to to factor the code out of the "new" script to find the
next id, and then have the new script call that?

Cheers,

Dave.
Darrick J. Wong Nov. 16, 2015, 11:51 p.m. UTC | #2
On Tue, Nov 17, 2015 at 07:58:45AM +1100, Dave Chinner wrote:
> On Fri, Nov 13, 2015 at 01:36:50PM -0800, Darrick J. Wong wrote:
> > Add two scripts: "nextid" finds the next available test ID number in a
> > group, and "mvtest" relocates a test, fixes the golden output, and
> > moves the group entry for that test.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >  mvtest |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  nextid |   35 +++++++++++++++++++++++++++++++++++
> 
> These should be placed in the "tools" directory.

<nod>

> 
> >  create mode 100755 mvtest
> >  create mode 100755 nextid
> > 
> > 
> > diff --git a/mvtest b/mvtest
> > new file mode 100755
> > index 0000000..b5406d1
> > --- /dev/null
> > +++ b/mvtest
> > @@ -0,0 +1,58 @@
> > +#!/bin/sh
> > +
> > +# Renumber a test
> > +
> > +if [ -z "$1" ] || [ "$1" = "--help" ]; then
> > +	echo "Usage: $0 path_to_test new_path_to_test"
> > +	exit 1
> > +fi
> > +
> > +src="$1"
> > +dest="$2"
> > +
> > +die() {
> > +	echo "$@"
> > +	exit 1
> > +}
> > +
> > +nsort() {
> > +	sort -g < "$1" > "$2"
> > +}
> > +
> > +append() {
> > +	out="$1"
> > +	shift
> > +	echo "$@" >> "${out}"
> > +}
> > +
> > +test "${src}" != "${dest}" || die "Test \"${src}\" is the same as dest."
> > +test -e "tests/${src}" || die "Test \"${src}\" does not exist."
> > +test ! -e "tests/${dest}" || die "Test \"${src}\" already exists."
> > +
> > +sid="$(basename "${src}")"
> > +did="$(basename "${dest}")"
> > +
> > +sgroup="$(basename "$(dirname "tests/${src}")")"
> > +dgroup="$(basename "$(dirname "tests/${dest}")")"
> > +
> > +sgroupfile="tests/${sgroup}/group"
> > +dgroupfile="tests/${sgroup}/group"
> > +
> > +$DBG git mv "tests/${src}" "tests/${dest}"
> 
> $DBG?

"DBG=echo ./mvtest foo bar" to see what it would have run, more or less.

(I suppose I could getopt a --dry-run, but I could also just get rid of them.)

> 
> ....
> > +$DBG sed -e "/^${sid}.*$/d" -i "${sgroupfile}"
> > +$DBG cp "${dgroupfile}" "${dgroupfile}.new"
> > +$DBG append "${dgroupfile}.new" "${newgrpline}"
> > +$DBG nsort "${dgroupfile}.new" "${dgroupfile}"
> 
> What does this do to comments in the group file?

Eats them.  I don't know of a good way to sort just the uncommented lines
in the file, short of writing a python script to do that.

I guess it's not that hard; I've sort of needed one here and there over
the years, but never wrote one, and $google doesn't immediately provide
any such thing.

> 
> ...
> 
> > diff --git a/nextid b/nextid
> > new file mode 100755
> > index 0000000..285b549
> > --- /dev/null
> > +++ b/nextid
> > @@ -0,0 +1,35 @@
> > +#!/bin/sh
> > +
> > +# Given a group name, find the next available test number.
> > +
> > +if [ -z "$1" ] || [ "$1" = "--help" ]; then
> > +	echo "Usage: $0 groupname[/start_looking_at_this_number]"
> > +	exit 1
> > +fi
> > +
> > +die() {
> > +	echo "$@"
> > +	exit 1
> > +}
> > +
> > +if [ "$(basename "$1")" != "$1" ]; then
> > +	group="$(dirname "$1")"
> > +	id="$(basename "$1")"
> > +else
> > +	group="$1"
> > +	id=1
> > +fi
> > +test -e "tests/${group}/group" || die "Unknown group \"${group}\"."
> > +
> > +while test "${id}" -lt 1000; do
> > +	name="$(printf "%.03d" "${id}")"
> > +	if [ ! -e "tests/${group}/${name}" ]; then
> > +		echo "${group}/${name}"
> > +		exit 0
> > +	fi
> > +	id=$((id + 1))
> > +done
> > +
> > +echo "No free IDs less than ${id} in group \"${group}\"."
> 
> So the "new" script does this differently, by reading the group
> file and looking for the first non-contiguous ID in the file. It
> doesn't need scan ID limits because EOF triggers that. Wouldn't it
> be better to to factor the code out of the "new" script to find the
> next id, and then have the new script call that?

Sure!

--D

> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Darrick J. Wong Nov. 17, 2015, 9:16 p.m. UTC | #3
On Mon, Nov 16, 2015 at 03:51:11PM -0800, Darrick J. Wong wrote:
> On Tue, Nov 17, 2015 at 07:58:45AM +1100, Dave Chinner wrote:
> > On Fri, Nov 13, 2015 at 01:36:50PM -0800, Darrick J. Wong wrote:
> > > Add two scripts: "nextid" finds the next available test ID number in a
> > > group, and "mvtest" relocates a test, fixes the golden output, and
> > > moves the group entry for that test.
> > > 
> > > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > > ---
> > >  mvtest |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >  nextid |   35 +++++++++++++++++++++++++++++++++++
> > 
> > These should be placed in the "tools" directory.
> 
> <nod>
> 
> > 
> > >  create mode 100755 mvtest
> > >  create mode 100755 nextid
> > > 
> > > 
> > > diff --git a/mvtest b/mvtest
> > > new file mode 100755
> > > index 0000000..b5406d1
> > > --- /dev/null
> > > +++ b/mvtest
> > > @@ -0,0 +1,58 @@
> > > +#!/bin/sh
> > > +
> > > +# Renumber a test
> > > +
> > > +if [ -z "$1" ] || [ "$1" = "--help" ]; then
> > > +	echo "Usage: $0 path_to_test new_path_to_test"
> > > +	exit 1
> > > +fi
> > > +
> > > +src="$1"
> > > +dest="$2"
> > > +
> > > +die() {
> > > +	echo "$@"
> > > +	exit 1
> > > +}
> > > +
> > > +nsort() {
> > > +	sort -g < "$1" > "$2"
> > > +}
> > > +
> > > +append() {
> > > +	out="$1"
> > > +	shift
> > > +	echo "$@" >> "${out}"
> > > +}
> > > +
> > > +test "${src}" != "${dest}" || die "Test \"${src}\" is the same as dest."
> > > +test -e "tests/${src}" || die "Test \"${src}\" does not exist."
> > > +test ! -e "tests/${dest}" || die "Test \"${src}\" already exists."
> > > +
> > > +sid="$(basename "${src}")"
> > > +did="$(basename "${dest}")"
> > > +
> > > +sgroup="$(basename "$(dirname "tests/${src}")")"
> > > +dgroup="$(basename "$(dirname "tests/${dest}")")"
> > > +
> > > +sgroupfile="tests/${sgroup}/group"
> > > +dgroupfile="tests/${sgroup}/group"
> > > +
> > > +$DBG git mv "tests/${src}" "tests/${dest}"
> > 
> > $DBG?
> 
> "DBG=echo ./mvtest foo bar" to see what it would have run, more or less.
> 
> (I suppose I could getopt a --dry-run, but I could also just get rid of them.)
> 
> > 
> > ....
> > > +$DBG sed -e "/^${sid}.*$/d" -i "${sgroupfile}"
> > > +$DBG cp "${dgroupfile}" "${dgroupfile}.new"
> > > +$DBG append "${dgroupfile}.new" "${newgrpline}"
> > > +$DBG nsort "${dgroupfile}.new" "${dgroupfile}"
> > 
> > What does this do to comments in the group file?
> 
> Eats them.  I don't know of a good way to sort just the uncommented lines
> in the file, short of writing a python script to do that.
> 
> I guess it's not that hard; I've sort of needed one here and there over
> the years, but never wrote one, and $google doesn't immediately provide
> any such thing.
> 
> > 
> > ...
> > 
> > > diff --git a/nextid b/nextid
> > > new file mode 100755
> > > index 0000000..285b549
> > > --- /dev/null
> > > +++ b/nextid
> > > @@ -0,0 +1,35 @@
> > > +#!/bin/sh
> > > +
> > > +# Given a group name, find the next available test number.
> > > +
> > > +if [ -z "$1" ] || [ "$1" = "--help" ]; then
> > > +	echo "Usage: $0 groupname[/start_looking_at_this_number]"
> > > +	exit 1
> > > +fi
> > > +
> > > +die() {
> > > +	echo "$@"
> > > +	exit 1
> > > +}
> > > +
> > > +if [ "$(basename "$1")" != "$1" ]; then
> > > +	group="$(dirname "$1")"
> > > +	id="$(basename "$1")"
> > > +else
> > > +	group="$1"
> > > +	id=1
> > > +fi
> > > +test -e "tests/${group}/group" || die "Unknown group \"${group}\"."
> > > +
> > > +while test "${id}" -lt 1000; do
> > > +	name="$(printf "%.03d" "${id}")"
> > > +	if [ ! -e "tests/${group}/${name}" ]; then
> > > +		echo "${group}/${name}"
> > > +		exit 0
> > > +	fi
> > > +	id=$((id + 1))
> > > +done
> > > +
> > > +echo "No free IDs less than ${id} in group \"${group}\"."
> > 
> > So the "new" script does this differently, by reading the group
> > file and looking for the first non-contiguous ID in the file. It
> > doesn't need scan ID limits because EOF triggers that. Wouldn't it
> > be better to to factor the code out of the "new" script to find the
> > next id, and then have the new script call that?
> 
> Sure!

In the end I wrote a short Python program to sort group files and it wasn't
much harder to reuse the code to implement nextid, so I did that instead.

I'll probably post this and a patch to fix the error codes in generic/157
later this week.

--D

> 
> --D
> 
> > 
> > Cheers,
> > 
> > Dave.
> > -- 
> > Dave Chinner
> > david@fromorbit.com
> > 
> > _______________________________________________
> > xfs mailing list
> > xfs@oss.sgi.com
> > http://oss.sgi.com/mailman/listinfo/xfs
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/mvtest b/mvtest
new file mode 100755
index 0000000..b5406d1
--- /dev/null
+++ b/mvtest
@@ -0,0 +1,58 @@ 
+#!/bin/sh
+
+# Renumber a test
+
+if [ -z "$1" ] || [ "$1" = "--help" ]; then
+	echo "Usage: $0 path_to_test new_path_to_test"
+	exit 1
+fi
+
+src="$1"
+dest="$2"
+
+die() {
+	echo "$@"
+	exit 1
+}
+
+nsort() {
+	sort -g < "$1" > "$2"
+}
+
+append() {
+	out="$1"
+	shift
+	echo "$@" >> "${out}"
+}
+
+test "${src}" != "${dest}" || die "Test \"${src}\" is the same as dest."
+test -e "tests/${src}" || die "Test \"${src}\" does not exist."
+test ! -e "tests/${dest}" || die "Test \"${src}\" already exists."
+
+sid="$(basename "${src}")"
+did="$(basename "${dest}")"
+
+sgroup="$(basename "$(dirname "tests/${src}")")"
+dgroup="$(basename "$(dirname "tests/${dest}")")"
+
+sgroupfile="tests/${sgroup}/group"
+dgroupfile="tests/${sgroup}/group"
+
+$DBG git mv "tests/${src}" "tests/${dest}"
+$DBG git mv "tests/${src}.out" "tests/${dest}.out"
+$DBG sed -e "s/^# FS QA Test No. ${sid}$/# FS QA Test No. ${did}/g" -i "tests/${dest}"
+$DBG sed -e "s/^QA output created by ${sid}$/QA output created by ${did}/g" -i "tests/${dest}.out"
+$DBG sed -e "s/test-${sid}/test-${did}/g" -i "tests/${dest}.out"
+
+grpline="$(grep "^${sid} " "${sgroupfile}")"
+newgrpline="$(echo "${grpline}" | sed -e "s/^${sid} /${did} /g")"
+
+$DBG sed -e "/^${sid}.*$/d" -i "${sgroupfile}"
+$DBG cp "${dgroupfile}" "${dgroupfile}.new"
+$DBG append "${dgroupfile}.new" "${newgrpline}"
+$DBG nsort "${dgroupfile}.new" "${dgroupfile}"
+$DBG rm "${dgroupfile}.new"
+
+echo "Moved \"${src}\" to \"${dest}\"."
+
+exit 0
diff --git a/nextid b/nextid
new file mode 100755
index 0000000..285b549
--- /dev/null
+++ b/nextid
@@ -0,0 +1,35 @@ 
+#!/bin/sh
+
+# Given a group name, find the next available test number.
+
+if [ -z "$1" ] || [ "$1" = "--help" ]; then
+	echo "Usage: $0 groupname[/start_looking_at_this_number]"
+	exit 1
+fi
+
+die() {
+	echo "$@"
+	exit 1
+}
+
+if [ "$(basename "$1")" != "$1" ]; then
+	group="$(dirname "$1")"
+	id="$(basename "$1")"
+else
+	group="$1"
+	id=1
+fi
+test -e "tests/${group}/group" || die "Unknown group \"${group}\"."
+
+while test "${id}" -lt 1000; do
+	name="$(printf "%.03d" "${id}")"
+	if [ ! -e "tests/${group}/${name}" ]; then
+		echo "${group}/${name}"
+		exit 0
+	fi
+	id=$((id + 1))
+done
+
+echo "No free IDs less than ${id} in group \"${group}\"."
+
+exit 1