Commit 00643e7d by Jamie Madill Committed by Commit Bot

Use Android API to get storage path.

This pipes through to a system call via JNI. This will allow Chromium changes to land that were prevented because ANGLE hard-coded some parts of this path. This in turn will allow us to more easily override these paths for changes needed for Android R support. Bug: chromium:1094062 Change-Id: I20d75b8ee40d418ba5c057f618640ef896248299 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2315483 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com>
parent 85707f7f
...@@ -302,14 +302,6 @@ if (build_angle_perftests) { ...@@ -302,14 +302,6 @@ if (build_angle_perftests) {
testonly = true testonly = true
if (build_angle_trace_perf_tests) { if (build_angle_trace_perf_tests) {
sources = [ "perf_tests/TracePerfTest.cpp" ] sources = [ "perf_tests/TracePerfTest.cpp" ]
if (is_android) {
_trace_data_path = "/sdcard/chromium_tests_root/third_party/angle/src/tests/restricted_traces"
} else {
_trace_data_path = rebase_path("restricted_traces", root_out_dir)
}
defines = [ "ANGLE_TRACE_DATA_DIR=\"${_trace_data_path}\"" ]
deps = [ deps = [
":angle_perftests_shared", ":angle_perftests_shared",
"$angle_root:angle_compression", "$angle_root:angle_compression",
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "platform/PlatformMethods.h" #include "platform/PlatformMethods.h"
#include "tests/test_expectations/GPUTestConfig.h" #include "tests/test_expectations/GPUTestConfig.h"
#include "tests/test_expectations/GPUTestExpectationsParser.h" #include "tests/test_expectations/GPUTestExpectationsParser.h"
#include "util/OSWindow.h"
#include "util/test_utils.h" #include "util/test_utils.h"
namespace angle namespace angle
...@@ -32,6 +33,7 @@ namespace ...@@ -32,6 +33,7 @@ namespace
bool gGlobalError = false; bool gGlobalError = false;
bool gExpectError = false; bool gExpectError = false;
uint32_t gBatchId = 0; uint32_t gBatchId = 0;
bool gVerbose = false;
constexpr char kInfoTag[] = "*RESULT"; constexpr char kInfoTag[] = "*RESULT";
...@@ -54,20 +56,11 @@ std::string DrawElementsToGoogleTestName(const std::string &dEQPName) ...@@ -54,20 +56,11 @@ std::string DrawElementsToGoogleTestName(const std::string &dEQPName)
return gTestName; return gTestName;
} }
const char *gCaseListSearchPaths[] = { // Relative to the ANGLE root folder.
"/../../sdcard/chromium_tests_root/third_party/angle/third_party/VK-GL-CTS/src", constexpr char kCTSRootPath[] = "third_party/VK-GL-CTS/src/";
"/../../third_party/VK-GL-CTS/src", constexpr char kSupportPath[] = "src/tests/deqp_support/";
"/../../third_party/angle/third_party/VK-GL-CTS/src",
};
const char *gTestExpectationsSearchPaths[] = {
"/../../src/tests/deqp_support/",
"/../../third_party/angle/src/tests/deqp_support/",
"/deqp_support/",
"/../../sdcard/chromium_tests_root/third_party/angle/src/tests/deqp_support/",
};
#define OPENGL_CTS_DIR(PATH) "/external/openglcts/data/mustpass/gles/" PATH #define OPENGL_CTS_DIR(PATH) "external/openglcts/data/mustpass/gles/" PATH
const char *gCaseListFiles[] = { const char *gCaseListFiles[] = {
OPENGL_CTS_DIR("aosp_mustpass/master/gles2-master.txt"), OPENGL_CTS_DIR("aosp_mustpass/master/gles2-master.txt"),
...@@ -116,6 +109,7 @@ constexpr char kANGLEEGLString[] = "--use-angle="; ...@@ -116,6 +109,7 @@ constexpr char kANGLEEGLString[] = "--use-angle=";
constexpr char kANGLEPreRotation[] = "--emulated-pre-rotation="; constexpr char kANGLEPreRotation[] = "--emulated-pre-rotation=";
constexpr char kdEQPCaseString[] = "--deqp-case="; constexpr char kdEQPCaseString[] = "--deqp-case=";
constexpr char kBatchIdString[] = "--batch-id="; constexpr char kBatchIdString[] = "--batch-id=";
constexpr char kVerboseString[] = "--verbose";
std::array<char, 500> gCaseStringBuffer; std::array<char, 500> gCaseStringBuffer;
...@@ -182,39 +176,30 @@ void Die() ...@@ -182,39 +176,30 @@ void Die()
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
Optional<std::string> FindFileFromPaths(const char *paths[], Optional<std::string> FindFileFromPath(const char *dirPath, const char *filePath)
size_t numPaths,
const std::string &exeDir,
const std::string &searchFile)
{ {
for (size_t pathIndex = 0; pathIndex < numPaths; ++pathIndex) std::stringstream strstr;
{ strstr << dirPath << filePath;
const char *testPath = paths[pathIndex]; std::string path = strstr.str();
std::stringstream pathStringStream;
pathStringStream << exeDir << testPath << searchFile;
std::string path = pathStringStream.str(); constexpr size_t kMaxFoundPathLen = 1000;
std::ifstream inFile(path.c_str()); char foundPath[kMaxFoundPathLen];
if (!inFile.fail()) if (angle::FindTestDataPath(path.c_str(), foundPath, kMaxFoundPathLen))
{ {
inFile.close(); return std::string(foundPath);
return Optional<std::string>(path);
}
} }
return Optional<std::string>::Invalid(); return Optional<std::string>::Invalid();
} }
Optional<std::string> FindCaseListPath(const std::string &exeDir, size_t testModuleIndex) Optional<std::string> FindCaseListPath(size_t testModuleIndex)
{ {
return FindFileFromPaths(gCaseListSearchPaths, ArraySize(gCaseListSearchPaths), exeDir, return FindFileFromPath(kCTSRootPath, gCaseListFiles[testModuleIndex]);
gCaseListFiles[testModuleIndex]);
} }
Optional<std::string> FindTestExpectationsPath(const std::string &exeDir, size_t testModuleIndex) Optional<std::string> FindTestExpectationsPath(size_t testModuleIndex)
{ {
return FindFileFromPaths(gTestExpectationsSearchPaths, ArraySize(gTestExpectationsSearchPaths), return FindFileFromPath(kSupportPath, gTestExpectationsFiles[testModuleIndex]);
exeDir, gTestExpectationsFiles[testModuleIndex]);
} }
class dEQPCaseList class dEQPCaseList
...@@ -266,16 +251,14 @@ void dEQPCaseList::initialize() ...@@ -266,16 +251,14 @@ void dEQPCaseList::initialize()
mInitialized = true; mInitialized = true;
std::string exeDir = GetExecutableDirectory(); Optional<std::string> caseListPath = FindCaseListPath(mTestModuleIndex);
Optional<std::string> caseListPath = FindCaseListPath(exeDir, mTestModuleIndex);
if (!caseListPath.valid()) if (!caseListPath.valid())
{ {
std::cerr << "Failed to find case list file." << std::endl; std::cerr << "Failed to find case list file." << std::endl;
Die(); Die();
} }
Optional<std::string> testExpectationsPath = FindTestExpectationsPath(exeDir, mTestModuleIndex); Optional<std::string> testExpectationsPath = FindTestExpectationsPath(mTestModuleIndex);
if (!testExpectationsPath.valid()) if (!testExpectationsPath.valid())
{ {
std::cerr << "Failed to find test expectations file." << std::endl; std::cerr << "Failed to find test expectations file." << std::endl;
...@@ -752,6 +735,11 @@ void InitTestHarness(int *argc, char **argv) ...@@ -752,6 +735,11 @@ void InitTestHarness(int *argc, char **argv)
{ {
HandleBatchId(argv[argIndex] + strlen(kBatchIdString)); HandleBatchId(argv[argIndex] + strlen(kBatchIdString));
} }
else if (strncmp(argv[argIndex], kVerboseString, strlen(kVerboseString)) == 0 ||
strcmp(argv[argIndex], "-v") == 0)
{
gVerbose = true;
}
argIndex++; argIndex++;
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "tcuRandomOrderExecutor.h" #include "tcuRandomOrderExecutor.h"
#include "tcuResource.hpp" #include "tcuResource.hpp"
#include "tcuTestLog.hpp" #include "tcuTestLog.hpp"
#include "util/OSWindow.h"
tcu::Platform *CreateANGLEPlatform(angle::LogErrorFunc logErrorFunc, uint32_t preRotation); tcu::Platform *CreateANGLEPlatform(angle::LogErrorFunc logErrorFunc, uint32_t preRotation);
...@@ -35,34 +36,6 @@ tcu::TestContext *g_testCtx = nullptr; ...@@ -35,34 +36,6 @@ tcu::TestContext *g_testCtx = nullptr;
tcu::TestPackageRoot *g_root = nullptr; tcu::TestPackageRoot *g_root = nullptr;
tcu::RandomOrderExecutor *g_executor = nullptr; tcu::RandomOrderExecutor *g_executor = nullptr;
const char *kDataPaths[] = {
".",
"../../sdcard/chromium_tests_root",
"../../sdcard/chromium_tests_root/third_party/angle/third_party/VK-GL-CTS/src",
"../../third_party/angle/third_party/VK-GL-CTS/src",
"../../third_party/VK-GL-CTS/src",
"third_party/VK-GL-CTS/src",
};
bool FindDataDir(std::string *dataDirOut)
{
for (const char *dataPath : kDataPaths)
{
std::stringstream dirStream;
dirStream << angle::GetExecutableDirectory() << "/" << dataPath << "/"
<< ANGLE_DEQP_DATA_DIR;
std::string candidateDataDir = dirStream.str();
if (angle::IsDirectory(candidateDataDir.c_str()))
{
*dataDirOut = candidateDataDir;
return true;
}
}
return false;
}
std::string GetLogFileName(std::string deqpDataDir) std::string GetLogFileName(std::string deqpDataDir)
{ {
#if (DE_OS == DE_OS_ANDROID) #if (DE_OS == DE_OS_ANDROID)
...@@ -95,15 +68,16 @@ ANGLE_LIBTESTER_EXPORT bool deqp_libtester_init_platform(int argc, ...@@ -95,15 +68,16 @@ ANGLE_LIBTESTER_EXPORT bool deqp_libtester_init_platform(int argc,
return false; return false;
} }
std::string deqpDataDir; constexpr size_t kMaxDataDirLen = 1000;
if (!FindDataDir(&deqpDataDir)) char deqpDataDir[kMaxDataDirLen];
if (!angle::FindTestDataPath(ANGLE_DEQP_DATA_DIR, deqpDataDir, kMaxDataDirLen))
{ {
std::cout << "Failed to find dEQP data directory." << std::endl; std::cout << "Failed to find dEQP data directory." << std::endl;
return false; return false;
} }
g_cmdLine = new tcu::CommandLine(argc, argv); g_cmdLine = new tcu::CommandLine(argc, argv);
g_archive = new tcu::DirArchive(deqpDataDir.c_str()); g_archive = new tcu::DirArchive(deqpDataDir);
g_log = new tcu::TestLog(GetLogFileName(deqpDataDir).c_str(), g_cmdLine->getLogFlags()); g_log = new tcu::TestLog(GetLogFileName(deqpDataDir).c_str(), g_cmdLine->getLogFlags());
g_testCtx = new tcu::TestContext(*g_platform, *g_archive, *g_log, *g_cmdLine, DE_NULL); g_testCtx = new tcu::TestContext(*g_platform, *g_archive, *g_log, *g_cmdLine, DE_NULL);
g_root = new tcu::TestPackageRoot(*g_testCtx, tcu::TestPackageRegistry::getSingleton()); g_root = new tcu::TestPackageRoot(*g_testCtx, tcu::TestPackageRegistry::getSingleton());
...@@ -168,7 +142,7 @@ ANGLE_LIBTESTER_EXPORT void deqp_libtester_shutdown_platform() ...@@ -168,7 +142,7 @@ ANGLE_LIBTESTER_EXPORT void deqp_libtester_shutdown_platform()
ANGLE_LIBTESTER_EXPORT TestResult deqp_libtester_run(const char *caseName) ANGLE_LIBTESTER_EXPORT TestResult deqp_libtester_run(const char *caseName)
{ {
const char *emptyString = ""; const char *emptyString = "";
if (g_platform == nullptr && !deqp_libtester_init_platform(1, &emptyString, nullptr, 0)) if (g_platform == nullptr)
{ {
tcu::die("Failed to initialize platform."); tcu::die("Failed to initialize platform.");
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "util/egl_loader_autogen.h" #include "util/egl_loader_autogen.h"
#include "util/frame_capture_test_utils.h" #include "util/frame_capture_test_utils.h"
#include "util/png_utils.h" #include "util/png_utils.h"
#include "util/test_utils.h"
#include "restricted_traces/restricted_traces_autogen.h" #include "restricted_traces/restricted_traces_autogen.h"
...@@ -309,10 +310,17 @@ void TracePerfTest::initializeBenchmark() ...@@ -309,10 +310,17 @@ void TracePerfTest::initializeBenchmark()
mEndFrame = traceInfo.endFrame; mEndFrame = traceInfo.endFrame;
SetBinaryDataDecompressCallback(params.testID, DecompressBinaryData); SetBinaryDataDecompressCallback(params.testID, DecompressBinaryData);
std::stringstream testDataDirStr; std::string relativeTestDataDir = std::string("src/tests/restricted_traces/") + traceInfo.name;
testDataDirStr << ANGLE_TRACE_DATA_DIR << "/" << traceInfo.name;
std::string testDataDir = testDataDirStr.str(); constexpr size_t kMaxDataDirLen = 1000;
SetBinaryDataDir(params.testID, testDataDir.c_str()); char testDataDir[kMaxDataDirLen];
if (!angle::FindTestDataPath(relativeTestDataDir.c_str(), testDataDir, kMaxDataDirLen))
{
ERR() << "Could not find test data folder.";
mSkipTest = true;
}
SetBinaryDataDir(params.testID, testDataDir);
mWindowWidth = mTestParams.windowWidth; mWindowWidth = mTestParams.windowWidth;
mWindowHeight = mTestParams.windowHeight; mWindowHeight = mTestParams.windowHeight;
......
...@@ -6,10 +6,16 @@ ...@@ -6,10 +6,16 @@
#include "OSWindow.h" #include "OSWindow.h"
#include <fstream>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include "common/debug.h" #include "common/debug.h"
#include "common/system_utils.h"
#if defined(ANGLE_PLATFORM_ANDROID)
# include "util/android/AndroidWindow.h"
#endif // defined(ANGLE_PLATFORM_ANDROID)
#ifndef DEBUG_EVENTS #ifndef DEBUG_EVENTS
# define DEBUG_EVENTS 0 # define DEBUG_EVENTS 0
...@@ -440,3 +446,47 @@ void OSWindow::Delete(OSWindow **window) ...@@ -440,3 +446,47 @@ void OSWindow::Delete(OSWindow **window)
delete *window; delete *window;
*window = nullptr; *window = nullptr;
} }
namespace angle
{
bool FindTestDataPath(const char *searchPath, char *dataPathOut, size_t maxDataPathOutLen)
{
#if defined(ANGLE_PLATFORM_ANDROID)
const std::string searchPaths[] = {
AndroidWindow::GetExternalStorageDirectory(),
AndroidWindow::GetExternalStorageDirectory() + "/third_party/angle"};
#else
const std::string searchPaths[] = {
GetExecutableDirectory(), GetExecutableDirectory() + "/../..", ".",
GetExecutableDirectory() + "/../../third_party/angle", "third_party/angle"};
#endif // defined(ANGLE_PLATFORM_ANDROID)
for (const std::string &path : searchPaths)
{
std::stringstream pathStream;
pathStream << path << "/" << searchPath;
std::string candidatePath = pathStream.str();
if (candidatePath.size() + 1 >= maxDataPathOutLen)
{
ERR() << "FindTestDataPath: Path too long.";
return false;
}
if (angle::IsDirectory(candidatePath.c_str()))
{
memcpy(dataPathOut, candidatePath.c_str(), candidatePath.size() + 1);
return true;
}
std::ifstream inFile(candidatePath.c_str());
if (!inFile.fail())
{
memcpy(dataPathOut, candidatePath.c_str(), candidatePath.size() + 1);
return true;
}
}
return false;
}
} // namespace angle
...@@ -87,4 +87,12 @@ class ANGLE_UTIL_EXPORT OSWindow ...@@ -87,4 +87,12 @@ class ANGLE_UTIL_EXPORT OSWindow
bool mIgnoreSizeEvents; bool mIgnoreSizeEvents;
}; };
namespace angle
{
// Find a test data file or directory.
ANGLE_UTIL_EXPORT bool FindTestDataPath(const char *searchPath,
char *dataPathOut,
size_t maxDataPathOutLen);
} // namespace angle
#endif // UTIL_OSWINDOW_H_ #endif // UTIL_OSWINDOW_H_
...@@ -53,7 +53,6 @@ int SetScreenOrientation(struct android_app *app, int orientation) ...@@ -53,7 +53,6 @@ int SetScreenOrientation(struct android_app *app, int orientation)
return 0; return 0;
} }
} // namespace } // namespace
AndroidWindow::AndroidWindow() {} AndroidWindow::AndroidWindow() {}
...@@ -191,6 +190,92 @@ void android_main(struct android_app *app) ...@@ -191,6 +190,92 @@ void android_main(struct android_app *app)
} }
// static // static
std::string AndroidWindow::GetExternalStorageDirectory()
{
// Use reverse JNI.
JNIEnv *jni = GetJniEnv();
if (!jni)
{
WARN() << "GetExternalStorageDirectory:: Failed to get JNI env";
return "";
}
// https://stackoverflow.com/questions/12841240/android-pass-parameter-to-native-activity
jclass clazz = jni->GetObjectClass(sApp->activity->clazz);
if (clazz == 0)
{
WARN() << "GetExternalStorageDirectory: Bad activity";
return "";
}
jmethodID giid = jni->GetMethodID(clazz, "getIntent", "()Landroid/content/Intent;");
if (giid == 0)
{
WARN() << "GetExternalStorageDirectory: Could not find getIntent";
return "";
}
jobject intent = jni->CallObjectMethod(sApp->activity->clazz, giid);
if (intent == 0)
{
WARN() << "GetExternalStorageDirectory: Error calling getIntent";
return "";
}
jclass icl = jni->GetObjectClass(intent);
if (icl == 0)
{
WARN() << "GetExternalStorageDirectory: Error getting getIntent class";
return "";
}
jmethodID gseid =
jni->GetMethodID(icl, "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
if (gseid == 0)
{
WARN() << "GetExternalStorageDirectory: Could not find getStringExtra";
return "";
}
jstring stringPath = static_cast<jstring>(jni->CallObjectMethod(
intent, gseid, jni->NewStringUTF("org.chromium.base.test.util.UrlUtils.RootDirectory")));
if (stringPath != 0)
{
const char *path = jni->GetStringUTFChars(stringPath, nullptr);
return std::string(path) + "/chromium_tests_root";
}
jclass environment = jni->FindClass("org/chromium/base/test/util/UrlUtils");
if (environment == 0)
{
WARN() << "GetExternalStorageDirectory: Failed to find Environment";
return "";
}
jmethodID getDir =
jni->GetStaticMethodID(environment, "getIsolatedTestRoot", "()Ljava/lang/String;");
if (getDir == 0)
{
WARN() << "GetExternalStorageDirectory: Failed to get static method";
return "";
}
stringPath = static_cast<jstring>(jni->CallStaticObjectMethod(environment, getDir));
jthrowable exception = jni->ExceptionOccurred();
if (exception != 0)
{
jni->ExceptionDescribe();
jni->ExceptionClear();
WARN() << "GetExternalStorageDirectory: Failed because of exception";
return "";
}
const char *path = jni->GetStringUTFChars(stringPath, nullptr);
return std::string(path);
}
// static
OSWindow *OSWindow::New() OSWindow *OSWindow::New()
{ {
// There should be only one live instance of AndroidWindow at a time, // There should be only one live instance of AndroidWindow at a time,
......
...@@ -34,6 +34,8 @@ class AndroidWindow : public OSWindow ...@@ -34,6 +34,8 @@ class AndroidWindow : public OSWindow
void signalTestEvent() override; void signalTestEvent() override;
ANGLE_UTIL_EXPORT static std::string GetExternalStorageDirectory();
private: private:
bool initializeImpl(const std::string &name, int width, int height) override; bool initializeImpl(const std::string &name, int width, int height) override;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment