Build unittests in Brillo.

Many unittests do not pass for simple reasons that will be addressed
later. This CL includes all the changes to make the unittests build.
In particular, the generated DBus mocks, required to build several
unittests are now included here.

The dbus-constants.h files were moved to the system_api repo, so they
can be removed from here.

The unittest build is only enabled for Brillo targets, since non-Brillo
targets don't even build DBus.

Bug: 26955860
TEST=`mmma` on edison-eng (and aosp_arm-eng).

Change-Id: Ib38241f0a6eb99b1d60d72db6bcfd125d38e3fad
diff --git a/payload_consumer/delta_performer_integration_test.cc b/payload_consumer/delta_performer_integration_test.cc
index 9b7854b..f0aea95 100644
--- a/payload_consumer/delta_performer_integration_test.cc
+++ b/payload_consumer/delta_performer_integration_test.cc
@@ -58,7 +58,7 @@
 extern const char* kUnittestPrivateKey2Path;
 extern const char* kUnittestPublicKey2Path;
 
-static const int kDefaultKernelSize = 4096;  // Something small for a test
+static const uint32_t kDefaultKernelSize = 4096;  // Something small for a test
 static const uint8_t kNewData[] = {'T', 'h', 'i', 's', ' ', 'i', 's', ' ',
                                    'n', 'e', 'w', ' ', 'd', 'a', 't', 'a', '.'};
 
@@ -124,7 +124,7 @@
 
 static void CompareFilesByBlock(const string& a_file, const string& b_file,
                                 size_t image_size) {
-  EXPECT_EQ(0, image_size % kBlockSize);
+  EXPECT_EQ(0U, image_size % kBlockSize);
 
   brillo::Blob a_data, b_data;
   EXPECT_TRUE(utils::ReadFile(a_file, &a_data)) << "file failed: " << a_file;
@@ -133,7 +133,7 @@
   EXPECT_GE(a_data.size(), image_size);
   EXPECT_GE(b_data.size(), image_size);
   for (size_t i = 0; i < image_size; i += kBlockSize) {
-    EXPECT_EQ(0, i % kBlockSize);
+    EXPECT_EQ(0U, i % kBlockSize);
     brillo::Blob a_sub(&a_data[i], &a_data[i + kBlockSize]);
     brillo::Blob b_sub(&b_data[i], &b_data[i + kBlockSize]);
     EXPECT_TRUE(a_sub == b_sub) << "Block " << (i/kBlockSize) << " differs";
@@ -350,7 +350,7 @@
                                  hardtocompress.size()));
 
     brillo::Blob zeros(16 * 1024, 0);
