Skip to content

libroach: use gtest in unitests#20594

Merged
mberhault merged 1 commit intocockroachdb:masterfrom
mberhault:marc/add_libroach_tests
Dec 11, 2017
Merged

libroach: use gtest in unitests#20594
mberhault merged 1 commit intocockroachdb:masterfrom
mberhault:marc/add_libroach_tests

Conversation

@mberhault
Copy link
Copy Markdown
Contributor

@mberhault mberhault commented Dec 9, 2017

Release Note: none.

Add new googletest c-dep and use it for libroach unitests.
Add support for many unittests in libroach, with naming scheme based on
the dir and filename. (eg: ccl_libroach_ccl_test for ccl/libroach_ccl_test.cc)

@mberhault mberhault requested review from a team and benesch December 9, 2017 16:39
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@benesch
Copy link
Copy Markdown
Contributor

benesch commented Dec 9, 2017

Shoot, we duplicated some work here. I've got a PR that adds some tests for our C++ encoding (8aa8ce9) that's been sidelined on other, unrelated changes in the PR. My bad!

The good news is that our approach is more or less the same. I'd love to get those encoding tests merged, though, while we're adding libroach tests. @mberhault how do you want to proceed?

@benesch
Copy link
Copy Markdown
Contributor

benesch commented Dec 9, 2017

Extracted and rebased here: #20595

@mberhault
Copy link
Copy Markdown
Contributor Author

Ah! funny! Let's get yours in, the main difference is in CMakeLists and my setup with split libroach and libroachccl is premature. I'll rebase on top of yours and keep working on adding googletest.

@mberhault
Copy link
Copy Markdown
Contributor Author

Added googletest for unittests, this should be more pleasant.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you're bored, would be nice to let clang format handle these, but it totally mangles cases64 IMO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be able to drop this variable now!

@mberhault mberhault force-pushed the marc/add_libroach_tests branch 4 times, most recently from f96bb11 to 4e57fc7 Compare December 9, 2017 22:21
@mberhault mberhault changed the title libroach: add unittest targets for libroach libroach: use gtest in unitests Dec 9, 2017
@mberhault mberhault force-pushed the marc/add_libroach_tests branch from 4e57fc7 to 6ad711f Compare December 9, 2017 22:27
@mberhault
Copy link
Copy Markdown
Contributor Author

@benesch: rebased on your change, PTAL.

Not much to be done about clang formatting I'm afraid. We can change some of the line merging things (eg: no one-line functions), but ultimately it parses everything then re-generates it from the AST so any arbitrary whitespace formatting is lost.

@mberhault mberhault force-pushed the marc/add_libroach_tests branch 4 times, most recently from 4bf9684 to 3b7880c Compare December 10, 2017 16:07
Makefile Outdated
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is weird, Cmake fails when cross-compiling (acceptance tests for some reason). This is kind of the accepted answer (mentioned in the failure itself). I need the absolute path as we're running cmake from the temp build dir.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ugh, what a pain! I think we can at least avoid some of the complexity, though, by dropping

set(THREADS_PTHREAD_ARG "2" CACHE STRING "Forcibly set by CMakeLists.txt." FORCE)

into libroach's CMakeLists.txt instead of introducing the whole cachefile kit and caboodle.

Could you also add a comment linking to https://gitlab.kitware.com/cmake/cmake/issues/16920? Looks like this is fixed in CMake 3.10 and so this workaround should eventually become unnecessary.

Copy link
Copy Markdown
Contributor

@benesch benesch left a comment

Choose a reason for hiding this comment

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

I think you're doing too much work! Both CMake and the top-level Makefile are building googletest AFAICT.

There are two options I see:

  • Let CMake handle building libgtest by simply removing all references to googletest from the top-level Makefile. In this case I think we should move the submodule to c-deps/libroach/googletest.
  • Let top-level Make handle building libgtest, and set the library search paths appropriately for libroach, and potentially other libraries whose tests need libgtest, like Snappy.

I have a slight preference for the first option since it's simpler and we don't actually care about running Snappy's tests, but I don't have strong feelings.

CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
COMPILE_OPTIONS "-Werror;-Wall;-Wno-sign-compare"
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shoot, I wish there were some way to share these properties across all targets. I don't know enough CMake to suggest a better alternative, though.

Copy link
Copy Markdown
Contributor Author

@mberhault mberhault Dec 10, 2017

Choose a reason for hiding this comment

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

yeah, I'm still fuzzy here, I've been meaning to check the rules for non-target properties. Is it "everything" after this point?

Makefile Outdated

PHONY: check-libroach
check-libroach: $(LIBROACH_DIR)/Makefile
check-libroach: $(LIBROACH_DIR)/Makefile libgtest
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By my read, this libgtest is built into ~/go/native/TRIPLE/googletest and is actually entirely ignored by libroach's CMake, which builds its own version at ~/go/native/TRIPLE/libroach/googletest thanks to the magic of add_subdirectory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See main comment: our cmake doesn't build googletest, it just needs a built library it can link in. This is what add_subdirectory does.

@mberhault
Copy link
Copy Markdown
Contributor Author

Our cmake uses the built googletest by calling add_subdirectory, it does not build it. It is possible to have cmake build it from source, but it's just as tedious (more so even, especially when you're not using a subdirectory).
The only thing our cmake does it look for googletest and finds the correct include and lib directories.

@benesch
Copy link
Copy Markdown
Contributor

benesch commented Dec 10, 2017 via email

@mberhault
Copy link
Copy Markdown
Contributor Author

Ok, ditto. I'm also very very confused, but that summarizes my week-end pretty well.
I'm pushing a commit with the main makefile changes reverted (except for that annoying cmake cache crap). Let's see how it goes. I'm just hoping the success isn't an artifact of my build caching, but that shouldn't impact you.

@mberhault
Copy link
Copy Markdown
Contributor Author

Ok, all green. Damn, I need to read up on cmake I guess.
I'll squash and push again.

@mberhault mberhault force-pushed the marc/add_libroach_tests branch 2 times, most recently from 36e0ddb to 55747d6 Compare December 11, 2017 02:24
@@ -0,0 +1,3 @@
# Cross-compilation does strange things with CMake. Tell it the pthreads check passes.
set(THREADS_PTHREAD_ARG "0" CACHE STRING "Result from TRY_RUN" FORCE)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By my read of https://github.com/Kitware/CMake/blob/v3.9.0/Modules/FindThreads.cmake, don't you want to set this to "2", not "0"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, I've tried a number of things, including setting it in the libroach cmake only. The only thing that's worked so far is setting it as a cache preset using -C. I honestly don't want to play with this crap again. It's broken, and this fixes it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ugh, now it works. Let's see if TC agrees.

Makefile Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ugh, what a pain! I think we can at least avoid some of the complexity, though, by dropping

set(THREADS_PTHREAD_ARG "2" CACHE STRING "Forcibly set by CMakeLists.txt." FORCE)

into libroach's CMakeLists.txt instead of introducing the whole cachefile kit and caboodle.

Could you also add a comment linking to https://gitlab.kitware.com/cmake/cmake/issues/16920? Looks like this is fixed in CMake 3.10 and so this workaround should eventually become unnecessary.

Copy link
Copy Markdown
Contributor

@benesch benesch left a comment

Choose a reason for hiding this comment

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

Amazing, LGTM! Sorry this was such a chore.

Probably worth getting someone else to buy in on the googletest dependency too.

@mberhault
Copy link
Copy Markdown
Contributor Author

mberhault commented Dec 11, 2017

TFTR!
You mean the location of the googletest tree? I think keeping the submodule in the same place as all the others is least surprising. But a point could be made for sticking it in libroach/

@bdarnell: any thoughts?

@benesch
Copy link
Copy Markdown
Contributor

benesch commented Dec 11, 2017 via email

@mberhault
Copy link
Copy Markdown
Contributor Author

I don't think there is, and anything that can make unit testing easier is good in my book.

@benesch
Copy link
Copy Markdown
Contributor

benesch commented Dec 11, 2017

Mk, SGTM.

@mberhault
Copy link
Copy Markdown
Contributor Author

Peter doesn't care. Squashing and rebuilding.

Release note: None

Add new `googletest` c-dep and use it for libroach unitests.
Add support for many unittests in libroach, with naming scheme based on
the dir and filename. (eg: `ccl_libroach_ccl_test` for
`ccl/libroach_ccl_test.cc`)
@mberhault mberhault force-pushed the marc/add_libroach_tests branch from c1a74d1 to 2d310c7 Compare December 11, 2017 16:09
@mberhault mberhault merged commit f9e5a08 into cockroachdb:master Dec 11, 2017
@mberhault mberhault deleted the marc/add_libroach_tests branch December 11, 2017 17:24
irfansharif added a commit to irfansharif/cockroach that referenced this pull request Oct 23, 2020
We don't need it anymore. We originally introduced it to support tests
in libroach (cockroachdb#20594), which has since been pared down to something much
simpler (cockroachdb#55509, just DBDumpThreadStacks).

Release note: None
craig bot pushed a commit that referenced this pull request Oct 23, 2020
55900: c-deps: remove googletest r=irfansharif a=irfansharif

We don't need it anymore. We originally introduced it to support tests
in libroach (#20594), which has since been pared down to something much
simpler (#55509, just DBDumpThreadStacks).

Release note: None

Co-authored-by: irfan sharif <irfanmahmoudsharif@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants