Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build googletest only if testing or basic benchmarking are enabled #1666

Closed
wants to merge 7 commits into from

Conversation

majetideepak
Copy link
Collaborator

@majetideepak majetideepak commented May 20, 2022

Also, adds a dummy definition forFRIEND_TEST when googletest is disabled.
Resolves #1654

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 20, 2022
Copy link
Contributor

@amitkdutta amitkdutta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loos good to me.

@majetideepak
Copy link
Collaborator Author

majetideepak commented May 20, 2022

@amitkdutta thanks for the review. Looks like there are a couple of more FRIEND_TEST uses. I will fix them shortly.

@majetideepak majetideepak force-pushed the fix-googletest branch 2 times, most recently from cb8f53d to 6d6beb9 Compare May 20, 2022 23:30
@majetideepak majetideepak changed the title Build googletest only if testing is enabled Build googletest only if testing or basic benchmarking are enabled May 21, 2022
@majetideepak
Copy link
Collaborator Author

@amitkdutta can you take another look? The S3 test failure is unrelated.

@majetideepak majetideepak requested review from amitkdutta and kgpai May 23, 2022 17:26
@majetideepak
Copy link
Collaborator Author

@kgpai @amitkdutta can you take another look at this?

@majetideepak majetideepak requested a review from mbasmanova May 25, 2022 13:09
Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -292,6 +292,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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, file an issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#ifdef VELOX_ENABLE_GOOGLETEST
#include <gtest/gtest_prod.h>
#else
#define FRIEND_TEST(X, Y)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Perhaps, add a comment to explain why is it Ok to replace this macro with "nothing".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Thanks.

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@kgpai kgpai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks Deepak.

@mbasmanova
Copy link
Contributor

I'm getting errors:

buck-out/v2/gen/fbcode/c6b399001575978c/velox/common/base/__velox_common_base__/headers/velox/common/base/GTestMacros.h:24:9: error: 'FRIEND_TEST' macro redefined [-Werror,-Wmacro-redefined]
#define FRIEND_TEST(X, Y)

@majetideepak
Copy link
Collaborator Author

@mbasmanova Can you share some more context from the error log. Does it see the previous definition from the gtest header? Thanks.

@mbasmanova
Copy link
Contributor

@majetideepak Here is what I get:

In file included from velox/common/memory/Memory.h:34:
velox/common/base/GTestMacros.h:24:9: error: 'FRIEND_TEST' macro redefined [-Werror,-Wmacro-redefined]
#define FRIEND_TEST(X, Y)
        ^
third-party-buck/platform009/build/googletest/include/gtest/gtest_prod.h:58:9: note: previous definition is here
#define FRIEND_TEST(test_case_name, test_name)\
        ^
1 error generated.

@mbasmanova
Copy link
Contributor

I assume something else is including gtest_prod.h

@mbasmanova
Copy link
Contributor

Maybe add an #ifndef guard?

@mbasmanova
Copy link
Contributor

Getting more errors

Xxx.h:536:3: error: ambiguous expansion of macro 'FRIEND_TEST' [-Werror,-Wambiguous-macro]
  FRIEND_TEST(ConfigTest, ParseScopeResolutionCondition);
  ^

@mbasmanova
Copy link
Contributor

I wonder if we end up having one definition is some cases and another in other cases.

@mbasmanova
Copy link
Contributor

I'm not sure how to make this work given that we cannot change all the code to replace gtest.h with GTestMacros.h

CC: @kgpai @Yuhta


#pragma once

#ifdef VELOX_ENABLE_GOOGLETEST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? Shouldn't we just not compile the code that includes gtest unless a specific variable is set?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you observed, FRIEND_TEST is coupled with non-test code.

@@ -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(VELOX_ENABLE_GOOGLETEST)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use VELOX_BUILD_TESTING here?

Copy link
Collaborator Author

@majetideepak majetideepak May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since googletest is needed by both VELOX_BUILD_TESTING and VELOX_ENABLE_BENCHMARKS_BASIC as some of the benchmarks are coupled with the test classes.
So VELOX_ENABLE_GOOGLETEST is a proxy for either.

@mbasmanova
Copy link
Contributor

I wonder if we could get rid of usages of FRIEND_TEST macro altogether.

@mbasmanova
Copy link
Contributor

Tight coupling that is created by using FRIEND_TEST macro doesn't feel quite right.

@mbasmanova
Copy link
Contributor

One option might be to introduce a new macro VELOX_FRIEND_TEST and define it as nothing if VELOX_BUILD_TESTING is off and FRIEND_TEST if on.

@majetideepak
Copy link
Collaborator Author

majetideepak commented May 25, 2022

One option might be to introduce a new macro VELOX_FRIEND_TEST and define it as nothing if VELOX_BUILD_TESTING is off and FRIEND_TEST if on.

FRIEND_TEST macro is really simple (see below) and I don't think VELOX_FRIEND_TEST is going to help much.
The real problem is the gtest_prod.h header included directly in the source code without a guard. If we can replace them with GTestMacros.h, it should resolve these issues.

https://github.com/google/googletest/blob/main/googletest/include/gtest/gtest_prod.h#L57

#define FRIEND_TEST(test_case_name, test_name)\
friend class test_case_name##_##test_name##_Test

@mbasmanova
Copy link
Contributor

If we can replace them with GTestMacros.h, it should resolve these issues.

Unfortunately, there are way too many places to update for this to be practical. @kgpai @Yuhta Krishna, Jimmy, what do you think?

@majetideepak
Copy link
Collaborator Author

Unfortunately, there are way too many places to update for this to be practical.

I see your point. Then changing FRIEND_TEST to VELOX_FRIEND_TEST should help. I will make this change.

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.


#pragma once

#ifdef VELOX_ENABLE_GOOGLETEST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is possible to have this ON by default. Otherwise, I'll need to figure out how too enable this for all the libraries that use it internally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this. Let me know if it does not work.


#pragma once

#ifdef VELOX_ENABLE_GOOGLETEST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have been clearer. I think I need #include <gtest/gtest_prod.h> to happen by default, e.g. without setting any variable as I don't have these variables in the internal build files. Is this possible?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. maybe we could have VELOX_DISABLE_GOOGLETEST variable instead of VELOX_ENABLE_GOOGLETEST

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change. I realized it should work for non-CMake systems as well by default.

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@wenleix
Copy link
Contributor

wenleix commented May 31, 2022

TorchArrow build starts to fail after submodule update to this commit: https://github.com/facebookresearch/torcharrow/runs/6605394261?check_suite_focus=true (Velox submodule commit: 118feb5), since velox/common/memory/Memory.h includes gtest/gtest_prod.h:

In file included from /home/runner/work/torcharrow/torcharrow/csrc/velox/velox/velox/common/memory/Memory.h:34,
                 from /home/runner/work/torcharrow/torcharrow/csrc/velox/lib.cpp:12:
/home/runner/work/torcharrow/torcharrow/csrc/velox/velox/velox/common/base/GTestMacros.h:24:10: fatal error: gtest/gtest_prod.h: No such file or directory

Build succeed with the previous commit (3591bbe) : https://github.com/facebookresearch/torcharrow/runs/6604765945?check_suite_focus=true

Looks like VELOX_MINIMAL should automatically enable VELOX_DISABLE_GOOGLETEST . Looking into.

cc @kgpai

@amitkdutta
Copy link
Contributor

@majetideepak @kgpai Presto CPP builds are failing as well.

velox/velox/dwio/dwrf/test/utils/E2EWriterTestUtil.cpp:19:10: fatal error: gtest/gtest.h: No such file or directory

https://app.circleci.com/pipelines/github/facebookexternal/presto_cpp/5216/workflows/0eddd571-7781-43f5-b5eb-392d97197a3e/jobs/19922

@wenleix
Copy link
Contributor

wenleix commented Jun 1, 2022

@amitkdutta I found manually set compiler flag VELOX_DISABLE_GOOGLETEST at TorchArrow CMakeFile level would make it build: pytorch/torcharrow#352 .

Basically there is

target_compile_definitions(
  _torcharrow
  PRIVATE
  VELOX_DISABLE_GOOGLETEST
)

(it needs #1745 to avoid linker error)


My guess (I am a CMake noob so I can be totally wrong) the compiler flag set at

add_definitions(-DVELOX_DISABLE_GOOGLETEST)
doesn't affects the outer-level project compiler flag (e.g. presto-cpp and torcharrow use Velox as submodule, thus their compiler flag doesn't get VELOX_DISABLE_GOOGLETEST set on )


Update: never mind, presto-cpp indeed needs GTest; this is different from TorchArrow

@majetideepak
Copy link
Collaborator Author

@amitkdutta #1738 should fix the presto_cpp failure

@majetideepak majetideepak deleted the fix-googletest branch June 16, 2022 18:37
zhejiangxiaomai pushed a commit to zhejiangxiaomai/velox that referenced this pull request Jun 21, 2022
…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
shiyu-bytedance pushed a commit to shiyu-bytedance/velox-1 that referenced this pull request Aug 18, 2022
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Googletest dependencies must be guarded
6 participants