Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Unified Diff: client/site_tests/platform_CrosDisksDBus/platform_CrosDisksDBus.py

Issue 6873021: Test CrosDisks DBus API (Closed) Base URL: ssh://gitrw.chromium.org:9222/autotest.git@master
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/site_tests/platform_CrosDisksDBus/platform_CrosDisksDBus.py
diff --git a/client/site_tests/platform_CrosDisksDBus/platform_CrosDisksDBus.py b/client/site_tests/platform_CrosDisksDBus/platform_CrosDisksDBus.py
index ba9699dd869432f0fbb40082f01870dbebd8896b..125bb3e310460012eb70336e71f42f2de1646c05 100644
--- a/client/site_tests/platform_CrosDisksDBus/platform_CrosDisksDBus.py
+++ b/client/site_tests/platform_CrosDisksDBus/platform_CrosDisksDBus.py
@@ -10,12 +10,84 @@ import dbus
class platform_CrosDisksDBus(test.test):
version = 1
+ def validate_disk(self, disk):
+ # Disk properties provided by the API
+ disk_properties = (
+ ('DeviceFile', dbus.String),
+ ('DeviceIsDrive', dbus.Boolean),
+ ('DeviceIsMediaAvailable', dbus.Boolean),
+ ('DeviceIsMounted', dbus.Boolean),
+ ('DeviceIsOpticalDisc', dbus.Boolean),
+ ('DeviceIsReadOnly', dbus.Boolean),
+ ('DeviceMountPaths', dbus.String),
+ ('DevicePresentationHide', dbus.Boolean),
+ ('DeviceSize', dbus.Int64),
+ ('DriveIsRotational', dbus.Boolean),
+ ('DriveModel', dbus.String),
+ ('IdLabel', dbus.String),
+ ('NativePath', dbus.String),
+ )
+
+ for (prop_name, prop_value_type) in disk_properties:
+ # Check if all disk properties are set.
+ if prop_name not in disk:
+ raise error.TestFail("disk.%s not found" % prop_name)
+
+ # Check if each disk property has the right data type.
+ prop_value = disk[prop_name]
+ if not isinstance(prop_value, prop_value_type):
+ raise error.TestFail(
+ "disk.%s is %s, but %s expected"
+ % (prop_name, type(prop_value), prop_value_type))
+
+ # Check if DeviceFile has a proper value.
+ if not disk['DeviceFile']:
+ raise error.TestFail(
+ "disk.DeviceFile should not be empty")
+
+ # Check if the values of DeviceIsMounted and DeviceMountPaths
+ # are consistent.
+ if disk['DeviceIsMounted']:
+ if not disk['DeviceMountPaths']:
+ raise error.TestFail(
+ "disk.DeviceMountPaths should not be empty "
+ "if disk.DeviceIsMounted is true")
+ else:
+ if disk['DeviceMountPaths']:
+ raise error.TestFail(
+ "disk.DeviceMountPaths should be empty "
+ "if disk.DeviceIsMounted is false")
+
def run_once(self):
# TODO(rtc): Excercise the whole API.
bus = dbus.SystemBus()
proxy = bus.get_object('org.chromium.CrosDisks',
'/org/chromium/CrosDisks')
cros_disks = dbus.Interface(proxy, 'org.chromium.CrosDisks')
+
+ # Check if CrosDisks server is alive.
rtc 2011/04/18 20:29:13 Can you pull these checks into different methods?
is_alive = cros_disks.IsAlive()
if not is_alive:
raise error.TestFail("Unable to talk to the disk daemon")
+
+ # Check if EnumerateDevices method returns a list of devices.
+ devices = cros_disks.EnumerateDevices()
+ for device in devices:
+ if not device or not isinstance(device, dbus.String):
+ raise error.TestFail(
+ "device returned by EnumerateDevices "
+ "should be a non-empty string")
+
+ # Check if GetAll method returns a list of disk properties.
+ disks = cros_disks.GetAll()
+ for disk in disks:
+ self.validate_disk(disk)
+
+ # Check if GetAll and EnumerateDevices return the same number
+ # of entries.
+ if len(disks) != len(devices):
+ raise error.TestFail(
+ "GetAll returns %d entries, "
+ "but EnumerateDevices returns %d entries"
+ % (len(disks), len(devices)))
+
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698