Line data Source code
1 : #include "test/common.h"
2 :
3 : #include "artdaq-database/Overlay/JSONDocumentOverlay.h"
4 :
5 : namespace bpo = boost::program_options;
6 :
7 : namespace ovl = artdaq::database::overlay;
8 :
9 : using artdaq::database::json::JsonReader;
10 :
11 : using artdaq::database::json::object_t;
12 : using artdaq::database::json::value_t;
13 :
14 27 : int main(int argc, char* argv[]) try {
15 27 : debug::registerUngracefullExitHandlers();
16 :
17 27 : std::ostringstream descstr;
18 27 : descstr << argv[0] << " <-s <config-file>> <other-options>";
19 :
20 27 : bpo::options_description desc = descstr.str();
21 :
22 27 : desc.add_options()("source,s", bpo::value<std::string>(), "Source file.")("result,x", bpo::value<std::string>(), "Result file.")(
23 27 : "mask,m", bpo::value<uint32_t>(), "Compare mask file.")("fail,f", "Test should fail.")("help,h", "produce help message");
24 :
25 27 : bpo::variables_map vm;
26 :
27 : try {
28 27 : bpo::store(bpo::command_line_parser(argc, argv).options(desc).run(), vm);
29 27 : bpo::notify(vm);
30 0 : } catch (bpo::error const& e) {
31 0 : std::cerr << "Exception from command line processing in " << argv[0] << ": " << e.what() << "\n";
32 0 : return process_exit_code::INVALID_ARGUMENT;
33 0 : }
34 :
35 54 : if (vm.count("result") == 0u) {
36 : std::cerr << "Exception from command line processing in " << argv[0] << ": no result configuration file given.\n"
37 : << "For usage and an options list, please do '" << argv[0] << " --help"
38 0 : << "'.\n";
39 0 : return process_exit_code::INVALID_ARGUMENT | 1;
40 : }
41 :
42 54 : if (vm.count("source") == 0u) {
43 : std::cerr << "Exception from command line processing in " << argv[0] << ": no source configuration file given.\n"
44 : << "For usage and an options list, please do '" << argv[0] << " --help"
45 0 : << "'.\n";
46 0 : return process_exit_code::INVALID_ARGUMENT | 1;
47 : }
48 :
49 27 : auto mask = uint32_t{0};
50 :
51 27 : auto should_succeed = bool{true};
52 :
53 54 : if (vm.count("mask") != 0u) {
54 30 : mask = vm["mask"].as<uint32_t>();
55 : }
56 :
57 54 : if (vm.count("fail") != 0u) {
58 13 : should_succeed = false;
59 : }
60 :
61 27 : auto file_src = vm["source"].as<std::string>();
62 27 : std::ifstream is1(file_src);
63 27 : std::string conf1((std::istreambuf_iterator<char>(is1)), std::istreambuf_iterator<char>());
64 :
65 27 : auto file_res = vm["result"].as<std::string>();
66 27 : std::ifstream is2(file_res);
67 27 : std::string conf2((std::istreambuf_iterator<char>(is2)), std::istreambuf_iterator<char>());
68 :
69 27 : ovl::useCompareMask(mask);
70 :
71 27 : auto ast1 = object_t{};
72 27 : auto ast2 = object_t{};
73 :
74 27 : bool testResult1 = JsonReader().read(conf1, ast1);
75 27 : bool testResult2 = JsonReader().read(conf2, ast2);
76 :
77 27 : if (!testResult1 || !testResult2) {
78 0 : return process_exit_code::FAILURE;
79 : }
80 :
81 27 : value_t value1 = ast1;
82 27 : value_t value2 = ast2;
83 :
84 27 : ovl::ovlDatabaseRecord record1(value1);
85 : // std::cout << "record1 =<" << record1.to_string() << ">" ;
86 :
87 27 : ovl::ovlDatabaseRecord record2(value2);
88 : // std::cout << "record2 =<" << record2.to_string() << ">" ;
89 :
90 27 : auto result = record1 == record2;
91 :
92 27 : if (result.first && should_succeed) {
93 14 : return process_exit_code::SUCCESS;
94 13 : } else if (!result.first && !should_succeed) {
95 13 : std::cout << "Compare mask=" << mask << "\n";
96 13 : std::cout << "Result:" << result.second << "\n";
97 13 : return process_exit_code::SUCCESS;
98 : }
99 :
100 0 : std::cout << "Compare mask=" << std::bitset<32>(ovl::useCompareMask()) << "\n";
101 0 : std::cout << "Result:" << result.second << "\n";
102 :
103 0 : return process_exit_code::FAILURE;
104 27 : } catch (...) {
105 0 : std::cerr << "Process exited with error: " << ::debug::current_exception_diagnostic_information();
106 0 : return process_exit_code::UNCAUGHT_EXCEPTION;
107 0 : }
|