-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grader): give WA when communicator received signal 13 before wri…
…ting verdict
- Loading branch information
Showing
10 changed files
with
247 additions
and
45 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
22 changes: 22 additions & 0 deletions
22
...src/integTest/resources/engines/interactive/helper/communicator-sigpipe-after-verdict.cpp
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,22 @@ | ||
// This communicator will receive SIGPIPE signal, | ||
// when paired with trigger-communicator-sigpipe.cpp. | ||
|
||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <unistd.h> | ||
|
||
int N; | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
FILE* in = fopen(argv[1], "r"); | ||
fscanf(in, "%d", &N); | ||
|
||
fprintf(stderr, "AC\n"); | ||
|
||
usleep(500 * 1000); | ||
|
||
printf("this output will trigger SIGPIPE signal"); | ||
fflush(stdout); | ||
} |
28 changes: 28 additions & 0 deletions
28
...rc/integTest/resources/engines/interactive/helper/communicator-sigpipe-before-verdict.cpp
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,28 @@ | ||
// This communicator will receive SIGPIPE signal, | ||
// when paired with trigger-communicator-sigpipe.cpp. | ||
|
||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <unistd.h> | ||
|
||
int N; | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
FILE* in = fopen(argv[1], "r"); | ||
fscanf(in, "%d", &N); | ||
|
||
usleep(500 * 1000); | ||
|
||
printf("this output will trigger SIGPIPE signal"); | ||
fflush(stdout); | ||
|
||
// Assume that the communicator never reached the following line, | ||
// because it would have been killed by the sandbox. | ||
|
||
// We must comment this out explicitly, because the fake sandbox | ||
// used in the tests does not actually sandbox the program. | ||
|
||
// fprintf(stderr, "AC\n"); | ||
} |
4 changes: 4 additions & 0 deletions
4
...gines/src/integTest/resources/engines/interactive/source/trigger-communicator-sigpipe.cpp
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,4 @@ | ||
// This solution does nothing to trigger the communicator to receive SIGPIPE signal, | ||
// because this solution would have exited while the communicator is still writing output. | ||
|
||
int main() {} |
34 changes: 34 additions & 0 deletions
34
...r-engines/src/integTest/resources/engines/interactive/source/trigger-solution-sigpipe.cpp
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,34 @@ | ||
#include <cstdio> | ||
#include <cstring> | ||
#include <unistd.h> | ||
|
||
char response[100]; | ||
|
||
int main() | ||
{ | ||
int lo = 1, hi = 1000; | ||
while (lo <= hi) | ||
{ | ||
int mid = (lo + hi) / 2; | ||
printf("%d\n", mid); | ||
fflush(stdout); | ||
|
||
fprintf(stderr, "debug"); | ||
fflush(stderr); | ||
|
||
scanf("%s", response); | ||
|
||
if (!strcmp(response, "too_low")) | ||
lo = mid+1; | ||
else | ||
hi = mid-1; | ||
} | ||
|
||
// At this point, the communicator will have exited | ||
// with AC verdict. | ||
|
||
usleep(500 * 1000); | ||
|
||
printf("this output will trigger SIGPIPE signal"); | ||
fflush(stdout); | ||
} |
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
Oops, something went wrong.