-
Notifications
You must be signed in to change notification settings - Fork 3
Unit test: caching #59
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
0f1f82e
Add caching test-case
furtib 93b2a10
Add test script to folder
furtib 14fb7d2
Create __init__.py
furtib d17ae02
Rename to fit with unittest standard
furtib f1ba2f5
Use common library
furtib 4408c64
Updated to follow common, and to be less than 80 char long
furtib b06bbc3
Add comments
furtib 7e01520
Update for common lib
furtib 8ec5f4d
Update for working path
furtib 0e01b02
Change to new path fix
furtib be93405
Format
furtib c4411be
Update comment
furtib 15f2b42
Add license
furtib 0b4607d
Update to follow common lib
furtib 65bb6aa
Remove comments
furtib dd014f8
Add setUp and teardown to handle file changes
furtib fccaec3
Improve regex
furtib bca3cd7
Replace regex
furtib a8dc75c
Change cleanup placement
furtib 50f54ad
Update test/unit/caching/test_caching.py
furtib 76cff4f
Use python specific solutions where applicable
furtib 4c5344e
Use only stderr
furtib 8405a5e
Accept suggestion on test/unit/caching/test_caching.py
furtib b9065ba
Format
furtib 65633a8
Remove unnecesary variable
furtib 42a6ce2
Add test for CTU targets caching
furtib 66387de
Fix name, add comments
furtib bf0adb1
Add manual tag
furtib 66dbd59
Remove bug from source
furtib 75082b5
Remove unnecesary comments and tags
furtib 413ccc7
Add comment
furtib de98359
Update test/unit/caching/BUILD
Szelethus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Copyright 2023 Ericsson AB | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # cc_binary for simple C++ tests | ||
| load( | ||
| "@rules_cc//cc:defs.bzl", | ||
| "cc_binary", | ||
| "cc_library", | ||
| ) | ||
|
|
||
| load( | ||
| "@bazel_codechecker//src:code_checker.bzl", | ||
| "code_checker_test", | ||
| ) | ||
|
|
||
| # We are not interested in finding bugs, we are only interested in whether the | ||
| # analysis re-runs after the files have been modified. As such, these files emit no | ||
| # warnings. | ||
|
|
||
| cc_library( | ||
| name = "linking", | ||
| hdrs = ["linking.h"], | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "secondary", | ||
| srcs = ["secondary.cc"], | ||
| deps = ["linking"], | ||
| ) | ||
|
|
||
| cc_binary( | ||
| name = "primary", | ||
| srcs = ["primary.cc"], | ||
| deps = [ | ||
| "secondary", | ||
| "linking" | ||
| ], | ||
| ) | ||
|
|
||
| code_checker_test( | ||
| name = "code_checker_caching", | ||
| targets = [ | ||
| "primary", | ||
| ], | ||
| ) | ||
|
|
||
| code_checker_test( | ||
| name = "code_checker_caching_ctu", | ||
| targets = [ | ||
| "primary", | ||
| ], | ||
| options = ["--ctu"], | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright 2023 Ericsson AB | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef LINKING_H | ||
| #define LINKING_H | ||
| int foo(); | ||
| #endif // LINKING_H |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright 2023 Ericsson AB | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "linking.h" | ||
|
|
||
| int main(){ | ||
| return 1/foo(); | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright 2023 Ericsson AB | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "linking.h" | ||
|
|
||
| int foo(){ | ||
| return 1; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # Copyright 2023 Ericsson AB | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| Functional test, to check if caching is working correctly | ||
furtib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| import unittest | ||
| import os | ||
| import shutil | ||
| from typing import final | ||
| from common.base import TestBase | ||
|
|
||
|
|
||
| class TestCaching(TestBase): | ||
| """Caching tests""" | ||
|
|
||
| # Set working directory | ||
| __test_path__ = os.path.dirname(os.path.abspath(__file__)) | ||
| BAZEL_BIN_DIR = os.path.join( | ||
| "../../..", "bazel-bin", "test", "unit", "caching" | ||
| ) | ||
| BAZEL_TESTLOGS_DIR = os.path.join( | ||
| "../../..", "bazel-testlogs", "test", "unit", "caching" | ||
| ) | ||
|
|
||
| @final | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| """Clean up before the test suite""" | ||
| super().setUpClass() | ||
| cls.run_command("bazel clean") | ||
|
|
||
| def setUp(self): | ||
| """Before every test: clean Bazel cache""" | ||
| super().setUp() | ||
| os.mkdir("tmp") | ||
| shutil.copy("primary.cc", "tmp") | ||
| shutil.copy("secondary.cc", "tmp") | ||
| shutil.copy("linking.h", "tmp") | ||
| shutil.copy("BUILD", "tmp") | ||
|
|
||
| def tearDown(self): | ||
| """Clean up working directory after every test""" | ||
| super().tearDown() | ||
| try: | ||
| shutil.rmtree("tmp") | ||
| except FileNotFoundError: | ||
| self.fail("Temporary working directory does not exists!") | ||
|
|
||
| def test_bazel_test_code_checker_caching(self): | ||
| """ | ||
| Test whether bazel correctly uses cached analysis | ||
| results for unchanged input files. | ||
| """ | ||
| target = "//test/unit/caching/tmp:code_checker_caching" | ||
| ret, _, _ = self.run_command(f"bazel build {target}") | ||
| self.assertEqual(ret, 0) | ||
| try: | ||
| with open("tmp/secondary.cc", "a", encoding="utf-8") as f: | ||
| f.write("//test") | ||
| except FileNotFoundError: | ||
| self.fail(f"File not found!") | ||
| ret, _, stderr = self.run_command(f"bazel build {target} --subcommands") | ||
| self.assertEqual(ret, 0) | ||
| # FIXME: This should be 1; 2 means that both .cpp files were reanalyzed | ||
| # despite only one of them being changed. | ||
| self.assertEqual( | ||
| stderr.count(f"SUBCOMMAND: # {target} [action 'CodeChecker"), 2 | ||
| ) | ||
|
|
||
| def test_bazel_test_code_checker_ctu_caching(self): | ||
| """ | ||
| Test whether bazel correctly reanalyses | ||
| the whole project when CTU is enabled | ||
| """ | ||
| target = "//test/unit/caching/tmp:code_checker_caching_ctu" | ||
| ret, _, _ = self.run_command(f"bazel build {target}") | ||
| self.assertEqual(ret, 0) | ||
| try: | ||
| with open("tmp/secondary.cc", "a", encoding="utf-8") as f: | ||
| f.write("//test") | ||
| except FileNotFoundError: | ||
| self.fail(f"File not found!") | ||
| ret, _, stderr = self.run_command(f"bazel build {target} --subcommands") | ||
| self.assertEqual(ret, 0) | ||
| # We expect both files to be reanalyzed, since there is no caching | ||
| # implemented for CTU analysis | ||
| self.assertEqual( | ||
| stderr.count(f"SUBCOMMAND: # {target} [action 'CodeChecker"), 2 | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main(buffer=True) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.