Skip to content

Commit c28cbd1

Browse files
authored
DPL: add test to verify crashing workflows (#13102)
1 parent ca74488 commit c28cbd1

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

Framework/Core/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ o2_add_test(O2DatabasePDG NAME test_Framework_test_O2DatabasePDG
281281
LABELS framework
282282
PUBLIC_LINK_LIBRARIES O2::Framework O2::FrameworkPhysicsSupport)
283283

284+
o2_add_executable(crashing-workflow
285+
SOURCES test/test_CrashingWorkflow.cxx
286+
COMPONENT_NAME Framework
287+
PUBLIC_LINK_LIBRARIES O2::Framework)
288+
284289
# All the tests which require ROOT to work
285290
add_executable(o2-test-framework-root
286291
test/test_Root2ArrowTable.cxx
@@ -290,6 +295,7 @@ target_link_libraries(o2-test-framework-root PRIVATE O2::Catch2)
290295
target_link_libraries(o2-test-framework-root PRIVATE ROOT::ROOTDataFrame)
291296
set_property(TARGET o2-test-framework-root PROPERTY RUNTIME_OUTPUT_DIRECTORY ${outdir})
292297
add_test(NAME framework:root COMMAND o2-test-framework-root --skip-benchmarks)
298+
add_test(NAME framework:crash COMMAND sh -e -c "PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}:$PATH ${CMAKE_CURRENT_LIST_DIR}/test/test_AllCrashTypes.sh")
293299

294300
o2_add_test(InfoLogger NAME test_Framework_test_InfoLogger
295301
SOURCES test/test_InfoLogger.cxx
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh -e
2+
echo $PATH
3+
printf "ok\nTesting runtime-init..."
4+
o2-framework-crashing-workflow --crash-type=runtime-init --completion-policy=quit -b --run | grep -q "Exception caught: This is a std::runtime_error" || { printf "runtime error not found" ; exit 1; }
5+
printf "ok\nTesting framework-init..."
6+
o2-framework-crashing-workflow --crash-type=framework-init --completion-policy=quit -b --run | grep -q "Exception caught: This is a o2::framework::runtime_error" || { printf "framework error not found" ; exit 1; }
7+
printf "ok\nTesting framework-run..."
8+
o2-framework-crashing-workflow --crash-type=framework-run --completion-policy=quit -b --run | grep -q "Unhandled o2::framework::runtime_error reached the top of main of o2-framework-crashing-workflow, device shutting down. Reason: This is a o2::framework::runtime_error" || { printf "framework error not found" ; exit 1; }
9+
printf "ok\nTesting runtime-run..."
10+
o2-framework-crashing-workflow --crash-type=runtime-run --completion-policy=quit --run | grep -q "Unhandled o2::framework::runtime_error reached the top of main of o2-framework-crashing-workflow, device shutting down. Reason: This is a std::runtime_error" || { echo "runtime error not found" ; exit 1; }
11+
printf "ok\n"
12+
13+
export O2_NO_CATCHALL_EXCEPTIONS=1
14+
echo O2_NO_CATCHALL_EXCEPTIONS enabled
15+
printf "ok\nTesting runtime-init..."
16+
o2-framework-crashing-workflow --crash-type=runtime-init --completion-policy=quit -b --run | grep -v -q "Exception caught: This is a std::runtime_error" || { printf "runtime error not found" ; exit 1; }
17+
printf "ok\nTesting framework-init..."
18+
o2-framework-crashing-workflow --crash-type=framework-init --completion-policy=quit -b --run | grep -v -q "Exception caught: This is a o2::framework::runtime_error" || { printf "framework error not found" ; exit 1; }
19+
printf "ok\nTesting framework-run..."
20+
o2-framework-crashing-workflow --crash-type=framework-run --completion-policy=quit -b --run | grep -v -q "Unhandled o2::framework::runtime_error reached the top of main of o2-framework-crashing-workflow, device shutting down. Reason: This is a o2::framework::runtime_error" || { printf "framework error not found" ; exit 1; }
21+
printf "ok\nTesting runtime-run..."
22+
o2-framework-crashing-workflow --crash-type=runtime-run --completion-policy=quit --run | grep -v -q "Unhandled o2::framework::runtime_error reached the top of main of o2-framework-crashing-workflow, device shutting down. Reason: This is a std::runtime_error" || { echo "runtime error not found" ; exit 1; }
23+
printf "ok"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
#include "Framework/ConfigParamSpec.h"
12+
#include "Framework/AlgorithmSpec.h"
13+
#include "Framework/Configurable.h"
14+
#include "Framework/Logger.h"
15+
#include "Framework/CallbackService.h"
16+
#include "Framework/Signpost.h"
17+
18+
O2_DECLARE_DYNAMIC_LOG(crash_test);
19+
20+
using namespace o2::framework;
21+
22+
struct WorkflowOptions {
23+
Configurable<std::string> crashType{"crash-type", "fatal-init", {"how should this crash? (fatal-init, fatal-run, runtime-init, runtime-fail, abort-init, abort-run)"}};
24+
};
25+
26+
#include "Framework/runDataProcessing.h"
27+
28+
AlgorithmSpec simpleCrashingSource(std::string const& what)
29+
{
30+
return AlgorithmSpec{adaptStateful([what](InitContext& ctx) {
31+
O2_SIGNPOST_ID_FROM_POINTER(ii, crash_test, &ctx);
32+
O2_SIGNPOST_START(crash_test, ii, "Init", "Starting Init");
33+
O2_SIGNPOST_EVENT_EMIT(crash_test, ii, "Init", "%{public}s selected", what.c_str());
34+
35+
if (what == "fatal-init") {
36+
LOG(fatal) << "This should have a fatal";
37+
} else if (what == "runtime-init") {
38+
throw std::runtime_error("This is a std::runtime_error");
39+
} else if (what == "abort-init") {
40+
abort();
41+
} else if (what == "framework-init") {
42+
throw o2::framework::runtime_error("This is a o2::framework::runtime_error");
43+
} else if (what == "framework-prerun") {
44+
ctx.services().get<CallbackService>().set<CallbackService::Id::PreProcessing>([](ServiceRegistryRef, int) {
45+
throw o2::framework::runtime_error("This is o2::framework::runtime_error in PreProcessing");
46+
});
47+
} else if (what == "runtime-prerun") {
48+
ctx.services().get<CallbackService>().set<CallbackService::Id::PreProcessing>([](ServiceRegistryRef, int) {
49+
throw std::runtime_error("This is std::runtime_error in PreProcessing");
50+
});
51+
}
52+
O2_SIGNPOST_END(crash_test, ii, "Init", "Init Done");
53+
return adaptStateless([what](ProcessingContext& pCtx) {
54+
O2_SIGNPOST_ID_FROM_POINTER(ri, crash_test, &pCtx);
55+
O2_SIGNPOST_START(crash_test, ri, "Run", "Starting Run");
56+
O2_SIGNPOST_EVENT_EMIT(crash_test, ri, "Run", "%{public}s selected", what.c_str());
57+
if (what == "fatal-run") {
58+
LOG(fatal) << "This should have a fatal";
59+
} else if (what == "runtime-run") {
60+
throw std::runtime_error("This is a std::runtime_error");
61+
} else if (what == "abort-run") {
62+
abort();
63+
} else if (what == "framework-run") {
64+
throw o2::framework::runtime_error("This is a o2::framework::runtime_error");
65+
}
66+
O2_SIGNPOST_EVENT_EMIT_ERROR(crash_test, ri, "Run", "Unknown option for crash-type: %{public}s.", what.c_str());
67+
O2_SIGNPOST_END(crash_test, ri, "Init", "Run Done");
68+
exit(1);
69+
});
70+
})};
71+
}
72+
73+
// This is how you can define your processing in a declarative way
74+
WorkflowSpec defineDataProcessing(ConfigContext const& config)
75+
{
76+
auto crashType = config.options().get<std::string>("crash-type");
77+
DataProcessorSpec a{
78+
.name = "deliberately-crashing",
79+
.outputs = {OutputSpec{{"a1"}, "TST", "A1"}},
80+
.algorithm = AlgorithmSpec{simpleCrashingSource(crashType)}};
81+
DataProcessorSpec b{
82+
.name = "B",
83+
.inputs = {InputSpec{"x", "TST", "A1", Lifetime::Timeframe}},
84+
.algorithm = AlgorithmSpec{adaptStateless([](ProcessingContext&) {})}};
85+
86+
return workflow::concat(WorkflowSpec{a, b});
87+
}
88+

0 commit comments

Comments
 (0)