summaryrefslogtreecommitdiffstats
path: root/src/examples/pfs_reader.c
diff options
context:
space:
mode:
authorFelipe Boeira <felipe.boeira@liu.se>2020-03-04 14:49:23 +0100
committerFelipe Boeira <felipe.boeira@liu.se>2020-03-04 14:49:23 +0100
commitaa02564229d69a16da3d34a3742233aac81fd8b1 (patch)
treec958a2f70d55ae7c3720d28559b3a5448b3f42b2 /src/examples/pfs_reader.c
parenta2730d47f02ddd8c40021bfdd962b986b09fc556 (diff)
downloadpintos-aa02564229d69a16da3d34a3742233aac81fd8b1.tar.gz
Updated tests
Diffstat (limited to 'src/examples/pfs_reader.c')
-rw-r--r--src/examples/pfs_reader.c73
1 files changed, 38 insertions, 35 deletions
diff --git a/src/examples/pfs_reader.c b/src/examples/pfs_reader.c
index 583583a..546b1eb 100644
--- a/src/examples/pfs_reader.c
+++ b/src/examples/pfs_reader.c
@@ -10,39 +10,42 @@ char buffer[BIG];
int main(void)
{
- int bytes, i, j, inconsistency;
- int id, messages;
-
- messages = open("messages");
-
- for (i = 0; i < TIMES; ++i)
- {
- id = open("file.1");
- bytes = read(id, buffer, BIG);
- close(id);
-
- if (bytes != BIG)
- {
- write(messages, "Buffer not filled!\n", 19);
- continue;
- }
- /* now check for consistency */
- for (j = 1, inconsistency = 0; j < BIG; ++j)
- {
- if (buffer[0] != buffer[j])
- {
- /* Ooops, inconsistency */
- write(messages, "INCONSISTENCY.", 14);
- printf("INCONSISTENCY\n");
- inconsistency = 1;
- break; /* no need to check further */
- }
- }
- if (!inconsistency)
- {
- write(messages, "cool\n", 5);
- }
- }
- close(messages);
- exit(0);
+ int bytes, j;
+ int id;
+ int fsize;
+
+ printf("-\n");
+ id = open("file.1");
+
+ fsize = filesize(id);
+ if (fsize < BIG * TIMES) {
+ printf("Invalid filesize\n");
+ close(id);
+ exit(-1);
+ }
+ while (tell(id) <= (fsize-BIG))
+ {
+ bytes = read(id, buffer, BIG);
+
+ if (bytes != BIG)
+ {
+ printf("Buffer not filled, read %d\n", bytes);
+ close(id);
+ exit(-1);
+ }
+ /* now check for consistency */
+ for (j = 1; j < BIG; ++j)
+ {
+ if (buffer[0] != buffer[j])
+ {
+ /* Ooops, inconsistency */
+ printf("INCONSISTENCY\n");
+ close(id);
+ exit(-1);
+ }
+ }
+ }
+ printf("*-\n");
+ close(id);
+ exit(0);
}