Debian Codegraph @

tests/src/test_gpuinfo.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include <catch2/catch_all.hpp>
5
6 #include "core/info/gpuinfo.h"
7 #include "core/info/ihwidtranslator.h"
8
9 namespace Tests::GPUInfo {
10
11 class ProviderStub : public IGPUInfo::IProvider
12 {
13 public:
14 std::vector<std::pair<std::string, std::string>>
15 provideInfo(Vendor, int, IGPUInfo::Path const &,
16 IHWIDTranslator const &) const override
17 {
18 std::vector<std::pair<std::string, std::string>> info;
19 info.emplace_back("info_key", "info");
20 return info;
21 }
22
23 std::vector<std::string>
24 provideCapabilities(Vendor, int, IGPUInfo::Path const &) const override
25 {
26 std::vector<std::string> cap;
27 cap.emplace_back("capability");
28 return cap;
29 }
30 };
31
32 class HWIDTranslatorStub : public IHWIDTranslator
33 {
34 public:
35 std::string vendor(std::string const &) const override
36 {
37 return "";
38 }
39
40 std::string device(std::string const &, std::string const &) const override
41 {
42 return "";
43 }
44
45 std::string subdevice(std::string const &, std::string const &,
46 std::string const &, std::string const &) const override
47 {
48 return "";
49 }
50 };
51
52 TEST_CASE("GPUInfo tests", "[Info][GPUInfo]")
53 {
54 int gpuIndex{123};
55 ::GPUInfo ts(Vendor::AMD, gpuIndex, IGPUInfo::Path("_sys_", "_dev_"));
56
57 SECTION("Has vendor")
58 {
59 REQUIRE(ts.vendor() == Vendor::AMD);
60 }
61
62 SECTION("Has GPU index")
63 {
64 REQUIRE(ts.index() == gpuIndex);
65 }
66
67 SECTION("Has device paths")
68 {
69 REQUIRE(ts.path().sys == "_sys_");
70 REQUIRE(ts.path().dev == "_dev_");
71 }
72
73 SECTION("GPU info and capabilities are collected on initialization")
74 {
75 REQUIRE(ts.keys().empty());
76
77 HWIDTranslatorStub hwidTranStub;
78 std::vector<std::unique_ptr<IGPUInfo::IProvider>> providers;
79 providers.emplace_back(std::make_unique<ProviderStub>());
80
81 ts.initialize(providers, hwidTranStub);
82 auto keys = ts.keys();
83
84 REQUIRE(keys.size() == 1);
85 REQUIRE(keys.front() == "info_key");
86 REQUIRE(ts.info("info_key") == "info");
87
88 REQUIRE(ts.hasCapability("capability"));
89 }
90 }
91
92 } // namespace Tests::GPUInfo