Project
Loading...
Searching...
No Matches
test_Mermaid.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include "Mocking.h"
13#include "../src/ComputingResourceHelpers.h"
14#include "../src/DeviceSpecHelpers.h"
15#include "../src/MermaidHelpers.h"
16#include "../src/SimpleResourceManager.h"
19#include "Headers/DataHeader.h"
20
21#include <catch_amalgamated.hpp>
22#include <sstream>
23
24using namespace o2::framework;
25
26namespace
27{
28// because comparing the whole thing is a pain.
29void lineByLineComparison(const std::string& as, const std::string& bs)
30{
31 std::istringstream a(as);
32 std::istringstream b(bs);
33
34 char bufferA[1024];
35 char bufferB[1024];
36 while (a.good() && b.good()) {
37 a.getline(bufferA, 1024);
38 b.getline(bufferB, 1024);
39 REQUIRE(std::string(bufferA) == std::string(bufferB));
40 }
41 REQUIRE(a.eof());
42 REQUIRE(b.eof());
43}
44
45// This is how you can define your processing in a declarative way
47{
48 return {{"A", Inputs{},
49 Outputs{OutputSpec{"TST", "A1"},
50 OutputSpec{"TST", "A2"}}},
51 {"B",
52 {InputSpec{"x", "TST", "A1"}},
53 Outputs{OutputSpec{"TST", "B1"}}},
54 {"C", Inputs{InputSpec{"x", "TST", "A2"}},
55 Outputs{OutputSpec{"TST", "C1"}}},
56 {"D",
57 Inputs{InputSpec{"i1", "TST", "B1"},
58 InputSpec{"i2", "TST", "C1"}},
59 Outputs{}}};
60}
61} // namespace
62
64{
65 return {
66 {"A",
67 {},
68 {
69 OutputSpec{"TST", "A"},
70 }},
71 timePipeline({"B",
72 {InputSpec{"a", "TST", "A"}},
73 {OutputSpec{"TST", "B"}}},
74 3),
75 timePipeline({"C",
76 {InputSpec{"b", "TST", "B"}},
77 {OutputSpec{"TST", "C"}}},
78 2),
79 };
80}
81
82TEST_CASE("TestMermaid")
83{
84 auto workflow = defineDataProcessing();
85 std::ostringstream str;
86 std::vector<DeviceSpec> devices;
87 for (auto& device : devices) {
88 REQUIRE(device.id != "");
89 }
90 auto configContext = makeEmptyConfigContext();
91 auto channelPolicies = ChannelConfigurationPolicy::createDefaultPolicies(*configContext);
92 auto completionPolicies = CompletionPolicy::createDefaultPolicies();
93 auto callbacksPolicies = CallbacksPolicy::createDefaultPolicies();
94 std::vector<ComputingResource> resources = {ComputingResourceHelpers::getLocalhostResource()};
95 SimpleResourceManager rm(resources);
96 DeviceSpecHelpers::dataProcessorSpecs2DeviceSpecs(workflow, channelPolicies, completionPolicies, callbacksPolicies, devices, rm, "workflow-id", *configContext);
97 str.str("");
99 lineByLineComparison(str.str(), R"EXPECTED(graph TD
100 A
101 B
102 C
103 D
104 A-- 22000:from_A_to_B -->B
105 A-- 22001:from_A_to_C -->C
106 B-- 22002:from_B_to_D -->D
107 C-- 22003:from_C_to_D -->D
108)EXPECTED");
109}
110
111TEST_CASE("TestMermaidWithPipeline")
112{
113 auto workflow = defineDataProcessing2();
114 std::ostringstream str;
115 std::vector<DeviceSpec> devices;
116 for (auto& device : devices) {
117 REQUIRE(device.id != "");
118 }
119 auto configContext = makeEmptyConfigContext();
120 auto channelPolicies = ChannelConfigurationPolicy::createDefaultPolicies(*configContext);
121 auto completionPolicies = CompletionPolicy::createDefaultPolicies();
122 auto callbacksPolicies = CallbacksPolicy::createDefaultPolicies();
123 std::vector<ComputingResource> resources = {ComputingResourceHelpers::getLocalhostResource()};
124 SimpleResourceManager rm(resources);
125 DeviceSpecHelpers::dataProcessorSpecs2DeviceSpecs(workflow, channelPolicies, completionPolicies, callbacksPolicies, devices, rm, "workflow-id", *configContext);
126 str.str("");
128 lineByLineComparison(str.str(), R"EXPECTED(graph TD
129 A
130 B_t0
131 B_t1
132 B_t2
133 C_t0
134 C_t1
135 A-- 22000:from_A_to_B_t0 -->B_t0
136 A-- 22001:from_A_to_B_t1 -->B_t1
137 A-- 22002:from_A_to_B_t2 -->B_t2
138 B_t0-- 22003:from_B_t0_to_C_t0 -->C_t0
139 B_t1-- 22005:from_B_t1_to_C_t0 -->C_t0
140 B_t2-- 22007:from_B_t2_to_C_t0 -->C_t0
141 B_t0-- 22004:from_B_t0_to_C_t1 -->C_t1
142 B_t1-- 22006:from_B_t1_to_C_t1 -->C_t1
143 B_t2-- 22008:from_B_t2_to_C_t1 -->C_t1
144)EXPECTED");
145}
WorkflowSpec defineDataProcessing(ConfigContext const &configcontext)
std::unique_ptr< ConfigContext > makeEmptyConfigContext()
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")
std::vector< DataProcessorSpec > WorkflowSpec
DataProcessorSpec timePipeline(DataProcessorSpec original, size_t count)
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
static std::vector< CallbacksPolicy > createDefaultPolicies()
static std::vector< ChannelConfigurationPolicy > createDefaultPolicies(ConfigContext const &configContext)
Default policies to use, based on the contents of the @configContex content.
static std::vector< CompletionPolicy > createDefaultPolicies()
Helper to create the default configuration.
static void dataProcessorSpecs2DeviceSpecs(const WorkflowSpec &workflow, std::vector< ChannelConfigurationPolicy > const &channelPolicies, std::vector< CompletionPolicy > const &completionPolicies, std::vector< DispatchPolicy > const &dispatchPolicies, std::vector< ResourcePolicy > const &resourcePolicies, std::vector< CallbacksPolicy > const &callbacksPolicies, std::vector< SendingPolicy > const &sendingPolicy, std::vector< ForwardingPolicy > const &forwardingPolicies, std::vector< DeviceSpec > &devices, ResourceManager &resourceManager, std::string const &uniqueWorkflowId, ConfigContext const &configContext, bool optimizeTopology=false, unsigned short resourcesMonitoringInterval=0, std::string const &channelPrefix="", OverrideServiceSpecs const &overrideServices={})
static void dumpDeviceSpec2Mermaid(std::ostream &, const Devices &specs)
Helper to dump a set of devices as a mermaid file.
WorkflowSpec defineDataProcessing2()
const std::string str