From 1c68aa93554d049d94e952c61b0f40bc10be1454 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Riette?= <sebastien.riette@meteo.fr>
Date: Tue, 19 Dec 2023 11:16:58 +0100
Subject: [PATCH] S. Riette 19 Dec 2023: add the documentation generation in
 the testing procedure

---
 docs/doxygen/doxygen_config      |  2 +-
 tools/generate_standalone_doc.sh |  3 ++
 tools/plot_perf.py               | 17 ++++++++--
 tools/testing.sh                 | 54 +++++++++++++++++++++++++++++---
 4 files changed, 68 insertions(+), 8 deletions(-)

diff --git a/docs/doxygen/doxygen_config b/docs/doxygen/doxygen_config
index 76352a566..6d264d4c3 100644
--- a/docs/doxygen/doxygen_config
+++ b/docs/doxygen/doxygen_config
@@ -867,7 +867,7 @@ WARN_LOGFILE           =
 INPUT                  = ../../src/
 INPUT                 += mainpage.md
 INPUT                 += ..
-INPUT                 += ../../tools/INSTALL.md ../../tools/INSTALL_mnh_expand.md ../../tools/INSTALL_pack_ial.md ../../tools/INSTALL_pack_mesonh.md ../../tools/INSTALL_testprogs.md
+INPUT                 += ../../tools/INSTALL.md ../../tools/INSTALL_pack_ial.md ../../tools/INSTALL_pack_mesonh.md ../../tools/INSTALL_testprogs.md
 INPUT                 += ../../build/with_fcm/README.md
 
 # This tag can be used to specify the character encoding of the source files
diff --git a/tools/generate_standalone_doc.sh b/tools/generate_standalone_doc.sh
index 426d4a644..a7d29983e 100755
--- a/tools/generate_standalone_doc.sh
+++ b/tools/generate_standalone_doc.sh
@@ -1,5 +1,8 @@
 #!/bin/bash
 
+set -e
+set -o pipefail #abort if left command on a pipe fails
+
 function usage {
   echo "Usage: $0 [-h] output"
   echo "output         output file with .pdf or .html extension"
diff --git a/tools/plot_perf.py b/tools/plot_perf.py
index 5fafa07a7..f5d8cf8b8 100755
--- a/tools/plot_perf.py
+++ b/tools/plot_perf.py
@@ -7,6 +7,7 @@ This script plots the data contained in the performance files obtained with the
 import matplotlib.pyplot as plt
 import numpy
 import pandas
+import re
 
 class Perf():
     def __init__(self, perffile):
@@ -15,6 +16,7 @@ class Perf():
         """
         self._df = df = pandas.read_csv(perffile, sep=' ',
                                         names=['commit', 'model', 'case', 'time'])
+
     def plotPerf(self, outfile, model=None, title=None, num=None):
         """
         :param outfile: output file
@@ -34,6 +36,7 @@ class Perf():
                 commits.append(commit)
         if num is not None:
             commits = commits[-num:]
+        shortCommits = [self.shortenCommit(c) for c in commits]
     
         df = self._df.groupby('model')
         for igrpM, grpM in enumerate(models):
@@ -44,7 +47,7 @@ class Perf():
                     ax[igrpM].set_title('Mean elapsed computational time for ' + grpM)
             else:
                 ax[igrpM].set_title(title.replace('%M', grpM))
-            ax[igrpM].set_ylabel('time (ms/gp)')
+            ax[igrpM].set_ylabel('time')
             ax[igrpM].set_yscale('log')
     
             dfp = df.get_group(grpM).groupby('case')
@@ -57,14 +60,22 @@ class Perf():
                     l = [numpy.nan if t < 0. else t for t in dfp.get_group(grp)[f]['time']]
                     time.append(numpy.nan if len(l) == 0 else numpy.ma.array(l).mean())
                 ax[igrpM].plot(range(len(commits)), numpy.ma.array(time), 'o-', label=grp)
-            if igrpM == len(df.groups) - 1:
+            if igrpM == len(models) - 1:
                 ax[igrpM].set_xlabel('PHYEX version')
                 ax[igrpM].set_xticks(range(len(commits)))
-                ax[igrpM].set_xticklabels(commits, rotation=45, ha='right')
+                ax[igrpM].set_xticklabels(shortCommits, rotation=45, ha='right')
             ax[igrpM].legend()
         fig.tight_layout()
         fig.savefig(outfile)
 
+    @staticmethod
+    def shortenCommit(commit):
+        """
+        :param commit: full commit SHA
+        :return: shorten version of commit SHA
+        """
+        return commit[:7] if re.match(r'^[0-9a-f]{40}$', commit) else commit
+
     def listModels(self):
         """
         :result: list of models present in the file
diff --git a/tools/testing.sh b/tools/testing.sh
index 3c351a898..7b24d0e0d 100755
--- a/tools/testing.sh
+++ b/tools/testing.sh
@@ -7,7 +7,7 @@ set -o pipefail #abort if left command on a pipe fails
 function usage {
   echo "Usage: $0 [-h] [--repo-user USER] [--repo-protocol PROTOCOL] [--repo-repo REPO] [--no-update] [--no-compil]"
   echo "               [--no-exec] [--no-comp] [--no-remove] [--force] [--commit SHA] [--ref REF]"
-  echo "               [--only-model MODEL] [--no-enable-gh-pages] [--perf PERF] [MAIL]"
+  echo "               [--only-model MODEL] [--no-enable-gh-pages] [--perf PERF] [--no-doc-gen] [MAIL]"
   echo "--repo-user USER"
   echo "                user hosting the PHYEX repository on github,"
   echo "                defaults to the env variable PHYEXREPOuser (=$PHYEXREPOuser)"
@@ -29,6 +29,7 @@ function usage {
   echo "--no-enable-gh-pages"
   echo "                dont't try to enable the project pages on github"
   echo "--perf FILE     add performance statistics in file FILE"
+  echo "--no-doc-gen    do not test the documentation generation"
   echo "MAIL            comma-separated list of e-mail addresses (no spaces); if not provided, mail is not sent"
   echo ""
   echo "This script provides functionality for automated tests."
@@ -43,7 +44,9 @@ function usage {
   echo "(for arome and/or mesonh) or with data (testprogs)."
   echo ""
   echo "The script compare the results against reference simulations. These reference simulations must"
-  echo "be available in the different subdirectories in \${WORKDIR}."
+  echo "be available in the different subdirectories in \${PHYEXWORKDIR}."
+  echo ""
+  echo "The documentation generation is also tested."
 }
 
 MAIL=""
@@ -63,6 +66,7 @@ force=0
 models=""
 enableghpages=1
 perfopt=""
+docgen=1
 
 while [ -n "$1" ]; do
   case "$1" in
@@ -81,6 +85,7 @@ while [ -n "$1" ]; do
     '--only-model') models="${models} $2"; shift;;
     '--no-enable-gh-pages') enableghpages=0;;
     '--perf') perfopt="--perf $2"; shift;;
+    '--no-doc-gen') docgen=0;;
     #--) shift; break ;;
      *) if [ -z "${MAIL-}" ]; then
           MAIL="$1"
@@ -243,7 +248,7 @@ if [ "${SHA}" -eq 0 ]; then
   log 1 "Commit hash is ${SHA}"
 fi
 if [ ${force} -eq 1 -o $(get_statuses "${SHA}" | grep "${context}" | wc -l) -eq 0 ]; then
-  log 1 "This commit has not been tested (or --force id provided)"
+  log 1 "This commit has not been tested (or --force is provided)"
   ret=0
   
   #Checkout tools, set PATH and use the last version of the testing script
@@ -262,7 +267,6 @@ if [ ${force} -eq 1 -o $(get_statuses "${SHA}" | grep "${context}" | wc -l) -eq
     git fetch "${PHYEXREPOgiturl}"
     git checkout "${SHA}"
     cd "${currentdir}"
-    . "${WORKDIR}/PHYEX/tools/env.sh"
     if [ -f "${WORKDIR}/PHYEX/tools/testing.sh" ]; then
       if [ "${currentMD5}" != $(md5sum "${WORKDIR}/PHYEX/tools/testing.sh" | cut -d\  -f1) ]; then
         log 1 "Script has changed, running the new version" #This log and the preivous ones are lost
@@ -270,6 +274,7 @@ if [ ${force} -eq 1 -o $(get_statuses "${SHA}" | grep "${context}" | wc -l) -eq
       fi
     fi
   fi
+  . "${WORKDIR}/PHYEX/tools/env.sh"
 
   #Enable the gihub project pages
   if [ $enableghpages -eq 1 ]; then
@@ -407,6 +412,47 @@ if [ ${force} -eq 1 -o $(get_statuses "${SHA}" | grep "${context}" | wc -l) -eq
     fi
   done
 
+  if [ $docgen -eq 1 ]; then
+    retdoc=0
+    log 0 "Test doc generation"
+
+    doccmd="generate_standalone_doc.sh ${WORKDIR}/documentation.html"
+    log 1 "Doc generation with ${doccmd}"
+    set +e
+    ${doccmd}
+    result=$?
+    set -e
+    if [ ${result} -ne 0 ]; then
+      retdoc=1
+      log 0 "  doc generarion with generate_standalone_doc.sh: error"
+    else
+      log 0 "  doc generarion with generate_standalone_doc.sh: OK"
+    fi
+
+    doccmd="doxygen doxygen_config"
+    log 1 "Doc generation with ${doccmd}"
+    cwd=$PWD
+    cd ${WORKDIR}/PHYEX/docs/doxygen
+    set +e
+    ${doccmd}
+    result=$?
+    set -e
+    cd $cwd
+    if [ ${result} -ne 0 ]; then
+      retdoc=1
+      log 0 "  doc generarion with doxygen: error"
+    else
+      log 0 "  doc generarion with doxygen: OK"
+    fi
+
+    if [ $retdoc -eq 0 ]; then
+      log 0 "..... global result for doc generation: OK"
+    else
+      ret=1
+      log 0 "XXXXX global result for doc generation: ERROR"
+    fi
+  fi
+
   #Report result
   report 0 ${ret}
 fi
-- 
GitLab