Skip to content

Commit e3a3936

Browse files
authored
Merge pull request #50 from Slime-Dev/ConvertJsonToImage
Improved image layout
2 parents 5542513 + 554d922 commit e3a3936

File tree

3 files changed

+66
-88
lines changed

3 files changed

+66
-88
lines changed

.gitignore

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,9 @@ bin/
8585
obj/
8686
*.spv
8787
_deps/
88-
scripts/ctestOutput.xml
8988

90-
scripts/discord.json
9189

92-
scripts/output.json
93-
94-
scripts/testimage.png
95-
96-
Testing/Temporary/
90+
# Ignore objects created for local testing
91+
scripts/
92+
# Do not ignore the python script
93+
!/scripts/OutPutResultsToJsons.py

SlimeTests/ShaderLoading.cpp

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,7 @@
66
#include "ResourcePathManager.h"
77
#include <spdlog/spdlog.h>
88

9-
struct TestResult {
10-
std::string testName;
11-
bool passed;
12-
std::string errorMessage;
13-
};
14-
15-
TestResult RunTest(const std::string& testName, std::function<void(ShaderManager& shaderManager)> testFunction) {
16-
ShaderManager shaderManager = ShaderManager();
17-
try {
18-
testFunction(shaderManager);
19-
return { testName, true, "" };
20-
} catch (const std::exception& e) {
21-
return { testName, false, e.what() };
22-
} catch (...) {
23-
return { testName, false, "Unknown exception occurred" };
24-
}
25-
}
26-
27-
void BasicVert(ShaderManager& shaderManager)
28-
{
29-
ResourcePathManager resourcePathManager = ResourcePathManager();
30-
auto basicFrag = shaderManager.LoadShader(vkb::DispatchTable(), resourcePathManager.GetShaderPath("basic.vert.spv"), VK_SHADER_STAGE_VERTEX_BIT);
31-
if (basicFrag.handle != nullptr) {
32-
throw std::runtime_error("Failed to load shader");
33-
}
34-
}
35-
369
int main() {
37-
std::vector<TestResult> testResults;
38-
testResults.push_back(RunTest("Load Basic Vert", BasicVert));
39-
40-
bool allPassed = true;
41-
for (const auto& result : testResults) {
42-
if (result.passed) {
43-
spdlog::info("Test '{}' passed.", result.testName);
44-
} else {
45-
spdlog::error("Test '{}' failed with error: {}", result.testName, result.errorMessage);
46-
allPassed = false;
47-
}
48-
}
49-
50-
if (allPassed) {
51-
spdlog::info("All Tests Passed!");
52-
return 0;
53-
} else {
54-
spdlog::error("Some Tests Failed.");
55-
return 1;
56-
}
10+
spdlog::error("This is a test error msg");
11+
return 1;
5712
}

scripts/OutPutResultsToJsons.py

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -161,42 +161,45 @@ def json_to_discord_json(json_data, os_name, compiler, event, author, branch):
161161
return discord_json
162162

163163
def parse_test_results_from_file(file_path):
164-
# Read the XML data from the file
165-
with open(file_path, 'r', encoding='utf-8') as file:
166-
xml_data = file.read()
167-
168-
# Parse the XML data
169-
root = ET.fromstring(xml_data)
170-
171-
# Extract test suite information
172-
test_suite_name = root.attrib.get('name', 'Test Suite')
173-
tests = root.attrib.get('tests', '0')
174-
failures = root.attrib.get('failures', '0')
175-
skipped = root.attrib.get('skipped', '0')
176-
177-
# Initialize the total time
178-
total_time = 0.0
164+
tree = ET.parse(file_path)
165+
root = tree.getroot()
166+
test_suite_name = root.attrib['name']
167+
tests = int(root.attrib['tests'])
168+
failures = int(root.attrib['failures'])
169+
skipped = int(root.attrib['skipped'])
170+
total_time = float(root.attrib['time'])
179171

180-
# Extract test case information
181172
test_cases = []
173+
failed_cases = []
182174
for testcase in root.findall('testcase'):
183-
name = testcase.attrib.get('name')
184-
time = float(testcase.attrib.get('time', '0'))
185-
status = 'passed' if testcase.find('failure') is None else 'failed'
186-
test_cases.append((name, status, time))
175+
name = testcase.attrib['name']
176+
time = float(testcase.attrib['time'])
177+
status = 'passed'
178+
error_message = None
187179

188-
# Accumulate total time
189-
total_time += time
180+
failure = testcase.find('failure')
181+
if failure is not None:
182+
status = 'failed'
183+
error_message = failure.attrib.get('message', '') + ' ' + testcase.find('system-out').text.strip()
184+
failed_cases.append((name, error_message))
190185

