1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/conf/dstest_file_remove.cfg Mon Jun 27 16:30:51 2022 +0200
1.3 @@ -0,0 +1,51 @@
1.4 +-- vim:set ft=lua:
1.5 +
1.6 +local L4 = require("L4");
1.7 +
1.8 +local l = L4.default_loader;
1.9 +
1.10 +local pipe_server = l:new_channel();
1.11 +
1.12 +l:startv({
1.13 + caps = {
1.14 + server = pipe_server:svr(),
1.15 + },
1.16 + log = { "pipes", "r" },
1.17 + },
1.18 + "rom/dstest_pipe_server", "10");
1.19 +
1.20 +local block_server = l:new_channel();
1.21 +
1.22 +l:startv({
1.23 + caps = {
1.24 + server = block_server:svr(),
1.25 + },
1.26 + log = { "blocksvr", "r" },
1.27 + },
1.28 + "rom/dstest_block_server", "10");
1.29 +
1.30 +local ext2svr = l:new_channel();
1.31 +
1.32 +l:startv({
1.33 + caps = {
1.34 + blocksvr = block_server,
1.35 + pipes = pipe_server,
1.36 + ext2svr = ext2svr:svr(),
1.37 + },
1.38 + log = { "ext2svr", "y" },
1.39 + },
1.40 + "rom/dstest_ext2_server", "blocksvr", "rom/e2test.fs", "10", "ext2svr");
1.41 +
1.42 +-- Obtain user filesystems with umask 0022 (18).
1.43 +
1.44 +local open_for_user = 6;
1.45 +local ext2svr_paulb = L4.cast(L4.Proto.Factory, ext2svr):create(open_for_user, 1000, 1000, 18);
1.46 +
1.47 +l:startv({
1.48 + caps = {
1.49 + server = ext2svr_paulb,
1.50 + },
1.51 + log = { "client", "g" },
1.52 + },
1.53 + -- program, file to create and remove
1.54 + "rom/dstest_file_remove", "home/paulb/to_remove");
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/conf/dstest_file_remove.list Mon Jun 27 16:30:51 2022 +0200
2.3 @@ -0,0 +1,28 @@
2.4 +entry dstest_file_remove
2.5 +roottask moe rom/dstest_file_remove.cfg
2.6 +module dstest_file_remove.cfg
2.7 +module e2test.fs
2.8 +module l4re
2.9 +module ned
2.10 +module dstest_file_remove
2.11 +module dstest_ext2_server
2.12 +module dstest_block_server
2.13 +module dstest_pipe_server
2.14 +module lib4re-c.so
2.15 +module lib4re-c-util.so
2.16 +module lib4re.so
2.17 +module lib4re-util.so
2.18 +module libc_be_l4refile.so
2.19 +module libc_be_l4re.so
2.20 +module libc_be_socket_noop.so
2.21 +module libc_support_misc.so
2.22 +module libdl.so
2.23 +module libipc.so
2.24 +module libl4sys-direct.so
2.25 +module libl4sys.so
2.26 +module libl4util.so
2.27 +module libld-l4.so
2.28 +module libpthread.so
2.29 +module libstdc++.so
2.30 +module libsupc++.so
2.31 +module libuc_c.so
3.1 --- a/tests/Makefile Mon Jun 27 16:30:36 2022 +0200
3.2 +++ b/tests/Makefile Mon Jun 27 16:30:51 2022 +0200
3.3 @@ -9,6 +9,7 @@
3.4 dstest_file_monitor \
3.5 dstest_file_readdir \
3.6 dstest_file_readdir_concurrent \
3.7 + dstest_file_remove \
3.8 dstest_file_rename \
3.9 dstest_host_client \
3.10 dstest_pipe_client \
3.11 @@ -65,6 +66,8 @@
3.12
3.13 SRC_CC_dstest_file_readdir_concurrent = dstest_file_readdir_concurrent.cc
3.14
3.15 +SRC_CC_dstest_file_remove = dstest_file_remove.cc
3.16 +
3.17 SRC_CC_dstest_file_rename = dstest_file_rename.cc
3.18
3.19 SRC_CC_dstest_host_client = dstest_host_client.cc
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/dstest_file_remove.cc Mon Jun 27 16:30:51 2022 +0200
4.3 @@ -0,0 +1,146 @@
4.4 +/*
4.5 + * Test removal operations.
4.6 + *
4.7 + * Copyright (C) 2020, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
4.8 + *
4.9 + * This program is free software; you can redistribute it and/or
4.10 + * modify it under the terms of the GNU General Public License as
4.11 + * published by the Free Software Foundation; either version 2 of
4.12 + * the License, or (at your option) any later version.
4.13 + *
4.14 + * This program is distributed in the hope that it will be useful,
4.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 + * GNU General Public License for more details.
4.18 + *
4.19 + * You should have received a copy of the GNU General Public License
4.20 + * along with this program; if not, write to the Free Software
4.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
4.22 + * Boston, MA 02110-1301, USA
4.23 + */
4.24 +
4.25 +#include <l4/re/env.h>
4.26 +#include <l4/sys/err.h>
4.27 +
4.28 +#include <stdio.h>
4.29 +#include <string.h>
4.30 +#include <stdlib.h>
4.31 +
4.32 +#include <fsclient/client.h>
4.33 +#include <systypes/fcntl.h>
4.34 +
4.35 +
4.36 +
4.37 +static void read_from_file(file_t *file)
4.38 +{
4.39 + char buf[20];
4.40 + offset_t nread;
4.41 +
4.42 + client_seek(file, 0, SEEK_SET);
4.43 +
4.44 + printf("Reading...\n");
4.45 +
4.46 + nread = client_read(file, buf, 20);
4.47 +
4.48 + printf("Read %ld bytes...\n", nread);
4.49 + fwrite(buf, sizeof(char), nread, stdout);
4.50 + fputs("\n", stdout);
4.51 +}
4.52 +
4.53 +static void write_to_file(file_t *file, const char *buf)
4.54 +{
4.55 + offset_t nwritten;
4.56 +
4.57 + client_seek(file, 0, SEEK_SET);
4.58 +
4.59 + printf("Writing...\n");
4.60 +
4.61 + nwritten = client_write(file, buf, strlen(buf));
4.62 +
4.63 + printf("Wrote %ld bytes: ", nwritten);
4.64 + fwrite(buf, sizeof(char), nwritten, stdout);
4.65 + fputs("\n", stdout);
4.66 +}
4.67 +
4.68 +int main(int argc, char *argv[])
4.69 +{
4.70 + if (argc < 2)
4.71 + {
4.72 + printf("Need a file to remove.\n");
4.73 + return 1;
4.74 + }
4.75 +
4.76 + char *filename = argv[1];
4.77 +
4.78 + printf("Creating %s...\n", filename);
4.79 +
4.80 + file_t *file = client_open(filename, O_WRONLY | O_CREAT);
4.81 +
4.82 + write_to_file(file, "An existing file.");
4.83 +
4.84 + client_close(file);
4.85 +
4.86 + printf("Opening %s...\n", filename);
4.87 +
4.88 + file = client_open(filename, O_RDONLY);
4.89 +
4.90 + if (file == NULL)
4.91 + {
4.92 + printf("Could not open file: %s\n", filename);
4.93 + return 1;
4.94 + }
4.95 +
4.96 + /* Read from the file, then remove the file, then read again. */
4.97 +
4.98 + read_from_file(file);
4.99 +
4.100 + printf("Removing...\n");
4.101 +
4.102 + long err = client_remove(filename);
4.103 +
4.104 + if (err)
4.105 + {
4.106 + printf("Could not remove file: %s\n", filename);
4.107 + return 1;
4.108 + }
4.109 +
4.110 + printf("Reading again...\n");
4.111 +
4.112 + read_from_file(file);
4.113 +
4.114 + /* Open the file again. */
4.115 +
4.116 + file_t *file_new = client_open(filename, O_RDONLY);
4.117 +
4.118 + if (file_new != NULL)
4.119 + {
4.120 + printf("File should be absent: %s\n", filename);
4.121 + return 1;
4.122 + }
4.123 +
4.124 + file_new = client_open(filename, O_RDWR | O_CREAT);
4.125 +
4.126 + if (file_new == NULL)
4.127 + {
4.128 + printf("File should be present: %s\n", filename);
4.129 + return 1;
4.130 + }
4.131 +
4.132 + write_to_file(file_new, "New file!");
4.133 +
4.134 + /* Read from the initial file and new file. */
4.135 +
4.136 + read_from_file(file);
4.137 + read_from_file(file_new);
4.138 +
4.139 + /* Close the files. */
4.140 +
4.141 + client_close(file);
4.142 + client_close(file_new);
4.143 +
4.144 + printf("End of tests.\n");
4.145 +
4.146 + return 0;
4.147 +}
4.148 +
4.149 +// vim: tabstop=2 expandtab shiftwidth=2