tools/pci: Replace memcpy on pci write with aligned copy

memcpy() does unaligned access. Using it for device memory causes
exception (SIGBUS).
Replace the memcpy in PciAccessBridge::write with aligned copy.

Signed-off-by: Vivekanand Veeracholan <vveerach@google.com>
Change-Id: I8e573715dc8971be547d882ce3cb6de31b2620e4
diff --git a/tools/test/tools_helper_unittest.cpp b/tools/test/tools_helper_unittest.cpp
index 1c5b30d..9aac01a 100644
--- a/tools/test/tools_helper_unittest.cpp
+++ b/tools/test/tools_helper_unittest.cpp
@@ -12,14 +12,14 @@
 using ::testing::Return;
 using ::testing::TypedEq;
 
-class UpdaterTest : public ::testing::Test
+class HelperTest : public ::testing::Test
 {
   protected:
     ipmiblob::BlobInterfaceMock blobMock;
     std::uint16_t session = 0xbeef;
 };
 
-TEST_F(UpdaterTest, PollStatusReturnsAfterSuccess)
+TEST_F(HelperTest, PollStatusReturnsAfterSuccess)
 {
     ipmiblob::StatResponse verificationResponse = {};
     /* the other details of the response are ignored, and should be. */
@@ -32,7 +32,7 @@
     EXPECT_TRUE(pollStatus(session, &blobMock));
 }
 
-TEST_F(UpdaterTest, PollStatusReturnsAfterFailure)
+TEST_F(HelperTest, PollStatusReturnsAfterFailure)
 {
     ipmiblob::StatResponse verificationResponse = {};
     /* the other details of the response are ignored, and should be. */
@@ -45,4 +45,24 @@
     EXPECT_FALSE(pollStatus(session, &blobMock));
 }
 
+TEST_F(HelperTest, MemcpyAlignedOneByte)
+{
+    const char source = 'a';
+    char destination;
+
+    EXPECT_EQ(&destination,
+              memcpyAligned(&destination, &source, sizeof(source)));
+    EXPECT_EQ(destination, source);
+}
+
+TEST_F(HelperTest, MemcpyAlignedMultiByte)
+{
+    const char source[14] = "abcdefghijklm";
+    char destination[14] = "xxxxxxxxxxxxx";
+
+    EXPECT_EQ(&destination,
+              memcpyAligned(&destination, &source, sizeof(source)));
+    EXPECT_EQ(0, memcmp(&destination, &source, sizeof(source)));
+}
+
 } // namespace host_tool