Commit 8eced75e authored by Eric Cano's avatar Eric Cano
Browse files

Initial project strucure: building rpm, validated by unit test.

parent f2768dac
# ----------------------------------------------------------------------
# File: CMakeLists.txt
# Author: Eric Cano - CERN
# ----------------------------------------------------------------------
# ************************************************************************
# * Tape Server *
# * Copyright (C) 2013 CERN/Switzerland *
# * *
# * 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 3 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, see <http://www.gnu.org/licenses/>.*
# ************************************************************************
##########################################################################
# Version Definition
##########################################################################
set(VERSION_MAJOR "0" )
set(VERSION_MINOR "0")
set(VERSION_PATCH "0")
set(VERSION_TWEAK "1")
###########################################################################
# In source build forbidding
###########################################################################
cmake_minimum_required (VERSION 2.6)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
###########################################################################
# project definition section
###########################################################################
project (CERN_Tape)
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
###########################################################################
# dependancies
###########################################################################
find_package(GTest REQUIRED)
enable_testing()
set(CTEST_OUTPUT_ON_FAILURE 1)
###########################################################################
# main part
###########################################################################
# Add parts first in dependency order
add_subdirectory(SCSI)
add_subdirectory(Drive)
# .. and then tools, tests, and daemon
# add_subdirectory(tools)
# add_subdirectory(deamon)
# .. and of course, the tests
add_subdirectory(test)
###########################################################################
# documentation
###########################################################################
# add a target to generate API documentation with Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)
\ No newline at end of file
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = "@CMAKE_PROJECT_NAME@"
PROJECT_NUMBER = "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@-@VERSION_TWEAK@"
OUTPUT_DIRECTORY = dox
CREATE_SUBDIRS = NO
INPUT = @CMAKE_SOURCE_DIR@/disk_transfer @CMAKE_SOURCE_DIR@/main @CMAKE_SOURCE_DIR@/bandwidth_simulation
CLASS_GRAPH = YES
HAVE_DOT = YES
CALL_GRAPH = YES
CALLER_GRAPH = YES
EXTRACT_ALL = YES
EXTRACT_STATIC = YES
EXTRACT_PRIVATE = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = YES
WARN_FORMAT = $file:$line: $text
WARN_LOGFILE =
GRAPHICAL_HIERARCHY = YES
UML_LOOK = YES
#USE_MATHJAX = NO
add_library(TapeDrive Drive.cc)
// ----------------------------------------------------------------------
// File: Drive.hh
// Author: Eric Cano - CERN
// ----------------------------------------------------------------------
/************************************************************************
* Tape Server *
* Copyright (C) 2013 CERN/Switzerland *
* *
* 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 3 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, see <http://www.gnu.org/licenses/>.*
************************************************************************/
/**
* @file Drive.hh
*
* @brief SCSI tape drive abstraction class definition.
*
*
*/
/**
* @brief
*/
// ----------------------------------------------------------------------
// File: Drive/DriveList.hh
// Author: Eric Cano - CERN
// ----------------------------------------------------------------------
/************************************************************************
* Tape Server *
* Copyright (C) 2013 CERN/Switzerland *
* *
* 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 3 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, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#include <vector>
namespace Tape{
/**
* Contains data about a tape drive
*/
struct DriveInfo: public SCSI::Device {
};
/**
* Detects the present tape drives on the system and gathers the basic
* information about them.
*/
class DriveList {
public:
DriveList();
virtual ~DriveList();
private:
listScsi();
std::vector<DriveInfo> m_
};
}; // namespace Tape
\ No newline at end of file
add_library(SCSI Device.cc)
\ No newline at end of file
// ----------------------------------------------------------------------
// File: SCSI/Device.cc
// Author: Eric Cano - CERN
// ----------------------------------------------------------------------
/************************************************************************
* Tape Server *
* Copyright (C) 2013 CERN/Switzerland *
* *
* 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 3 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, see <http://www.gnu.org/licenses/>.*
************************************************************************/
// ----------------------------------------------------------------------
// File: SCSI/Device.hh
// Author: Eric Cano - CERN
// ----------------------------------------------------------------------
/************************************************************************
* Tape Server *
* Copyright (C) 2013 CERN/Switzerland *
* *
* 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 3 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, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#include <string>
#include <vector>
#include <sys/types.h>
#include <dirent.h>
namespace SCSI {
/**
* Bare-bones representation of a SCSI device
*/
struct Device {
std::string sg_path;
};
/**
* Automatic lister of the system's SCSI devices
*/
template<class sysWrapperClass>
class DeviceList : public std::vector<Device> {
public:
/**
* Fill up the array that the device list is with all the system's
* SCSI devices information.
*
* (all code using templates must be in the header file)
*/
DeviceList(sysWrapperClass & sysWrapper) {
std::string sysDevsPath = "/sys/bus/scsi/devices";
DIR* dirp = sysWrapper.opendir(sysDevsPath.c_str());
if (!dirp) return; /* TODO: throw exception? */
while (struct dirent * dent = sysWrapper.readdir(dirp)) {
struct Device dev;
dev.sg_path = sysDevsPath + "/" + dent->d_name;
}
sysWrapper.closedir(dirp);
}
};
};
// ----------------------------------------------------------------------
// File: SCSI/DeviceTest.cc
// Author: Eric Cano - CERN
// ----------------------------------------------------------------------
/************************************************************************
* Tape Server *
* Copyright (C) 2013 CERN/Switzerland *
* *
* 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 3 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, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#include <gtest/gtest.h>
#include <gmock/gmock-cardinalities.h>
#include "Device.hh"
#include "../system/Wrapper.hh"
using ::testing::AtLeast;
using ::testing::Return;
using ::testing::_;
TEST(DeviceList, TriesToFind) {
Tape::System::mockWrapper sysWrapper;
/* Give minimal service output from mock system calls:
* at least pretend there is a directory to scan */
/* _ means anything goes */
EXPECT_CALL(sysWrapper, opendir(_)).Times(1);
EXPECT_CALL(sysWrapper, readdir(sysWrapper.m_DIR)).Times(1);
EXPECT_CALL(sysWrapper, closedir(sysWrapper.m_DIR)).Times(1);
SCSI::DeviceList<Tape::System::mockWrapper> dl(sysWrapper);
}
# Locate the Google C++ Testing Framework.
#
# Defines the following variables:
#
# GTEST_FOUND - Found the Google Testing framework
# GTEST_INCLUDE_DIRS - Include directories
#
# Also defines the library variables below as normal
# variables. These contain debug/optimized keywords when
# a debugging library is found.
#
# GTEST_BOTH_LIBRARIES - Both libgtest & libgtest-main
# GTEST_LIBRARIES - libgtest
# GTEST_MAIN_LIBRARIES - libgtest-main
#
# Accepts the following variables as input:
#
# GTEST_ROOT - (as a CMake or environment variable)
# The root directory of the gtest install prefix
#
# GTEST_MSVC_SEARCH - If compiling with MSVC, this variable can be set to
# "MD" or "MT" to enable searching a GTest build tree
# (defaults: "MD")
#
#-----------------------
# Example Usage:
#
# enable_testing()
# find_package(GTest REQUIRED)
# include_directories(${GTEST_INCLUDE_DIRS})
#
# add_executable(foo foo.cc)
# target_link_libraries(foo ${GTEST_BOTH_LIBRARIES})
#
# add_test(AllTestsInFoo foo)
#
#-----------------------
#
# If you would like each Google test to show up in CTest as
# a test you may use the following macro.
# NOTE: It will slow down your tests by running an executable
# for each test and test fixture. You will also have to rerun
# CMake after adding or removing tests or test fixtures.
#
# GTEST_ADD_TESTS(executable extra_args ARGN)
# executable = The path to the test executable
# extra_args = Pass a list of extra arguments to be passed to
# executable enclosed in quotes (or "" for none)
# ARGN = A list of source files to search for tests & test
# fixtures.
#
# Example:
# set(FooTestArgs --foo 1 --bar 2)
# add_executable(FooTest FooUnitTest.cc)
# GTEST_ADD_TESTS(FooTest "${FooTestArgs}" FooUnitTest.cc)
#=============================================================================
# Copyright 2009 Kitware, Inc.
# Copyright 2009 Philip Lowman <philip@yhbt.com>
# Copyright 2009 Daniel Blezek <blezek@gmail.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
#
# Thanks to Daniel Blezek <blezek@gmail.com> for the GTEST_ADD_TESTS code
function(GTEST_ADD_TESTS executable extra_args)
if(NOT ARGN)
message(FATAL_ERROR "Missing ARGN: Read the documentation for GTEST_ADD_TESTS")
endif()
foreach(source ${ARGN})
file(READ "${source}" contents)
string(REGEX MATCHALL "TEST_?F?\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})
foreach(hit ${found_tests})
string(REGEX REPLACE ".*\\( *([A-Za-z_0-9]+), *([A-Za-z_0-9]+) *\\).*" "\\1.\\2" test_name ${hit})
add_test(${test_name} ${executable} --gtest_filter=${test_name} ${extra_args})
endforeach()
endforeach()
endfunction()
function(_gtest_append_debugs _endvar _library)
if(${_library} AND ${_library}_DEBUG)
set(_output optimized ${${_library}} debug ${${_library}_DEBUG})
else()
set(_output ${${_library}})
endif()
set(${_endvar} ${_output} PARENT_SCOPE)
endfunction()
function(_gtest_find_library _name)
find_library(${_name}
NAMES ${ARGN}
HINTS
ENV GTEST_ROOT
${GTEST_ROOT}
PATH_SUFFIXES ${_gtest_libpath_suffixes}
)
mark_as_advanced(${_name})
endfunction()
#
if(NOT DEFINED GTEST_MSVC_SEARCH)
set(GTEST_MSVC_SEARCH MD)
endif()
set(_gtest_libpath_suffixes lib)
if(MSVC)
if(GTEST_MSVC_SEARCH STREQUAL "MD")
list(APPEND _gtest_libpath_suffixes
msvc/gtest-md/Debug
msvc/gtest-md/Release)
elseif(GTEST_MSVC_SEARCH STREQUAL "MT")
list(APPEND _gtest_libpath_suffixes
msvc/gtest/Debug
msvc/gtest/Release)
endif()
endif()
find_path(GTEST_INCLUDE_DIR gtest/gtest.h
HINTS
$ENV{GTEST_ROOT}/include
${GTEST_ROOT}/include
)
mark_as_advanced(GTEST_INCLUDE_DIR)
if(MSVC AND GTEST_MSVC_SEARCH STREQUAL "MD")
# The provided /MD project files for Google Test add -md suffixes to the
# library names.
_gtest_find_library(GTEST_LIBRARY gtest-md gtest)
_gtest_find_library(GTEST_LIBRARY_DEBUG gtest-mdd gtestd)
_gtest_find_library(GTEST_MAIN_LIBRARY gtest_main-md gtest_main)
_gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_main-mdd gtest_maind)
else()
_gtest_find_library(GTEST_LIBRARY gtest)
_gtest_find_library(GTEST_LIBRARY_DEBUG gtestd)
_gtest_find_library(GTEST_MAIN_LIBRARY gtest_main)
_gtest_find_library(GTEST_MAIN_LIBRARY_DEBUG gtest_maind)
endif()
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTest DEFAULT_MSG GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
if(GTEST_FOUND)
set(GTEST_INCLUDE_DIRS ${GTEST_INCLUDE_DIR})
_gtest_append_debugs(GTEST_LIBRARIES GTEST_LIBRARY)
_gtest_append_debugs(GTEST_MAIN_LIBRARIES GTEST_MAIN_LIBRARY)
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
endif()
#!/bin/sh
echo "### INFO ### Creating tarball"
# Extract package related information
specfile=`find . -maxdepth 1 -name '*.spec' -type f`
name=`awk '$1 == "Name:" { print $2 }' ${specfile}`
version=`awk '$1 == "Version:" { print $2 }' ${specfile}`
release=`awk '$1 == "Release:" { print $2 }' ${specfile}`
# Create the distribution tarball
rm -rf ${name}-${version}-${release}
rsync -aC --exclude '.__afs*' --exclude '.svn' --exclude '.git' --exclude '*build*' . ${name}-${version}-${release}
tar -zcf ${name}-${version}-${release}.tar.gz ${name}-${version}-${release}
rm -rf ${name}-${version}-${release}
thisstatus=$?
if [ $thisstatus != 0 ]; then
exit $thisstatus
fi
echo "### INFO ### Creating rpms"
buildtree=`mktemp -d`
mkdir -p ${buildtree}/{RPMS/{i386,i586,i686,x86_64},SPECS,BUILD,SOURCES,SRPMS}
rpmbuild --define "_topdir ${buildtree}" \
-ts -vvv ${name}-${version}-${release}.tar.gz
thisstatus=$?
if [ $thisstatus != 0 ]; then
exit $thisstatus
fi
rpmbuild --define "_topdir ${buildtree}" \
-ta -vvv ${name}-${version}-${release}.tar.gz
thisstatus=$?
find ${buildtree}/{,S}RPMS -type f -name "*.rpm" -exec mv -v {} ./ \;
rm -rf ${buildtree}
rm ${name}-${version}-${release}.tar.gz
exit $thisstatus
// ----------------------------------------------------------------------
// File: System/realWrapper.hh
// Author: Eric Cano - CERN
// ----------------------------------------------------------------------
/************************************************************************
* Tape Server *
* Copyright (C) 2013 CERN/Switzerland *
* *
* 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 3 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, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#include <sys/types.h>
#include <dirent.h>
#include <gmock/gmock.h>
namespace Tape {
namespace System {
/**
* Wrapper class the all system calls used, allowing writing of test harnesses
* for unit testing.
* The member function are purposedly non-virtual, allowing full
* performance with inline member functions.
*/
class realWrapper{
public:
DIR* opendir(const char *name) { return ::opendir(name); }
struct dirent * readdir(DIR* dirp) { return ::readdir(dirp); }
int closedir(DIR* dirp) { return ::closedir(dirp); }
};
/**
* Mock class for system wrapper, used to develop tests.
*/
class mockWrapper {
public:
mockWrapper(): m_DIR((DIR*)&m_DIRfake) {
ON_CALL(*this, opendir(::testing::_))
.WillByDefault(::testing::Return(m_DIR));
}
MOCK_METHOD1(opendir, DIR*(const char *name));
MOCK_METHOD1(readdir, struct dirent*(DIR* dirp));
MOCK_METHOD1(closedir, int(DIR* dirp));
int m_DIRfake;
DIR* m_DIR;
};
} // namespace System
} // namespace Tape
Summary: The CERN tape server project
Name: tape-server
Version: 0.0.0
Release: 1
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
%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
%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=RelWithDebInfo