|
14 | 14 | static constexpr auto s_tag = "[ProcessAccelerator]"; |
15 | 15 |
|
16 | 16 | namespace { |
17 | | - std::string makeSwitchConfig(bool test2Enabled, |
18 | | - std::string_view test1, |
19 | | - std::string_view test2, |
20 | | - std::string_view accelerator) { |
21 | | - const std::string appendTest2 = test2Enabled ? "self._enabled.append('test2')" : ""; |
22 | | - return fmt::format( |
23 | | - R"_(from FWCore.TestProcessor.TestProcess import * |
24 | | -import FWCore.ParameterSet.Config as cms |
25 | | -
|
26 | | -class ProcessAcceleratorTest(cms.ProcessAccelerator): |
27 | | - def __init__(self): |
28 | | - super(ProcessAcceleratorTest,self).__init__() |
29 | | - self._labels = ["test1", "test2"] |
30 | | - self._enabled = ["test1"] |
31 | | - {} |
32 | | - def labels(self): |
33 | | - return self._labels |
34 | | - def enabledLabels(self): |
35 | | - return self._enabled |
36 | | -
|
37 | | -class SwitchProducerTest(cms.SwitchProducer): |
38 | | - def __init__(self, **kargs): |
39 | | - super(SwitchProducerTest,self).__init__( |
40 | | - dict( |
41 | | - cpu = cms.SwitchProducer.getCpu(), |
42 | | - test1 = lambda accelerators: ("test1" in accelerators, 2), |
43 | | - test2 = lambda accelerators: ("test2" in accelerators, 3), |
44 | | - ), **kargs) |
45 | | -
|
46 | | -process = TestProcess() |
47 | | -process.options.accelerators = ["{}"] |
48 | | -process.ProcessAcceleratorTest = ProcessAcceleratorTest() |
49 | | -process.s = SwitchProducerTest( |
50 | | - cpu = cms.EDProducer('IntProducer', ivalue = cms.int32(0)), |
51 | | - test1 = {}, |
52 | | - test2 = {} |
53 | | -) |
54 | | -process.moduleToTest(process.s) |
55 | | -)_", |
56 | | - appendTest2, |
57 | | - accelerator, |
58 | | - test1, |
59 | | - test2); |
60 | | - } |
61 | | - |
62 | 17 | std::string makeResolverConfig(bool enableOther, std::string_view accelerator, std::string_view variant) { |
63 | 18 | const std::string appendOther = enableOther ? "self._enabled.append('other')" : ""; |
64 | 19 | const std::string explicitVariant = |
@@ -116,105 +71,6 @@ process.moduleToTest(process.m) |
116 | 71 | } |
117 | 72 | } // namespace |
118 | 73 |
|
119 | | -TEST_CASE("Configuration with SwitchProducer", s_tag) { |
120 | | - const std::string test1{"cms.EDProducer('IntProducer', ivalue = cms.int32(1))"}; |
121 | | - const std::string test2{"cms.EDProducer('ManyIntProducer', ivalue = cms.int32(2), values = cms.VPSet())"}; |
122 | | - |
123 | | - const std::string baseConfig_auto = makeSwitchConfig(true, test1, test2, "*"); |
124 | | - const std::string baseConfig_test1 = makeSwitchConfig(true, test1, test2, "test1"); |
125 | | - const std::string baseConfig_test2 = makeSwitchConfig(true, test1, test2, "test2"); |
126 | | - const std::string baseConfigTest2Disabled_auto = makeSwitchConfig(false, test1, test2, "*"); |
127 | | - const std::string baseConfigTest2Disabled_test1 = makeSwitchConfig(false, test1, test2, "test1"); |
128 | | - const std::string baseConfigTest2Disabled_test2 = makeSwitchConfig(false, test1, test2, "test2"); |
129 | | - |
130 | | - SECTION("Configuration hash is not changed") { |
131 | | - std::unique_ptr<edm::ParameterSet> pset_auto, pset_test1, pset_test2; |
132 | | - std::unique_ptr<edm::ParameterSet> psetTest2Disabled_auto, psetTest2Disabled_test1, psetTest2Disabled_test2; |
133 | | - edm::makeParameterSets(baseConfig_auto, pset_auto); |
134 | | - edm::makeParameterSets(baseConfig_test1, pset_test1); |
135 | | - edm::makeParameterSets(baseConfig_test2, pset_test2); |
136 | | - edm::makeParameterSets(baseConfigTest2Disabled_auto, psetTest2Disabled_auto); |
137 | | - edm::makeParameterSets(baseConfigTest2Disabled_test1, psetTest2Disabled_test1); |
138 | | - edm::makeParameterSets(baseConfigTest2Disabled_test2, psetTest2Disabled_test2); |
139 | | - pset_auto->registerIt(); |
140 | | - pset_test1->registerIt(); |
141 | | - pset_test2->registerIt(); |
142 | | - psetTest2Disabled_auto->registerIt(); |
143 | | - psetTest2Disabled_test1->registerIt(); |
144 | | - psetTest2Disabled_test2->registerIt(); |
145 | | - REQUIRE(pset_auto->id() == pset_test1->id()); |
146 | | - REQUIRE(pset_auto->id() == pset_test2->id()); |
147 | | - REQUIRE(pset_auto->id() == psetTest2Disabled_auto->id()); |
148 | | - REQUIRE(pset_auto->id() == psetTest2Disabled_test1->id()); |
149 | | - REQUIRE(pset_auto->id() == psetTest2Disabled_test2->id()); |
150 | | - } |
151 | | - |
152 | | - edm::test::TestProcessor::Config config_auto{baseConfig_auto}; |
153 | | - edm::test::TestProcessor::Config config_test1{baseConfig_test1}; |
154 | | - edm::test::TestProcessor::Config config_test2{baseConfig_test2}; |
155 | | - edm::test::TestProcessor::Config configTest2Disabled_auto{baseConfigTest2Disabled_auto}; |
156 | | - edm::test::TestProcessor::Config configTest2Disabled_test1{baseConfigTest2Disabled_test1}; |
157 | | - edm::test::TestProcessor::Config configTest2Disabled_test2{baseConfigTest2Disabled_test2}; |
158 | | - |
159 | | - SECTION("Base configuration is OK") { REQUIRE_NOTHROW(edm::test::TestProcessor(config_auto)); } |
160 | | - |
161 | | - SECTION("No event data") { |
162 | | - edm::test::TestProcessor tester(config_auto); |
163 | | - REQUIRE_NOTHROW(tester.test()); |
164 | | - } |
165 | | - |
166 | | - SECTION("beginJob and endJob only") { |
167 | | - edm::test::TestProcessor tester(config_auto); |
168 | | - REQUIRE_NOTHROW(tester.testBeginAndEndJobOnly()); |
169 | | - } |
170 | | - |
171 | | - SECTION("Run with no LuminosityBlocks") { |
172 | | - edm::test::TestProcessor tester(config_auto); |
173 | | - REQUIRE_NOTHROW(tester.testRunWithNoLuminosityBlocks()); |
174 | | - } |
175 | | - |
176 | | - SECTION("LuminosityBlock with no Events") { |
177 | | - edm::test::TestProcessor tester(config_auto); |
178 | | - REQUIRE_NOTHROW(tester.testLuminosityBlockWithNoEvents()); |
179 | | - } |
180 | | - |
181 | | - SECTION("Test2 enabled, acclerators=*") { |
182 | | - edm::test::TestProcessor tester(config_auto); |
183 | | - auto event = tester.test(); |
184 | | - REQUIRE(event.get<edmtest::IntProduct>()->value == 2); |
185 | | - } |
186 | | - |
187 | | - SECTION("Test2 enabled, acclerators=test1") { |
188 | | - edm::test::TestProcessor tester(config_test1); |
189 | | - auto event = tester.test(); |
190 | | - REQUIRE(event.get<edmtest::IntProduct>()->value == 1); |
191 | | - } |
192 | | - |
193 | | - SECTION("Test2 enabled, acclerators=test2") { |
194 | | - edm::test::TestProcessor tester(config_test2); |
195 | | - auto event = tester.test(); |
196 | | - REQUIRE(event.get<edmtest::IntProduct>()->value == 2); |
197 | | - } |
198 | | - |
199 | | - SECTION("Test2 disabled, accelerators=*") { |
200 | | - edm::test::TestProcessor tester(configTest2Disabled_auto); |
201 | | - auto event = tester.test(); |
202 | | - REQUIRE(event.get<edmtest::IntProduct>()->value == 1); |
203 | | - } |
204 | | - |
205 | | - SECTION("Test2 disabled, accelerators=test1") { |
206 | | - edm::test::TestProcessor tester(configTest2Disabled_test1); |
207 | | - auto event = tester.test(); |
208 | | - REQUIRE(event.get<edmtest::IntProduct>()->value == 1); |
209 | | - } |
210 | | - |
211 | | - SECTION("Test2 disabled, accelerators=test2") { |
212 | | - REQUIRE_THROWS_WITH( |
213 | | - edm::test::TestProcessor(configTest2Disabled_test2), |
214 | | - Catch::Contains("The system has no compute accelerators that match the patterns") && Catch::Contains("test1")); |
215 | | - } |
216 | | -} |
217 | | - |
218 | 74 | TEST_CASE("Configuration with ModuleTypeResolver", s_tag) { |
219 | 75 | const std::string baseConfig_auto = makeResolverConfig(true, "*", ""); |
220 | 76 | const std::string baseConfig_cpu = makeResolverConfig(true, "cpu", ""); |
|
0 commit comments