Servod: Updating servo_server.py to fix the keypress value issue

In keyboard.xml, 'map="keypress_duration"' restrict the key press control to
just the 'tab', 'press', and 'long_press' settings. This creates the problem
for the 'press' value triggered from Autotest like 'dut-control power_key:0.5'
& 'dut-control ctrl_d:0.1'.

And autotests are failing with error "Map keypress_duration doesn't contain
key \nTry one of -> 'press', 'long_press', 'tab'".

So adding new params in map (tab="0.1" & short_press="0.2") and mapping them
to the keys when autotest calling keypress without passing any values
(eg. self.servo.ctrl_d()).

And also added the try-except block in resolve_val to pass the ValueError
for the proper logging of error message at the end.

BUG=b:113756713
Branch=None
TEST=Verified firmware_FMap.dev & firmware_ECPowerButton tests on
Octopus-Yorp board, tests are passing. And also verified the following key
press events.
dut-control power_key_val:0.5
dut-control power_key:tab
dut-control power_key:press
dut-control power_key:long_press
dut-control ctrl_d:0.1

Change-Id: I3ae3d8c672c32f980a013f42c21554807fc17d08
Signed-off-by: Lenine Ajagappane <leninex.ajagappane@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/1206151
Commit-Ready: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Tested-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
diff --git a/servo/data/keyboard.xml b/servo/data/keyboard.xml
index 8db3d38..bf99e7a 100644
--- a/servo/data/keyboard.xml
+++ b/servo/data/keyboard.xml
@@ -3,11 +3,11 @@
   <map>
     <name>keypress_duration</name>
     <doc>short hand configs for keypress durations</doc>
-    <params tab="0.2" press="1.2" long_press="8.5"></params>
+    <params tab="0.1" short_press="0.2" press="1.2" long_press="8.5"></params>
   </map>
   <control>
     <name>power_key</name>
-    <doc>Send d key either by servoflex or USB KB emulation</doc>
+    <doc>Send power key either by servoflex or USB KB emulation</doc>
     <params cmd="set" key="power_key" interface="servo" drv="kb"
     input_type="float" map="keypress_duration" clobber_ok=""></params>
   </control>
diff --git a/servo/servo_server.py b/servo/servo_server.py
index c73fa94..25e7a2e 100755
--- a/servo/servo_server.py
+++ b/servo/servo_server.py
@@ -1125,64 +1125,65 @@
 
   def power_short_press(self):
     """Simulate a short power button press."""
-    return self.set('power_key', 'tab')
+    return self.set('power_key', 'short_press')
 
-  def power_key(self, secs=''):
+  def power_key(self, press_secs=''):
     """Simulate a power button press.
 
     Args:
-      secs: Time in seconds to simulate the keypress.
+      press_secs: Time in seconds to simulate the keypress.
     """
-    return self.set('power_key', secs)
+    return self.set('power_key', 'press' if press_secs is '' else press_secs)
 
   def ctrl_d(self, press_secs=''):
     """Simulate Ctrl-d simultaneous button presses."""
-    return self.set('ctrl_d', press_secs)
+    return self.set('ctrl_d', 'tab' if press_secs is '' else press_secs)
 
   def ctrl_u(self, press_secs=''):
     """Simulate Ctrl-u simultaneous button presses."""
-    return self.set('ctrl_u', press_secs)
+    return self.set('ctrl_u', 'tab' if press_secs is '' else press_secs)
 
   def ctrl_enter(self, press_secs=''):
     """Simulate Ctrl-enter simultaneous button presses."""
-    return self.set('ctrl_enter', press_secs)
+    return self.set('ctrl_enter', 'tab' if press_secs is '' else press_secs)
 
   def d_key(self, press_secs=''):
     """Simulate Enter key button press."""
-    return self.set('d_key', press_secs)
+    return self.set('d_key', 'tab' if press_secs is '' else press_secs)
 
   def ctrl_key(self, press_secs=''):
     """Simulate Enter key button press."""
-    return self.set('ctrl_key', press_secs)
+    return self.set('ctrl_key', 'tab' if press_secs is '' else press_secs)
 
   def enter_key(self, press_secs=''):
     """Simulate Enter key button press."""
-    return self.set('enter_key', press_secs)
+    return self.set('enter_key', 'tab' if press_secs is '' else press_secs)
 
   def refresh_key(self, press_secs=''):
     """Simulate Refresh key (F3) button press."""
-    return self.set('refresh_key', press_secs)
+    return self.set('refresh_key', 'tab' if press_secs is '' else press_secs)
 
   def ctrl_refresh_key(self, press_secs=''):
     """Simulate Ctrl and Refresh (F3) simultaneous press.
 
     This key combination is an alternative of Space key.
     """
-    return self.set('ctrl_refresh_key', press_secs)
+    return self.set('ctrl_refresh_key', ('tab' if press_secs is '' else
+                                         press_secs))
 
   def imaginary_key(self, press_secs=''):
     """Simulate imaginary key button press.
 
     Maps to a key that doesn't physically exist.
     """
-    return self.set('imaginary_key', press_secs)
+    return self.set('imaginary_key', 'tab' if press_secs is '' else press_secs)
 
   def sysrq_x(self, press_secs=''):
     """Simulate Alt VolumeUp X simultaneous press.
 
     This key combination is the kernel system request (sysrq) x.
     """
-    return self.set('sysrq_x', press_secs)
+    return self.set('sysrq_x', 'tab' if press_secs is '' else press_secs)
 
   def get_servo_serials(self):
     """Return all the serials associated with this process."""
diff --git a/servo/system_config.py b/servo/system_config.py
index a7b1d2e..dc22094 100644
--- a/servo/system_config.py
+++ b/servo/system_config.py
@@ -390,12 +390,17 @@
       except KeyError:
         # Do not raise error yet. This might just be that the input is not
         # using the map i.e. it's directly writing a raw mapped value.
-        err = "Map %s doesn't contain key %s\n" % (params['map'], map_vstr)
+        err = "Map '%s' doesn't contain key '%s'\n" % (params['map'], map_vstr)
         err += "Try one of -> '%s'" % "', '".join(map_dict['map_params'].keys())
     if 'input_type' in params:
       if params['input_type'] in ALLOWABLE_INPUT_TYPES:
-        input_type = ALLOWABLE_INPUT_TYPES[params['input_type']]
-        return input_type(map_vstr)
+        try:
+          input_type = ALLOWABLE_INPUT_TYPES[params['input_type']]
+          return input_type(map_vstr)
+        except ValueError:
+          err += "\n%s Input should be 'int' or 'float'." % ('Or' if 'Map' in
+                                                             err else '')
+          pass
       else:
         self._logger.error('Unrecognized input type.')
     # TODO(tbroch): deprecate below once all controls have input_type params