Bug #55582 mtr root detection (and if-expression execution) broken
Submitted: 27 Jul 2010 13:25 Modified: 13 Nov 2010 16:13
Reporter: Domas Mituzas Email Updates:
Status: Closed Impact on me:
None 
Category:Tools: MTR / mysql-test-run Severity:S3 (Non-critical)
Version:5.1-bzr OS:Any (MacOSX 10.6)
Assigned to: Bjørn Munch
Tags: Contribution
Triage: Needs Triage: D3 (Medium)

[27 Jul 2010 13:25] Domas Mituzas
Description:
5.1-bzr mysql test suite doesn't correctly run include/not_as_root.inc

even though it is straightforward:

if ($MYSQL_TEST_ROOT){
 skip Not as root;
}

it does not evaluate to false when MYsQL_TEST_ROOT is set to "YES" (I can verify that with echo in a script too).

How to repeat:
run this testcase as root:

--source include/not_as_root.inc
--echo STILL RUNNING! $MYSQL_TEST_ROOT

Suggested fix:
my current hack is following, and it works, though I'm sure, that making expressions work would be much better, than work around by setting it to 1. 

=== modified file 'mysql-test/mysql-test-run.pl'
--- mysql-test/mysql-test-run.pl	2010-02-17 15:28:02 +0000
+++ mysql-test/mysql-test-run.pl	2010-07-27 13:19:36 +0000
@@ -2241,7 +2241,7 @@
   {
     mtr_warning("running this script as _root_ will cause some " .
                 "tests to be skipped");
-    $ENV{'MYSQL_TEST_ROOT'}= "YES";
+    $ENV{'MYSQL_TEST_ROOT'}= 1;
   }
 
   chmod(oct("0755"), $test_file);
[27 Jul 2010 13:38] Valerii Kravchuk
Verified on Mac OS X:

macbook-pro:mysql-test openxs$ sudo ./mtr bug55582
Password:
Logging: ./mtr  bug55582
100727 16:36:04 [Warning] Setting lower_case_table_names=2 because file system for /tmp/NGDagAh0tk/ is case insensitive
100727 16:36:04 [Note] Plugin 'FEDERATED' is disabled.
100727 16:36:04 [Note] Plugin 'ndbcluster' is disabled.
MySQL Version 5.1.50
Checking supported features...
 - using ndbcluster when necessary, mysqld supports it
 - SSL connections supported
 - binaries are debug compiled
Collecting tests...
vardir: /Users/openxs/dbs/5.1/mysql-test/var
Checking leftover processes...
Removing old var directory...
 - WARNING: Using the 'mysql-test/var' symlink
Creating var directory '/Users/openxs/dbs/5.1/mysql-test/var'...
Installing system database...
Using server port 61902

==============================================================================

TEST                                      RESULT   TIME (ms)
------------------------------------------------------------

worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 13000..13009
worker[1] mysql-test-run: WARNING: running this script as _root_ will cause some tests to be skipped
main.bug55582                            [ fail ]
        Test ended at 2010-07-27 16:36:08

CURRENT_TEST: main.bug55582
--- /Users/openxs/dbs/5.1/mysql-test/r/bug55582.result	2010-07-27 16:35:33.000000000 +0300
+++ /Users/openxs/dbs/5.1/mysql-test/r/bug55582.reject	2010-07-27 16:36:08.000000000 +0300
@@ -0,0 +1 @@
+STILL RUNNING! YES
[3 Aug 2010 12:28] Bjørn Munch
The proposed one-line patch would resolve this particular issue, but I'd prefer to fix the semantics of if(). Treating any non-numeric string as being false is counter-intuitive and the result of simplistic programming. The documentation does not state how non-numeric values are treated in if().

I have a working fix for this. No tests that I ran were negatively affected except one which was actually incorrectly coded. I am unable to commit at the moment due to some temporary SNAFU in my local repository or bzr installation, will do as soon as I have this resolved.
[3 Aug 2010 14:12] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/114941

2921 Bjorn Munch	2010-08-03
      Bug #55582 mtr root detection (and if-expression execution) broken
      if() treated any non-numeric string as false
      Fixed to treat those as true instead
      Added some test cases
      Fixed missing $ in variable name in include/mix2.inc
[3 Aug 2010 14:20] Magnus Blåudd
Why skip unary + and - ?

Otherwise looks ok
[3 Aug 2010 14:23] Bjørn Munch
Well, -0 or +0 would evaluate to numeric 0 and I think it makes sense for this also to be treated as false. Not that it's very likely to occur...
[4 Aug 2010 8:54] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/114986

2922 Bjorn Munch	2010-08-04
      Bug #55582 mtr root detection (and if-expression execution) broken
      Follow-up patch: added test cases for -0 and while
[4 Aug 2010 13:11] Bjørn Munch
Pushed to next-mr-mtr, trunk-mtr, 5.1-mtr. Expecting merge to main branches soon.
[16 Aug 2010 6:31] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@sun.com-20100816062701-qo9dpnk5tkt1pksb) (version source revid:alik@sun.com-20100816062603-xc16eftmv7rmktyq) (merge vers: 5.6.1-m4) (pib:20)
[16 Aug 2010 6:34] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100816062819-bluwgdq8q4xysmlg) (version source revid:alik@sun.com-20100816062612-enatdwnv809iw3s9) (pib:20)
[16 Aug 2010 17:04] Paul Dubois
Test suite changes. No changelog entry needed.
[28 Sep 2010 8:50] Bugs System
Pushed into mysql-5.1 5.1.52 (revid:sunanda.menon@sun.com-20100928083322-wangbv97uobu7g66) (version source revid:sunanda.menon@sun.com-20100928083322-wangbv97uobu7g66) (merge vers: 5.1.52) (pib:21)
[14 Oct 2010 8:29] Bugs System
Pushed into mysql-5.1-telco-7.0 5.1.51-ndb-7.0.20 (revid:martin.skold@mysql.com-20101014082627-jrmy9xbfbtrebw3c) (version source revid:martin.skold@mysql.com-20101014082627-jrmy9xbfbtrebw3c) (merge vers: 5.1.51-ndb-7.0.20) (pib:21)
[14 Oct 2010 8:44] Bugs System
Pushed into mysql-5.1-telco-6.3 5.1.51-ndb-6.3.39 (revid:martin.skold@mysql.com-20101014083757-5qo48b86d69zjvzj) (version source revid:martin.skold@mysql.com-20101014083757-5qo48b86d69zjvzj) (merge vers: 5.1.51-ndb-6.3.39) (pib:21)
[14 Oct 2010 8:59] Bugs System
Pushed into mysql-5.1-telco-6.2 5.1.51-ndb-6.2.19 (revid:martin.skold@mysql.com-20101014084420-y54ecj85j5we27oa) (version source revid:martin.skold@mysql.com-20101014084420-y54ecj85j5we27oa) (merge vers: 5.1.51-ndb-6.2.19) (pib:21)
[15 Oct 2010 14:03] Jon Stephens
Set back to Closed -- see above.
[20 Oct 2010 14:17] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/121341

2943 Bjorn Munch	2010-10-20
      Follow-up to Bug #55582 which allows chaecking strings in if
      Simplified cases where a select was used to compare variable against ''
[21 Oct 2010 13:21] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/121535

2947 Bjorn Munch	2010-10-21
      Follow-up to Bug #55582 which allows checking strings in if
        Simplified cases where a select was used to compare variable against ''
[29 Oct 2010 15:31] Paul Dubois
Changes to test suite. No changelog entry needed.
[13 Nov 2010 16:05] Bugs System
Pushed into mysql-trunk 5.6.99-m5 (revid:alexander.nozdrin@oracle.com-20101113155825-czmva9kg4n31anmu) (version source revid:alexander.nozdrin@oracle.com-20101113152450-2zzcm50e7i4j35v7) (merge vers: 5.6.1-m4) (pib:21)
[13 Nov 2010 16:31] Bugs System
Pushed into mysql-next-mr (revid:alexander.nozdrin@oracle.com-20101113160336-atmtmfb3mzm4pz4i) (version source revid:vasil.dimov@oracle.com-20100629074804-359l9m9gniauxr94) (pib:21)
[18 Nov 2010 15:56] Bugs System
Pushed into mysql-5.1 5.1.54 (revid:build@mysql.com-20101118153531-693taxtxyxpt037i) (version source revid:build@mysql.com-20101118153531-693taxtxyxpt037i) (merge vers: 5.1.54) (pib:21)
[16 Dec 2010 22:27] Bugs System
Pushed into mysql-5.5 5.5.9 (revid:jonathan.perkin@oracle.com-20101216101358-fyzr1epq95a3yett) (version source revid:jonathan.perkin@oracle.com-20101216101358-fyzr1epq95a3yett) (merge vers: 5.5.9) (pib:24)