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) {
testonly = true
if (build_angle_trace_perf_tests) {
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 = [
":angle_perftests_shared",
"$angle_root:angle_compression",
......
......@@ -23,6 +23,7 @@
#include "platform/PlatformMethods.h"
#include "tests/test_expectations/GPUTestConfig.h"
#include "tests/test_expectations/GPUTestExpectationsParser.h"
#include "util/OSWindow.h"
#include "util/test_utils.h"
namespace angle
......@@ -32,6 +33,7 @@ namespace
bool gGlobalError = false;
bool gExpectError = false;
uint32_t gBatchId = 0;
bool gVerbose = false;
constexpr char kInfoTag[] = "*RESULT";
......@@ -54,20 +56,11 @@ std::string DrawElementsToGoogleTestName(const std::string &dEQPName)
return gTestName;
}
const char *gCaseListSearchPaths[] = {
"/../../sdcard/chromium_tests_root/third_party/angle/third_party/VK-GL-CTS/src",
"/../../third_party/VK-GL-CTS/src",
"/../../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/",
};
// Relative to the ANGLE root folder.
constexpr char kCTSRootPath[] = "third_party/VK-GL-CTS/src/";
constexpr char kSupportPath[] = "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[] = {
OPENGL_CTS_DIR("aosp_mustpass/master/gles2-master.txt"),
......@@ -116,6 +109,7 @@ constexpr char kANGLEEGLString[] = "--use-angle=";
constexpr char kANGLEPreRotation[] = "--emulated-pre-rotation=";
constexpr char kdEQPCaseString[] = "--deqp-case=";
constexpr char kBatchIdString[] = "--batch-id=";
constexpr char kVerboseString[] = "--verbose";
std::array<char, 500> gCaseStringBuffer;
......@@ -182,39 +176,30 @@ void Die()
exit(EXIT_FAILURE);
}
Optional<std::string> FindFileFromPaths(const char *paths[],
size_t numPaths,
const std::string &exeDir,
const std::string &searchFile)
Optional<std::string> FindFileFromPath(const char *dirPath, const char *filePath)
{
for (size_t pathIndex = 0; pathIndex < numPaths; ++pathIndex)
{
const char *testPath = paths[pathIndex];
std::stringstream pathStringStream;
pathStringStream << exeDir << testPath << searchFile;
std::stringstream strstr;
strstr << dirPath << filePath;
std::string path = strstr.str();
std::string path = pathStringStream.str();
std::ifstream inFile(path.c_str());
if (!inFile.fail())
{
inFile.close();
return Optional<std::string>(path);
}
constexpr size_t kMaxFoundPathLen = 1000;
char foundPath[kMaxFoundPathLen];
if (angle::FindTestDataPath(path.c_str(), foundPath, kMaxFoundPathLen))
{
return std::string(foundPath);
}
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,
gCaseListFiles[testModuleIndex]);
return FindFileFromPath(kCTSRootPath, 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),
exeDir, gTestExpectationsFiles[testModuleIndex]);
return FindFileFromPath(kSupportPath, gTestExpectationsFiles[testModuleIndex]);
}
class dEQPCaseList
......@@ -266,16 +251,14 @@ void dEQPCaseList::initialize()
mInitialized = true;
std::string exeDir = GetExecutableDirectory();
Optional<std::string> caseListPath = FindCaseListPath(exeDir, mTestModuleIndex);
Optional<std::string> caseListPath = FindCaseListPath(mTestModuleIndex);
if (!caseListPath.valid())
{
std::cerr << "Failed to find case list file." << std::endl;
Die();
}
Optional<std::string> testExpectationsPath = FindTestExpectationsPath(exeDir, mTestModuleIndex);
Optional<std::string> testExpectationsPath = FindTestExpectationsPath(mTestModuleIndex);
if (!testExpectationsPath.valid())
{
std::cerr << "Failed to find test expectations file." << std::endl;
......@@ -752,6 +735,11 @@ void InitTestHarness(int *argc, char **argv)
{
HandleBatchId(argv[argIndex] + strlen(kBatchIdString));
}
else if (strncmp(argv[argIndex], kVerboseString, strlen(kVerboseString)) == 0 ||
strcmp(argv[argIndex], "-v") == 0)
{
gVerbose = true;
}
argIndex++;
}
......
......@@ -21,6 +21,7 @@
#include "tcuRandomOrderExecutor.h"
#include "tcuResource.hpp"
#include "tcuTestLog.hpp"
#include "util/OSWindow.h"
tcu::Platform *CreateANGLEPlatform(angle::LogErrorFunc logErrorFunc, uint32_t preRotation);
......@@ -35,34 +36,6 @@ tcu::TestContext *g_testCtx = nullptr;
tcu::TestPackageRoot *g_root = 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)
{
#if (DE_OS == DE_OS_ANDROID)
......@@ -95,15 +68,16 @@ ANGLE_LIBTESTER_EXPORT bool deqp_libtester_init_platform(int argc,
return false;
}
std::string deqpDataDir;
if (!FindDataDir(&deqpDataDir))
constexpr size_t kMaxDataDirLen = 1000;
char deqpDataDir[kMaxDataDirLen];
if (!angle::FindTestDataPath(ANGLE_DEQP_DATA_DIR, deqpDataDir, kMaxDataDirLen))
{
std::cout << "Failed to find dEQP data directory." << std::endl;
return false;
}
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_testCtx = new tcu::TestContext(*g_platform, *g_archive, *g_log, *g_cmdLine, DE_NULL);
g_root = new tcu::TestPackageRoot(*g_testCtx, tcu::TestPackageRegistry::getSingleton());
......@@ -168,7 +142,7 @@ ANGLE_LIBTESTER_EXPORT void deqp_libtester_shutdown_platform()
ANGLE_LIBTESTER_EXPORT TestResult deqp_libtester_run(const char *caseName)
{
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.");
}
......
......@@ -16,6 +16,7 @@
#include "util/egl_loader_autogen.h"
#include "util/frame_capture_test_utils.h"
#include "util/png_utils.h"
#include "util/test_utils.h"
#include "restricted_traces/restricted_traces_autogen.h"
......@@ -309,10 +310,17 @@ void TracePerfTest::initializeBenchmark()
mEndFrame = traceInfo.endFrame;
SetBinaryDataDecompressCallback(params.testID, DecompressBinaryData);
std::stringstream testDataDirStr;
testDataDirStr << ANGLE_TRACE_DATA_DIR << "/" << traceInfo.name;
std::string testDataDir = testDataDirStr.str();
SetBinaryDataDir(params.testID, testDataDir.c_str());
std::string relativeTestDataDir = std::string("src/tests/restricted_traces/") + traceInfo.name;
constexpr size_t kMaxDataDirLen = 1000;
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;
mWindowHeight = mTestParams.windowHeight;
......
......@@ -6,10 +6,16 @@
#include "OSWindow.h"
#include <fstream>
#include <iostream>
#include <sstream>
#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
# define DEBUG_EVENTS 0
......@@ -440,3 +446,47 @@ void OSWindow::Delete(OSWindow **window)
delete *window;
*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
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_
......@@ -53,7 +53,6 @@ int SetScreenOrientation(struct android_app *app, int orientation)
return 0;
}
} // namespace
AndroidWindow::AndroidWindow() {}
......@@ -191,6 +190,92 @@ void android_main(struct android_app *app)
}
// 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()
{
// There should be only one live instance of AndroidWindow at a time,
......
......@@ -34,6 +34,8 @@ class AndroidWindow : public OSWindow
void signalTestEvent() override;
ANGLE_UTIL_EXPORT static std::string GetExternalStorageDirectory();
private:
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