support logical OR operations on options
authoranthraxx <levente@leventepolyak.net>
Mon, 25 Jun 2018 22:21:10 +0000 (00:21 +0200)
committerAlexander Popov <alex.popov@linux.com>
Tue, 24 Jul 2018 16:43:48 +0000 (19:43 +0300)
The OR class implementation supports combining Opt's logically
with an or-operator. If any of the Opt's provided to the OR class
returns True, the check is considered OK.

Fixes #1

Conflicts resolved by @a13xp0p0v

kconfig-hardened-check.py

index 30f3d1770ccc7b9e6fd80b0a93c0b0b3a5dccc71..89b343ef3662ad1391f9b7984eec7acdf45b509a 100755 (executable)
@@ -49,6 +49,41 @@ class OptCheck:
         return '{} = {}'.format(self.name, self.state)
 
 
+class OR:
+    def __init__(self, *opts):
+        self.opts = opts
+        self.result = None
+
+    @property
+    def name(self):
+        return self.opts[0].name
+
+    @property
+    def expected(self):
+        return self.opts[0].expected
+
+    @property
+    def state(self):
+        return self.opts[0].state
+
+    @property
+    def decision(self):
+        return self.opts[0].decision
+
+    @property
+    def reason(self):
+        return self.opts[0].reason
+
+    def check(self):
+        for opt in self.opts:
+            result, msg = opt.check()
+            if result:
+                self.result = 'OK (CONFIG_{} {})'.format(opt.name, opt.state)
+                return result, self.result
+        self.result = 'FAIL: "{}"'.format(self.opts[0].state)
+        return False, self.result
+
+
 def construct_opt_checks():
     checklist.append(OptCheck('BUG',                     'y', 'ubuntu18', 'self_protection'))
     checklist.append(OptCheck('PAGE_TABLE_ISOLATION',    'y', 'ubuntu18', 'self_protection'))
@@ -178,7 +213,11 @@ def get_option_state(options, name):
 
 def perform_checks(parsed_options):
     for opt in checklist:
-        opt.state = get_option_state(parsed_options, opt.name)
+        if hasattr(opt, 'opts'):
+            for o in opt.opts:
+                o.state = get_option_state(parsed_options, o.name)
+        else:
+            opt.state = get_option_state(parsed_options, opt.name)
         opt.check()