Mock CheckCompilationSpace in unit test.

Before this change, the real check was performed, so the test would fail
if the space is low, making the test flaky. This CL fixes this issue by
replacing the check with a fake one in the test.

Bug: 278120080
Test: atest art_standalone_odrefresh_tests
Change-Id: Ifc875a41c1310527703fa8e4005d41fced2a2575
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index 9d227fe..85766cc 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -55,6 +55,7 @@
 
 #include "android-base/chrono_utils.h"
 #include "android-base/file.h"
+#include "android-base/function_ref.h"
 #include "android-base/logging.h"
 #include "android-base/macros.h"
 #include "android-base/parsebool.h"
@@ -655,15 +656,18 @@
 OnDeviceRefresh::OnDeviceRefresh(const OdrConfig& config)
     : OnDeviceRefresh(config,
                       config.GetArtifactDirectory() + "/" + kCacheInfoFile,
-                      std::make_unique<ExecUtils>()) {}
+                      std::make_unique<ExecUtils>(),
+                      CheckCompilationSpace) {}
 
 OnDeviceRefresh::OnDeviceRefresh(const OdrConfig& config,
                                  const std::string& cache_info_filename,
-                                 std::unique_ptr<ExecUtils> exec_utils)
-    : config_{config},
-      cache_info_filename_{cache_info_filename},
-      start_time_{time(nullptr)},
-      exec_utils_{std::move(exec_utils)} {
+                                 std::unique_ptr<ExecUtils> exec_utils,
+                                 android::base::function_ref<bool()> check_compilation_space)
+    : config_(config),
+      cache_info_filename_(cache_info_filename),
+      start_time_(time(nullptr)),
+      exec_utils_(std::move(exec_utils)),
+      check_compilation_space_(check_compilation_space) {
   // Updatable APEXes should not have DEX files in the DEX2OATBOOTCLASSPATH. At the time of
   // writing i18n is a non-updatable APEX and so does appear in the DEX2OATBOOTCLASSPATH.
   dex2oat_boot_classpath_jars_ = Split(config_.GetDex2oatBootClasspath(), ":");
@@ -1811,7 +1815,7 @@
         CompilationResult::Error(OdrMetrics::Status::kUnknown, "Minimal boot image requested"));
   }
 
-  if (!CheckCompilationSpace()) {
+  if (!check_compilation_space_()) {
     result.Merge(CompilationResult::Error(OdrMetrics::Status::kNoSpace, "Insufficient space"));
   }
 
@@ -1957,7 +1961,7 @@
   CompilationResult result = CompilationResult::Ok();
   std::vector<std::string> classloader_context;
 
-  if (!CheckCompilationSpace()) {
+  if (!check_compilation_space_()) {
     LOG(ERROR) << "Compilation of system_server failed: Insufficient space";
     return CompilationResult::Error(OdrMetrics::Status::kNoSpace, "Insufficient space");
   }
diff --git a/odrefresh/odrefresh.h b/odrefresh/odrefresh.h
index 93812eb..1b296ef 100644
--- a/odrefresh/odrefresh.h
+++ b/odrefresh/odrefresh.h
@@ -26,6 +26,7 @@
 #include <unordered_set>
 #include <vector>
 
+#include "android-base/function_ref.h"
 #include "android-base/result.h"
 #include "base/os.h"
 #include "com_android_apex.h"
@@ -164,7 +165,8 @@
   // Constructor with injections. For testing and internal use only.
   OnDeviceRefresh(const OdrConfig& config,
                   const std::string& cache_info_filename,
-                  std::unique_ptr<ExecUtils> exec_utils);
+                  std::unique_ptr<ExecUtils> exec_utils,
+                  android::base::function_ref<bool()> check_compilation_space);
 
   // Returns the exit code and specifies what should be compiled in `compilation_options`.
   WARN_UNUSED ExitCode
@@ -384,6 +386,8 @@
 
   std::unique_ptr<ExecUtils> exec_utils_;
 
+  android::base::function_ref<bool()> check_compilation_space_;
+
   DISALLOW_COPY_AND_ASSIGN(OnDeviceRefresh);
 };
 
diff --git a/odrefresh/odrefresh_test.cc b/odrefresh/odrefresh_test.cc
index f87fcff..119de6b 100644
--- a/odrefresh/odrefresh_test.cc
+++ b/odrefresh/odrefresh_test.cc
@@ -235,8 +235,10 @@
     mock_exec_utils_ = mock_exec_utils.get();
 
     metrics_ = std::make_unique<OdrMetrics>(dalvik_cache_dir_);
-    odrefresh_ = std::make_unique<OnDeviceRefresh>(
-        config_, dalvik_cache_dir_ + "/cache-info.xml", std::move(mock_exec_utils));
+    odrefresh_ = std::make_unique<OnDeviceRefresh>(config_,
+                                                   dalvik_cache_dir_ + "/cache-info.xml",
+                                                   std::move(mock_exec_utils),
+                                                   /*check_compilation_space=*/[] { return true; });
   }
 
   void TearDown() override {