Repository: eclipse-iceoryx/iceoryx (C++)

Issue:
MacOS tests that use EXPECT_DEATH stuck
## Required information

Jobs that failed
https://github.com/eclipse-iceoryx/iceoryx/runs/3250456083
https://github.com/eclipse-iceoryx/iceoryx/runs/3249546327
https://github.com/eclipse-iceoryx/iceoryx/runs/3242681619


**Operating system:**
macos-10.14 (and macos-latest) (github actions machines)

**Compiler version:**
Apple clang version 12.0.0 (clang-1200.0.32.29) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Applications/Xcode_12.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

**Observed result or behaviour:**
On MacOS seems we hit deadlock or some other glitches (e.g. described [here](https://github.com/google/googletest/blob/master/docs/advanced.md#caveats)) in tests that use EXPECT_DEATH

e.g. jobs above stuck on
* RouDiEnvironment_test.StartingRouDiTwiceLeadsToError (2x)
* BindingC_Runtime_test.RuntimeNameIsNullptr

**Expected result or behaviour:**
What do you expect to happen?

No stuck tests

**Conditions where it occurred / Performed steps:**
Describe how one can reproduce the bug.

Rerun CI at least 3-5 times, if macos job is running 30+ minutes it means it stuck (6h timeout from github)

## Related

 #1422

Remove `EXPECT_DEATH`
## Required information

In our cases using `EXPECT_DEATH` come often with undefined behavior which is unacceptable for certified tests. Possible approaches are:

* Create thread and call `pthread_exit` inside the error handler, would require the implementation of that feature in #1365 
* Throw an exception in the error handler, would require heavy refactoring and feature #1392 
* Another nifty idea.

## ToDo
- [x] (high prio) Define an alternative technique to `EXPECT_DEATH` and document it in the iceoryx testing document
- [x] (high prio) Remove all occurrences of `EXPECT_DEATH` in cxx tests
- [x] (medium prio) Remove all occurrences of `EXPECT_DEATH` in remaining hoofs
- [ ] (low prio) Remove all occurrences of `EXPECT_DEATH` in the remaining iceoryx repo
  - Using `EXPECT_FATAL_FAILURE` in combination with the `RouDiEnvironment` results in triggering the leak sanitizer
  - The same is the case when the SUT allocate in the call which leads to the fatal failure, e.g. the ctor of `FileReader`

Can be split up in further issues when required.

Extracted from: #1196 


Discussion: The problem is not the death tests per se but the forking after there are other threads are already running, which is the case when RouDiEnvironment is used. Luckily, many of the death tests don't really need a running RouDi
Discussion in developer meeting: Replace the EXPECT_DEATH with something based on exceptions or an extended version of our error handler. 
@elfenpiff to create an issue to continue the error handler discussion 
Created issue #1032 when the error handling concept is implemented death tests should be obsolete.
With the merge of #1879 most of the `EXPECT_DEATH` are replaced. The remaining ones need a suppression for the leak sanitizer when used with `EXPECT_FATAL_FAILURE`

@elfenpiff last week @MatthiasKillat tried the approach with returning from a running thread. This might be the solution to remove the `EXPECT_DEATH` once the error handler is merged.



Fix (patch):
diff --git a/doc/design/error-handling.md b/doc/design/error-handling.md
index c600d03985..5667bf1245 100644
--- a/doc/design/error-handling.md
+++ b/doc/design/error-handling.md
@@ -281,6 +281,14 @@ TEST(MyTest, valueOnNulloptIsFatal) {
 }
 ```
 
+In cases where the `IOX_EXPECT_FATAL_FAILURE` cannot be used, e.g. testing the `PoshRuntime` with its singleton, `EXPECT_DEATH`
+shall be used with `GTEST_FLAG(death_test_style) = "threadsafe";`.
+
+```cpp
+GTEST_FLAG(death_test_style) = "threadsafe";
+EXPECT_DEATH(bad_call(), ".*");
+```
+
 ## Open points
 
 ### Centralized error handling
diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md
index 6b402fd8e0..36c495bace 100644
--- a/doc/website/release-notes/iceoryx-unreleased.md
+++ b/doc/website/release-notes/iceoryx-unreleased.md
@@ -88,6 +88,8 @@
 - ServiceDescription `Interfaces` and `INTERFACE_NAMES` do not match [\#1977](https://github.com/eclipse-iceoryx/iceoryx/issues/1977)
 - Implement and test nullptr check in c binding [\#1106](https://github.com/eclipse-iceoryx/iceoryx/issues/1106)
 - Fix `expected<void, Error>` is unusable due to `final` [\#1976](https://github.com/eclipse-iceoryx/iceoryx/issues/1976)
+- MacOS tests that use `EXPECT_DEATH` stuck [#898](https://github.com/eclipse-iceoryx/iceoryx/issues/898)
+- Remove `EXPECT_DEATH` [#1613](https://github.com/eclipse-iceoryx/iceoryx/issues/1613)
 
 **Refactoring:**
 
diff --git a/iceoryx_posh/source/mepoo/mem_pool.cpp b/iceoryx_posh/source/mepoo/mem_pool.cpp
index 393c42eb28..7532d336fa 100644
--- a/iceoryx_posh/source/mepoo/mem_pool.cpp
+++ b/iceoryx_posh/source/mepoo/mem_pool.cpp
@@ -62,7 +62,8 @@ MemPool::MemPool(const greater_or_equal<uint32_t, CHUNK_MEMORY_ALIGNMENT> chunkS
     else
     {
         IOX_LOG(FATAL) << "Chunk size must be multiple of '" << CHUNK_MEMORY_ALIGNMENT << "'! Requested size is "
-                       << chunkSize << " for " << numberOfChunks << " chunks!";
+                       << static_cast<uint32_t>(chunkSize) << " for " << static_cast<uint32_t>(numberOfChunks)
+                       << " chunks!";
         errorHandler(PoshError::MEPOO__MEMPOOL_CHUNKSIZE_MUST_BE_MULTIPLE_OF_CHUNK_MEMORY_ALIGNMENT);
     }
 }