tests: Pick up testdata with LOCAL_TEST_DATA.

Also push the testdata in AndroidTest.xml for `atest`.

LOCAL_TEST_DATA was added in commit [1], which ships testdata next to
native tests.

With this CL,
 1) manually sync-ing via `adb sync` and running tests with `adb shell`
    keep working.
 2) both of 32- and 64-bit recovery_{unit,component}_test now work in
    APCT continuous tests. Note that 64-bit tests were failing
    previously in APCT, due to missing testdata.
 3) `atest recovery_unit_test` works, as the testdata gets pushed to
    /data/local/tmp.

[1] commit d07ba4e2a625a8f000d042c1953adb612bccbbe2 in
https://android-review.googlesource.com/c/platform/build/+/312567.

Bug: 77320514
Test: Build recovery_{unit,component,manual}_test. Setup the test via
      `adb sync data`. Run both of 32- and 64-bit versions on device.
Test: Build and run recovery_host_test on host, for both of 32- and
      64-bit versions.
Test: `atest recovery_component_test`
Change-Id: Ie54037726043a3a659a80030b83db1f8c1de318d
This commit is contained in:
Tao Bao 2018-03-30 20:43:45 -07:00
parent d408a865af
commit 9d91e89831
4 changed files with 25 additions and 62 deletions

View file

