travis: run all coccinelle scripts
cover travis: run all coccinelle scripts
Another item from my 'automated testing' list: use travis-ci to run coccinelle scripts. This series is more of a PoC. The idea would be to run it once a day only on /master.
Patch 1 is here only to speedup travis testing.
Patch 3 add a script which run each cocci script sequencially. If the script modified any file from the repo, changes are commited. If the script generated some output (i.e. using python), this output is logged in an empty commit. Spatch is run thru a debian-based Docker image.
Patch 4 is the travis job: it calls the previous script. To respect travis time limit timeout, each script is limited to <10min. If any commit were generated, they are pushed to my gh-repo:
Build output (Ran for 23 min 7 sec):
https://travis-ci.org/philmd/qemu/builds/246848085
Any idea is welcome :)
Regards,
Phil.
Philippe Mathieu-Daudé (4):
travis: simplify matrix
coccinelle: ignore ASTs pre-parsed cached C files
coccinelle: script to run them all
travis: add job to run coccinelle scripts
.gitignore | 2 + .travis.sshkey | Bin 0 -> 1296 bytes .travis.yml | 145 ++++++----------------------------------- scripts/check-cocci-scripts.sh | 47 +++++++++++++ 4 files changed, 69 insertions(+), 125 deletions(-) create mode 100644 .travis.sshkey create mode 100755 scripts/check-cocci-scripts.sh
Signature · 1 line
2.13.1
RFC PATCH 1/4 XXX travis: simplify matrix
to speedup further testing
--- .travis.yml | 119 ------------------------------------------------------------ 1 file changed, 119 deletions(-)
.travis.yml +0 -119
@@ -48,11 +48,6 @@ env: - TEST_CMD="make check" matrix: - CONFIG="" - - CONFIG="--enable-debug --enable-debug-tcg --enable-trace-backends=log" - - CONFIG="--disable-linux-aio --disable-cap-ng --disable-attr --disable-brlapi --disable-uuid --disable-libusb" - - CONFIG="--enable-modules" - - CONFIG="--with-coroutine=ucontext" - - CONFIG="--with-coroutine=sigaltstack" git: # we want to do this ourselves submodules: false
@@ -67,39 +62,6 @@ script: - make -j3 && ${TEST_CMD} matrix: include: - # Test with CLang for compile portability - - env: CONFIG="" - compiler: clang - # gprof/gcov are GCC features - - env: CONFIG="--enable-gprof --enable-gcov --disable-pie" - compiler: gcc - # We manually include builds which we disable "make check" for - - env: CONFIG="--enable-debug --enable-tcg-interpreter" - TEST_CMD="" - compiler: gcc - - env: CONFIG="--enable-trace-backends=simple" - TEST_CMD="" - compiler: gcc - - env: CONFIG="--enable-trace-backends=ftrace" - TEST_CMD="" - compiler: gcc - - env: CONFIG="--enable-trace-backends=ust" - TEST_CMD="" - compiler: gcc - - env: CONFIG="" - os: osx - compiler: clang - # Plain Trusty System Build - - env: CONFIG="--disable-linux-user" - sudo: required - addons: - dist: trusty - compiler: gcc - before_install: - - sudo apt-get update -qq - - sudo apt-get build-dep -qq qemu - - wget -O - http://people.linaro.org/~alex.bennee/qemu-submodule-git-seed.tar.xz | tar -xvJ - - git submodule update --init --recursive # Plain Trusty Linux User Build - env: CONFIG="--disable-system" sudo: required
@@ -111,84 +73,3 @@ matrix: - sudo apt-get build-dep -qq qemu - wget -O - http://people.linaro.org/~alex.bennee/qemu-submodule-git-seed.tar.xz | tar -xvJ - git submodule update --init --recursive - # Trusty System build with latest stable clang - - sudo: required - addons: - dist: trusty - language: generic - compiler: none - env: - - COMPILER_NAME=clang CXX=clang++-3.9 CC=clang-3.9 - - CONFIG="--disable-linux-user --cc=clang-3.9 --cxx=clang++-3.9" - before_install: - - wget -nv -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add - - - sudo apt-add-repository -y 'deb http://llvm.org/apt/trusty llvm-toolchain-trusty-3.9 main' - - sudo apt-get update -qq - - sudo apt-get install -qq -y clang-3.9 - - sudo apt-get build-dep -qq qemu - - wget -O - http://people.linaro.org/~alex.bennee/qemu-submodule-git-seed.tar.xz | tar -xvJ - - git submodule update --init --recursive - before_script: - - ./configure ${CONFIG} || cat config.log - # Trusty Linux User build with latest stable clang - - sudo: required - addons: - dist: trusty - language: generic - compiler: none - env: - - COMPILER_NAME=clang CXX=clang++-3.9 CC=clang-3.9 - - CONFIG="--disable-system --cc=clang-3.9 --cxx=clang++-3.9" - before_install: - - wget -nv -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add - - - sudo apt-add-repository -y 'deb http://llvm.org/apt/trusty llvm-toolchain-trusty-3.9 main' - - sudo apt-get update -qq - - sudo apt-get install -qq -y clang-3.9 - - sudo apt-get build-dep -qq qemu - - wget -O - http://people.linaro.org/~alex.bennee/qemu-submodule-git-seed.tar.xz | tar -xvJ - - git submodule update --init --recursive - before_script: - - ./configure ${CONFIG} || cat config.log - # Using newer GCC with sanitizers - - addons: - apt: - sources: - # PPAs for newer toolchains - - ubuntu-toolchain-r-test - packages: - # Extra toolchains - - gcc-5 - - g++-5 - # Build dependencies - - libaio-dev - - libattr1-dev - - libbrlapi-dev - - libcap-ng-dev - - libgnutls-dev - - libgtk-3-dev - - libiscsi-dev - - liblttng-ust-dev - - libnfs-dev - - libncurses5-dev - - libnss3-dev - - libpixman-1-dev - - libpng12-dev - - librados-dev - - libsdl1.2-dev - - libseccomp-dev - - libspice-protocol-dev - - libspice-server-dev - - libssh2-1-dev - - liburcu-dev - - libusb-1.0-0-dev - - libvte-2.90-dev - - sparse - - uuid-dev - language: generic - compiler: none - env: - - COMPILER_NAME=gcc CXX=g++-5 CC=gcc-5 - - CONFIG="--cc=gcc-5 --cxx=g++-5 --disable-pie --disable-linux-user" - - TEST_CMD="" - before_script: - - ./configure ${CONFIG} --extra-cflags="-g3 -O0 -fsanitize=thread -fuse-ld=gold" || cat config.log
Signature · 1 line
2.13.1
RFC PATCH 2/4 coccinelle: ignore ASTs pre-parsed cached C files
In reply to Philippe Mathieu-Daudéfiles generated using coccinelle tool: 'spatch --use-cache'
--- .gitignore | 2 ++ 1 file changed, 2 insertions(+)
.gitignore +2 -0
@@ -116,6 +116,8 @@ tags TAGS docker-src.* *~ +*.ast_raw +*.depend_raw trace.h trace.c trace-ust.h
Signature · 1 line
2.13.1
RFC PATCH 3/4 coccinelle: script to run them all
In reply to Philippe Mathieu-Daudé--- scripts/check-cocci-scripts.sh | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 scripts/check-cocci-scripts.sh
scripts/check-cocci-scripts.sh new file +47 -0
@@ -0,0 +1,47 @@ +#! /usr/bin/env bash + +test -d scripts/coccinelle || exit 1 + +SPATCH_IMAGE="philmd/coccinelle:1.0.4" + +GIT_AUTHOR_NAME="Coccinelle Spatch" +GIT_COMMITTER_NAME="Coccinelle Spatch" + +if [ -n "$TRAVIS" ]; then + # avoid stalling builds: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received + TIMEOUT_S=530 + TIMEOUT_CMD="timeout -k 550 500" + EXTRA_ARGS="--timeout ${TIMEOUT_S}" +else + TIMEOUT_S=0 +fi + +HEAD=19 #`echo -n scripts/coccinelle/ | wc -c` +TAIL=6 #`echo -n .cocci | wc -c` + +test -z "$(${SUDO} docker images -q ${SPATCH_IMAGE})" && ${SUDO} docker pull ${SPATCH_IMAGE} + +LOG=/tmp/cocci-spatch-$$ +for script in scripts/coccinelle/*.cocci; do + desc=${script:$HEAD:-$TAIL} + echo -e "\nRunning ${script}...\n" + echo -e "coccinelle: committing changes after running \"$desc\" script\n" > ${LOG}.topic + ${TIMEOUT_CMD} ${SUDO} \ + docker run --rm -v `pwd`:`pwd` -w `pwd` -u `id -u` \ + ${SPATCH_IMAGE} --use-cache --use-gitgrep --keep-comments \ + --very-quiet ${EXTRA_ARGS} \ + --sp-file ${script} \ + --macro-file scripts/cocci-macro-file.h \ + --dir . \ + --in-place | tee ${LOG}.content + git add -u + git diff --cached --exit-code -s + if [ $? -ne 0 ]; then + :> ${LOG}.content + else + test -s ${LOG}.content || continue + fi + cat ${LOG}.{topic,content} | git commit --allow-empty -F - +done + +rm -f ${LOG}.{topic,content}
Signature · 1 line
2.13.1
Re: [Qemu-devel] [RFC PATCH 3/4] coccinelle: script to run them all
Quoted 25 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- scripts/check-cocci-scripts.sh | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 scripts/check-cocci-scripts.shscripts/check-cocci-scripts.sh new file +13
-0@@ -0,0 +1,47 @@ +#! /usr/bin/env bash + +test -d scripts/coccinelle || exit 1 + +SPATCH_IMAGE="philmd/coccinelle:1.0.4" + +GIT_AUTHOR_NAME="Coccinelle Spatch" +GIT_COMMITTER_NAME="Coccinelle Spatch" + +if [ -n "$TRAVIS" ]; then + # avoid stalling builds: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received + TIMEOUT_S=530 + TIMEOUT_CMD="timeout -k 550 500"
scripts/check-cocci-scripts.sh line 23
Quoted 10 lines
scripts/check-cocci-scripts.sh new file +10
-0+ EXTRA_ARGS="--timeout ${TIMEOUT_S}" +else + TIMEOUT_S=0 +fi + +HEAD=19 #`echo -n scripts/coccinelle/ | wc -c` +TAIL=6 #`echo -n .cocci | wc -c` + +test -z "$(${SUDO} docker images -q ${SPATCH_IMAGE})" && ${SUDO} docker pull ${SPATCH_IMAGE} +
Can the docker magic be made optional (and disabled by default), so people who already have Coccinelle installed can run this script more quickly?
Quoted 27 lines
scripts/check-cocci-scripts.sh new file +24
-0+LOG=/tmp/cocci-spatch-$$ +for script in scripts/coccinelle/*.cocci; do + desc=${script:$HEAD:-$TAIL} + echo -e "\nRunning ${script}...\n" + echo -e "coccinelle: committing changes after running \"$desc\" script\n" > ${LOG}.topic + ${TIMEOUT_CMD} ${SUDO} \ + docker run --rm -v `pwd`:`pwd` -w `pwd` -u `id -u` \ + ${SPATCH_IMAGE} --use-cache --use-gitgrep --keep-comments \ + --very-quiet ${EXTRA_ARGS} \ + --sp-file ${script} \ + --macro-file scripts/cocci-macro-file.h \ + --dir . \ + --in-place | tee ${LOG}.content + git add -u + git diff --cached --exit-code -s + if [ $? -ne 0 ]; then + :> ${LOG}.content + else + test -s ${LOG}.content || continue + fi + cat ${LOG}.{topic,content} | git commit --allow-empty -F - +done + +rm -f ${LOG}.{topic,content}Signature · 1 line
2.13.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [RFC PATCH 3/4] coccinelle: script to run them all
Quoted 1 line · Eduardo Habkost
On Sun, Jun 25, 2017 at 04:29:49PM -0300, Philippe Mathieu-Daudé wrote:
[...]
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+test -z "$(${SUDO} docker images -q ${SPATCH_IMAGE})" && ${SUDO} docker pull ${SPATCH_IMAGE} +Can the docker magic be made optional (and disabled by default), so people who already have Coccinelle installed can run this script more quickly?
Ok. Actually I didn't even think about running out of docker, the list of ocaml requisites scared me a bit.
Using a dockerized spatch allow to stick to a common version (so I know the scripts I run locally will run exactly the same on Travis). But it makes sens ;)
I tried the multi-threaded options and for some reason they did not work within docker, but I did not try out of it.
Regards,
Phil.
Re: [Qemu-devel] [RFC PATCH 3/4] coccinelle: script to run them all
In reply to Philippe Mathieu-DaudéQuoted 38 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- scripts/check-cocci-scripts.sh | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 scripts/check-cocci-scripts.shscripts/check-cocci-scripts.sh new file +26
-0@@ -0,0 +1,47 @@ +#! /usr/bin/env bash + +test -d scripts/coccinelle || exit 1 + +SPATCH_IMAGE="philmd/coccinelle:1.0.4" + +GIT_AUTHOR_NAME="Coccinelle Spatch" +GIT_COMMITTER_NAME="Coccinelle Spatch" + +if [ -n "$TRAVIS" ]; then + # avoid stalling builds: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received + TIMEOUT_S=530 + TIMEOUT_CMD="timeout -k 550 500" + EXTRA_ARGS="--timeout ${TIMEOUT_S}" +else + TIMEOUT_S=0 +fi + +HEAD=19 #`echo -n scripts/coccinelle/ | wc -c` +TAIL=6 #`echo -n .cocci | wc -c` + +test -z "$(${SUDO} docker images -q ${SPATCH_IMAGE})" && ${SUDO} docker pull ${SPATCH_IMAGE} + +LOG=/tmp/cocci-spatch-$$ +for script in scripts/coccinelle/*.cocci; do + desc=${script:$HEAD:-$TAIL}
scripts/check-cocci-scripts.sh line 36
Quoted 10 lines
scripts/check-cocci-scripts.sh new file +10
-0+ echo -e "\nRunning ${script}...\n" + echo -e "coccinelle: committing changes after running \"$desc\" script\n" > ${LOG}.topic + ${TIMEOUT_CMD} ${SUDO} \ + docker run --rm -v `pwd`:`pwd` -w `pwd` -u `id -u` \ + ${SPATCH_IMAGE} --use-cache --use-gitgrep --keep-comments \ + --very-quiet ${EXTRA_ARGS} \ + --sp-file ${script} \ + --macro-file scripts/cocci-macro-file.h \ + --dir . \ + --in-place | tee ${LOG}.content
Is it possible to do an "incremental" run of coccinelle to only process affected files by a series (maybe on those files that are updated by an incremental make invocation)? That way we can save much time.
BTW I think you should use whitespaces instead of tabs for indentation.
Fam
RFC PATCH 4/4 travis: add job to run coccinelle scripts
In reply to Philippe Mathieu-Daudéresult pushed to my gh repo via ssh deploy key
--- .travis.sshkey | Bin 0 -> 1296 bytes .travis.yml | 26 ++++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 .travis.sshkey
.travis.sshkey new file binary +0 -0
.travis.yml +20 -6
@@ -51,6 +51,9 @@ env: git: # we want to do this ourselves submodules: false +branches: + except: + - /^autogenerated-.*/ before_install: - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update ; fi - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install libffi gettext glib pixman ; fi
@@ -62,14 +65,25 @@ script: - make -j3 && ${TEST_CMD} matrix: include: - # Plain Trusty Linux User Build - - env: CONFIG="--disable-system" + # Coccinelle using Trusty + - env: TEST_CMD="" + GIT_AUTHOR_EMAIL="coccinelle@travis-ci" + GIT_COMMITTER_EMAIL="[email protected]" sudo: required - addons: + services: + - docker dist: trusty + group: deprecated-2017Q2 compiler: gcc before_install: - - sudo apt-get update -qq - sudo apt-get build-dep -qq qemu - - wget -O - http://people.linaro.org/~alex.bennee/qemu-submodule-git-seed.tar.xz | tar -xvJ - - git submodule update --init --recursive + - git submodule update --init dtc + script: + - ORIGIN=$(git rev-parse HEAD) + - scripts/check-cocci-scripts.sh + after_success: + - if [ ${ORIGIN} = $(git rev-parse HEAD) ]; then exit; fi + - eval "$(ssh-agent -s)" + - openssl aes-256-cbc -K $encrypted_8b1bab3b4d04_key -iv $encrypted_8b1bab3b4d04_iv -in .travis.sshkey -d | ssh-add - + - BRANCH=autogenerated-coccinelle-`date +%Y%m%d`-${TRAVIS_BUILD_NUMBER} + - git checkout -b ${BRANCH} && git remote add deploy [email protected]:${TRAVIS_REPO_SLUG}.git && git push -f deploy ${BRANCH}
Signature · 1 line
2.13.1
Quoted 3 lines
Patch 4 is the travis job: it calls the previous script. To respect travis time limit timeout, each script is limited to <10min. If any commit were generated, they are pushed to my gh-repo
Initially I wanted to use git format-patch/send-email to send to the list as a series but it seems too verbose and Travis doesn't seem to allow to send mails. Another possibility is to send to a S3 bucket or gh-page. The push-to-repo way involves deploy ssh key but is easier to manage with regular git commands, I can fetch this repo and cherry-pick/rework/amend commits.
I also plan to add Marc-André Lureau clang-tidy work:
http://lists.nongnu.org/archive/html/qemu-devel/2017-06/msg05034.html
Quoted 15 lines · Philippe Mathieu-Daudé
Another item from my 'automated testing' list: use travis-ci to run coccinelle scripts. This series is more of a PoC. The idea would be to run it once a day only on /master.
Patch 1 is here only to speedup travis testing.
Patch 3 add a script which run each cocci script sequencially. If the script modified any file from the repo, changes are commited. If the script generated some output (i.e. using python), this output is logged in an empty commit. Spatch is run thru a debian-based Docker image.
Patch 4 is the travis job: it calls the previous script. To respect travis time limit timeout, each script is limited to <10min. If any commit were generated, they are pushed to my gh-repo:
Quoted 6 lines
Build output (Ran for 23 min 7 sec):
https://travis-ci.org/philmd/qemu/builds/246848085Any idea is welcome :)
Are we sure all the Coccinelle scripts always produce desirable and correct results? I often use Coccinelle to do the tedious 95% of the job, followed by a bit of manual cleanup. What if manual cleanup is required to make things compile cleanly? Say because the transformation leaves unused variables behind. What if the transformation is wanted in 19 out of 20 cases? Say because it replaces a bulky expression by the helper call created for this purpose (good), including in the helper function (bad)?