Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Static Code Checks for Test Files #1257

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

schedutron
Copy link
Contributor

@schedutron schedutron commented Apr 4, 2018

(Implementing #1192)
I've added a check for test class name. Do I also have to create another paths variable via glob module, which contains all the test files' paths (which end with *_test.cpp)?

Also, I'll add other checks soon.

@schedutron
Copy link
Contributor Author

schedutron commented Apr 4, 2018

@tcm-marcel Should check_tests function be only called on staged test files? Also, what are the criteria for the gtest macro methods to be checked? Should each test case name end with the 'Test' suffix?

@tcm-marcel tcm-marcel changed the title Static Code Checks for Test Files (in progress) Static Code Checks for Test Files Apr 4, 2018
@tcm-marcel
Copy link
Contributor

I would check in validate_file(file_path) [1] if the file matches /test/*/*.cpp and then run the check in addition to the other checks. This way every test file that the validator is called with gets checked. The pre-commit hook calls the validator with the stages files, to this happens automatically.

[1] https://github.com/schedutron/peloton/blob/dda18900b9c5efafbea1d4ada73b2903ecd4dc9a/script/validators/source_validator.py#L237

@schedutron
Copy link
Contributor Author

schedutron commented Apr 4, 2018

I think I should add a path regex for checking whether we have a test file instead of checking membership in the path set returned by glob.glob() for faster execution. Will do so soon. Or maybe a startswith()-endswith() call pair would also be fine - and simpler.

@coveralls
Copy link

coveralls commented Apr 4, 2018

Coverage Status

Coverage increased (+0.01%) to 77.566% when pulling 3d74f74 on schedutron:static into 5686479 on cmu-db:master.

@tcm-marcel tcm-marcel self-requested a review April 4, 2018 22:26
Copy link
Contributor

@tcm-marcel tcm-marcel left a comment

Choose a reason for hiding this comment

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

Hey, I just took a quick look and found a few problems:

  1. at the moment the script accidentally picks up forward declarations:
04-06-2018 13:18:59 [check_tests:217] INFO : Invalid class name in /home/marcel/dev/peloton/peloton_review/test/concurrency/testing_transaction_util.cpp
04-06-2018 13:18:59 [check_tests:219] INFO : Line 34: class ExecutorContext;
04-06-2018 13:18:59 [check_tests:219] INFO : Line 37: class InsertPlan;
04-06-2018 13:18:59 [check_tests:219] INFO : Line 38: class ProjectInfo;
04-06-2018 13:18:59 [check_tests:221] INFO : Test class names should end with 'Tests' suffix.
  1. methods are not checked yet: TEST_F(..)

It looks like all other matches are correct, meaning that the rules are actually violated there. So once we agreed on the result, we will add one more commit that fixes the naming in the files.

@schedutron
Copy link
Contributor Author

schedutron commented Apr 11, 2018

@tcm-marcel How do I check the methods? They don't follow a prefix/suffix pattern.

Also, to resolve the issue you mentioned above, should I omit the files that end with a _util suffix?

@tcm-marcel
Copy link
Contributor

How do I check the methods? They don't follow a prefix/suffix pattern.

You can use a regex to find these lines and extract the information. (see example: https://regexr.com/3nnro)

Also, to resolve the issue you mentioned above, should I omit the files that end with a _util suffix?

Sounds good.

@schedutron
Copy link
Contributor Author

Alright, but do we have to check after we extract the identifiers?

@tcm-marcel
Copy link
Contributor

Ah sorry, I got you wrong. The naming conventions say, that every method (test case) should have the suffix Test.

@schedutron
Copy link
Contributor Author

Yeah, but a lot of test cases across different test files do not. Are we going to use the validator script to fix all these files?

@tcm-marcel
Copy link
Contributor

tcm-marcel commented Apr 11, 2018

Yeah, but a lot of test cases across different test files do not. Are we going to use the validator script to fix all these files?

Correct, that's the idea. Unfortunately we have a lot of code that doesn't meet our conventions, because it is older than these conventions or because people didn't care. The validator shall help to prevent this in the future.

Copy link
Contributor Author

@schedutron schedutron left a comment

Choose a reason for hiding this comment

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

I have couple of doubts.

class_status = False
LOG.info("Line %s: %s", line_num, line.strip())

else:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should there be a separate loop for this? That will prevent interleaved output.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am ok with this, we hope not to have thousands of those errors.

@@ -66,6 +66,8 @@
"src/codegen/util/cc_hash_table.cpp"
]

TEST_CASE_PATT = re.compile(r'TEST_F\(([a-zA-Z]+), ([a-zA-Z]+)\)')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the right place to define the regex?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so.

Copy link
Contributor

@tcm-marcel tcm-marcel left a comment

Choose a reason for hiding this comment

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

Looks good!
Next step would be to fix all wrong test cases. In generel this should be easy, maybe we have to do some refactoring there.

@@ -224,6 +259,11 @@ def validate_file(file_path):
if not validator(file_path):
file_status = False

relative_path = file_path.replace(PELOTON_DIR, '')
Copy link
Contributor

Choose a reason for hiding this comment

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

One more thing: Can you use os.path.relpath here instead of string replace?

@schedutron
Copy link
Contributor Author

schedutron commented Apr 27, 2018

As a first iteration, I will simply add the Test suffix to the incorrect test class name and the Tests suffix to the incorrect test method names.

Also, do I need to implement the correction code in the formatter script or simply fix the incorrect files in the Python interpreter and push them?

@tcm-marcel
Copy link
Contributor

@schedutron No, we don't provide automated fixing. We expect people to fix their violations manually ;)

Copy link
Contributor Author

@schedutron schedutron left a comment

Choose a reason for hiding this comment

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

I can see one obvious issue: there were few classes ending with Test rather than Tests. What happened during the fix is that they're now suffixed with TestTests. I'll fix these soon.

@@ -36,7 +36,7 @@ using std::make_tuple;
namespace peloton {
namespace test {

class BinderCorrectnessTest : public PelotonTest {
class BinderCorrectnessTestTests : public PelotonTest {
Copy link
Contributor Author

@schedutron schedutron Apr 28, 2018

Choose a reason for hiding this comment

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

This class should've been named BinderCorrectnessTests!

Copy link
Contributor

Choose a reason for hiding this comment

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

@schedutron Can you apply this change and rebase the PR? How many changes of the test files are still missing?

It's time that we merge it in and finish that part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for getting this delayed. I'll apply the changes soon.

@@ -36,7 +36,7 @@ using std::make_tuple;
namespace peloton {
namespace test {

class BinderCorrectnessTest : public PelotonTest {
class BinderCorrectnessTests : public PelotonTest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tcm-marcel At this stage, there are parent classes which still have the Test suffix instead of the Tests suffix. They are defined in .h files, and thus were not changed by the name-fixing script I ran. If I change them, I would also have to change their name in inheritance statements, e.g., here the statement will look like class BinderCorrectnessTests : public PelotonTests {. Should I do that?

Copy link
Member

Choose a reason for hiding this comment

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

@schedutron
Copy link
Contributor Author

@tcm-marcel Have a look now :)

@tcm-marcel
Copy link
Contributor

tcm-marcel commented May 11, 2018

Hey, I fear you screwed up the code when resolving the merge conflicts in 2f28acc. This is also the reason the tests fail.

I think the easiest way to solve this is to

  1. make a temporary copy of your branch git checkout -b temp
  2. reset the old branch (the one with the PR) to upstream master git branch -f ... (don't forget to fetch and rebase your master branch before)
  3. cherry pick the commits you want to have (all except the resolve merge conflicts one and the last one*)
  4. force push the new version of this branch, the PR will update accordingly

*Please remove the changes where you format the headers. It's a good idea, but it should be a separate PR.

If you need help, let me know.

@schedutron
Copy link
Contributor Author

@tcm-marcel I was afraid that could happen. Will fix this soon. Thanks for the tips!

@schedutron
Copy link
Contributor Author

@tcm-marcel The checks are passing now!

@tcm-marcel
Copy link
Contributor

tcm-marcel commented May 21, 2018

Hey, sorry for looking at this only now.
1) something is still wrong from rebasing, there are several changes in the test files, for example in test/codegen/oa_hash_table_test.cpp
2) I think the two classes PelotonTest and PelotonCodeGenTest should not be changed. I just created a commit to revert this, but I now realized that you will have to touch all files again anyway.

Let me try if I can fix this quickly.

@schedutron
Copy link
Contributor Author

What exactly are the changes in, say, test/codegen/oa_hash_table_test.cpp?

@tcm-marcel
Copy link
Contributor

I can't find it anymore... seems like I looked at a wrong version. I am sorry! Let me take another look.

@tcm-marcel
Copy link
Contributor

Ok sorry, I messed this up a little bit:

  1. I was wrong, I must have looked at the wrong diff
  2. I thought about this again and decided that we leave it that way

I will try to rebase your PR and make it ready to merge.

@saatviks
Copy link
Contributor

@schedutron can you fix the merge conflicts so this can be merged in?

@tli2
Copy link
Contributor

tli2 commented Jun 5, 2018

What is the status of this PR right now? I am putting In Progress tag until merge conflicts are fixed.

@schedutron
Copy link
Contributor Author

Lets finalize this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants