Skip to contentSkip to conversation

automation: introduce a script for build test

PATCH In review Wei Liu 4 participants 7 messages Jul 25, 2018

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH v6 1/1 automation: introduce a script for build test

---
This is a script I wrote previously for build test.

Given it basically runs a set of commands on every commit, maybe it should be named for-each-commit.sh ?

Cc Andrew Cooper <[email protected]>
Cc George Dunlap <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Tim Deegan <[email protected]>
Cc Wei Liu <[email protected]>
Cc Julien Grall <[email protected]>
Cc Anthony PERARD <[email protected]>

v6: Use pushd to switch to toplevel directory automatically.

v5:
1. Use bash so that while do ... done < () works.
2. Move script to automation directory.

v4:
1. Check, save/restore $?.
2. Don't use trap, check exit code directly.
3. More error messages.

v3:
1. Use git-clean in default rune.
2. Print more friendly message.
3. Restore HEAD automatically.

---
 automation/scripts/build-test.sh | 65 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100755 automation/scripts/build-test.sh
automation/scripts/build-test.sh new file +65 -0
new file mode 100755
index 0000000000..43ab71751c
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+# Run command on every commit within the range specified. If no command is
+# provided, use the default one to clean and build the whole tree.
+#
+# The default rune is rather simple. To do a cross-build, please put your usual
+# build rune in a shell script and invoke it with this script.
+
+if test $# -lt 2 ; then
+    echo "Usage: $0 <BASE> <TIP> [CMD]"
+    exit 1
+fi
+
+pushd `git rev-parse --show-toplevel`
+
+status=`git status -s`
+if test -n "$status"; then
+    echo "Tree is dirty, aborted"
+    exit 1
+fi
+
+BASE=$1; shift
+TIP=$1; shift
+
+ORIG_BRANCH=`git symbolic-ref -q --short HEAD`
+if test $? -ne 0; then
+    echo "Detached HEAD, aborted"
+    exit 1
+fi
+
+while read num rev; do
+    echo "Testing $num $rev"
+
+    git checkout $rev
+    ret=$?
+    if test $ret -ne 0; then
+        echo "Failed to checkout $num $rev with $ret"
+        break
+    fi
+
+    if test $# -eq 0 ; then
+        git clean -fdx && ./configure && make -j4
+    else
+        "$@"
+    fi
+    ret=$?
+    if test $ret -ne 0; then
+        echo "Failed at $num $rev with $ret"
+        break
+    fi
+    echo
+done < <(git rev-list $BASE..$TIP | nl -ba | tac)
+
+echo "Restoring original HEAD"
+git checkout $ORIG_BRANCH
+gco_ret=$?
+if test $gco_ret -ne 0; then
+    echo "Failed to restore orignal HEAD. Check tree status before doing anything else!"
+    exit $gco_ret
+fi
+
+if test $ret -eq 0; then
+    echo "ok."
+fi
+exit $ret
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 7 lines · Wei Liu

---
This is a script I wrote previously for build test.

Given it basically runs a set of commands on every commit, maybe it should be named for-each-commit.sh ?

Except that you also build just the whole series if the base and tip aren't specified.

Since it's about building a series (either all at once or one commit at a time), what about built-series? Or series-build-test?

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#2 lore raw
Quoted 6 lines · George Dunlap
Quoted 5 lines · Wei Liu

---
This is a script I wrote previously for build test.

Quoted 6 lines
Quoted 2 lines

Given it basically runs a set of commands on every commit, maybe it should be named for-each-commit.sh ?

Except that you also build just the whole series if the base and tip aren't specified.

What do you mean by this? Base and tip are required.

Quoted 3 lines

Since it's about building a series (either all at once or one commit at a time), what about built-series? Or series-build-test?

Not sure. My point was it could do more things than just building. You can supply your own script or commands to do stuff with each commit.

Wei.

Quoted 1 line

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 7 lines · Wei Liu
Quoted 6 lines · George Dunlap
Quoted 5 lines · Wei Liu

---
This is a script I wrote previously for build test.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Given it basically runs a set of commands on every commit, maybe it should be named for-each-commit.sh ?

