Skip to content

Commit

Permalink
tests: added backtrace_test
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Jul 4, 2019
1 parent 4d54d74 commit 95708d5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/src/tests/CMakeLists.txt
Expand Up @@ -277,3 +277,20 @@ target_link_libraries(test_fileindex_list

gtest_discover_tests(test_fileindex_list TEST_PREFIX gtest:)

####### test_backtrace #####################################
IF(HAVE_EXECINFO_H AND HAVE_BACKTRACE AND HAVE_BACKTRACE_SYMBOLS)
add_executable(test_backtrace test_backtrace.cc)

target_link_libraries(test_backtrace
bareos
${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
)

add_test(NAME test_backtrace
COMMAND test_backtrace
)

gtest_discover_tests(test_backtrace TEST_PREFIX gtest:)
ENDIF()

34 changes: 34 additions & 0 deletions core/src/tests/test_backtrace.cc
@@ -0,0 +1,34 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2019-2019 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program 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
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/

#include "gtest/gtest.h"
#include "include/bareos.h"
#include "lib/backtrace.cc"

#include <string>
#include <iostream>

TEST(Backtrace, test_backtrace)
{
std::vector<BacktraceInfo> bt(Backtrace(0, 1));
ASSERT_EQ(bt.size(), 1);
EXPECT_NE(bt[0].function_call_.find("Backtrace"), std::string::npos);
}

0 comments on commit 95708d5

Please sign in to comment.