Skip to content

Commit

Permalink
Build googletest only if testing or basic benchmarking are enabled (f…
Browse files Browse the repository at this point in the history
…acebookincubator#1666)

Summary:
Also, adds a dummy definition for`FRIEND_TEST` when googletest is disabled.
Resolves facebookincubator#1654

Pull Request resolved: facebookincubator#1666

Reviewed By: kgpai

Differential Revision: D36664732

Pulled By: mbasmanova

fbshipit-source-id: a08859f96f68d5bc9d2c5092be6f7f397508706f
  • Loading branch information
majetideepak authored and U-CCR\zhenhuiz committed Jun 21, 2022
1 parent 6d22844 commit 42d21e1
Show file tree
Hide file tree
Showing 24 changed files with 98 additions and 80 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ if(VELOX_BUILD_TESTING AND NOT VELOX_ENABLE_DUCKDB)
)
endif()

# Benchmarks and tests at some places are coupled which is not great. See
# velox/vector/CMakeLists.txt. TODO: Decouple.
set(VELOX_DISABLE_GOOGLETEST OFF)
if(NOT VELOX_BUILD_TESTING AND NOT VELOX_ENABLE_BENCHMARKS_BASIC)
set(VELOX_DISABLE_GOOGLETEST ON)
add_definitions(-DVELOX_DISABLE_GOOGLETEST)
endif()

include_directories(SYSTEM velox)
include_directories(SYSTEM velox/external)
include_directories(SYSTEM velox/external/duckdb)
Expand Down
6 changes: 5 additions & 1 deletion third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_subdirectory(googletest)

if(NOT VELOX_DISABLE_GOOGLETEST)
add_subdirectory(googletest)
endif()

add_subdirectory(xsimd)
2 changes: 0 additions & 2 deletions velox/benchmarks/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ set(velox_benchmark_deps
${FOLLY}
${FOLLY_BENCHMARK}
${DOUBLE_CONVERSION}
gtest
gtest_main
${gflags_LIBRARIES}
glog::glog)

