diff options
Diffstat (limited to 'scripts/test')
-rw-r--r-- | scripts/test/appveyor-irc-notify.py | 219 | ||||
-rwxr-xr-x | scripts/test/cov-diff | 14 | ||||
-rwxr-xr-x | scripts/test/cov-exclude | 6 | ||||
-rwxr-xr-x | scripts/test/coverage | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | scripts/test/scan-build.sh | 61 |
5 files changed, 285 insertions, 17 deletions
diff --git a/scripts/test/appveyor-irc-notify.py b/scripts/test/appveyor-irc-notify.py new file mode 100644 index 0000000000..cfe0afe7ae --- /dev/null +++ b/scripts/test/appveyor-irc-notify.py @@ -0,0 +1,219 @@ +# coding=utf8 +# Copyright (C) 2015-2016 Christopher R. Wood +# Copyright (c) 2018 The Tor Project +# Copyright (c) 2018 isis agora lovecruft +# +# From: https://raw.githubusercontent.com/gridsync/gridsync/def54f8166089b733d166665fdabcad4cdc526d8/misc/irc-notify.py +# and: https://github.com/gridsync/gridsync +# +# Modified by nexB on October 2016: +# - rework the handling of environment variables. +# - made the script use functions +# - support only Appveyor loading its environment variable to craft IRC notices. +# +# Modified by isis agora lovecruft <isis@torproject.org> in 2018: +# - Make IRC server configurable. +# - Make bot IRC nick deterministic. +# - Make bot join the channel rather than sending NOTICE messages externally. +# - Fix a bug which always caused sys.exit() to be logged as a traceback. +# - Actually reset the IRC colour codes after printing. +# +# Modified by Marcin Cieślak in 2018: +# - Accept UTF-8 +# - only guess github URLs +# - stop using ANSI colors +# +# Modified by teor in 2018: +# - fix github provider detection ('gitHub' or 'gitHubEnterprise', apparently) +# - make short commits 10 hexdigits long (that's what git does for tor) +# - generate correct branches and URLs for pull requests and tags +# - switch to one URL per line + +# This program is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software Foundation; +# either version 2 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with this +# program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, +# Fifth Floor, Boston, MA 02110-1301 USA. + +"""Simple AppVeyor IRC notification script. + +The first argument is an IRC server and port; the second is the channel. Other +arguments passed to the script will be sent as notice messages content and any +{var}-formatted environment variables will be expanded automatically, replaced +with a corresponding Appveyor environment variable value. Use commas to +delineate multiple messages. + + +Example: +export APPVEYOR_ACCOUNT_NAME=isislovecruft +export APPVEYOR_BUILD_VERSION=1 +export APPVEYOR_PROJECT_NAME=tor +export APPVEYOR_PULL_REQUEST_NUMBER=pull_request_number +export APPVEYOR_PULL_REQUEST_TITLE=pull_request_title +export APPVEYOR_REPO_BRANCH=repo_branch +export APPVEYOR_REPO_COMMIT=22c95b72e29248dc4de9b85e590ee18f6f587de8 +export APPVEYOR_REPO_COMMIT_AUTHOR=isislovecruft +export APPVEYOR_REPO_COMMIT_MESSAGE="some IRC test" +export APPVEYOR_REPO_COMMIT_TIMESTAMP=2018-04-23 +export APPVEYOR_REPO_NAME=isislovecruft/tor +export APPVEYOR_REPO_PROVIDER=github +export APPVEYOR_URL=https://ci.appveyor.com +python ./appveyor-irc-notify.py irc.oftc.net:6697 tor-ci '{repo_name} {repo_branch} {short_commit} - {repo_commit_author}: {repo_commit_message}','Build #{build_version} passed. Details: {build_url} | Commit: {commit_url} + +See also https://github.com/gridsync/gridsync/blob/master/appveyor.yml for examples +in Appveyor's YAML: + + on_success: + - "python scripts/test/appveyor-irc-notify.py irc.oftc.net:6697 tor-ci success + on_failure: + - "python scripts/test/appveyor-irc-notify.py irc.oftc.net:6697 tor-ci failure +""" + +from __future__ import print_function +from __future__ import absolute_import + +import os +import random +import socket +import ssl +import sys +import time + + +def appveyor_vars(): + """ + Return a dict of key value crafted from appveyor environment variables. + """ + + vars = dict([ + ( + v.replace('APPVEYOR_', '').lower(), + os.getenv(v, '').decode('utf-8') + ) for v in [ + 'APPVEYOR_ACCOUNT_NAME', + 'APPVEYOR_BUILD_VERSION', + 'APPVEYOR_PROJECT_NAME', + 'APPVEYOR_PULL_REQUEST_HEAD_COMMIT', + 'APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH', + 'APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME', + 'APPVEYOR_PULL_REQUEST_NUMBER', + 'APPVEYOR_PULL_REQUEST_TITLE', + 'APPVEYOR_REPO_BRANCH', + 'APPVEYOR_REPO_COMMIT', + 'APPVEYOR_REPO_COMMIT_AUTHOR', + 'APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL', + 'APPVEYOR_REPO_COMMIT_MESSAGE', + 'APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED', + 'APPVEYOR_REPO_COMMIT_TIMESTAMP', + 'APPVEYOR_REPO_NAME', + 'APPVEYOR_REPO_PROVIDER', + 'APPVEYOR_REPO_TAG_NAME', + 'APPVEYOR_URL', + ] + ]) + + BUILD_FMT = u'{url}/project/{account_name}/{project_name}/build/{build_version}' + + if vars["repo_tag_name"]: + BRANCH_FMT = u'{repo_name} {repo_tag_name} {short_commit}' + else: + BRANCH_FMT = u'{repo_name} {repo_branch} {short_commit}' + + vars.update(head_commit=vars["repo_commit"]) + + if vars["repo_provider"].lower().startswith('github'): + COMMIT_FMT = u'https://github.com/{repo_name}/commit/{repo_commit}' + if vars["pull_request_number"]: + vars.update(head_commit=vars["pull_request_head_commit"]) + BRANCH_FMT = u'{repo_name} {repo_branch} pull {pull_request_head_repo_name} {pull_request_head_repo_branch} {short_commit}' + COMMIT_FMT = u'https://github.com/{pull_request_head_repo_name}/commit/{pull_request_head_commit}' + PULL_FMT = u'https://github.com/{repo_name}/pull/{pull_request_number}' + vars.update(pull_url=PULL_FMT.format(**vars)) + vars.update(commit_url=COMMIT_FMT.format(**vars)) + + vars.update(short_commit=vars["head_commit"][:10]) + + vars.update( + build_url=BUILD_FMT.format(**vars), + branch_detail=BRANCH_FMT.format(**vars), + ) + return vars + + +def notify(): + """ + Send IRC notification + """ + apvy_vars = appveyor_vars() + + server, port = sys.argv[1].rsplit(":", 1) + channel = sys.argv[2] + success = sys.argv[3] == "success" + failure = sys.argv[3] == "failure" + + if success or failure: + messages = [] + messages.append(u"{branch_detail} - {repo_commit_author}: {repo_commit_message}") + + if success: + messages.append(u"Build #{build_version} passed. Details: {build_url}") + if failure: + messages.append(u"Build #{build_version} failed. Details: {build_url}") + + if "commit_url" in apvy_vars: + messages.append(u"Commit: {commit_url}") + + if "pull_url" in apvy_vars: + messages.append(u"Pull: {pull_url}") + + else: + messages = sys.argv[3:] + messages = ' '.join(messages) + messages = messages.decode("utf-8").split(',') + + print(repr(apvy_vars)) + messages = [msg.format(**apvy_vars).strip() for msg in messages] + + irc_username = 'appveyor-ci' + irc_nick = irc_username + + # establish connection + irc_sock = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) + irc_sock.connect((socket.gethostbyname(server), int(port))) + irc_sock.send('NICK {0}\r\nUSER {0} * 0 :{0}\r\n'.format(irc_username).encode()) + irc_sock.send('JOIN #{0}\r\n'.format(channel).encode()) + irc_file = irc_sock.makefile() + + while irc_file: + line = irc_file.readline() + print(line.rstrip()) + response = line.split() + + if response[0] == 'PING': + irc_file.send('PONG {}\r\n'.format(response[1]).encode()) + + elif response[1] == '433': + irc_sock.send('NICK {}\r\n'.format(irc_nick).encode()) + + elif response[1] == '001': + time.sleep(5) + # send notification + for msg in messages: + print(u'PRIVMSG #{} :{}'.format(channel, msg).encode("utf-8")) + irc_sock.send(u'PRIVMSG #{} :{}\r\n'.format(channel, msg).encode("utf-8")) + time.sleep(5) + return + + +if __name__ == '__main__': + try: + notify() + except: + import traceback + print('ERROR: Failed to send notification: \n' + traceback.format_exc()) diff --git a/scripts/test/cov-diff b/scripts/test/cov-diff index 7da7f0be9d..6179dff63e 100755 --- a/scripts/test/cov-diff +++ b/scripts/test/cov-diff @@ -7,11 +7,15 @@ DIRA="$1" DIRB="$2" -for A in $DIRA/*; do - B=$DIRB/`basename $A` - perl -pe 's/^\s*\!*\d+:/ 1:/; s/^([^:]+:)[\d\s]+:/$1/; s/^ *-:(Runs|Programs):.*//;' "$A" > "$A.tmp" - perl -pe 's/^\s*\!*\d+:/ 1:/; s/^([^:]+:)[\d\s]+:/$1/; s/^ *-:(Runs|Programs):.*//;' "$B" > "$B.tmp" - diff -u "$A.tmp" "$B.tmp" +for B in $DIRB/*; do + A=$DIRA/`basename $B` + if [ -f $A ]; then + perl -pe 's/^\s*\!*\d+(\*?):/ 1$1:/; s/^([^:]+:)[\d\s]+:/$1/; s/^ *-:(Runs|Programs):.*//;' "$A" > "$A.tmp" + else + cat /dev/null > "$A.tmp" + fi + perl -pe 's/^\s*\!*\d+(\*?):/ 1$1:/; s/^([^:]+:)[\d\s]+:/$1/; s/^ *-:(Runs|Programs):.*//;' "$B" > "$B.tmp" + diff -u "$A.tmp" "$B.tmp" |perl -pe 's/^((?:\+\+\+|---)(?:.*tmp))\s+.*/$1/;' rm "$A.tmp" "$B.tmp" done diff --git a/scripts/test/cov-exclude b/scripts/test/cov-exclude index 5117f11ec4..5cb9b1282d 100755 --- a/scripts/test/cov-exclude +++ b/scripts/test/cov-exclude @@ -26,3 +26,9 @@ if ($excluding or $exclude_this) { s{^\s*\#\#+:}{ x:}; s{^ (\s*)(\d+):}{$1!!!$2:}; } + +if (eof and $excluding) { + warn "Runaway LCOV_EXCL_START in $ARGV"; + $excluding = 0; +} + diff --git a/scripts/test/coverage b/scripts/test/coverage index f4ae475828..f10c5afaae 100755 --- a/scripts/test/coverage +++ b/scripts/test/coverage @@ -29,7 +29,7 @@ for fn in src/or/*.c src/common/*.c; do gcov -o $on $fn if [ -e $GC ] then - if [ -n $dst ] + if [ -d "$dst" ] then mv $GC $dst/$GC fi diff --git a/scripts/test/scan-build.sh b/scripts/test/scan-build.sh index 36e69e6d00..8d126cbcee 100644..100755 --- a/scripts/test/scan-build.sh +++ b/scripts/test/scan-build.sh @@ -5,37 +5,76 @@ # This script is used for running a bunch of clang scan-build checkers # on Tor. +# These don't seem to cause false positives in our code, so let's turn +# them on. CHECKERS="\ - -disable-checker deadcode.DeadStores \ - -enable-checker alpha.core.CastSize \ + -enable-checker alpha.core.CallAndMessageUnInitRefArg \ -enable-checker alpha.core.CastToStruct \ + -enable-checker alpha.core.Conversion \ + -enable-checker alpha.core.FixedAddr \ -enable-checker alpha.core.IdenticalExpr \ + -enable-checker alpha.core.PointerArithm \ -enable-checker alpha.core.SizeofPtr \ - -enable-checker alpha.security.ArrayBoundV2 \ + -enable-checker alpha.core.TestAfterDivZero \ -enable-checker alpha.security.MallocOverflow \ -enable-checker alpha.security.ReturnPtrRange \ - -enable-checker alpha.unix.SimpleStream + -enable-checker alpha.unix.BlockInCriticalSection \ + -enable-checker alpha.unix.Chroot \ + -enable-checker alpha.unix.PthreadLock \ + -enable-checker alpha.unix.PthreadLock \ + -enable-checker alpha.unix.SimpleStream \ + -enable-checker alpha.unix.Stream \ -enable-checker alpha.unix.cstring.BufferOverlap \ -enable-checker alpha.unix.cstring.NotNullTerminated \ - -enable-checker alpha.unix.cstring.OutOfBounds \ - -enable-checker alpha.core.FixedAddr \ + -enable-checker valist.CopyToSelf \ + -enable-checker valist.Uninitialized \ + -enable-checker valist.Unterminated \ + -enable-checker security.FloatLoopCounter \ -enable-checker security.insecureAPI.strcpy \ - -enable-checker alpha.unix.PthreadLock \ - -enable-checker alpha.core.PointerArithm \ - -enable-checker alpha.core.TestAfterDivZero \ " +# These have high false-positive rates. +EXTRA_CHECKERS="\ + -enable-checker alpha.security.ArrayBoundV2 \ + -enable-checker alpha.unix.cstring.OutOfBounds \ + -enable-checker alpha.core.CastSize \ +" + +# These don't seem to generate anything useful +NOISY_CHECKERS="\ + -enable-checker alpha.clone.CloneChecker \ + -enable-checker alpha.deadcode.UnreachableCode \ +" + +if test "x$SCAN_BUILD_OUTPUT" != "x"; then + OUTPUTARG="-o $SCAN_BUILD_OUTPUT" +else + OUTPUTARG="" +fi + scan-build \ $CHECKERS \ ./configure scan-build \ + make clean + +# Make this not get scanned for dead assignments, since it has lots of +# dead assignments we don't care about. +scan-build \ $CHECKERS \ - make -j2 -k + -disable-checker deadcode.DeadStores \ + make -j5 -k ./src/ext/ed25519/ref10/libed25519_ref10.a +scan-build \ + $CHECKERS $OUTPUTARG \ + make -j5 -k + +CHECKERS="\ +" # This one gives a false positive on every strcmp. # -enable-checker alpha.core.PointerSub # Needs work -# alpha.unix.MallocWithAnnotations ?? +# -enable-checker alpha.unix.MallocWithAnnotations |