tests: Set up testdata path for continuous native tests.

continuous_native_tests expects the testdata under DATA/ in
continuous_native_tests.zip. This CL packs a copy of the testdata into
continuous_native_tests.zip as DATA/nativetest/recovery/testdata (via
LOCAL_PICKUP_FILES).

This CL also removes the extra copy for nativetest64. Testdata will
always stay at /data/nativetest/recovery/testdata, even for 64-bit
version. Otherwise we will unnecessarily get four copies (two for data/
and another two for DATA/).

Bug: 32123241
Test: mmma bootable/recovery && adb sync data. On bullhead,
    /data/nativetest/recovery_component_test/recovery_component_test works;
    /data/nativetest64/recovery_component_test/recovery_component_test works.
Test: m continuous_native_test; DATA/nativetest/recovery/testdata exists.

Change-Id: Ifefa0309de7af23c77654e8e450848ca2da218c2
diff --git a/tests/Android.mk b/tests/Android.mk
index 461d6ef..8f19992 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -87,7 +87,8 @@
 
 testdata_files := $(call find-subdir-files, testdata/*)
 
-testdata_out_path := $(TARGET_OUT_DATA_NATIVE_TESTS)/recovery
+# The testdata files that will go to $OUT/data/nativetest/recovery.
+testdata_out_path := $(TARGET_OUT_DATA)/nativetest/recovery
 GEN := $(addprefix $(testdata_out_path)/, $(testdata_files))
 $(GEN): PRIVATE_PATH := $(LOCAL_PATH)
 $(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
@@ -95,14 +96,16 @@
 	$(transform-generated-source)
 LOCAL_GENERATED_SOURCES += $(GEN)
 
-ifdef TARGET_2ND_ARCH
-testdata_out_path_2nd_arch := $($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_DATA_NATIVE_TESTS)/recovery
-GEN_2ND_ARCH := $(addprefix $(testdata_out_path_2nd_arch)/, $(testdata_files))
-$(GEN_2ND_ARCH): PRIVATE_PATH := $(LOCAL_PATH)
-$(GEN_2ND_ARCH): PRIVATE_CUSTOM_TOOL = cp $< $@
-$(GEN_2ND_ARCH): $(testdata_out_path_2nd_arch)/% : $(LOCAL_PATH)/%
+# A copy of the testdata to be packed into continuous_native_tests.zip.
+testdata_continuous_zip_prefix := \
+    $(call intermediates-dir-for,PACKAGING,recovery_component_test)/DATA
+testdata_continuous_zip_path := $(testdata_continuous_zip_prefix)/nativetest/recovery
+GEN := $(addprefix $(testdata_continuous_zip_path)/, $(testdata_files))
+$(GEN): PRIVATE_PATH := $(LOCAL_PATH)
+$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
+$(GEN): $(testdata_continuous_zip_path)/% : $(LOCAL_PATH)/%
 	$(transform-generated-source)
-LOCAL_GENERATED_SOURCES += $(GEN_2ND_ARCH)
-endif # TARGET_2ND_ARCH
+LOCAL_GENERATED_SOURCES += $(GEN)
+LOCAL_PICKUP_FILES := $(testdata_continuous_zip_prefix)
 
 include $(BUILD_NATIVE_TEST)
diff --git a/tests/common/test_constants.h b/tests/common/test_constants.h
index 3490f68..97e74a3 100644
--- a/tests/common/test_constants.h
+++ b/tests/common/test_constants.h
@@ -13,13 +13,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 #ifndef _OTA_TEST_CONSTANTS_H
 #define _OTA_TEST_CONSTANTS_H
 
-#if defined(__LP64__)
-#define NATIVE_TEST_PATH "/nativetest64"
-#else
-#define NATIVE_TEST_PATH "/nativetest"
-#endif
+#include <stdlib.h>
 
-#endif
+static const char* data_root = getenv("ANDROID_DATA");
+
+static std::string from_testdata_base(const std::string& fname) {
+  return std::string(data_root) + "/nativetest/recovery/testdata/" + fname;
+}
+
+#endif  // _OTA_TEST_CONSTANTS_H
diff --git a/tests/component/applypatch_test.cpp b/tests/component/applypatch_test.cpp
index f95ebed..1a0b191 100644
--- a/tests/component/applypatch_test.cpp
+++ b/tests/component/applypatch_test.cpp
@@ -37,9 +37,6 @@
 #include "common/test_constants.h"
 #include "print_sha1.h"
 
-static const std::string DATA_PATH = getenv("ANDROID_DATA");
-static const std::string TESTDATA_PATH = "/recovery/testdata";
-
 static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize = nullptr) {
   ASSERT_NE(nullptr, sha1);
 
@@ -72,10 +69,6 @@
   return c1 == c2;
 }
 
-static std::string from_testdata_base(const std::string& fname) {
-  return DATA_PATH + NATIVE_TEST_PATH + TESTDATA_PATH + "/" + fname;
-}
-
 class ApplyPatchTest : public ::testing::Test {
  public:
   static void SetUpTestCase() {
diff --git a/tests/component/verifier_test.cpp b/tests/component/verifier_test.cpp
index 7f9a714..60a78f5 100644
--- a/tests/component/verifier_test.cpp
+++ b/tests/component/verifier_test.cpp
@@ -37,9 +37,6 @@
 #include "ui.h"
 #include "verifier.h"
 
-static const char* DATA_PATH = getenv("ANDROID_DATA");
-static const char* TESTDATA_PATH = "/recovery/testdata/";
-
 RecoveryUI* ui = NULL;
 
 class MockUI : public RecoveryUI {
@@ -92,17 +89,13 @@
 
     virtual void SetUp() {
         std::vector<std::string> args = GetParam();
-        std::string package =
-            android::base::StringPrintf("%s%s%s%s", DATA_PATH, NATIVE_TEST_PATH,
-                                        TESTDATA_PATH, args[0].c_str());
+        std::string package = from_testdata_base(args[0]);
         if (sysMapFile(package.c_str(), &memmap) != 0) {
             FAIL() << "Failed to mmap " << package << ": " << strerror(errno) << "\n";
         }
 
         for (auto it = ++(args.cbegin()); it != args.cend(); ++it) {
-            std::string public_key_file = android::base::StringPrintf(
-                    "%s%s%stestkey_%s.txt", DATA_PATH, NATIVE_TEST_PATH,
-                    TESTDATA_PATH, it->c_str());
+            std::string public_key_file = from_testdata_base("testkey_" + *it + ".txt");
             ASSERT_TRUE(load_keys(public_key_file.c_str(), certs));
         }
     }