Directly use unit test tempalte buck (#6926)

Summary:
Make RocksDB run a predefined unit test so that it can be integrated with better tools.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6926

Test Plan: Watch tests

Reviewed By: pdillinger

Differential Revision: D21866216

fbshipit-source-id: cafca82efdf0b72671be8d30b665e88a75ae6000
main
sdong 4 years ago committed by Facebook GitHub Bot
parent 98b0cbea88
commit 2e7070b194
  1. 44
      TARGETS
  2. 25
      buckifier/buckify_rocksdb.py
  3. 11
      buckifier/targets_builder.py
  4. 30
      buckifier/targets_cfg.py

@ -78,7 +78,6 @@ ROCKSDB_PREPROCESSOR_FLAGS = [
# Directories with files for #include # Directories with files for #include
"-I" + REPO_PATH + "include/", "-I" + REPO_PATH + "include/",
"-I" + REPO_PATH, "-I" + REPO_PATH,
"-I" + REPO_PATH + "third-party/gtest-1.8.1/fused-src/",
] ]
ROCKSDB_ARCH_PREPROCESSOR_FLAGS = { ROCKSDB_ARCH_PREPROCESSOR_FLAGS = {
@ -398,11 +397,10 @@ cpp_library(
os_deps = ROCKSDB_OS_DEPS, os_deps = ROCKSDB_OS_DEPS,
os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS, os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS,
preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
deps = [ deps = [":rocksdb_lib"],
":rocksdb_lib", external_deps = ROCKSDB_EXTERNAL_DEPS + [
":rocksdb_third_party_gtest", ("googletest", None, "gtest"),
], ],
external_deps = ROCKSDB_EXTERNAL_DEPS,
) )
cpp_library( cpp_library(
@ -449,19 +447,6 @@ cpp_library(
external_deps = ROCKSDB_EXTERNAL_DEPS, external_deps = ROCKSDB_EXTERNAL_DEPS,
) )
cpp_library(
name = "rocksdb_third_party_gtest",
srcs = ["third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc"],
headers = ["third-party/gtest-1.8.1/fused-src/gtest/gtest.h"],
arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS,
compiler_flags = ROCKSDB_COMPILER_FLAGS,
os_deps = ROCKSDB_OS_DEPS,
os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS,
preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
deps = [],
external_deps = ROCKSDB_EXTERNAL_DEPS,
)
cpp_library( cpp_library(
name = "env_basic_test_lib", name = "env_basic_test_lib",
srcs = ["env/env_basic_test.cc"], srcs = ["env/env_basic_test.cc"],
@ -1645,18 +1630,17 @@ ROCKS_TESTS = [
# Do not build the tests in opt mode, since SyncPoint and other test code # Do not build the tests in opt mode, since SyncPoint and other test code
# will not be included. # will not be included.
[ [
test_binary( cpp_unittest(
extra_compiler_flags = extra_compiler_flags, name = test_name,
extra_deps = extra_deps, srcs = [test_cc],
parallelism = parallelism, arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS,
rocksdb_arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS,
rocksdb_compiler_flags = ROCKSDB_COMPILER_FLAGS, compiler_flags = ROCKSDB_COMPILER_FLAGS,
rocksdb_external_deps = ROCKSDB_EXTERNAL_DEPS, preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
rocksdb_os_deps = ROCKSDB_OS_DEPS, deps = [":rocksdb_test_lib"] + extra_deps,
rocksdb_os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS, external_deps = ROCKSDB_EXTERNAL_DEPS + [
rocksdb_preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, ("googletest", None, "gtest"),
test_cc = test_cc, ],
test_name = test_name,
) )
for test_name, test_cc, parallelism, extra_deps, extra_compiler_flags in ROCKS_TESTS for test_name, test_cc, parallelism, extra_deps, extra_compiler_flags in ROCKS_TESTS
if not is_opt_mode if not is_opt_mode

@ -108,16 +108,6 @@ def get_tests(repo_path):
return tests return tests
# Get gtest dir from Makefile
def get_gtest_dir(repo_path):
for line in open(repo_path + "/Makefile"):
if line.strip().startswith("GTEST_DIR ="):
return line.split("=")[1].strip()
# if not found
exit_with_error("Unable to find GTEST_DIR in Makefile")
# Parse extra dependencies passed by user from command line # Parse extra dependencies passed by user from command line
def get_dependencies(): def get_dependencies():
deps_map = { deps_map = {
@ -151,13 +141,11 @@ def generate_targets(repo_path, deps_map):
cc_files = get_cc_files(repo_path) cc_files = get_cc_files(repo_path)
# get tests from Makefile # get tests from Makefile
tests = get_tests(repo_path) tests = get_tests(repo_path)
# get gtest dir
gtest_dir = get_gtest_dir(repo_path) + "/"
if src_mk is None or cc_files is None or tests is None: if src_mk is None or cc_files is None or tests is None:
return False return False
TARGETS = TARGETSBuilder("%s/TARGETS" % repo_path, gtest_dir) TARGETS = TARGETSBuilder("%s/TARGETS" % repo_path)
# rocksdb_lib # rocksdb_lib
TARGETS.add_library( TARGETS.add_library(
@ -171,7 +159,10 @@ def generate_targets(repo_path, deps_map):
src_mk.get("TEST_LIB_SOURCES", []) + src_mk.get("TEST_LIB_SOURCES", []) +
src_mk.get("EXP_LIB_SOURCES", []) + src_mk.get("EXP_LIB_SOURCES", []) +
src_mk.get("ANALYZER_LIB_SOURCES", []), src_mk.get("ANALYZER_LIB_SOURCES", []),
[":rocksdb_lib", ":rocksdb_third_party_gtest"]) [":rocksdb_lib"],
extra_external_deps=""" + [
("googletest", None, "gtest"),
]""")
# rocksdb_tools_lib # rocksdb_tools_lib
TARGETS.add_library( TARGETS.add_library(
"rocksdb_tools_lib", "rocksdb_tools_lib",
@ -185,12 +176,6 @@ def generate_targets(repo_path, deps_map):
src_mk.get("ANALYZER_LIB_SOURCES", []) src_mk.get("ANALYZER_LIB_SOURCES", [])
+ src_mk.get('STRESS_LIB_SOURCES', []) + src_mk.get('STRESS_LIB_SOURCES', [])
+ ["test_util/testutil.cc"]) + ["test_util/testutil.cc"])
# rocksdb_third_party_gtest
TARGETS.add_library(
"rocksdb_third_party_gtest",
[gtest_dir + "gtest/gtest-all.cc"],
[],
[gtest_dir + "gtest/gtest.h"])
print("Extra dependencies:\n{0}".format(json.dumps(deps_map))) print("Extra dependencies:\n{0}".format(json.dumps(deps_map)))
# test for every test we found in the Makefile # test for every test we found in the Makefile

@ -25,11 +25,10 @@ def pretty_list(lst, indent=8):
class TARGETSBuilder(object): class TARGETSBuilder(object):
def __init__(self, path, gtest_dir): def __init__(self, path):
self.path = path self.path = path
self.targets_file = open(path, 'w') self.targets_file = open(path, 'w')
header = targets_cfg.rocksdb_target_header_template.format( header = targets_cfg.rocksdb_target_header_template
gtest_dir=gtest_dir)
self.targets_file.write(header) self.targets_file.write(header)
self.total_lib = 0 self.total_lib = 0
self.total_bin = 0 self.total_bin = 0
@ -39,7 +38,8 @@ class TARGETSBuilder(object):
def __del__(self): def __del__(self):
self.targets_file.close() self.targets_file.close()
def add_library(self, name, srcs, deps=None, headers=None): def add_library(self, name, srcs, deps=None, headers=None,
extra_external_deps=""):
headers_attr_prefix = "" headers_attr_prefix = ""
if headers is None: if headers is None:
headers_attr_prefix = "auto_" headers_attr_prefix = "auto_"
@ -51,7 +51,8 @@ class TARGETSBuilder(object):
srcs=pretty_list(srcs), srcs=pretty_list(srcs),
headers_attr_prefix=headers_attr_prefix, headers_attr_prefix=headers_attr_prefix,
headers=headers, headers=headers,
deps=pretty_list(deps))) deps=pretty_list(deps),
extra_external_deps=extra_external_deps))
self.total_lib = self.total_lib + 1 self.total_lib = self.total_lib + 1
def add_rocksdb_library(self, name, srcs, headers=None): def add_rocksdb_library(self, name, srcs, headers=None):

@ -85,14 +85,13 @@ ROCKSDB_PREPROCESSOR_FLAGS = [
# Directories with files for #include # Directories with files for #include
"-I" + REPO_PATH + "include/", "-I" + REPO_PATH + "include/",
"-I" + REPO_PATH, "-I" + REPO_PATH,
"-I" + REPO_PATH + "{gtest_dir}",
] ]
ROCKSDB_ARCH_PREPROCESSOR_FLAGS = {{ ROCKSDB_ARCH_PREPROCESSOR_FLAGS = {
"x86_64": [ "x86_64": [
"-DHAVE_PCLMUL", "-DHAVE_PCLMUL",
], ],
}} }
build_mode = read_config("fbcode", "build_mode") build_mode = read_config("fbcode", "build_mode")
@ -134,7 +133,7 @@ cpp_library(
os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS, os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS,
preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
deps = [{deps}], deps = [{deps}],
external_deps = ROCKSDB_EXTERNAL_DEPS, external_deps = ROCKSDB_EXTERNAL_DEPS{extra_external_deps},
) )
""" """
@ -183,18 +182,17 @@ ROCKS_TESTS = [
# Do not build the tests in opt mode, since SyncPoint and other test code # Do not build the tests in opt mode, since SyncPoint and other test code
# will not be included. # will not be included.
[ [
test_binary( cpp_unittest(
extra_compiler_flags = extra_compiler_flags, name = test_name,
extra_deps = extra_deps, srcs = [test_cc],
parallelism = parallelism, arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS,
rocksdb_arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS,
rocksdb_compiler_flags = ROCKSDB_COMPILER_FLAGS, compiler_flags = ROCKSDB_COMPILER_FLAGS,
rocksdb_external_deps = ROCKSDB_EXTERNAL_DEPS, preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS,
rocksdb_os_deps = ROCKSDB_OS_DEPS, deps = [":rocksdb_test_lib"] + extra_deps,
rocksdb_os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS, external_deps = ROCKSDB_EXTERNAL_DEPS + [
rocksdb_preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, ("googletest", None, "gtest"),
test_cc = test_cc, ],
test_name = test_name,
) )
for test_name, test_cc, parallelism, extra_deps, extra_compiler_flags in ROCKS_TESTS for test_name, test_cc, parallelism, extra_deps, extra_compiler_flags in ROCKS_TESTS
if not is_opt_mode if not is_opt_mode

Loading…
Cancel
Save