@ -45,6 +45,8 @@ LOCAL_SRC_FILES := \
LOCAL_C_INCLUDES := bootable/recovery LOCAL_C_INCLUDES := bootable/recovery
LOCAL_SHARED_LIBRARIES := liblog LOCAL_SHARED_LIBRARIES := liblog
LOCAL_TEST_DATA := \
$(call find-test-data-in-subdirs, $(LOCAL_PATH), "*", testdata)
include $(BUILD_NATIVE_TEST) include $(BUILD_NATIVE_TEST)
# Manual tests # Manual tests
@ -61,25 +63,8 @@ LOCAL_SHARED_LIBRARIES := \
liblog \ liblog \
libpng libpng
resource_files := $(call find-files-in-subdirs, bootable/recovery, \ LOCAL_TEST_DATA := \
"*_text.png", \ $(call find-test-data-in-subdirs, bootable/recovery, "*_text.png", res-*)
res-mdpi/images \
res-hdpi/images \
res-xhdpi/images \
res-xxhdpi/images \
res-xxxhdpi/images \
)
# The resource image files that will go to $OUT/data/nativetest/recovery.
testimage_out_path := $(TARGET_OUT_DATA)/nativetest/recovery
GEN := $(addprefix $(testimage_out_path)/, $(resource_files))
$(GEN): PRIVATE_PATH := $(LOCAL_PATH)
$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@
$(GEN): $(testimage_out_path)/% : bootable/recovery/%
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
include $(BUILD_NATIVE_TEST) include $(BUILD_NATIVE_TEST)
# Component tests # Component tests
@ -171,29 +156,8 @@ LOCAL_STATIC_LIBRARIES := \
libBionicGtestMain \ libBionicGtestMain \
$(tune2fs_static_libraries) $(tune2fs_static_libraries)
testdata_files := $(call find-subdir-files, testdata/*) LOCAL_TEST_DATA := \
$(call find-test-data-in-subdirs, $(LOCAL_PATH), "*", testdata)
# 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 $< $@
$(GEN): $(testdata_out_path)/% : $(LOCAL_PATH)/%
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
# 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)
LOCAL_PICKUP_FILES := $(testdata_continuous_zip_prefix)
include $(BUILD_NATIVE_TEST) include $(BUILD_NATIVE_TEST)
# Host tests # Host tests
@ -222,4 +186,6 @@ LOCAL_STATIC_LIBRARIES := \
libBionicGtestMain libBionicGtestMain
LOCAL_SHARED_LIBRARIES := \ LOCAL_SHARED_LIBRARIES := \
liblog liblog
LOCAL_TEST_DATA := \
$(call find-test-data-in-subdirs, $(LOCAL_PATH), "*", testdata)
include $(BUILD_HOST_NATIVE_TEST) include $(BUILD_HOST_NATIVE_TEST)

View file

@ -16,16 +16,18 @@
<configuration description="Config for recovery_component_test and recovery_unit_test"> <configuration description="Config for recovery_component_test and recovery_unit_test">
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"> <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
<option name="cleanup" value="true" /> <option name="cleanup" value="true" />
<option name="push" value="recovery_component_test->/data/local/tmp/recovery_component_test" /> <option name="push" value="recovery_component_test->/data/local/tmp/recovery_component_test/recovery_component_test" />
<option name="push" value="recovery_unit_test->/data/local/tmp/recovery_unit_test" /> <option name="push" value="testdata->/data/local/tmp/recovery_component_test/testdata" />
<option name="push" value="recovery_unit_test->/data/local/tmp/recovery_unit_test/recovery_unit_test" />
<option name="push" value="testdata->/data/local/tmp/recovery_unit_test/testdata" />
</target_preparer> </target_preparer>
<option name="test-suite-tag" value="apct" /> <option name="test-suite-tag" value="apct" />
<test class="com.android.tradefed.testtype.GTest" > <test class="com.android.tradefed.testtype.GTest" >
<option name="native-test-device-path" value="/data/local/tmp" /> <option name="native-test-device-path" value="/data/local/tmp/recovery_component_test" />
<option name="module-name" value="recovery_component_test" /> <option name="module-name" value="recovery_component_test" />
</test> </test>
<test class="com.android.tradefed.testtype.GTest" > <test class="com.android.tradefed.testtype.GTest" >
<option name="native-test-device-path" value="/data/local/tmp" /> <option name="native-test-device-path" value="/data/local/tmp/recovery_unit_test" />
<option name="module-name" value="recovery_unit_test" /> <option name="module-name" value="recovery_unit_test" />
</test> </test>
</configuration> </configuration>

View file

@ -17,10 +17,10 @@
#ifndef _OTA_TEST_CONSTANTS_H #ifndef _OTA_TEST_CONSTANTS_H
#define _OTA_TEST_CONSTANTS_H #define _OTA_TEST_CONSTANTS_H
#include <stdlib.h>
#include <string> #include <string>
#include <android-base/file.h>
// Zip entries in ziptest_valid.zip. // Zip entries in ziptest_valid.zip.
static const std::string kATxtContents("abcdefghabcdefgh\n"); static const std::string kATxtContents("abcdefghabcdefgh\n");
static const std::string kBTxtContents("abcdefgh\n"); static const std::string kBTxtContents("abcdefgh\n");
@ -32,14 +32,9 @@ static const std::string kATxtSha1Sum("32c96a03dc8cd20097940f351bca6261ee5a1643"
// echo -n -e "abcdefgh\n" | sha1sum // echo -n -e "abcdefgh\n" | sha1sum
static const std::string kBTxtSha1Sum("e414af7161c9554089f4106d6f1797ef14a73666"); static const std::string kBTxtSha1Sum("e414af7161c9554089f4106d6f1797ef14a73666");
static std::string from_testdata_base(const std::string& fname) { [[maybe_unused]] static std::string from_testdata_base(const std::string& fname) {
#ifdef __ANDROID__ static std::string exec_dir = android::base::GetExecutableDirectory();
static std::string data_root = getenv("ANDROID_DATA"); return exec_dir + "/testdata/" + fname;
#else
static std::string data_root = std::string(getenv("ANDROID_PRODUCT_OUT")) + "/data";
#endif
return data_root + "/nativetest/recovery/testdata/" + fname;
} }
#endif // _OTA_TEST_CONSTANTS_H #endif // _OTA_TEST_CONSTANTS_H

View file

@ -34,7 +34,6 @@
static const std::string myFilename = "/data/misc/recovery/inject.txt"; static const std::string myFilename = "/data/misc/recovery/inject.txt";
static const std::string myContent = "Hello World\nWelcome to my recovery\n"; static const std::string myContent = "Hello World\nWelcome to my recovery\n";
static const std::string kLocale = "zu"; static const std::string kLocale = "zu";
static const std::string kResourceTestDir = "/data/nativetest/recovery/";
// Failure is expected on systems that do not deliver either the // Failure is expected on systems that do not deliver either the
// recovery-persist or recovery-refresh executables. Tests also require // recovery-persist or recovery-refresh executables. Tests also require
@ -108,19 +107,20 @@ static int png_filter(const dirent* de) {
return 1; return 1;
} }
// Find out all png files to test under /data/nativetest/recovery/. // Find out all the PNG files to test, which stay under the same dir with the executable.
static std::vector<std::string> add_files() { static std::vector<std::string> add_files() {
std::string exec_dir = android::base::GetExecutableDirectory();
std::vector<std::string> files; std::vector<std::string> files;
for (const std::string& str : image_dir) { for (const std::string& image : image_dir) {
std::string dir_path = kResourceTestDir + str; std::string dir_path = exec_dir + "/" + image;
dirent** namelist; dirent** namelist;
int n = scandir(dir_path.c_str(), &namelist, png_filter, alphasort); int n = scandir(dir_path.c_str(), &namelist, png_filter, alphasort);
if (n == -1) { if (n == -1) {
printf("Failed to scan dir %s: %s\n", kResourceTestDir.c_str(), strerror(errno)); printf("Failed to scan dir %s: %s\n", exec_dir.c_str(), strerror(errno));
return files; return files;
} }
if (n == 0) { if (n == 0) {
printf("No file is added for test in %s\n", kResourceTestDir.c_str()); printf("No file is added for test in %s\n", exec_dir.c_str());
} }
while (n--) { while (n--) {