|
| 1 | +#define CATCH_CONFIG_MAIN |
| 2 | +#include "catch.hpp" |
| 3 | + |
| 4 | +#include "DataFormats/TestObjects/interface/ToyProducts.h" |
| 5 | +#include "FWCore/ParameterSet/interface/ParameterSet.h" |
| 6 | +#include "FWCore/ParameterSetReader/interface/ParameterSetReader.h" |
| 7 | +#include "FWCore/TestProcessor/interface/TestProcessor.h" |
| 8 | + |
| 9 | +#include <fmt/format.h> |
| 10 | + |
| 11 | +#include <iostream> |
| 12 | +#include <string_view> |
| 13 | + |
| 14 | +static constexpr auto s_tag = "[ProcessAccelerator]"; |
| 15 | + |
| 16 | +namespace { |
| 17 | + std::string makeConfig(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 | +} // namespace |
| 62 | + |
| 63 | +TEST_CASE("Configuration", s_tag) { |
| 64 | + const std::string test1{"cms.EDProducer('IntProducer', ivalue = cms.int32(1))"}; |
| 65 | + const std::string test2{"cms.EDProducer('ManyIntProducer', ivalue = cms.int32(2), values = cms.VPSet())"}; |
| 66 | + |
| 67 | + const std::string baseConfig_auto = makeConfig(true, test1, test2, "*"); |
| 68 | + const std::string baseConfig_test1 = makeConfig(true, test1, test2, "test1"); |
| 69 | + const std::string baseConfig_test2 = makeConfig(true, test1, test2, "test2"); |
| 70 | + const std::string baseConfigTest2Disabled_auto = makeConfig(false, test1, test2, "*"); |
| 71 | + const std::string baseConfigTest2Disabled_test1 = makeConfig(false, test1, test2, "test1"); |
| 72 | + const std::string baseConfigTest2Disabled_test2 = makeConfig(false, test1, test2, "test2"); |
| 73 | + |
| 74 | + SECTION("Configuration hash is not changed") { |
| 75 | + auto pset_auto = edm::readConfig(baseConfig_auto); |
| 76 | + auto pset_test1 = edm::readConfig(baseConfig_test1); |
| 77 | + auto pset_test2 = edm::readConfig(baseConfig_test2); |
| 78 | + auto psetTest2Disabled_auto = edm::readConfig(baseConfigTest2Disabled_auto); |
| 79 | + auto psetTest2Disabled_test1 = edm::readConfig(baseConfigTest2Disabled_test1); |
| 80 | + auto psetTest2Disabled_test2 = edm::readConfig(baseConfigTest2Disabled_test2); |
| 81 | + pset_auto->registerIt(); |
| 82 | + pset_test1->registerIt(); |
| 83 | + pset_test2->registerIt(); |
| 84 | + psetTest2Disabled_auto->registerIt(); |
| 85 | + psetTest2Disabled_test1->registerIt(); |
| 86 | + psetTest2Disabled_test2->registerIt(); |
| 87 | + REQUIRE(pset_auto->id() == pset_test1->id()); |
| 88 | + REQUIRE(pset_auto->id() == pset_test2->id()); |
| 89 | + REQUIRE(pset_auto->id() == psetTest2Disabled_auto->id()); |
| 90 | + REQUIRE(pset_auto->id() == psetTest2Disabled_test1->id()); |
| 91 | + REQUIRE(pset_auto->id() == psetTest2Disabled_test2->id()); |
| 92 | + } |
| 93 | + |
| 94 | + edm::test::TestProcessor::Config config_auto{baseConfig_auto}; |
| 95 | + edm::test::TestProcessor::Config config_test1{baseConfig_test1}; |
| 96 | + edm::test::TestProcessor::Config config_test2{baseConfig_test2}; |
| 97 | + edm::test::TestProcessor::Config configTest2Disabled_auto{baseConfigTest2Disabled_auto}; |
| 98 | + edm::test::TestProcessor::Config configTest2Disabled_test1{baseConfigTest2Disabled_test1}; |
| 99 | + edm::test::TestProcessor::Config configTest2Disabled_test2{baseConfigTest2Disabled_test2}; |
| 100 | + |
| 101 | + SECTION("Base configuration is OK") { REQUIRE_NOTHROW(edm::test::TestProcessor(config_auto)); } |
| 102 | + |
| 103 | + SECTION("No event data") { |
| 104 | + edm::test::TestProcessor tester(config_auto); |
| 105 | + REQUIRE_NOTHROW(tester.test()); |
| 106 | + } |
| 107 | + |
| 108 | + SECTION("beginJob and endJob only") { |
| 109 | + edm::test::TestProcessor tester(config_auto); |
| 110 | + REQUIRE_NOTHROW(tester.testBeginAndEndJobOnly()); |
| 111 | + } |
| 112 | + |
| 113 | + SECTION("Run with no LuminosityBlocks") { |
| 114 | + edm::test::TestProcessor tester(config_auto); |
| 115 | + REQUIRE_NOTHROW(tester.testRunWithNoLuminosityBlocks()); |
| 116 | + } |
| 117 | + |
| 118 | + SECTION("LuminosityBlock with no Events") { |
| 119 | + edm::test::TestProcessor tester(config_auto); |
| 120 | + REQUIRE_NOTHROW(tester.testLuminosityBlockWithNoEvents()); |
| 121 | + } |
| 122 | + |
| 123 | + SECTION("Test2 enabled, acclerators=*") { |
| 124 | + edm::test::TestProcessor tester(config_auto); |
| 125 | + auto event = tester.test(); |
| 126 | + REQUIRE(event.get<edmtest::IntProduct>()->value == 2); |
| 127 | + } |
| 128 | + |
| 129 | + SECTION("Test2 enabled, acclerators=test1") { |
| 130 | + edm::test::TestProcessor tester(config_test1); |
| 131 | + auto event = tester.test(); |
| 132 | + REQUIRE(event.get<edmtest::IntProduct>()->value == 1); |
| 133 | + } |
| 134 | + |
| 135 | + SECTION("Test2 enabled, acclerators=test2") { |
| 136 | + edm::test::TestProcessor tester(config_test2); |
| 137 | + auto event = tester.test(); |
| 138 | + REQUIRE(event.get<edmtest::IntProduct>()->value == 2); |
| 139 | + } |
| 140 | + |
| 141 | + SECTION("Test2 disabled, accelerators=*") { |
| 142 | + edm::test::TestProcessor tester(configTest2Disabled_auto); |
| 143 | + auto event = tester.test(); |
| 144 | + REQUIRE(event.get<edmtest::IntProduct>()->value == 1); |
| 145 | + } |
| 146 | + |
| 147 | + SECTION("Test2 disabled, accelerators=test1") { |
| 148 | + edm::test::TestProcessor tester(configTest2Disabled_test1); |
| 149 | + auto event = tester.test(); |
| 150 | + REQUIRE(event.get<edmtest::IntProduct>()->value == 1); |
| 151 | + } |
| 152 | + |
| 153 | + SECTION("Test2 disabled, accelerators=test2") { |
| 154 | + REQUIRE_THROWS_WITH( |
| 155 | + edm::test::TestProcessor(configTest2Disabled_test2), |
| 156 | + Catch::Contains("The system has no compute accelerators that match the patterns") && Catch::Contains("test1")); |
| 157 | + } |
| 158 | +} |
0 commit comments