| 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 "common/hwidtranslatorstub.h" |
| 7 | #include "common/vectorstringdatasourcestub.h" |
| 8 | #include "core/info/common/cpuinfolscpu.h" |
| 9 | |
| 10 | namespace Tests::CPUInfoLsCpu { |
| 11 | |
| 12 | TEST_CASE("CPUInfoLsCpu tests", "[Info][CPUInfo][CPUInfoLsCpu]") |
| 13 | { |
| 14 | SECTION("Returns empty info when there is no data") |
| 15 | { |
| 16 | std::vector<std::string> const infoData; |
| 17 | |
| 18 | ::CPUInfoLsCpu ts( |
| 19 | std::make_unique<VectorStringDataSourceStub>("lscpu", infoData)); |
| 20 | |
| 21 | auto output = ts.provideInfo(0, {{0, 0, "/cpu0"}}); |
| 22 | REQUIRE(output.empty()); |
| 23 | } |
| 24 | |
| 25 | SECTION("Provides architecture") |
| 26 | { |
| 27 | std::vector<std::string> const infoData{"Architecture: z48"}; |
| 28 | |
| 29 | ::CPUInfoLsCpu ts( |
| 30 | std::make_unique<VectorStringDataSourceStub>("lscpu", infoData)); |
| 31 | |
| 32 | auto output = ts.provideInfo(0, {{0, 0, "/cpu0"}}); |
| 33 | auto data = std::make_pair(std::string(::CPUInfoLsCpu::Keys::arch), |
| 34 | std::string("z48")); |
| 35 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(data)); |
| 36 | } |
| 37 | |
| 38 | SECTION("Provides operation mode") |
| 39 | { |
| 40 | std::vector<std::string> const infoData{"CPU op-mode(s): 48-bit"}; |
| 41 | |
| 42 | ::CPUInfoLsCpu ts( |
| 43 | std::make_unique<VectorStringDataSourceStub>("lscpu", infoData)); |
| 44 | |
| 45 | auto output = ts.provideInfo(0, {{0, 0, "/cpu0"}}); |
| 46 | auto data = std::make_pair(std::string(::CPUInfoLsCpu::Keys::opMode), |
| 47 | std::string("48-bit")); |
| 48 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(data)); |
| 49 | } |
| 50 | |
| 51 | SECTION("Provides byte order") |
| 52 | { |
| 53 | std::vector<std::string> const infoData{ |
| 54 | "Byte Order: Middle Endian"}; |
| 55 | |
| 56 | ::CPUInfoLsCpu ts( |
| 57 | std::make_unique<VectorStringDataSourceStub>("lscpu", infoData)); |
| 58 | |
| 59 | auto output = ts.provideInfo(0, {{0, 0, "/cpu0"}}); |
| 60 | auto data = std::make_pair(std::string(::CPUInfoLsCpu::Keys::byteOrder), |
| 61 | std::string("Middle Endian")); |
| 62 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(data)); |
| 63 | } |
| 64 | |
| 65 | SECTION("Provides virtualization") |
| 66 | { |
| 67 | std::vector<std::string> const infoData{"Virtualization: zzz"}; |
| 68 | |
| 69 | ::CPUInfoLsCpu ts( |
| 70 | std::make_unique<VectorStringDataSourceStub>("lscpu", infoData)); |
| 71 | |
| 72 | auto output = ts.provideInfo(0, {{0, 0, "/cpu0"}}); |
| 73 | auto data = std::make_pair(std::string(::CPUInfoLsCpu::Keys::virt), |
| 74 | std::string("zzz")); |
| 75 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(data)); |
| 76 | } |
| 77 | |
| 78 | SECTION("Provides L1d cache size") |
| 79 | { |
| 80 | std::vector<std::string> const infoData{"L1d cache: 320K"}; |
| 81 | |
| 82 | ::CPUInfoLsCpu ts( |
| 83 | std::make_unique<VectorStringDataSourceStub>("lscpu", infoData)); |
| 84 | |
| 85 | auto output = ts.provideInfo(0, {{0, 0, "/cpu0"}}); |
| 86 | auto data = std::make_pair(std::string(::CPUInfoLsCpu::Keys::l1dCache), |
| 87 | std::string("320K")); |
| 88 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(data)); |
| 89 | } |
| 90 | |
| 91 | SECTION("Provides L1i cache size") |
| 92 | { |
| 93 | std::vector<std::string> const infoData{"L1i cache: 320K"}; |
| 94 | |
| 95 | ::CPUInfoLsCpu ts( |
| 96 | std::make_unique<VectorStringDataSourceStub>("lscpu", infoData)); |
| 97 | |
| 98 | auto output = ts.provideInfo(0, {{0, 0, "/cpu0"}}); |
| 99 | auto data = std::make_pair(std::string(::CPUInfoLsCpu::Keys::l1iCache), |
| 100 | std::string("320K")); |
| 101 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(data)); |
| 102 | } |
| 103 | |
| 104 | SECTION("Provides L2 cache size") |
| 105 | { |
| 106 | std::vector<std::string> const infoData{"L2 cache: 640K"}; |
| 107 | |
| 108 | ::CPUInfoLsCpu ts( |
| 109 | std::make_unique<VectorStringDataSourceStub>("lscpu", infoData)); |
| 110 | |
| 111 | auto output = ts.provideInfo(0, {{0, 0, "/cpu0"}}); |
| 112 | auto data = std::make_pair(std::string(::CPUInfoLsCpu::Keys::l2Cache), |
| 113 | std::string("640K")); |
| 114 | REQUIRE_THAT(output, Catch::Matchers::VectorContains(data)); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | } // namespace Tests::CPUInfoLsCpu |