From 0fdd019f629f9b767376c4ce7847468f4fae3d2b 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, 51 insertions(+), 11 deletions(-) diff --git a/TARGETS b/TARGETS index b20fa774b..a7f8a7306 100644 --- a/TARGETS +++ b/TARGETS @@ -447,6 +447,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"], @@ -560,13 +579,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 b708173cf..6072437ce 100644 --- a/buckifier/buckify_rocksdb.py +++ b/buckifier/buckify_rocksdb.py @@ -64,8 +64,6 @@ def get_cc_files(repo_path): continue for filename in fnmatch.filter(filenames, '*.cc'): cc_files.append(os.path.join(root, filename)) - for filename in fnmatch.filter(filenames, '*.c'): - cc_files.append(os.path.join(root, filename)) return cc_files @@ -178,10 +176,18 @@ def generate_targets(repo_path, deps_map): + ["test_util/testutil.cc"]) print("Extra dependencies:\n{0}".format(json.dumps(deps_map))) - # test for every test we found in the Makefile + + # 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. + TARGETS.add_c_test() + + # test for every .cc test we found in the Makefile for target_alias, deps in deps_map.items(): for test in sorted(tests): - match_src = [src for src in cc_files if ("/%s.c" % test) in src] + if test == 'c_test': + continue + match_src = [src for src in cc_files if ("/%s.cc" % test) in src] if len(match_src) == 0: print(ColorString.warning("Cannot find .cc file for %s" % test)) continue 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,