From 38fe1ef1ea75753dd40618119f7cb2c0cf5e86f8 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Tue, 22 Oct 2024 23:22:37 +0200
Subject: [PATCH] Update build info showing slurm library info

---
 src/utils/BuildInfo.cpp  | 26 ++++++++++++++++++++++----
 src/utils/BuildInfo.hpp  |  1 +
 src/utils/PugsUtils.cpp  |  1 +
 tests/test_BuildInfo.cpp | 17 +++++++++++++++++
 tests/test_PugsUtils.cpp |  1 +
 5 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/src/utils/BuildInfo.cpp b/src/utils/BuildInfo.cpp
index c6ac6cde6..81d756775 100644
--- a/src/utils/BuildInfo.cpp
+++ b/src/utils/BuildInfo.cpp
@@ -21,6 +21,10 @@
 #include <highfive/highfive.hpp>
 #endif   // PUGS_HAS_HDF5
 
+#ifdef PUGS_HAS_SLURM
+#include <slurm/slurm.h>
+#endif   // PUGS_HAS_SLURM
+
 std::string
 BuildInfo::type()
 {
@@ -51,7 +55,7 @@ BuildInfo::mpiLibrary()
     MPI_Get_library_version(mpi_version, &length);
     return std::string(mpi_version);
   }();
-#else
+#else    // PUGS_HAS_MPI
   return "none";
 #endif   // PUGS_HAS_MPI
 }
@@ -62,7 +66,7 @@ BuildInfo::petscLibrary()
 #ifdef PUGS_HAS_PETSC
   return stringify(PETSC_VERSION_MAJOR) + "." + stringify(PETSC_VERSION_MINOR) + "." +
          stringify(PETSC_VERSION_SUBMINOR);
-#else
+#else    // PUGS_HAS_PETSC
   return "none";
 #endif   // PUGS_HAS_PETSC
 }
@@ -73,7 +77,7 @@ BuildInfo::slepcLibrary()
 #ifdef PUGS_HAS_SLEPC
   return stringify(SLEPC_VERSION_MAJOR) + "." + stringify(SLEPC_VERSION_MINOR) + "." +
          stringify(SLEPC_VERSION_SUBMINOR);
-#else
+#else    // PUGS_HAS_SLEPC
   return "none";
 #endif   // PUGS_HAS_SLEPC
 }
@@ -89,7 +93,21 @@ BuildInfo::hdf5Library()
   return stringify(H5_VERSION) + " [sequential]";
 #endif   // H5_HAVE_PARALLEL
 
-#else
+#else    // PUGS_HAS_HDF5
   return "none";
 #endif   // PUGS_HAS_HDF5
 }
+
+std::string
+BuildInfo::slurmLibrary()
+{
+#ifdef PUGS_HAS_SLURM
+
+  return stringify(SLURM_VERSION_MAJOR(SLURM_VERSION_NUMBER)) + "." +
+         stringify(SLURM_VERSION_MINOR(SLURM_VERSION_NUMBER)) + "." +
+         stringify(SLURM_VERSION_MICRO(SLURM_VERSION_NUMBER));
+
+#else    // PUGS_HAS_SLURM
+  return "none";
+#endif   // PUGS_HAS_SLURM
+}
diff --git a/src/utils/BuildInfo.hpp b/src/utils/BuildInfo.hpp
index 89a73e541..df4a32d93 100644
--- a/src/utils/BuildInfo.hpp
+++ b/src/utils/BuildInfo.hpp
@@ -12,6 +12,7 @@ struct BuildInfo
   static std::string petscLibrary();
   static std::string slepcLibrary();
   static std::string hdf5Library();
+  static std::string slurmLibrary();
 };
 
 #endif   // BUILD_INFO_HPP
diff --git a/src/utils/PugsUtils.cpp b/src/utils/PugsUtils.cpp
index b3d7d6c9a..e04e8eeee 100644
--- a/src/utils/PugsUtils.cpp
+++ b/src/utils/PugsUtils.cpp
@@ -65,6 +65,7 @@ pugsBuildInfo()
   os << "PETSc:    " << rang::style::bold << BuildInfo::petscLibrary() << rang::style::reset << '\n';
   os << "SLEPc:    " << rang::style::bold << BuildInfo::slepcLibrary() << rang::style::reset << '\n';
   os << "HDF5:     " << rang::style::bold << BuildInfo::hdf5Library() << rang::style::reset << '\n';
+  os << "SLURM:    " << rang::style::bold << BuildInfo::slurmLibrary() << rang::style::reset << '\n';
   os << "-------------------------------------------------------";
 
   return os.str();
diff --git a/tests/test_BuildInfo.cpp b/tests/test_BuildInfo.cpp
index 847db9f3c..9414902f4 100644
--- a/tests/test_BuildInfo.cpp
+++ b/tests/test_BuildInfo.cpp
@@ -16,6 +16,10 @@
 #include <petsc.h>
 #endif   // PUGS_HAS_PETSC
 
+#ifdef PUGS_HAS_SLURM
+#include <slurm/slurm.h>
+#endif   // PUGS_HAS_SLURM
+
 // clazy:excludeall=non-pod-global-static
 
 TEST_CASE("BuildInfo", "[utils]")
@@ -64,4 +68,17 @@ TEST_CASE("BuildInfo", "[utils]")
     REQUIRE(BuildInfo::petscLibrary() == "none");
 #endif   // PUGS_HAS_PETSC
   }
+
+  SECTION("slurm")
+  {
+#ifdef PUGS_HAS_SLURM
+    const std::string slurm_library = stringify(SLURM_VERSION_MAJOR(SLURM_VERSION_NUMBER)) + "." +
+                                      stringify(SLURM_VERSION_MINOR(SLURM_VERSION_NUMBER)) + "." +
+                                      stringify(SLURM_VERSION_MICRO(SLURM_VERSION_NUMBER));
+
+    REQUIRE(BuildInfo::slurmLibrary() == slurm_library);
+#else
+    REQUIRE(BuildInfo::slurmLibrary() == "none");
+#endif   // PUGS_HAS_SLURM
+  }
 }
diff --git a/tests/test_PugsUtils.cpp b/tests/test_PugsUtils.cpp
index 9dfd686da..fb8648652 100644
--- a/tests/test_PugsUtils.cpp
+++ b/tests/test_PugsUtils.cpp
@@ -52,6 +52,7 @@ TEST_CASE("PugsUtils", "[utils]")
       os << "PETSc:    " << rang::style::bold << BuildInfo::petscLibrary() << rang::style::reset << '\n';
       os << "SLEPc:    " << rang::style::bold << BuildInfo::slepcLibrary() << rang::style::reset << '\n';
       os << "HDF5:     " << rang::style::bold << BuildInfo::hdf5Library() << rang::style::reset << '\n';
+      os << "SLURM:    " << rang::style::bold << BuildInfo::slurmLibrary() << rang::style::reset << '\n';
       os << "-------------------------------------------------------";
 
       return os.str();
-- 
GitLab