Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
tests: use preload tests to test pmemfile-fuse
Browse files Browse the repository at this point in the history
  • Loading branch information
mslusarz committed Nov 8, 2017
1 parent fbb67ef commit 527e0e5
Show file tree
Hide file tree
Showing 21 changed files with 150 additions and 141 deletions.
72 changes: 51 additions & 21 deletions tests/preload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ int main() {
}
" XATTR_AVAILABLE_IN_TEST_DIR)

if(BUILD_PMEMFILE_FUSE)
find_program(FUSERMOUNT fusermount)
if (NOT FUSERMOUNT)
message(FATAL_ERROR "fusermount not available")
endif()
endif()

add_executable(preload_basic basic/basic.c)
add_executable(preload_dup dup/dup.c)
set_target_properties(preload_dup PROPERTIES INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/src)
Expand Down Expand Up @@ -93,8 +100,8 @@ if(USE_ASAN)
endif()

# Configures test ${name}${sub_name} using test dir ${name} and executable ${main_executable}
function(add_test_generic name sub_name main_executable)
add_test(NAME preload_${name}${sub_name}
function(add_test_generic prefix name sub_name main_executable)
add_test(NAME ${prefix}${name}${sub_name}
COMMAND ${CMAKE_COMMAND}
${GLOBAL_TEST_ARGS}
-DTEST_NAME=${name}${sub_name}
Expand All @@ -105,61 +112,84 @@ function(add_test_generic name sub_name main_executable)
${ARGN}
-P ${CMAKE_CURRENT_SOURCE_DIR}/${name}/${name}.cmake)

set_tests_properties(preload_${name}${sub_name} PROPERTIES
set_tests_properties(${prefix}${name}${sub_name} PROPERTIES
ENVIRONMENT "LC_ALL=C")
endfunction()

function(add_test_generic_ps name sub_name main_executable)
add_test_generic(${name} "${sub_name}" ${main_executable} ${ARGN})
add_test_generic(${name} "${sub_name}_with_process_switching" ${main_executable} -DTEST_PROCESS_SWITCHING=1 ${ARGN})
function(add_preload_test name sub_name main_executable)
add_test_generic("preload_" "${name}" "${sub_name}" "${main_executable}" ${ARGN})
endfunction()

function(add_preload_test_ps name sub_name main_executable)
add_preload_test(${name} "${sub_name}" ${main_executable} ${ARGN})
add_preload_test(${name} "${sub_name}_with_process_switching" ${main_executable} -DTEST_PROCESS_SWITCHING=1 ${ARGN})
endfunction()

find_program(SQLITE3 sqlite3)
if (SQLITE3)
add_test_generic(sqlite "" none)
add_preload_test(sqlite "" none)
else()
add_test(NAME sqlite_SKIPPED_BECAUSE_OF_MISSING_SQLITE3 COMMAND true)
endif()

add_test_generic_ps(basic "" $<TARGET_FILE:preload_basic>)
add_test_generic_ps(dup "" $<TARGET_FILE:preload_dup>)
add_test_generic_ps(basic_commands "" none)
add_test_generic(nested_dirs "" none)
add_test_generic(pool_locking "" $<TARGET_FILE:preload_pool_locking>)
add_preload_test_ps(basic "" $<TARGET_FILE:preload_basic>)
add_preload_test_ps(dup "" $<TARGET_FILE:preload_dup>)
add_preload_test_ps(basic_commands "" none)
add_preload_test(nested_dirs "" none)
add_preload_test(pool_locking "" $<TARGET_FILE:preload_pool_locking>)

add_test_generic(config "_valid_via_symlink" $<TARGET_FILE:preload_config> -DTEST_PATH=some_dir/some_link/a)
add_preload_test(config "_valid_via_symlink" $<TARGET_FILE:preload_config> -DTEST_PATH=some_dir/some_link/a)
set_tests_properties("preload_config_valid_via_symlink"
PROPERTIES PASS_REGULAR_EXPRESSION "no error")

add_test_generic(config "_invalid" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point_wrong/a)
add_preload_test(config "_invalid" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point_wrong/a)
set_tests_properties("preload_config_invalid"
PROPERTIES PASS_REGULAR_EXPRESSION "EIO")

add_test_generic(config "_invalid_plus_nested" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point_wrong/a/b/c)
add_preload_test(config "_invalid_plus_nested" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point_wrong/a/b/c)
set_tests_properties("preload_config_invalid_plus_nested"
PROPERTIES PASS_REGULAR_EXPRESSION "EIO")

add_test_generic(config "_valid_plus_nested" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point/a/b)
add_preload_test(config "_valid_plus_nested" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point/a/b)
set_tests_properties("preload_config_valid_plus_nested"
PROPERTIES PASS_REGULAR_EXPRESSION "ENOENT")

add_test_generic(config "_invalid_via_valid" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point/./../mount_point_wrong/a)
add_preload_test(config "_invalid_via_valid" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point/./../mount_point_wrong/a)
set_tests_properties("preload_config_invalid_via_valid"
PROPERTIES PASS_REGULAR_EXPRESSION "EIO")

add_test_generic(config "_outer_via_valid" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point/../a)
add_preload_test(config "_outer_via_valid" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point/../a)
set_tests_properties("preload_config_outer_via_valid"
PROPERTIES PASS_REGULAR_EXPRESSION "no error")

add_test_generic(config "_outer_via_invalid" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point_wrong/../a)
add_preload_test(config "_outer_via_invalid" $<TARGET_FILE:preload_config> -DTEST_PATH=mount_point_wrong/../a)
set_tests_properties("preload_config_outer_via_invalid"
PROPERTIES PASS_REGULAR_EXPRESSION "EIO")

add_test_generic_ps(unix "" $<TARGET_FILE:preload_unix>)
add_preload_test_ps(unix "" $<TARGET_FILE:preload_unix>)

if(XATTR_AVAILABLE_IN_TEST_DIR)
add_executable(preload_xattr xattr/xattr.c)
add_cstyle(tests-preload-xattr ${CMAKE_CURRENT_SOURCE_DIR}/xattr/xattr.c)
add_check_whitespace(tests-preload-xattr ${CMAKE_CURRENT_SOURCE_DIR}/xattr/xattr.c)
add_test_generic_ps(xattr "" $<TARGET_FILE:preload_xattr>)
add_preload_test_ps(xattr "" $<TARGET_FILE:preload_xattr>)
endif()

function(add_fuse_test name main_executable)
add_test_generic(fuse_ ${name} "" ${main_executable} -DUSE_FUSE=1 -DFUSERMOUNT=${FUSERMOUNT} -DPMEMFILE_FUSE=$<TARGET_FILE:pmemfile-fuse> ${ARGN})
endfunction()

if(BUILD_PMEMFILE_FUSE)
add_fuse_test(basic $<TARGET_FILE:preload_basic>)
add_fuse_test(dup $<TARGET_FILE:preload_dup>)
add_fuse_test(basic_commands none)
add_fuse_test(nested_dirs none)
add_fuse_test(pool_locking $<TARGET_FILE:preload_pool_locking>)
if (SQLITE3)
add_fuse_test(sqlite none)
endif()
add_fuse_test(unix $<TARGET_FILE:preload_unix>)
if(XATTR_AVAILABLE_IN_TEST_DIR)
add_fuse_test(xattr $<TARGET_FILE:preload_xattr>)
endif()
endif()
24 changes: 11 additions & 13 deletions tests/preload/basic/basic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,28 @@

include(${SRC_DIR}/../preload-helpers.cmake)

setup()
setup(128m)

mkfs(${DIR}/fs 128m)

execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/mount_point)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/some_dir)
execute_process(COMMAND ln -s ../mount_point ${DIR}/some_dir/some_link)

