| #!/usr/bin/env python3 | |
| # Copyright 2026 The Chromium Authors | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| """Tests for engines.py.""" | |
| import pathlib | |
| import unittest | |
| import engines | |
| class GetAdapterTest(unittest.TestCase): | |
| def test_get_adapter(self): | |
| for name in engines.ENGINES: | |
| with self.subTest(name=name): | |
| self.assertEqual(engines.get_adapter(name).name, name) | |
| class LibFuzzerCommandTest(unittest.TestCase): | |
| def get_command(self, **options): | |
| return engines.LibFuzzerAdapter().command( | |
| engines.Target(pathlib.Path('/b'), 'foo_fuzzer'), | |
| engines.EngineOptions(duration_s=900, **options), | |
| corpus_dir=pathlib.Path('/o/corpus'), | |
| crashes_dir=pathlib.Path('/o/crashes'), | |
| ) | |
| def test_command(self): | |
| command = self.get_command() | |
| self.assertEqual(command[0], '/b/foo_fuzzer') | |
| self.assertIn('-max_total_time=900', command) | |
| self.assertIn('-artifact_prefix=/o/crashes/', command) | |
| # libFuzzer writes its corpus into the first positional argument. | |
| positional = [arg for arg in command[1:] if not arg.startswith('-')] | |
| self.assertEqual(positional, ['/o/corpus']) | |
| def test_seed(self): | |
| self.assertNotIn('-seed=', ' '.join(self.get_command())) | |
| self.assertIn('-seed=7', self.get_command(seed=7)) | |
| if __name__ == '__main__': | |
| unittest.main() |