Project
Loading...
Searching...
No Matches
test_WorkflowSerialization.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
13#include "../src/WorkflowSerializationHelpers.h"
14#include <catch_amalgamated.hpp>
15
16using namespace o2::framework;
17
18TEST_CASE("TestVerifyWorkflowSerialization")
19{
20 using namespace o2::framework;
21 WorkflowSpec w0{ //
22 DataProcessorSpec{"A", //
23 {InputSpec{"foo", "A", "COLLISIONCONTEXT", 1, Lifetime::Condition, {
24 ConfigParamSpec{"aUrl", VariantType::String, "foo/bar", {"A InputSpec option"}}, //
25 ConfigParamSpec{"bUrl", VariantType::String, "foo/foo", {"Another InputSpec option"}}, //
26 }}}, //
27 {OutputSpec{{"bar"}, "C", "D", 2, Lifetime::Timeframe}}, //
28 AlgorithmSpec{[](ProcessingContext& ctx) {}}, //
29 { //
30 ConfigParamSpec{"aInt", VariantType::Int, 0, {"An Int"}}, //
31 ConfigParamSpec{"aFloat", VariantType::Float, 1.3, {"A Float"}}, //
32 ConfigParamSpec{"aBool", VariantType::Bool, true, {"A Bool"}}, //
33 ConfigParamSpec{"aString", VariantType::String, "some string", {"A String"}}}}, // //
34 DataProcessorSpec{"B", //
35 {InputSpec{"foo", "C", "D"}}, //
36 { //
37 OutputSpec{{"bar1"}, "E", "F", 0}, //
38 OutputSpec{{"bar2"}, "E", "F", 1}}, //
39 AlgorithmSpec{[](ProcessingContext& ctx) {}}, //
40 {}}, //
41 DataProcessorSpec{"C", {}, //
42 { //
43 OutputSpec{{"bar"}, "G", "H"}}, //
44 AlgorithmSpec{[](ProcessingContext& ctx) {}}, //
45 {}}, //
46 DataProcessorSpec{"D", {InputSpec{"foo", {"C", "D"}}}, //
47 {OutputSpec{{"bar"}, {"I", "L"}}}, //
48 AlgorithmSpec{[](ProcessingContext& ctx) {}}, //
49 {}, //
51 {{"label a"}, {"label \"b\""}},
52 {{"key1", "v\"al'1"}, {"", "val2"}, {"key3", ""}, {"", ""}}}};
53
54 std::vector<DataProcessorInfo> dataProcessorInfoOut{
55 {"A", "test_Framework_test_SerializationWorkflow", {"foo"}, {ConfigParamSpec{"aBool", VariantType::Bool, true, {"A Bool"}}}},
56 {"B", "test_Framework_test_SerializationWorkflow", {"b-bar", "bfoof", "fbdbfaso"}},
57 {"C", "test_Framework_test_SerializationWorkflow", {}},
58 {"D", "test_Framework_test_SerializationWorkflow", {}},
59 };
60
61 CommandInfo commandInfoOut{"o2-dpl-workflow -b --option 1 --option 2"};
62
63 std::vector<DataProcessorInfo> dataProcessorInfoIn{};
64 CommandInfo commandInfoIn;
65
66 std::ostringstream firstDump;
67 WorkflowSerializationHelpers::dump(firstDump, w0, dataProcessorInfoOut, commandInfoOut);
68 std::istringstream is;
69 is.str(firstDump.str());
70 WorkflowSpec w1;
71 WorkflowSerializationHelpers::import(is, w1, dataProcessorInfoIn, commandInfoIn);
72
73 std::ostringstream secondDump;
74 WorkflowSerializationHelpers::dump(secondDump, w1, dataProcessorInfoIn, commandInfoIn);
75
76 REQUIRE(w0.size() == 4);
77 REQUIRE(w0.size() == w1.size());
78 REQUIRE(firstDump.str() == secondDump.str());
79 REQUIRE(commandInfoIn.command == commandInfoOut.command);
80
81 // also check if the conversion to ConcreteDataMatcher is working at import
82 REQUIRE(std::get_if<ConcreteDataMatcher>(&w1[0].inputs[0].matcher) != nullptr);
83}
84
87TEST_CASE("TestVerifyWildcard")
88{
89 using namespace o2::framework;
90 WorkflowSpec w0{
92 .name = "A",
93 .inputs = {{"clbPayload", "CLP"}, {"clbWrapper", "CLW"}},
94 }};
95
96 std::vector<DataProcessorInfo> dataProcessorInfoOut{
97 {"A", "test_Framework_test_SerializationWorkflow", {}},
98 };
99
100 CommandInfo commandInfoOut{"o2-dpl-workflow -b --option 1 --option 2"};
101
102 std::vector<DataProcessorInfo> dataProcessorInfoIn{};
103 CommandInfo commandInfoIn;
104
105 std::ostringstream firstDump;
106 WorkflowSerializationHelpers::dump(firstDump, w0, dataProcessorInfoOut, commandInfoOut);
107 std::istringstream is;
108 is.str(firstDump.str());
109 WorkflowSpec w1;
110 WorkflowSerializationHelpers::import(is, w1, dataProcessorInfoIn, commandInfoIn);
111
112 std::ostringstream secondDump;
113 WorkflowSerializationHelpers::dump(secondDump, w1, dataProcessorInfoIn, commandInfoIn);
114
115 REQUIRE(w0.size() == 1);
116 REQUIRE(w0.size() == w1.size());
117 REQUIRE(firstDump.str() == secondDump.str());
118 REQUIRE(commandInfoIn.command == commandInfoOut.command);
119
120 // also check if the conversion to ConcreteDataMatcher is working at import
121 // REQUIRE(std::get_if<ConcreteDataTypeMatcher>(&w1[0].inputs[0].matcher) != nullptr);;
122}
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
TEST_CASE("test_prepareArguments")
std::vector< DataProcessorSpec > WorkflowSpec
static std::vector< ServiceSpec > defaultServices(std::string extraPlugins="", int numWorkers=0)
Split a string into a vector of strings using : as a separator.
static void dump(std::ostream &o, std::vector< DataProcessorSpec > const &workflow, std::vector< DataProcessorInfo > const &metadata, CommandInfo const &commandInfo)
static bool import(std::istream &s, std::vector< DataProcessorSpec > &workflow, std::vector< DataProcessorInfo > &metadata, CommandInfo &command)