From 36d87e8366d2b1449117dfc6e8bc1a50e0b43b01 Mon Sep 17 00:00:00 2001 From: Andrew Taylor Date: Fri, 26 Jul 2019 13:40:55 +1000 Subject: [PATCH] improve fix for major bug with unflushed stdio --- dcc_check_output.c | 1 + dcc_dual_sanitizers.c | 9 ++- explain_output_difference.py | 3 +- tests/check_output/simple_check_output.sh | 2 + .../default/simple_check_output.txt | 80 +++++++++++++++---- 5 files changed, 73 insertions(+), 22 deletions(-) diff --git a/dcc_check_output.c b/dcc_check_output.c index 59701e0..007de22 100644 --- a/dcc_check_output.c +++ b/dcc_check_output.c @@ -7,6 +7,7 @@ static int init_check_output(void) { } static void __dcc_check_output(int fd, const char *buf, size_t size) { + expected_stdout = (unsigned char *)getenv("DCC_EXPECTED_STDOUT"); } static void __dcc_check_close(int fd) { diff --git a/dcc_dual_sanitizers.c b/dcc_dual_sanitizers.c index 22db55a..24defca 100644 --- a/dcc_dual_sanitizers.c +++ b/dcc_dual_sanitizers.c @@ -138,6 +138,7 @@ struct system_call { static int synchronization_terminated; static void disconnect_sanitizers(void) { + debug_printf(2, "disconnect_sanitizers()\n"); if (synchronization_terminated) { return; } @@ -206,8 +207,8 @@ static void stop_sanitizer2(void) { static void synchronization_failed(void) { debug_printf(1, "warning: sanitizer synchronization lost\n"); - if (debug_level > 1) { - debug_printf(2, "sleeping for 3600 seconds because in debug mode\n"); + if (debug_level > 3) { + debug_printf(3, "sleeping for 3600 seconds because in debug mode\n"); sleep(3600); } stop_sanitizer2(); @@ -219,7 +220,7 @@ static void synchronization_failed(void) { static void synchronize_system_call(enum which_system_call which, int64_t n) { debug_printf(3, "synchronize_system_call(%s, %d)\n", system_call_names[which], (int)n); if (synchronization_terminated) { - debug_printf(2, "synchronization_terminated\n"); + debug_printf(2, "synchronize_system_calls - synchronization_terminated\n"); #if __I_AM_SANITIZER2__ __dcc_error_exit(); #endif @@ -261,7 +262,7 @@ static int64_t synchronize_system_call_result(enum which_system_call which , int64_t return_value) { debug_printf(3, "synchronize_system_call_result(%s, %d)\n", system_call_names[which], (int)return_value); if (synchronization_terminated) { - debug_printf(2, "synchronization_terminated\n"); + debug_printf(2, "synchronize_system_call_result - synchronization_terminated\n"); #if __I_AM_SANITIZER2__ __dcc_error_exit(); #endif diff --git a/explain_output_difference.py b/explain_output_difference.py index dc9a093..cef8eb9 100755 --- a/explain_output_difference.py +++ b/explain_output_difference.py @@ -122,11 +122,10 @@ def explain_output_difference1(loc, output_stream, color): print("of an", danger('incorrect output line.'), file=output_stream) print('Byte', actual_column + 1, 'of line', line_number, "of program output was incorrect.", file=output_stream) - if not actual_line[actual_column+1:]: if actual_line.rstrip(b'\n') + expected_byte == expected_line.rstrip(b'\n'): print("A", "'" + danger(sanitize(expected_byte)) + "'", "was missing from the end of the output line.", file=output_stream) - else: + elif actual_column > 1: print("The characters you printed were correct, but more characters were expected.", file=output_stream) print("The correct output line was:", file=output_stream) diff --git a/tests/check_output/simple_check_output.sh b/tests/check_output/simple_check_output.sh index c75a3bc..e7fceaa 100755 --- a/tests/check_output/simple_check_output.sh +++ b/tests/check_output/simple_check_output.sh @@ -43,6 +43,8 @@ function run_test { run_test default-1 "" $'Hello!\n' run_test no-output-1-fail "" $'' +run_test one-byte-missing-fail "" $'Hello\n' +run_test two-bytes-missing-fail "" $'Hell\n' run_test trailing-white-space-1 "" $'Hello! \n' run_test trailing-white-space-2-fail "DCC_IGNORE_TRAILING_WHITE_SPACE=0" $'Hello! \n' diff --git a/tests/expected_output/default/simple_check_output.txt b/tests/expected_output/default/simple_check_output.txt index 7d0a34a..c69c2b6 100644 --- a/tests/expected_output/default/simple_check_output.txt +++ b/tests/expected_output/default/simple_check_output.txt @@ -15,13 +15,61 @@ Execution failed because program produced no output. The first expected line was: Hello! -*** Test 3 - trailing-white-space-1 +*** Test 3 - one-byte-missing-fail +*** Test Environment +expected output: Hello! + +actual output : Hello + + +Execution stopped because of an incorrect output line. +Byte 6 of line 1 of program output was incorrect. +A '!' was missing from the end of the output line. +The correct output line was: +Hello! +Your program printed this line: +Hello + +Execution stopped in main(argc=2, argv=0x) in tmp.c at line 2: + +#include +-->int main(int argc, char *argv[]) {printf("%s", argv[1]);return 0;} + +Values when execution stopped: + +argc = +argv[1] = +*** Test 4 - two-bytes-missing-fail +*** Test Environment +expected output: Hello! + +actual output : Hell + + +Execution stopped because of an incorrect output line. +Byte 5 of line 1 of program output was incorrect. +The characters you printed were correct, but more characters were expected. +The correct output line was: +Hello! +Your program printed this line: +Hell + +Execution stopped in main(argc=2, argv=0x) in tmp.c at line 2: + +#include +-->int main(int argc, char *argv[]) {printf("%s", argv[1]);return 0;} + +Values when execution stopped: + +argc = +argv[1] = +*** Test 5 - trailing-white-space-1 *** Test Environment expected output: Hello! actual output : Hello! -*** Test 4 - trailing-white-space-2-fail +*** Test 6 - trailing-white-space-2-fail *** Test Environment DCC_IGNORE_TRAILING_WHITE_SPACE=0 expected output: Hello! @@ -44,7 +92,7 @@ Values when execution stopped: argc = argv[1] = -*** Test 5 - extra-new-line-1-fail +*** Test 7 - extra-new-line-1-fail *** Test Environment expected output: Hello! @@ -65,14 +113,14 @@ Values when execution stopped: argc = argv[1] = -*** Test 6 - extra-new-line-2 +*** Test 8 - extra-new-line-2 *** Test Environment DCC_IGNORE_EMPTY_LINES=1 expected output: Hello! actual output : Hello! -*** Test 7 - missing-new-line-1-fail +*** Test 9 - missing-new-line-1-fail *** Test Environment expected output: Hello! @@ -83,7 +131,7 @@ Your program produced all the expected output, except the last newline ('\n') wa For more information go to https://comp1511unsw.github.io/dcc/missing_newline.html -*** Test 8 - ignore-case-1-fail +*** Test 10 - ignore-case-1-fail *** Test Environment expected output: Hello! @@ -106,13 +154,13 @@ Values when execution stopped: argc = argv[1] = -*** Test 9 - ignore-case-2 +*** Test 11 - ignore-case-2 *** Test Environment DCC_IGNORE_CASE=1 expected output: Hello! actual output : hEllo! -*** Test 10 - ignore-white-space-1-fail +*** Test 12 - ignore-white-space-1-fail *** Test Environment expected output: Hello! @@ -135,19 +183,19 @@ Values when execution stopped: argc = argv[1] = -*** Test 11 - ignore-white-space-2 +*** Test 13 - ignore-white-space-2 *** Test Environment DCC_IGNORE_WHITE_SPACE=1 expected output: Hello! actual output : H ello ! -*** Test 12 - ignore-characters-1 +*** Test 14 - ignore-characters-1 *** Test Environment DCC_IGNORE_CHARACTERS=+ expected output: Hello! actual output : +++Hello!+++ -*** Test 13 - ignore-characters-2-fail +*** Test 15 - ignore-characters-2-fail *** Test Environment DCC_IGNORE_CHARACTERS=lzn expected output: Hello! @@ -171,13 +219,13 @@ Values when execution stopped: argc = argv[1] = -*** Test 14 - ignore-characters-3 +*** Test 16 - ignore-characters-3 *** Test Environment DCC_IGNORE_CHARACTERS=lzno! expected output: Hello! actual output : Hen -*** Test 15 - compare-only-characters-1-fail +*** Test 17 - compare-only-characters-1-fail *** Test Environment DCC_COMPARE_ONLY_CHARACTERS=Hel expected output: Hello! @@ -200,13 +248,13 @@ Values when execution stopped: argc = argv[1] = -*** Test 16 - compare-only-characters-2 +*** Test 18 - compare-only-characters-2 *** Test Environment DCC_COMPARE_ONLY_CHARACTERS=el expected output: Hello! actual output : HiheHilloHi ! -*** Test 17 - compare-only-characters-3-fail +*** Test 19 - compare-only-characters-3-fail *** Test Environment DCC_COMPARE_ONLY_CHARACTERS=hel expected output: Hello! @@ -229,7 +277,7 @@ Values when execution stopped: argc = argv[1] = -*** Test 18 - compare-only-characters-4 +*** Test 20 - compare-only-characters-4 *** Test Environment DCC_IGNORE_CASE=1 DCC_COMPARE_ONLY_CHARACTERS=hel expected output: Hello!