cppcheck/tools/donate-cpu.py

647 lines
24 KiB
Python
Raw Normal View History

# Donate CPU
#
# A script a user can run to donate CPU to cppcheck project
#
# Syntax: donate-cpu.py [-jN] [--package=url] [--stop-time=HH:MM] [--work-path=path] [--test] [--bandwidth-limit=limit]
# -jN Use N threads in compilation/analysis. Default is 1.
# --package=url Check a specific package and then stop. Can be useful if you want to reproduce
# some warning/crash/exception/etc..
# --stop-time=HH:MM Stop analysis when time has passed. Default is that you must terminate the script.
# --work-path=path Work folder path. Default path is cppcheck-donate-cpu-workfolder in your home folder.
# --test Connect to a donate-cpu-server that is running locally on port 8001 for testing.
# --bandwidth-limit=limit Limit download rate for packages. Format for limit is the same that wget uses.
# Examples: --bandwidth-limit=250k => max. 250 kilobytes per second
# --bandwidth-limit=2m => max. 2 megabytes per second
# --max-packages=N Process N packages and then exit. A value of 0 means infinitely.
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
# --no-upload Do not upload anything. Defaults to False.
#
# What this script does:
# 1. Check requirements
# 2. Pull & compile Cppcheck
# 3. Select a package
# 4. Download package
# 5. Analyze source code
# 6. Upload results
# 7. Repeat from step 2
#
# Quick start: just run this script without any arguments
import shutil
import os
import subprocess
import sys
import socket
import time
import re
import tarfile
import platform
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
# changes)
CLIENT_VERSION = "1.1.37"
2019-06-30 12:43:05 +02:00
def check_requirements():
result = True
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
for app in ['g++', 'git', 'make', 'wget', 'gdb']:
try:
subprocess.call([app, '--version'])
except OSError:
2018-12-20 14:26:00 +01:00
print(app + ' is required')
result = False
return result
def get_cppcheck(cppcheck_path, work_path):
print('Get Cppcheck..')
2018-08-26 16:23:42 +02:00
for i in range(5):
2019-06-30 12:43:05 +02:00
if os.path.exists(cppcheck_path):
try:
os.chdir(cppcheck_path)
subprocess.check_call(['git', 'checkout', '-f'])
subprocess.check_call(['git', 'pull'])
except:
print('Failed to update Cppcheck sources! Retrying..')
time.sleep(10)
continue
2018-08-26 16:23:42 +02:00
else:
try:
subprocess.check_call(['git', 'clone', 'https://github.com/danmar/cppcheck.git', cppcheck_path])
except:
2018-08-26 16:23:42 +02:00
print('Failed to clone, will try again in 10 minutes..')
time.sleep(600)
continue
time.sleep(2)
return True
if os.path.exists(cppcheck_path):
print('Failed to update Cppcheck sources, trying a fresh clone..')
try:
os.chdir(work_path)
shutil.rmtree(cppcheck_path)
get_cppcheck(cppcheck_path, work_path)
except:
print('Failed to remove Cppcheck folder, please manually remove ' + work_path)
return False
2018-08-26 16:23:42 +02:00
return False
def get_cppcheck_info(cppcheck_path):
try:
os.chdir(cppcheck_path)
return subprocess.check_output(['git', 'show', "--pretty=%h (%ci)", 'HEAD', '--no-patch', '--no-notes']).decode('utf-8').strip()
except:
return ''
2019-06-30 12:43:05 +02:00
def compile_version(work_path, jobs, version):
if os.path.isfile(work_path + '/' + version + '/cppcheck'):
2018-08-26 16:23:42 +02:00
return True
2019-06-30 12:43:05 +02:00
os.chdir(work_path + '/cppcheck')
subprocess.call(['git', 'checkout', version])
subprocess.call(['make', 'clean'])
subprocess.call(['make', jobs, 'MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g'])
2019-06-30 12:43:05 +02:00
if os.path.isfile(work_path + '/cppcheck/cppcheck'):
os.mkdir(work_path + '/' + version)
destPath = work_path + '/' + version + '/'
subprocess.call(['cp', '-R', work_path + '/cppcheck/cfg', destPath])
subprocess.call(['cp', 'cppcheck', destPath])
subprocess.call(['git', 'checkout', 'master'])
2018-08-26 16:23:42 +02:00
try:
2019-06-30 12:43:05 +02:00
subprocess.call([work_path + '/' + version + '/cppcheck', '--version'])
2018-08-26 16:23:42 +02:00
except OSError:
return False
return True
2019-06-30 12:43:05 +02:00
def compile(cppcheck_path, jobs):
print('Compiling Cppcheck..')
try:
2019-06-30 12:43:05 +02:00
os.chdir(cppcheck_path)
subprocess.call(['make', jobs, 'MATCHCOMPILER=yes', 'CXXFLAGS=-O2 -g'])
2019-06-30 12:43:05 +02:00
subprocess.call([cppcheck_path + '/cppcheck', '--version'])
except OSError:
return False
return True
2019-06-30 12:43:05 +02:00
def get_cppcheck_versions(server_address):
print('Connecting to server to get Cppcheck versions..')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(server_address)
sock.send(b'GetCppcheckVersions\n')
versions = sock.recv(256)
except socket.error as err:
print('Failed to get cppcheck versions: ' + str(err))
2018-12-08 11:39:44 +01:00
return None
sock.close()
return versions.decode('utf-8').split()
2019-06-30 12:43:05 +02:00
def get_package(server_address):
print('Connecting to server to get assigned work..')
package = None
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(server_address)
sock.send(b'get\n')
package = sock.recv(256)
except socket.error:
package = ''
sock.close()
return package.decode('utf-8')
2019-06-30 12:43:05 +02:00
def handle_remove_readonly(func, path, exc):
import stat
if not os.access(path, os.W_OK):
# Is the error an access error ?
os.chmod(path, stat.S_IWUSR)
func(path)
2019-06-30 12:43:05 +02:00
def remove_tree(folderName):
if not os.path.exists(folderName):
return
count = 5
while count > 0:
count -= 1
try:
2019-06-30 12:43:05 +02:00
shutil.rmtree(folderName, onerror=handle_remove_readonly)
break
except OSError as err:
time.sleep(30)
if count == 0:
print('Failed to cleanup {}: {}'.format(folderName, err))
sys.exit(1)
def wget(url, destfile, bandwidth_limit):
if os.path.exists(destfile):
if os.path.isfile(destfile):
os.remove(destfile)
else:
print('Error: ' + destfile + ' exists but it is not a file! Please check the path and delete it manually.')
sys.exit(1)
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
wget_call = ['wget', '--tries=10', '--timeout=300', '-O', destfile, url]
if bandwidth_limit and isinstance(bandwidth_limit, str):
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
wget_call.append('--limit-rate=' + bandwidth_limit)
exitcode = subprocess.call(wget_call)
if exitcode != 0:
print('wget failed with ' + str(exitcode))
os.remove(destfile)
return False
if not os.path.isfile(destfile):
return False
return True
2019-06-30 12:43:05 +02:00
def download_package(work_path, package, bandwidth_limit):
print('Download package ' + package)
2019-06-30 12:43:05 +02:00
destfile = work_path + '/temp.tgz'
if not wget(package, destfile, bandwidth_limit):
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
return None
return destfile
2019-06-30 12:43:05 +02:00
def unpack_package(work_path, tgz):
print('Unpacking..')
2019-06-30 12:43:05 +02:00
temp_path = work_path + '/temp'
remove_tree(temp_path)
os.mkdir(temp_path)
os.chdir(temp_path)
found = False
if tarfile.is_tarfile(tgz):
tf = tarfile.open(tgz)
for member in tf:
if member.name.startswith(('/', '..')):
# Skip dangerous file names
continue
elif member.name.lower().endswith(('.c', '.cpp', '.cxx', '.cc', '.c++', '.h', '.hpp',
'.h++', '.hxx', '.hh', '.tpp', '.txx', '.qml')):
try:
tf.extract(member.name)
found = True
except OSError:
pass
except AttributeError:
pass
tf.close()
2019-06-30 12:43:05 +02:00
os.chdir(work_path)
return found
2019-06-30 12:43:05 +02:00
def has_include(path, includes):
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
re_includes = [re.escape(inc) for inc in includes]
re_expr = '^[ \t]*#[ \t]*include[ \t]*(' + '|'.join(re_includes) + ')'
for root, _, files in os.walk(path):
for name in files:
filename = os.path.join(root, name)
try:
if sys.version_info.major < 3:
f = open(filename, 'rt')
else:
f = open(filename, 'rt', errors='ignore')
filedata = f.read()
try:
# Python2 needs to decode the data first
filedata = filedata.decode(encoding='utf-8', errors='ignore')
except AttributeError:
# Python3 directly reads the data into a string object that has no decode()
pass
f.close()
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
if re.search(re_expr, filedata, re.MULTILINE):
return True
except IOError:
pass
return False
2019-06-30 12:43:05 +02:00
def run_command(cmd):
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
print(cmd)
startTime = time.time()
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
comm = p.communicate()
2019-06-30 12:43:05 +02:00
stop_time = time.time()
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
stdout = comm[0].decode(encoding='utf-8', errors='ignore')
stderr = comm[1].decode(encoding='utf-8', errors='ignore')
2019-06-30 12:43:05 +02:00
elapsed_time = stop_time - startTime
return p.returncode, stdout, stderr, elapsed_time
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
def scan_package(work_path, cppcheck_path, jobs, libraries):
print('Analyze..')
2019-06-30 12:43:05 +02:00
os.chdir(work_path)
libs = ''
for library in libraries:
if os.path.exists(os.path.join(cppcheck_path, 'cfg', library + '.cfg')):
libs += ' --library=' + library
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
# Reference for GNU C: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
options = jobs + libs + ' -D__GNUC__ --check-library --inconclusive --enable=style,information --platform=unix64 --template=daca2 -rp=temp temp'
2019-06-30 12:43:05 +02:00
cppcheck_cmd = cppcheck_path + '/cppcheck' + ' ' + options
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
cmd = 'nice ' + cppcheck_cmd
2019-06-30 12:43:05 +02:00
returncode, stdout, stderr, elapsed_time = run_command(cmd)
sig_num = -1
sig_msg = 'Internal error: Child process crashed with signal '
sig_pos = stderr.find(sig_msg)
if sig_pos != -1:
sig_start_pos = sig_pos + len(sig_msg)
sig_num = int(stderr[sig_start_pos:stderr.find(' ', sig_start_pos)])
print('cppcheck finished with ' + str(returncode) + ('' if sig_num == -1 else ' (signal ' + str(sig_num) + ')'))
# generate stack trace for SIGSEGV, SIGABRT, SIGILL, SIGFPE, SIGBUS
if returncode in (-11,-6,-4,-8,-7) or sig_num in (11,6,4,8,7):
print('Crash!')
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
stacktrace = ''
2019-06-30 12:43:05 +02:00
if cppcheck_path == 'cppcheck':
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
# re-run within gdb to get a stacktrace
cmd = 'gdb --batch --eval-command=run --eval-command=bt --return-child-result --args ' + cppcheck_cmd + " -j1"
dummy, stdout, stderr, elapsed_time = run_command(cmd)
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
gdb_pos = stdout.find(" received signal")
if not gdb_pos == -1:
last_check_pos = stdout.rfind('Checking ', 0, gdb_pos)
if last_check_pos == -1:
stacktrace = stdout[gdb_pos:]
else:
stacktrace = stdout[last_check_pos:]
return returncode, stacktrace, '', returncode, options
if returncode != 0:
print('Error!')
if returncode > 0:
returncode = -100-returncode
return returncode, stdout, '', returncode, options
if stderr.find('Internal error: Child process crashed with signal ') > 0:
print('Error!')
s = 'Internal error: Child process crashed with signal '
pos1 = stderr.find(s)
pos2 = stderr.find(' [cppcheckError]', pos1)
signr = int(stderr[pos1+len(s):pos2])
return -signr, '', '', -signr, options
if stderr.find('#### ThreadExecutor') > 0:
print('Thread!')
return -222, '', '', -222, options
information_messages_list = []
issue_messages_list = []
count = 0
for line in stderr.split('\n'):
if ': information: ' in line:
information_messages_list.append(line + '\n')
elif line:
issue_messages_list.append(line + '\n')
if re.match(r'.*:[0-9]+:.*\]$', line):
count += 1
2018-08-26 16:23:42 +02:00
print('Number of issues: ' + str(count))
2019-06-30 12:43:05 +02:00
return count, ''.join(issue_messages_list), ''.join(information_messages_list), elapsed_time, options
2019-06-30 12:43:05 +02:00
def split_results(results):
ret = []
w = None
for line in results.split('\n'):
if line.endswith(']') and re.search(r': (error|warning|style|performance|portability|information|debug):', line):
if w is not None:
ret.append(w.strip())
w = ''
if w is not None:
w += ' ' * 5 + line + '\n'
if w is not None:
ret.append(w.strip())
return ret
2019-06-30 12:43:05 +02:00
def diff_results(work_path, ver1, results1, ver2, results2):
2018-08-26 13:42:01 +02:00
print('Diff results..')
ret = ''
2019-06-30 12:43:05 +02:00
r1 = sorted(split_results(results1))
r2 = sorted(split_results(results2))
2018-08-26 13:42:01 +02:00
i1 = 0
i2 = 0
while i1 < len(r1) and i2 < len(r2):
if r1[i1] == r2[i2]:
i1 += 1
i2 += 1
elif r1[i1] < r2[i2]:
ret += ver1 + ' ' + r1[i1] + '\n'
i1 += 1
else:
ret += ver2 + ' ' + r2[i2] + '\n'
i2 += 1
while i1 < len(r1):
ret += ver1 + ' ' + r1[i1] + '\n'
i1 += 1
while i2 < len(r2):
ret += ver2 + ' ' + r2[i2] + '\n'
i2 += 1
2018-08-26 13:42:01 +02:00
return ret
2019-06-30 12:43:05 +02:00
def send_all(connection, data):
bytes = data.encode('ascii', 'ignore')
while bytes:
num = connection.send(bytes)
if num < len(bytes):
bytes = bytes[num:]
2018-08-25 10:25:05 +02:00
else:
bytes = None
2018-08-25 10:25:05 +02:00
2019-06-30 12:43:05 +02:00
def upload_results(package, results, server_address):
print('Uploading results.. ' + str(len(results)) + ' bytes')
max_retries = 4
for retry in range(max_retries):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(server_address)
cmd = 'write\n'
2019-06-30 12:43:05 +02:00
send_all(sock, cmd + package + '\n' + results + '\nDONE')
sock.close()
print('Results have been successfully uploaded.')
return True
except socket.error as err:
print('Upload error: ' + str(err))
if retry < (max_retries - 1):
print('Retrying upload in 30 seconds')
time.sleep(30)
print('Upload permanently failed!')
return False
2019-06-30 12:43:05 +02:00
def upload_info(package, info_output, server_address):
print('Uploading information output.. ' + str(len(info_output)) + ' bytes')
max_retries = 3
for retry in range(max_retries):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(server_address)
2019-06-30 12:43:05 +02:00
send_all(sock, 'write_info\n' + package + '\n' + info_output + '\nDONE')
sock.close()
print('Information output has been successfully uploaded.')
return True
except socket.error as err:
print('Upload error: ' + str(err))
if retry < (max_retries - 1):
print('Retrying upload in 30 seconds')
time.sleep(30)
print('Upload permanently failed!')
return False
def get_libraries():
libraries = ['posix', 'gnu']
library_includes = {'boost': ['<boost/'],
# 'cairo': ['<cairo.h>'], <= enable after release of version 1.90
'cppunit': ['<cppunit/'],
'googletest': ['<gtest/gtest.h>'],
'gtk': ['<gtk/gtk.h>', '<glib.h>', '<glib/', '<gnome.h>'],
'libcerror': ['<libcerror.h>'],
'libcurl': ['<curl/curl.h>'],
'lua': ['<lua.h>', '"lua.h"'],
'microsoft_sal': ['<sal.h>'],
'motif': ['<X11/', '<Xm/'],
'nspr': ['<prtypes.h>', '"prtypes.h"'],
'opengl': ['<GL/gl.h>', '<GL/glu.h>', '<GL/glut.h>'],
'openmp': ['<omp.h>'],
'python': ['<Python.h>', '"Python.h"'],
'qt': ['<QApplication>', '<QList>', '<qlist.h>', '<QObject>', '<QString>', '<qstring.h>', '<QWidget>', '<QtWidgets>', '<QtGui'],
'ruby': ['<ruby.h>', '<ruby/', '"ruby.h"'],
'sdl': ['<SDL.h>', '<SDL/SDL.h>', '<SDL2/SDL.h>'],
'sqlite3': ['<sqlite3.h>', '"sqlite3.h"'],
'tinyxml2': ['<tinyxml2', '"tinyxml2'],
'wxwidgets': ['<wx/', '"wx/'],
'zlib': ['<zlib.h>'],
}
for library, includes in library_includes.items():
if has_include('temp', includes):
libraries.append(library)
return libraries
jobs = '-j1'
2019-06-30 12:43:05 +02:00
stop_time = None
work_path = os.path.expanduser('~/cppcheck-donate-cpu-workfolder')
package_url = None
2019-09-06 22:28:34 +02:00
server_address = ('cppcheck1.osuosl.org', 8000)
bandwidth_limit = None
max_packages = None
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
do_upload = True
for arg in sys.argv[1:]:
# --stop-time=12:00 => run until ~12:00 and then stop
if arg.startswith('--stop-time='):
2019-06-30 12:43:05 +02:00
stop_time = arg[-5:]
print('Stop time:' + stop_time)
elif arg.startswith('-j'):
jobs = arg
print('Jobs:' + jobs[2:])
2018-11-19 10:04:53 +01:00
elif arg.startswith('--package='):
2019-06-30 12:43:05 +02:00
package_url = arg[arg.find('=')+1:]
print('Package:' + package_url)
elif arg.startswith('--work-path='):
2019-06-30 12:43:05 +02:00
work_path = arg[arg.find('=')+1:]
print('work_path:' + work_path)
if not os.path.exists(work_path):
print('work path does not exist!')
sys.exit(1)
elif arg == '--test':
server_address = ('localhost', 8001)
elif arg.startswith('--bandwidth-limit='):
bandwidth_limit = arg[arg.find('=')+1:]
elif arg.startswith('--max-packages='):
arg_value = arg[arg.find('=')+1:]
try:
max_packages = int(arg_value)
except ValueError:
max_packages = None
if max_packages < 0:
max_packages = None
if max_packages is None:
print('Error: Max. packages value "{}" is invalid. Must be a positive number or 0.'.format(arg_value))
sys.exit(1)
# 0 means infinitely, no counting needed.
if max_packages == 0:
max_packages = None
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
elif arg.startswith('--no-upload'):
do_upload = False
elif arg == '--help':
print('Donate CPU to Cppcheck project')
print('')
print('Syntax: donate-cpu.py [-jN] [--stop-time=HH:MM] [--work-path=path]')
print(' -jN Use N threads in compilation/analysis. Default is 1.')
print(' --package=url Check a specific package and then stop. Can be useful if you want to reproduce')
print(' some warning/crash/exception/etc..')
print(' --stop-time=HH:MM Stop analysis when time has passed. Default is that you must terminate the script.')
2019-06-30 12:43:05 +02:00
print(' --work-path=path Work folder path. Default path is ' + work_path)
print(' --bandwidth-limit=limit Limit download rate for packages. Format for limit is the same that wget uses.')
print(' Examples: --bandwidth-limit=250k => max. 250 kilobytes per second')
print(' --bandwidth-limit=2m => max. 2 megabytes per second')
print(' --max-packages=N Process N packages and then exit. A value of 0 means infinitely.')
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
print(' --no-upload Do not upload anything. Defaults to False.')
print('')
print('Quick start: just run this script without any arguments')
sys.exit(0)
else:
print('Unhandled argument: ' + arg)
sys.exit(1)
print('Thank you!')
2019-06-30 12:43:05 +02:00
if not check_requirements():
sys.exit(1)
if bandwidth_limit and isinstance(bandwidth_limit, str):
2019-09-06 22:28:34 +02:00
if subprocess.call(['wget', '--limit-rate=' + bandwidth_limit, '-q', '--spider', 'cppcheck1.osuosl.org']) is 2:
print('Error: Bandwidth limit value "' + bandwidth_limit + '" is invalid.')
sys.exit(1)
else:
print('Bandwidth-limit: ' + bandwidth_limit)
2019-06-30 12:43:05 +02:00
if package_url:
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
max_packages = 1
if max_packages:
print('Maximum number of packages to download and analyze: {}'.format(max_packages))
2019-06-30 12:43:05 +02:00
if not os.path.exists(work_path):
os.mkdir(work_path)
cppcheck_path = os.path.join(work_path, 'cppcheck')
packages_processed = 0
while True:
if max_packages:
if packages_processed >= max_packages:
print('Processed the specified number of {} package(s). Exiting now.'.format(max_packages))
break
else:
print('Processing package {} of the specified {} package(s).'.format(packages_processed + 1, max_packages))
packages_processed += 1
2019-06-30 12:43:05 +02:00
if stop_time:
print('stop_time:' + stop_time + '. Time:' + time.strftime('%H:%M') + '.')
if stop_time < time.strftime('%H:%M'):
print('Stopping. Thank you!')
sys.exit(0)
if not get_cppcheck(cppcheck_path, work_path):
2018-08-26 16:23:42 +02:00
print('Failed to clone Cppcheck, retry later')
sys.exit(1)
2019-06-30 12:43:05 +02:00
cppcheck_versions = get_cppcheck_versions(server_address)
if cppcheck_versions is None:
2018-12-08 11:39:44 +01:00
print('Failed to communicate with server, retry later')
sys.exit(1)
2019-06-30 12:43:05 +02:00
if len(cppcheck_versions) == 0:
print('Did not get any cppcheck versions from server, retry later')
sys.exit(1)
2019-06-30 12:43:05 +02:00
for ver in cppcheck_versions:
if ver == 'head':
2019-06-30 12:43:05 +02:00
if not compile(cppcheck_path, jobs):
print('Failed to compile Cppcheck, retry later')
sys.exit(1)
2019-06-30 12:43:05 +02:00
elif not compile_version(work_path, jobs, ver):
print('Failed to compile Cppcheck-{}, retry later'.format(ver))
sys.exit(1)
2019-06-30 12:43:05 +02:00
if package_url:
package = package_url
2018-11-19 10:04:53 +01:00
else:
2019-06-30 12:43:05 +02:00
package = get_package(server_address)
2018-11-19 10:04:53 +01:00
while len(package) == 0:
print("network or server might be temporarily down.. will try again in 30 seconds..")
time.sleep(30)
2019-06-30 12:43:05 +02:00
package = get_package(server_address)
tgz = download_package(work_path, package, bandwidth_limit)
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
if tgz is None:
print("No package downloaded")
continue
2019-06-30 12:43:05 +02:00
if not unpack_package(work_path, tgz):
print("No files to process")
continue
crash = False
count = ''
2019-06-30 12:43:05 +02:00
elapsed_time = ''
results_to_diff = []
cppcheck_options = ''
head_info_msg = ''
cppcheck_head_info = '';
libraries = get_libraries();
2019-06-30 12:43:05 +02:00
for ver in cppcheck_versions:
if ver == 'head':
current_cppcheck_dir = 'cppcheck'
cppcheck_head_info = get_cppcheck_info(work_path + '/cppcheck')
else:
current_cppcheck_dir = ver
c, errout, info, t, cppcheck_options = scan_package(work_path, current_cppcheck_dir, jobs, libraries)
if c < 0:
if c == -101 and 'error: could not find or open any of the paths given.' in errout:
# No sourcefile found (for example only headers present)
count += ' 0'
else:
crash = True
count += ' Crash!'
else:
count += ' ' + str(c)
2019-06-30 12:43:05 +02:00
elapsed_time += " {:.1f}".format(t)
results_to_diff.append(errout)
if ver == 'head':
head_info_msg = info
output = 'cppcheck-options: ' + cppcheck_options + '\n'
output += 'platform: ' + platform.platform() + '\n'
output += 'python: ' + platform.python_version() + '\n'
output += 'client-version: ' + CLIENT_VERSION + '\n'
2019-06-30 12:43:05 +02:00
output += 'cppcheck: ' + ' '.join(cppcheck_versions) + '\n'
output += 'head-info: ' + cppcheck_head_info + '\n'
output += 'count:' + count + '\n'
2019-06-30 12:43:05 +02:00
output += 'elapsed-time:' + elapsed_time + '\n'
info_output = output
info_output += 'info messages:\n' + head_info_msg
2019-06-30 12:43:05 +02:00
if 'head' in cppcheck_versions:
output += 'head results:\n' + results_to_diff[cppcheck_versions.index('head')]
if not crash:
2019-06-30 12:43:05 +02:00
output += 'diff:\n' + diff_results(work_path, cppcheck_versions[0], results_to_diff[0], cppcheck_versions[1], results_to_diff[1]) + '\n'
if package_url:
2018-11-19 10:04:53 +01:00
print('=========================================================')
print(output)
print('=========================================================')
print(info_output)
print('=========================================================')
donate-cpu.py: add stack traces for daca@home crashes / bugfixes (#1764) * Get stack traces for daca@home crashes If a command in daca@home crashes, execute it again within gdb to get a stack trace. * donate-cpu.py: added "gdb" to checkRequirements() * donate-cpu.py: handle wget failures * donate-cpu.py: added --no-upload option to disable all uploads * donate-cpu.py: set max_packages to 1 if --package is provided to avoid endless processing of the same package * donate-cpu.py: no longer treat missing sources as a crash * donate-cpu.py: fixed wget "http://: Invalid host name." error caused by empty argument in subprocess.call() * donate-cpu.py: added --no-upload to --help * donate-cpu.py: detect crashes when using -j1 * donate-cpu.py: added -g to compiler flags * donate-cpu.py: fixed gdb call and stacktrace printing / always pass "-j1" to gdb call so the exception will actually occur in the application * donate-cpu.py: removed left-over --verbose from wget call * donate-cpu.py: removed unnecessary break * donate-cpu.py: only use gdb for crash in head run / actually provide the stack trace for the output * donate-cpu.py: include the last checked file with the stack trace * donate-cpu.py: removed unnecessary wget() call and a sleep in it / also inverted some logic * donate-cpu.py: small hasInclude() optimization * donate-cpu.py: bumped version number * donate-cpu.py: detect start of gdb output when Cygwin is used The Cygwin output looks like this: Thread 1 "cppcheck" received signal SIGSEGV, Segmentation fault. Co-Authored-By: firewave <firewave@users.noreply.github.com>
2019-03-28 15:49:20 +01:00
if do_upload:
2019-06-30 12:43:05 +02:00
upload_results(package, output, server_address)
upload_info(package, info_output, server_address)
if not max_packages or packages_processed < max_packages:
print('Sleep 5 seconds..')
time.sleep(5)