From patchwork Mon Feb 21 10:18:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 577311 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1LAIoGx009768 for ; Mon, 21 Feb 2011 10:18:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755163Ab1BUKSj (ORCPT ); Mon, 21 Feb 2011 05:18:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:65304 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755118Ab1BUKSf (ORCPT ); Mon, 21 Feb 2011 05:18:35 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1LAIYn3023882 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 21 Feb 2011 05:18:34 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p1LAIXAm032220; Mon, 21 Feb 2011 05:18:33 -0500 Received: from qu0061.eng.lab.tlv.redhat.com ([10.35.16.61]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p1LAITx3004094; Mon, 21 Feb 2011 05:18:32 -0500 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 3/3] KVM test: kvm_config.py: support negative conditional blocks Date: Mon, 21 Feb 2011 12:18:46 +0200 Message-Id: <1298283526-21348-3-git-send-email-mgoldish@redhat.com> In-Reply-To: <1298283526-21348-1-git-send-email-mgoldish@redhat.com> References: <1298283526-21348-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 21 Feb 2011 10:18:50 +0000 (UTC) diff --git a/client/tests/kvm/kvm_config.py b/client/tests/kvm/kvm_config.py index b6e089b..4dbb1d4 100755 --- a/client/tests/kvm/kvm_config.py +++ b/client/tests/kvm/kvm_config.py @@ -137,6 +137,14 @@ class NoOnlyFilter(Filter): class OnlyFilter(NoOnlyFilter): + def is_irrelevant(self, ctx, ctx_set, descendant_labels): + return self.match(ctx, ctx_set) + + + def requires_action(self, ctx, ctx_set, descendant_labels): + return not self.might_match(ctx, ctx_set, descendant_labels) + + def might_pass(self, failed_ctx, failed_ctx_set, ctx, ctx_set, descendant_labels): for word in self.filter: @@ -148,6 +156,14 @@ class OnlyFilter(NoOnlyFilter): class NoFilter(NoOnlyFilter): + def is_irrelevant(self, ctx, ctx_set, descendant_labels): + return not self.might_match(ctx, ctx_set, descendant_labels) + + + def requires_action(self, ctx, ctx_set, descendant_labels): + return self.match(ctx, ctx_set) + + def might_pass(self, failed_ctx, failed_ctx_set, ctx, ctx_set, descendant_labels): for word in self.filter: @@ -165,6 +181,13 @@ class Condition(NoFilter): self.content = [] +class NegativeCondition(OnlyFilter): + def __init__(self, line): + Filter.__init__(self, line.lstrip("!").rstrip(":")) + self.line = line + self.content = [] + + class Parser(object): """ Parse an input file or string that follows the KVM Test Config File format @@ -229,24 +252,15 @@ class Parser(object): if type(obj) is Op: new_content.append(t) continue - elif type(obj) is OnlyFilter: - if not obj.might_match(ctx, ctx_set, labels): - self._debug(" filter did not pass: %r (%s:%s)", - obj.line, filename, linenum) - failed_filters.append(t) - return False - elif obj.match(ctx, ctx_set): - continue - elif type(obj) is NoFilter: - if obj.match(ctx, ctx_set): + # obj is an OnlyFilter/NoFilter/Condition/NegativeCondition + if obj.requires_action(ctx, ctx_set, labels): + # This filter requires action now + if type(obj) is OnlyFilter or type(obj) is NoFilter: self._debug(" filter did not pass: %r (%s:%s)", obj.line, filename, linenum) failed_filters.append(t) return False - elif not obj.might_match(ctx, ctx_set, labels): - continue - elif type(obj) is Condition: - if obj.match(ctx, ctx_set): + else: self._debug(" conditional block matches: %r (%s:%s)", obj.line, filename, linenum) # Check and unpack the content inside this Condition @@ -259,9 +273,12 @@ class Parser(object): failed_filters.append(t) return False continue - elif not obj.might_match(ctx, ctx_set, labels): - continue - new_content.append(t) + elif obj.is_irrelevant(ctx, ctx_set, labels): + # This filter is no longer relevant and can be removed + continue + else: + # Keep the filter and check it again later + new_content.append(t) return True def might_pass(failed_ctx, @@ -429,7 +446,8 @@ class Parser(object): # Parse 'variants' if line == "variants:": # 'variants' is not allowed inside a conditional block - if isinstance(node, Condition): + if (isinstance(node, Condition) or + isinstance(node, NegativeCondition)): raise ParserError("'variants' is not allowed inside a " "conditional block", None, cr.filename, linenum) @@ -481,7 +499,10 @@ class Parser(object): cr.set_next_line(line[index:], indent, linenum) line = line[:index] try: - cond = Condition(line) + if line.startswith("!"): + cond = NegativeCondition(line) + else: + cond = Condition(line) except ParserError, e: e.line = line e.filename = cr.filename