Commit c99f92e5 authored by Eric Cano's avatar Eric Cano
Browse files

Moved inheritance of tape::exception from std::exception to castor::execption::Exception.

Removed the now duplicated backtrace and adapted the code where needed.
parent 44e3ea20
......@@ -17,9 +17,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Eric Cano
*****************************************************************************/
......@@ -33,6 +30,7 @@ namespace castor {
public:
Backtrace();
operator std::string() const { return m_trace; }
Backtrace& operator= (const Backtrace& bt) { m_trace = bt.m_trace; return *this; }
private:
std::string m_trace;
};
......
......@@ -75,6 +75,14 @@ namespace castor {
return m_message;
}
/**
* Get the value of m_message as a sting, for const-c orrectness
* @return the value as a string.
*/
std::string getMessageValue() const {
return m_message.str();
}
/**
* Get the backtrace's contents
* @return backtrace in a standard string.
......@@ -110,6 +118,7 @@ namespace castor {
*/
std::string m_what;
protected:
/**
* Backtrace object. Its constructor does the heavy lifting of
* generating the backtrace.
......
add_executable(tapeserverd tapeserverd.cpp)
target_link_libraries(tapeserverd Exception SCSI System Utils File)
\ No newline at end of file
target_link_libraries(tapeserverd Exception SCSI System Utils File castorcommon)
\ No newline at end of file
......@@ -5,6 +5,6 @@ set_property(SOURCE Drive.cpp
add_executable(TapeDriveReadWriteTest TapeDriveReadWriteTest.cpp)
target_link_libraries(TapeDriveReadWriteTest TapeDrive Exception SCSI System Utils ${GTEST_LIBRARY} gmock pthread)
target_link_libraries(TapeDriveReadWriteTest TapeDrive Exception SCSI System Utils castorcommon ${GTEST_LIBRARY} gmock pthread)
install(TARGETS TapeDriveReadWriteTest
RUNTIME DESTINATION bin)
......@@ -30,9 +30,6 @@
#include <string.h>
#include <sstream>
#include <iosfwd>
#include <sstream>
#include <execinfo.h>
#include <cxxabi.h>
/* TODO remove me: it should be temporary */
......@@ -40,19 +37,13 @@
using namespace castor::tape;
const char * Exception::what() const throw () {
return m_what.c_str();
}
const char * Exception::shortWhat() const throw () {
return m_shortWhat.c_str();
void Exception::setWhat(const std::string& what) {
getMessage() << what;
}
void Exception::setWhat(const std::string& what) {
std::stringstream w;
w << what << std::endl << std::string(backtrace);
m_what = w.str();
m_shortWhat = what;
Exception::Exception(const Exception &ex): castor::exception::Exception(0) {
getMessage() << ex.getMessageValue();
m_backtrace = ex.m_backtrace;
}
Exceptions::Errnum::Errnum(std::string what):Exception("") {
......@@ -76,39 +67,4 @@ Exceptions::Errnum::Errnum(std::string what):Exception("") {
setWhat(w2.str());
}
Exceptions::Backtrace::Backtrace() {
void * array[200];
size_t depth = ::backtrace(array, sizeof(array)/sizeof(void*));
char ** strings = ::backtrace_symbols(array, depth);
if (!strings)
m_trace = "";
else {
std::stringstream trc;
for (size_t i=0; i<depth; i++) {
std::string line(strings[i]);
/* Demangle the c++, if possible. We expect the c++ function name's to live
* between a '(' and a +
* line format: /usr/lib/somelib.so.1(_Mangle2Mangle3Ev+0x123) [0x12345] */
if ((std::string::npos != line.find("(")) && (std::string::npos != line.find("+"))) {
std::string before, theFunc, after;
before = line.substr(0, line.find("(")+1);
theFunc = line.substr(line.find("(")+1, line.find("+") - (line.find("(") + 1));
after = line.substr(line.find("+"), std::string::npos);
int status(-1);
char demangled[200];
size_t length(sizeof(demangled));
abi::__cxa_demangle(theFunc.c_str(), demangled, &length, &status);
if (0 == status)
trc << before << demangled << after << " (C++ demangled)" << std::endl;
else
trc << strings[i] << std::endl;
} else {
trc << strings[i] << std::endl;
}
}
free (strings);
m_trace = trc.str();
}
}
......@@ -23,34 +23,20 @@
*****************************************************************************/
#pragma once
#include "../../../exception/Exception.hpp"
#include <exception>
#include <string>
namespace castor {
namespace tape {
namespace Exceptions {
class Backtrace {
public:
Backtrace();
operator std::string() const { return m_trace; }
private:
std::string m_trace;
};
}
class Exception: public std::exception {
class Exception: public castor::exception::Exception {
public:
Exception(const std::string& what) { setWhat(what); }
Exception(const std::string& what): castor::exception::Exception(0) { setWhat(what); }
// Copy operator needed to throw anonymous instance (throw myClass("some failure."))
Exception(const Exception &ex);
virtual ~Exception() throw() {};
virtual const char * what() const throw();
virtual const char * shortWhat() const throw();
Exceptions::Backtrace backtrace;
protected:
void setWhat(const std::string &w);
private:
std::string m_what;
std::string m_shortWhat;
};
namespace Exceptions {
......
......@@ -56,10 +56,10 @@ namespace UnitTests {
try {
Nested x;
} catch (castor::tape::Exception & e) {
std::string bt = e.backtrace;
std::string bt = e.backtrace();
ASSERT_NE(std::string::npos, bt.find("Nested::f1"));
ASSERT_NE(std::string::npos, bt.find("castor::tape::Exceptions::Backtrace::Backtrace"));
ASSERT_EQ("", std::string(e.shortWhat()));
ASSERT_NE(std::string::npos, bt.find("castor::exception::Backtrace::Backtrace"));
ASSERT_EQ("", std::string(e.getMessageValue()));
std::string fullWhat(e.what());
ASSERT_NE(std::string::npos, fullWhat.find("Nested::f1"));
}
......
......@@ -48,7 +48,7 @@ namespace SCSI {
w << ": " << sense->getACSString();
} catch (Exception &ex) {
w << ": In addition, failed to get ACS string: "
<< ex.shortWhat();
<< ex.getMessage();
}
}
setWhat(w.str());
......
......@@ -574,7 +574,7 @@ namespace UnitTests {
try { sense.getACSString(); ASSERT_TRUE(false); }
catch (castor::tape::Exception & ex) {
std::string what(ex.shortWhat());
std::string what(ex.getMessageValue());
ASSERT_NE(std::string::npos, what.find("response code not supported (0x74)"));
}
}
......@@ -618,7 +618,7 @@ namespace UnitTests {
ASSERT_THROW(castor::tape::SCSI::ExceptionLauncher(sgio), castor::tape::SCSI::Exception);
try { castor::tape::SCSI::ExceptionLauncher(sgio, "In exception validation:"); ASSERT_TRUE(false); }
catch (castor::tape::SCSI::Exception & ex) {
std::string what(ex.shortWhat());
std::string what(ex.getMessageValue());
ASSERT_NE(std::string::npos, what.find("Block sequence error"));
/* We check here that the formatting is also done correctly (space added when context
not empty */
......
......@@ -10,7 +10,7 @@ set_property(SOURCE ../SCSI/StructuresTest.cpp
PROPERTY COMPILE_FLAGS -fno-strict-aliasing
)
target_link_libraries(unitTest TapeDrive Exception SCSI System Utils File ${GTEST_LIBRARY} gmock pthread)
target_link_libraries(unitTest TapeDrive Exception SCSI System Utils File ${GTEST_LIBRARY} gmock pthread castorcommon)
install(TARGETS unitTest
RUNTIME DESTINATION bin)
......
Summary: The CERN tape server project
Name: tape-server
Version: @tape-server_VERSION_MAJOR@
Release: @tape-server_VERSION_MINOR@
Prefix: /usr
License: GPL
Group: Applications/File
Source: %{name}-%{version}-%{release}.tar.gz
BuildRoot: %{_tmppath}/%{name}-root
BuildRequires: cmake >= 2.6
BuildRequires: gtest >= 1.5.0
BuildRequires: gmock >= 1.5.0
BuildRequires: gtest-devel >= 1.5.0
BuildRequires: gmock-devel >= 1.5.0
BuildRequires: valgrind >= 3.5.0
BuildRequires: tetex-latex
BuildRequires: latex2html
BuildRequires: ImageMagick
BuildRequires: doxygen
BuildRequires: graphviz
%description
The CERN tape server project.
#######################################################################################
%package -n tape-server-utils
#######################################################################################
Summary: The CERN tape server utilities
Group: Applications/File
%description -n tape-server-utils
The CERN tape server utilities
#######################################################################################
%package -n tape-server-docs
#######################################################################################
Summary: The CERN tape server documentation
Group: Applications/File
%description -n tape-server-docs
The CERN tape server documentation
#######################################################################################
%package -n tape-server-system-tests
#######################################################################################
Summary: The CERN tape server system tests
Group: Applications/File
Requires: kmod-st-driver
Requires: kmod-mhvtl >= 1.4.4, mhvtl-utils >= 1.4.4
%description -n tape-server-system-tests
The CERN tape server system tests. Those tests are potentially destructive and should be used with care.
%prep
%setup -n %{name}-%{version}-%{release}
%build
test -e $RPM_BUILD_ROOT && rm -r $RPM_BUILD_ROOT
#%if 0%{?rhel} < 6 && %{?fedora}%{!?fedora:0} <= 1
#export CC=/usr/bin/gcc44 CXX=/usr/bin/g++44
#%endif
mkdir -p build
cd build
cmake ../ -DRELEASE=%{release} -DCMAKE_BUILD_TYPE=Debug
%{__make} %{_smp_mflags} all
#TapeServer_pdf
%install
cd build
%{__make} install DESTDIR=$RPM_BUILD_ROOT
echo "Installed!"
%check
cd build
test/unitTest
valgrind --leak-check=full --show-reachable=yes --error-exitcode=1 test/unitTest
%clean
rm -rf $RPM_BUILD_ROOT
%files -n tape-server-utils
%defattr(-,root,root)
/usr/local/bin/TapeDriveReadWriteTest
/usr/local/bin/unitTest
%files -n tape-server-docs
%defattr(-,root,root)
/usr/share/doc/*
%files -n tape-server-system-tests
%defattr(-,root,root)
/etc/*
%attr(755,-,-) /usr/local/bin/tape-server-system-test.sh
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment