From 42f30c7e43912755afaa8d5c3a3c78e8ab1a5df4 Mon Sep 17 00:00:00 2001 From: AfonsoSantos96 Date: Wed, 22 Nov 2023 09:42:52 +0000 Subject: [PATCH] feat(HIS): add goto statement checker Signed-off-by: Afonso Santos --- docker/Dockerfile | 3 +++ his_checker.py | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 530ebf4..c859d8a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -10,6 +10,8 @@ ARG CLANG_VERSION=14 # use this repo temporarily while the patches for misra fps are not in a new official version ARG CPPCHECK_REPO=https://github.com/danmar/cppcheck.git ARG CPPCHECK_VERSION=2.9 +# repo for qmcalc tool +ARG QMCALC_REPO=https://github.com/dspinellis/cqmetrics.git # install dependencies RUN apt-get update && apt-get install -y \ @@ -40,6 +42,7 @@ RUN apt-get update && apt-get install -y \ pip3 install doorstop && \ pip3 install pyspellchecker && \ npm install -g cspell@latest && \ + mkdir /opt/qmcalc && git clone $QMCALC_REPO --depth 1 /opt/qmcalc && make -C /opt/qmcalc/src && \ mkdir /opt/cppcheck && git clone $CPPCHECK_REPO --depth 1 --branch $CPPCHECK_VERSION /opt/cppcheck && make -C /opt/cppcheck FILESDIR=/usr/share/cppcheck && make -C /opt/cppcheck install FILESDIR=/usr/share/cppcheck && \ mkdir /opt/aarch64-toolchain && curl $AARCH64_TOOLCHAIN_LINK | tar xJ -C /opt/aarch64-toolchain --strip-components=1 && \ mkdir /opt/riscv-toolchain && curl $RISCV_TOOLCHAIN_LINK | tar xz -C /opt/riscv-toolchain --strip-components=1 && \ diff --git a/his_checker.py b/his_checker.py index 2ec03e9..a1d17d5 100755 --- a/his_checker.py +++ b/his_checker.py @@ -9,9 +9,29 @@ import sys import argparse +import os + +GOTO_THRESHOLD = 0 + +def process_goto(files): + + """Process number of goto statements in a function""" + + metric_fail = 0 + qmcalc_goto_index = 18 + goto_tool = "qmcalc " + print("Checking the number of goto statements in each function") + for file in files.files: + sline = os.popen(goto_tool + str(file)).read().split('\n') + for fields in [line.split('\t') for line in sline[:-1]]: + if int(fields[qmcalc_goto_index]) > GOTO_THRESHOLD: + print("At " + file + " there is a goto statement. No goto statements are allowed") + metric_fail += 1 + print("Check done with " + str(metric_fail) + " error(s)\n") + return metric_fail if __name__ == "__main__": - METRICS_LIST = [] + METRICS_LIST = [process_goto] CHECK_FAIL = 0 PARSER = argparse.ArgumentParser() PARSER.add_argument("files", nargs="+", help="The files to process")