Fix failure in CodeItemOverrun on target

Use unlink rather than exec /bin/rm to delete files.

Bug: b/72979892
Test: m test-art-target-gtest-dexlayout_test64
Change-Id: I91aa87fcf9a4fd91a26c1bb524ce2e8567ddf4c7
diff --git a/dexlayout/dexlayout_test.cc b/dexlayout/dexlayout_test.cc
index db35a03..bebdc20 100644
--- a/dexlayout/dexlayout_test.cc
+++ b/dexlayout/dexlayout_test.cc
@@ -310,12 +310,10 @@
       if (!::art::Exec(diff_exec_argv, error_msg)) {
         return false;
       }
-      std::vector<std::string> rm_zip_exec_argv = { "/bin/rm", tmp_dir + "classes.dex" };
-      if (!::art::Exec(rm_zip_exec_argv, error_msg)) {
+      if (!UnlinkFile(tmp_dir + "classes.dex")) {
         return false;
       }
-      std::vector<std::string> rm_out_exec_argv = { "/bin/rm", tmp_dir + dex_file_name };
-      if (!::art::Exec(rm_out_exec_argv, error_msg)) {
+      if (!UnlinkFile(tmp_dir + dex_file_name)) {
         return false;
       }
     }
@@ -432,10 +430,7 @@
     }
 
     // -v makes sure that the layout did not corrupt the dex file.
-
-    std::vector<std::string> rm_exec_argv =
-        { "/bin/rm", dex_file, profile_file, output_dex };
-    if (!::art::Exec(rm_exec_argv, error_msg)) {
+    if (!UnlinkFile(dex_file) || !UnlinkFile(profile_file) || !UnlinkFile(output_dex)) {
       return false;
     }
     return true;
@@ -496,10 +491,11 @@
       diff_result = false;
     }
 
-    std::vector<std::string> rm_exec_argv =
-        { "/bin/rm", dex_file, profile_file, output_dex, second_output_dex };
-    if (!::art::Exec(rm_exec_argv, error_msg)) {
-      return false;
+    std::vector<std::string> test_files = { dex_file, profile_file, output_dex, second_output_dex };
+    for (auto test_file : test_files) {
+      if (!UnlinkFile(test_file)) {
+        return false;
+      }
     }
 
     return diff_result;
@@ -528,9 +524,11 @@
       return false;
     }
 
-    std::vector<std::string> rm_exec_argv = { "/bin/rm", input_dex, output_dex };
-    if (!::art::Exec(rm_exec_argv, error_msg)) {
-      return false;
+    std::vector<std::string> dex_files = { input_dex, output_dex };
+    for (auto dex_file : dex_files) {
+      if (!UnlinkFile(dex_file)) {
+        return false;
+      }
     }
     return true;
   }
@@ -573,6 +571,10 @@
 
     return ::art::Exec(argv, error_msg);
   }
+
+  bool UnlinkFile(const std::string& file_path) {
+    return unix_file::FdFile(file_path, 0, false).Unlink();
+  }
 };
 
 
@@ -764,11 +766,7 @@
                             /*dex_filename*/ nullptr,
                             &profile_file,
                             dexlayout_args));
-
-  std::string output_dex = temp_dex.GetFilename() + ".new";
-  std::vector<std::string> rm_exec_argv =
-      { "/bin/rm", output_dex };
-  ASSERT_TRUE(::art::Exec(rm_exec_argv, &error_msg));
+  ASSERT_TRUE(UnlinkFile(temp_dex.GetFilename() + ".new"));
 }
 
 // Test that link data is written out (or at least the header is updated).
@@ -806,11 +804,7 @@
                             /*dex_filename*/ nullptr,
                             &profile_file,
                             dexlayout_args));
-
-  std::string output_dex = temp_dex.GetFilename() + ".new";
-  std::vector<std::string> rm_exec_argv =
-      { "/bin/rm", output_dex };
-  ASSERT_TRUE(::art::Exec(rm_exec_argv, &error_msg));
+  ASSERT_TRUE(UnlinkFile(temp_dex.GetFilename() + ".new"));
 }
 
 TEST_F(DexLayoutTest, ClassFilter) {