Skip to content

Commit 36d87e8

Browse files
committed
improve fix for major bug with unflushed stdio
1 parent 4168231 commit 36d87e8

File tree

5 files changed

+73
-22
lines changed

5 files changed

+73
-22
lines changed

dcc_check_output.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ static int init_check_output(void) {
77
}
88

99
static void __dcc_check_output(int fd, const char *buf, size_t size) {
10+
expected_stdout = (unsigned char *)getenv("DCC_EXPECTED_STDOUT");
1011
}
1112

1213
static void __dcc_check_close(int fd) {

dcc_dual_sanitizers.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ struct system_call {
138138
static int synchronization_terminated;
139139

140140
static void disconnect_sanitizers(void) {
141+
debug_printf(2, "disconnect_sanitizers()\n");
141142
if (synchronization_terminated) {
142143
return;
143144
}
@@ -206,8 +207,8 @@ static void stop_sanitizer2(void) {
206207

207208
static void synchronization_failed(void) {
208209
debug_printf(1, "warning: sanitizer synchronization lost\n");
209-
if (debug_level > 1) {
210-
debug_printf(2, "sleeping for 3600 seconds because in debug mode\n");
210+
if (debug_level > 3) {
211+
debug_printf(3, "sleeping for 3600 seconds because in debug mode\n");
211212
sleep(3600);
212213
}
213214
stop_sanitizer2();
@@ -219,7 +220,7 @@ static void synchronization_failed(void) {
219220
static void synchronize_system_call(enum which_system_call which, int64_t n) {
220221
debug_printf(3, "synchronize_system_call(%s, %d)\n", system_call_names[which], (int)n);
221222
if (synchronization_terminated) {
222-
debug_printf(2, "synchronization_terminated\n");
223+
debug_printf(2, "synchronize_system_calls - synchronization_terminated\n");
223224
#if __I_AM_SANITIZER2__
224225
__dcc_error_exit();
225226
#endif
@@ -261,7 +262,7 @@ static int64_t synchronize_system_call_result(enum which_system_call which
261262
, int64_t return_value) {
262263
debug_printf(3, "synchronize_system_call_result(%s, %d)\n", system_call_names[which], (int)return_value);
263264
if (synchronization_terminated) {
264-
debug_printf(2, "synchronization_terminated\n");
265+
debug_printf(2, "synchronize_system_call_result - synchronization_terminated\n");
265266
#if __I_AM_SANITIZER2__
266267
__dcc_error_exit();
267268
#endif

explain_output_difference.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ def explain_output_difference1(loc, output_stream, color):
122122

123123
print("of an", danger('incorrect output line.'), file=output_stream)
124124
print('Byte', actual_column + 1, 'of line', line_number, "of program output was incorrect.", file=output_stream)
125-
126125
if not actual_line[actual_column+1:]:
127126
if actual_line.rstrip(b'\n') + expected_byte == expected_line.rstrip(b'\n'):
128127
print("A", "'" + danger(sanitize(expected_byte)) + "'", "was missing from the end of the output line.", file=output_stream)
129-
else:
128+
elif actual_column > 1:
130129
print("The characters you printed were correct, but more characters were expected.", file=output_stream)
131130

132131
print("The correct output line was:", file=output_stream)

tests/check_output/simple_check_output.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function run_test {
4343
run_test default-1 "" $'Hello!\n'
4444

4545
run_test no-output-1-fail "" $''
46+
run_test one-byte-missing-fail "" $'Hello\n'
47+
run_test two-bytes-missing-fail "" $'Hell\n'
4648

4749
run_test trailing-white-space-1 "" $'Hello! \n'
4850
run_test trailing-white-space-2-fail "DCC_IGNORE_TRAILING_WHITE_SPACE=0" $'Hello! \n'

tests/expected_output/default/simple_check_output.txt

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,61 @@ Execution failed because program produced no output.
1515
The first expected line was:
1616
Hello!
1717

18-
*** Test 3 - trailing-white-space-1
18+
*** Test 3 - one-byte-missing-fail
19+
*** Test Environment
20+
expected output: Hello!
21+
22+
actual output : Hello
23+
24+
25+
Execution stopped because of an incorrect output line.
26+
Byte 6 of line 1 of program output was incorrect.
27+
A '!' was missing from the end of the output line.
28+
The correct output line was:
29+
Hello!
30+
Your program printed this line:
31+
Hello
32+
33+
Execution stopped in main(argc=2, argv=0x<deleted-hexadecimal-constant>) in tmp.c at line 2:
34+
35+
#include <stdio.h>
36+
-->int main(int argc, char *argv[]) {printf("%s", argv[1]);return 0;}
37+
38+
Values when execution stopped:
39+
40+
argc = <deleted-value>
41+
argv[1] = <deleted-value>
42+
*** Test 4 - two-bytes-missing-fail
43+
*** Test Environment
44+
expected output: Hello!
45+
46+
actual output : Hell
47+
48+
49+
Execution stopped because of an incorrect output line.
50+
Byte 5 of line 1 of program output was incorrect.
51+
The characters you printed were correct, but more characters were expected.
52+
The correct output line was:
53+
Hello!
54+
Your program printed this line:
55+
Hell
56+
57+
Execution stopped in main(argc=2, argv=0x<deleted-hexadecimal-constant>) in tmp.c at line 2:
58+
59+
#include <stdio.h>
60+
-->int main(int argc, char *argv[]) {printf("%s", argv[1]);return 0;}
61+
62+
Values when execution stopped:
63+
64+
argc = <deleted-value>
65+
argv[1] = <deleted-value>
66+
*** Test 5 - trailing-white-space-1
1967
*** Test Environment
2068
expected output: Hello!
2169

2270
actual output : Hello!
2371

24-
*** Test 4 - trailing-white-space-2-fail
72+
*** Test 6 - trailing-white-space-2-fail
2573
*** Test Environment DCC_IGNORE_TRAILING_WHITE_SPACE=0
2674
expected output: Hello!
2775

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

4593
argc = <deleted-value>
4694
argv[1] = <deleted-value>
47-
*** Test 5 - extra-new-line-1-fail
95+
*** Test 7 - extra-new-line-1-fail
4896
*** Test Environment
4997
expected output: Hello!
5098

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

66114
argc = <deleted-value>
67115
argv[1] = <deleted-value>
68-
*** Test 6 - extra-new-line-2
116+
*** Test 8 - extra-new-line-2
69117
*** Test Environment DCC_IGNORE_EMPTY_LINES=1
70118
expected output: Hello!
71119

72120
actual output : Hello!
73121

74122

75-
*** Test 7 - missing-new-line-1-fail
123+
*** Test 9 - missing-new-line-1-fail
76124
*** Test Environment
77125
expected output: Hello!
78126

@@ -83,7 +131,7 @@ Your program produced all the expected output, except the last newline ('\n') wa
83131

84132
For more information go to https://comp1511unsw.github.io/dcc/missing_newline.html
85133

86-
*** Test 8 - ignore-case-1-fail
134+
*** Test 10 - ignore-case-1-fail
87135
*** Test Environment
88136
expected output: Hello!
89137

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

107155
argc = <deleted-value>
108156
argv[1] = <deleted-value>
109-
*** Test 9 - ignore-case-2
157+
*** Test 11 - ignore-case-2
110158
*** Test Environment DCC_IGNORE_CASE=1
111159
expected output: Hello!
112160

113161
actual output : hEllo!
114162

115-
*** Test 10 - ignore-white-space-1-fail
163+
*** Test 12 - ignore-white-space-1-fail
116164
*** Test Environment
117165
expected output: Hello!
118166

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

136184
argc = <deleted-value>
137185
argv[1] = <deleted-value>
138-
*** Test 11 - ignore-white-space-2
186+
*** Test 13 - ignore-white-space-2
139187
*** Test Environment DCC_IGNORE_WHITE_SPACE=1
140188
expected output: Hello!
141189

142190
actual output : H ello !
143191

144-
*** Test 12 - ignore-characters-1
192+
*** Test 14 - ignore-characters-1
145193
*** Test Environment DCC_IGNORE_CHARACTERS=+
146194
expected output: Hello!
147195

148196
actual output : +++Hello!+++
149197

150-
*** Test 13 - ignore-characters-2-fail
198+
*** Test 15 - ignore-characters-2-fail
151199
*** Test Environment DCC_IGNORE_CHARACTERS=lzn
152200
expected output: Hello!
153201

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

172220
argc = <deleted-value>
173221
argv[1] = <deleted-value>
174-
*** Test 14 - ignore-characters-3
222+
*** Test 16 - ignore-characters-3
175223
*** Test Environment DCC_IGNORE_CHARACTERS=lzno!
176224
expected output: Hello!
177225

178226
actual output : Hen
179227

180-
*** Test 15 - compare-only-characters-1-fail
228+
*** Test 17 - compare-only-characters-1-fail
181229
*** Test Environment DCC_COMPARE_ONLY_CHARACTERS=Hel
182230
expected output: Hello!
183231

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

201249
argc = <deleted-value>
202250
argv[1] = <deleted-value>
203-
*** Test 16 - compare-only-characters-2
251+
*** Test 18 - compare-only-characters-2
204252
*** Test Environment DCC_COMPARE_ONLY_CHARACTERS=el
205253
expected output: Hello!
206254

207255
actual output : HiheHilloHi !
208256

209-
*** Test 17 - compare-only-characters-3-fail
257+
*** Test 19 - compare-only-characters-3-fail
210258
*** Test Environment DCC_COMPARE_ONLY_CHARACTERS=hel
211259
expected output: Hello!
212260

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

230278
argc = <deleted-value>
231279
argv[1] = <deleted-value>
232-
*** Test 18 - compare-only-characters-4
280+
*** Test 20 - compare-only-characters-4
233281
*** Test Environment DCC_IGNORE_CASE=1 DCC_COMPARE_ONLY_CHARACTERS=hel
234282
expected output: Hello!
235283

0 commit comments

Comments
 (0)