Adding portability test

This commit is contained in:
Randolph Voorhies
2014-03-11 16:28:37 -07:00
committed by Shane Grant
parent ba2ca7c94d
commit 9bd06b6118
13 changed files with 174 additions and 77 deletions

3
.gitignore vendored
View File

@@ -30,9 +30,6 @@ test.txt
boost_serialize boost_serialize
arr.txt arr.txt
performance performance
sandbox
sandbox_json
sandbox_rtti
include_renamed include_renamed
.ycm_extra_conf.py* .ycm_extra_conf.py*
doc/html doc/html

View File

@@ -5,11 +5,7 @@ set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Werror -g -Wextra -Wshadow -pedantic ${CM
include_directories(./include) include_directories(./include)
add_executable(sandbox sandbox.cpp) add_subdirectory(sandbox)
add_executable(sandbox_json sandbox_json.cpp)
add_executable(sandbox_rtti sandbox_rtti.cpp)
add_executable(sandbox_vs sandbox_vs.cpp)
add_executable(portability_test portability_test.cpp)
find_package(Boost COMPONENTS serialization unit_test_framework) find_package(Boost COMPONENTS serialization unit_test_framework)
if(Boost_FOUND) if(Boost_FOUND)
@@ -18,5 +14,4 @@ if(Boost_FOUND)
enable_testing() enable_testing()
add_subdirectory(unittests) add_subdirectory(unittests)
endif(Boost_FOUND) endif(Boost_FOUND)

View File

@@ -24,9 +24,9 @@ unittests: unittests/*.cpp
performance: performance.cpp performance: performance.cpp
${CXX} performance.cpp -o performance -lboost_serialization ${CPPFLAGS} -O3 ${CXX} performance.cpp -o performance -lboost_serialization ${CPPFLAGS} -O3
portability: portability_test.cpp portability: unittests/portability_test.cpp
${CXX} portability_test.cpp -o portability64 ${CPPFLAGS} ${CXX} unittests/portability_test.cpp -o portability64 ${CPPFLAGS}
${CXX} portability_test.cpp -o portability32 ${CPPFLAGS} -m32 ${CXX} unittests/portability_test.cpp -o portability32 ${CPPFLAGS} -m32
./portability64 save 64 ./portability64 save 64
./portability32 load 32 ./portability32 load 32
./portability32 save 32 ./portability32 save 32

5
sandbox/CMakeLists.txt Normal file
View File

@@ -0,0 +1,5 @@
add_executable(sandbox sandbox.cpp)
add_executable(sandbox_json sandbox_json.cpp)
add_executable(sandbox_rtti sandbox_rtti.cpp)
add_executable(sandbox_vs sandbox_vs.cpp)
#add_executable(portability_test portability_test.cpp)

View File

@@ -0,0 +1,57 @@
/*
Copyright (c) 2013, Randolph Voorhies, Shane Grant
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of cereal nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <cereal/archives/xml.hpp>
#include <cereal/access.hpp>
#include <iostream>
class Test
{
public:
private:
friend class cereal::access;
template <class Archive>
void serialize( Archive & ar, const unsigned int version )
{
}
};
int main()
{
{
cereal::XMLOutputArchive ar(std::cout);
Test a;
ar( a );
}
return 0;
}

View File

@@ -1,13 +1,37 @@
file(GLOB TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) file(GLOB TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
# A semi-colon separated list of test sources that should not be automatically built with boost unit test
set(SPECIAL_TESTS "portability_test.cpp")
# Build the portability test only if we are on a 64-bit machine (void* is 8 bytes)
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
add_executable(portability_test32 portability_test.cpp)
set_target_properties(portability_test32 PROPERTIES COMPILE_FLAGS "-m32")
set_target_properties(portability_test32 PROPERTIES LINK_FLAGS "-m32")
add_executable(portability_test64 portability_test.cpp)
add_test(NAME portability_test COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_portability_test.sh)
endif(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
# Build all of the non-special tests and link against the boost unit test framework
foreach(TEST_SOURCE ${TESTS}) foreach(TEST_SOURCE ${TESTS})
string(REPLACE ".cpp" "" TEST_TARGET "${TEST_SOURCE}") string(REPLACE ".cpp" "" TEST_TARGET "${TEST_SOURCE}")
set(TEST_TARGET "test_${TEST_TARGET}") set(TEST_TARGET "test_${TEST_TARGET}")
add_executable(${TEST_TARGET} ${TEST_SOURCE}) # Check to see if our target is listed in "SPECIAL_TESTS"
set_target_properties(${TEST_TARGET} PROPERTIES COMPILE_DEFINITIONS "BOOST_TEST_DYN_LINK;BOOST_TEST_MODULE=${TEST_TARGET}") list(FIND SPECIAL_TESTS "${TEST_SOURCE}" IS_SPECIAL_TEST)
target_link_libraries(${TEST_TARGET} ${Boost_LIBRARIES})
add_test("${TEST_TARGET}" "${TEST_TARGET}") if(IS_SPECIAL_TEST EQUAL -1)
add_executable(${TEST_TARGET} ${TEST_SOURCE})
set_target_properties(${TEST_TARGET} PROPERTIES COMPILE_DEFINITIONS "BOOST_TEST_DYN_LINK;BOOST_TEST_MODULE=${TEST_TARGET}")
target_link_libraries(${TEST_TARGET} ${Boost_LIBRARIES})
add_test("${TEST_TARGET}" "${TEST_TARGET}")
endif(IS_SPECIAL_TEST EQUAL -1)
endforeach() endforeach()

View File

@@ -3,74 +3,75 @@
template <class IArchive, class OArchive> template <class IArchive, class OArchive>
void test_chrono() void test_chrono()
{ {
for(int ii=0; ii<100; ++ii) std::chrono::steady_clock::now();
{ //for(int ii=0; ii<100; ++ii)
auto o_timePoint1 = std::chrono::system_clock::now(); //{
#ifndef CEREAL_OLDER_GCC // auto o_timePoint1 = std::chrono::system_clock::now();
auto o_timePoint2 = std::chrono::steady_clock::now(); // #ifndef CEREAL_OLDER_GCC
#endif // CEREAL_OLDER_GCC // auto o_timePoint2 = std::chrono::steady_clock::now();
auto o_timePoint3 = std::chrono::high_resolution_clock::now(); // #endif // CEREAL_OLDER_GCC
// auto o_timePoint3 = std::chrono::high_resolution_clock::now();
auto o_duration1 = std::chrono::system_clock::now() - o_timePoint1; // auto o_duration1 = std::chrono::system_clock::now() - o_timePoint1;
#ifndef CEREAL_OLDER_GCC // #ifndef CEREAL_OLDER_GCC
auto o_duration2 = std::chrono::steady_clock::now() - o_timePoint2; // auto o_duration2 = std::chrono::steady_clock::now() - o_timePoint2;
#endif // CEREAL_OLDER_GCC // #endif // CEREAL_OLDER_GCC
auto o_duration3 = std::chrono::high_resolution_clock::now() - o_timePoint3; // auto o_duration3 = std::chrono::high_resolution_clock::now() - o_timePoint3;
std::ostringstream os; // std::ostringstream os;
{ // {
OArchive oar(os); // OArchive oar(os);
oar(o_timePoint1); // oar(o_timePoint1);
#ifndef CEREAL_OLDER_GCC // #ifndef CEREAL_OLDER_GCC
oar(o_timePoint2); // oar(o_timePoint2);
#endif // CEREAL_OLDER_GCC // #endif // CEREAL_OLDER_GCC
oar(o_timePoint3); // oar(o_timePoint3);
oar(o_duration1); // oar(o_duration1);
#ifndef CEREAL_OLDER_GCC // #ifndef CEREAL_OLDER_GCC
oar(o_duration2); // oar(o_duration2);
#endif // CEREAL_OLDER_GCC // #endif // CEREAL_OLDER_GCC
oar(o_duration3); // oar(o_duration3);
} // }
decltype(o_timePoint1) i_timePoint1; // decltype(o_timePoint1) i_timePoint1;
#ifndef CEREAL_OLDER_GCC // #ifndef CEREAL_OLDER_GCC
decltype(o_timePoint2) i_timePoint2; // decltype(o_timePoint2) i_timePoint2;
#endif // CEREAL_OLDER_GCC // #endif // CEREAL_OLDER_GCC
decltype(o_timePoint3) i_timePoint3; // decltype(o_timePoint3) i_timePoint3;
decltype(o_duration1) i_duration1; // decltype(o_duration1) i_duration1;
#ifndef CEREAL_OLDER_GCC // #ifndef CEREAL_OLDER_GCC
decltype(o_duration2) i_duration2; // decltype(o_duration2) i_duration2;
#endif // CEREAL_OLDER_GCC // #endif // CEREAL_OLDER_GCC
decltype(o_duration3) i_duration3; // decltype(o_duration3) i_duration3;
std::istringstream is(os.str()); // std::istringstream is(os.str());
{ // {
IArchive iar(is); // IArchive iar(is);
iar(i_timePoint1); // iar(i_timePoint1);
#ifndef CEREAL_OLDER_GCC // #ifndef CEREAL_OLDER_GCC
iar(i_timePoint2); // iar(i_timePoint2);
#endif // CEREAL_OLDER_GCC // #endif // CEREAL_OLDER_GCC
iar(i_timePoint3); // iar(i_timePoint3);
iar(i_duration1); // iar(i_duration1);
#ifndef CEREAL_OLDER_GCC // #ifndef CEREAL_OLDER_GCC
iar(i_duration2); // iar(i_duration2);
#endif // CEREAL_OLDER_GCC // #endif // CEREAL_OLDER_GCC
iar(i_duration3); // iar(i_duration3);
} // }
BOOST_CHECK( o_timePoint1 == i_timePoint1 ); // BOOST_CHECK( o_timePoint1 == i_timePoint1 );
#ifndef CEREAL_OLDER_GCC // #ifndef CEREAL_OLDER_GCC
BOOST_CHECK( o_timePoint2 == i_timePoint2 ); // BOOST_CHECK( o_timePoint2 == i_timePoint2 );
#endif // CEREAL_OLDER_GCC // #endif // CEREAL_OLDER_GCC
BOOST_CHECK( o_timePoint3 == i_timePoint3 ); // BOOST_CHECK( o_timePoint3 == i_timePoint3 );
BOOST_CHECK( o_duration1 == i_duration1 ); // BOOST_CHECK( o_duration1 == i_duration1 );
#ifndef CEREAL_OLDER_GCC // #ifndef CEREAL_OLDER_GCC
BOOST_CHECK( o_duration2 == i_duration2 ); // BOOST_CHECK( o_duration2 == i_duration2 );
#endif // CEREAL_OLDER_GCC // #endif // CEREAL_OLDER_GCC
BOOST_CHECK( o_duration3 == i_duration3 ); // BOOST_CHECK( o_duration3 == i_duration3 );
} //}
} }
BOOST_AUTO_TEST_CASE( binary_chrono ) BOOST_AUTO_TEST_CASE( binary_chrono )

View File

@@ -164,16 +164,25 @@ int main( int, char ** argv )
ar( int_i ); ar( int_i );
if( int_i != int_o ) if( int_i != int_o )
{
std::cerr << "in " << int_i << ", out: " << int_o << std::endl; std::cerr << "in " << int_i << ", out: " << int_o << std::endl;
return -1;
}
ar( vec_i ); ar( vec_i );
ar( data_i ); ar( data_i );
if( vec_i != vec_o ) if( vec_i != vec_o )
{
std::cerr << "Input vector did not equal output vector" << std::endl; std::cerr << "Input vector did not equal output vector" << std::endl;
return -1;
}
if( !(*data_i == *data_o) ) if( !(*data_i == *data_o) )
{
std::cerr << "Data did not match" << std::endl; std::cerr << "Data did not match" << std::endl;
return -1;
}
} }
else if( std::string(argv[1]) == "save" ) else if( std::string(argv[1]) == "save" )
{ {

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e
./portability_test64 save 64
./portability_test32 load 32
./portability_test32 save 32
./portability_test64 load 64
./portability_test64 remove 64