-    EXPECT_EQ(zeros.size(),
+    EXPECT_EQ(static_cast<int>(zeros.size()),
               base::WriteFile(base::FilePath(base::StringPrintf(
                                   "%s/move-to-sparse", a_mnt.c_str())),
                               reinterpret_cast<const char*>(zeros.data()),
@@ -416,7 +416,7 @@
                         16 * 1024));
 
     brillo::Blob zeros(16 * 1024, 0);
-    EXPECT_EQ(zeros.size(),
+    EXPECT_EQ(static_cast<int>(zeros.size()),
               base::WriteFile(base::FilePath(base::StringPrintf(
                                   "%s/move-from-sparse", b_mnt.c_str())),
                               reinterpret_cast<const char*>(zeros.data()),
@@ -614,7 +614,7 @@
       else
         EXPECT_EQ(1, sigs_message.signatures_size());
       const Signatures_Signature& signature = sigs_message.signatures(0);
-      EXPECT_EQ(1, signature.version());
+      EXPECT_EQ(1U, signature.version());
 
       uint64_t expected_sig_data_length = 0;
       vector<string> key_paths{kUnittestPrivateKeyPath};
@@ -880,7 +880,7 @@
                          updated_kernel_partition.begin()));
 
   const auto& partitions = state->install_plan.partitions;
-  EXPECT_EQ(2, partitions.size());
+  EXPECT_EQ(2U, partitions.size());
   EXPECT_EQ(kLegacyPartitionNameRoot, partitions[0].name);
   EXPECT_EQ(kLegacyPartitionNameKernel, partitions[1].name);
 
diff --git a/payload_consumer/delta_performer_unittest.cc b/payload_consumer/delta_performer_unittest.cc
index dabe138..98a378b 100644
--- a/payload_consumer/delta_performer_unittest.cc
+++ b/payload_consumer/delta_performer_unittest.cc
@@ -16,6 +16,7 @@
 
 #include "update_engine/payload_consumer/delta_performer.h"
 
+#include <endian.h>
 #include <inttypes.h>
 
 #include <string>
@@ -649,7 +650,7 @@
   EXPECT_EQ(kBrilloMajorPayloadVersion, performer_.GetMajorVersion());
   uint64_t manifest_offset;
   EXPECT_TRUE(performer_.GetManifestOffset(&manifest_offset));
-  EXPECT_EQ(24, manifest_offset);  // 4 + 8 + 8 + 4
+  EXPECT_EQ(24U, manifest_offset);  // 4 + 8 + 8 + 4
   EXPECT_EQ(manifest_offset + manifest_size, performer_.GetMetadataSize());
   EXPECT_EQ(metadata_signature_size, performer_.metadata_signature_size_);
 }
diff --git a/payload_consumer/download_action_unittest.cc b/payload_consumer/download_action_unittest.cc
index 979776f..51d3c3a 100644
--- a/payload_consumer/download_action_unittest.cc
+++ b/payload_consumer/download_action_unittest.cc
@@ -532,8 +532,10 @@
   // Check the p2p file and its content matches what was sent.
   string file_id = download_action_->p2p_file_id();
   EXPECT_NE("", file_id);
-  EXPECT_EQ(data_.length(), p2p_manager_->FileGetSize(file_id));
-  EXPECT_EQ(data_.length(), p2p_manager_->FileGetExpectedSize(file_id));
+  EXPECT_EQ(static_cast<int>(data_.length()),
+            p2p_manager_->FileGetSize(file_id));
+  EXPECT_EQ(static_cast<int>(data_.length()),
+            p2p_manager_->FileGetExpectedSize(file_id));
   string p2p_file_contents;
   EXPECT_TRUE(ReadFileToString(p2p_manager_->FileGetPath(file_id),
                                &p2p_file_contents));
@@ -580,8 +582,10 @@
   // DownloadAction should convey the same file_id and the file should
   // have the expected size.
   EXPECT_EQ(download_action_->p2p_file_id(), file_id);
-  EXPECT_EQ(p2p_manager_->FileGetSize(file_id), data_.length());
-  EXPECT_EQ(p2p_manager_->FileGetExpectedSize(file_id), data_.length());
+  EXPECT_EQ(static_cast<ssize_t>(data_.length()),
+            p2p_manager_->FileGetSize(file_id));
+  EXPECT_EQ(static_cast<ssize_t>(data_.length()),
+            p2p_manager_->FileGetExpectedSize(file_id));
   string p2p_file_contents;
   // Check that the first 1000 bytes wasn't touched and that we
   // appended the remaining as appropriate.
@@ -611,14 +615,14 @@
                       1000), 1000);
 
   // Check that the file is there.
-  EXPECT_EQ(p2p_manager_->FileGetSize(file_id), 1000);
-  EXPECT_EQ(p2p_manager_->CountSharedFiles(), 1);
+  EXPECT_EQ(1000, p2p_manager_->FileGetSize(file_id));
+  EXPECT_EQ(1, p2p_manager_->CountSharedFiles());
 
   StartDownload(false);  // use_p2p_to_share
 
   // DownloadAction should have deleted the p2p file. Check that it's gone.
-  EXPECT_EQ(p2p_manager_->FileGetSize(file_id), -1);
-  EXPECT_EQ(p2p_manager_->CountSharedFiles(), 0);
+  EXPECT_EQ(-1, p2p_manager_->FileGetSize(file_id));
+  EXPECT_EQ(0, p2p_manager_->CountSharedFiles());
 }
 
 }  // namespace chromeos_update_engine
