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

Create more general Test Framework and Organize the bulk of current tests #67

Merged
merged 12 commits into from
Oct 10, 2020

Conversation

xTVaser
Copy link
Member

@xTVaser xTVaser commented Oct 8, 2020

This PR doesn't yet add new torture tests, I figure that can come later. Just trying to replicate the current tests with the new framework and work-out the kinks

Of which there are still a few.

Copy link
Collaborator

@water111 water111 left a comment

Choose a reason for hiding this comment

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

This is awesome, I took a look and really liked this approach. It will be a huge help for making a a reliable compiler!

// This is used by the test runner code to know what the expected value is
// For a simple example like this, a single eval is all that's required, but for
// more complex tests, this may not be the case.
std::string eval() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is great and will probably be super useful for more complicated randomly generated expressions.

testing::ValuesIn(genIntegerTests(4,
true,
true,
{IntegerParam(-2147483648),
Copy link
Collaborator

Choose a reason for hiding this comment

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

At some point we should add in more edge case integers. See 'IR_LoadConstant64::do_codegen` which picks one of 5 different instructions for doing the load depending on the size/sign of the value.

}

// In the interest of speed, we want to share the same thread/compiler across
// all the tests in this suite, so we have to over-ride this.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 without this the tests can take a while

void TearDown() {}

// Common Resources Across all Tests in the Suite
static std::thread runtime_thread;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems kinda weird, but maybe this is what you're supposed to do for gtests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, using gtest's Fixture support was the best way I could think of to share the thread/compiler/runner across all tests.

However I don't really like it for several reasons:

  • Since the Fixture has to extend with the parameter, you can't easily have 2 different types of parameters to generate tests, unless you make a new fixture, which means a new thread,etc.
  • Lots of boilerplate

So this is an area for improvement. I think it would be nicer to have a "global" runner with/without the kernel, and have some sort of mechanism to "refresh/wipe" the state so we can ensure tests are hermetic. I ran into some difficulty trying to do the former though.

There might also be a better way to do the parameterized tests - https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#creating-value-parameterized-abstract-tests so we can have a common library of some sorts.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I looked at this a little bit more and I think what you have now is good. The static stuff in the fixture class seemed weird to me at first because I didn't realize each test would get its own fixture.

I agree we need a better way to reset the state of the compiler/runtime between tests. I don't think it would be too hard to add a reset_state to the compiler that clears out all the variable/constant/function/type definitions. Doing a fast reset of the runtime is going to be much harder though. There's some hacky stuff we could do like saving the entire runtime GOAL memory before a test and restoring it, but this won't catch everything.

GoalTest::CompilerTestRunner WithGameTests::runner;

// TODO - havn't done anything with these really yet
TEST_F(WithGameTests, All) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is probably for another PR, but I think a lot of these tests just call a single function with a few arguments and check the result. I imagine we could have a Call Function test that generates these without needing all these separate test .gc files.

@xTVaser xTVaser marked this pull request as ready for review October 9, 2020 23:37
@xTVaser xTVaser force-pushed the generative-tests branch 4 times, most recently from 068d2b7 to 7540e6a Compare October 10, 2020 00:10
@coveralls
Copy link

coveralls commented Oct 10, 2020

Pull Request Test Coverage Report for Build 298482569

  • 538 of 573 (93.89%) changed or added relevant lines in 18 files are covered.
  • 345 unchanged lines in 20 files lost coverage.
  • Overall coverage decreased (-1.7%) to 79.953%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/test_main.cpp 3 4 75.0%
test/goalc/test_with_game.cpp 61 64 95.31%
test/goalc/framework/test_runner.cpp 33 64 51.56%
Files with Coverage Reduction New Missed Lines %
game/kernel/kdsnetm.cpp 1 73.47%
game/kernel/kmalloc.cpp 1 46.58%
game/kernel/kprint.cpp 1 50.1%
game/overlord/iso_queue.cpp 1 76.06%
goalc/emitter/IGen.h 1 95.31%
goalc/regalloc/Allocator.cpp 1 79.45%
common/goos/Object.h 2 84.84%
common/goos/Interpreter.cpp 3 87.81%
common/type_system/deftype.cpp 3 77.34%
common/type_system/Type.h 3 77.42%
Totals Coverage Status
Change from base Build 296754685: -1.7%
Covered Lines: 14278
Relevant Lines: 17858

💛 - Coveralls

Copy link
Collaborator

@water111 water111 left a comment

Choose a reason for hiding this comment

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

👍

test_deftype.cpp
test_pretty_print.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this removed by accident?

std::string& testCategory,
const std::string& test_file,
const std::vector<std::string>& expected,
MatchParam<int> truncate) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't worry about changing this now, but C++17 now has std::optional which is better than the MatchParam thing. Eventually I'll switch everything to std::optional

@@ -5,7 +5,7 @@ jobs:
common:
# TODO - Start using clang-tidy - requires a bit more setup though - http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
name: Linting & Formatting
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
Copy link
Collaborator

Choose a reason for hiding this comment

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

good idea

@water111 water111 merged commit 0a231af into open-goal:master Oct 10, 2020
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.

3 participants