Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,182 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Authored regressions for explicit firmware preparation and bundle boundaries."""
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
MODULE = Path(__file__).resolve().parents[1] / 'build.py'
|
||||
SPEC = importlib.util.spec_from_file_location('rom_build', MODULE)
|
||||
BUILD = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(BUILD)
|
||||
|
||||
|
||||
def fingerprint(data):
|
||||
return hashlib.sha256(data).hexdigest()
|
||||
|
||||
|
||||
class ROMBuildTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.temporary = tempfile.TemporaryDirectory(prefix='vcc-rom-builder-test-')
|
||||
self.addCleanup(self.temporary.cleanup)
|
||||
self.root = Path(self.temporary.name)
|
||||
self.records, self.locations = BUILD.DEPENDENCIES.load_records()
|
||||
self.record = json.loads(json.dumps(self.records['cocoroms']))
|
||||
|
||||
def fixture_outputs(self):
|
||||
directory = self.root / 'roms'
|
||||
directory.mkdir()
|
||||
expected = {}
|
||||
for name in BUILD.ROM_NAMES:
|
||||
data = bytes(32768 if name == 'coco3.rom' else 8192)
|
||||
(directory / name).write_bytes(data)
|
||||
expected[name] = {'bytes': len(data), 'sha256': fingerprint(data)}
|
||||
return directory, expected
|
||||
|
||||
def fixture_inputs(self):
|
||||
dependencies = self.root / 'dependencies'
|
||||
source = dependencies / 'cocoroms'
|
||||
source.mkdir(parents=True)
|
||||
hashes = {}
|
||||
for name in BUILD.SOURCE_NAMES:
|
||||
data = ('Authored source fixture: ' + name + '\n').encode()
|
||||
(source / name).write_bytes(data)
|
||||
hashes[name] = fingerprint(data)
|
||||
self.record['upstreamFileSHA256'] = self.record['vendoredFileSHA256'] = hashes
|
||||
_, self.record['romOutputs'] = self.fixture_outputs()
|
||||
return dependencies
|
||||
|
||||
def fixture_assembler(self, fail=False):
|
||||
tool = self.root / 'explicit-assembler-with-another-name'
|
||||
tool.write_text('''#!/usr/bin/env python3
|
||||
from pathlib import Path
|
||||
import sys
|
||||
if '--version' in sys.argv: print('Authored assembler fixture'); raise SystemExit(0)
|
||||
''' + ("raise SystemExit(7)\n" if fail else '''if '--raw' in sys.argv:
|
||||
name = sys.argv[sys.argv.index('-o') + 1]
|
||||
Path(name).write_bytes(bytes(32768 if name == 'coco3.rom' else 8192))
|
||||
else: print('fixture EQU 0')
|
||||
'''))
|
||||
tool.chmod(0o755)
|
||||
return tool
|
||||
|
||||
def test_firmware_fetch_is_explicit_and_manifest_contains_only_source(self):
|
||||
record = BUILD.source_record(self.records)
|
||||
self.assertEqual(set(record['upstreamFileSHA256']), BUILD.SOURCE_NAMES)
|
||||
self.assertNotIn('cocoroms', BUILD.DEPENDENCIES.default_selection(self.records))
|
||||
self.assertEqual(len(BUILD.DEPENDENCIES.default_selection(self.records)), 17)
|
||||
self.assertNotIn('.rom', ''.join(record['upstreamFileSHA256']))
|
||||
self.assertEqual(record['archiveRootPrefix'], 'cocoroms/')
|
||||
|
||||
def test_unreviewed_firmware_input_is_refused(self):
|
||||
self.record['vendoredFileSHA256']['supplied.rom'] = '0' * 64
|
||||
with self.assertRaisesRegex(ValueError, 'exactly the eight'):
|
||||
BUILD.source_record({'cocoroms': self.record})
|
||||
|
||||
def test_optional_flag_requires_a_boolean(self):
|
||||
self.record['optional'] = 'true'
|
||||
with self.assertRaisesRegex(ValueError, 'optional flag'):
|
||||
BUILD.DEPENDENCIES.validate_record(self.record)
|
||||
|
||||
def test_malformed_output_metadata_is_rejected_explicitly(self):
|
||||
for spec in [None, {'bytes': 32768, 'sha256': None}, {'bytes': 32768, 'sha256': 'not-a-hash'}]:
|
||||
record = json.loads(json.dumps(self.records['cocoroms']))
|
||||
record['romOutputs']['coco3.rom'] = spec
|
||||
with self.assertRaisesRegex(ValueError, 'firmware fingerprint'):
|
||||
BUILD.source_record({'cocoroms': record})
|
||||
record = json.loads(json.dumps(self.records['cocoroms']))
|
||||
record['romOutputs'] = None
|
||||
with self.assertRaisesRegex(ValueError, 'output inventory'):
|
||||
BUILD.source_record({'cocoroms': record})
|
||||
|
||||
def test_generated_hash_size_links_and_hardlinks_are_checked(self):
|
||||
source, expected = self.fixture_outputs()
|
||||
self.assertEqual(BUILD.validate_outputs(source, expected), expected)
|
||||
target = source / 'disk11.rom'
|
||||
target.write_bytes(b'changed')
|
||||
with self.assertRaisesRegex(ValueError, 'qualified fingerprint'):
|
||||
BUILD.validate_outputs(source, expected)
|
||||
target.unlink()
|
||||
target.symlink_to(source / 'bas13.rom')
|
||||
with self.assertRaisesRegex(ValueError, 'unlinked'):
|
||||
BUILD.validate_outputs(source, expected)
|
||||
target.unlink()
|
||||
os.link(source / 'bas13.rom', target)
|
||||
with self.assertRaisesRegex(ValueError, 'unlinked'):
|
||||
BUILD.validate_outputs(source, expected)
|
||||
|
||||
def test_bundle_has_exactly_two_roms_manifest_notice_and_no_private_paths(self):
|
||||
source, expected = self.fixture_outputs()
|
||||
manifest = BUILD.bundle_manifest(self.record, self.locations['cocoroms'] / 'cocoroms.json',
|
||||
{'version': 'fixture', 'sha256': 'a' * 64}, expected)
|
||||
destination = self.root / 'bundle'
|
||||
BUILD.write_bundle(destination, source, manifest)
|
||||
self.assertEqual({p.name for p in destination.iterdir()},
|
||||
{'ROMBuild.json', 'ROM_SOURCE_NOTICE.txt', 'coco3.rom', 'disk11.rom'})
|
||||
published = json.loads((destination / 'ROMBuild.json').read_text())
|
||||
self.assertEqual(published['schemaVersion'], 1)
|
||||
self.assertEqual(published['generator'], 'vccplus-rom-build')
|
||||
self.assertEqual(set(published['roms']), set(BUILD.BUNDLE_NAMES))
|
||||
self.assertNotIn(str(self.root), (destination / 'ROMBuild.json').read_text())
|
||||
self.assertIn('MICROWARE', (destination / 'ROM_SOURCE_NOTICE.txt').read_text())
|
||||
with self.assertRaisesRegex(ValueError, 'fresh ROM bundle'):
|
||||
BUILD.write_bundle(destination, source, manifest)
|
||||
|
||||
def test_cold_build_uses_exact_explicit_assembler_and_no_existing_roms(self):
|
||||
dependencies = self.fixture_inputs()
|
||||
records = dict(self.records, cocoroms=self.record)
|
||||
tool = self.fixture_assembler()
|
||||
output, bundle = self.root / 'output', self.root / 'bundle'
|
||||
with patch.object(BUILD.DEPENDENCIES, 'load_records', return_value=(records, self.locations)):
|
||||
report = BUILD.build(output, dependencies, tool, bundle)
|
||||
self.assertEqual(report['status'], 'passed')
|
||||
self.assertEqual(len(report['commands']), 6)
|
||||
self.assertTrue(all(command['argv'][0] == str(tool.resolve()) for command in report['commands']))
|
||||
self.assertFalse(report['preassembledROMInputs'])
|
||||
self.assertEqual(report['roms'], self.record['romOutputs'])
|
||||
self.assertTrue((bundle / 'coco3.rom').is_file())
|
||||
|
||||
def test_preassembled_dependency_payload_is_refused_before_execution(self):
|
||||
dependencies = self.fixture_inputs()
|
||||
(dependencies / 'cocoroms/preassembled.rom').write_bytes(b'fixture')
|
||||
records = dict(self.records, cocoroms=self.record)
|
||||
with patch.object(BUILD.DEPENDENCIES, 'load_records', return_value=(records, self.locations)), \
|
||||
patch.object(BUILD.subprocess, 'run') as execute:
|
||||
with self.assertRaisesRegex(ValueError, 'differs from reviewed import'):
|
||||
BUILD.build(self.root / 'output', dependencies, self.fixture_assembler())
|
||||
execute.assert_not_called()
|
||||
self.assertFalse((self.root / 'output').exists())
|
||||
|
||||
def test_failed_assembly_retains_evidence_without_creating_bundle(self):
|
||||
dependencies = self.fixture_inputs()
|
||||
records = dict(self.records, cocoroms=self.record)
|
||||
output, bundle = self.root / 'output', self.root / 'bundle'
|
||||
with patch.object(BUILD.DEPENDENCIES, 'load_records', return_value=(records, self.locations)):
|
||||
with self.assertRaises(BUILD.subprocess.CalledProcessError):
|
||||
BUILD.build(output, dependencies, self.fixture_assembler(fail=True), bundle)
|
||||
self.assertEqual(json.loads((output / 'BuildReport.json').read_text())['status'], 'failed')
|
||||
self.assertTrue((output / 'build.log').is_file())
|
||||
self.assertFalse(bundle.exists())
|
||||
|
||||
def test_bundle_cannot_contaminate_dependencies_or_occupy_build_ancestor(self):
|
||||
dependencies = self.fixture_inputs()
|
||||
records = dict(self.records, cocoroms=self.record)
|
||||
tool = self.fixture_assembler()
|
||||
for bundle in [dependencies / 'cocoroms/package', dependencies.resolve() / 'cocoroms/canonical-package', self.root / 'new-build-parent']:
|
||||
output = self.root / 'new-build-parent/output'
|
||||
with patch.object(BUILD.DEPENDENCIES, 'load_records', return_value=(records, self.locations)), \
|
||||
patch.object(BUILD.subprocess, 'run') as execute:
|
||||
with self.assertRaisesRegex(ValueError, 'separate from dependency'):
|
||||
BUILD.build(output, dependencies, tool, bundle)
|
||||
execute.assert_not_called()
|
||||
self.assertFalse(output.exists())
|
||||
self.assertFalse(bundle.exists())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user