Add DaliPrintBackTrace for common 54/302454/2
authorHeeyong Song <heeyong.song@samsung.com>
Wed, 17 Nov 2021 07:00:04 +0000 (16:00 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Thu, 7 Dec 2023 04:49:35 +0000 (13:49 +0900)
Change-Id: Ieb24205ccdc75d3b9a4ac3e7b44166503a472d80

automated-tests/src/dali/CMakeLists.txt
automated-tests/src/dali/utc-Dali-Common.cpp [new file with mode: 0644]
dali/public-api/common/dali-common.cpp
dali/public-api/common/dali-common.h

index 0baf3ec..64aa025 100644 (file)
@@ -15,6 +15,7 @@ SET(TC_SOURCES
         utc-Dali-BaseHandle.cpp
         utc-Dali-CameraActor.cpp
         utc-Dali-CircularQueue.cpp
+        utc-Dali-Common.cpp
         utc-Dali-ConditionalWait.cpp
         utc-Dali-ConnectionTracker.cpp
         utc-Dali-Constrainer.cpp
diff --git a/automated-tests/src/dali/utc-Dali-Common.cpp b/automated-tests/src/dali/utc-Dali-Common.cpp
new file mode 100644 (file)
index 0000000..e4a0870
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali-test-suite-utils.h>
+
+#include <dali/public-api/common/dali-common.h>
+
+using namespace Dali;
+
+void utc_dali_common_startup(void)
+{
+  test_return_value = TET_UNDEF;
+}
+
+void utc_dali_common_cleanup(void)
+{
+  test_return_value = TET_PASS;
+}
+
+int UtcDaliCommonPrintBackTrace(void)
+{
+  TestApplication application;
+  tet_infoline("Testing Dali::DaliPrintBackTrace");
+
+  try
+  {
+    Dali::DaliPrintBackTrace();
+    tet_result(TET_PASS);
+  }
+  catch(...)
+  {
+    tet_result(TET_FAIL);
+  }
+
+  END_TEST;
+}
index 486606a..87dfa7f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -124,6 +124,21 @@ DALI_CORE_API DaliException::DaliException(const char* location, const char* con
   free(symbols);
 }
 
+DALI_CORE_API void DaliPrintBackTrace()
+{
+  DALI_LOG_ERROR_NOFN("Backtrace:\n");
+
+  void*   frameArray[MAX_NUM_STACK_FRAMES];
+  int32_t nSize   = backtrace(frameArray, MAX_NUM_STACK_FRAMES);
+  char**  symbols = backtrace_symbols(frameArray, nSize);
+  for(int32_t i = 1; i < nSize; i++)
+  {
+    std::string demangled_symbol = Demangle(symbols[i]);
+    DALI_LOG_ERROR_NOFN("[%02d]   %s\n", i, demangled_symbol.c_str());
+  }
+  free(symbols);
+}
+
 #else // BACKTRACE_ENABLED
 
 DALI_CORE_API DaliException::DaliException(const char* location, const char* condition)
@@ -137,6 +152,10 @@ DALI_CORE_API DaliException::DaliException(const char* location, const char* con
 #endif
 }
 
+DALI_CORE_API void DaliPrintBackTrace()
+{
+}
+
 #endif // BACKTRACE_ENABLED
 
 DALI_CORE_API void DaliAssertMessage(const char* location, const char* condition)
index a32e4a8..d703cd6 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_COMMON_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -119,6 +119,14 @@ namespace Dali
 DALI_CORE_API void DaliAssertMessage(const char* location, const char* condition);
 
 /**
+ * @brief Print backtrace log if required.
+ * @note Do nothing if ENABLE_BACKTRACE option off.
+ *
+ * @SINCE_2_3.2
+ */
+DALI_CORE_API void DaliPrintBackTrace();
+
+/**
  * @brief Exception class for Dali Core library - Raised by assertions in codebase.
  * @SINCE_1_0.0
  */