Except that you also build just the whole series if the base and tip aren't specified.

What do you mean by this? Base and tip are required.

Oh, so it does. Sorry, for some reason when I skimmed it the first time I thought I saw that it had two different modes.

Quoted 6 lines
Quoted 3 lines

Since it's about building a series (either all at once or one commit at a time), what about built-series? Or series-build-test?

Not sure. My point was it could do more things than just building. You can supply your own script or commands to do stuff with each commit.

Yes, in that case, something like for-each-commit would be sensible. Although I might consider not including the 'default build' command in the script in that case, on the grounds that it would violate the principle of least surprise for a script named "for-each-commit" to start building things on its own.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v6 1/1
#5 lore raw
In reply to Wei Liu
Quoted 7 lines · Wei Liu

---
This is a script I wrote previously for build test.

Given it basically runs a set of commands on every commit, maybe it should be named for-each-commit.sh ?

So if we do that can we make it clear that there's a default action that's going to be run? Mentally I'd expect a script called like that would require a command that it would execute but you do have a default.

automation/scripts/build-test.sh line 42

Quoted 13 lines
automation/scripts/build-test.sh new file +13 -0
+
+while read num rev; do
+    echo "Testing $num $rev"
+
+    git checkout $rev
+    ret=$?
+    if test $ret -ne 0; then
+        echo "Failed to checkout $num $rev with $ret"
+        break
+    fi
+
+    if test $# -eq 0 ; then
+        git clean -fdx && ./configure && make -j4

maybe some comment in the code like "hey someone reading me this is the default command"

Overall I think this is a good addition to the tree. If people feel different than I do about the default command then feel free to commit with my:

--
Doug

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#4 lore raw
In reply to George Dunlap
Quoted 24 lines · George Dunlap
Quoted 7 lines · Wei Liu
Quoted 6 lines · George Dunlap
Quoted 5 lines · Wei Liu

---
This is a script I wrote previously for build test.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Given it basically runs a set of commands on every commit, maybe it should be named for-each-commit.sh ?

Except that you also build just the whole series if the base and tip aren't specified.

What do you mean by this? Base and tip are required.

Oh, so it does. Sorry, for some reason when I skimmed it the first time I thought I saw that it had two different modes.

Quoted 4 lines
Quoted 3 lines

Since it's about building a series (either all at once or one commit at a time), what about built-series? Or series-build-test?

Quoted 8 lines
Quoted 2 lines

Not sure. My point was it could do more things than just building. You can supply your own script or commands to do stuff with each commit.

Yes, in that case, something like for-each-commit would be sensible. Although I might consider not including the 'default build' command in the script in that case, on the grounds that it would violate the principle of least surprise for a script named "for-each-commit" to start building things on its own.

Thinking about it the main purpose of this script is help build test. It can be (ab)used to some other things is secondary. I think I will keep build-test.sh for now.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

author
#6 lore raw
In reply to Doug Goldstein
Quoted 6 lines · Doug Goldstein
Quoted 5 lines · Wei Liu

---
This is a script I wrote previously for build test.

Quoted 7 lines
Quoted 2 lines

Given it basically runs a set of commands on every commit, maybe it should be named for-each-commit.sh ?

So if we do that can we make it clear that there's a default action that's going to be run? Mentally I'd expect a script called like that would require a command that it would execute but you do have a default.

I think I will keep the old name for now. See my reply to George.

Quoted 8 lines
Quoted 8 lines
automation/scripts/build-test.sh new file +8 -0
+
+while read num rev; do
+    echo "Testing $num $rev"
+
+    git checkout $rev
+    ret=$?
+    if test $ret -ne 0; then
+        echo "Failed to checkout $num $rev with $ret"
Quoted 9 lines

automation/scripts/build-test.sh line 42

Quoted 5 lines
automation/scripts/build-test.sh new file +5 -0
+        break
+    fi
+
+    if test $# -eq 0 ; then
+        git clean -fdx && ./configure && make -j4

maybe some comment in the code like "hey someone reading me this is the default command"

I would add the following to the script usage output at the beginning.

echo "If [CMD] is not specified, run the default command git clean -fdx && ./configure && make -j4"

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel