feat(coverity-scan):Notify if newly-added files not included for coverity scan
Added a test script to detect the newly added files between patches,
not analysed by the tf-coverity job. The script checks for only source
files("*.c") and logs the filenames not included for coverity analysis.
The test is included along with other existing static checks and
executed as part of 'tf-static-checks' under level 1 CI Job -
"tf-gerrit-tforg-l1".
Signed-off-by: Jayanth Dodderi Chidanand <jayanthdodderi.chidanand@arm.com>
Change-Id: I846d56010dae521f375515d993855a648635ef81
diff --git a/script/static-checks/static-checks-detect-newly-added-files.sh b/script/static-checks/static-checks-detect-newly-added-files.sh
new file mode 100755
index 0000000..c7907a6
--- /dev/null
+++ b/script/static-checks/static-checks-detect-newly-added-files.sh
@@ -0,0 +1,83 @@
+#!/usr/bin/env bash
+#
+# Copyright (c) 2021 Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# static-checks-detect-newly-added-files.sh
+# This script aims at identifying the newly added source files
+# between the commits.
+# It runs on every TF-A patch and detects the new files and updates
+# the patch contibutor to include them for Coverity Scan analysis.
+
+LOG_FILE=$(mktemp -t files-detection-check.XXXX)
+TFA_PATCH_NEWFILES_LIST=$(mktemp -t tfa-patch-newfiles-list.XXXX)
+EXIT_VALUE=0
+
+# Function : file_updation_report
+# Description : To update the inclusion of files listed in the temp file
+# (tfa-patch-newfiles-list.XXXX) for Coverity Scan Analysis.
+# Return : newly added source files,are captured onto the error log
+# and the Error status is printed.
+function file_updation_report( )
+{
+ echo "========================================================================"
+ echo "New source files have been identified in your patch.."
+ echo >> "$LOG_FILE"
+ echo "New source files have been identified in your patch.." >> "$LOG_FILE"
+# Iterating through the patch filenames and logging them onto error report.
+ while read filename
+ do
+ echo "$filename"
+ echo "$filename" >> "$LOG_FILE"
+ done < "$TFA_PATCH_NEWFILES_LIST"
+
+ echo
+ echo -e "1. Kindly ensure they are updated in the \"tf_cov_make\" build script as \n \
+well to consider them for Coverity Scan analysis."
+ echo >> "$LOG_FILE"
+ echo -e "1. Kindly ensure they are updated in the \"tf_cov_make\" build script as \n \
+well to consider them for Coverity Scan analysis." >> "$LOG_FILE"
+
+ echo
+ echo -e "2. Please ignore if files are already updated. Further the Code Maintainer \n \
+will resolve the issue by taking appropriate action."
+ echo >> "$LOG_FILE"
+ echo -e "2. Please ignore if files are already updated. Further the Code Maintainer \n \
+will resolve the issue by taking appropriate action." >> "$LOG_FILE"
+ echo "========================================================================"
+
+ EXIT_VALUE=1
+}
+
+# Detecting source files not analysed by tf-coverity-job in the latest patch
+ echo "# Check to detect whether newly added files are analysed by Coverity in the patch"
+ TEST_CASE="Newly added files detection check for Coverity Scan analysis on patch(es)"
+# Extracting newly added source files added between commits.
+ git diff origin/master...HEAD --name-only --diff-filter=A "*.c" &> "$TFA_PATCH_NEWFILES_LIST"
+ if [ -s "$TFA_PATCH_NEWFILES_LIST" ]
+ then
+ file_updation_report
+ fi
+
+echo >> "$LOG_TEST_FILENAME"
+echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME"
+echo >> "$LOG_TEST_FILENAME"
+
+if [[ "$EXIT_VALUE" == 0 ]]; then
+ echo "Result : SUCCESS" >> "$LOG_TEST_FILENAME"
+else
+ echo "Result : FAILURE" >> "$LOG_TEST_FILENAME"
+fi
+
+# Printing the script output to show the warnings.
+echo >> "$LOG_TEST_FILENAME"
+cat "$LOG_FILE" >> "$LOG_TEST_FILENAME"
+echo >> "$LOG_TEST_FILENAME"
+
+#Deleting temporary files
+rm -f "$LOG_FILE"
+rm -f "$TFA_PATCH_NEWFILES_LIST"
+
+exit "$EXIT_VALUE"
diff --git a/script/static-checks/static-checks.sh b/script/static-checks/static-checks.sh
index efeba3b..92689e0 100755
--- a/script/static-checks/static-checks.sh
+++ b/script/static-checks/static-checks.sh
@@ -109,6 +109,18 @@
fi
echo
+# Check to ensure newly added source files are detected for Coverity Scan analysis
+
+echo 'Checking whether the newly added source files are detected for Coverity Scan analysis...'
+echo
+"$CI_ROOT"/script/static-checks/static-checks-detect-newly-added-files.sh
+if [ "$?" != 0 ]; then
+ echo "Files Detection check: FAILURE"
+ ((ERROR_COUNT++))
+else
+ echo "Files Detection check: PASS"
+fi
+echo
# Check error count