set(ENV{LD_PRELOAD} ${PRELOAD_LIB})
set(ENV{PMEMFILE_POOLS} ${DIR}/mount_point:${DIR}/fs)
set(ENV{PMEMFILE_PRELOAD_LOG} ${BIN_DIR}/pmemfile_preload.log)
set(ENV{INTERCEPT_LOG} ${BIN_DIR}/intercept.log)
set(ENV{PMEMFILE_EXIT_ON_NOT_SUPPORTED} 1)
if (NOT USE_FUSE)
set(ENV{PMEMFILE_EXIT_ON_NOT_SUPPORTED} 1)
endif()

execute_process(COMMAND ${MAIN_EXECUTABLE} ${DIR}/some_dir/some_link/a ${DIR} mount_point/b mount_point b
OUTPUT_FILE ${DIR}/root_dir.log
RESULT_VARIABLE res)
if(res)
message(FATAL_ERROR "Test1 command failed: ${res}")
message(FATAL_ERROR "Test1 command failed: ${res}")
endif()

unset(ENV{LD_PRELOAD})

pf_cat(${DIR}/fs /a ${DIR}/a.dump)
if(USE_FUSE)
execute_with_output(${DIR}/a.dump cat ${DIR}/mount_point/a)
else()
unset(ENV{LD_PRELOAD})
pf_cat(${DIR}/fs /a ${DIR}/a.dump)
endif()

cmp(${DIR}/a.dump ${SRC_DIR}/a.expected_dump)