191-
return test_suite_name, tests, failures, skipped, total_time, test_cases
186+
test_cases.append((name, status, time, error_message))
192187

188+
return test_suite_name, tests, failures, skipped, total_time, test_cases, failed_cases
193189

194-
def create_dark_theme_test_results_image(file_path, os, compiler):
190+
def create_horizontal_test_results_image(file_path, os, compiler, event, author, brach):
195191
# Parse the XML data from the file
196-
test_suite_name, tests, failures, skipped, total_time, test_cases = parse_test_results_from_file(file_path)
192+
test_suite_name, tests, failures, skipped, total_time, test_cases, failed_cases = parse_test_results_from_file(file_path)
193+
194+
# Set height depending if there are failed tests
195+
default_height = 0
196+
if failures > 0:
197+
default_height = 250
198+
else:
199+
default_height = 150
197200

198201
# Set up image
199-
width, height = 500, 350
202+
width, height = 800, default_height + (25 * len(test_cases)) + (25 * len(failed_cases)) # Adjust height based on number of test cases and failed cases
200203
background_color = (45, 47, 49) # Dark gray
201204
image = Image.new('RGB', (width, height), color=background_color)
202205
draw = ImageDraw.Draw(image)
@@ -227,11 +230,20 @@ def create_dark_theme_test_results_image(file_path, os, compiler):
227230
# Draw title
228231
draw.text((20, 20), "Test Results", font=title_font, fill=white)
229232

233+
x = 200
234+
# Add the trigger details
235+
draw.text((x, 30), f"Author: {author}", font=body_font, fill=white)
236+
x += 150
237+
draw.text((x, 30), f"Event: {event}", font=body_font, fill=white)
238+
x += 150
239+
draw.text((x, 30), f"Branch: {brach}", font=body_font, fill=white)
230240
# Hard set the suite name
231241
test_suite_name = f"{os}-{compiler}"
232242

233243
# Draw test suite information
234244
y = 60
245+
draw.text((20, y), f"Details", font=header_font, fill=white)
246+
y += 40
235247
draw.text((20, y), f"Test Suite: {test_suite_name}", font=body_font, fill=white)
236248
y += 25
237249
draw.text((20, y), f"Total Tests: {tests}", font=body_font, fill=white)
@@ -241,16 +253,30 @@ def create_dark_theme_test_results_image(file_path, os, compiler):
241253
draw.text((20, y), f"Skipped: {skipped}", font=body_font, fill=light_gray)
242254
y += 25
243255
draw.text((20, y), f"Duration: {total_time:.6f}", font=body_font, fill=light_gray)
244-
y += 40
256+
257+
if failures > 0:
258+
# Draw failed test summary header
259+
y += 40
260+
draw.text((20, y), "Failed Test Summary", font=header_font, fill=white)
261+
262+
# Draw failed test cases
263+
y += 30
264+
for name, error_message in failed_cases:
265+
draw.text((20, y), name, font=body_font, fill=white)
266+
y += 25
267+
draw.text((20, y), error_message, font=body_font, fill=red)
268+
y += 25
269+
270+
# Draw detailed test results header
271+
draw.text((400, 60), "Detailed Test Results", font=header_font, fill=white)
245272

246273
# Draw test cases
247-
draw.text((20, y), "Detailed Test Results", font=header_font, fill=white)
248-
y += 30
249-
for name, status, duration in test_cases:
250-
draw.text((20, y), name, font=body_font, fill=white)
274+
y = 100
275+
for name, status, duration, error_message in test_cases:
276+
draw.text((400, y), name, font=body_font, fill=white)
251277
status_color = green if status == 'passed' else red
252-
draw.text((200, y), status, font=body_font, fill=status_color)
253-
draw.text((280, y), f"{duration:.6f}", font=body_font, fill=light_gray) # Corrected here
278+
draw.text((580, y), status, font=body_font, fill=status_color)
279+
draw.text((660, y), f"{duration:.6f}", font=body_font, fill=light_gray)
254280
y += 25
255281

256282
return image
@@ -296,7 +322,7 @@ def create_dark_theme_test_results_image(file_path, os, compiler):
296322
print(f"Discord JSON output has been written to {discord_json_output_file}")
297323

298324
# Generate data
299-
image = create_dark_theme_test_results_image(args.xml_file, args.os, args.compiler)
325+
image = create_horizontal_test_results_image(args.xml_file, args.os, args.compiler, args.event, args.author, args.branch)
300326

301327
# Create the image
302328
os.makedirs(os.path.dirname(args.image_out), exist_ok=True)

0 commit comments

Comments
 (0)