Skip to content

Commit

Permalink
Merge pull request #3500 from thisismiller/toml-testspec
Browse files Browse the repository at this point in the history
Add support for .toml tests
  • Loading branch information
xumengpanda committed Jul 20, 2020
2 parents f22a6c2 + 8782544 commit e069a15
Show file tree
Hide file tree
Showing 208 changed files with 3,344 additions and 2,563 deletions.
63 changes: 63 additions & 0 deletions build/txt-to-toml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
import sys


def main():
if len(sys.argv) != 2:
print("Usage: txt-to-toml.py [src.txt]")
return 1

filename = sys.argv[1]

indent = " "
in_workload = False
first_test = False
keys_before_test = False

for line in open(filename):
k = ""
v = ""

if line.strip().startswith(";"):
print((indent if in_workload else "") + line.strip().replace(";", "#"))
continue

if "=" in line:
(k, v) = line.strip().split("=")
(k, v) = (k.strip(), v.strip())

if k == "testTitle":
first_test = True
if in_workload:
print("")
in_workload = False
if keys_before_test:
print("")
keys_before_test = False
print("[[test]]")

if k == "testName":
in_workload = True
print("")
print(indent + "[[test.workload]]")

if not first_test:
keys_before_test = True

if v.startswith("."):
v = "0" + v

if any(c.isalpha() or c in ["/", "!"] for c in v):
if v != "true" and v != "false":
v = "'" + v + "'"

if k == "buggify":
print("buggify = " + ("true" if v == "'on'" else "false"))
elif k:
print((indent if in_workload else "") + k + " = " + v)

return 0


if __name__ == "__main__":
sys.exit(main())
4 changes: 3 additions & 1 deletion cmake/AddFdbTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function(configure_testing)
set(no_tests YES)
if(CONFIGURE_TESTING_ERROR_ON_ADDITIONAL_FILES)
file(GLOB_RECURSE candidates "${CONFIGURE_TESTING_TEST_DIRECTORY}/*.txt")
file(GLOB_RECURSE toml_candidates "${CONFIGURE_TESTING_TEST_DIRECTORY}/*.toml")
list(APPEND candidates ${toml_candidates})
foreach(candidate IN LISTS candidates)
set(candidate_is_test YES)
foreach(pattern IN LISTS CONFIGURE_TESTING_IGNORE_PATTERNS)
Expand Down Expand Up @@ -79,7 +81,7 @@ function(add_fdb_test)
set(test_type "test")
endif()
list(GET ADD_FDB_TEST_TEST_FILES 0 first_file)
string(REGEX REPLACE "^(.*)\\.txt$" "\\1" test_name ${first_file})
string(REGEX REPLACE "^(.*)\\.(txt|toml)$" "\\1" test_name ${first_file})
if("${test_name}" MATCHES "(-\\d)$")
string(REGEX REPLACE "(.*)(-\\d)$" "\\1" test_name_1 ${test_name})
message(STATUS "new testname ${test_name_1}")
Expand Down
8 changes: 8 additions & 0 deletions cmake/FDBComponents.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ else()
set(WITH_ROCKSDB_EXPERIMENTAL OFF)
endif()

################################################################################
# TOML11
################################################################################

# TOML can download and install itself into the binary directory, so it should
# always be available.
find_package(TOML11)

################################################################################

file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/packages)
Expand Down
28 changes: 28 additions & 0 deletions cmake/FindTOML11.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
find_path(TOML11_INCLUDE_DIR
NAMES
toml.hpp
PATH_SUFFIXES
include
toml11
include/toml11
HINTS
"${_TOML11_HINTS}"
)

if (NOT TOML11_INCLUDE_DIR)
include(ExternalProject)

ExternalProject_add(toml11
URL "https://github.com/ToruNiina/toml11/archive/v3.4.0.tar.gz"
URL_HASH SHA256=bc6d733efd9216af8c119d8ac64a805578c79cc82b813e4d1d880ca128bd154d
CMAKE_CACHE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/toml11
-Dtoml11_BUILD_TEST:BOOL=OFF)

set(TOML11_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/toml11/include")
endif()

find_package_handle_standard_args(TOML11
REQUIRED_VARS
TOML11_INCLUDE_DIR
)
3 changes: 3 additions & 0 deletions fdbserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ else()
target_link_libraries(fdbserver PRIVATE fdbclient fdb_sqlite)
endif()

add_dependencies(fdbserver toml11)
target_include_directories(fdbserver PRIVATE ${TOML11_INCLUDE_DIR})

if (GPERFTOOLS_FOUND)
add_compile_definitions(USE_GPERFTOOLS)
target_link_libraries(fdbserver PRIVATE gperftools)
Expand Down
6 changes: 4 additions & 2 deletions fdbserver/fdbserver.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,12 @@ Optional<bool> checkBuggifyOverride(const char *testFile) {
std::string value = removeWhitespace(line.substr(found + 1));

if (attrib == "buggify") {
if( !strcmp( value.c_str(), "on" ) ) {
// Testspec uses `on` or `off` (without quotes).
// TOML uses literal `true` and `false`.
if( !strcmp( value.c_str(), "on" ) || !strcmp( value.c_str(), "true" ) ) {
ifs.close();
return true;
} else if( !strcmp( value.c_str(), "off" ) ) {
} else if( !strcmp( value.c_str(), "off" ) || !strcmp( value.c_str(), "false" )) {
ifs.close();
return false;
} else {
Expand Down

0 comments on commit e069a15

Please sign in to comment.