testdrive sets wrong MEM value

Bug #497499 reported by Roland Dreier
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
TestDrive
Fix Released
Medium
Dustin Kirkland 
testdrive (Ubuntu)
Fix Released
Medium
Dustin Kirkland 

Bug Description

I have testdrive 1.15-0ubuntu1~ppa4 installed, and it ends up passing 256 MB of memory when starting kvm if I set MEM in the config file, due to the code:

[ -z "$MEM" ] && [ $(grep "^MemTotal" /proc/meminfo | awk '{print $2}') -gt 1000000 ] && MEM=512 || MEM=256

the && and || operators are left-associative and have the same priority in shell, so this is evaluated as:

( ( [ -z "$MEM" ] && [ $(grep "^MemTotal" /proc/meminfo | awk '{print $2}') -gt 1000000 ] ) && MEM=512 ) || MEM=256

and the initial -z $MEM test ends up being false, so the expression falls through to the MEM=256 part.

I think the fix for this is to rewrite the expression as:

[ -z "$MEM" ] && { [ $(grep "^MemTotal" /proc/meminfo | awk '{print $2}') -gt 1000000 ] && MEM=512 || MEM=256 ; }

ie only do the whole "check MemTotal and default MEM based on that" thing if MEM isn't set in the first place.

Or perhaps make it more explicit and do

if [ -z "$MEM" ]; then
        [ $(grep "^MemTotal" /proc/meminfo | awk '{print $2}') -gt 1000000 ] && MEM=512 || MEM=256
fi

Changed in testdrive:
importance: Undecided → Medium
status: New → Triaged
Changed in testdrive:
status: Triaged → Fix Committed
Changed in testdrive (Ubuntu):
status: New → Fix Committed
importance: Undecided → Medium
Changed in testdrive:
assignee: nobody → Dustin Kirkland (kirkland)
Changed in testdrive (Ubuntu):
assignee: nobody → Dustin Kirkland (kirkland)
Changed in testdrive:
status: Fix Committed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package testdrive - 1.17-0ubuntu1

---------------
testdrive (1.17-0ubuntu1) lucid; urgency=low

  * testdrive-select-iso, testdriverc: netbook remix no longer "remix",
    LP: #505909
  * testdrive: fix MEM setting logic, LP: #497499
 -- Dustin Kirkland <email address hidden> Tue, 12 Jan 2010 14:55:34 -0600

Changed in testdrive (Ubuntu):
status: Fix Committed → Fix Released
Revision history for this message
Roland Dreier (roland.dreier) wrote :

I'm reopening this because as far as I can tell, the fix that was put in is bogus -- the code now reads:

if [ -z "$MEM" ]; then
        [ $(grep "^MemTotal" /proc/meminfo | awk '{print $2}') -gt 1000000 ] && MEM=512 || MEM=256
else
        MEM=256
fi

and that "else" clause is wrong. The whole point is that we don't want to set MEM if it is already set.

Changed in testdrive:
status: Fix Released → New
Changed in testdrive:
status: New → Confirmed
Changed in testdrive:
status: Confirmed → Fix Committed
Changed in testdrive:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.