Files
RedBear-OS/local/recipes/dev/libclc/source/llvm/unittests/Debuginfod/DebuginfodTests.cpp
T
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00

70 lines
3.0 KiB
C++

//===-- llvm/unittest/Support/DebuginfodTests.cpp - unit tests ------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "llvm/Debuginfod/Debuginfod.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
#ifdef _WIN32
#define setenv(name, var, ignore) _putenv_s(name, var)
#endif
#define ASSERT_NO_ERROR(x) \
if (std::error_code ASSERT_NO_ERROR_ec = x) { \
SmallString<128> MessageStorage; \
raw_svector_ostream Message(MessageStorage); \
Message << #x ": did not return errc::success.\n" \
<< "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
<< "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
} else { \
}
using namespace llvm;
// Check that the Debuginfod client can find locally cached artifacts.
TEST(DebuginfodClient, CacheHit) {
int FD;
SmallString<64> CachedFilePath;
sys::fs::createTemporaryFile("llvmcache-key", "temp", FD, CachedFilePath);
StringRef CacheDir = sys::path::parent_path(CachedFilePath);
StringRef UniqueKey = sys::path::filename(CachedFilePath);
EXPECT_TRUE(UniqueKey.consume_front("llvmcache-"));
raw_fd_ostream OF(FD, true, /*unbuffered=*/true);
OF << "contents\n";
OF << CacheDir << "\n";
OF.close();
Expected<std::string> PathOrErr = getCachedOrDownloadArtifact(
UniqueKey, /*UrlPath=*/"/null", CacheDir,
/*DebuginfodUrls=*/{}, /*Timeout=*/std::chrono::milliseconds(1));
EXPECT_THAT_EXPECTED(PathOrErr, HasValue(CachedFilePath));
}
// Check that the Debuginfod client returns an Error when it fails to find an
// artifact.
TEST(DebuginfodClient, CacheMiss) {
SmallString<32> CacheDir;
ASSERT_NO_ERROR(
sys::fs::createUniqueDirectory("debuginfod-unittest", CacheDir));
sys::path::append(CacheDir, "cachedir");
ASSERT_FALSE(sys::fs::exists(CacheDir));
setenv("DEBUGINFOD_CACHE_PATH", CacheDir.c_str(),
/*replace=*/1);
// Ensure there are no urls to guarantee a cache miss.
setenv("DEBUGINFOD_URLS", "", /*replace=*/1);
HTTPClient::initialize();
Expected<std::string> PathOrErr = getCachedOrDownloadArtifact(
/*UniqueKey=*/"nonexistent-key", /*UrlPath=*/"/null");
EXPECT_THAT_EXPECTED(PathOrErr, Failed<StringError>());
// A cache miss with no possible URLs should not create the cache directory.
EXPECT_FALSE(sys::fs::exists(CacheDir));
}