Refactor compiler tests around CompilerDriver.

Introduce CommonCompilerDriverTest and inherit that in tests
that need to use CompilerDriver. This is in preparation for
moving the CompilerDriver to dex2oat/.

Test: m test-art-host-gtest
Change-Id: I46cf0bc1df4327569eef5526eeab0781473173a1
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 1c9830b..3be5627 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -643,55 +643,6 @@
                        quick_fn);
 }
 
-// Compile a single Method. (For testing only.)
-void CompilerDriver::CompileOne(Thread* self,
-                                jobject class_loader,
-                                const DexFile& dex_file,
-                                uint16_t class_def_idx,
-                                uint32_t method_idx,
-                                uint32_t access_flags,
-                                InvokeType invoke_type,
-                                const dex::CodeItem* code_item,
-                                Handle<mirror::DexCache> dex_cache,
-                                Handle<mirror::ClassLoader> h_class_loader) {
-  // Can we run DEX-to-DEX compiler on this class ?
-  optimizer::DexToDexCompiler::CompilationLevel dex_to_dex_compilation_level =
-      GetDexToDexCompilationLevel(self,
-                                  *this,
-                                  class_loader,
-                                  dex_file,
-                                  dex_file.GetClassDef(class_def_idx));
-
-  CompileMethodQuick(self,
-                     this,
-                     code_item,
-                     access_flags,
-                     invoke_type,
-                     class_def_idx,
-                     method_idx,
-                     h_class_loader,
-                     dex_file,
-                     dex_to_dex_compilation_level,
-                     dex_cache);
-
-  const size_t num_methods = dex_to_dex_compiler_.NumCodeItemsToQuicken(self);
-  if (num_methods != 0) {
-    DCHECK_EQ(num_methods, 1u);
-    CompileMethodDex2Dex(self,
-                         this,
-                         code_item,
-                         access_flags,
-                         invoke_type,
-                         class_def_idx,
-                         method_idx,
-                         h_class_loader,
-                         dex_file,
-                         dex_to_dex_compilation_level,
-                         dex_cache);
-    dex_to_dex_compiler_.ClearState();
-  }
-}
-
 void CompilerDriver::Resolve(jobject class_loader,
                              const std::vector<const DexFile*>& dex_files,
                              TimingLogger* timings) {
@@ -903,7 +854,7 @@
     // Avoid adding the dex files in the case where we aren't going to add compiled methods.
     // This reduces RAM usage for this case.
     for (const DexFile* dex_file : dex_files) {
-      // Can be already inserted if the caller is CompileOne. This happens for gtests.
+      // Can be already inserted. This happens for gtests.
       if (!compiled_methods_.HaveDexFile(dex_file)) {
         compiled_methods_.AddDexFile(dex_file);
       }
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 199835c..85f0e17 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -121,19 +121,6 @@
                   TimingLogger* timings)
       REQUIRES(!Locks::mutator_lock_);
 
-  // Compile a single Method. (For testing only.)
-  void CompileOne(Thread* self,
-                  jobject class_loader,
-                  const DexFile& dex_file,
-                  uint16_t class_def_idx,
-                  uint32_t method_idx,
-                  uint32_t access_flags,
-                  InvokeType invoke_type,
-                  const dex::CodeItem* code_item,
-                  Handle<mirror::DexCache> dex_cache,
-                  Handle<mirror::ClassLoader> h_class_loader)
-      REQUIRES(!Locks::mutator_lock_);
-
   const CompilerOptions& GetCompilerOptions() const {
     return *compiler_options_;
   }
@@ -360,7 +347,7 @@
   // Compiler for dex to dex (quickening).
   optimizer::DexToDexCompiler dex_to_dex_compiler_;
 
-  friend class CommonCompilerTest;
+  friend class CommonCompilerDriverTest;
   friend class CompileClassVisitor;
   friend class DexToDexDecompilerTest;
   friend class InitializeClassVisitor;
diff --git a/compiler/driver/compiler_driver_test.cc b/compiler/driver/compiler_driver_test.cc
index e73d072..dd2b3ab 100644
--- a/compiler/driver/compiler_driver_test.cc
+++ b/compiler/driver/compiler_driver_test.cc
@@ -24,7 +24,7 @@
 #include "art_method-inl.h"
 #include "base/casts.h"
 #include "class_linker-inl.h"
-#include "common_compiler_test.h"
+#include "common_compiler_driver_test.h"
 #include "compiler_callbacks.h"
 #include "dex/dex_file.h"
 #include "dex/dex_file_types.h"
@@ -40,7 +40,7 @@
 
 namespace art {
 
-class CompilerDriverTest : public CommonCompilerTest {
+class CompilerDriverTest : public CommonCompilerDriverTest {
  protected:
   void CompileAllAndMakeExecutable(jobject class_loader) REQUIRES(!Locks::mutator_lock_) {
     TimingLogger timings("CompilerDriverTest::CompileAllAndMakeExecutable", false, false);
@@ -77,6 +77,20 @@
     }
   }
 
+  void MakeExecutable(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) {
+    CHECK(method != nullptr);
+
+    const CompiledMethod* compiled_method = nullptr;
+    if (!method->IsAbstract()) {
+      mirror::DexCache* dex_cache = method->GetDeclaringClass()->GetDexCache();
+      const DexFile& dex_file = *dex_cache->GetDexFile();
+      compiled_method =
+          compiler_driver_->GetCompiledMethod(MethodReference(&dex_file,
+                                                              method->GetDexMethodIndex()));
+    }
+    CommonCompilerTest::MakeExecutable(method, compiled_method);
+  }
+
   void MakeDexFileExecutable(jobject class_loader, const DexFile& dex_file) {
     ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
     for (size_t i = 0; i < dex_file.NumClassDefs(); i++) {
diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h
index 25d7b36..5908b87 100644
--- a/compiler/driver/compiler_options.h
+++ b/compiler/driver/compiler_options.h
@@ -463,6 +463,7 @@
 
   friend class Dex2Oat;
   friend class DexToDexDecompilerTest;
+  friend class CommonCompilerDriverTest;
   friend class CommonCompilerTest;
   friend class jit::JitCompiler;
   friend class verifier::VerifierDepsTest;