78 lines
3.1 KiB
Python
78 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Exercise release-gate process failures independently of host compilation."""
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
SOURCE = Path(__file__).resolve().parents[1] / 'ops' / 'regression_gate.sh'
|
|
|
|
class GateStatus(unittest.TestCase):
|
|
def run_gate(self, status, failures='', baseline='', ninja_status=0):
|
|
with tempfile.TemporaryDirectory(prefix='gateway-gate-status-') as temporary:
|
|
root = Path(temporary)
|
|
(root/'ops').mkdir()
|
|
(root/'bin').mkdir()
|
|
(root/'host'/'Testing'/'Temporary').mkdir(parents=True)
|
|
shutil.copyfile(SOURCE, root/'ops'/'regression_gate.sh')
|
|
(root/'ops'/'regression-baseline.txt').write_text(baseline)
|
|
(root/'bin'/'ninja').write_text('#!/bin/sh\nexit "$GATE_NINJA_STATUS"\n')
|
|
(root/'bin'/'ctest').write_text('''#!/bin/sh
|
|
if [ "$GATE_CTEST_STATUS" = empty ]; then
|
|
exec "$GATE_REAL_CTEST" "$@"
|
|
fi
|
|
if [ -n "$GATE_FAILURES" ]; then
|
|
printf '%s\\n' "$GATE_FAILURES" > Testing/Temporary/LastTestsFailed.log
|
|
fi
|
|
exit "$GATE_CTEST_STATUS"
|
|
''')
|
|
for executable in (root/'bin').iterdir():
|
|
executable.chmod(0o700)
|
|
env = dict(os.environ, PATH=str(root/'bin')+os.pathsep+os.environ['PATH'],
|
|
GATE_REAL_CTEST=shutil.which("ctest"), GATE_CTEST_STATUS=str(status), GATE_NINJA_STATUS=str(ninja_status), GATE_FAILURES=failures)
|
|
result = subprocess.run(['bash',str(root/'ops'/'regression_gate.sh'),str(root/'host')],
|
|
env=env,text=True,capture_output=True,timeout=10)
|
|
return result.returncode, result.stdout
|
|
|
|
def test_success(self):
|
|
code, output = self.run_gate(0)
|
|
self.assertEqual(code,0)
|
|
self.assertIn('GATE PASS',output)
|
|
|
|
def test_known_failure_remains_baselined(self):
|
|
code, output = self.run_gate(8,'1:known-test','known-test\n')
|
|
self.assertEqual(code,0)
|
|
self.assertIn('GATE PASS',output)
|
|
|
|
def test_new_failure(self):
|
|
code, output = self.run_gate(8,'1:new-test')
|
|
self.assertNotEqual(code,0)
|
|
self.assertNotIn('GATE PASS',output)
|
|
|
|
def test_unsuccessful_ctest_without_records(self):
|
|
for status in (1,2,8,127,130,137):
|
|
with self.subTest(status=status):
|
|
code, output = self.run_gate(status)
|
|
self.assertNotEqual(code,0)
|
|
self.assertNotIn('GATE PASS',output)
|
|
|
|
def test_interrupted_partial_known_failures(self):
|
|
code, output = self.run_gate(137,'1:known-test','known-test\n')
|
|
self.assertNotEqual(code,0)
|
|
self.assertNotIn('GATE PASS',output)
|
|
|
|
def test_real_ctest_empty_build_is_not_a_pass(self):
|
|
code, output = self.run_gate('empty')
|
|
self.assertNotEqual(code,0)
|
|
self.assertNotIn('GATE PASS',output)
|
|
|
|
def test_build_failure(self):
|
|
code, output = self.run_gate(0,ninja_status=1)
|
|
self.assertNotEqual(code,0)
|
|
self.assertNotIn('GATE PASS',output)
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|