From e0d0b49577fc221f5027e287dc444098c99c93e6 Mon Sep 17 00:00:00 2001 From: sdong Date: Thu, 2 Jul 2020 20:27:31 -0700 Subject: [PATCH] Fix test in buck test (#7076) Summary: This is to fix special logic to run tests inside FB. Buck test is broken after moving to cpp_unittest(). Move c_test back to the previous approach. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7076 Test Plan: Watch the Sandcastle run Reviewed By: ajkr Differential Revision: D22370096 fbshipit-source-id: 4a464d0903f2c76ae2de3a8ad373ffc9bedec64c --- TARGETS | 26 +++++++++++++++++++------- buckifier/buckify_rocksdb.py | 14 +++++++++++--- buckifier/targets_builder.py | 22 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/TARGETS b/TARGETS index df285d497..c7ce57fe2 100644 --- a/TARGETS +++ b/TARGETS @@ -449,6 +449,25 @@ cpp_library( external_deps = ROCKSDB_EXTERNAL_DEPS, ) +cpp_binary( + name = "c_test_bin", + srcs = ["db/c_test.c"], + arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, + os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS, + compiler_flags = ROCKSDB_COMPILER_FLAGS, + preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, + deps = [":rocksdb_test_lib"], +) + +custom_unittest( + "c_test", + command = [ + native.package_name() + "/buckifier/rocks_test_runner.sh", + "$(location :{})".format("c_test_bin"), + ], + type = "simple", +) + cpp_library( name = "env_basic_test_lib", srcs = ["env/env_basic_test.cc"], @@ -562,13 +581,6 @@ ROCKS_TESTS = [ [], [], ], - [ - "c_test", - "db/c_test.c", - "serial", - [], - [], - ], [ "cache_simulator_test", "utilities/simulator_cache/cache_simulator_test.cc", diff --git a/buckifier/buckify_rocksdb.py b/buckifier/buckify_rocksdb.py index 6bda6d409..e9704f069 100644 --- a/buckifier/buckify_rocksdb.py +++ b/buckifier/buckify_rocksdb.py @@ -166,9 +166,17 @@ def generate_targets(repo_path, deps_map): # Dictionary test executable name -> relative source file path test_source_map = {} print(src_mk) - test_main_sources = src_mk.get("TEST_MAIN_SOURCES", []) + \ - src_mk.get("TEST_MAIN_SOURCES_C", []) - for test_src in test_main_sources: + + # c_test.c is added through TARGETS.add_c_test(). If there + # are more than one .c test file, we need to extend + # TARGETS.add_c_test() to include other C tests too. + for test_src in src_mk.get("TEST_MAIN_SOURCES_C", []): + if test_src != 'db/c_test.c': + print("Don't know how to deal with " + test_src) + return False + TARGETS.add_c_test() + + for test_src in src_mk.get("TEST_MAIN_SOURCES", []): test = test_src.split('.c')[0].strip().split('/')[-1].strip() test_source_map[test] = test_src print("" + test + " " + test_src) diff --git a/buckifier/targets_builder.py b/buckifier/targets_builder.py index 980525ada..a86c0a40c 100644 --- a/buckifier/targets_builder.py +++ b/buckifier/targets_builder.py @@ -76,6 +76,28 @@ class TARGETSBuilder(object): pretty_list(deps))) self.total_bin = self.total_bin + 1 + def add_c_test(self): + self.targets_file.write(""" +cpp_binary( + name = "c_test_bin", + srcs = ["db/c_test.c"], + arch_preprocessor_flags = ROCKSDB_ARCH_PREPROCESSOR_FLAGS, + os_preprocessor_flags = ROCKSDB_OS_PREPROCESSOR_FLAGS, + compiler_flags = ROCKSDB_COMPILER_FLAGS, + preprocessor_flags = ROCKSDB_PREPROCESSOR_FLAGS, + deps = [":rocksdb_test_lib"], +) + +custom_unittest( + "c_test", + command = [ + native.package_name() + "/buckifier/rocks_test_runner.sh", + "$(location :{})".format("c_test_bin"), + ], + type = "simple", +) +""") + def register_test(self, test_name, src,