@@ -67,6 +67,12 @@ from typing import (
67
67
# Globals
68
68
# -----------------------------------------------------------------------------
69
69
70
+
71
+ # Exit codes
72
+ EXIT_SUCCESS = 0
73
+ EXIT_ERROR = 1
74
+
75
+
70
76
INOTIFY_RECOMMENDED = 64000
71
77
INOTIFY_PER_CONTAINER = 4000
72
78
@@ -319,12 +325,13 @@ class CheckState(enum.Enum):
319
325
# 'success' check states
320
326
SUCCESS = "success"
321
327
NEUTRAL = "neutral"
322
- # 'failure ' check states
328
+ # 'warning ' check states
323
329
WARNING = "warning"
330
+ # 'failure' check states
324
331
SKIPPED = "skipped"
325
332
FAILED = "failed"
326
333
# Check state for when the check fails to run/errors
327
- # Note: this is neither 'success' nor 'failure'
334
+ # Note: this is not 'success', 'warning' or 'failure'
328
335
ERROR = "error"
329
336
330
337
def is_failure (self ) -> bool :
@@ -335,7 +342,6 @@ class CheckState(enum.Enum):
335
342
return self in [
336
343
CheckState .FAILED ,
337
344
CheckState .SKIPPED ,
338
- CheckState .WARNING ,
339
345
]
340
346
341
347
@@ -1597,20 +1603,29 @@ def perform_checks(checks: List[Check]) -> Mapping[str, CheckState]:
1597
1603
return results
1598
1604
1599
1605
1606
+ class ExtraResults (NamedTuple ):
1607
+ """The results of any extra checks."""
1608
+
1609
+ supported : Set [str ]
1610
+ not_supported : Set [str ]
1611
+ errored : Set [str ]
1612
+ warned : Set [str ]
1613
+
1614
+
1600
1615
def run_if_extra_checks (
1601
1616
extra_checks : Optional [List [str ]] = None ,
1602
- ) -> Tuple [ Set [ str ], Set [ str ], Set [ str ]] :
1617
+ ) -> ExtraResults :
1603
1618
"""
1604
- Run the specified extra checks, printing the results and returning the
1605
- checks that succeeded, failed and errored.
1619
+ Run the specified extra checks, printing the results.
1606
1620
:param extra_checks:
1607
1621
List of extra checks to perform.
1608
1622
:returns:
1609
- Tuple of the checks that: succeeded, failed and errored .
1623
+ NamedTuple of sets of checks that succeeded, failed, errored and warned .
1610
1624
"""
1611
1625
extras_supported = set ()
1612
1626
extras_not_supported = set ()
1613
1627
extras_errored = set ()
1628
+ extras_warned = set ()
1614
1629
1615
1630
if extra_checks :
1616
1631
print ("" ) # insert a newline
@@ -1623,40 +1638,49 @@ def run_if_extra_checks(
1623
1638
extras_not_supported .add (extra_check )
1624
1639
elif any (c is CheckState .ERROR for c in extra_results .values ()):
1625
1640
extras_errored .add (extra_check )
1641
+ elif any (c is CheckState .WARNING for c in extra_results .values ()):
1642
+ extras_warned .add (extra_check )
1626
1643
else :
1627
1644
extras_supported .add (extra_check )
1628
1645
1629
- return extras_supported , extras_not_supported , extras_errored
1646
+ return ExtraResults (
1647
+ extras_supported ,
1648
+ extras_not_supported ,
1649
+ extras_errored ,
1650
+ extras_warned ,
1651
+ )
1630
1652
1631
1653
1632
- def print_extra_checks_summary (
1633
- extras_supported : Set [str ],
1634
- extras_not_supported : Set [str ],
1635
- extras_errored : Set [str ],
1636
- ) -> None :
1654
+ def print_extra_checks_summary (extra_results : ExtraResults ) -> None :
1637
1655
"""
1638
1656
Print a summary of the extra checks that passed and failed.
1639
- :param extras_supported:
1640
- The checks that were successful.
1641
- :param extras_not_supported:
1642
- The checks that were not successful.
1643
- :param extras_errored:
1644
- The checks that errored/failed to run.
1657
+ :param extras_results:
1658
+ The results of the extra checks.
1645
1659
"""
1646
1660
print (f"{ DASHED_LINE } " )
1647
- if extras_supported :
1648
- print ("Extra checks passed: " + ", " .join (sorted (extras_supported )))
1649
- if extras_not_supported :
1661
+ if extra_results .supported :
1662
+ print (
1663
+ "Extra checks passed: "
1664
+ + ", " .join (sorted (extra_results .supported ))
1665
+ )
1666
+ if extra_results .not_supported :
1667
+ print (
1668
+ "Extra checks failed: "
1669
+ + ", " .join (sorted (extra_results .not_supported ))
1670
+ )
1671
+ if extra_results .errored :
1650
1672
print (
1651
- "Extra checks failed: " + ", " .join (sorted (extras_not_supported ))
1673
+ "Extra checks errored: " + ", " .join (sorted (extra_results .errored ))
1674
+ )
1675
+ if extra_results .warned :
1676
+ print (
1677
+ "Extra checks warned: " + ", " .join (sorted (extra_results .warned ))
1652
1678
)
1653
- if extras_errored :
1654
- print ("Extra checks errored: " + ", " .join (sorted (extras_errored )))
1655
1679
1656
1680
1657
1681
def run_checks_specific_platform (
1658
1682
platform : str , extra_checks : List [str ]
1659
- ) -> bool :
1683
+ ) -> int :
1660
1684
"""
1661
1685
Run checks for the given platform (including the base checks that are
1662
1686
required for all platforms).
@@ -1666,19 +1690,18 @@ def run_checks_specific_platform(
1666
1690
:param extra_checks:
1667
1691
A list of the extra checks.
1668
1692
:return:
1669
- Whether all checks that were performed succeeded.
1693
+ EXIT_SUCCESS if all checks were successful
1694
+ EXIT_ERROR if there are any failures, warnings or errors (including
1695
+ extra checks)
1670
1696
"""
1671
1697
1672
1698
print_heading (f"Platform checks - { platform } " )
1673
1699
plat_results = perform_checks (BASE_CHECKS + PLATFORM_CHECKS_MAP [platform ])
1674
1700
plat_failure = any (check .is_failure () for check in plat_results .values ())
1675
1701
plat_error = any (c is CheckState .ERROR for c in plat_results .values ())
1702
+ plat_warning = any (c is CheckState .WARNING for c in plat_results .values ())
1676
1703
1677
- (
1678
- extras_supported ,
1679
- extras_not_supported ,
1680
- extras_errored ,
1681
- ) = run_if_extra_checks (extra_checks )
1704
+ extra_results = run_if_extra_checks (extra_checks )
1682
1705
1683
1706
# Print a summary of what is and is not supported
1684
1707
print (f"\n { DOUBLE_DASHED_LINE } " )
@@ -1688,29 +1711,44 @@ def run_checks_specific_platform(
1688
1711
print (
1689
1712
"!! One or more platform checks could not be performed, see errors above !!"
1690
1713
)
1714
+ elif plat_warning :
1715
+ print (
1716
+ "!! One or more platform checks resulted in a warning, see warnings above !!"
1717
+ )
1691
1718
else :
1692
1719
print (f"Host environment set up correctly for { platform } " )
1693
1720
if extra_checks :
1694
- print_extra_checks_summary (
1695
- extras_supported , extras_not_supported , extras_errored
1696
- )
1721
+ print_extra_checks_summary (extra_results )
1697
1722
print (f"{ DOUBLE_DASHED_LINE } " )
1698
1723
1699
- return not (
1700
- plat_failure or plat_error or extras_not_supported or extras_errored
1701
- )
1724
+ if (
1725
+ plat_failure
1726
+ or plat_error
1727
+ or extra_results .not_supported
1728
+ or extra_results .errored
1729
+ or plat_warning
1730
+ or extra_results .warned
1731
+ ):
1732
+ rc = EXIT_ERROR
1733
+ else :
1734
+ rc = EXIT_SUCCESS
1735
+
1736
+ return rc
1702
1737
1703
1738
1704
- def run_checks_all_platforms (extra_checks : List [str ]) -> bool :
1739
+ def run_checks_all_platforms (extra_checks : List [str ]) -> int :
1705
1740
"""
1706
1741
Run checks for all platforms and report which platforms are supported.
1707
1742
1708
1743
:return:
1709
- Whether at least one XR platform is supported.
1744
+ EXIT_SUCCESS if all checks were successful
1745
+ EXIT_ERROR if there are any failures, warnings or errors (including
1746
+ extra tests)
1710
1747
"""
1711
1748
platforms_supported : Set [str ] = set ()
1712
1749
platforms_not_supported : Set [str ] = set ()
1713
1750
platforms_errored : Set [str ] = set ()
1751
+ platforms_warned : Set [str ] = set ()
1714
1752
1715
1753
print_heading ("Platform checks" )
1716
1754
print_subheading ("base checks" )
@@ -1727,14 +1765,14 @@ def run_checks_all_platforms(extra_checks: List[str]) -> bool:
1727
1765
result is CheckState .ERROR for result in base_and_plat_results
1728
1766
):
1729
1767
platforms_errored .add (platform )
1768
+ elif any (
1769
+ result is CheckState .WARNING for result in base_and_plat_results
1770
+ ):
1771
+ platforms_warned .add (platform )
1730
1772
else :
1731
1773
platforms_supported .add (platform )
1732
1774
1733
- (
1734
- extras_supported ,
1735
- extras_not_supported ,
1736
- extras_errored ,
1737
- ) = run_if_extra_checks (extra_checks )
1775
+ extra_results = run_if_extra_checks (extra_checks )
1738
1776
1739
1777
# Print a summary of what is and is not supported
1740
1778
print (f"\n { DOUBLE_DASHED_LINE } " )
@@ -1744,21 +1782,43 @@ def run_checks_all_platforms(extra_checks: List[str]) -> bool:
1744
1782
)
1745
1783
if platforms_not_supported :
1746
1784
print (
1747
- "XR platforms NOT supported: "
1785
+ "!! XR platforms NOT supported: "
1748
1786
+ ", " .join (sorted (platforms_not_supported ))
1787
+ + " !!"
1749
1788
)
1750
1789
if platforms_errored :
1751
1790
print (
1752
- "!! One or more platform checks could not be performed, see errors above !!"
1791
+ "!! One or more platform checks could not be performed for XR platforms: !!"
1792
+ + "\n "
1793
+ + ",\n " .join (sorted (platforms_errored ))
1794
+ + "\n See errors above."
1795
+ )
1796
+ if platforms_warned :
1797
+ print (
1798
+ "!! One or more platform checks resulted in a warning for XR platforms: !!"
1799
+ + "\n "
1800
+ + ",\n " .join (sorted (platforms_warned ))
1801
+ + "\n See warnings above."
1753
1802
)
1803
+
1754
1804
# Print the result of any extra checks
1755
1805
if extra_checks :
1756
- print_extra_checks_summary (
1757
- extras_supported , extras_not_supported , extras_errored
1758
- )
1806
+ print_extra_checks_summary (extra_results )
1759
1807
print (f"{ DOUBLE_DASHED_LINE } " )
1760
1808
1761
- return len (platforms_supported ) > 0
1809
+ if (
1810
+ platforms_not_supported
1811
+ or platforms_errored
1812
+ or extra_results .not_supported
1813
+ or extra_results .errored
1814
+ or platforms_warned
1815
+ or extra_results .warned
1816
+ ):
1817
+ rc = EXIT_ERROR
1818
+ else :
1819
+ rc = EXIT_SUCCESS
1820
+
1821
+ return rc
1762
1822
1763
1823
1764
1824
def parse_args (argv : List [str ]) -> argparse .Namespace :
@@ -1786,12 +1846,10 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
1786
1846
def main (argv : List [str ]) -> NoReturn :
1787
1847
args = parse_args (argv )
1788
1848
if args .platform :
1789
- success = run_checks_specific_platform (
1790
- args .platform , args .extra_checks
1791
- )
1849
+ rc = run_checks_specific_platform (args .platform , args .extra_checks )
1792
1850
else :
1793
- success = run_checks_all_platforms (args .extra_checks )
1794
- sys .exit (0 if success else 1 )
1851
+ rc = run_checks_all_platforms (args .extra_checks )
1852
+ sys .exit (rc )
1795
1853
1796
1854
1797
1855
if __name__ == "__main__" :
0 commit comments