File indexing completed on 2024-04-06 12:13:08
0001 #include "FWCore/SharedMemory/interface/ControllerChannel.h"
0002 #include "FWCore/SharedMemory/interface/WorkerChannel.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004
0005 #include <memory>
0006 #include <string>
0007 #include <stdio.h>
0008 #include <cassert>
0009 #include <thread>
0010
0011 #include "controller.h"
0012 namespace {
0013 int worker(int argc, char** argv) {
0014 using namespace edm::shared_memory;
0015
0016 assert(argc == 3);
0017 WorkerChannel channel(argv[1], argv[2]);
0018
0019
0020 channel.workerSetupDone();
0021
0022 channel.handleTransitions(
0023 [&](edm::Transition iTransition, unsigned long long iTransitionID) { throw cms::Exception("BAD"); });
0024 return 0;
0025 }
0026 const char* jobType(bool isWorker) {
0027 if (isWorker) {
0028 return "Worker";
0029 }
0030 return "Controller";
0031 }
0032
0033 }
0034
0035 int main(int argc, char** argv) {
0036 bool isWorker = true;
0037 int retValue = 0;
0038 try {
0039 if (argc > 1) {
0040 retValue = worker(argc, argv);
0041 } else {
0042 isWorker = false;
0043 retValue = controller(argc, argv, 5);
0044 }
0045 } catch (cms::Exception const& iException) {
0046 if (iException.category() != "TimeOut") {
0047 std::cerr << "Caught exception\n" << iException.what() << "\n";
0048 return 1;
0049 } else {
0050 std::cout << "expected failure occurred\n";
0051 return 0;
0052 }
0053 } catch (std::exception const& iException) {
0054 std::cerr << "Caught exception\n" << iException.what() << "\n";
0055 if (isWorker) {
0056 std::cerr << "in worker\n";
0057 } else {
0058 std::cerr << "in controller\n";
0059 }
0060 return 1;
0061 }
0062 if (0 == retValue) {
0063 std::cout << jobType(isWorker) << " success" << std::endl;
0064 } else {
0065 std::cout << jobType(isWorker) << " failed" << std::endl;
0066 }
0067 return 1;
0068 }