-
Notifications
You must be signed in to change notification settings - Fork 68
fix: ensure XDG_DATA_DIRS contains system dirs so Vulkan drivers load #1742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
btlqql
wants to merge
1
commit into
OpenAtom-Linyaps:master
Choose a base branch
from
btlqql:btlqql/issue-1457
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
libs/linglong/tests/ll-tests/src/linglong/oci_cfg_generators/container_cfg_builder_test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include "../../common/tempdir.h" | ||
| #include "linglong/common/strings.h" | ||
| #include "linglong/oci-cfg-generators/container_cfg_builder.h" | ||
|
|
||
| #include <algorithm> | ||
| #include <filesystem> | ||
| #include <optional> | ||
| #include <string> | ||
|
|
||
| using namespace linglong; | ||
|
|
||
| namespace { | ||
|
|
||
| std::optional<std::string> getEnvValue(const ocppi::runtime::config::types::Config &config, | ||
| const std::string &key) | ||
| { | ||
| if (!config.process.has_value() || !config.process->env.has_value()) { | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| const std::string prefix = key + "="; | ||
| for (const auto &entry : *config.process->env) { | ||
| if (entry.size() >= prefix.size() && entry.compare(0, prefix.size(), prefix) == 0) { | ||
| return entry.substr(prefix.size()); | ||
| } | ||
| } | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| bool containsPart(std::string_view value, std::string_view part) | ||
| { | ||
| auto parts = common::strings::split(value, ':', common::strings::splitOption::SkipEmpty); | ||
| return std::find(parts.begin(), parts.end(), part) != parts.end(); | ||
| } | ||
|
|
||
| std::ptrdiff_t countPart(std::string_view value, std::string_view part) | ||
| { | ||
| auto parts = common::strings::split(value, ':', common::strings::splitOption::SkipEmpty); | ||
| return std::count(parts.begin(), parts.end(), part); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| // Regression test for issue #1457: the Vulkan ICD loader discovers driver | ||
| // manifests by scanning each XDG_DATA_DIRS entry for a "vulkan/icd.d" | ||
| // subdirectory. When XDG_DATA_DIRS is not present in the container environment, | ||
| // build() must still expose the conventional system data directories so that | ||
| // system provided drivers (e.g. the Mesa Turnip/freedreno Vulkan driver under | ||
| // /usr/share/vulkan/icd.d) remain discoverable. | ||
| TEST(ContainerCfgBuilderEnvTest, XdgDataDirsUnsetGetsSystemDefaults) | ||
| { | ||
| TempDir tmp; | ||
| ASSERT_TRUE(tmp.isValid()); | ||
| std::filesystem::create_directories(tmp.path() / "bundle"); | ||
|
|
||
| generator::ContainerCfgBuilder builder; | ||
| builder.setAppId("org.deepin.base") | ||
| .setBasePath(tmp.path() / "base") | ||
| .setBundlePath(tmp.path() / "bundle") | ||
| .disablePatch(); | ||
|
|
||
| auto result = builder.build(); | ||
| ASSERT_TRUE(result.has_value()) << result.error().message(); | ||
|
|
||
| auto xdg = getEnvValue(builder.getConfig(), "XDG_DATA_DIRS"); | ||
| ASSERT_TRUE(xdg.has_value()); | ||
| EXPECT_TRUE(containsPart(*xdg, "/usr/share")); | ||
| EXPECT_TRUE(containsPart(*xdg, "/usr/local/share")); | ||
| } | ||
|
|
||
| // Regression test for issue #1457: a host XDG_DATA_DIRS that only points at | ||
| // Linyaps specific paths may be forwarded into the container, overriding the | ||
| // Vulkan loader default search path. The forwarded value must be preserved | ||
| // while the standard system data directories are appended so that the loader | ||
| // still finds /usr/share/vulkan/icd.d. | ||
| TEST(ContainerCfgBuilderEnvTest, XdgDataDirsForwardedHostValueKeepsSystemDefaults) | ||
| { | ||
| TempDir tmp; | ||
| ASSERT_TRUE(tmp.isValid()); | ||
| std::filesystem::create_directories(tmp.path() / "bundle"); | ||
|
|
||
| generator::ContainerCfgBuilder builder; | ||
| builder.setAppId("org.deepin.base") | ||
| .setBasePath(tmp.path() / "base") | ||
| .setBundlePath(tmp.path() / "bundle") | ||
| .disablePatch() | ||
| .appendEnv("XDG_DATA_DIRS", "/var/lib/linglong/entries/share"); | ||
|
|
||
| auto result = builder.build(); | ||
| ASSERT_TRUE(result.has_value()) << result.error().message(); | ||
|
|
||
| auto xdg = getEnvValue(builder.getConfig(), "XDG_DATA_DIRS"); | ||
| ASSERT_TRUE(xdg.has_value()); | ||
| EXPECT_TRUE(containsPart(*xdg, "/var/lib/linglong/entries/share")); | ||
| EXPECT_TRUE(containsPart(*xdg, "/usr/share")); | ||
| EXPECT_TRUE(containsPart(*xdg, "/usr/local/share")); | ||
| } | ||
|
|
||
| TEST(ContainerCfgBuilderEnvTest, XdgDataDirsDoesNotDuplicateSystemDefaults) | ||
| { | ||
| TempDir tmp; | ||
| ASSERT_TRUE(tmp.isValid()); | ||
| std::filesystem::create_directories(tmp.path() / "bundle"); | ||
|
|
||
| generator::ContainerCfgBuilder builder; | ||
| builder.setAppId("org.deepin.base") | ||
| .setBasePath(tmp.path() / "base") | ||
| .setBundlePath(tmp.path() / "bundle") | ||
| .disablePatch() | ||
| .appendEnv("XDG_DATA_DIRS", "/usr/share:/usr/local/share"); | ||
|
|
||
| auto result = builder.build(); | ||
| ASSERT_TRUE(result.has_value()) << result.error().message(); | ||
|
|
||
| auto xdg = getEnvValue(builder.getConfig(), "XDG_DATA_DIRS"); | ||
| ASSERT_TRUE(xdg.has_value()); | ||
| EXPECT_EQ(*xdg, "/usr/share:/usr/local/share"); | ||
| EXPECT_EQ(countPart(*xdg, "/usr/share"), 1); | ||
| EXPECT_EQ(countPart(*xdg, "/usr/local/share"), 1); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can optimize this block to avoid unnecessary string copying and heap allocations:
std::string_viewforcurrentValueinstead of copyingxdgIt->secondinto a newstd::string.entriesbefore allocating and copying elements intodirs. If they are already present, we can skip the entire update process entirely.