Replace dpl asserts with libc ones 80/228680/3
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 24 Mar 2020 16:32:26 +0000 (17:32 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 25 Mar 2020 12:28:53 +0000 (13:28 +0100)
- Libc asserts were already used in few places. Now it's unified.
- Libc asserts are disabled in release builds unlike dpl ones.
- Code coverage is improved.

Change-Id: Ie241b997433b2286d1b6c3f5e24571af5bf5809f

18 files changed:
CMakeLists.txt
src/CMakeLists.txt
src/manager/CMakeLists.txt
src/manager/common/certificate-impl.cpp
src/manager/crypto/sw-backend/internals.cpp
src/manager/dpl/core/include/dpl/assert.h [deleted file]
src/manager/dpl/core/include/dpl/noreturn.h [deleted file]
src/manager/dpl/core/src/assert.cpp [deleted file]
src/manager/dpl/core/src/binary_queue.cpp
src/manager/dpl/db/include/dpl/db/sql_connection.h
src/manager/dpl/db/src/naive_synchronization_object.cpp
src/manager/dpl/db/src/sql_connection.cpp
src/manager/dpl/log/src/log.cpp
src/manager/main/socket-manager.cpp
src/manager/service/glib-service.cpp
tests/CMakeLists.txt
tests/test_sql.cpp
tools/ckm_db_tool/CMakeLists.txt

index cfa5cc2..9787428 100644 (file)
@@ -80,6 +80,8 @@ ENDIF (DEFINED WATCHDOG_ENABLED)
 IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
     ADD_DEFINITIONS("-DTIZEN_DEBUG_ENABLE")
     ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG")
+ELSE (CMAKE_BUILD_TYPE MATCHES "DEBUG")
+    ADD_DEFINITIONS("-DNDEBUG=1")
 ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
 
 SET(TARGET_KEY_MANAGER "key-manager")
index d6fed0d..f69ab36 100644 (file)
@@ -73,7 +73,6 @@ SET(KEY_MANAGER_SOURCES
     ${KEY_MANAGER_PATH}/initial-values/NoCharactersHandler.cpp
     ${KEY_MANAGER_PATH}/initial-values/xml-utils.cpp
     ${KEY_MANAGER_PATH}/initial-values/initial-value-loader.cpp
-    ${KEY_MANAGER_PATH}/dpl/core/src/assert.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/sql_connection.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/naive_synchronization_object.cpp
     ${KEY_MANAGER_PATH}/sqlcipher/sqlcipher.c
index c22c6ca..ee0ce5e 100644 (file)
@@ -32,7 +32,6 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/dpl/log/src/log.cpp
     ${COMMON_PATH}/dpl/log/src/old_style_log_provider.cpp
     ${COMMON_PATH}/dpl/log/src/journal_log_provider.cpp
-    ${COMMON_PATH}/dpl/core/src/assert.cpp
     ${COMMON_PATH}/dpl/core/src/binary_queue.cpp
     ${COMMON_PATH}/dpl/core/src/colors.cpp
     ${COMMON_PATH}/dpl/core/src/exception.cpp
index 6a5f5e8..f81d44a 100644 (file)
  * @version     1.0
  * @brief       Certificate implementation.
  */
+#include <cassert>
+
 #include <openssl/x509.h>
 #include <openssl/x509v3.h>
 #include <openssl/pem.h>
 
 #include <dpl/log/log.h>
-#include <dpl/assert.h>
 
 #include <key-impl.h>
 #include <certificate-impl.h>
@@ -69,7 +70,7 @@ CertificateImpl::CertificateImpl(const RawBuffer &der, DataFormat format)
 
 CertificateImpl::CertificateImpl(X509 *x509, bool duplicate)
 {
-       Assert(x509);
+       assert(x509);
 
        if (duplicate)
                m_x509 = X509_dup(x509);
index a0f0239..a2d1ee8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -35,7 +35,6 @@
 #include <openssl/obj_mac.h>
 
 #include <ckm/ckm-error.h>
-#include <assert.h>
 #include <dpl/log/log.h>
 
 #include <generic-backend/exception.h>
diff --git a/src/manager/dpl/core/include/dpl/assert.h b/src/manager/dpl/core/include/dpl/assert.h
deleted file mode 100644 (file)
index ee865d1..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    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.
- */
-/*
- * @file        assert.h
- * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
- * @version     1.0
- * @brief       This file is the implementation file of assert
- */
-#ifndef CENT_KEY_ASSERT_H
-#define CENT_KEY_ASSERT_H
-
-#include <dpl/noreturn.h>
-#include <string>
-
-namespace CKM {
-// Assertion handler procedure
-// Do not call directly
-// Always use Assert macro
-CENT_KEY_NORETURN void AssertProc(const char *condition,
-                                                                 const char *file,
-                                                                 int line,
-                                                                 const char *function);
-} // namespace CKM
-
-#define Assert(Condition) do { if (!(Condition)) { CKM::AssertProc(#Condition, \
-                               __FILE__, \
-                               __LINE__, \
-                               __FUNCTION__); \
-       } } while (0)
-
-#define AssertMsg(Condition, Msg)                                         \
-       do {                                                                  \
-               if (!(Condition)) {                                               \
-                       CKM::AssertProc(                                              \
-                                       (std::string(std::string(#Condition)+" ") + Msg).c_str(), \
-                                       __FILE__, __LINE__, __FUNCTION__);                        \
-               }                                                                 \
-       } while (0)
-
-#endif // CENT_KEY_ASSERT_H
diff --git a/src/manager/dpl/core/include/dpl/noreturn.h b/src/manager/dpl/core/include/dpl/noreturn.h
deleted file mode 100644 (file)
index b9b85e0..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    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.
- */
-/*
- * @file        noreturn.h
- * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
- * @version     1.0
- * @brief       This file is the implementation file of noreturn
- */
-#ifndef CENT_KEY_NORETURN_H
-#define CENT_KEY_NORETURN_H
-
-#define CENT_KEY_NORETURN __attribute__((__noreturn__))
-
-#endif // CENT_KEY_NORETURN_H
diff --git a/src/manager/dpl/core/src/assert.cpp b/src/manager/dpl/core/src/assert.cpp
deleted file mode 100644 (file)
index 9fb4fa6..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    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.
- */
-/*
- * @file        assert.cpp
- * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
- * @version     1.0
- * @brief       This file is the implementation file of assert
- */
-#include "dpl/assert.h"
-
-#include <iostream>
-#include <cstdlib>
-#include <dpl/log/log.h>
-
-namespace CKM {
-void AssertProc(const char *condition,
-                               const char *file,
-                               int line,
-                               const char *function)
-{
-       try {
-               LogError(
-                       "################################################################################"
-                       << std::endl <<
-                       "###                          CKM assertion failed!                           ###"
-                       << std::endl <<
-                       "################################################################################"
-                       << std::endl <<
-                       "### Condition: " << condition << std::endl <<
-                       "### File: " << file << std::endl <<
-                       "### Line: " << line << std::endl <<
-                       "### Function: " << function <<
-                       "################################################################################");
-       } catch (...) {
-               // Just ignore possible double errors
-       }
-
-       // Fail with c-library abort
-       abort();
-}
-} // namespace CKM
index d30e18b..97f19e1 100644 (file)
@@ -21,7 +21,7 @@
  */
 #include <stddef.h>
 #include <dpl/binary_queue.h>
-#include <dpl/assert.h>
+#include <cassert>
 #include <algorithm>
 #include <functional>
 #include <malloc.h>
@@ -197,7 +197,7 @@ void BinaryQueue::Flatten(void *buffer, size_t bufferSize) const
        size_t bytesLeft = bufferSize;
        void *ptr = buffer;
        BucketList::const_iterator bucketIterator = m_buckets.begin();
-       Assert(m_buckets.end() != bucketIterator);
+       assert(m_buckets.end() != bucketIterator);
 
        // Flatten data
        while (bytesLeft > 0) {
@@ -250,8 +250,8 @@ BinaryQueue::Bucket::Bucket(const void *data,
        deleter(dataDeleter),
        param(userParam)
 {
-       Assert(data != NULL);
-       Assert(deleter != NULL);
+       assert(data != NULL);
+       assert(deleter != NULL);
 }
 
 BinaryQueue::Bucket::~Bucket()
@@ -280,7 +280,7 @@ void BinaryQueue::BucketVisitorCall::operator()(Bucket *bucket) const
 
 void BinaryQueue::VisitBuckets(BucketVisitor *visitor) const
 {
-       Assert(visitor != NULL);
+       assert(visitor != NULL);
 
        // Visit all buckets
        std::for_each(m_buckets.begin(), m_buckets.end(), BucketVisitorCall(visitor));
index 466ffa0..b0825bc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@
 #include <boost/optional.hpp>
 #include <dpl/log/log.h>
 #include <sqlcipher.h>
-#include <dpl/assert.h>
 #include <stdint.h>
 #include <dpl/raw-buffer.h>
 #include <noncopyable.h>
index 809b9e4..1c92e0b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -22,8 +22,8 @@
  */
 #include <stddef.h>
 #include <dpl/db/naive_synchronization_object.h>
-#include <dpl/assert.h>
 #include <time.h>
+#include <cassert>
 
 namespace {
 unsigned int seed = time(NULL);
@@ -56,8 +56,7 @@ void NanoSleep(uint64_t nanoseconds)
                if (nanosleep(&requestedTime, &remainingTime) == 0)
                        break;
 
-               int error = errno;
-               Assert(error == EINTR);
+               assert(errno == EINTR);
 
                requestedTime = remainingTime;
        }
index 15e3cc8..a9ee1b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2019 Samsung Electronics Co., Ltd. All rights reserved
+ * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -25,9 +25,9 @@
 #include <stddef.h>
 #include <dpl/db/sql_connection.h>
 #include <dpl/db/naive_synchronization_object.h>
-#include <dpl/assert.h>
 #include <dpl/scoped_ptr.h>
 #include <unistd.h>
+#include <cassert>
 #include <cstdio>
 #include <cstdarg>
 #include <memory>
@@ -70,7 +70,7 @@ SqlConnection::DataCommand::DataCommand(SqlConnection *connection,
        m_masterConnection(connection),
        m_stmt(NULL)
 {
-       Assert(connection != NULL);
+       assert(connection != NULL);
 
        // Notify all after potentially synchronized database connection access
        ScopedNotifyAll notifyAll(connection->m_synchronizationObject.get());
@@ -735,9 +735,10 @@ void SqlConnection::ResetKey(const RawBuffer &rawPassOld,
                return;
        }
 
-       AssertMsg(rawPassOld.size() == SQLCIPHER_RAW_DATA_SIZE &&
-                         rawPassNew.size() == SQLCIPHER_RAW_DATA_SIZE,
-                         "Binary data for raw password should be 32 bytes long.");
+       // Binary data for raw password should be 32 bytes long.
+       assert(rawPassOld.size() == SQLCIPHER_RAW_DATA_SIZE &&
+              rawPassNew.size() == SQLCIPHER_RAW_DATA_SIZE);
+
 
        // sqlcipher3_rekey requires for key to be already set
        if (!m_isKeySet)
@@ -767,9 +768,7 @@ void SqlConnection::Disconnect()
        LogPedantic("Disconnecting from DB...");
 
        // All stored data commands must be deleted before disconnect
-       AssertMsg(m_dataCommandsCount == 0,
-                         "All stored procedures must be deleted"
-                         " before disconnecting SqlConnection");
+       assert(m_dataCommandsCount == 0);
 
        int result;
 
index 37baa3a..8d86312 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2011 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -24,8 +24,6 @@
 
 #include <stdexcept>
 
-#include <cassert>
-
 #include <dpl/log/log.h>
 #include <dpl/singleton_safe_impl.h>
 #include <dpl/log/old_style_log_provider.h>
index 07ce31c..55150fe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
 #include <fcntl.h>
 #include <signal.h>
 #include <errno.h>
+#include <cassert>
 
 #include <systemd/sd-daemon.h>
 
 #include <dpl/errno_string.h>
 #include <dpl/log/log.h>
-#include <dpl/assert.h>
 
 #include <smack-check.h>
 #include <socket-manager.h>
@@ -456,7 +456,7 @@ void SocketManager::MainLoop()
                int ret = select(m_maxDesc + 1, &readSet, &writeSet, NULL, ptrTimeout);
 
                if (0 == ret) { // timeout
-                       Assert(!m_timeoutQueue.empty());
+                       assert(!m_timeoutQueue.empty());
 
                        Timeout pqTimeout = m_timeoutQueue.top();
                        m_timeoutQueue.pop();
index 3568384..d24833c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2016 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
  */
 
 #include <thread>
+#include <cassert>
 
 #include <dpl/log/log.h>
 
index b8ee380..40cd751 100644 (file)
@@ -26,7 +26,6 @@ SET(ENCRYPTION_SCHEME_SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/encryption-scheme/smack-access.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/encryption-scheme/scheme-test.cpp
 
-    ${KEY_MANAGER_PATH}/dpl/core/src/assert.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/naive_synchronization_object.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/sql_connection.cpp
     ${KEY_MANAGER_PATH}/service/db-crypto.cpp
@@ -134,7 +133,6 @@ SET(TEST_MERGED_SOURCES
     ${KEY_MANAGER_PATH}/crypto/sw-backend/internals.cpp
     ${KEY_MANAGER_PATH}/crypto/sw-backend/obj.cpp
     ${KEY_MANAGER_PATH}/crypto/sw-backend/store.cpp
-    ${KEY_MANAGER_PATH}/dpl/core/src/assert.cpp
     ${KEY_MANAGER_PATH}/dpl/core/src/colors.cpp
     ${KEY_MANAGER_PATH}/dpl/core/src/errno_string.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/naive_synchronization_object.cpp
index a63455a..d408711 100644 (file)
@@ -27,7 +27,6 @@
 #include <vector>
 #include <string>
 #include <sstream>
-#include <assert.h>
 #include <sqlcipher.h>
 #include <ckm/ckm-type.h>
 #include <errno.h>
index 1068aa0..7833c67 100644 (file)
@@ -46,7 +46,6 @@ SET(CKM_DB_TOOLS_SOURCES
     ${KEY_MANAGER_PATH}/crypto/sw-backend/internals.cpp
     ${KEY_MANAGER_PATH}/crypto/sw-backend/obj.cpp
     ${KEY_MANAGER_PATH}/crypto/sw-backend/store.cpp
-    ${KEY_MANAGER_PATH}/dpl/core/src/assert.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/naive_synchronization_object.cpp
     ${KEY_MANAGER_PATH}/dpl/db/src/sql_connection.cpp
     ${KEY_MANAGER_PATH}/initial-values/BufferHandler.cpp