Expand Down
41 changes: 22 additions & 19 deletions tests/preload/basic_commands/basic_commands.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,11 @@

include(${SRC_DIR}/../preload-helpers.cmake)

setup()
setup(128m)

mkfs(${DIR}/fs 128m)

execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/mount_point)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/some_dir)
execute_process(COMMAND ln -s ../mount_point ${DIR}/some_dir/some_link)

set(ENV{LD_PRELOAD} ${PRELOAD_LIB})
set(ENV{PMEMFILE_POOLS} ${DIR}/mount_point:${DIR}/fs)
set(ENV{PMEMFILE_PRELOAD_LOG} ${BIN_DIR}/pmemfile_preload.log)
set(ENV{INTERCEPT_LOG} ${BIN_DIR}/intercept.log)
#set(ENV{PMEMFILE_EXIT_ON_NOT_SUPPORTED} 1)

execute(cp ${SRC_DIR}/repo_dummy_file_a ${DIR}/dummy_file_a)
execute(chmod 644 ${DIR}/dummy_file_a)
execute(cp ${SRC_DIR}/repo_dummy_file_b ${DIR}/dummy_file_b)
Expand Down Expand Up @@ -84,18 +75,26 @@ list_files(ls_with_dir.log ${DIR}/mount_point)
rmdir(${DIR}/mount_point/dummy_dir_a)
list_files(ls_without_dir.log ${DIR}/mount_point)

set(ENV{PMEMFILE_CD} ${DIR}/mount_point)
mkdir(dir_inside)
unset(ENV{PMEMFILE_CD})
if (USE_FUSE)
mkdir(${DIR}/mount_point/dir_inside)
else()
set(ENV{PMEMFILE_CD} ${DIR}/mount_point)
mkdir(dir_inside)
unset(ENV{PMEMFILE_CD})
endif()
execute(stat ${DIR}/mount_point/dir_inside)

mkdir(${DIR}/mount_point/../test)
execute(ls -lR ${DIR})
execute(stat ${DIR}/test)

set(ENV{PMEMFILE_CD} ${DIR}/mount_point/dir_inside)
mkdir(../../dir_outside)
unset(ENV{PMEMFILE_CD})
if (USE_FUSE)
mkdir(${DIR}/mount_point/dir_inside/../../dir_outside)
else()
set(ENV{PMEMFILE_CD} ${DIR}/mount_point/dir_inside)
mkdir(../../dir_outside)
unset(ENV{PMEMFILE_CD})
endif()
execute(ls -lR ${DIR})
execute(stat ${DIR}/dir_outside)

Expand Down Expand Up @@ -126,9 +125,13 @@ execute_expect_failure(cp ${SRC_DIR}/repo_dummy_file_a ${DIR}/mount_point/file_b
execute(ln -s symlink_to_itself ${DIR}/mount_point/symlink_to_itself)
execute_expect_failure(cat ${DIR}/mount_point/symlink_to_itself)

set(ENV{PMEMFILE_CD} ${DIR}/mount_point)
execute(stat ../dummy_file_a)
unset(ENV{PMEMFILE_CD})
if (USE_FUSE)
execute(stat ${DIR}/mount_point/../dummy_file_a)
else()
set(ENV{PMEMFILE_CD} ${DIR}/mount_point)
execute(stat ../dummy_file_a)
unset(ENV{PMEMFILE_CD})
endif()

# test syscalls for paths outside of pmemfile mount point
execute(touch ${DIR}/out_file)
Expand Down
4 changes: 3 additions & 1 deletion tests/preload/basic_commands/ls.log.match
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
total $(N)
drwxrwxrwx 2 $(N) .
drwxrwxrwx 2 $(N) ..
$(OPT)drwxrwxrwx 2 $(N) ..
$(OPX)drwxr-xr-x 4 $(N) ..
$(OPT) XXX there shouldn't be any difference between libpmemfile and pmemfile-fuse!
-rw-r--r-- 1 391 file_a
-rw-r--r-- 1 4401 file_b
4 changes: 3 additions & 1 deletion tests/preload/basic_commands/ls_with_dir.log.match
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
total $(N)
drwxrwxrwx 3 $(N) .
drwxrwxrwx 3 $(N) ..
$(OPT)drwxrwxrwx 3 $(N) ..
$(OPX)drwxr-xr-x 4 $(N) ..
$(OPT) XXX there shouldn't be any difference between libpmemfile and pmemfile-fuse!
drwxr-xr-x 2 $(N) dummy_dir_a
-rw-r--r-- 1 391 file_a
-rw-r--r-- 1 4401 file_b
4 changes: 3 additions & 1 deletion tests/preload/basic_commands/ls_without_dir.log.match
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
total $(N)
drwxrwxrwx 2 $(N) .
drwxrwxrwx 2 $(N) ..
$(OPT)drwxrwxrwx 2 $(N) ..
$(OPX)drwxr-xr-x 4 $(N) ..
$(OPT) XXX there shouldn't be any difference between libpmemfile and pmemfile-fuse!
-rw-r--r-- 1 391 file_a
-rw-r--r-- 1 4401 file_b
8 changes: 1 addition & 7 deletions tests/preload/config/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,13 @@

include(${SRC_DIR}/../preload-helpers.cmake)

setup()
setup(128m)

mkfs(${DIR}/fs 128m)

execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/mount_point)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/mount_point_wrong)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/some_dir)
execute_process(COMMAND ln -s ../mount_point ${DIR}/some_dir/some_link)

