Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-24 02:12:42

0001 #define CATCH_CONFIG_MAIN
0002 #include "catch.hpp"
0003 
0004 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ParameterSetReader/interface/ParameterSetReader.h"
0007 #include "FWCore/TestProcessor/interface/TestProcessor.h"
0008 
0009 #include <fmt/format.h>
0010 
0011 #include <iostream>
0012 #include <string_view>
0013 
0014 static constexpr auto s_tag = "[ProcessAccelerator]";
0015 
0016 namespace {
0017   std::string makeConfig(bool test2Enabled,
0018                          std::string_view test1,
0019                          std::string_view test2,
0020                          std::string_view accelerator) {
0021     const std::string appendTest2 = test2Enabled ? "self._enabled.append('test2')" : "";
0022     return fmt::format(
0023         R"_(from FWCore.TestProcessor.TestProcess import *
0024 import FWCore.ParameterSet.Config as cms
0025 
0026 class ProcessAcceleratorTest(cms.ProcessAccelerator):
0027     def __init__(self):
0028         super(ProcessAcceleratorTest,self).__init__()
0029         self._labels = ["test1", "test2"]
0030         self._enabled = ["test1"]
0031         {}
0032     def labels(self):
0033         return self._labels
0034     def enabledLabels(self):
0035         return self._enabled
0036 
0037 class SwitchProducerTest(cms.SwitchProducer):
0038     def __init__(self, **kargs):
0039         super(SwitchProducerTest,self).__init__(
0040             dict(
0041                 cpu = cms.SwitchProducer.getCpu(),
0042                 test1 = lambda accelerators: ("test1" in accelerators, 2),
0043                 test2 = lambda accelerators: ("test2" in accelerators, 3),
0044             ), **kargs)
0045 
0046 process = TestProcess()
0047 process.options.accelerators = ["{}"]
0048 process.ProcessAcceleratorTest = ProcessAcceleratorTest()
0049 process.s = SwitchProducerTest(
0050    cpu = cms.EDProducer('IntProducer', ivalue = cms.int32(0)),
0051    test1 = {},
0052    test2 = {}
0053 )
0054 process.moduleToTest(process.s)
0055 )_",
0056         appendTest2,
0057         accelerator,
0058         test1,
0059         test2);
0060   }
0061 }  // namespace
0062 
0063 TEST_CASE("Configuration", s_tag) {
0064   const std::string test1{"cms.EDProducer('IntProducer', ivalue = cms.int32(1))"};
0065   const std::string test2{"cms.EDProducer('ManyIntProducer', ivalue = cms.int32(2), values = cms.VPSet())"};
0066 
0067   const std::string baseConfig_auto = makeConfig(true, test1, test2, "*");
0068   const std::string baseConfig_test1 = makeConfig(true, test1, test2, "test1");
0069   const std::string baseConfig_test2 = makeConfig(true, test1, test2, "test2");
0070   const std::string baseConfigTest2Disabled_auto = makeConfig(false, test1, test2, "*");
0071   const std::string baseConfigTest2Disabled_test1 = makeConfig(false, test1, test2, "test1");
0072   const std::string baseConfigTest2Disabled_test2 = makeConfig(false, test1, test2, "test2");
0073 
0074   SECTION("Configuration hash is not changed") {
0075     auto pset_auto = edm::readConfig(baseConfig_auto);
0076     auto pset_test1 = edm::readConfig(baseConfig_test1);
0077     auto pset_test2 = edm::readConfig(baseConfig_test2);
0078     auto psetTest2Disabled_auto = edm::readConfig(baseConfigTest2Disabled_auto);
0079     auto psetTest2Disabled_test1 = edm::readConfig(baseConfigTest2Disabled_test1);
0080     auto psetTest2Disabled_test2 = edm::readConfig(baseConfigTest2Disabled_test2);
0081     pset_auto->registerIt();
0082     pset_test1->registerIt();
0083     pset_test2->registerIt();
0084     psetTest2Disabled_auto->registerIt();
0085     psetTest2Disabled_test1->registerIt();
0086     psetTest2Disabled_test2->registerIt();
0087     REQUIRE(pset_auto->id() == pset_test1->id());
0088     REQUIRE(pset_auto->id() == pset_test2->id());
0089     REQUIRE(pset_auto->id() == psetTest2Disabled_auto->id());
0090     REQUIRE(pset_auto->id() == psetTest2Disabled_test1->id());
0091     REQUIRE(pset_auto->id() == psetTest2Disabled_test2->id());
0092   }
0093 
0094   edm::test::TestProcessor::Config config_auto{baseConfig_auto};
0095   edm::test::TestProcessor::Config config_test1{baseConfig_test1};
0096   edm::test::TestProcessor::Config config_test2{baseConfig_test2};
0097   edm::test::TestProcessor::Config configTest2Disabled_auto{baseConfigTest2Disabled_auto};
0098   edm::test::TestProcessor::Config configTest2Disabled_test1{baseConfigTest2Disabled_test1};
0099   edm::test::TestProcessor::Config configTest2Disabled_test2{baseConfigTest2Disabled_test2};
0100 
0101   SECTION("Base configuration is OK") { REQUIRE_NOTHROW(edm::test::TestProcessor(config_auto)); }
0102 
0103   SECTION("No event data") {
0104     edm::test::TestProcessor tester(config_auto);
0105     REQUIRE_NOTHROW(tester.test());
0106   }
0107 
0108   SECTION("beginJob and endJob only") {
0109     edm::test::TestProcessor tester(config_auto);
0110     REQUIRE_NOTHROW(tester.testBeginAndEndJobOnly());
0111   }
0112 
0113   SECTION("Run with no LuminosityBlocks") {
0114     edm::test::TestProcessor tester(config_auto);
0115     REQUIRE_NOTHROW(tester.testRunWithNoLuminosityBlocks());
0116   }
0117 
0118   SECTION("LuminosityBlock with no Events") {
0119     edm::test::TestProcessor tester(config_auto);
0120     REQUIRE_NOTHROW(tester.testLuminosityBlockWithNoEvents());
0121   }
0122 
0123   SECTION("Test2 enabled, acclerators=*") {
0124     edm::test::TestProcessor tester(config_auto);
0125     auto event = tester.test();
0126     REQUIRE(event.get<edmtest::IntProduct>()->value == 2);
0127   }
0128 
0129   SECTION("Test2 enabled, acclerators=test1") {
0130     edm::test::TestProcessor tester(config_test1);
0131     auto event = tester.test();
0132     REQUIRE(event.get<edmtest::IntProduct>()->value == 1);
0133   }
0134 
0135   SECTION("Test2 enabled, acclerators=test2") {
0136     edm::test::TestProcessor tester(config_test2);
0137     auto event = tester.test();
0138     REQUIRE(event.get<edmtest::IntProduct>()->value == 2);
0139   }
0140 
0141   SECTION("Test2 disabled, accelerators=*") {
0142     edm::test::TestProcessor tester(configTest2Disabled_auto);
0143     auto event = tester.test();
0144     REQUIRE(event.get<edmtest::IntProduct>()->value == 1);
0145   }
0146 
0147   SECTION("Test2 disabled, accelerators=test1") {
0148     edm::test::TestProcessor tester(configTest2Disabled_test1);
0149     auto event = tester.test();
0150     REQUIRE(event.get<edmtest::IntProduct>()->value == 1);
0151   }
0152 
0153   SECTION("Test2 disabled, accelerators=test2") {
0154     REQUIRE_THROWS_WITH(
0155         edm::test::TestProcessor(configTest2Disabled_test2),
0156         Catch::Contains("The system has no compute accelerators that match the patterns") && Catch::Contains("test1"));
0157   }
0158 }