LCOV - code coverage report
Current view: top level - oks/apps - oks_check_schema.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 44 0
Test Date: 2026-02-16 10:18:04 Functions: 0.0 % 6 0

            Line data    Source code
       1              : /**
       2              :  * @file oks_check_schema.cxx
       3              :  *
       4              :  * Program to do some simple integrity checks on a schema file
       5              :  *
       6              :  * This is part of the DUNE DAQ Application Framework, copyright 2025.
       7              :  * Licensing/copyright details are in the COPYING file that you should have
       8              :  * received with this code.
       9              :  */
      10              : 
      11              : #include "CLI/CLI.hpp"
      12              : #include "logging/Logging.hpp"
      13              : #include "oks/class.hpp"
      14              : #include "oks/file.hpp"
      15              : #include "oks/kernel.hpp"
      16              : #include "oks/relationship.hpp"
      17              : 
      18              : #include <fmt/core.h>
      19              : #include <string>
      20              : 
      21              : using namespace dunedaq::oks;
      22              : 
      23              : 
      24            0 : int main(int argc, char **argv) {
      25            0 :   enum Exitcode : int {SUCCESS, BADCMD, NOFILE, LOADFAIL, BADRELATIONSHIP};
      26              : 
      27            0 :   CLI::App app{"Check consistency of OKS schema file\n"+
      28            0 :     fmt::format("Return codes: {} Success, file is OK\n", Exitcode::SUCCESS)+
      29            0 :     fmt::format("              {} Bad command line\n", Exitcode::BADCMD)+
      30            0 :     fmt::format("              {} Failed to find file\n", Exitcode::NOFILE)+
      31            0 :     fmt::format("              {} Failed to load file -- invalid schema\n", Exitcode::LOADFAIL)+
      32            0 :     fmt::format("              {} File contains relationship to non loaded class\n", Exitcode::BADRELATIONSHIP)
      33            0 :   };
      34              : 
      35            0 :   std::string filename;
      36            0 :   app.add_option("-f,--file", filename, "Schema file")
      37            0 :     ->required();
      38              : 
      39            0 :   CLI11_PARSE(app, argc, argv);
      40              : 
      41            0 :   OksKernel kernel;
      42            0 :   try {
      43            0 :     const auto file = kernel.load_file(filename);
      44            0 :     if (file == nullptr) {
      45            0 :       TLOG() << "Failed to load " << filename;
      46            0 :       return Exitcode::LOADFAIL;
      47              :     }
      48              :   }
      49            0 :   catch (FailedLoadFile& fail) {
      50            0 :     TLOG() << fail.what() << "\n";
      51            0 :     return Exitcode::LOADFAIL;
      52            0 :   }
      53            0 :   catch (CanNotOpenFile& fail) {
      54            0 :     TLOG() << fail.what() << "\n";
      55            0 :     return Exitcode::NOFILE;
      56            0 :   }
      57            0 :   catch (std::exception& exc) {
      58            0 :     TLOG() << exc.what() << "\n";
      59            0 :     return Exitcode::LOADFAIL;
      60            0 :   }
      61              : 
      62            0 :   for (auto [name, oks_class] : kernel.classes()) {
      63            0 :     auto relationships = oks_class->direct_relationships();
      64            0 :     if (relationships != nullptr) {
      65            0 :       for (auto rel: *relationships) {
      66            0 :         auto rel_class = rel->get_class_type();
      67            0 :         if (rel_class == nullptr) {
      68            0 :           TLOG() << "Error class '" << name
      69            0 :                     << "' has relationship '" << rel->get_name()
      70            0 :                     << "' to a class '" << rel->get_type()
      71            0 :                     << "' that is not loaded\n";
      72            0 :           return Exitcode::BADRELATIONSHIP;
      73              :         }
      74              :       }
      75              :     }
      76              :     // Could check super-classes but we wouldn't have got past the
      77              :     // load if they referred to a missing class.
      78              :   }
      79              : 
      80            0 :   return 0;
      81            0 : }
        

Generated by: LCOV version 2.0-1