diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..076ff75a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,236 @@ +# +# Copyright 2018, Intel Corporation +# +# 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 the copyright holder 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 THE COPYRIGHT +# OWNER OR CONTRIBUTORS 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. + +cmake_minimum_required(VERSION 3.3) +project(pmdk-convert C) + +set(VERSION_MAJOR 1) +set(VERSION_MINOR 5) +set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}) + +set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}) + +include(FindThreads) + +set(MAX_VERSION 1.5) + +STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+" "\\1" MIN_VERSION_MAJOR "${MIN_VERSION}") +STRING(REGEX REPLACE "^[0-9]+\\.([0-9]+)" "\\1" MIN_VERSION_MINOR "${MIN_VERSION}") + +STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+" "\\1" MAX_VERSION_MAJOR "${MAX_VERSION}") +STRING(REGEX REPLACE "^[0-9]+\\.([0-9]+)" "\\1" MAX_VERSION_MINOR "${MAX_VERSION}") + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "RelWithDebInfo") +endif (NOT CMAKE_BUILD_TYPE) + +include(CheckCCompilerFlag) +include(GNUInstallDirs) +if(NOT MSVC) + find_package(PkgConfig QUIET) +endif() + +set(CMAKE_C_STANDARD 99) + +# Checks whether flag is supported by current C compiler and appends +# it to the relevant cmake variable. +# 1st argument is a flag +# 2nd (optional) argument is a build type (debug, release, relwithdebinfo) +macro(add_c_flag flag) + string(REPLACE - _ flag2 ${flag}) + string(REPLACE " " _ flag2 ${flag2}) + string(REPLACE = "_" flag2 ${flag2}) + set(check_name "C_HAS_${flag2}") + + check_c_compiler_flag("${flag}" "${check_name}") + + if (${${check_name}}) + if (${ARGC} EQUAL 1) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}") + else() + set(CMAKE_C_FLAGS_${ARGV1} "${CMAKE_C_FLAGS_${ARGV1}} ${flag}") + endif() + endif() +endmacro() + +if(NOT MSVC) + add_c_flag(-fno-common) + add_c_flag(-Wall) + add_c_flag(-Wconversion) + add_c_flag(-Wmissing-field-initializers) + add_c_flag(-Wmissing-prototypes) + add_c_flag(-Wmissing-variable-declarations) + add_c_flag(-Wpointer-arith) + add_c_flag(-Wsign-compare) + add_c_flag(-Wsign-conversion) + add_c_flag(-Wunused-macros) + add_c_flag(-Wunreachable-code-return) + + # Place each function or data item into its own section. Will be used to strip unneeded symbols. + add_c_flag(-fdata-sections) + add_c_flag(-ffunction-sections) + + add_c_flag(-ggdb DEBUG) + add_c_flag(-DDEBUG DEBUG) + + add_c_flag(-ggdb RELWITHDEBINFO) + add_c_flag(-fno-omit-frame-pointer RELWITHDEBINFO) + + check_c_compiler_flag(-Wl,-z,relro LINKER_HAS_RELRO) + if(LINKER_HAS_RELRO) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro") + endif() + + check_c_compiler_flag(-Wl,--warn-common LINKER_HAS_WARN_COMMON) + if(LINKER_HAS_WARN_COMMON) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--warn-common") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--warn-common") + endif() + + add_c_flag("-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" RELEASE) +endif() + +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) + +# add_executable(check_license EXCLUDE_FROM_ALL utils/check_license/check-license.c) + +# function(add_cstyle name) +# if(${ARGC} EQUAL 1) +# add_custom_target(cstyle-${name} +# COMMAND ${PERL_EXECUTABLE} +# ${CMAKE_SOURCE_DIR}/utils/cstyle +# ${CMAKE_CURRENT_SOURCE_DIR}/*.c +# ${CMAKE_CURRENT_SOURCE_DIR}/*.h) +# else() +# add_custom_target(cstyle-${name} +# COMMAND ${PERL_EXECUTABLE} +# ${CMAKE_SOURCE_DIR}/utils/cstyle ${ARGN}) +# endif() +# add_dependencies(cstyle cstyle-${name}) +# endfunction() + +# Generates check-whitespace-$name target and attaches it as a dependency +# of global "check-whitespace" target. This target verifies C files in current +# source dir do not have any whitespace errors. +# If more arguments are used, then they are used as files to be checked +# instead. +# ${name} must be unique. + +# function(add_check_whitespace name) +# if(${ARGC} EQUAL 1) +# add_custom_target(check-whitespace-${name} +# COMMAND ${PERL_EXECUTABLE} +# ${CMAKE_SOURCE_DIR}/utils/check_whitespace +# ${CMAKE_CURRENT_SOURCE_DIR}/*.c +# ${CMAKE_CURRENT_SOURCE_DIR}/*.h) +# else() +# add_custom_target(check-whitespace-${name} +# COMMAND ${PERL_EXECUTABLE} +# ${CMAKE_SOURCE_DIR}/utils/check_whitespace ${ARGN}) +# endif() +# add_dependencies(check-whitespace check-whitespace-${name}) +# endfunction() + +# add_custom_target(checkers ALL) +# add_custom_target(cstyle) +# add_custom_target(check-whitespace) +# add_custom_target(check-license +# COMMAND ${CMAKE_SOURCE_DIR}/utils/check_license/check-headers.sh +# ${CMAKE_SOURCE_DIR} +# ${CMAKE_BINARY_DIR}/check_license +# ${CMAKE_SOURCE_DIR}/LICENSE +# -a) + +#add_custom_target(md2man +# COMMAND ${CMAKE_SOURCE_DIR}/utils/md2man/md2man.sh +# ${CMAKE_SOURCE_DIR}/doc/pmdk-convert/pmdk-convert.1.md +# ${CMAKE_SOURCE_DIR}/utils/md2man/default.man +# ${CMAKE_SOURCE_DIR}/doc/generated/pmdk-convert.1 +# ) + +#if (NOT WIN32) +# install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/doc/generated/pmdk-convert.1 +# DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) +#endif() + +# add_dependencies(check-license check_license) + +#add_cstyle(main) +#add_cstyle(check_license ${CMAKE_SOURCE_DIR}/utils/check_license/*.c) + +#add_check_whitespace(check_license ${CMAKE_SOURCE_DIR}/utils/check_license/*.c) +#add_check_whitespace(src) +#add_check_whitespace(other +# ${CMAKE_SOURCE_DIR}/utils/check_license/*.sh +# ${CMAKE_SOURCE_DIR}/README.md + # ${CMAKE_SOURCE_DIR}/utils/*.sh + # ${CMAKE_SOURCE_DIR}/*.spec + # ${CMAKE_SOURCE_DIR}/debian/* + # ${CMAKE_SOURCE_DIR}/debian/*/* + # ${CMAKE_SOURCE_DIR}/doc/*.md +# ) + +option(DEVELOPER_MODE "enable developer checks" OFF) +if(DEVELOPER_MODE) +# add_dependencies(checkers cstyle) +# add_dependencies(checkers check-whitespace) +# add_dependencies(checkers check-license) +endif(DEVELOPER_MODE) + +set(SOURCES main.c) + +add_library(vmemcache SHARED ${SOURCES}) +target_link_libraries(vmemcache PRIVATE -Wl,--version-script=${CMAKE_SOURCE_DIR}/libvmemcache.map) + +target_compile_definitions(vmemcache PRIVATE SRCVERSION="${NVML15}") + +install(TARGETS vmemcache + DESTINATION ${CMAKE_INSTALL_LIBDIR}/) + + + + option(TRACE_TESTS + "more verbose test outputs" OFF) + enable_testing() + add_subdirectory(tests) + +if(NOT "${CPACK_GENERATOR}" STREQUAL "") + include(${CMAKE_SOURCE_DIR}/packages.cmake) +endif() diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in new file mode 100644 index 00000000..9dd59db7 --- /dev/null +++ b/cmake_uninstall.cmake.in @@ -0,0 +1,22 @@ +# From: https://cmake.org/Wiki/CMake_FAQ + +if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") +endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling $ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + exec_program("@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif(NOT "${rm_retval}" STREQUAL 0) + else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) diff --git a/libvmemcache.map b/libvmemcache.map new file mode 100644 index 00000000..8ef11f77 --- /dev/null +++ b/libvmemcache.map @@ -0,0 +1,38 @@ +# +# Copyright 2018, Intel Corporation +# +# 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 the copyright holder 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 THE COPYRIGHT +# OWNER OR CONTRIBUTORS 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. +# + +{ + global: + function; + local: + *; +}; diff --git a/main.c b/main.c new file mode 100644 index 00000000..3724d05f --- /dev/null +++ b/main.c @@ -0,0 +1,41 @@ +/* + * Copyright 2018, Intel Corporation + * + * 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 the copyright holder 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 THE COPYRIGHT + * OWNER OR CONTRIBUTORS 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. + */ + +/* an example library */ +#include +#include "main.h" + +int function() +{ + printf("hello world\n)"); + return 0; +} diff --git a/main.h b/main.h new file mode 100644 index 00000000..d79f0358 --- /dev/null +++ b/main.h @@ -0,0 +1,34 @@ +/* + * Copyright 2018, Intel Corporation + * + * 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 the copyright holder 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 THE COPYRIGHT + * OWNER OR CONTRIBUTORS 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. + */ + +/* an example library */ +int function(void); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..d0262cc2 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,87 @@ +# +# Copyright 2018, Intel Corporation +# +# 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 the copyright holder 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 THE COPYRIGHT +# OWNER OR CONTRIBUTORS 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. + +set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/test + CACHE STRING "working directory for tests") + +option(TESTS_USE_FORCED_PMEM "let tests force enable or force disable use of optimized flush in libpmemobj (to speed them up)" OFF) + +set(DEVICE_DAX_PATHS "" CACHE STRING + "for tests that require raw dax devices without a file system. Some tests might require two DAX devices. + Example: '/dev/dax1.0 /dev/dax2.0'") + +set(GLOBAL_TEST_ARGS + -DPARENT_DIR=${TEST_DIR}/ + -DTESTS_USE_FORCED_PMEM=${TESTS_USE_FORCED_PMEM} + -DDEVICE_DAX_PATHS=${DEVICE_DAX_PATHS}) + +# convert the DEVICE_DAX_PATHS list to the array +if(DEVICE_DAX_PATHS) + string(REPLACE " " ";" DEVICE_DAX_PATHS ${DEVICE_DAX_PATHS}) +endif() + +list(LENGTH DEVICE_DAX_PATHS devdax_num) + +if(TRACE_TESTS) + set(GLOBAL_TEST_ARGS ${GLOBAL_TEST_ARGS} --trace-expand) +endif() + +# Configures test ${name} +function(test name file) + add_test(NAME ${name} + COMMAND ${CMAKE_COMMAND} + ${GLOBAL_TEST_ARGS} + -DTEST_NAME=${name} + -DSRC_DIR=${CMAKE_CURRENT_SOURCE_DIR} + -DBIN_DIR=${CMAKE_CURRENT_BINARY_DIR}/${file} + -DVERSIONS=${VERSIONS} + -DCONFIG=$ + -P ${CMAKE_CURRENT_SOURCE_DIR}/${file}.cmake) + + set_tests_properties(${name} PROPERTIES + ENVIRONMENT "LC_ALL=C;PATH=$ENV{PATH}") +endfunction() + +macro(require_libpmempool ver) + if(PKG_CONFIG_FOUND) + pkg_check_modules(LIBPMEMPOOL REQUIRED libpmempool>=${ver}) + else() + find_package(LIBPMEMPOOL REQUIRED) + endif() + link_directories(${LIBPMEMPOOL_LIBRARY_DIRS}) +endmacro() + + +add_executable(example_test test.c) +target_include_directories(example_test PRIVATE ${CMAKE_SOURCE_DIR}) +target_link_libraries(example_test PRIVATE vmemcache) + +test("example" example) diff --git a/tests/example.cmake b/tests/example.cmake new file mode 100644 index 00000000..8e65b478 --- /dev/null +++ b/tests/example.cmake @@ -0,0 +1,38 @@ +# +# Copyright 2018, Intel Corporation +# +# 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 the copyright holder 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 THE COPYRIGHT +# OWNER OR CONTRIBUTORS 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(${SRC_DIR}/helpers.cmake) + +setup() + +execute(0 ${TEST_DIR}/example_test) + +cleanup() diff --git a/tests/helpers.cmake b/tests/helpers.cmake new file mode 100644 index 00000000..f2309cb0 --- /dev/null +++ b/tests/helpers.cmake @@ -0,0 +1,92 @@ +# +# Copyright 2017-2018, Intel Corporation +# +# 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 the copyright holder 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 THE COPYRIGHT +# OWNER OR CONTRIBUTORS 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. + +cmake_minimum_required(VERSION 3.3) +set(DIR ${PARENT_DIR}/😘⠝⠧⠍⠇ɗPMDKӜ⥺🙋${TEST_NAME}) + +if (WIN32) + set(EXE_DIR ${CMAKE_CURRENT_BINARY_DIR}/../${CONFIG}) + set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/../tests/${CONFIG}) +else() + set(EXE_DIR ${CMAKE_CURRENT_BINARY_DIR}/../) + set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/../tests/) +endif() + +function(setup) + execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIR}) + execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}) + execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${BIN_DIR}) + execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BIN_DIR}) +endfunction() + +function(cleanup) + execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIR}) +endfunction() + +# Executes test command ${name} and verifies its status matches ${expectation}. +# Optional function arguments are passed as consecutive arguments to +# the command. +function(execute_arg input expectation name) + if(TESTS_USE_FORCED_PMEM) + set(ENV{PMEM_IS_PMEM_FORCE} 1) + endif() + + message(STATUS "Executing: ${name} ${ARGN}") + if("${input}" STREQUAL "") + execute_process(COMMAND ${name} ${ARGN} + RESULT_VARIABLE RET + OUTPUT_FILE ${BIN_DIR}/out + ERROR_FILE ${BIN_DIR}/err) + else() + execute_process(COMMAND ${name} ${ARGN} + RESULT_VARIABLE RET + INPUT_FILE ${input} + OUTPUT_FILE ${BIN_DIR}/out + ERROR_FILE ${BIN_DIR}/err) + endif() + if(TESTS_USE_FORCED_PMEM) + unset(ENV{PMEM_IS_PMEM_FORCE}) + endif() + + message(STATUS "Test ${name}:") + file(READ ${BIN_DIR}/out OUT) + message(STATUS "Stdout:\n${OUT}") + file(READ ${BIN_DIR}/err ERR) + message(STATUS "Stderr:\n${ERR}") + + if(NOT RET EQUAL expectation) + message(FATAL_ERROR "${name} ${ARGN} exit code ${RET} doesn't match expectation ${expectation}") + endif() +endfunction() + +function(execute expectation name) + execute_arg("" ${expectation} ${name} ${ARGN}) +endfunction() diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 00000000..fad9541b --- /dev/null +++ b/tests/test.c @@ -0,0 +1,40 @@ +/* + * Copyright 2018, Intel Corporation + * + * 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 the copyright holder 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 THE COPYRIGHT + * OWNER OR CONTRIBUTORS 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. + */ + +/* an example test */ + +#include "main.h" + +int main() +{ + return function(); +}