Skip to content

Commit

Permalink
improve fix for major bug with unflushed stdio
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-taylor committed Jul 26, 2019
1 parent 4168231 commit 36d87e8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 22 deletions.
1 change: 1 addition & 0 deletions dcc_check_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions dcc_dual_sanitizers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions explain_output_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions tests/check_output/simple_check_output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
80 changes: 64 additions & 16 deletions tests/expected_output/default/simple_check_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<deleted-hexadecimal-constant>) in tmp.c at line 2:

#include <stdio.h>
-->int main(int argc, char *argv[]) {printf("%s", argv[1]);return 0;}

Values when execution stopped:

argc = <deleted-value>
argv[1] = <deleted-value>
*** 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<deleted-hexadecimal-constant>) in tmp.c at line 2:

#include <stdio.h>
-->int main(int argc, char *argv[]) {printf("%s", argv[1]);return 0;}

Values when execution stopped:

argc = <deleted-value>
argv[1] = <deleted-value>
*** 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!

Expand All @@ -44,7 +92,7 @@ Values when execution stopped:

argc = <deleted-value>
argv[1] = <deleted-value>
*** Test 5 - extra-new-line-1-fail
*** Test 7 - extra-new-line-1-fail
*** Test Environment
expected output: Hello!

Expand All @@ -65,14 +113,14 @@ Values when execution stopped:

argc = <deleted-value>
argv[1] = <deleted-value>
*** 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!

Expand All @@ -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!

Expand All @@ -106,13 +154,13 @@ Values when execution stopped:

argc = <deleted-value>
argv[1] = <deleted-value>
*** 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!

Expand All @@ -135,19 +183,19 @@ Values when execution stopped:

argc = <deleted-value>
argv[1] = <deleted-value>
*** 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!

Expand All @@ -171,13 +219,13 @@ Values when execution stopped:

argc = <deleted-value>
argv[1] = <deleted-value>
*** 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!

Expand All @@ -200,13 +248,13 @@ Values when execution stopped:

argc = <deleted-value>
argv[1] = <deleted-value>
*** 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!

Expand All @@ -229,7 +277,7 @@ Values when execution stopped:

argc = <deleted-value>
argv[1] = <deleted-value>
*** 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!

Expand Down

0 comments on commit 36d87e8

Please sign in to comment.