Introduce GoogleTest for Valkey unit testing#3241
Merged
madolson merged 10 commits intovalkey-io:unstablefrom Feb 26, 2026
Merged
Introduce GoogleTest for Valkey unit testing#3241madolson merged 10 commits intovalkey-io:unstablefrom
madolson merged 10 commits intovalkey-io:unstablefrom
Conversation
### This PR adds GoogleTest (gtest) support to Valkey to enable writing modern unit tests. **Motivation**: GoogleTest provides richer assertions, test fixtures, mocking support, and improved diagnostics, helping improve test coverage and maintainability over time. **Summary**: The change is limited to test infrastructure, and existing C unit tests remain unchanged. This PR focuses only on integrating the framework and includes a small set of example tests to demonstrate usage. For more details, see `src/gtest/README.md`. --------- Signed-off-by: Harry Lin <harrylhl@amazon.com> Signed-off-by: Madelyn Olson <madelyneolson@gmail.com> Signed-off-by: Harry Lin <49881386+harrylin98@users.noreply.github.com> Co-authored-by: Harry Lin <harrylhl@amazon.com> Co-authored-by: Jim Brunner <brunnerj@amazon.com> Co-authored-by: Madelyn Olson <madelyneolson@gmail.com> Co-authored-by: Jacob Murphy <jkmurphy@google.com>
This PR fixes the issue where changes to src files did not trigger a rebuild of libvalkey.a when rerunning `make test-gtest`. It also resolves the problem where unchanged .cpp test files were unnecessarily recompiled during make test-gtest. Now: If nothing changed: - Nothing rebuilds, no relinking occurs. If only C++ test files changed: - Both libvalkey.a and C++ test files recompile (because release.o changes) - Test executable relinks If only src code changed: - Only libvalkey.a rebuilds - C++ test files do not recompile - Test executable relinks If both changed: - Both libvalkey.a and C++ test files rebuild - Test executable relinks Signed-off-by: Harry Lin <harrylhl@amazon.com> Co-authored-by: Harry Lin <harrylhl@amazon.com>
Resolved conflicts by merging both gtest and libbacktrace features: - ci.yml: Combined gtest dependencies with libbacktrace support - Makefile: Added libbacktrace configuration alongside gtest-parallel - daily.yml: Merged g++-multilib with libbacktrace build steps All build configurations now support both USE_LIBBACKTRACE and gtest unit tests.
## Overview: This PR converted existing C unit tests to GTEST based on this introduction of GoogleTest framework valkey-io#2956 , as mentioned in valkey-io#2878 . ## Details: 1. Kept the previous test logic as much as possible, also kept all original comments from C unit tests. 2. Deleted C unit tests. 3. Changed headers: include "generated_wrappers.hpp" and remove all header files already in "generated_wrappers.hpp". 4. Used extern "C" to wrap the C include files to prevent name mangling. 5. Added Test Fixture with Setup/Teardown. ## Notes: 1. `ustime` is included in `util.h`, so deleted some duplicated `ustime`. 2. A lot of C tests include `.c` files directly to use static functions, but we don't want to copy static functions from `.c` to `.cpp`, so I added wrapper functions (prefix: `testOnly`) to `.c` to use in `.cpp` file. 3. Some C tests have shared state which is incompatible with gtest-parallel, so I changed them to isolated tests. (e.g. in `test_dict.cpp`, I made `_dict` an instance variable created fresh in SetUp() for each test, and added back the necessary setup code to each test so they can run independently in any order or in parallel). ## Testing: * GTEST: 253 tests + 32 disabled tests (285 tests in total) all pass --------- Signed-off-by: Alina Liu <liusalisa6363@gmail.com> Signed-off-by: Harry Lin <harrylhl@amazon.com> Signed-off-by: Harry Lin <49881386+harrylin98@users.noreply.github.com> Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com> Co-authored-by: Harry Lin <harrylhl@amazon.com> Co-authored-by: Harry Lin <49881386+harrylin98@users.noreply.github.com> Co-authored-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
Signed-off-by: Harry Lin <harrylhl@amazon.com> Signed-off-by: Harry Lin <49881386+harrylin98@users.noreply.github.com> Signed-off-by: Alina Liu <liusalisa6363@gmail.com> Signed-off-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com> Co-authored-by: Harry Lin <harrylhl@amazon.com> Co-authored-by: Madelyn Olson <madelyneolson@gmail.com> Co-authored-by: Alina Liu <liusalisa6363@gmail.com> Co-authored-by: Alina Liu <alinalq@dev-dsk-alinalq-2b-2db84246.us-west-2.amazon.com>
Signed-off-by: Harry Lin <harrylhl@amazon.com>
madolson
approved these changes
Feb 23, 2026
Member
madolson
left a comment
There was a problem hiding this comment.
Incremental merge of the various other gtest improvements. @valkey-io/core-team please take a look.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #3241 +/- ##
================================
================================
🚀 New features to boost your workflow:
|
Signed-off-by: harrylin98 <harrylin980107@gmail.com>
Signed-off-by: harrylin98 <harrylin980107@gmail.com>
c92f57f to
e9b10e5
Compare
Signed-off-by: harrylin98 <harrylin980107@gmail.com>
Contributor
sarthakaggarwal97
left a comment
There was a problem hiding this comment.
Thanks for the change! @harrylin98 would you please fix DCO as well!
Contributor
Author
This commit was already merged in the |
zuiderkwast
reviewed
Feb 27, 2026
hpatro
pushed a commit
to hpatro/valkey
that referenced
this pull request
Mar 5, 2026
This PR adds GoogleTest (gtest) support to Valkey to enable writing modern unit tests,as mentioned in valkey-io#2878 **Motivation**: GoogleTest provides richer assertions, test fixtures, mocking support, and improved diagnostics, helping improve test coverage and maintainability over time. For more details, see `src/gtest/README.md`. **Changes** This PR integrates the GoogleTest framework and migrates all existing C unit tests to GoogleTest. --------- Signed-off-by: Harry Lin <harrylhl@amazon.com> Signed-off-by: Madelyn Olson <madelyneolson@gmail.com> Signed-off-by: Alina Liu <liusalisa6363@gmail.com> Signed-off-by: Jacob Murphy <jkmurphy@google.com> Signed-off-by: Jim Brunner <brunnerj@amazon.com> Co-authored-by: Harry Lin <harrylhl@amazon.com> Co-authored-by: Jim Brunner <brunnerj@amazon.com> Co-authored-by: Madelyn Olson <madelyneolson@gmail.com> Co-authored-by: Jacob Murphy <jkmurphy@google.com> Co-authored-by: Alina Liu <liusalisa6363@gmail.com> Signed-off-by: Harkrishn Patro <bunty.hari@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the final merge PR that merged
feature-gtestintounstable.This PR adds GoogleTest (gtest) support to Valkey to enable
writing modern unit tests,as mentioned in #2878
Motivation:
GoogleTest provides richer assertions, test fixtures, mocking
support, and improved diagnostics, helping improve test coverage
and maintainability over time.
For more details, see
src/gtest/README.md.Changes
This PR integrates the GoogleTest framework and migrates all
existing C unit tests to GoogleTest.
Authors
Harry Lin, Alina Liu