From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756637Ab1JQQ7y (ORCPT ); Mon, 17 Oct 2011 12:59:54 -0400 Received: from hrndva-omtalb.mail.rr.com ([71.74.56.125]:45329 "EHLO hrndva-omtalb.mail.rr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756599Ab1JQQ7w (ORCPT ); Mon, 17 Oct 2011 12:59:52 -0400 X-Authority-Analysis: v=1.1 cv=G2mrdTwFgeQf4gnIVCGl5REDSA/JVLCrZmxI9r5hHjY= c=1 sm=0 a=vhdKIqpQuCYA:10 a=1Vthl_CjnasA:10 a=5SG0PmZfjMsA:10 a=bbbx4UPp9XUA:10 a=ZycB6UtQUfgMyuk2+PxD7w==:17 a=20KFwNOVAAAA:8 a=meVymXHHAAAA:8 a=g3W1TVA1e65YW-LzzFwA:9 a=IhAwZzdN0q-5rzXpZo8A:7 a=QEXdDO2ut3YA:10 a=jEp0ucaQiEUA:10 a=jeBq3FmKZ4MA:10 a=59up8UmTGVMYl7dueysA:9 a=ZycB6UtQUfgMyuk2+PxD7w==:117 X-Cloudmark-Score: 0 X-Originating-IP: 74.67.80.29 Message-Id: <20111017165951.607972540@goodmis.org> User-Agent: quilt/0.48-1 Date: Mon, 17 Oct 2011 12:05:05 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Subject: [PATCH 10/17][RFC] ktest: Let IF keyword take comparisons References: <20111017160455.498567257@goodmis.org> Content-Disposition: inline; filename=0010-ktest-Let-IF-keyword-take-comparisons.patch Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="00GvhwF7k39YY" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --00GvhwF7k39YY Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: Steven Rostedt Allow =3D=3D, !=3D, <=3D, >=3D, <, and > to be used in IF statements to compare if a section should be processed or not. For example: BITS :=3D 32 DEFAULTS IF ${BITS} =3D=3D 32 MIN_CONFIG =3D ${CONFIG_DIR}/config-32 ELSE MIN_CONFIG =3D ${CONFIG_DIR}/config-64 Signed-off-by: Steven Rostedt --- tools/testing/ktest/ktest.pl | 54 ++++++++++++++++++++++++++++++++++-= --- tools/testing/ktest/sample.conf | 14 ++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index c76e18f..ed20d68 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -361,11 +361,47 @@ sub set_variable { } } =20 +sub process_compare { + my ($lval, $cmp, $rval) =3D @_; + + # remove whitespace + + $lval =3D~ s/^\s*//; + $lval =3D~ s/\s*$//; + + $rval =3D~ s/^\s*//; + $rval =3D~ s/\s*$//; + + if ($cmp eq "=3D=3D") { + return $lval eq $rval; + } elsif ($cmp eq "!=3D") { + return $lval ne $rval; + } + + my $statement =3D "$lval $cmp $rval"; + my $ret =3D eval $statement; + + # $@ stores error of eval + if ($@) { + return -1; + } + + return $ret; +} + sub process_if { my ($name, $value) =3D @_; =20 my $val =3D process_variables($value); =20 + if ($val =3D~ /(.*)(=3D=3D|\!=3D|>=3D|<=3D|>|<)(.*)/) { + my $ret =3D process_compare($1, $2, $3); + if ($ret < 0) { + die "$name: $.: Unable to process comparison\n"; + } + return $ret; + } + if ($val =3D~ /^\s*0\s*$/) { return 0; } elsif ($val =3D~ /^\s*\d+\s*$/) { @@ -428,8 +464,8 @@ sub read_config { $repeat_tests{"$test_num"} =3D $repeat; } =20 - if ($rest =3D~ /\sIF\s+(\S*)(.*)/) { - $rest =3D $2; + if ($rest =3D~ /\sIF\s+(.*)/) { + $rest =3D ""; if (process_if($name, $1)) { $if_set =3D 1; } else { @@ -461,14 +497,14 @@ sub read_config { $skip =3D 0; } =20 - if ($rest =3D~ /\sIF\s+(\S*)(.*)/) { + if ($rest =3D~ /\sIF\s+(.*)/) { $if =3D 1; - $rest =3D $2; if (process_if($name, $1)) { $if_set =3D 1; } else { $skip =3D 1; } + $rest =3D ""; } else { $if =3D 0; } @@ -477,26 +513,32 @@ sub read_config { die "$name: $.: Gargbage found after DEFAULTS\n$_"; } =20 - } elsif (/^\s*ELSE(.*)$/) { + } elsif (/^\s*ELSE\b(.*)$/) { if (!$if) { die "$name: $.: ELSE found with out matching IF section\n$_"; } $rest =3D $1; if ($if_set) { $skip =3D 1; + $rest =3D ""; } else { $skip =3D 0; =20 - if ($rest =3D~ /\sIF\s+(\S*)(.*)/) { + if ($rest =3D~ /\sIF\s+(.*)/) { # May be a ELSE IF section. if (!process_if($name, $1)) { $skip =3D 1; } + $rest =3D ""; } else { $if =3D 0; } } =20 + if ($rest !~ /^\s*$/) { + die "$name: $.: Gargbage found after DEFAULTS\n$_"; + } + } elsif (/^\s*([A-Z_\[\]\d]+)\s*=3D\s*(.*?)\s*$/) { =20 next if ($skip); diff --git a/tools/testing/ktest/sample.conf b/tools/testing/ktest/sample.c= onf index 6a0a0ba..4e8fb91 100644 --- a/tools/testing/ktest/sample.conf +++ b/tools/testing/ktest/sample.conf @@ -72,6 +72,8 @@ # the same option name under the same test or as default # ktest will fail to execute, and no tests will run. # +# +# # Both TEST_START and DEFAULTS sections can also have the IF keyword # The value after the IF must evaluate into a 0 or non 0 positive # integer, and can use the config variables (explained below). @@ -110,6 +112,18 @@ # ELSE # BUILD_TYPE =3D useconfig:${CONFIG_DIR}/config-network # +# The if statement may also have comparisons that will and for +# =3D=3D and !=3D, strings may be used for both sides. +# +# BOX_TYPE :=3D x86_32 +# +# DEFAULTS IF ${BOX_TYPE} =3D=3D x86_32 +# BUILD_TYPE =3D useconfig:${CONFIG_DIR}/config-32 +# ELSE +# BUILD_TYPE =3D useconfig:${CONFIG_DIR}/config-64 +# + + =20 #### Config variables #### # --=20 1.7.6.3 --00GvhwF7k39YY Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAABAgAGBQJOnF8HAAoJEIy3vGnGbaoACZIP/iPgNlijOsSF3WYYIgqh7FHD 1JAyXyTG6yxW4mAr4u7p9JAhSahap2FzAdcgKSlbORhg3uu22Jpxs4L9ms+n8bJI K8R6yRvL8W75s5KK1ep0LjFqrj6QiDFX1Y4P+lXlicO76n2Rbcm6uf3lkFOGWDoa khAcKO0U3JsX42DBvIQJpw4eLTyTOhbPZP5rGkiE9i3Qack2iVELGj7WiOyCD5S7 JJi18/6BjadPNleZ/j8wIuBXojCAggiNUdOpNwj9fvXZOeqywq0mlHPtxuMKo/fQ yKGM807OO9DKzshMOo2uiq5hGZI7A+vV7MtT8ISSCbz/2DPuXd/rpnXaatI6UZET xSReFL1EwVX/wUVhjGTqkP33WoH52bDL/0F8ipOovQt83whtNY3jjWRUhVZJQO7Q h6Ml2OfJHVP5MralQWVrf9pkcPj0TXOdWMns2aVWlH1XHm1NuxolDaVFVnNUzHM+ pn9POgC0Wbo9EJdRbsY8PSEAcDghlgOidrTEsEo300yGEOgpM/Dm6Ms92MwDs4++ HUtcfcbKM1VwNR33VohRBOTqsJsTG0Az08hG4BiIbjr6AKUE6AS0je+Q1rnv3922 tWmUS75kYfwLWRbHtnHP3LY3UXG0JiKh6vTffar3S3ydHII+2mYQ8eJowu1XaAwE I03xgIom+qgIasPWyqna =gN1k -----END PGP SIGNATURE----- --00GvhwF7k39YY--