Expand Down
3 changes: 0 additions & 3 deletions velox/benchmarks/tpch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ target_link_libraries(
velox_type
velox_caching
velox_vector
velox_vector_test_lib
gtest
gtest_main
${FOLLY_WITH_DEPENDENCIES}
${FOLLY_BENCHMARK}
${FMT})
26 changes: 26 additions & 0 deletions velox/common/base/GTestMacros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#ifdef VELOX_DISABLE_GOOGLETEST
// VELOX_FRIEND_TEST macro is only used when testing is enabled.
// Replacing it with "nothing" is okay when testing is disabled.
#define VELOX_FRIEND_TEST(X, Y)
#else
#include <gtest/gtest_prod.h>
#define VELOX_FRIEND_TEST(X, Y) FRIEND_TEST(X, Y)
#endif
4 changes: 4 additions & 0 deletions velox/common/memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ add_library(

target_link_libraries(velox_memory velox_flag_definitions velox_exception gtest
${FOLLY_WITH_DEPENDENCIES})

if(NOT VELOX_DISABLE_GOOGLETEST)
target_link_libraries(velox_memory gtest)
endif()
17 changes: 8 additions & 9 deletions velox/common/memory/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
#include <string>

#include <fmt/format.h>
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <gtest/gtest_prod.h>

#include "folly/CPortability.h"
#include "folly/Likely.h"
#include "folly/Random.h"
#include "folly/SharedMutex.h"
#include "folly/experimental/FunctionScheduler.h"
#include "velox/common/base/GTestMacros.h"
#include "velox/common/memory/MemoryUsage.h"
#include "velox/common/memory/MemoryUsageTracker.h"

Expand Down Expand Up @@ -406,7 +405,7 @@ class MemoryPoolImpl : public MemoryPoolBase {
int64_t getSubtreeMaxBytes() const;

private:
FRIEND_TEST(MemoryPoolTest, Ctor);
VELOX_FRIEND_TEST(MemoryPoolTest, Ctor);

template <uint16_t A>
struct ALIGNER {};
Expand Down Expand Up @@ -549,12 +548,12 @@ class MemoryManager final : public IMemoryManager {
Allocator& getAllocator();

private:
FRIEND_TEST(MemoryPoolImplTest, CapSubtree);
FRIEND_TEST(MemoryPoolImplTest, CapAllocation);
FRIEND_TEST(MemoryPoolImplTest, UncapMemory);
FRIEND_TEST(MemoryPoolImplTest, MemoryManagerGlobalCap);
FRIEND_TEST(MultiThreadingUncappingTest, Flat);
FRIEND_TEST(MultiThreadingUncappingTest, SimpleTree);
VELOX_FRIEND_TEST(MemoryPoolImplTest, CapSubtree);
VELOX_FRIEND_TEST(MemoryPoolImplTest, CapAllocation);
VELOX_FRIEND_TEST(MemoryPoolImplTest, UncapMemory);
VELOX_FRIEND_TEST(MemoryPoolImplTest, MemoryManagerGlobalCap);
VELOX_FRIEND_TEST(MultiThreadingUncappingTest, Flat);
VELOX_FRIEND_TEST(MultiThreadingUncappingTest, SimpleTree);

std::shared_ptr<Allocator> allocator_;
const int64_t memoryQuota_;
Expand Down
22 changes: 11 additions & 11 deletions velox/dwio/common/ChainedBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#pragma once

#include <gtest/gtest_prod.h>
#include <bitset>
#include "velox/common/base/GTestMacros.h"
#include "velox/dwio/common/DataBuffer.h"

namespace facebook {
Expand Down Expand Up @@ -202,16 +202,16 @@ class ChainedBuffer {
return val + 1;
}

FRIEND_TEST(ChainedBufferTests, testCreate);
FRIEND_TEST(ChainedBufferTests, testReserve);
FRIEND_TEST(ChainedBufferTests, testAppend);
FRIEND_TEST(ChainedBufferTests, testClear);
FRIEND_TEST(ChainedBufferTests, testGetPage);
FRIEND_TEST(ChainedBufferTests, testGetPageIndex);
FRIEND_TEST(ChainedBufferTests, testGetPageOffset);
FRIEND_TEST(ChainedBufferTests, testBitCount);
FRIEND_TEST(ChainedBufferTests, testTrailingZeros);
FRIEND_TEST(ChainedBufferTests, testPowerOf2);
VELOX_FRIEND_TEST(ChainedBufferTests, testCreate);
VELOX_FRIEND_TEST(ChainedBufferTests, testReserve);
VELOX_FRIEND_TEST(ChainedBufferTests, testAppend);
VELOX_FRIEND_TEST(ChainedBufferTests, testClear);
VELOX_FRIEND_TEST(ChainedBufferTests, testGetPage);
VELOX_FRIEND_TEST(ChainedBufferTests, testGetPageIndex);
VELOX_FRIEND_TEST(ChainedBufferTests, testGetPageOffset);
VELOX_FRIEND_TEST(ChainedBufferTests, testBitCount);
VELOX_FRIEND_TEST(ChainedBufferTests, testTrailingZeros);
VELOX_FRIEND_TEST(ChainedBufferTests, testPowerOf2);
};

} // namespace common
Expand Down
4 changes: 2 additions & 2 deletions velox/dwio/dwrf/common/IntEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#pragma once

#include <folly/Varint.h>
#include <gtest/gtest_prod.h>
#include "velox/common/base/BitUtil.h"
#include "velox/common/base/GTestMacros.h"
#include "velox/common/base/Nulls.h"
#include "velox/common/encode/Coding.h"
#include "velox/dwio/dwrf/common/IntCodecCommon.h"
Expand Down Expand Up @@ -197,7 +197,7 @@ class IntEncoder {
FOLLY_ALWAYS_INLINE int32_t writeVslong(int64_t value, char* buffer);
FOLLY_ALWAYS_INLINE int32_t writeLongLE(int64_t value, char* buffer);

FRIEND_TEST(TestIntEncoder, TestVarIntEncoder);
VELOX_FRIEND_TEST(TestIntEncoder, TestVarIntEncoder);
};

#define WRITE_INTS(FUNC) \
Expand Down
6 changes: 3 additions & 3 deletions velox/dwio/dwrf/common/RLEv1.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#include <gtest/gtest_prod.h>
#include "velox/common/base/GTestMacros.h"
#include "velox/common/base/Nulls.h"
#include "velox/dwio/dwrf/common/Adaptor.h"
#include "velox/dwio/dwrf/common/DecoderUtil.h"
Expand Down Expand Up @@ -198,8 +198,8 @@ class RleEncoderV1 : public IntEncoder<isSigned> {
}
}

FRIEND_TEST(RleEncoderV1Test, encodeMinAndMax);
FRIEND_TEST(RleEncoderV1Test, encodeMinAndMaxint32);
VELOX_FRIEND_TEST(RleEncoderV1Test, encodeMinAndMax);
VELOX_FRIEND_TEST(RleEncoderV1Test, encodeMinAndMaxint32);
};

