Skip to content

(#513) Refactor into set_log_streams_for_tests() to manage unit-test outputs.#514

Merged
gapisback merged 1 commit intomainfrom
agurajada/513-ctest-output
Jan 18, 2023
Merged

(#513) Refactor into set_log_streams_for_tests() to manage unit-test outputs.#514
gapisback merged 1 commit intomainfrom
agurajada/513-ctest-output

Conversation

@gapisback
Copy link
Contributor

@gapisback gapisback commented Dec 23, 2022

This commit refactors existing chunks of code that exists in different unit- test sources to manage output file handles to a common function, now defined in new file unit/unit_tests_common.c ; set_log_streams_for_tests().

Tests that check error-raising behaviour will now need to call set_log_streams_for_neg_tests(), to manage output streams.

Minor correction to TEST_DB_NAME; change it to conform to the r.e. defined in .gitignore to suppress listing this in 'git status' output.


NOTE: I did not try to make this even more generic beyond unit-tests to have functional/ tests also call into these interfaces. That's why this new file unit_tests_common.c is in tests/unit sub-dir and not in top-level tests/ dir.

I think, let's see how this settles down and if we ever find the need to make functional tests also get this capability, we can consider relocating this new file to tests/ sub-dir.

@netlify
Copy link

netlify bot commented Dec 23, 2022

Deploy Preview for splinterdb canceled.

Name Link
🔨 Latest commit 5d05ab9
🔍 Latest deploy log https://app.netlify.com/sites/splinterdb/deploys/63c867eb8ac3780009829bad

# defined above using unit_test_self_dependency.
#
$(BINDIR)/$(UNITDIR)/misc_test: $(UTIL_SYS)
$(BINDIR)/$(UNITDIR)/misc_test: $(UTIL_SYS) $(COMMON_UNIT_TESTOBJ)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about including this new .o in COMMON_TESTOBJ symbol, but that would mean we are mixing up shared .o's from diff sub-dirs.

The way it's done is a bit more work to keep adding this COMMON_UNIT_TESTOBJ dependency in several lines, but it's at least clear, and cleaner, to specify exactly which unit_test-dot-oh depends on which common object.

if (Ctest_verbose) {
platform_set_log_streams(stdout, stderr);
}
set_log_streams_for_tests();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For symmetry, I introduced this set_ method, too. This is really not needed, but it makes it easier for new unit-test dev to just follow one set_log_streams_for*() pattern.


/* Name of SplinterDB device created for unit-tests */
#define TEST_DB_NAME "unit_tests_db"
#define TEST_DB_NAME "splinterdb_unit_tests_db"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Slightly unrelated bug-fix ... arising from one of @rosenhouse 's suggestion on an earlier PR.

# unit-tests (and won't pick-up test-specific common files, e.g.
# btree_test_common.c)
COMMON_UNIT_TESTSRC := $(shell find $(UNIT_TESTSDIR) -name "*tests_common.c")
COMMON_UNIT_TESTSRC := $(wildcard $(UNIT_TESTSDIR)/*tests_common.c)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comes about due to changes introduced under earlier PR integrated at SHA 615050a to remove use of shell built-ins in favor of using Makefile built-in commands.

@gapisback
Copy link
Contributor Author

Small reminder @rosenhouse - to see if you can spend some time on this review. I just rebased off of /main and pushed an updated commit set. Thanks!

Copy link
Contributor

@rosenhouse rosenhouse left a comment

Choose a reason for hiding this comment

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

Definitely an improvement, though I would prefer a different name for the error-case function.

This commit refactors existing chunks of code that exists in different unit-
test sources to manage output file handles to a common function. This is
defined in new file unit/unit_tests_common.c ; set_log_streams_for_tests()
Tests that check error-raising behaviour will now need to call
set_log_streams_for_error_tests(), to manage output streams.

Minor correction to TEST_DB_NAME; change it to conform to the r.e. defined
in .gitignore to suppress listing this in 'git status' output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor code that manages stdout / stderr file handles in unit tests to a common routine.

3 participants