summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhaoqi Xu <lzy00419@outlook.com>2026-08-31 11:33:43 +0300
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2026-09-29 20:12:07 +0300
commit53d441a7402aab3ecd02909ae1a0ae6a2e135332 (patch)
treec2494558cf73de60ddfb515c8fefb7c07a417ed4
parentf21a6e6fb6cd915584fbccfd421c2088d22ca5ba (diff)
downloadedk2-master.tar.xz
BaseTools/FMMT: Return non-zero exit status on failureHEADmaster
FMMT catches exceptions from operations such as viewing a missing input file, prints the error, and then returns status 0. Callers and scripts treat that as success. Set status to 1 in the exception handler so the process exit code matches the failure. A regression test covers FMMT -v not-a-file. Signed-off-by: Zhaoqi Xu <lzy00419@outlook.com>
-rw-r--r--BaseTools/Source/Python/FMMT/FMMT.py1
-rw-r--r--BaseTools/Tests/TestFmmtExit.py55
2 files changed, 56 insertions, 0 deletions
diff --git a/BaseTools/Source/Python/FMMT/FMMT.py b/BaseTools/Source/Python/FMMT/FMMT.py
index d4fa07a984..e8bc9ea09a 100644
--- a/BaseTools/Source/Python/FMMT/FMMT.py
+++ b/BaseTools/Source/Python/FMMT/FMMT.py
@@ -155,6 +155,7 @@ def main():
parser.print_help()
except Exception as e:
print(e)
+ status = 1
return status
diff --git a/BaseTools/Tests/TestFmmtExit.py b/BaseTools/Tests/TestFmmtExit.py
new file mode 100644
index 0000000000..f0d4d4f5b9
--- /dev/null
+++ b/BaseTools/Tests/TestFmmtExit.py
@@ -0,0 +1,55 @@
+## @file
+# Tests for FMMT CLI exit status.
+#
+# Copyright (c) 2026, Zhaoqi Xu <lzy00419@outlook.com>. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+
+import os
+import subprocess
+import sys
+import unittest
+from pathlib import Path
+
+_BASETOOLS = Path(__file__).resolve().parent.parent
+_PYTHON_SRC = _BASETOOLS / 'Source' / 'Python'
+_FMMT_DIR = _PYTHON_SRC / 'FMMT'
+_FMMT_PY = _FMMT_DIR / 'FMMT.py'
+
+
+def _fmmt_env():
+ env = os.environ.copy()
+ extra = os.pathsep.join((str(_PYTHON_SRC), str(_FMMT_DIR)))
+ env['PYTHONPATH'] = extra + os.pathsep + env.get('PYTHONPATH', '')
+ return env
+
+
+class TestFmmtExit(unittest.TestCase):
+ def test_view_missing_file_exits_nonzero(self):
+ result = subprocess.run(
+ [sys.executable, str(_FMMT_PY), '-v', 'not-a-file'],
+ env=_fmmt_env(),
+ capture_output=True,
+ text=True,
+ )
+ self.assertNotEqual(
+ result.returncode,
+ 0,
+ msg='FMMT -v not-a-file must fail: stdout=%r stderr=%r' % (
+ result.stdout, result.stderr),
+ )
+ combined = result.stdout + result.stderr
+ self.assertIn('Invalid inputfile', combined)
+
+ def test_help_exits_zero(self):
+ result = subprocess.run(
+ [sys.executable, str(_FMMT_PY), '-h'],
+ env=_fmmt_env(),
+ capture_output=True,
+ text=True,
+ )
+ self.assertEqual(result.returncode, 0)
+
+
+if __name__ == '__main__':
+ unittest.main()