49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
|
|
//SPDX-License-Identifier: LGPL-3.0-only
|
||
|
|
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
// The debug messenger prints the loader's and layers' info messages only when
|
||
|
|
// CRAFTER_GRAPHICS_VALIDATION is set. It used to print them on every run (the
|
||
|
|
// loader alone reports its device sorting a few times over), so every
|
||
|
|
// application's output started with lines that were not its own. Warnings and
|
||
|
|
// errors still print either way.
|
||
|
|
//
|
||
|
|
// Captures what Device::Initialize writes to stdout without validation, so it
|
||
|
|
// skips when CRAFTER_GRAPHICS_VALIDATION is set. Needs a Vulkan device.
|
||
|
|
|
||
|
|
#include <cstdio>
|
||
|
|
#include <cstdlib>
|
||
|
|
#include <unistd.h>
|
||
|
|
#include "vulkan/vulkan.h"
|
||
|
|
|
||
|
|
import Crafter.Graphics;
|
||
|
|
import std;
|
||
|
|
using namespace Crafter;
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
if (std::getenv("CRAFTER_GRAPHICS_VALIDATION") != nullptr) {
|
||
|
|
std::println("SKIP checks a run without CRAFTER_GRAPHICS_VALIDATION");
|
||
|
|
return 77;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Send stdout to a file while the device comes up.
|
||
|
|
std::FILE* capture = std::tmpfile();
|
||
|
|
std::fflush(stdout);
|
||
|
|
const int saved = dup(STDOUT_FILENO);
|
||
|
|
dup2(fileno(capture), STDOUT_FILENO);
|
||
|
|
Device::Initialize();
|
||
|
|
std::fflush(stdout);
|
||
|
|
dup2(saved, STDOUT_FILENO);
|
||
|
|
close(saved);
|
||
|
|
|
||
|
|
std::string output;
|
||
|
|
std::rewind(capture);
|
||
|
|
for (int c = std::fgetc(capture); c != EOF; c = std::fgetc(capture)) output.push_back(static_cast<char>(c));
|
||
|
|
std::fclose(capture);
|
||
|
|
|
||
|
|
const bool quiet = output.find("(info)") == std::string::npos;
|
||
|
|
std::println("{} Device::Initialize prints no info messages without validation", quiet ? "PASS" : "FAIL");
|
||
|
|
if (!quiet) {
|
||
|
|
std::println(" it printed:\n{}", output.substr(0, 400));
|
||
|
|
}
|
||
|
|
return quiet ? EXIT_SUCCESS : EXIT_FAILURE;
|
||
|
|
}
|