Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ build-debug/
build-release/
cmake-build-debug/
cmake-build-release/
ignore/
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,34 @@ unset(BUILD_TEST_MODULES CACHE)
unset(BUILD_EXAMPLE_MODULES CACHE)
unset(USE_TLS CACHE)
unset(DEBUG_FORCE_DEFRAG CACHE)

# Helper to copy runtest scripts to allow running tests with CMake built binaries
function(copy_runtest_script script_name)
set(src "${CMAKE_SOURCE_DIR}/${script_name}")
set(dst "${CMAKE_BINARY_DIR}/${script_name}")
file(READ "${src}" contents)

# Split at the first newline (after shebang #!/bin/sh)
string(FIND "${contents}" "\n" index_of_first_newline_char)
math(EXPR first_index_script_body "${index_of_first_newline_char} + 1")

string(SUBSTRING "${contents}" 0 ${first_index_script_body} shebang_line)
string(SUBSTRING "${contents}" ${first_index_script_body} -1 script_body)

# Insert our environment variable lines
set(insert_content
"# Most tests assume running from the project root
cd ${CMAKE_SOURCE_DIR}
export VALKEY_BIN_DIR=\"${CMAKE_BINARY_DIR}/bin\"
")
# Reconstruct the full script
set(new_contents "${shebang_line}${insert_content}${script_body}")
file(WRITE "${dst}" "${new_contents}")
file(CHMOD "${dst}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ WORLD_READ)
endfunction()

copy_runtest_script("runtest")
copy_runtest_script("runtest-cluster")
copy_runtest_script("runtest-moduleapi")
copy_runtest_script("runtest-rdma")
copy_runtest_script("runtest-sentinel")
14 changes: 7 additions & 7 deletions cmake/Modules/ValkeySetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ endif ()

# Helper function for creating symbolic link so that: link -> source
macro (valkey_create_symlink source link)
install(
CODE "execute_process( \
COMMAND /bin/bash ${CMAKE_BINARY_DIR}/CreateSymlink.sh \
${source} \
${link} \
)"
COMPONENT "valkey")
add_custom_command(
TARGET ${source} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
"$<TARGET_FILE_NAME:${source}>"
"$<TARGET_FILE_DIR:${source}>/${link}"
VERBATIM
)
endmacro ()

# Install a binary
Expand Down
10 changes: 10 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,13 @@ endif ()
if (BUILD_UNIT_TESTS)
add_subdirectory(unit)
endif ()

# Friendly hint like the Makefile one
file(RELATIVE_PATH _CMAKE_DIR_RELATIVE_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}")
add_custom_target(hint ALL
DEPENDS valkey-server valkey-cli valkey-benchmark
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "Hint: It is a good idea to run tests with your CMake-built binaries \\;\\)"
COMMAND ${CMAKE_COMMAND} -E echo " ./${_CMAKE_DIR_RELATIVE_PATH}/runtest"
COMMAND ${CMAKE_COMMAND} -E echo ""
)
3 changes: 3 additions & 0 deletions tests/cluster/run.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# This software is released under the BSD License. See the COPYING file for
# more information.

# Set the executable paths at project root
source tests/support/set_executable_path.tcl

cd tests/cluster
source cluster.tcl
source ../instances.tcl
Expand Down
2 changes: 1 addition & 1 deletion tests/cluster/tests/04-resharding.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ test "Cluster consistency during live resharding" {
flush stdout
set target [dict get [get_myself [randomInt 5]] id]
set tribpid [lindex [exec \
../../../src/valkey-cli --cluster reshard \
$::VALKEY_CLI_BIN --cluster reshard \
127.0.0.1:[get_instance_attrib valkey 0 port] \
--cluster-from all \
--cluster-to $target \
Expand Down
4 changes: 2 additions & 2 deletions tests/cluster/tests/12-replica-migration-2.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test "Set allow-replica-migration yes" {
set master0_id [dict get [get_myself 0] id]
test "Resharding all the master #0 slots away from it" {
set output [exec \
../../../src/valkey-cli --cluster rebalance \
$::VALKEY_CLI_BIN --cluster rebalance \
127.0.0.1:[get_instance_attrib valkey 0 port] \
{*}[valkeycli_tls_config "../../../tests"] \
--cluster-weight ${master0_id}=0 >@ stdout ]
Expand All @@ -59,7 +59,7 @@ test "Resharding back some slot to master #0" {
# new resharding.
after 10000
set output [exec \
../../../src/valkey-cli --cluster rebalance \
$::VALKEY_CLI_BIN --cluster rebalance \
127.0.0.1:[get_instance_attrib valkey 0 port] \
{*}[valkeycli_tls_config "../../../tests"] \
--cluster-weight ${master0_id}=.01 \
Expand Down
2 changes: 1 addition & 1 deletion tests/cluster/tests/12.1-replica-migration-3.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test "Set allow-replica-migration no" {
set master0_id [dict get [get_myself 0] id]
test "Resharding all the master #0 slots away from it" {
set output [exec \
../../../src/valkey-cli --cluster rebalance \
$::VALKEY_CLI_BIN --cluster rebalance \
127.0.0.1:[get_instance_attrib valkey 0 port] \
{*}[valkeycli_tls_config "../../../tests"] \
--cluster-weight ${master0_id}=0 >@ stdout ]
Expand Down
6 changes: 3 additions & 3 deletions tests/cluster/tests/includes/utils.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ proc config_set_all_nodes {keyword value} {

proc fix_cluster {addr} {
set code [catch {
exec ../../../src/valkey-cli {*}[valkeycli_tls_config "../../../tests"] --cluster fix $addr << yes
exec $::VALKEY_CLI_BIN {*}[valkeycli_tls_config "../../../tests"] --cluster fix $addr << yes
} result]
if {$code != 0} {
puts "valkey-cli --cluster fix returns non-zero exit code, output below:\n$result"
Expand All @@ -17,7 +17,7 @@ proc fix_cluster {addr} {
# but we can ignore that and rely on the check below.
assert_cluster_state ok
wait_for_condition 100 100 {
[catch {exec ../../../src/valkey-cli {*}[valkeycli_tls_config "../../../tests"] --cluster check $addr} result] == 0
[catch {exec $::VALKEY_CLI_BIN {*}[valkeycli_tls_config "../../../tests"] --cluster check $addr} result] == 0
} else {
puts "valkey-cli --cluster check returns non-zero exit code, output below:\n$result"
fail "Cluster could not settle with configuration"
Expand All @@ -26,7 +26,7 @@ proc fix_cluster {addr} {

proc wait_cluster_stable {} {
wait_for_condition 1000 50 {
[catch {exec ../../../src/valkey-cli --cluster \
[catch {exec $::VALKEY_CLI_BIN --cluster \
check 127.0.0.1:[get_instance_attrib valkey 0 port] \
{*}[valkeycli_tls_config "../../../tests"] \
}] == 0
Expand Down
8 changes: 4 additions & 4 deletions tests/instances.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ if {[catch {cd tmp}]} {
# the provided configuration file. Returns the PID of the process.
proc exec_instance {type dirname cfgfile} {
if {$type eq "valkey"} {
set prgname valkey-server
set program_path $::VALKEY_SERVER_BIN
} elseif {$type eq "sentinel"} {
set prgname valkey-sentinel
set program_path $::VALKEY_SENTINEL_BIN
} else {
error "Unknown instance type."
}

set errfile [file join $dirname err.txt]
if {$::valgrind} {
set pid [exec valgrind --track-origins=yes --suppressions=../../../src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full ../../../src/${prgname} $cfgfile 2>> $errfile &]
set pid [exec valgrind --track-origins=yes --suppressions=../../../src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full ${program_path} $cfgfile 2>> $errfile &]
} else {
set pid [exec ../../../src/${prgname} $cfgfile 2>> $errfile &]
set pid [exec ${program_path} $cfgfile 2>> $errfile &]
}
return $pid
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/aof-race.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tags {"aof external:skip"} {
# was subsequently appended to the new AOF, resulting in duplicate commands.
start_server_aof [list dir $server_path] {
set client [valkey [srv host] [srv port] 0 $::tls]
set bench [open "|src/valkey-benchmark -q -s [srv unixsocket] -c 20 -n 20000 incr foo" "r+"]
set bench [open "|$::VALKEY_BENCHMARK_BIN -q -s [srv unixsocket] -c 20 -n 20000 incr foo" "r+"]

wait_for_condition 100 1 {
[$client get foo] > 0
Expand Down
32 changes: 16 additions & 16 deletions tests/integration/aof.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ tags {"aof external:skip logreqres:skip"} {
## Test that valkey-check-aof indeed sees this AOF is not valid
test "Short read: Utility should confirm the AOF is not valid" {
catch {
exec src/valkey-check-aof $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN $aof_manifest_file
} result
assert_match "*not valid*" $result
}
Expand All @@ -121,13 +121,13 @@ tags {"aof external:skip logreqres:skip"} {
}

catch {
exec src/valkey-check-aof $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN $aof_manifest_file
} result
assert_match "*ok_up_to_line=8*" $result
}

test "Short read: Utility should be able to fix the AOF" {
set result [exec src/valkey-check-aof --fix $aof_manifest_file << "y\n"]
set result [exec $::VALKEY_CHECK_AOF_BIN --fix $aof_manifest_file << "y\n"]
assert_match "*Successfully truncated AOF*" $result
}

Expand Down Expand Up @@ -399,7 +399,7 @@ tags {"aof external:skip logreqres:skip"} {

test {Truncate AOF to specific timestamp} {
# truncate to timestamp 1628217473
exec src/valkey-check-aof --truncate-to-timestamp 1628217473 $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN --truncate-to-timestamp 1628217473 $aof_manifest_file
start_server_aof [list dir $server_path] {
set c [valkey [srv host] [srv port] 0 $::tls]
wait_done_loading $c
Expand All @@ -409,7 +409,7 @@ tags {"aof external:skip logreqres:skip"} {
}

# truncate to timestamp 1628217471
exec src/valkey-check-aof --truncate-to-timestamp 1628217471 $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN --truncate-to-timestamp 1628217471 $aof_manifest_file
start_server_aof [list dir $server_path] {
set c [valkey [srv host] [srv port] 0 $::tls]
wait_done_loading $c
Expand All @@ -419,7 +419,7 @@ tags {"aof external:skip logreqres:skip"} {
}

# truncate to timestamp 1628217470
exec src/valkey-check-aof --truncate-to-timestamp 1628217470 $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN --truncate-to-timestamp 1628217470 $aof_manifest_file
start_server_aof [list dir $server_path] {
set c [valkey [srv host] [srv port] 0 $::tls]
wait_done_loading $c
Expand All @@ -428,7 +428,7 @@ tags {"aof external:skip logreqres:skip"} {
}

# truncate to timestamp 1628217469
catch {exec src/valkey-check-aof --truncate-to-timestamp 1628217469 $aof_manifest_file} e
catch {exec $::VALKEY_CHECK_AOF_BIN --truncate-to-timestamp 1628217469 $aof_manifest_file} e
assert_match {*aborting*} $e
}

Expand Down Expand Up @@ -478,7 +478,7 @@ tags {"aof external:skip logreqres:skip"} {
}

catch {
exec src/valkey-check-aof $aof_file
exec $::VALKEY_CHECK_AOF_BIN $aof_file
} result
assert_match "*Start checking Old-Style AOF*is valid*" $result
}
Expand All @@ -490,14 +490,14 @@ tags {"aof external:skip logreqres:skip"} {
}

catch {
exec src/valkey-check-aof $aof_file
exec $::VALKEY_CHECK_AOF_BIN $aof_file
} result
assert_match "*Start checking Old-Style AOF*is valid*" $result
}

test {Test valkey-check-aof for old style rdb-preamble AOF} {
catch {
exec src/valkey-check-aof tests/assets/rdb-preamble.aof
exec $::VALKEY_CHECK_AOF_BIN tests/assets/rdb-preamble.aof
} result
assert_match "*Start checking Old-Style AOF*RDB preamble is OK, proceeding with AOF tail*is valid*" $result
}
Expand All @@ -519,7 +519,7 @@ tags {"aof external:skip logreqres:skip"} {
}

catch {
exec src/valkey-check-aof $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN $aof_manifest_file
} result
assert_match "*Start checking Multi Part AOF*Start to check BASE AOF (RESP format)*BASE AOF*is valid*Start to check INCR files*INCR AOF*is valid*All AOF files and manifest are valid*" $result
}
Expand All @@ -538,7 +538,7 @@ tags {"aof external:skip logreqres:skip"} {
}

catch {
exec src/valkey-check-aof $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN $aof_manifest_file
} result
assert_match "*Start checking Multi Part AOF*Start to check BASE AOF (RDB format)*DB preamble is OK, proceeding with AOF tail*BASE AOF*is valid*Start to check INCR files*INCR AOF*is valid*All AOF files and manifest are valid*" $result
}
Expand All @@ -551,7 +551,7 @@ tags {"aof external:skip logreqres:skip"} {
}

catch {
exec src/valkey-check-aof $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN $aof_manifest_file
} result
assert_match "*Invalid AOF manifest file format*" $result
}
Expand All @@ -574,12 +574,12 @@ tags {"aof external:skip logreqres:skip"} {
}

catch {
exec src/valkey-check-aof $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN $aof_manifest_file
} result
assert_match "*not valid*" $result

catch {
exec src/valkey-check-aof --fix $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN --fix $aof_manifest_file
} result
assert_match "*Failed to truncate AOF*because it is not the last file*" $result
}
Expand Down Expand Up @@ -607,7 +607,7 @@ tags {"aof external:skip logreqres:skip"} {
}

catch {
exec src/valkey-check-aof --truncate-to-timestamp 1628217473 $aof_manifest_file
exec $::VALKEY_CHECK_AOF_BIN --truncate-to-timestamp 1628217473 $aof_manifest_file
} result
assert_match "*Failed to truncate AOF*to timestamp*because it is not the last file*" $result
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/psync2-reg.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ start_server {} {
}

set cycle_start_time [clock milliseconds]
set bench_pid [exec src/valkey-benchmark -s $R_unixsocket(0) -n 10000000 -r 1000 incr __rand_int__ > /dev/null &]
set bench_pid [exec $::VALKEY_BENCHMARK_BIN -s $R_unixsocket(0) -n 10000000 -r 1000 incr __rand_int__ > /dev/null &]
while 1 {
set elapsed [expr {[clock milliseconds]-$cycle_start_time}]
if {$elapsed > $duration*1000} break
Expand Down
Loading
Loading