Commit dab954d7 authored by Raphael Defosseux's avatar Raphael Defosseux

feat(ci): cppcheck stage updates

  * using focal instead of xenial (new cppcheck version)
  * detecting the difference in stats with latest develop stats
Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent 52ead754
...@@ -35,6 +35,7 @@ import sys # arg ...@@ -35,6 +35,7 @@ import sys # arg
import re # reg import re # reg
import logging import logging
import os import os
from pathlib import Path
import time import time
#----------------------------------------------------------- #-----------------------------------------------------------
...@@ -51,7 +52,7 @@ class CppCheckResults(): ...@@ -51,7 +52,7 @@ class CppCheckResults():
def __init__(self): def __init__(self):
self.variants = ['xenial', 'bionic'] self.variants = ['bionic', 'focal']
self.versions = ['',''] self.versions = ['','']
self.nbErrors = [0,0] self.nbErrors = [0,0]
self.nbWarnings = [0,0] self.nbWarnings = [0,0]
...@@ -116,12 +117,22 @@ class StaticCodeAnalysis(): ...@@ -116,12 +117,22 @@ class StaticCodeAnalysis():
# if the commit ID is provided use it to point to it # if the commit ID is provided use it to point to it
if self.ranCommitID != '': if self.ranCommitID != '':
mySSH.command('git checkout -f ' + self.ranCommitID, '\$', 30) mySSH.command('git checkout -f ' + self.ranCommitID, '\$', 30)
# if the branch is not develop, then it is a merge request and we need to do
mySSH.command('docker image rm oai-cppcheck:bionic oai-cppcheck:xenial || true', '\$', 60) # the potential merge. Note that merge conflicts should already been checked earlier
mySSH.command('docker build --tag oai-cppcheck:xenial --file ci-scripts/docker/Dockerfile.cppcheck.xenial . > cmake_targets/log/cppcheck-xenial.txt 2>&1', '\$', 600) if (self.ranAllowMerge):
if self.ranTargetBranch == '':
if (self.ranBranch != 'develop') and (self.ranBranch != 'origin/develop'):
mySSH.command('git merge --ff origin/develop -m "Temporary merge for CI"', '\$', 5)
else:
logging.debug('Merging with the target branch: ' + self.ranTargetBranch)
mySSH.command('git merge --ff origin/' + self.ranTargetBranch + ' -m "Temporary merge for CI"', '\$', 5)
mySSH.command('docker image rm oai-cppcheck:bionic oai-cppcheck:focal || true', '\$', 60)
mySSH.command('sed -e "s@xenial@bionic@" ci-scripts/docker/Dockerfile.cppcheck.xenial > ci-scripts/docker/Dockerfile.cppcheck.bionic', '\$', 6) mySSH.command('sed -e "s@xenial@bionic@" ci-scripts/docker/Dockerfile.cppcheck.xenial > ci-scripts/docker/Dockerfile.cppcheck.bionic', '\$', 6)
mySSH.command('docker build --tag oai-cppcheck:bionic --file ci-scripts/docker/Dockerfile.cppcheck.bionic . > cmake_targets/log/cppcheck-bionic.txt 2>&1', '\$', 600) mySSH.command('docker build --tag oai-cppcheck:bionic --file ci-scripts/docker/Dockerfile.cppcheck.bionic . > cmake_targets/log/cppcheck-bionic.txt 2>&1', '\$', 600)
mySSH.command('docker image rm oai-cppcheck:bionic oai-cppcheck:xenial || true', '\$', 30) mySSH.command('sed -e "s@xenial@focal@" ci-scripts/docker/Dockerfile.cppcheck.xenial > ci-scripts/docker/Dockerfile.cppcheck.focal', '\$', 6)
mySSH.command('docker build --tag oai-cppcheck:focal --file ci-scripts/docker/Dockerfile.cppcheck.focal . > cmake_targets/log/cppcheck-focal.txt 2>&1', '\$', 600)
mySSH.command('docker image rm oai-cppcheck:bionic oai-cppcheck:focal || true', '\$', 30)
# Analyzing the logs # Analyzing the logs
mySSH.command('cd ' + lSourcePath + '/cmake_targets', '\$', 5) mySSH.command('cd ' + lSourcePath + '/cmake_targets', '\$', 5)
...@@ -131,8 +142,22 @@ class StaticCodeAnalysis(): ...@@ -131,8 +142,22 @@ class StaticCodeAnalysis():
mySSH.copyin(lIpAddr, lUserName, lPassWord, lSourcePath + '/cmake_targets/build_log_' + self.testCase_id + '/*', '.') mySSH.copyin(lIpAddr, lUserName, lPassWord, lSourcePath + '/cmake_targets/build_log_' + self.testCase_id + '/*', '.')
CCR = CppCheckResults() CCR = CppCheckResults()
CCR_ref = CppCheckResults()
vId = 0 vId = 0
for variant in CCR.variants: for variant in CCR.variants:
refAvailable = False
if self.ranAllowMerge:
refFolder = str(Path.home()) + '/cppcheck-references'
if (os.path.isfile(refFolder + '/cppcheck-'+ variant + '.txt')):
refAvailable = True
with open(refFolder + '/cppcheck-'+ variant + '.txt', 'r') as refFile:
for line in refFile:
ret = re.search(' (?P<nb_errors>[0-9\.]+) errors', str(line))
if ret is not None:
CCR_ref.nbErrors[vId] = int(ret.group('nb_errors'))
ret = re.search(' (?P<nb_warnings>[0-9\.]+) warnings', str(line))
if ret is not None:
CCR_ref.nbWarnings[vId] = int(ret.group('nb_warnings'))
if (os.path.isfile('./cppcheck-'+ variant + '.txt')): if (os.path.isfile('./cppcheck-'+ variant + '.txt')):
xmlStart = False xmlStart = False
with open('./cppcheck-'+ variant + '.txt', 'r') as logfile: with open('./cppcheck-'+ variant + '.txt', 'r') as logfile:
...@@ -167,21 +192,43 @@ class StaticCodeAnalysis(): ...@@ -167,21 +192,43 @@ class StaticCodeAnalysis():
CCR.nbPtrAddNotNull[vId] += 1 CCR.nbPtrAddNotNull[vId] += 1
if re.search('id="oppositeInnerCondition"', str(line)) is not None: if re.search('id="oppositeInnerCondition"', str(line)) is not None:
CCR.nbOppoInnerCondition[vId] += 1 CCR.nbOppoInnerCondition[vId] += 1
logging.debug('======== Variant ' + variant + ' - ' + CCR.versions[vId] + ' ========') vMsg = ''
logging.debug(' ' + str(CCR.nbErrors[vId]) + ' errors') vMsg += '======== Variant ' + variant + ' - ' + CCR.versions[vId] + ' ========\n'
logging.debug(' ' + str(CCR.nbWarnings[vId]) + ' warnings') vMsg += ' ' + str(CCR.nbErrors[vId]) + ' errors\n'
logging.debug(' -- Details --') vMsg += ' ' + str(CCR.nbWarnings[vId]) + ' warnings\n'
logging.debug(' Memory leak: ' + str(CCR.nbMemLeaks[vId])) vMsg += ' -- Details --\n'
logging.debug(' Possible null pointer deference: ' + str(CCR.nbNullPtrs[vId])) vMsg += ' Memory leak: ' + str(CCR.nbMemLeaks[vId]) + '\n'
logging.debug(' Uninitialized variable: ' + str(CCR.nbUninitVars[vId])) vMsg += ' Possible null pointer deference: ' + str(CCR.nbNullPtrs[vId]) + '\n'
logging.debug(' Undefined behaviour shifting: ' + str(CCR.nbTooManyBitsShift[vId])) vMsg += ' Uninitialized variable: ' + str(CCR.nbUninitVars[vId]) + '\n'
logging.debug(' Signed integer overflow: ' + str(CCR.nbIntegerOverflow[vId])) vMsg += ' Undefined behaviour shifting: ' + str(CCR.nbTooManyBitsShift[vId]) + '\n'
logging.debug('') vMsg += ' Signed integer overflow: ' + str(CCR.nbIntegerOverflow[vId]) + '\n'
logging.debug(' Printf formatting issue: ' + str(CCR.nbInvalidPrintf[vId])) vMsg += '\n'
logging.debug(' Modulo result is predetermined: ' + str(CCR.nbModuloAlways[vId])) vMsg += ' Printf formatting issue: ' + str(CCR.nbInvalidPrintf[vId]) + '\n'
logging.debug(' Opposite Condition -> dead code: ' + str(CCR.nbOppoInnerCondition[vId])) vMsg += ' Modulo result is predetermined: ' + str(CCR.nbModuloAlways[vId]) + '\n'
logging.debug(' Wrong Scanf Nb Args: ' + str(CCR.nbWrongScanfArg[vId])) vMsg += ' Opposite Condition -> dead code: ' + str(CCR.nbOppoInnerCondition[vId]) + '\n'
logging.debug('') vMsg += ' Wrong Scanf Nb Args: ' + str(CCR.nbWrongScanfArg[vId]) + '\n'
for vLine in vMsg.split('\n'):
logging.debug(vLine)
if self.ranAllowMerge and refAvailable:
if CCR_ref.nbErrors[vId] == CCR.nbErrors[vId]:
logging.debug(' No change in number of errors')
elif CCR_ref.nbErrors[vId] > CCR.nbErrors[vId]:
logging.debug(' Good! Decrease in number of errors')
else:
logging.debug(' Bad! increase in number of errors')
if CCR_ref.nbWarnings[vId] == CCR.nbWarnings[vId]:
logging.debug(' No change in number of warnings')
elif CCR_ref.nbWarnings[vId] > CCR.nbWarnings[vId]:
logging.debug(' Good! Decrease in number of warnings')
else:
logging.debug(' Bad! increase in number of warnings')
# Create new reference file
if not self.ranAllowMerge:
refFolder = str(Path.home()) + '/cppcheck-references'
if not os.path.isdir(refFolder):
os.mkdir(refFolder)
with open(refFolder + '/cppcheck-'+ variant + '.txt', 'w') as refFile:
refFile.write(vMsg)
vId += 1 vId += 1
HTML.CreateHtmlTestRow('N/A', 'OK', CONST.ALL_PROCESSES_OK) HTML.CreateHtmlTestRow('N/A', 'OK', CONST.ALL_PROCESSES_OK)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment