libmems: Support Device Name in FakeIioDevice::ReadStringAttribute

BUG=b:174544536
TEST=builds

Change-Id: I6838027a5f0b9a2463c9dcdbc8e2eaf80068ef33
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2595758
Reviewed-by: Cheng-Hao Yang <chenghaoyang@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Tested-by: Cheng-Hao Yang <chenghaoyang@chromium.org>
Commit-Queue: Cheng-Hao Yang <chenghaoyang@chromium.org>
GitOrigin-RevId: d2c3c945c50b698fe37c60020c775900e3aaceab
diff --git a/common_types.h b/common_types.h
index 9709335..75560fb 100644
--- a/common_types.h
+++ b/common_types.h
@@ -16,6 +16,10 @@
 constexpr char kIioSysfsTrigger[] = "iio_sysfs_trigger";
 constexpr char kTriggerIdPrefix[] = "trigger";
 
+// The attribute name to get the device name with
+// IioDevice::ReadStringAttribute.
+constexpr char kDeviceName[] = "name";
+
 constexpr char kFrequencyAttr[] = "frequency";
 constexpr char kSamplingFrequencyAttr[] = "sampling_frequency";
 constexpr char kHWFifoTimeoutAttr[] = "buffer/hwfifo_timeout";
diff --git a/test_fakes.cc b/test_fakes.cc
index 5b0438c..95651a6 100644
--- a/test_fakes.cc
+++ b/test_fakes.cc
@@ -95,6 +95,8 @@
 
 base::Optional<std::string> FakeIioDevice::ReadStringAttribute(
     const std::string& name) const {
+  if (name.compare(kDeviceName) == 0)
+    return name_;
   return FakeReadAttributes<>(name, text_attributes_);
 }
 base::Optional<int64_t> FakeIioDevice::ReadNumberAttribute(