set(ENV{LD_PRELOAD} ${PRELOAD_LIB})
set(ENV{PMEMFILE_POOLS} "${DIR}/mount_point:${DIR}/fs;${DIR}/mount_point_wrong:${DIR}/invalid")
set(ENV{PMEMFILE_PRELOAD_LOG} ${BIN_DIR}/pmemfile_preload.log)
set(ENV{INTERCEPT_LOG} ${BIN_DIR}/intercept.log)

execute(${MAIN_EXECUTABLE} ${DIR}/${TEST_PATH})

Expand Down
15 changes: 4 additions & 11 deletions tests/preload/dup/dup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@

include(${SRC_DIR}/../preload-helpers.cmake)

setup()
setup(128m)

mkfs(${DIR}/fs 16m)

execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/mount_point)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/some_dir)

set(ENV{LD_PRELOAD} ${PRELOAD_LIB})
set(ENV{PMEMFILE_POOLS} ${DIR}/mount_point:${DIR}/fs)
set(ENV{PMEMFILE_PRELOAD_LOG} ${BIN_DIR}/pmemfile_preload.log)
set(ENV{INTERCEPT_LOG} ${BIN_DIR}/intercept.log)
set(ENV{PMEMFILE_EXIT_ON_NOT_SUPPORTED} 1)
if (NOT USE_FUSE)
set(ENV{PMEMFILE_EXIT_ON_NOT_SUPPORTED} 1)
endif()

execute_process(COMMAND ${MAIN_EXECUTABLE} ${DIR}/some_dir/filename ${DIR}/mount_point/filename
OUTPUT_FILE ${DIR}/root_dir.log
Expand All @@ -51,6 +46,4 @@ if(res)
message(FATAL_ERROR "command failed: ${res}")
endif()

unset(ENV{LD_PRELOAD})

cleanup()
10 changes: 1 addition & 9 deletions tests/preload/nested_dirs/nested_dirs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,11 @@

include(${SRC_DIR}/../preload-helpers.cmake)

setup()
setup(128m)

mkfs(${DIR}/fs 128m)

execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/mount_point)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/some_dir)
execute_process(COMMAND ln -s ../mount_point ${DIR}/some_dir/some_link)

set(ENV{LD_PRELOAD} ${PRELOAD_LIB})
set(ENV{PMEMFILE_POOLS} ${DIR}/mount_point:${DIR}/fs)
set(ENV{PMEMFILE_PRELOAD_LOG} ${BIN_DIR}/pmemfile_preload.log)
set(ENV{INTERCEPT_LOG} ${BIN_DIR}/intercept.log)

mkdir_expect_failure(${DIR}/mount_point/nonexistent/dummy_dir_a)
mkdir(${DIR}/mount_point/test_dir)
mkdir(${DIR}/mount_point/test_dir_other)
Expand Down
15 changes: 4 additions & 11 deletions tests/preload/pool_locking/pool_locking.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,11 @@

include(${SRC_DIR}/../preload-helpers.cmake)

setup()
setup(128m)

mkfs(${DIR}/fs 128m)

execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${DIR}/mount_point)

set(ENV{LD_PRELOAD} ${PRELOAD_LIB})
set(ENV{PMEMFILE_POOLS} ${DIR}/mount_point:${DIR}/fs)

if (NOT TEST_PROCESS_SWITCHING)
set(ENV{PMEMFILE_PRELOAD_LOG} ${BIN_DIR}/pmemfile_preload.log)
set(ENV{INTERCEPT_LOG} ${BIN_DIR}/intercept.log)
if (TEST_PROCESS_SWITCHING)
unset(ENV{PMEMFILE_PRELOAD_LOG})
unset(ENV{INTERCEPT_LOG})
endif()

execute(${MAIN_EXECUTABLE} ${DIR}/mount_point/file)
Expand Down
Loading

0 comments on commit 527e0e5

Please sign in to comment.