Commit 0eb11490 authored by Steven Murray's avatar Steven Murray
Browse files

Added castorlegacymsgunittests.so

parent 771928cb
......@@ -18,6 +18,20 @@ set(CMAKE_CXX_FLAGS "-fPIC -pedantic -Wall -Wextra -Werror -Wno-unused-parameter
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g")
# With the exception of shared-library plugins, the CASTOR rpms only install the
# /usr/lib64/libcastor*.so symbolic links for libraries used by end-user
# developers. Therefore the locations of the internal CASTOR libraries required
# by tapeserved and not by end-user developers need to be imported into cmake.
add_library(castorlegacymsg SHARED IMPORTED)
set_target_properties(castorlegacymsg PROPERTIES
IMPORTED_LOCATION /usr/lib64/libcastorlegacymsg.so.2.1)
add_library(castorserver SHARED IMPORTED)
set_target_properties(castorserver PROPERTIES
IMPORTED_LOCATION /usr/lib64/libcastorserver.so.2.1)
add_library(castortapegatewayprotocol SHARED IMPORTED)
set_target_properties(castortapegatewayprotocol PROPERTIES
IMPORTED_LOCATION /usr/lib64/libcastortapegatewayprotocol.so.2.1)
IF(NOT CMAKE_BUILD_TYPE STREQUAL "")
# If the user specifies -DCMAKE_BUILD_TYPE on the command line, take their definition and dump it in the cache
message(STATUS "Setting build type to ${CMAKE_BUILD_TYPE} as requested.")
......
......@@ -20,6 +20,7 @@ cmake_minimum_required (VERSION 2.6)
add_subdirectory (exception)
add_subdirectory (io)
add_subdirectory (legacymsg)
add_subdirectory (log)
add_subdirectory (mediachanger)
add_subdirectory (messages)
......
cmake_minimum_required (VERSION 2.6)
include_directories(${PROJECT_SOURCE_DIR}/tapeserver)
include_directories(${PROJECT_SOURCE_DIR}/tapeserver/h)
add_library (castorlegacymsgunittests SHARED
CommonMarshalTest.cpp
GenericMarshalTest.cpp
TapeMarshalTest.cpp)
target_link_libraries (castorlegacymsgunittests
castorclient
castorlegacymsg
castormessages)
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/io/io.hpp"
#include "castor/legacymsg/CommonMarshal.hpp"
#include <errno.h>
#include <iostream>
#include <string.h>
//-----------------------------------------------------------------------------
// marshal
//-----------------------------------------------------------------------------
size_t castor::legacymsg::marshal(char *const dst, const size_t dstLen,
const MessageHeader &src) {
if(dst == NULL) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to marshal MessageHeader"
<< ": Pointer to destination buffer is NULL";
throw ex;
}
// Calculate the length of the message header
const uint32_t totalLen = 3 * sizeof(uint32_t); // magic + reqType + len
// Check that the message header buffer is big enough
if(totalLen > dstLen) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to marshal MessageHeader"
": Buffer too small : required=" << totalLen << " actual=" << dstLen;
throw ex;
}
// Marshal the message header
char *p = dst;
io::marshalUint32(src.magic , p);
io::marshalUint32(src.reqType , p);
io::marshalUint32(src.lenOrStatus, p);
// Calculate the number of bytes actually marshalled
const size_t nbBytesMarshalled = p - dst;
// Check that the number of bytes marshalled was what was expected
if(totalLen != nbBytesMarshalled) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to marshal MessageHeader"
": Mismatch between expected total length and actual"
": expected=" << totalLen << " actual=" << nbBytesMarshalled;
throw ex;
}
return totalLen;
}
//-----------------------------------------------------------------------------
// unmarshal
//-----------------------------------------------------------------------------
void castor::legacymsg::unmarshal(const char * &src, size_t &srcLen,
MessageHeader &dst) {
io::unmarshalUint32(src, srcLen, dst.magic);
io::unmarshalUint32(src, srcLen, dst.reqType);
io::unmarshalUint32(src, srcLen, dst.lenOrStatus);
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/legacymsg/GenericErrorReplyMsgBody.hpp"
#include <string.h>
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
castor::legacymsg::GenericErrorReplyMsgBody::GenericErrorReplyMsgBody() throw() {
memset(errorMessage, '\0', sizeof(errorMessage));
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/io/io.hpp"
#include "castor/legacymsg/GenericMarshal.hpp"
#include <string.h>
//-----------------------------------------------------------------------------
// marshal
//-----------------------------------------------------------------------------
size_t castor::legacymsg::marshal(char *const dst, const size_t dstLen,
const uint32_t srcMagic, const uint32_t srcReqType,
const GenericReplyMsgBody &srcBody) {
const char *const task = "marshal GenericReplyMsgBody";
if(dst == NULL) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task <<
": Pointer to destination buffer is NULL";
throw ex;
}
// Calculate the length of the message body
const uint32_t bodyLen =
sizeof(srcBody.status) +
strlen(srcBody.errorMessage) + 1;
// Calculate the total length of the message (header + body)
const uint32_t totalLen =
sizeof(uint32_t) + // magic
sizeof(uint32_t) + // reqType
sizeof(uint32_t) + // len
bodyLen;
// Check that the message buffer is big enough
if(totalLen > dstLen) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task <<
": Buffer too small: required=" << totalLen << " actual=" << dstLen;
throw ex;
}
// Marshal message header
char *p = dst;
try {
io::marshalUint32(srcMagic, p);
io::marshalUint32(srcReqType, p);
io::marshalUint32(bodyLen, p);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task << ": Failed to marshal header: "
<< ne.getMessage().str();
throw ex;
}
// Marshal message body
try {
io::marshalUint32(srcBody.status, p);
io::marshalString(srcBody.errorMessage, p);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task << ": Failed to marshal body: "
<< ne.getMessage().str();
throw ex;
}
// Calculate the number of bytes actually marshalled
const size_t nbBytesMarshalled = p - dst;
// Check that the number of bytes marshalled was what was expected
if(totalLen != nbBytesMarshalled) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task <<
": Mismatch between expected total length and actual"
": expected=" << totalLen << " actual=" << nbBytesMarshalled;
throw ex;
}
return totalLen;
}
//-----------------------------------------------------------------------------
// unmarshal
//-----------------------------------------------------------------------------
void castor::legacymsg::unmarshal(const char * &src, size_t &srcLen,
GenericReplyMsgBody &dst) {
try {
io::unmarshalUint32(src, srcLen, dst.status);
io::unmarshalString(src, srcLen, dst.errorMessage);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to unmarshal GenericReplyMsgBody: " <<
ne.getMessage().str();
throw ex;
}
}
//-----------------------------------------------------------------------------
// marshal
//-----------------------------------------------------------------------------
size_t castor::legacymsg::marshal(char *const dst, const size_t dstLen,
const uint32_t srcMagic, const uint32_t srcReqType,
const GenericErrorReplyMsgBody &srcBody) {
const char *const task = "marshal GenericErrorReplyMsgBody";
if(dst == NULL) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task <<
": Pointer to destination buffer is NULL";
throw ex;
}
// Calculate the length of the message body
const uint32_t bodyLen = strlen(srcBody.errorMessage) + 1;
// Calculate the total length of the message (header + body)
const uint32_t totalLen =
sizeof(uint32_t) + // magic
sizeof(uint32_t) + // reqType
sizeof(uint32_t) + // len
bodyLen;
// Check that the message buffer is big enough
if(totalLen > dstLen) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task <<
": Buffer too small: required=" << totalLen << " actual=" << dstLen;
throw ex;
}
// Marshal message header
char *p = dst;
try {
io::marshalUint32(srcMagic, p);
io::marshalUint32(srcReqType, p);
io::marshalUint32(bodyLen, p);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task << ": Failed to marshal header: "
<< ne.getMessage().str();
throw ex;
}
// Marshal message body
try {
io::marshalString(srcBody.errorMessage, p);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task << ": Failed to marshal body: "
<< ne.getMessage().str();
throw ex;
}
// Calculate the number of bytes actually marshalled
const size_t nbBytesMarshalled = p - dst;
// Check that the number of bytes marshalled was what was expected
if(totalLen != nbBytesMarshalled) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task <<
": Mismatch between expected total length and actual"
": expected=" << totalLen << " actual=" << nbBytesMarshalled;
throw ex;
}
return totalLen;
}
//-----------------------------------------------------------------------------
// unmarshal
//-----------------------------------------------------------------------------
void castor::legacymsg::unmarshal(const char * &src, size_t &srcLen,
GenericErrorReplyMsgBody &dst) {
try {
io::unmarshalString(src, srcLen, dst.errorMessage);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to unmarshal GenericErrorReplyMsgBody: " <<
ne.getMessage().str();
throw ex;
}
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/legacymsg/GenericReplyMsgBody.hpp"
#include <string.h>
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
castor::legacymsg::GenericReplyMsgBody::GenericReplyMsgBody() throw():
status(0) {
memset(errorMessage, '\0', sizeof(errorMessage));
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/legacymsg/GiveOutpMsgBody.hpp"
#include <string.h>
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::legacymsg::GiveOutpMsgBody::GiveOutpMsgBody() throw() {
memset(message, '\0', sizeof(message));
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/legacymsg/MessageHeader.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::legacymsg::MessageHeader::MessageHeader() throw():
magic(0),
reqType(0),
lenOrStatus(0) {
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/io/io.hpp"
#include "castor/legacymsg/RmcMarshal.hpp"
#include "h/rmc_constants.h"
#include <string.h>
//-----------------------------------------------------------------------------
// marshal
//-----------------------------------------------------------------------------
size_t castor::legacymsg::marshal(char *const dst, const size_t dstLen, const RmcMountMsgBody &src) {
const char *task = "marshal RmcMountMsgBody";
if(dst == NULL) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task <<
": Pointer to destination buffer is NULL";
throw ex;
}
// Calculate the length of the message body
const uint32_t bodyLen =
sizeof(src.uid) +
sizeof(src.gid) +
strlen(src.unusedLoader) + 1 +
strlen(src.vid) + 1 +
sizeof(src.side) +
sizeof(src.drvOrd);
// Calculate the total length of the message (header + body)
const uint32_t totalLen =
sizeof(uint32_t) + // magic
sizeof(uint32_t) + // reqType
sizeof(uint32_t) + // len
bodyLen;
// Check that the message buffer is big enough
if(totalLen > dstLen) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task <<
": Buffer too small: required=" << totalLen << " actual=" << dstLen;
throw ex;
}
// Marshal message header
char *p = dst;
try {
const uint32_t magic = RMC_MAGIC;
const uint32_t reqType = RMC_MOUNT;
io::marshalUint32(magic , p);
io::marshalUint32(reqType, p);
io::marshalUint32(totalLen, p);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task << ": Failed to marshal header: "
<< ne.getMessage().str();
throw ex;
}
// Marshal message body
try {
io::marshalUint32(src.uid, p);
io::marshalUint32(src.gid, p);
io::marshalString(src.unusedLoader, p);
io::marshalString(src.vid, p);
io::marshalUint16(src.side, p);
io::marshalUint16(src.drvOrd, p);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task << ": Failed to marshal body: "
<< ne.getMessage().str();
throw ex;
}
// Calculate the number of bytes actually marshalled
const size_t nbBytesMarshalled = p - dst;
// Check that the number of bytes marshalled was what was expected
if(totalLen != nbBytesMarshalled) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to " << task <<
": Mismatch between expected total length and actual"
": expected=" << totalLen << " actual=" << nbBytesMarshalled;
throw ex;
}
return totalLen;
}
//-----------------------------------------------------------------------------
// unmarshal
//-----------------------------------------------------------------------------
void castor::legacymsg::unmarshal(const char * &src, size_t &srcLen, RmcMountMsgBody &dst) {
try {
io::unmarshalUint32(src, srcLen, dst.uid);
io::unmarshalUint32(src, srcLen, dst.gid);
io::unmarshalString(src, srcLen, dst.unusedLoader);
io::unmarshalString(src, srcLen, dst.vid);
io::unmarshalUint16(src, srcLen, dst.side);
io::unmarshalUint16(src, srcLen, dst.drvOrd);