Skip to content

Commit 350067c

Browse files
committed
Add testing of maximum size for files generated by solutions.
1 parent 7499924 commit 350067c

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

cmstestsuite/Tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Contest Management System - http://cms-dev.github.io/
55
# Copyright © 2012 Bernard Blackham <bernard@largestprime.net>
66
# Copyright © 2013-2015 Stefano Maggiolo <s.maggiolo@gmail.com>
7-
# Copyright © 2014 Giovanni Mascellani <mascellani@poisson.phc.unipi.it>
7+
# Copyright © 2014-2015 Giovanni Mascellani <mascellani@poisson.phc.unipi.it>
88
#
99
# This program is free software: you can redistribute it and/or modify
1010
# it under the terms of the GNU Affero General Public License as
@@ -235,4 +235,11 @@
235235
languages=(LANG_C,),
236236
checks=[CheckOverallScore(0, 100)]),
237237

238+
# Write a huge file
239+
240+
Test('write-big-fileio',
241+
task=batch_fileio, filename='write-big-fileio.%l',
242+
languages=LANG_C,
243+
checks=[CheckOverallScore(0, 100)]),
244+
238245
]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdio.h>
2+
3+
#include <sys/types.h>
4+
#include <sys/stat.h>
5+
#include <fcntl.h>
6+
#include <unistd.h>
7+
8+
/* First we create a huge file in output.txt (2 GB). If the check on
9+
file size is enforced, the write fails and we write a wrong
10+
output. Otherwise we write correct output. */
11+
12+
int main() {
13+
int n, i;
14+
FILE *in = fopen("input.txt", "r");
15+
fscanf(in, "%d", &n);
16+
17+
// Seek is done in two steps so there are no probles even when
18+
// type off_t is 4 bytes long. In this part everything is done
19+
// calling directly syscalls because apparently libc does not
20+
// properly report EFBIG errors.
21+
int outfd = open("output.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666);
22+
lseek(outfd, 1024 * 1024 * 1024, SEEK_CUR);
23+
lseek(outfd, 1024 * 1024 * 1024, SEEK_CUR);
24+
i = write(outfd, "\0", 1);
25+
close(outfd);
26+
27+
FILE *out = fopen("output.txt", "w");
28+
if (i != 1) {
29+
fprintf(out, "incorrect %d\n", n);
30+
return 1;
31+
} else {
32+
fprintf(out, "correct %d\n", n);
33+
return 0;
34+
}
35+
}

0 commit comments

Comments
 (0)