From 5d2d7f3d6f771d4c5e00fdfab141c8a4592f5823 Mon Sep 17 00:00:00 2001
From: Peter Albrecht <albrecpe@gmail.com>
Date: Tue, 16 Jan 2024 15:54:53 +0100
Subject: [PATCH] Added segfault skill

---
 .../SkillProviderExample/CMakeLists.txt       |  2 +
 .../skills/SkillProviderExample/Segfault.cpp  | 29 +++++++++++++
 .../skills/SkillProviderExample/Segfault.h    | 41 +++++++++++++++++++
 .../SkillProviderExample.cpp                  |  4 ++
 .../SkillProviderExample.h                    |  1 +
 5 files changed, 77 insertions(+)
 create mode 100644 source/RobotAPI/components/skills/SkillProviderExample/Segfault.cpp
 create mode 100644 source/RobotAPI/components/skills/SkillProviderExample/Segfault.h

diff --git a/source/RobotAPI/components/skills/SkillProviderExample/CMakeLists.txt b/source/RobotAPI/components/skills/SkillProviderExample/CMakeLists.txt
index b13f663e2..56bfd4d8a 100644
--- a/source/RobotAPI/components/skills/SkillProviderExample/CMakeLists.txt
+++ b/source/RobotAPI/components/skills/SkillProviderExample/CMakeLists.txt
@@ -18,6 +18,7 @@ set(SOURCES
     Chaining.cpp
     Callback.cpp
     Timeout.cpp
+    Segfault.cpp
 )
 
 set(HEADERS
@@ -27,6 +28,7 @@ set(HEADERS
     Chaining.h
     Callback.h
     Timeout.h
+    Segfault.h
 )
 
 armarx_add_component("${SOURCES}" "${HEADERS}")
diff --git a/source/RobotAPI/components/skills/SkillProviderExample/Segfault.cpp b/source/RobotAPI/components/skills/SkillProviderExample/Segfault.cpp
new file mode 100644
index 000000000..324a67048
--- /dev/null
+++ b/source/RobotAPI/components/skills/SkillProviderExample/Segfault.cpp
@@ -0,0 +1,29 @@
+
+#include "Segfault.h"
+
+namespace armarx::skills::provider
+{
+    SegfaultSkill::SegfaultSkill() : SimpleSkill(GetSkillDescription())
+    {
+    }
+
+    SkillDescription
+    SegfaultSkill::GetSkillDescription()
+    {
+        return SkillDescription{
+            .skillId = skills::SkillID{.skillName = "Segfault"},
+            .description = "This skill segfaults while executing. This will kill the Provider!",
+            .timeout = armarx::core::time::Duration::MilliSeconds(100)};
+    }
+
+    Skill::MainResult
+    SegfaultSkill::main(const MainInput& in)
+    {
+        int* number = nullptr;
+        (*number)++;
+
+        ARMARX_IMPORTANT << "If you can read this in the log, something is really wrong with the "
+                            "SegfaultSkill. It should have segfaulted by now...";
+        return {TerminatedSkillStatus::Succeeded, nullptr};
+    }
+} // namespace armarx::skills::provider
diff --git a/source/RobotAPI/components/skills/SkillProviderExample/Segfault.h b/source/RobotAPI/components/skills/SkillProviderExample/Segfault.h
new file mode 100644
index 000000000..75c5a81fe
--- /dev/null
+++ b/source/RobotAPI/components/skills/SkillProviderExample/Segfault.h
@@ -0,0 +1,41 @@
+
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author     Fabian Reister ( fabian dot reister at kit dot edu )
+ * @date       2021
+ * @copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+
+#pragma once
+
+
+// RobotAPI
+#include <RobotAPI/libraries/skills/provider/SimpleSkill.h>
+
+namespace armarx::skills::provider
+{
+    class SegfaultSkill : public SimpleSkill
+    {
+    public:
+        SegfaultSkill();
+
+        static SkillDescription GetSkillDescription();
+
+    private:
+        Skill::MainResult main(const MainInput&) final;
+    };
+} // namespace armarx::skills::provider
diff --git a/source/RobotAPI/components/skills/SkillProviderExample/SkillProviderExample.cpp b/source/RobotAPI/components/skills/SkillProviderExample/SkillProviderExample.cpp
index 5ab480cd5..7a5be5053 100644
--- a/source/RobotAPI/components/skills/SkillProviderExample/SkillProviderExample.cpp
+++ b/source/RobotAPI/components/skills/SkillProviderExample/SkillProviderExample.cpp
@@ -57,6 +57,10 @@ namespace armarx::skills::provider
         // incomplete and prepare
         ARMARX_INFO << "Adding skill IncompleteSkill";
         addSkillFactory<IncompleteSkill>();
+
+        // incomplete and prepare
+        ARMARX_INFO << "Adding skill SegfaultSkill";
+        addSkillFactory<SegfaultSkill>();
     }
 
     void
diff --git a/source/RobotAPI/components/skills/SkillProviderExample/SkillProviderExample.h b/source/RobotAPI/components/skills/SkillProviderExample/SkillProviderExample.h
index b8391b088..be0c6b370 100644
--- a/source/RobotAPI/components/skills/SkillProviderExample/SkillProviderExample.h
+++ b/source/RobotAPI/components/skills/SkillProviderExample/SkillProviderExample.h
@@ -33,6 +33,7 @@
 #include "Chaining.h"
 #include "HelloWorld.h"
 #include "Incomplete.h"
+#include "Segfault.h"
 #include "Timeout.h"
 
 namespace armarx::skills::provider
-- 
GitLab