template <bool isSigned>
Expand Down
6 changes: 3 additions & 3 deletions velox/dwio/dwrf/common/Range.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#include <gtest/gtest_prod.h>
#include "velox/common/base/GTestMacros.h"
#include "velox/dwio/common/exception/Exception.h"

namespace facebook::velox::dwrf {
Expand Down Expand Up @@ -120,8 +120,8 @@ class Ranges {
std::vector<std::tuple<size_t, size_t>> ranges_;
size_t size_{0};

FRIEND_TEST(RangeTests, Add);
FRIEND_TEST(RangeTests, Filter);
VELOX_FRIEND_TEST(RangeTests, Add);
VELOX_FRIEND_TEST(RangeTests, Filter);
};

} // namespace facebook::velox::dwrf
5 changes: 2 additions & 3 deletions velox/dwio/dwrf/reader/StripeDictionaryCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

#pragma once

#include <gtest/gtest_prod.h>

#include <folly/Function.h>

#include "velox/common/base/GTestMacros.h"
#include "velox/dwio/dwrf/common/Common.h"
#include "velox/dwio/dwrf/common/IntDecoder.h"
#include "velox/vector/BaseVector.h"
Expand Down Expand Up @@ -59,7 +58,7 @@ class StripeDictionaryCache {
EncodingKeyHash>
intDictionaryFactories_;

FRIEND_TEST(TestStripeDictionaryCache, RegisterDictionary);
VELOX_FRIEND_TEST(TestStripeDictionaryCache, RegisterDictionary);
};

} // namespace facebook::velox::dwrf
2 changes: 1 addition & 1 deletion velox/dwio/dwrf/test/TestWriterFlush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class DummyWriter : public velox::dwrf::WriterShared {
MOCK_METHOD0(resetImpl, void());

friend class WriterFlushTestHelper;
FRIEND_TEST(TestWriterFlush, CheckAgainstMemoryBudget);
VELOX_FRIEND_TEST(TestWriterFlush, CheckAgainstMemoryBudget);
};

// Big idea is to directly manipulate context states (num rows) + memory pool
Expand Down
5 changes: 2 additions & 3 deletions velox/dwio/dwrf/writer/ColumnWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

#pragma once

#include "gtest/gtest_prod.h"

#include "velox/common/base/GTestMacros.h"
#include "velox/dwio/dwrf/common/ByteRLE.h"
#include "velox/dwio/dwrf/common/Common.h"
#include "velox/dwio/dwrf/common/IntEncoder.h"
Expand Down Expand Up @@ -226,7 +225,7 @@ class ColumnWriter {
// in_map stream
const std::function<void(IndexBuilder&)> onRecordPosition_;

FRIEND_TEST(ColumnWriterTests, LowMemoryModeConfig);
VELOX_FRIEND_TEST(ColumnWriterTests, LowMemoryModeConfig);
friend class ValueStatisticsBuilder;
};

Expand Down
1 change: 0 additions & 1 deletion velox/dwio/dwrf/writer/IndexBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#pragma once

#include <gtest/gtest_prod.h>
#include "velox/dwio/dwrf/common/OutputStream.h"
#include "velox/dwio/dwrf/common/wrap/dwrf-proto-wrapper.h"
#include "velox/dwio/dwrf/writer/StatisticsBuilder.h"
Expand Down
8 changes: 4 additions & 4 deletions velox/dwio/dwrf/writer/IntegerDictionaryEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#pragma once

#include <folly/container/F14Set.h>
#include <gtest/gtest_prod.h>
#include "velox/common/base/GTestMacros.h"
#include "velox/dwio/common/DataBuffer.h"
#include "velox/dwio/dwrf/common/IntEncoder.h"
#include "velox/dwio/dwrf/writer/DictionaryEncodingUtils.h"
Expand Down Expand Up @@ -275,9 +275,9 @@ class IntegerDictionaryEncoder : public AbstractIntegerDictionaryEncoder {
}

private:
FRIEND_TEST(TestIntegerDictionaryEncoder, Clear);
FRIEND_TEST(TestIntegerDictionaryEncoder, GetCount);
FRIEND_TEST(TestWriterContext, GetIntDictionaryEncoder);
VELOX_FRIEND_TEST(TestIntegerDictionaryEncoder, Clear);
VELOX_FRIEND_TEST(TestIntegerDictionaryEncoder, GetCount);
VELOX_FRIEND_TEST(TestWriterContext, GetIntDictionaryEncoder);

