Commit aa629531 authored by Victor Kotlyar's avatar Victor Kotlyar
Browse files

Moved castor::utils::CRC into cta/common

parent 75bc3be2
...@@ -23,6 +23,8 @@ find_package (libuuid REQUIRED) ...@@ -23,6 +23,8 @@ find_package (libuuid REQUIRED)
add_subdirectory (exception) add_subdirectory (exception)
set_source_files_properties(CRC.cpp PROPERTIES COMPILE_FLAGS -O2)
set (COMMON_LIB_SRC_FILES set (COMMON_LIB_SRC_FILES
dataStructures/AdminHost.cpp dataStructures/AdminHost.cpp
dataStructures/AdminUser.cpp dataStructures/AdminUser.cpp
...@@ -102,6 +104,7 @@ set (COMMON_LIB_SRC_FILES ...@@ -102,6 +104,7 @@ set (COMMON_LIB_SRC_FILES
remoteFS/RemotePath.cpp remoteFS/RemotePath.cpp
remoteFS/RemotePathAndStatus.cpp remoteFS/RemotePathAndStatus.cpp
SmartFd.cpp SmartFd.cpp
CRC.cpp
threading/ChildProcess.cpp threading/ChildProcess.cpp
threading/Daemon.cpp threading/Daemon.cpp
threading/Mutex.cpp threading/Mutex.cpp
...@@ -141,6 +144,7 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES ...@@ -141,6 +144,7 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES
log/StringLoggerTest.cpp log/StringLoggerTest.cpp
remoteFS/RemotePathTest.cpp remoteFS/RemotePathTest.cpp
SmartFdTest.cpp SmartFdTest.cpp
CRCTest.cpp
threading/DaemonTest.cpp threading/DaemonTest.cpp
threading/SocketPairTest.cpp threading/SocketPairTest.cpp
threading/ThreadingBlockingQTests.cpp threading/ThreadingBlockingQTests.cpp
......
/****************************************************************************** /*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
* *
* This file is part of the Castor project. * This program is free software: you can redistribute it and/or modify
* See http://castor.web.cern.ch/castor * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* *
* 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * 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 * You should have received a copy of the GNU General Public License
*****************************************************************************/ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "castor/utils/CRC.hpp" #include "common/CRC.hpp"
#include <stdint.h> #include <stdint.h>
namespace cta {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// crcRS_sw // crcRS_sw
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
uint32_t castor::utils::CRC::crcRS_sw (const uint32_t crcInit, uint32_t crcRS_sw (const uint32_t crcInit,
const uint32_t cnt, const void *const start) { const uint32_t cnt, const void *const start) {
static const uint32_t crcTable[256] = { static const uint32_t crcTable[256] = {
0x00000000, 0x38CF3801, 0x70837002, 0x484C4803, 0xE01BE004, 0xD8D4D805, 0x00000000, 0x38CF3801, 0x70837002, 0x484C4803, 0xE01BE004, 0xD8D4D805,
...@@ -87,7 +86,7 @@ uint32_t castor::utils::CRC::crcRS_sw (const uint32_t crcInit, ...@@ -87,7 +86,7 @@ uint32_t castor::utils::CRC::crcRS_sw (const uint32_t crcInit,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// crc32c_sw // crc32c_sw
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
uint32_t castor::utils::CRC::crc32c_sw (const uint32_t crcInit, uint32_t crc32c_sw (const uint32_t crcInit,
const uint32_t cnt, const void *const start) const uint32_t cnt, const void *const start)
{ {
static const uint32_t crcTable[256] = { static const uint32_t crcTable[256] = {
...@@ -194,7 +193,7 @@ uint32_t crc32c_intel_le_hw_64b(const uint32_t crcInit, ...@@ -194,7 +193,7 @@ uint32_t crc32c_intel_le_hw_64b(const uint32_t crcInit,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// crc32c_hw // crc32c_hw
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
uint32_t castor::utils::CRC::crc32c_hw (const uint32_t crcInit, uint32_t crc32c_hw (const uint32_t crcInit,
const uint32_t cnt, const void *const start) { const uint32_t cnt, const void *const start) {
/* Do CPU 64 instruction */ /* Do CPU 64 instruction */
...@@ -217,7 +216,7 @@ uint32_t castor::utils::CRC::crc32c_hw (const uint32_t crcInit, ...@@ -217,7 +216,7 @@ uint32_t castor::utils::CRC::crc32c_hw (const uint32_t crcInit,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// crc32c // crc32c
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
uint32_t castor::utils::CRC::crc32c(const uint32_t crcInit, const uint32_t cnt, uint32_t crc32c(const uint32_t crcInit, const uint32_t cnt,
const void *const start) { const void *const start) {
int sse42; int sse42;
...@@ -228,7 +227,7 @@ uint32_t castor::utils::CRC::crc32c(const uint32_t crcInit, const uint32_t cnt, ...@@ -228,7 +227,7 @@ uint32_t castor::utils::CRC::crc32c(const uint32_t crcInit, const uint32_t cnt,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// addCrc32cToMemoryBlock // addCrc32cToMemoryBlock
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
uint32_t castor::utils::CRC::addCrc32cToMemoryBlock(const uint32_t crcInit, uint32_t addCrc32cToMemoryBlock(const uint32_t crcInit,
const uint32_t cnt, uint8_t *start ) { const uint32_t cnt, uint8_t *start ) {
if (cnt == 0) if (cnt == 0)
return 0; //no such thing as a zero length block in SSC (write NOP) return 0; //no such thing as a zero length block in SSC (write NOP)
...@@ -245,7 +244,7 @@ uint32_t castor::utils::CRC::addCrc32cToMemoryBlock(const uint32_t crcInit, ...@@ -245,7 +244,7 @@ uint32_t castor::utils::CRC::addCrc32cToMemoryBlock(const uint32_t crcInit,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// verifyCrc32cForMemoryBlockWithCrc32c // verifyCrc32cForMemoryBlockWithCrc32c
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool castor::utils::CRC::verifyCrc32cForMemoryBlockWithCrc32c( bool verifyCrc32cForMemoryBlockWithCrc32c(
const uint32_t crcInit, const uint32_t cnt, const uint8_t *start) { const uint32_t crcInit, const uint32_t cnt, const uint8_t *start) {
if (cnt <= 4) if (cnt <= 4)
return false; //block is too small to be valid, cannot check CRC return false; //block is too small to be valid, cannot check CRC
...@@ -260,3 +259,5 @@ bool castor::utils::CRC::verifyCrc32cForMemoryBlockWithCrc32c( ...@@ -260,3 +259,5 @@ bool castor::utils::CRC::verifyCrc32cForMemoryBlockWithCrc32c(
return false; //block CRC is incorrect return false; //block CRC is incorrect
return true; return true;
} }
} // namespace cta
\ No newline at end of file
/****************************************************************************** /*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
* *
* This file is part of the Castor project. * This program is free software: you can redistribute it and/or modify
* See http://castor.web.cern.ch/castor * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* *
* 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * 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 * You should have received a copy of the GNU General Public License
*****************************************************************************/ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
namespace castor { namespace cta {
namespace utils {
namespace CRC {
/** /**
* Set of CRC functions. * Set of CRC functions.
*/ */
...@@ -130,6 +123,5 @@ uint32_t addCrc32cToMemoryBlock(const uint32_t crcInit, ...@@ -130,6 +123,5 @@ uint32_t addCrc32cToMemoryBlock(const uint32_t crcInit,
bool verifyCrc32cForMemoryBlockWithCrc32c( bool verifyCrc32cForMemoryBlockWithCrc32c(
const uint32_t crcInit, const uint32_t cnt, const uint8_t *start); const uint32_t crcInit, const uint32_t cnt, const uint8_t *start);
} // namespace CRC
} // namespace utils } // namespace cta
} // namespace castor
/****************************************************************************** /*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
* *
* This file is part of the Castor project. * This program is free software: you can redistribute it and/or modify
* See http://castor.web.cern.ch/castor * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* *
* 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * 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.
*
* *
* * You should have received a copy of the GNU General Public License
* @author Castor Dev team, castor-dev@cern.ch * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ */
#include "castor/utils/CRC.hpp" #include "common/CRC.hpp"
#include <gtest/gtest.h> #include <gtest/gtest.h>
...@@ -29,7 +24,7 @@ ...@@ -29,7 +24,7 @@
namespace unitTests { namespace unitTests {
class castor_CRC : public ::testing::Test { class cta_CRC : public ::testing::Test {
protected: protected:
virtual void SetUp() { virtual void SetUp() {
...@@ -39,8 +34,8 @@ protected: ...@@ -39,8 +34,8 @@ protected:
} }
}; };
TEST_F(castor_CRC, testCRCRS_sw) { TEST_F(cta_CRC, testCRCRS_sw) {
using namespace castor::utils::CRC; using namespace cta;
const uint8_t block1[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, const uint8_t block1[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
...@@ -59,8 +54,8 @@ TEST_F(castor_CRC, testCRCRS_sw) { ...@@ -59,8 +54,8 @@ TEST_F(castor_CRC, testCRCRS_sw) {
ASSERT_EQ(computedCRC3, 0x754ED37E); ASSERT_EQ(computedCRC3, 0x754ED37E);
} }
TEST_F(castor_CRC, testCRC32C_sw) { TEST_F(cta_CRC, testCRC32C_sw) {
using namespace castor::utils::CRC; using namespace cta;
const uint8_t block1[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, const uint8_t block1[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
...@@ -78,8 +73,8 @@ TEST_F(castor_CRC, testCRC32C_sw) { ...@@ -78,8 +73,8 @@ TEST_F(castor_CRC, testCRC32C_sw) {
ASSERT_EQ(computedCRC2, 0x56DAB0A6); ASSERT_EQ(computedCRC2, 0x56DAB0A6);
ASSERT_EQ(computedCRC3, 0x56DAB0A6); ASSERT_EQ(computedCRC3, 0x56DAB0A6);
} }
TEST_F(castor_CRC, testCRC32C_hw) { TEST_F(cta_CRC, testCRC32C_hw) {
using namespace castor::utils::CRC; using namespace cta;
/* check if we have SSE4_2 to test hardware CRC32C */ /* check if we have SSE4_2 to test hardware CRC32C */
int sse42; int sse42;
...@@ -103,8 +98,8 @@ TEST_F(castor_CRC, testCRC32C_hw) { ...@@ -103,8 +98,8 @@ TEST_F(castor_CRC, testCRC32C_hw) {
ASSERT_EQ(computedCRC3, 0x56DAB0A6); ASSERT_EQ(computedCRC3, 0x56DAB0A6);
} }
} }
TEST_F(castor_CRC, testCRC32C) { TEST_F(cta_CRC, testCRC32C) {
using namespace castor::utils::CRC; using namespace cta;
const uint8_t block1[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, const uint8_t block1[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "castor/tape/tapeserver/drive/DriveGeneric.hpp" #include "castor/tape/tapeserver/drive/DriveGeneric.hpp"
#include "castor/utils/Timer.hpp" #include "castor/utils/Timer.hpp"
#include "castor/utils/CRC.hpp" #include "common/CRC.hpp"
#include "common/exception/MemException.hpp" #include "common/exception/MemException.hpp"
namespace castor { namespace castor {
...@@ -703,7 +703,7 @@ void drive::DriveGeneric::writeBlock(const void * data, size_t count) { ...@@ -703,7 +703,7 @@ void drive::DriveGeneric::writeBlock(const void * data, size_t count) {
} }
memcpy(dataWithCrc32c, data, count); memcpy(dataWithCrc32c, data, count);
const size_t countWithCrc32c = const size_t countWithCrc32c =
castor::utils::CRC::addCrc32cToMemoryBlock( cta::addCrc32cToMemoryBlock(
SCSI::logicBlockProtectionMethod::CRC32CSeed, SCSI::logicBlockProtectionMethod::CRC32CSeed,
count, dataWithCrc32c); count, dataWithCrc32c);
if (countWithCrc32c != if (countWithCrc32c !=
...@@ -771,7 +771,7 @@ ssize_t drive::DriveGeneric::readBlock(void * data, size_t count) { ...@@ -771,7 +771,7 @@ ssize_t drive::DriveGeneric::readBlock(void * data, size_t count) {
delete[] dataWithCrc32c; delete[] dataWithCrc32c;
throw cta::exception::Exception("In DriveGeneric::readBlock: wrong data block size, checksum cannot fit"); throw cta::exception::Exception("In DriveGeneric::readBlock: wrong data block size, checksum cannot fit");
} }
if (castor::utils::CRC::verifyCrc32cForMemoryBlockWithCrc32c( if (cta::verifyCrc32cForMemoryBlockWithCrc32c(
SCSI::logicBlockProtectionMethod::CRC32CSeed, SCSI::logicBlockProtectionMethod::CRC32CSeed,
res, dataWithCrc32c)) { res, dataWithCrc32c)) {
// everything is fine here do mem copy // everything is fine here do mem copy
...@@ -835,7 +835,7 @@ void drive::DriveGeneric::readExactBlock(void * data, size_t count, std::string ...@@ -835,7 +835,7 @@ void drive::DriveGeneric::readExactBlock(void * data, size_t count, std::string
delete[] dataWithCrc32c; delete[] dataWithCrc32c;
throw UnexpectedSize(context); throw UnexpectedSize(context);
} }
if (castor::utils::CRC::verifyCrc32cForMemoryBlockWithCrc32c( if (cta::verifyCrc32cForMemoryBlockWithCrc32c(
SCSI::logicBlockProtectionMethod::CRC32CSeed, SCSI::logicBlockProtectionMethod::CRC32CSeed,
res, dataWithCrc32c)) { res, dataWithCrc32c)) {
// everything is fine here do mem copy // everything is fine here do mem copy
......
...@@ -22,11 +22,9 @@ cmake_minimum_required (VERSION 2.6) ...@@ -22,11 +22,9 @@ cmake_minimum_required (VERSION 2.6)
include_directories(/usr/include/shift) include_directories(/usr/include/shift)
include_directories(${PROJECT_SOURCE_DIR}/tapeserver) include_directories(${PROJECT_SOURCE_DIR}/tapeserver)
set_source_files_properties(CRC.cpp PROPERTIES COMPILE_FLAGS -O2)
set (UTILS_LIB_SRC_FILES set (UTILS_LIB_SRC_FILES
SmartFILEPtr.cpp SmartFILEPtr.cpp
Timer.cpp Timer.cpp
CRC.cpp
utils.cpp utils.cpp
../common/CastorConfiguration.cpp ../common/CastorConfiguration.cpp
../System.cpp ../System.cpp
......
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