Debian Codegraph @

tests/src/test_cpuutils.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/tests/src/test_cpuutils.cpp`/
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include <catch2/catch_all.hpp>
5
6 #include "core/components/cpuutils.h"cxx . . $ `<file>/src/core/components/cpuutils.h`/
7
8 namespace Testscxx . . $ Tests/::Utilscxx . . $ Tests/Utils/::CPUcxx . . $ Tests/Utils/CPU/ {
9
10 TEST_CASEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:144:11`!("CPU utils tests", "[Utils][CPU]")
11 {
12 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("parseProcCpuInfo")
13 {
14 // clang-format off
15 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> inputcxx . . $ std/vector#vector(9619226211e5a241).{"processor : 0",
16 "target : data"};
17 // clang-format on
18
19 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns target data")
20 {
21 auto data = ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::parseProcCpuInfocxx . . $ Utils/CPU/parseProcCpuInfo(6ce55c29d0623432).(input, 0, "target"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).);
22 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(data.has_value());
23 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(*data == "data");
24 }
25
26 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns nothing when input doesn't have the requested processor")
27 {
28 auto data = ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::parseProcCpuInfocxx . . $ Utils/CPU/parseProcCpuInfo(6ce55c29d0623432).(input, 10, "target"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).);
29 REQUIRE_FALSEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:128:11`!(data.has_value());
30 }
31
32 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns nothing when input doesn't have the requested target on "
33 "the processor")
34 {
35 auto data = ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::parseProcCpuInfocxx . . $ Utils/CPU/parseProcCpuInfo(6ce55c29d0623432).(input, 0, "wrong_target"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).);
36 REQUIRE_FALSEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:128:11`!(data.has_value());
37 }
38 }
39
40 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("parseProcStat")
41 {
42 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns the CPU aggregate stats from /proc/stat info")
43 {
44 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> inputcxx . . $ std/vector#vector(9619226211e5a241).{
45 "cpu 141434 264 40474 2021588 12439 5752 2750 0 0 0"};
46 auto stat = ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::parseProcStatcxx . . $ Utils/CPU/parseProcStat(c74a6c71ef0cb6d8).(input);
47 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(stat.has_value());
48 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(stat->user == 141434);
49 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(stat->nice == 264);
50 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(stat->system == 40474);
51 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(stat->idle == 2021588);
52 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(stat->ioWait == 12439);
53 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(stat->irq == 5752);
54 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(stat->softIrq == 2750);
55 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(stat->steal == 0);
56 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(stat->total ==
57 141434 + 264 + 40474 + 2021588 + 12439 + 5752 + 2750 + 0);
58 }
59
60 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns nothing when some stat values are missing from the cpu "
61 "aggregate line")
62 {
63 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> inputcxx . . $ std/vector#vector(9619226211e5a241).{"cpu 141434 264 40474 2021588 0 0 0"};
64 auto stat = ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::parseProcStatcxx . . $ Utils/CPU/parseProcStat(c74a6c71ef0cb6d8).(input);
65 REQUIRE_FALSEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:128:11`!(stat.has_value());
66 }
67
68 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns nothing when the cpu aggregate line is missing")
69 {
70 stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> inputcxx . . $ std/vector#vector(9619226211e5a241).{"other data"};
71 auto stat = ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::parseProcStatcxx . . $ Utils/CPU/parseProcStat(c74a6c71ef0cb6d8).(input);
72 REQUIRE_FALSEcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:128:11`!(stat.has_value());
73 }
74 }
75
76 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("computeCPUUsage")
77 {
78 SECTIONcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:149:11`!("Returns CPU usage")
79 {
80 stdcxx . . $ std/::uint64_tcxx . . $ std/uint64_t# total = 723998 + 5703 + 159187 + 9095956 + 22936 + 23633 +
81 10115 + 0;
82 auto statT0 = ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::Statcxx . . $ Utils/CPU/Stat#{723998, 5703, 159187, 9095956, 22936,
83 23633, 10115, 0, total};
84 total = 725077 + 5703 + 159248 + 9095956 + 22936 + 23638 + 10116 + 0;
85 auto statT1 = ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::Statcxx . . $ Utils/CPU/Stat#{725077, 5703, 159248, 9095956, 22936,
86 23638, 10116, 0, total};
87 auto usage = ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::computeCPUUsagecxx . . $ Utils/CPU/computeCPUUsage(501d82387ff0e1d5).(statT0, statT1);
88 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(usage == 100);
89
90 total = 664215 + 2940 + 147770 + 6752849 + 19569 + 21752 + 9330 + 0;
91 statT0 =cxx . . $ Utils/CPU/Stat#`operator=`(c34c3aa69824451f). ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::Statcxx . . $ Utils/CPU/Stat#{664215, 2940, 147770, 6752849, 19569,
92 21752, 9330, 0, total};
93 total = 664215 + 2940 + 147770 + 6754574 + 19583 + 21752 + 9330 + 0;
94 statT1 =cxx . . $ Utils/CPU/Stat#`operator=`(c34c3aa69824451f). ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::Statcxx . . $ Utils/CPU/Stat#{664215, 2940, 147770, 6754574, 19583,
95 21752, 9330, 0, total};
96 usage = ::Utilscxx . . $ Utils/::CPUcxx . . $ Utils/CPU/::computeCPUUsagecxx . . $ Utils/CPU/computeCPUUsage(501d82387ff0e1d5).(statT0, statT1);
97 REQUIREcxx . . $ `<external>/1821973855936310166/catch_test_macros.hpp:127:11`!(usage == 0);
98 }
99 }
100 }
101
102 } // namespace Tests::Utils::CPU