// TODO: partially specialize for integers only.
template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion velox/dwio/dwrf/writer/LayoutPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LayoutPlanner {
static void sort(StreamList::iterator begin, StreamList::iterator end);
};

FRIEND_TEST(LayoutPlannerTests, Basic);
VELOX_FRIEND_TEST(LayoutPlannerTests, Basic);
};

} // namespace facebook::velox::dwrf
11 changes: 6 additions & 5 deletions velox/dwio/dwrf/writer/StringDictionaryEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

#include <folly/container/F14Set.h>
#include <folly/hash/Checksum.h>
#include <gtest/gtest_prod.h>

#include "velox/common/base/GTestMacros.h"
#include "velox/dwio/common/DataBuffer.h"

namespace facebook::velox::dwrf {
Expand Down Expand Up @@ -171,10 +172,10 @@ class StringDictionaryEncoder {
}

private:
FRIEND_TEST(TestStringDictionaryEncoder, GetCount);
FRIEND_TEST(TestStringDictionaryEncoder, GetIndex);
FRIEND_TEST(TestStringDictionaryEncoder, GetStride);
FRIEND_TEST(TestStringDictionaryEncoder, Clear);
VELOX_FRIEND_TEST(TestStringDictionaryEncoder, GetCount);
VELOX_FRIEND_TEST(TestStringDictionaryEncoder, GetIndex);
VELOX_FRIEND_TEST(TestStringDictionaryEncoder, GetStride);
VELOX_FRIEND_TEST(TestStringDictionaryEncoder, Clear);

// Intended for testing only.
uint32_t getIndex(folly::StringPiece sp) {
Expand Down
4 changes: 2 additions & 2 deletions velox/dwio/dwrf/writer/WriterBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#pragma once

#include "gtest/gtest_prod.h"
#include "velox/common/base/GTestMacros.h"
#include "velox/dwio/dwrf/writer/WriterContext.h"
#include "velox/dwio/dwrf/writer/WriterSink.h"

Expand Down Expand Up @@ -163,7 +163,7 @@ class WriterBase {
void writeUserMetadata(uint32_t writerVersion);

friend class WriterTest;
FRIEND_TEST(WriterBaseTest, FlushWriterSinkUponClose);
VELOX_FRIEND_TEST(WriterBaseTest, FlushWriterSinkUponClose);
};

} // namespace facebook::velox::dwrf
7 changes: 3 additions & 4 deletions velox/dwio/dwrf/writer/WriterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

#pragma once

#include <gtest/gtest_prod.h>

#include "velox/common/base/GTestMacros.h"
#include "velox/common/time/CpuWallTimer.h"
#include "velox/dwio/dwrf/common/Compression.h"
#include "velox/dwio/dwrf/writer/IndexBuilder.h"
Expand Down Expand Up @@ -498,8 +497,8 @@ class WriterContext : public CompressionBufferPool {
friend class IntegerColumnWriterDirectEncodingIndexTest;
friend class StringColumnWriterDictionaryEncodingIndexTest;
friend class StringColumnWriterDirectEncodingIndexTest;
FRIEND_TEST(TestWriterContext, GetIntDictionaryEncoder);
FRIEND_TEST(TestWriterContext, RemoveIntDictionaryEncoderForNode);
VELOX_FRIEND_TEST(TestWriterContext, GetIntDictionaryEncoder);
VELOX_FRIEND_TEST(TestWriterContext, RemoveIntDictionaryEncoderForNode);
// TODO: remove once writer code is consolidated
template <typename TestType>
friend class WriterEncodingIndexTest2;
Expand Down
7 changes: 3 additions & 4 deletions velox/dwio/dwrf/writer/WriterShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#include <iterator>
#include <limits>

#include <gtest/gtest_prod.h>

#include "velox/common/base/GTestMacros.h"
#include "velox/dwio/dwrf/common/Encryption.h"
#include "velox/dwio/dwrf/common/wrap/dwrf-proto-wrapper.h"
#include "velox/dwio/dwrf/proto/dwrf_proto.pb.h"
Expand Down Expand Up @@ -65,8 +64,8 @@ class EncodingIter {

void next();

FRIEND_TEST(TestEncodingIter, Ctor);
FRIEND_TEST(TestEncodingIter, EncodingIterBeginAndEnd);
VELOX_FRIEND_TEST(TestEncodingIter, Ctor);
VELOX_FRIEND_TEST(TestEncodingIter, EncodingIterBeginAndEnd);
bool emptyEncryptionGroups() const;

const proto::StripeFooter& footer_;
Expand Down
Loading

0 comments on commit 42d21e1

Please sign in to comment.