-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import pprint | ||
from run_eval import CompileResult, RunResult | ||
import discord | ||
|
||
|
||
def _limit_length(text: str, maxlen: int): | ||
if len(text) > maxlen: | ||
return text[:maxlen-6] + " [...]" | ||
else: | ||
return text | ||
|
||
|
||
def _send_split_log(thread: discord.Thread, partial_message: str, header: str, log: str): | ||
if len(partial_message) + len(log) + len(header) < 1900: | ||
partial_message += f"\n\n## {header}:\n" | ||
partial_message += f"```\n{log}```" | ||
return partial_message | ||
else: | ||
# send previous chunk | ||
thread.send(partial_message) | ||
lines = log.splitlines() | ||
chunks = [] | ||
partial_message = "" | ||
for line in lines: | ||
if len(partial_message) + len(line) < 1900: | ||
partial_message += line + "\n" | ||
else: | ||
chunks.append(partial_message) | ||
partial_message = line | ||
|
||
# now, format the chunks | ||
for i, chunk in enumerate(chunks): | ||
partial_message += f"\n\n## {header} ({i}/{len(chunks)}):\n" | ||
partial_message += f"```\n{_limit_length(log, 1900)}```" | ||
thread.send(partial_message) | ||
|
||
return "" | ||
|
||
|
||
def generate_report(thread: discord.Thread, comp: CompileResult, run: RunResult): | ||
message = "" | ||
if not comp.success or not run.success: | ||
message = "# Run was not successful\n" | ||
else: | ||
message = "# Run was successful\n" | ||
|
||
if not comp.success: | ||
if not comp.nvcc_found: | ||
message += "**Compilation failed**\nNVCC could not be found.\n" | ||
message += "This indicates a bug in the runner configuration, _not in your code_.\n" | ||
message += "Please notify the server admins of this problem" | ||
thread.send(message) | ||
return | ||
|
||
# ok, we found nvcc | ||
message += "**Compilation failed**\n" | ||
message += "Command " | ||
message += f"```bash\n>{_limit_length(comp.command, 1000)}```\n" | ||
message += f"exited with code **{comp.exit_code}**." | ||
|
||
message += _send_split_log(thread, message, "Compiler stderr", comp.stderr.strip()) | ||
|
||
if len(comp.stdout.strip()) > 0: | ||
message += _send_split_log(thread, message, "Compiler stdout", comp.stdout.strip()) | ||
|
||
if len(message) != 0: | ||
thread.send(message) | ||
|
||
return | ||
|
||
if not run.success: | ||
message += "**Running failed**\n" | ||
message += "Command " | ||
message += f"```bash\n>{_limit_length(run.command, 1000)}```\n" | ||
message += f"exited with error code **{run.exit_code}** after {run.duration} seconds." | ||
|
||
if len(run.stderr.strip()) > 0: | ||
message += _send_split_log(thread, message, "Program stderr", run.stderr.strip()) | ||
|
||
if len(run.stdout.strip()) > 0: | ||
message += _send_split_log(thread, message, "Program stdout", run.stdout.strip()) | ||
|
||
if len(message) != 0: | ||
thread.send(message) | ||
|
||
return | ||
|
||
if not run.passed: | ||
message += "**Testing failed**\n" | ||
message += "Command " | ||
message += f"```bash\n>{_limit_length(run.command, 1000)}```\n" | ||
message += f"ran successfully in {run.duration} seconds, but did not pass all tests.\n" | ||
|
||
if len(run.stderr.strip()) > 0: | ||
message += _send_split_log(thread, message, "Program stderr", run.stderr.strip()) | ||
|
||
if len(run.stdout.strip()) > 0: | ||
message += _send_split_log(thread, message, "Program stdout", run.stdout.strip()) | ||
|
||
if len(message) != 0: | ||
thread.send(message) | ||
|
||
# TODO dedicated "error" entry in our results dict that gets populated by check_implementation | ||
return | ||
|
||
# OK, we were successful | ||
message += "**Success!**\n" | ||
message += _send_split_log(thread, message, "Result", pprint.pformat(run.result)) | ||
|
||
if len(run.stderr.strip()) > 0: | ||
message += _send_split_log(thread, message, "Program stderr", run.stderr).strip() | ||
|
||
if len(run.stdout.strip()) > 0: | ||
message += _send_split_log(thread, message, "Program stdout", run.stdout.strip()) | ||
|
||
if len(message) != 0: | ||
thread.send(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters