forked from AliceO2Group/QualityControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestCheck.cxx
176 lines (141 loc) · 5.87 KB
/
testCheck.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file testCheck.cxx
/// \author Rafal Pacholek
///
#include "QualityControl/CheckInterface.h"
#include "QualityControl/CheckRunnerFactory.h"
#include "QualityControl/CommonSpec.h"
#include "QualityControl/MonitorObject.h"
#include "QualityControl/InfrastructureSpecReader.h"
#include "getTestDataDirectory.h"
#include <DataSampling/DataSampling.h>
#include <Common/Exceptions.h>
#include <TH1F.h>
#include <Configuration/ConfigurationFactory.h>
#include <Configuration/ConfigurationInterface.h>
#define BOOST_TEST_MODULE Check test
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
using namespace o2::quality_control::checker;
using namespace o2::quality_control::core;
using namespace std;
using namespace o2::framework;
using namespace o2::utilities;
using namespace o2::header;
using namespace o2::configuration;
using namespace AliceO2::Common;
CheckConfig getCheckConfig(const std::string& configFilePath, const std::string& checkName)
{
auto config = ConfigurationFactory::getConfiguration(configFilePath);
auto infrastructureSpec = InfrastructureSpecReader::readInfrastructureSpec(config->getRecursive(), WorkflowType::Standalone);
auto checkSpec = std::find_if(infrastructureSpec.checks.begin(), infrastructureSpec.checks.end(),
[&checkName](const auto& checkSpec) {
return checkSpec.checkName == checkName;
});
if (checkSpec != infrastructureSpec.checks.end()) {
return Check::extractConfig(infrastructureSpec.common, *checkSpec);
} else {
throw std::runtime_error("check " + checkName + " not found in the config file");
}
}
BOOST_AUTO_TEST_CASE(test_check_specs)
{
std::string configFilePath = std::string("json://") + getTestDataDirectory() + "testSharedConfig.json";
Check check(getCheckConfig(configFilePath, "singleCheck"));
BOOST_REQUIRE_EQUAL(check.getInputs().size(), 1);
BOOST_CHECK_EQUAL(check.getInputs()[0], (InputSpec{ { "mo" }, "QTST", "skeletonTask", 0, Lifetime::Sporadic }));
BOOST_CHECK_EQUAL(check.getOutputSpec(), (OutputSpec{ "CDET", "singleCheck", 0, Lifetime::Sporadic }));
}
BOOST_AUTO_TEST_CASE(test_check_long_description)
{
std::string configFilePath = std::string("json://") + getTestDataDirectory() + "testSharedConfig.json";
Check check(getCheckConfig(configFilePath, "singleCheckLongDescription"));
BOOST_REQUIRE_EQUAL(check.getInputs().size(), 1);
BOOST_CHECK_EQUAL(check.getInputs()[0], (InputSpec{ { "mo" }, "QTST", "skeletonTask", 0, Lifetime::Sporadic }));
BOOST_CHECK_EQUAL(check.getOutputSpec(), (OutputSpec{ "CDET", "singleCheckL9fdb", 0, Lifetime::Sporadic }));
}
std::shared_ptr<MonitorObject> dummyMO(const std::string& objName)
{
auto obj = std::make_shared<MonitorObject>(new TH1F(objName.c_str(), objName.c_str(), 100, 0, 10), "test", "test", "TST");
obj->setIsOwner(true);
return obj;
}
BOOST_AUTO_TEST_CASE(test_check_empty_mo)
{
std::string configFilePath = std::string("json://") + getTestDataDirectory() + "testSharedConfig.json";
Check check(getCheckConfig(configFilePath, "singleCheck"));
check.init();
check.startOfActivity(Activity());
{
std::map<std::string, std::shared_ptr<MonitorObject>> moMap{
{ "skeletonTask/example", nullptr }
};
auto qos = check.check(moMap);
BOOST_CHECK_EQUAL(qos.size(), 0);
}
{
std::map<std::string, std::shared_ptr<MonitorObject>> moMap{
{ "skeletonTask/example", std::make_shared<MonitorObject>() }
};
auto qos = check.check(moMap);
BOOST_CHECK_EQUAL(qos.size(), 0);
}
}
BOOST_AUTO_TEST_CASE(test_check_invoke_check)
{
std::string configFilePath = std::string("json://") + getTestDataDirectory() + "testSharedConfig.json";
Check check(getCheckConfig(configFilePath, "singleCheck"));
check.init();
check.startOfActivity(Activity());
std::map<std::string, std::shared_ptr<MonitorObject>> moMap{
{ "skeletonTask/example", dummyMO("example") }
};
auto qos = check.check(moMap);
BOOST_CHECK_EQUAL(qos.size(), 1);
}
BOOST_AUTO_TEST_CASE(test_check_postprocessing)
{
std::string configFilePath = std::string("json://") + getTestDataDirectory() + "testSharedConfig.json";
Check check(getCheckConfig(configFilePath, "checkAnyPP"));
check.init();
check.startOfActivity(Activity());
std::map<std::string, std::shared_ptr<MonitorObject>> moMap{
{ "SkeletonPostProcessing/example", dummyMO("example") }
};
auto qos = check.check(moMap);
BOOST_CHECK_EQUAL(qos.size(), 1);
}
BOOST_AUTO_TEST_CASE(test_check_activity)
{
Check check({ "test",
"QcSkeleton",
"o2::quality_control_modules::skeleton::SkeletonCheck",
"TST",
{},
UpdatePolicyType::OnAny,
{},
true });
std::map<std::string, std::shared_ptr<MonitorObject>> moMap{
{ "abcTask/test1", dummyMO("test1") },
{ "abcTask/test2", dummyMO("test2") }
};
moMap["abcTask/test1"]->setActivity({ 300000, 1, "LHC22a", "spass", "qc", { 1, 10 }, "pp" });
moMap["abcTask/test2"]->setActivity({ 300000, 1, "LHC22a", "spass", "qc", { 5, 15 }, "pp" });
check.init();
check.startOfActivity(Activity());
auto qos = check.check(moMap);
BOOST_REQUIRE_EQUAL(qos.size(), 1);
ValidityInterval correctValidity{ 1, 15 };
BOOST_CHECK(qos[0]->getActivity().mValidity == correctValidity);
}