mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-12-02 06:02:15 +09:00
[Feature] (Client): read a system config file and decline EGL/GLX/GBM when no server answers
This commit is contained in:
1 parent
d24abe9287
commit
69e96f5b8d
18 files changed
+932
-13
No files matched your search
@@ -71,8 +71,27 @@ target_link_libraries(
|
||||
${LINK_LIBRARIES}
|
||||
)
|
||||
|
||||
# The system configuration files under the environment: the precedence MG_ConfigLoader::Init()
|
||||
# and its pre-init LookupSetting readers share. No GL context, no driver.
|
||||
add_executable(
|
||||
ConfigFileTest
|
||||
ConfigFileTest.cpp
|
||||
)
|
||||
|
||||
target_include_directories(ConfigFileTest PRIVATE
|
||||
${MGL_ROOT}/include
|
||||
${MGL_ROOT}/MobileGL
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
ConfigFileTest PRIVATE
|
||||
GTest::gtest_main
|
||||
${LINK_LIBRARIES}
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(JobNodeTest DISCOVERY_TIMEOUT 30 PROPERTIES LABELS unit)
|
||||
gtest_discover_tests(LogLevelTest DISCOVERY_TIMEOUT 30 PROPERTIES LABELS unit)
|
||||
gtest_discover_tests(PipeStatsTest DISCOVERY_TIMEOUT 30 PROPERTIES LABELS unit)
|
||||
gtest_discover_tests(DamageTest DISCOVERY_TIMEOUT 30 PROPERTIES LABELS unit)
|
||||
gtest_discover_tests(ConfigFileTest DISCOVERY_TIMEOUT 30 PROPERTIES LABELS unit)
|
||||
@@ -0,0 +1,176 @@
|
||||
// MobileGL - MobileGL/MG_Test/Util/ConfigFileTest.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// The system configuration files (ConfigLoader.cpp): environment > backend file > client.conf >
|
||||
// built-in default, for MG_ConfigLoader::Init() and for the LookupSetting readers that run before
|
||||
// it. No GL context, no driver: the loader is parsing.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <Config.h>
|
||||
#include <Init.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace {
|
||||
using MobileGL::BackendType;
|
||||
using MobileGL::String;
|
||||
namespace Config = MobileGL::MG_Config;
|
||||
namespace Loader = MobileGL::MG_ConfigLoader;
|
||||
|
||||
// Every variable a case touches, restored after it.
|
||||
constexpr const char* kTouched[] = {
|
||||
"MOBILEGL_CONFIG_FILE", "MOBILEGL_BACKEND_FILE", "MOBILEGL_BACKEND_TYPE",
|
||||
"MOBILEGL_MAGMA_FRAMESINFLIGHT", "MOBILEGL_TRANSPORT", "MOBILEGL_IPC_CONTROL",
|
||||
"MOBILEGL_IPC_DATA", "MOBILEGL_IPC_ROLE", "MOBILEGL_TEST_ONLY_KEY",
|
||||
};
|
||||
|
||||
class ConfigFileTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
for (const char* name : kTouched) {
|
||||
const char* value = std::getenv(name);
|
||||
saved_.emplace_back(name, value != nullptr, value != nullptr ? value : "");
|
||||
::unsetenv(name);
|
||||
}
|
||||
dir_ = std::filesystem::temp_directory_path() /
|
||||
("mgl-config-test-" + std::to_string(::getpid()) + "-" +
|
||||
::testing::UnitTest::GetInstance()->current_test_info()->name());
|
||||
std::filesystem::create_directories(dir_);
|
||||
conf_ = (dir_ / "client.conf").string();
|
||||
backend_ = (dir_ / "backend").string();
|
||||
// Point both at this case's files, which do not exist yet: the host's own /etc is
|
||||
// never read by a case.
|
||||
::setenv("MOBILEGL_CONFIG_FILE", conf_.c_str(), 1);
|
||||
::setenv("MOBILEGL_BACKEND_FILE", backend_.c_str(), 1);
|
||||
}
|
||||
void TearDown() override {
|
||||
for (const auto& [name, had, value] : saved_) {
|
||||
if (had) ::setenv(name.c_str(), value.c_str(), 1);
|
||||
else ::unsetenv(name.c_str());
|
||||
}
|
||||
std::error_code ec;
|
||||
std::filesystem::remove_all(dir_, ec);
|
||||
Loader::Init(); // leave the process's configuration as its environment says
|
||||
}
|
||||
static void Write(const std::string& path, const std::string& text) {
|
||||
std::ofstream out(path, std::ios::binary);
|
||||
out << text;
|
||||
}
|
||||
static String Lookup(const char* key) {
|
||||
String value;
|
||||
return Loader::LookupSetting(key, value) ? value : String("<unset>");
|
||||
}
|
||||
|
||||
std::vector<std::tuple<std::string, bool, std::string>> saved_;
|
||||
std::filesystem::path dir_;
|
||||
std::string conf_;
|
||||
std::string backend_;
|
||||
};
|
||||
|
||||
TEST_F(ConfigFileTest, WithoutFilesOrEnvironmentTheBuiltInDefaultsHold) {
|
||||
Loader::Init();
|
||||
EXPECT_EQ(Config::ActiveBackendType, BackendType::DirectGLES);
|
||||
EXPECT_EQ(Config::Features.MagmaFramesInFlight, 3u);
|
||||
EXPECT_EQ(Lookup("MOBILEGL_TRANSPORT"), "<unset>");
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
EXPECT_EQ(Config::Transport, Config::TransportMode::Monolith);
|
||||
EXPECT_EQ(Config::Ipc.Control, "fork");
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(ConfigFileTest, TheFileFillsWhatTheEnvironmentLeavesUnset) {
|
||||
Write(conf_, "# a comment\n"
|
||||
"\n"
|
||||
" MOBILEGL_MAGMA_FRAMESINFLIGHT = 5 \n"
|
||||
"MOBILEGL_TRANSPORT=spawn\r\n"
|
||||
"MOBILEGL_IPC_CONTROL=\"unix:@test-endpoint\"\n"
|
||||
"MOBILEGL_IPC_DATA='shm'\n"
|
||||
"NOT_OURS=1\n"
|
||||
"garbage line without equals\n"
|
||||
"MOBILEGL_TEST_ONLY_KEY=a=b\n");
|
||||
Loader::Init();
|
||||
EXPECT_EQ(Config::Features.MagmaFramesInFlight, 5u);
|
||||
EXPECT_EQ(Lookup("MOBILEGL_TRANSPORT"), "spawn");
|
||||
EXPECT_EQ(Lookup("MOBILEGL_IPC_CONTROL"), "unix:@test-endpoint");
|
||||
EXPECT_EQ(Lookup("MOBILEGL_IPC_DATA"), "shm");
|
||||
EXPECT_EQ(Lookup("MOBILEGL_TEST_ONLY_KEY"), "a=b"); // only the first '=' splits
|
||||
EXPECT_EQ(Lookup("NOT_OURS"), "<unset>");
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
EXPECT_EQ(Config::Transport, Config::TransportMode::Spawn);
|
||||
EXPECT_EQ(Config::Ipc.Control, "unix:@test-endpoint");
|
||||
EXPECT_EQ(Config::Ipc.Data, "shm");
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(ConfigFileTest, TheEnvironmentWinsOverTheFile) {
|
||||
Write(conf_, "MOBILEGL_MAGMA_FRAMESINFLIGHT=5\nMOBILEGL_IPC_CONTROL=unix:@from-file\n");
|
||||
::setenv("MOBILEGL_MAGMA_FRAMESINFLIGHT", "7", 1);
|
||||
::setenv("MOBILEGL_IPC_CONTROL", "unix:@from-env", 1);
|
||||
Loader::Init();
|
||||
EXPECT_EQ(Config::Features.MagmaFramesInFlight, 7u);
|
||||
EXPECT_EQ(Lookup("MOBILEGL_IPC_CONTROL"), "unix:@from-env");
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
EXPECT_EQ(Config::Ipc.Control, "unix:@from-env");
|
||||
#endif
|
||||
// Set but empty is still the environment speaking.
|
||||
::setenv("MOBILEGL_IPC_CONTROL", "", 1);
|
||||
EXPECT_EQ(Lookup("MOBILEGL_IPC_CONTROL"), "");
|
||||
}
|
||||
|
||||
TEST_F(ConfigFileTest, TheBackendFileNamesTheBackendUnderTheEnvironmentAndOverClientConf) {
|
||||
Write(backend_, " DirectVulkan \n");
|
||||
Write(conf_, "MOBILEGL_BACKEND_TYPE=DirectGLES\n");
|
||||
Loader::Init();
|
||||
EXPECT_EQ(Config::ActiveBackendType, BackendType::DirectVulkan);
|
||||
EXPECT_EQ(Lookup("MOBILEGL_BACKEND_TYPE"), "DirectVulkan");
|
||||
|
||||
::setenv("MOBILEGL_BACKEND_TYPE", "DirectGLES", 1);
|
||||
Loader::Init();
|
||||
EXPECT_EQ(Config::ActiveBackendType, BackendType::DirectGLES);
|
||||
::unsetenv("MOBILEGL_BACKEND_TYPE");
|
||||
|
||||
// Without the backend file, client.conf's line is the answer.
|
||||
std::filesystem::remove(backend_);
|
||||
Write(conf_, "MOBILEGL_BACKEND_TYPE=DirectVulkan\n");
|
||||
Loader::Init();
|
||||
EXPECT_EQ(Config::ActiveBackendType, BackendType::DirectVulkan);
|
||||
}
|
||||
|
||||
TEST_F(ConfigFileTest, AnEmptyPathTurnsAFileOffAndAMissingFileIsNoError) {
|
||||
Write(conf_, "MOBILEGL_MAGMA_FRAMESINFLIGHT=5\n");
|
||||
Write(backend_, "DirectVulkan\n");
|
||||
::setenv("MOBILEGL_CONFIG_FILE", "", 1);
|
||||
::setenv("MOBILEGL_BACKEND_FILE", "", 1);
|
||||
Loader::Init();
|
||||
EXPECT_EQ(Config::Features.MagmaFramesInFlight, 3u);
|
||||
EXPECT_EQ(Config::ActiveBackendType, BackendType::DirectGLES);
|
||||
|
||||
::setenv("MOBILEGL_CONFIG_FILE", (dir_ / "absent.conf").string().c_str(), 1);
|
||||
Loader::Init();
|
||||
EXPECT_EQ(Config::Features.MagmaFramesInFlight, 3u);
|
||||
}
|
||||
|
||||
TEST_F(ConfigFileTest, AServerProcessNeverReadsTheClientsFile) {
|
||||
Write(conf_, "MOBILEGL_MAGMA_FRAMESINFLIGHT=5\n");
|
||||
Write(backend_, "DirectVulkan\n");
|
||||
::setenv("MOBILEGL_IPC_ROLE", "server", 1);
|
||||
Loader::Init();
|
||||
EXPECT_EQ(Config::Features.MagmaFramesInFlight, 3u);
|
||||
EXPECT_EQ(Config::ActiveBackendType, BackendType::DirectGLES);
|
||||
EXPECT_EQ(Lookup("MOBILEGL_MAGMA_FRAMESINFLIGHT"), "<unset>");
|
||||
}
|
||||
} // namespace
|
||||
@@ -77,6 +77,10 @@ if (NOT WIN32)
|
||||
# supervisor over loopback TCP (P12ServerRig.h): refused by name once per session on the side
|
||||
# that names it, map_persistent DECLINED, never a Fatal. Needs the server image too.
|
||||
list(APPEND MOBILEGL_WIRE_TESTS AdoptTierStreamTest)
|
||||
# Declining when no server is there (Client/ServerProbe.h): the probe over unix/abstract/TCP
|
||||
# listeners, and the EGL/glvnd/GLX entry points in forked clients, with no server (they decline
|
||||
# inside a second) and against a real `--serve` supervisor (a display). Needs the server image.
|
||||
list(APPEND MOBILEGL_WIRE_TESTS ServerProbeTest)
|
||||
endif()
|
||||
|
||||
include(GoogleTest)
|
||||
@@ -95,7 +99,7 @@ foreach (test IN LISTS MOBILEGL_WIRE_TESTS)
|
||||
${MGL_ROOT}/3rdparty/flatbuffers/include
|
||||
)
|
||||
if (test STREQUAL "PeerLatchTest" OR test STREQUAL "InProcessServerTest" OR test STREQUAL "ServerOwnedSurfaceTest" OR
|
||||
test STREQUAL "AdoptTierStreamTest" OR test STREQUAL "MultiSessionTest")
|
||||
test STREQUAL "AdoptTierStreamTest" OR test STREQUAL "MultiSessionTest" OR test STREQUAL "ServerProbeTest")
|
||||
# It builds records and a program archive by hand, so it reaches MG_Pipe and MG_State
|
||||
# the way the codec suites do. (P12's two server suites share PeerLatchTest's healthy
|
||||
# session, P12ServerRig.h, and so its include paths.)
|
||||
@@ -116,8 +120,13 @@ foreach (test IN LISTS MOBILEGL_WIRE_TESTS)
|
||||
target_compile_definitions(${test} PRIVATE MOBILEGL_SOURCE_ROOT="${MGL_ROOT}")
|
||||
endif ()
|
||||
|
||||
if (test STREQUAL "ServerProbeTest")
|
||||
# It calls the glvnd vendor entry point the way libEGL does.
|
||||
target_include_directories(${test} PRIVATE ${MGL_ROOT}/3rdparty/glvnd/include)
|
||||
endif ()
|
||||
|
||||
if (test STREQUAL "ServerSpawnTest" OR test STREQUAL "PeerLatchTest" OR test STREQUAL "InProcessServerTest" OR
|
||||
test STREQUAL "ServerOwnedSurfaceTest" OR test STREQUAL "AdoptTierStreamTest")
|
||||
test STREQUAL "ServerOwnedSurfaceTest" OR test STREQUAL "AdoptTierStreamTest" OR test STREQUAL "ServerProbeTest")
|
||||
# It execs the real image, so it must be built first and must be told
|
||||
# where it is. MOBILEGL_TEST_SERVER_PATH is read by the test's
|
||||
# ServerImage() helper; without it the test would depend on the working
|
||||
|
||||
@@ -0,0 +1,263 @@
|
||||
// MobileGL - MobileGL/MG_Test/Wire/ServerProbeTest.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// DECLINING WHEN NO SERVER IS THERE (MG_Remote/Client/ServerProbe.h).
|
||||
//
|
||||
// Installed as the system's EGL/GLX/GBM vendor, MobileGL is asked first by every GL process, so it
|
||||
// must step aside - quickly - when the server it would dial is not running:
|
||||
// * the probe itself: a listening abstract name / path / loopback port answers Reachable, an
|
||||
// absent one Unreachable within milliseconds, and the configurations with nothing to dial
|
||||
// (monolith, fork, fd:, probing turned off) NotApplicable;
|
||||
// * the entry points, each in a fresh forked process: with the configured endpoint absent,
|
||||
// eglGetDisplay, the glvnd vendor's getPlatformDisplay and its device list all decline, and
|
||||
// the GLX vendor refuses to load - in well under a second, where the session bring-up they
|
||||
// replace waits 20 s; with a real `--serve` supervisor listening, a display is handed out.
|
||||
|
||||
#include "P12ServerRig.h"
|
||||
|
||||
#include <Init.h>
|
||||
#include <MG_Impl/EGLImpl/EGLImpl.h>
|
||||
#include <MG_Remote/Client/ServerProbe.h>
|
||||
#include <MG_Remote/Transport/SocketTransport.h>
|
||||
|
||||
#include <glvnd/libeglabi.h>
|
||||
|
||||
#include <sys/un.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
extern "C" EGLBoolean __egl_Main(uint32_t version, const __EGLapiExports* exports, __EGLvendorInfo* vendor,
|
||||
__EGLapiImports* imports);
|
||||
extern "C" int __glx_Main(uint32_t version, const void* exports, void* vendor, void* imports);
|
||||
|
||||
using namespace MobileGL;
|
||||
|
||||
namespace {
|
||||
|
||||
namespace EGL = MobileGL::MG_Impl::EGLImpl;
|
||||
namespace Probe = MobileGL::MG_Remote::Client;
|
||||
namespace Debug = MobileGL::MG_Util::Debug;
|
||||
using MobileGL::MG_Remote::Transport::SocketTransport;
|
||||
|
||||
std::string UniqueName(const char* what) {
|
||||
return std::string("mgl-probe-test-") + what + "-" + std::to_string(::getpid());
|
||||
}
|
||||
|
||||
// A bare listener (no MobileGL server): all the probe needs is someone accepting connections.
|
||||
struct Listener {
|
||||
int fd = -1;
|
||||
~Listener() {
|
||||
if (fd >= 0) ::close(fd);
|
||||
}
|
||||
bool Unix(const std::string& endpoint) { // "@name" or a path
|
||||
fd = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
sockaddr_un address{};
|
||||
address.sun_family = AF_UNIX;
|
||||
socklen_t length = 0;
|
||||
if (endpoint[0] == '@') {
|
||||
std::memcpy(address.sun_path + 1, endpoint.c_str() + 1, endpoint.size() - 1);
|
||||
length = static_cast<socklen_t>(offsetof(sockaddr_un, sun_path) + endpoint.size());
|
||||
} else {
|
||||
std::memcpy(address.sun_path, endpoint.c_str(), endpoint.size());
|
||||
length = static_cast<socklen_t>(offsetof(sockaddr_un, sun_path) + endpoint.size() + 1);
|
||||
}
|
||||
return fd >= 0 && ::bind(fd, reinterpret_cast<sockaddr*>(&address), length) == 0 && ::listen(fd, 4) == 0;
|
||||
}
|
||||
int Tcp() { // returns the port
|
||||
fd = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||
sockaddr_in address{};
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
socklen_t length = sizeof(address);
|
||||
if (fd < 0 || ::bind(fd, reinterpret_cast<sockaddr*>(&address), sizeof(address)) != 0 ||
|
||||
::listen(fd, 4) != 0 || ::getsockname(fd, reinterpret_cast<sockaddr*>(&address), &length) != 0)
|
||||
return -1;
|
||||
return ntohs(address.sin_port);
|
||||
}
|
||||
};
|
||||
|
||||
long long MillisSince(std::chrono::steady_clock::time_point start) {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start).count();
|
||||
}
|
||||
|
||||
// The probe reads the environment over the system configuration; no case may read the host's.
|
||||
class ServerProbeTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
::setenv("MOBILEGL_CONFIG_FILE", "", 1);
|
||||
::setenv("MOBILEGL_BACKEND_FILE", "", 1);
|
||||
::unsetenv("MOBILEGL_IPC_PROBE_TIMEOUT_MS");
|
||||
Probe::ResetServerProbeCache();
|
||||
}
|
||||
void TearDown() override {
|
||||
::unsetenv("MOBILEGL_TRANSPORT");
|
||||
::unsetenv("MOBILEGL_IPC_CONTROL");
|
||||
::unsetenv("MOBILEGL_IPC_PROBE_TIMEOUT_MS");
|
||||
Probe::ResetServerProbeCache();
|
||||
}
|
||||
static void Configure(const char* transport, const std::string& control) {
|
||||
::setenv("MOBILEGL_TRANSPORT", transport, 1);
|
||||
::setenv("MOBILEGL_IPC_CONTROL", control.c_str(), 1);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ServerProbeTest, AListeningEndpointIsReachableAndAnAbsentOneIsNotQuickly) {
|
||||
Listener abstract;
|
||||
const std::string name = "@" + UniqueName("abstract");
|
||||
ASSERT_TRUE(abstract.Unix(name));
|
||||
EXPECT_TRUE(SocketTransport::Probe(name, 250));
|
||||
|
||||
const std::string path = "/tmp/" + UniqueName("path") + ".sock";
|
||||
::unlink(path.c_str());
|
||||
{
|
||||
Listener filesystem;
|
||||
ASSERT_TRUE(filesystem.Unix(path));
|
||||
EXPECT_TRUE(SocketTransport::Probe(path, 250));
|
||||
}
|
||||
::unlink(path.c_str());
|
||||
|
||||
Listener tcp;
|
||||
const int port = tcp.Tcp();
|
||||
ASSERT_GT(port, 0);
|
||||
EXPECT_TRUE(SocketTransport::Probe("tcp://127.0.0.1:" + std::to_string(port), 250));
|
||||
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
EXPECT_FALSE(SocketTransport::Probe("@" + UniqueName("nobody"), 250));
|
||||
EXPECT_FALSE(SocketTransport::Probe(path, 250)); // unlinked: ENOENT
|
||||
::close(std::exchange(tcp.fd, -1));
|
||||
EXPECT_FALSE(SocketTransport::Probe("tcp://127.0.0.1:" + std::to_string(port), 250));
|
||||
EXPECT_LT(MillisSince(start), 200) << "a refused or absent endpoint must answer at once, not at the bound";
|
||||
}
|
||||
|
||||
TEST_F(ServerProbeTest, TheConfigurationDecidesWhatIsProbed) {
|
||||
Listener abstract;
|
||||
const std::string name = "@" + UniqueName("configured");
|
||||
ASSERT_TRUE(abstract.Unix(name));
|
||||
|
||||
Configure("spawn", "unix:" + name);
|
||||
EXPECT_EQ(Probe::ProbeConfiguredServer(), Probe::ServerProbeResult::Reachable);
|
||||
Configure("SPAWN", "unix:@" + UniqueName("absent"));
|
||||
EXPECT_EQ(Probe::ProbeConfiguredServer(), Probe::ServerProbeResult::Unreachable);
|
||||
|
||||
// Nothing to dial: these are served some other way, never declined by a probe.
|
||||
Configure("monolith", "unix:@" + UniqueName("absent"));
|
||||
EXPECT_EQ(Probe::ProbeConfiguredServer(), Probe::ServerProbeResult::NotApplicable);
|
||||
Configure("spawn", "fork");
|
||||
EXPECT_EQ(Probe::ProbeConfiguredServer(), Probe::ServerProbeResult::NotApplicable);
|
||||
Configure("spawn", "fd:3,4");
|
||||
EXPECT_EQ(Probe::ProbeConfiguredServer(), Probe::ServerProbeResult::NotApplicable);
|
||||
::unsetenv("MOBILEGL_TRANSPORT");
|
||||
::unsetenv("MOBILEGL_IPC_CONTROL");
|
||||
EXPECT_EQ(Probe::ProbeConfiguredServer(), Probe::ServerProbeResult::NotApplicable);
|
||||
|
||||
// MOBILEGL_IPC_PROBE_TIMEOUT_MS=0 turns probing off.
|
||||
Configure("spawn", "unix:@" + UniqueName("absent"));
|
||||
::setenv("MOBILEGL_IPC_PROBE_TIMEOUT_MS", "0", 1);
|
||||
EXPECT_EQ(Probe::ProbeConfiguredServer(), Probe::ServerProbeResult::NotApplicable);
|
||||
}
|
||||
|
||||
TEST_F(ServerProbeTest, APositiveAnswerIsCachedAndANegativeOneIsAskedAgain) {
|
||||
const std::string name = "@" + UniqueName("cache");
|
||||
Configure("spawn", "unix:" + name);
|
||||
EXPECT_FALSE(Probe::ConfiguredServerAvailable());
|
||||
{
|
||||
Listener late;
|
||||
ASSERT_TRUE(late.Unix(name));
|
||||
EXPECT_TRUE(Probe::ConfiguredServerAvailable()); // the server came up: asked again
|
||||
}
|
||||
EXPECT_TRUE(Probe::ConfiguredServerAvailable()); // and remembered
|
||||
Probe::ResetServerProbeCache();
|
||||
EXPECT_FALSE(Probe::ConfiguredServerAvailable());
|
||||
}
|
||||
|
||||
// ---- the entry points, each in a fresh process ---------------------------------------------
|
||||
|
||||
struct EntryReport {
|
||||
Int32 getDisplay = -1; // 1: eglGetDisplay gave a display
|
||||
Int32 vendorDisplay = -1; // 1: the glvnd vendor's getPlatformDisplay did
|
||||
Int32 vendorDevices = -1; // the vendor's eglQueryDevicesEXT count
|
||||
Int32 glxLoaded = -1; // __glx_Main's answer
|
||||
Int64 elapsedMs = -1; // all of the above, end to end
|
||||
};
|
||||
|
||||
EntryReport RunEntryPoints(const std::string& control, const std::string& logBase) {
|
||||
EntryReport report{};
|
||||
int fds[2] = {-1, -1};
|
||||
if (::pipe(fds) != 0) return report;
|
||||
std::fflush(nullptr);
|
||||
const pid_t pid = ::fork();
|
||||
if (pid == 0) {
|
||||
::close(fds[0]);
|
||||
::setenv("MOBILEGL_LOG_FILE_PATH", logBase.c_str(), 1);
|
||||
::setenv("MOBILEGL_TRANSPORT", "spawn", 1);
|
||||
::setenv("MOBILEGL_IPC_CONTROL", control.c_str(), 1);
|
||||
::setenv("MOBILEGL_BACKEND_TYPE", "DirectGLES", 1);
|
||||
EntryReport r{};
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
|
||||
__EGLapiExports exports{};
|
||||
__EGLapiImports imports{};
|
||||
const bool vendor = __egl_Main(EGL_VENDOR_ABI_VERSION, &exports, nullptr, &imports) == EGL_TRUE;
|
||||
r.vendorDisplay = vendor && imports.getPlatformDisplay(EGL_NONE, EGL_DEFAULT_DISPLAY, nullptr) != EGL_NO_DISPLAY;
|
||||
r.getDisplay = EGL::GetDisplay(EGL_DEFAULT_DISPLAY) != EGL_NO_DISPLAY;
|
||||
if (vendor) {
|
||||
using QueryDevices = EGLBoolean (*)(EGLint, EGLDeviceEXT*, EGLint*);
|
||||
auto* query = reinterpret_cast<QueryDevices>(imports.getProcAddress("eglQueryDevicesEXT"));
|
||||
EGLint count = -1;
|
||||
if (query != nullptr && query(0, nullptr, &count) == EGL_TRUE) r.vendorDevices = count;
|
||||
}
|
||||
void* glxExports[16] = {};
|
||||
void* glxImports[16] = {};
|
||||
r.glxLoaded = __glx_Main(1u << 16, glxExports, nullptr, glxImports);
|
||||
r.elapsedMs = MillisSince(start);
|
||||
|
||||
const ssize_t wrote = ::write(fds[1], &r, sizeof(r));
|
||||
(void)wrote;
|
||||
std::fflush(nullptr);
|
||||
::_exit(0);
|
||||
}
|
||||
::close(fds[1]);
|
||||
pollfd pfd{fds[0], POLLIN, 0};
|
||||
if (pid > 0 && ::poll(&pfd, 1, 60000) > 0) {
|
||||
const ssize_t got = ::read(fds[0], &report, sizeof(report));
|
||||
(void)got;
|
||||
}
|
||||
::close(fds[0]);
|
||||
if (pid > 0) {
|
||||
::kill(pid, SIGKILL);
|
||||
::waitpid(pid, nullptr, 0);
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
TEST_F(ServerProbeTest, WithNoServerEveryEntryPointDeclinesWellInsideASecond) {
|
||||
const std::string logBase = "/tmp/" + UniqueName("decline") + ".log";
|
||||
const EntryReport r = RunEntryPoints("unix:@" + UniqueName("no-server"), logBase);
|
||||
EXPECT_EQ(r.vendorDisplay, 0) << "the glvnd vendor must decline so the next vendor is asked";
|
||||
EXPECT_EQ(r.getDisplay, 0);
|
||||
EXPECT_EQ(r.vendorDevices, 0) << "no device either, and no error (glvnd fails its merge on one)";
|
||||
EXPECT_EQ(r.glxLoaded, 0) << "the GLX vendor must refuse to load so libGLX falls back";
|
||||
EXPECT_GE(r.elapsedMs, 0);
|
||||
EXPECT_LT(r.elapsedMs, 1000) << "declining must not cost the bring-up's 20 s connect budget";
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(Debug::RoleLogPath(logBase.c_str(), Debug::LogRole::Client), ec);
|
||||
}
|
||||
|
||||
TEST_F(ServerProbeTest, WithAServerListeningADisplayIsHandedOut) {
|
||||
P12::ServerProcess server;
|
||||
if (!P12::LaunchSupervisor("probe", &server)) GTEST_SKIP() << "no `--serve` supervisor on this host";
|
||||
const std::string logBase = "/tmp/" + UniqueName("serve") + ".log";
|
||||
const EntryReport r = RunEntryPoints(server.endpoint, logBase);
|
||||
EXPECT_EQ(r.vendorDisplay, 1) << server.Log();
|
||||
EXPECT_EQ(r.getDisplay, 1);
|
||||
EXPECT_EQ(r.vendorDevices, 1);
|
||||
EXPECT_EQ(r.glxLoaded, 1);
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(Debug::RoleLogPath(logBase.c_str(), Debug::LogRole::Client), ec);
|
||||
}
|
||||
} // namespace
|
||||
Reference in new issue
Block a user