provided code
This commit is contained in:
18
src/tests/filesys/base/Make.tests
Normal file
18
src/tests/filesys/base/Make.tests
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- makefile -*-
|
||||
|
||||
tests/filesys/base_TESTS = $(addprefix tests/filesys/base/,lg-create \
|
||||
lg-full lg-random lg-seq-block lg-seq-random sm-create sm-full \
|
||||
sm-random sm-seq-block sm-seq-random syn-read syn-remove syn-write)
|
||||
|
||||
tests/filesys/base_PROGS = $(tests/filesys/base_TESTS) $(addprefix \
|
||||
tests/filesys/base/,child-syn-read child-syn-wrt)
|
||||
|
||||
$(foreach prog,$(tests/filesys/base_PROGS), \
|
||||
$(eval $(prog)_SRC += $(prog).c tests/lib.c tests/filesys/seq-test.c))
|
||||
$(foreach prog,$(tests/filesys/base_TESTS), \
|
||||
$(eval $(prog)_SRC += tests/main.c))
|
||||
|
||||
tests/filesys/base/syn-read_PUTFILES = tests/filesys/base/child-syn-read
|
||||
tests/filesys/base/syn-write_PUTFILES = tests/filesys/base/child-syn-wrt
|
||||
|
||||
tests/filesys/base/syn-read.output: TIMEOUT = 300
|
||||
19
src/tests/filesys/base/Rubric
Normal file
19
src/tests/filesys/base/Rubric
Normal file
@@ -0,0 +1,19 @@
|
||||
Functionality of base file system:
|
||||
- Test basic support for small files.
|
||||
1 sm-create
|
||||
2 sm-full
|
||||
2 sm-random
|
||||
2 sm-seq-block
|
||||
3 sm-seq-random
|
||||
|
||||
- Test basic support for large files.
|
||||
1 lg-create
|
||||
2 lg-full
|
||||
2 lg-random
|
||||
2 lg-seq-block
|
||||
3 lg-seq-random
|
||||
|
||||
- Test synchronized multiprogram access to files.
|
||||
4 syn-read
|
||||
4 syn-write
|
||||
2 syn-remove
|
||||
44
src/tests/filesys/base/child-syn-read.c
Normal file
44
src/tests/filesys/base/child-syn-read.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* Child process for syn-read test.
|
||||
Reads the contents of a test file a byte at a time, in the
|
||||
hope that this will take long enough that we can get a
|
||||
significant amount of contention in the kernel file system
|
||||
code. */
|
||||
|
||||
#include <random.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <syscall.h>
|
||||
#include "tests/lib.h"
|
||||
#include "tests/filesys/base/syn-read.h"
|
||||
|
||||
const char *test_name = "child-syn-read";
|
||||
|
||||
static char buf[BUF_SIZE];
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
{
|
||||
int child_idx;
|
||||
int fd;
|
||||
size_t i;
|
||||
|
||||
quiet = true;
|
||||
|
||||
CHECK (argc == 2, "argc must be 2, actually %d", argc);
|
||||
child_idx = atoi (argv[1]);
|
||||
|
||||
random_init (0);
|
||||
random_bytes (buf, sizeof buf);
|
||||
|
||||
CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
|
||||
for (i = 0; i < sizeof buf; i++)
|
||||
{
|
||||
char c;
|
||||
CHECK (read (fd, &c, 1) > 0, "read \"%s\"", file_name);
|
||||
compare_bytes (&c, buf + i, 1, i, file_name);
|
||||
}
|
||||
close (fd);
|
||||
|
||||
return child_idx;
|
||||
}
|
||||
|
||||
35
src/tests/filesys/base/child-syn-wrt.c
Normal file
35
src/tests/filesys/base/child-syn-wrt.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* Child process for syn-read test.
|
||||
Writes into part of a test file. Other processes will be
|
||||
writing into other parts at the same time. */
|
||||
|
||||
#include <random.h>
|
||||
#include <stdlib.h>
|
||||
#include <syscall.h>
|
||||
#include "tests/lib.h"
|
||||
#include "tests/filesys/base/syn-write.h"
|
||||
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int child_idx;
|
||||
int fd;
|
||||
|
||||
quiet = true;
|
||||
|
||||
CHECK (argc == 2, "argc must be 2, actually %d", argc);
|
||||
child_idx = atoi (argv[1]);
|
||||
|
||||
random_init (0);
|
||||
random_bytes (buf, sizeof buf);
|
||||
|
||||
CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
|
||||
seek (fd, CHUNK_SIZE * (unsigned) child_idx);
|
||||
CHECK (write (fd, buf + CHUNK_SIZE * (unsigned) child_idx, CHUNK_SIZE) > 0,
|
||||
"write \"%s\"", file_name);
|
||||
msg ("close \"%s\"", file_name);
|
||||
close (fd);
|
||||
|
||||
return child_idx;
|
||||
}
|
||||
20
src/tests/filesys/base/full.inc
Normal file
20
src/tests/filesys/base/full.inc
Normal file
@@ -0,0 +1,20 @@
|
||||
/* -*- c -*- */
|
||||
|
||||
#include "tests/filesys/seq-test.h"
|
||||
#include "tests/main.h"
|
||||
|
||||
static char buf[TEST_SIZE];
|
||||
|
||||
static size_t
|
||||
return_test_size (void)
|
||||
{
|
||||
return TEST_SIZE;
|
||||
}
|
||||
|
||||
void
|
||||
test_main (void)
|
||||
{
|
||||
seq_test ("quux",
|
||||
buf, sizeof buf, sizeof buf,
|
||||
return_test_size, NULL);
|
||||
}
|
||||
5
src/tests/filesys/base/lg-create.c
Normal file
5
src/tests/filesys/base/lg-create.c
Normal file
@@ -0,0 +1,5 @@
|
||||
/* Tests that create properly zeros out the contents of a fairly
|
||||
large file. */
|
||||
|
||||
#define TEST_SIZE 75678
|
||||
#include "tests/filesys/create.inc"
|
||||
13
src/tests/filesys/base/lg-create.ck
Normal file
13
src/tests/filesys/base/lg-create.ck
Normal file
@@ -0,0 +1,13 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(lg-create) begin
|
||||
(lg-create) create "blargle"
|
||||
(lg-create) open "blargle" for verification
|
||||
(lg-create) verified contents of "blargle"
|
||||
(lg-create) close "blargle"
|
||||
(lg-create) end
|
||||
EOF
|
||||
pass;
|
||||
6
src/tests/filesys/base/lg-full.c
Normal file
6
src/tests/filesys/base/lg-full.c
Normal file
@@ -0,0 +1,6 @@
|
||||
/* Writes out the contents of a fairly large file all at once,
|
||||
and then reads it back to make sure that it was written
|
||||
properly. */
|
||||
|
||||
#define TEST_SIZE 75678
|
||||
#include "tests/filesys/base/full.inc"
|
||||
16
src/tests/filesys/base/lg-full.ck
Normal file
16
src/tests/filesys/base/lg-full.ck
Normal file
@@ -0,0 +1,16 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(lg-full) begin
|
||||
(lg-full) create "quux"
|
||||
(lg-full) open "quux"
|
||||
(lg-full) writing "quux"
|
||||
(lg-full) close "quux"
|
||||
(lg-full) open "quux" for verification
|
||||
(lg-full) verified contents of "quux"
|
||||
(lg-full) close "quux"
|
||||
(lg-full) end
|
||||
EOF
|
||||
pass;
|
||||
7
src/tests/filesys/base/lg-random.c
Normal file
7
src/tests/filesys/base/lg-random.c
Normal file
@@ -0,0 +1,7 @@
|
||||
/* Writes out the content of a fairly large file in random order,
|
||||
then reads it back in random order to verify that it was
|
||||
written properly. */
|
||||
|
||||
#define BLOCK_SIZE 512U
|
||||
#define TEST_SIZE (512 * 150)
|
||||
#include "tests/filesys/base/random.inc"
|
||||
14
src/tests/filesys/base/lg-random.ck
Normal file
14
src/tests/filesys/base/lg-random.ck
Normal file
@@ -0,0 +1,14 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(lg-random) begin
|
||||
(lg-random) create "bazzle"
|
||||
(lg-random) open "bazzle"
|
||||
(lg-random) write "bazzle" in random order
|
||||
(lg-random) read "bazzle" in random order
|
||||
(lg-random) close "bazzle"
|
||||
(lg-random) end
|
||||
EOF
|
||||
pass;
|
||||
7
src/tests/filesys/base/lg-seq-block.c
Normal file
7
src/tests/filesys/base/lg-seq-block.c
Normal file
@@ -0,0 +1,7 @@
|
||||
/* Writes out a fairly large file sequentially, one fixed-size
|
||||
block at a time, then reads it back to verify that it was
|
||||
written properly. */
|
||||
|
||||
#define TEST_SIZE 75678
|
||||
#define BLOCK_SIZE 513
|
||||
#include "tests/filesys/base/seq-block.inc"
|
||||
16
src/tests/filesys/base/lg-seq-block.ck
Normal file
16
src/tests/filesys/base/lg-seq-block.ck
Normal file
@@ -0,0 +1,16 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(lg-seq-block) begin
|
||||
(lg-seq-block) create "noodle"
|
||||
(lg-seq-block) open "noodle"
|
||||
(lg-seq-block) writing "noodle"
|
||||
(lg-seq-block) close "noodle"
|
||||
(lg-seq-block) open "noodle" for verification
|
||||
(lg-seq-block) verified contents of "noodle"
|
||||
(lg-seq-block) close "noodle"
|
||||
(lg-seq-block) end
|
||||
EOF
|
||||
pass;
|
||||
6
src/tests/filesys/base/lg-seq-random.c
Normal file
6
src/tests/filesys/base/lg-seq-random.c
Normal file
@@ -0,0 +1,6 @@
|
||||
/* Writes out a fairly large file sequentially, one random-sized
|
||||
block at a time, then reads it back to verify that it was
|
||||
written properly. */
|
||||
|
||||
#define TEST_SIZE 75678
|
||||
#include "tests/filesys/base/seq-random.inc"
|
||||
16
src/tests/filesys/base/lg-seq-random.ck
Normal file
16
src/tests/filesys/base/lg-seq-random.ck
Normal file
@@ -0,0 +1,16 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(lg-seq-random) begin
|
||||
(lg-seq-random) create "nibble"
|
||||
(lg-seq-random) open "nibble"
|
||||
(lg-seq-random) writing "nibble"
|
||||
(lg-seq-random) close "nibble"
|
||||
(lg-seq-random) open "nibble" for verification
|
||||
(lg-seq-random) verified contents of "nibble"
|
||||
(lg-seq-random) close "nibble"
|
||||
(lg-seq-random) end
|
||||
EOF
|
||||
pass;
|
||||
59
src/tests/filesys/base/random.inc
Normal file
59
src/tests/filesys/base/random.inc
Normal file
@@ -0,0 +1,59 @@
|
||||
/* -*- c -*- */
|
||||
|
||||
#include <random.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syscall.h>
|
||||
#include "tests/lib.h"
|
||||
#include "tests/main.h"
|
||||
|
||||
#if TEST_SIZE % BLOCK_SIZE != 0
|
||||
#error TEST_SIZE must be a multiple of BLOCK_SIZE
|
||||
#endif
|
||||
|
||||
#define BLOCK_CNT (TEST_SIZE / BLOCK_SIZE)
|
||||
|
||||
char buf[TEST_SIZE];
|
||||
int order[BLOCK_CNT];
|
||||
|
||||
void
|
||||
test_main (void)
|
||||
{
|
||||
const char *file_name = "bazzle";
|
||||
int fd;
|
||||
size_t i;
|
||||
|
||||
random_init (57);
|
||||
random_bytes (buf, sizeof buf);
|
||||
|
||||
for (i = 0; i < BLOCK_CNT; i++)
|
||||
order[i] = (int) i;
|
||||
|
||||
CHECK (create (file_name, TEST_SIZE), "create \"%s\"", file_name);
|
||||
CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
|
||||
|
||||
msg ("write \"%s\" in random order", file_name);
|
||||
shuffle (order, BLOCK_CNT, sizeof *order);
|
||||
for (i = 0; i < BLOCK_CNT; i++)
|
||||
{
|
||||
size_t ofs = BLOCK_SIZE * (unsigned) order[i];
|
||||
seek (fd, ofs);
|
||||
if (write (fd, buf + ofs, BLOCK_SIZE) != BLOCK_SIZE)
|
||||
fail ("write %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
|
||||
}
|
||||
|
||||
msg ("read \"%s\" in random order", file_name);
|
||||
shuffle (order, BLOCK_CNT, sizeof *order);
|
||||
for (i = 0; i < BLOCK_CNT; i++)
|
||||
{
|
||||
char block[BLOCK_SIZE];
|
||||
size_t ofs = BLOCK_SIZE * (unsigned) order[i];
|
||||
seek (fd, ofs);
|
||||
if (read (fd, block, BLOCK_SIZE) != BLOCK_SIZE)
|
||||
fail ("read %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs);
|
||||
compare_bytes (block, buf + ofs, BLOCK_SIZE, ofs, file_name);
|
||||
}
|
||||
|
||||
msg ("close \"%s\"", file_name);
|
||||
close (fd);
|
||||
}
|
||||
20
src/tests/filesys/base/seq-block.inc
Normal file
20
src/tests/filesys/base/seq-block.inc
Normal file
@@ -0,0 +1,20 @@
|
||||
/* -*- c -*- */
|
||||
|
||||
#include "tests/filesys/seq-test.h"
|
||||
#include "tests/main.h"
|
||||
|
||||
static char buf[TEST_SIZE];
|
||||
|
||||
static size_t
|
||||
return_block_size (void)
|
||||
{
|
||||
return BLOCK_SIZE;
|
||||
}
|
||||
|
||||
void
|
||||
test_main (void)
|
||||
{
|
||||
seq_test ("noodle",
|
||||
buf, sizeof buf, sizeof buf,
|
||||
return_block_size, NULL);
|
||||
}
|
||||
22
src/tests/filesys/base/seq-random.inc
Normal file
22
src/tests/filesys/base/seq-random.inc
Normal file
@@ -0,0 +1,22 @@
|
||||
/* -*- c -*- */
|
||||
|
||||
#include <random.h>
|
||||
#include "tests/filesys/seq-test.h"
|
||||
#include "tests/main.h"
|
||||
|
||||
static char buf[TEST_SIZE];
|
||||
|
||||
static size_t
|
||||
return_random (void)
|
||||
{
|
||||
return random_ulong () % 1031 + 1;
|
||||
}
|
||||
|
||||
void
|
||||
test_main (void)
|
||||
{
|
||||
random_init ( (unsigned) -1);
|
||||
seq_test ("nibble",
|
||||
buf, sizeof buf, sizeof buf,
|
||||
return_random, NULL);
|
||||
}
|
||||
5
src/tests/filesys/base/sm-create.c
Normal file
5
src/tests/filesys/base/sm-create.c
Normal file
@@ -0,0 +1,5 @@
|
||||
/* Tests that create properly zeros out the contents of a fairly
|
||||
small file. */
|
||||
|
||||
#define TEST_SIZE 5678
|
||||
#include "tests/filesys/create.inc"
|
||||
13
src/tests/filesys/base/sm-create.ck
Normal file
13
src/tests/filesys/base/sm-create.ck
Normal file
@@ -0,0 +1,13 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(sm-create) begin
|
||||
(sm-create) create "blargle"
|
||||
(sm-create) open "blargle" for verification
|
||||
(sm-create) verified contents of "blargle"
|
||||
(sm-create) close "blargle"
|
||||
(sm-create) end
|
||||
EOF
|
||||
pass;
|
||||
6
src/tests/filesys/base/sm-full.c
Normal file
6
src/tests/filesys/base/sm-full.c
Normal file
@@ -0,0 +1,6 @@
|
||||
/* Writes out the contents of a fairly small file all at once,
|
||||
and then reads it back to make sure that it was written
|
||||
properly. */
|
||||
|
||||
#define TEST_SIZE 5678
|
||||
#include "tests/filesys/base/full.inc"
|
||||
16
src/tests/filesys/base/sm-full.ck
Normal file
16
src/tests/filesys/base/sm-full.ck
Normal file
@@ -0,0 +1,16 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(sm-full) begin
|
||||
(sm-full) create "quux"
|
||||
(sm-full) open "quux"
|
||||
(sm-full) writing "quux"
|
||||
(sm-full) close "quux"
|
||||
(sm-full) open "quux" for verification
|
||||
(sm-full) verified contents of "quux"
|
||||
(sm-full) close "quux"
|
||||
(sm-full) end
|
||||
EOF
|
||||
pass;
|
||||
7
src/tests/filesys/base/sm-random.c
Normal file
7
src/tests/filesys/base/sm-random.c
Normal file
@@ -0,0 +1,7 @@
|
||||
/* Writes out the content of a fairly small file in random order,
|
||||
then reads it back in random order to verify that it was
|
||||
written properly. */
|
||||
|
||||
#define BLOCK_SIZE 13
|
||||
#define TEST_SIZE (13 * 123)
|
||||
#include "tests/filesys/base/random.inc"
|
||||
14
src/tests/filesys/base/sm-random.ck
Normal file
14
src/tests/filesys/base/sm-random.ck
Normal file
@@ -0,0 +1,14 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(sm-random) begin
|
||||
(sm-random) create "bazzle"
|
||||
(sm-random) open "bazzle"
|
||||
(sm-random) write "bazzle" in random order
|
||||
(sm-random) read "bazzle" in random order
|
||||
(sm-random) close "bazzle"
|
||||
(sm-random) end
|
||||
EOF
|
||||
pass;
|
||||
7
src/tests/filesys/base/sm-seq-block.c
Normal file
7
src/tests/filesys/base/sm-seq-block.c
Normal file
@@ -0,0 +1,7 @@
|
||||
/* Writes out a fairly small file sequentially, one fixed-size
|
||||
block at a time, then reads it back to verify that it was
|
||||
written properly. */
|
||||
|
||||
#define TEST_SIZE 5678
|
||||
#define BLOCK_SIZE 513
|
||||
#include "tests/filesys/base/seq-block.inc"
|
||||
16
src/tests/filesys/base/sm-seq-block.ck
Normal file
16
src/tests/filesys/base/sm-seq-block.ck
Normal file
@@ -0,0 +1,16 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(sm-seq-block) begin
|
||||
(sm-seq-block) create "noodle"
|
||||
(sm-seq-block) open "noodle"
|
||||
(sm-seq-block) writing "noodle"
|
||||
(sm-seq-block) close "noodle"
|
||||
(sm-seq-block) open "noodle" for verification
|
||||
(sm-seq-block) verified contents of "noodle"
|
||||
(sm-seq-block) close "noodle"
|
||||
(sm-seq-block) end
|
||||
EOF
|
||||
pass;
|
||||
6
src/tests/filesys/base/sm-seq-random.c
Normal file
6
src/tests/filesys/base/sm-seq-random.c
Normal file
@@ -0,0 +1,6 @@
|
||||
/* Writes out a fairly large file sequentially, one random-sized
|
||||
block at a time, then reads it back to verify that it was
|
||||
written properly. */
|
||||
|
||||
#define TEST_SIZE 5678
|
||||
#include "tests/filesys/base/seq-random.inc"
|
||||
16
src/tests/filesys/base/sm-seq-random.ck
Normal file
16
src/tests/filesys/base/sm-seq-random.ck
Normal file
@@ -0,0 +1,16 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(sm-seq-random) begin
|
||||
(sm-seq-random) create "nibble"
|
||||
(sm-seq-random) open "nibble"
|
||||
(sm-seq-random) writing "nibble"
|
||||
(sm-seq-random) close "nibble"
|
||||
(sm-seq-random) open "nibble" for verification
|
||||
(sm-seq-random) verified contents of "nibble"
|
||||
(sm-seq-random) close "nibble"
|
||||
(sm-seq-random) end
|
||||
EOF
|
||||
pass;
|
||||
31
src/tests/filesys/base/syn-read.c
Normal file
31
src/tests/filesys/base/syn-read.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* Spawns 10 child processes, all of which read from the same
|
||||
file and make sure that the contents are what they should
|
||||
be. */
|
||||
|
||||
#include <random.h>
|
||||
#include <stdio.h>
|
||||
#include <syscall.h>
|
||||
#include "tests/lib.h"
|
||||
#include "tests/main.h"
|
||||
#include "tests/filesys/base/syn-read.h"
|
||||
|
||||
static char buf[BUF_SIZE];
|
||||
|
||||
#define CHILD_CNT 10
|
||||
|
||||
void
|
||||
test_main (void)
|
||||
{
|
||||
pid_t children[CHILD_CNT];
|
||||
int fd;
|
||||
|
||||
CHECK (create (file_name, sizeof buf), "create \"%s\"", file_name);
|
||||
CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
|
||||
random_bytes (buf, sizeof buf);
|
||||
CHECK (write (fd, buf, sizeof buf) > 0, "write \"%s\"", file_name);
|
||||
msg ("close \"%s\"", file_name);
|
||||
close (fd);
|
||||
|
||||
exec_children ("child-syn-read", children, CHILD_CNT);
|
||||
wait_children (children, CHILD_CNT);
|
||||
}
|
||||
33
src/tests/filesys/base/syn-read.ck
Normal file
33
src/tests/filesys/base/syn-read.ck
Normal file
@@ -0,0 +1,33 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(syn-read) begin
|
||||
(syn-read) create "data"
|
||||
(syn-read) open "data"
|
||||
(syn-read) write "data"
|
||||
(syn-read) close "data"
|
||||
(syn-read) exec child 1 of 10: "child-syn-read 0"
|
||||
(syn-read) exec child 2 of 10: "child-syn-read 1"
|
||||
(syn-read) exec child 3 of 10: "child-syn-read 2"
|
||||
(syn-read) exec child 4 of 10: "child-syn-read 3"
|
||||
(syn-read) exec child 5 of 10: "child-syn-read 4"
|
||||
(syn-read) exec child 6 of 10: "child-syn-read 5"
|
||||
(syn-read) exec child 7 of 10: "child-syn-read 6"
|
||||
(syn-read) exec child 8 of 10: "child-syn-read 7"
|
||||
(syn-read) exec child 9 of 10: "child-syn-read 8"
|
||||
(syn-read) exec child 10 of 10: "child-syn-read 9"
|
||||
(syn-read) wait for child 1 of 10 returned 0 (expected 0)
|
||||
(syn-read) wait for child 2 of 10 returned 1 (expected 1)
|
||||
(syn-read) wait for child 3 of 10 returned 2 (expected 2)
|
||||
(syn-read) wait for child 4 of 10 returned 3 (expected 3)
|
||||
(syn-read) wait for child 5 of 10 returned 4 (expected 4)
|
||||
(syn-read) wait for child 6 of 10 returned 5 (expected 5)
|
||||
(syn-read) wait for child 7 of 10 returned 6 (expected 6)
|
||||
(syn-read) wait for child 8 of 10 returned 7 (expected 7)
|
||||
(syn-read) wait for child 9 of 10 returned 8 (expected 8)
|
||||
(syn-read) wait for child 10 of 10 returned 9 (expected 9)
|
||||
(syn-read) end
|
||||
EOF
|
||||
pass;
|
||||
7
src/tests/filesys/base/syn-read.h
Normal file
7
src/tests/filesys/base/syn-read.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef TESTS_FILESYS_BASE_SYN_READ_H
|
||||
#define TESTS_FILESYS_BASE_SYN_READ_H
|
||||
|
||||
#define BUF_SIZE 1024
|
||||
static const char file_name[] = "data";
|
||||
|
||||
#endif /* tests/filesys/base/syn-read.h */
|
||||
30
src/tests/filesys/base/syn-remove.c
Normal file
30
src/tests/filesys/base/syn-remove.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* Verifies that a deleted file may still be written to and read
|
||||
from. */
|
||||
|
||||
#include <random.h>
|
||||
#include <string.h>
|
||||
#include <syscall.h>
|
||||
#include "tests/lib.h"
|
||||
#include "tests/main.h"
|
||||
|
||||
char buf1[1234];
|
||||
char buf2[1234];
|
||||
|
||||
void
|
||||
test_main (void)
|
||||
{
|
||||
const char *file_name = "deleteme";
|
||||
int fd;
|
||||
|
||||
CHECK (create (file_name, sizeof buf1), "create \"%s\"", file_name);
|
||||
CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
|
||||
CHECK (remove (file_name), "remove \"%s\"", file_name);
|
||||
random_bytes (buf1, sizeof buf1);
|
||||
CHECK (write (fd, buf1, sizeof buf1) > 0, "write \"%s\"", file_name);
|
||||
msg ("seek \"%s\" to 0", file_name);
|
||||
seek (fd, 0);
|
||||
CHECK (read (fd, buf2, sizeof buf2) > 0, "read \"%s\"", file_name);
|
||||
compare_bytes (buf2, buf1, sizeof buf1, 0, file_name);
|
||||
msg ("close \"%s\"", file_name);
|
||||
close (fd);
|
||||
}
|
||||
16
src/tests/filesys/base/syn-remove.ck
Normal file
16
src/tests/filesys/base/syn-remove.ck
Normal file
@@ -0,0 +1,16 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(syn-remove) begin
|
||||
(syn-remove) create "deleteme"
|
||||
(syn-remove) open "deleteme"
|
||||
(syn-remove) remove "deleteme"
|
||||
(syn-remove) write "deleteme"
|
||||
(syn-remove) seek "deleteme" to 0
|
||||
(syn-remove) read "deleteme"
|
||||
(syn-remove) close "deleteme"
|
||||
(syn-remove) end
|
||||
EOF
|
||||
pass;
|
||||
31
src/tests/filesys/base/syn-write.c
Normal file
31
src/tests/filesys/base/syn-write.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* Spawns several child processes to write out different parts of
|
||||
the contents of a file and waits for them to finish. Then
|
||||
reads back the file and verifies its contents. */
|
||||
|
||||
#include <random.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syscall.h>
|
||||
#include "tests/filesys/base/syn-write.h"
|
||||
#include "tests/lib.h"
|
||||
#include "tests/main.h"
|
||||
|
||||
char buf1[BUF_SIZE];
|
||||
char buf2[BUF_SIZE];
|
||||
|
||||
void
|
||||
test_main (void)
|
||||
{
|
||||
pid_t children[CHILD_CNT];
|
||||
int fd;
|
||||
|
||||
CHECK (create (file_name, sizeof buf1), "create \"%s\"", file_name);
|
||||
|
||||
exec_children ("child-syn-wrt", children, CHILD_CNT);
|
||||
wait_children (children, CHILD_CNT);
|
||||
|
||||
CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
|
||||
CHECK (read (fd, buf1, sizeof buf1) > 0, "read \"%s\"", file_name);
|
||||
random_bytes (buf2, sizeof buf2);
|
||||
compare_bytes (buf1, buf2, sizeof buf1, 0, file_name);
|
||||
}
|
||||
32
src/tests/filesys/base/syn-write.ck
Normal file
32
src/tests/filesys/base/syn-write.ck
Normal file
@@ -0,0 +1,32 @@
|
||||
# -*- perl -*-
|
||||
use strict;
|
||||
use warnings;
|
||||
use tests::tests;
|
||||
check_expected (IGNORE_EXIT_CODES => 1, [<<'EOF']);
|
||||
(syn-write) begin
|
||||
(syn-write) create "stuff"
|
||||
(syn-write) exec child 1 of 10: "child-syn-wrt 0"
|
||||
(syn-write) exec child 2 of 10: "child-syn-wrt 1"
|
||||
(syn-write) exec child 3 of 10: "child-syn-wrt 2"
|
||||
(syn-write) exec child 4 of 10: "child-syn-wrt 3"
|
||||
(syn-write) exec child 5 of 10: "child-syn-wrt 4"
|
||||
(syn-write) exec child 6 of 10: "child-syn-wrt 5"
|
||||
(syn-write) exec child 7 of 10: "child-syn-wrt 6"
|
||||
(syn-write) exec child 8 of 10: "child-syn-wrt 7"
|
||||
(syn-write) exec child 9 of 10: "child-syn-wrt 8"
|
||||
(syn-write) exec child 10 of 10: "child-syn-wrt 9"
|
||||
(syn-write) wait for child 1 of 10 returned 0 (expected 0)
|
||||
(syn-write) wait for child 2 of 10 returned 1 (expected 1)
|
||||
(syn-write) wait for child 3 of 10 returned 2 (expected 2)
|
||||
(syn-write) wait for child 4 of 10 returned 3 (expected 3)
|
||||
(syn-write) wait for child 5 of 10 returned 4 (expected 4)
|
||||
(syn-write) wait for child 6 of 10 returned 5 (expected 5)
|
||||
(syn-write) wait for child 7 of 10 returned 6 (expected 6)
|
||||
(syn-write) wait for child 8 of 10 returned 7 (expected 7)
|
||||
(syn-write) wait for child 9 of 10 returned 8 (expected 8)
|
||||
(syn-write) wait for child 10 of 10 returned 9 (expected 9)
|
||||
(syn-write) open "stuff"
|
||||
(syn-write) read "stuff"
|
||||
(syn-write) end
|
||||
EOF
|
||||
pass;
|
||||
9
src/tests/filesys/base/syn-write.h
Normal file
9
src/tests/filesys/base/syn-write.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef TESTS_FILESYS_BASE_SYN_WRITE_H
|
||||
#define TESTS_FILESYS_BASE_SYN_WRITE_H
|
||||
|
||||
#define CHILD_CNT 10
|
||||
#define CHUNK_SIZE 512U
|
||||
#define BUF_SIZE (CHILD_CNT * CHUNK_SIZE)
|
||||
static const char file_name[] = "stuff";
|
||||
|
||||
#endif /* tests/filesys/base/syn-write.h */
|
||||
Reference in New Issue
Block a user