aboutsummaryrefslogtreecommitdiff
path: root/infra/build_specified_commit_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'infra/build_specified_commit_test.py')
-rw-r--r--infra/build_specified_commit_test.py112
1 files changed, 71 insertions, 41 deletions
diff --git a/infra/build_specified_commit_test.py b/infra/build_specified_commit_test.py
index 77a0698fe..808bcc21f 100644
--- a/infra/build_specified_commit_test.py
+++ b/infra/build_specified_commit_test.py
@@ -11,42 +11,28 @@
# 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.
-"""Test the functionality of the build image from state module.
-NOTE: THIS TEST NEEDS TO BE RUN FROM THE OSS-FUZZ BASE DIR
-The will consist of the following functional tests
- 1. The inferance of the main repo for a specific project
+"""Test the functionality of the build image from commit module.
+The will consist of the following functional tests:
+ 1. The inference of the main repo for a specific project.
+ 2. The building of a projects fuzzers from a specific commit.
+
+IMPORTANT: This test needs to be run with root privileges.
"""
+import os
+import tempfile
import unittest
import build_specified_commit
import helper
+import repo_manager
+import test_repos
-
-class BuildImageUnitTests(unittest.TestCase):
- """Class to test the functionality of the build image from state module."""
-
- def test_infer_main_repo(self):
- """Tests that the main repo can be infered based on an example commit."""
- infered_repo = build_specified_commit.infer_main_repo(
- 'curl', 'tmp', 'bc5d22c3dede2f04870c37aec9a50474c4b888ad')
- self.assertEqual(infered_repo, 'https://github.com/curl/curl.git')
- infered_repo = build_specified_commit.infer_main_repo('curl', 'tmp')
- self.assertEqual(infered_repo, 'https://github.com/curl/curl.git')
-
- infered_repo = build_specified_commit.infer_main_repo('usrsctp', 'tmp')
- self.assertEqual(infered_repo, 'https://github.com/weinrank/usrsctp')
- infered_repo = build_specified_commit.infer_main_repo(
- 'usrsctp', 'tmp', '4886aaa49fb90e479226fcfc3241d74208908232')
- self.assertEqual(infered_repo, 'https://github.com/weinrank/usrsctp',
- '4886aaa49fb90e479226fcfc3241d74208908232')
-
- infered_repo = build_specified_commit.infer_main_repo(
- 'not_a_project', 'tmp')
- self.assertEqual(infered_repo, None)
+# Necessary because __file__ changes with os.chdir
+TEST_DIR_PATH = os.path.dirname(os.path.realpath(__file__))
class BuildImageIntegrationTests(unittest.TestCase):
- """Testing if an image can be built from different states e.g. a commit"""
+ """Testing if an image can be built from different states e.g. a commit."""
def test_build_fuzzers_from_commit(self):
"""Tests if the fuzzers can build at a proper commit.
@@ -55,21 +41,65 @@ class BuildImageIntegrationTests(unittest.TestCase):
The old commit should show the error when its fuzzers run and the new one
should not.
"""
- project_name = 'yara'
- old_commit = 'f79be4f2330f4b89ea2f42e1c44ca998c59a0c0f'
- new_commit = 'f50a39051ea8c7f10d6d8db9656658b49601caef'
- fuzzer = 'rules_fuzzer'
- test_data = 'infra/yara_test_data'
- build_specified_commit.build_fuzzer_from_commit(
- project_name, old_commit, 'tmp', sanitizer='address')
- old_error_code = helper.reproduce_impl(project_name, fuzzer, False, [], [],
- test_data)
- build_specified_commit.build_fuzzer_from_commit(
- project_name, new_commit, 'tmp', sanitizer='address')
- new_error_code = helper.reproduce_impl(project_name, fuzzer, False, [], [],
- test_data)
- self.assertNotEqual(new_error_code, old_error_code)
+
+ with tempfile.TemporaryDirectory() as tmp_dir:
+ test_case = test_repos.TEST_REPOS[0]
+ test_repo_manager = repo_manager.RepoManager(
+ test_case.git_url, tmp_dir, repo_name=test_case.oss_repo_name)
+ build_data = build_specified_commit.BuildData(
+ sanitizer='address',
+ architecture='x86_64',
+ engine='libfuzzer',
+ project_name=test_case.project_name)
+
+ build_specified_commit.build_fuzzers_from_commit(test_case.old_commit,
+ test_repo_manager,
+ build_data)
+ old_error_code = helper.reproduce_impl(test_case.project_name,
+ test_case.fuzz_target, False, [],
+ [], test_case.test_case_path)
+ build_specified_commit.build_fuzzers_from_commit(test_case.new_commit,
+ test_repo_manager,
+ build_data)
+ new_error_code = helper.reproduce_impl(test_case.project_name,
+ test_case.fuzz_target, False, [],
+ [], test_case.test_case_path)
+ self.assertNotEqual(new_error_code, old_error_code)
+
+ def test_detect_main_repo_from_commit(self):
+ """Test the detect main repo function from build specific commit module."""
+ for example_repo in test_repos.TEST_REPOS:
+ repo_origin, repo_name = build_specified_commit.detect_main_repo(
+ example_repo.project_name, commit=example_repo.new_commit)
+ self.assertEqual(repo_origin, example_repo.git_url)
+ self.assertEqual(repo_name,
+ os.path.join('/src', example_repo.oss_repo_name))
+
+ repo_origin, repo_name = build_specified_commit.detect_main_repo(
+ test_repos.INVALID_REPO.project_name,
+ test_repos.INVALID_REPO.new_commit)
+ self.assertIsNone(repo_origin)
+ self.assertIsNone(repo_name)
+
+ def test_detect_main_repo_from_name(self):
+ """Test the detect main repo function from build specific commit module."""
+ for example_repo in test_repos.TEST_REPOS:
+ repo_origin, repo_name = build_specified_commit.detect_main_repo(
+ example_repo.project_name, repo_name=example_repo.git_repo_name)
+ self.assertEqual(repo_origin, example_repo.git_url)
+ self.assertEqual(repo_name,
+ os.path.join('/src', example_repo.oss_repo_name))
+
+ repo_origin, repo_name = build_specified_commit.detect_main_repo(
+ test_repos.INVALID_REPO.project_name,
+ test_repos.INVALID_REPO.oss_repo_name)
+ self.assertIsNone(repo_origin)
+ self.assertIsNone(repo_name)
if __name__ == '__main__':
+
+ # Change to oss-fuzz main directory so helper.py runs correctly.
+ if os.getcwd() != os.path.dirname(TEST_DIR_PATH):
+ os.chdir(os.path.dirname(TEST_DIR_PATH))
unittest.main()