diff --git a/payload_consumer/filesystem_verifier_action_unittest.cc b/payload_consumer/filesystem_verifier_action_unittest.cc
index 10daaa8..cdf7fc0 100644
--- a/payload_consumer/filesystem_verifier_action_unittest.cc
+++ b/payload_consumer/filesystem_verifier_action_unittest.cc
@@ -120,7 +120,7 @@
 // failures and whether or not they are due to the test setup or an inherent
 // issue with the chroot environment, library versions we use, etc.
 TEST_F(FilesystemVerifierActionTest, DISABLED_RunAsRootSimpleTest) {
-  ASSERT_EQ(0, getuid());
+  ASSERT_EQ(0U, getuid());
   bool test = DoTest(false, false, VerifierMode::kComputeSourceHash);
   EXPECT_TRUE(test);
   if (!test)
@@ -309,18 +309,18 @@
 }
 
 TEST_F(FilesystemVerifierActionTest, RunAsRootVerifyHashTest) {
-  ASSERT_EQ(0, getuid());
+  ASSERT_EQ(0U, getuid());
   EXPECT_TRUE(DoTest(false, false, VerifierMode::kVerifyTargetHash));
   EXPECT_TRUE(DoTest(false, false, VerifierMode::kComputeSourceHash));
 }
 
 TEST_F(FilesystemVerifierActionTest, RunAsRootVerifyHashFailTest) {
-  ASSERT_EQ(0, getuid());
+  ASSERT_EQ(0U, getuid());
   EXPECT_TRUE(DoTest(false, true, VerifierMode::kVerifyTargetHash));
 }
 
 TEST_F(FilesystemVerifierActionTest, RunAsRootTerminateEarlyTest) {
-  ASSERT_EQ(0, getuid());
+  ASSERT_EQ(0U, getuid());
   EXPECT_TRUE(DoTest(true, false, VerifierMode::kVerifyTargetHash));
   // TerminateEarlyTest may leak some null callbacks from the Stream class.
   while (loop_.RunOnce(false)) {}
@@ -366,13 +366,13 @@
   loop_.Run();
   install_plan = collector_action.object();
 
-  ASSERT_EQ(2, install_plan.partitions.size());
+  ASSERT_EQ(2U, install_plan.partitions.size());
   // When computing the size of the rootfs on legacy delta updates we use the
   // size of the filesystem, but when updating the kernel we use the whole
   // partition.
-  EXPECT_EQ(10 * 1024 * 1024, install_plan.partitions[0].source_size);
+  EXPECT_EQ(10U << 20, install_plan.partitions[0].source_size);
   EXPECT_EQ(kLegacyPartitionNameRoot, install_plan.partitions[0].name);
-  EXPECT_EQ(20 * 1024 * 1024, install_plan.partitions[1].source_size);
+  EXPECT_EQ(20U << 20, install_plan.partitions[1].source_size);
   EXPECT_EQ(kLegacyPartitionNameKernel, install_plan.partitions[1].name);
 }
 
diff --git a/payload_consumer/postinstall_runner_action_unittest.cc b/payload_consumer/postinstall_runner_action_unittest.cc
index beed4f1..c4c68b1 100644
--- a/payload_consumer/postinstall_runner_action_unittest.cc
+++ b/payload_consumer/postinstall_runner_action_unittest.cc
@@ -121,8 +121,8 @@
     bool do_losetup,
     int err_code,
     bool powerwash_required) {
-  ASSERT_EQ(0, getuid()) << "Run me as root. Ideally don't run other tests "
-                         << "as root, tho.";
+  ASSERT_EQ(0U, getuid()) << "Run me as root. Ideally don't run other tests "
+                          << "as root, tho.";
   // True if the post-install action is expected to succeed.
   bool should_succeed = do_losetup && !err_code;
 
@@ -251,7 +251,7 @@
 
 // Death tests don't seem to be working on Hardy
 TEST_F(PostinstallRunnerActionTest, DISABLED_RunAsRootDeathTest) {
-  ASSERT_EQ(0, getuid());
+  ASSERT_EQ(0U, getuid());
   PostinstallRunnerAction runner_action(&fake_boot_control_);
   ASSERT_DEATH({ runner_action.TerminateProcessing(); },
                "postinstall_runner_action.h:.*] Check failed");