From b5f3f44c5753e2a4dc06ffa1b385ee77a23d7f51 Mon Sep 17 00:00:00 2001 From: El Date: Mon, 7 Apr 2025 17:14:07 +0500 Subject: [PATCH] KASM-6984 Refactor SelfBench XML generation and enhance benchmarking. Simplified XML structure by removing unnecessary elements and attributes. Added new fields to aggregate test case count, total time, and class name in the generated "SelfBench.xml" file. Ensures clearer benchmarking output and streamlined code. KASM-6984 Refactor SelfBench XML generation and enhance benchmarking. Simplified XML structure by removing unnecessary elements and attributes. Added new fields to aggregate test case count, total time, and class name in the generated --- common/rfb/SelfBench.cxx | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/common/rfb/SelfBench.cxx b/common/rfb/SelfBench.cxx index ca8e3fb..62c0cac 100644 --- a/common/rfb/SelfBench.cxx +++ b/common/rfb/SelfBench.cxx @@ -44,14 +44,10 @@ static constexpr uint32_t HEIGHT = 1200; void SelfBench() { tinyxml2::XMLDocument doc; - auto *root = doc.NewElement("testsuites"); - root->SetAttribute("name", "Benchmarking"); - - auto *test_suits = doc.InsertFirstChild(root); - - auto *test_suit = doc.NewElement("testsuit"); + auto *test_suit = doc.NewElement("testsuite"); test_suit->SetAttribute("name", "SelfBench"); - test_suits->InsertEndChild(test_suit); + + doc.InsertFirstChild(test_suit); ManagedPixelBuffer f1(pfRGBX, WIDTH, HEIGHT); ManagedPixelBuffer f2(pfRGBX, WIDTH, HEIGHT); @@ -85,18 +81,26 @@ void SelfBench() { TightJPEGEncoder jpeg(nullptr); - auto benchmark = [&doc, &test_suit](const char *name, uint32_t runs, auto func) { + uint32_t test_cases {}; + uint64_t total_time {}; + + auto benchmark = [&doc, &test_suit, &test_cases, &total_time](const char *name, uint32_t runs, auto func) { auto now = std::chrono::high_resolution_clock::now(); for (uint32_t i = 0; i < runs; i++) { func(i); } + ++test_cases; auto value = elapsedMs(now); + double junit_value = value / 1000.; + total_time += value; + vlog.info("%s took %lu ms (%u runs)", name, value, runs); auto *test_case = doc.NewElement("testcase"); test_case->SetAttribute("name", name); - test_case->SetAttribute("time", value); + test_case->SetAttribute("time", junit_value); test_case->SetAttribute("runs", runs); + test_case->SetAttribute("classname", "KasmVNC"); test_suit->InsertEndChild(test_case); }; @@ -180,6 +184,10 @@ void SelfBench() { comparer->compare(false, cursorReg); }); + test_suit->SetAttribute("tests", test_cases); + test_suit->SetAttribute("failures", 0); + test_suit->SetAttribute("time", total_time); + doc.SaveFile("SelfBench.xml"); exit(0);