# HG changeset patch # User Paul Boddie # Date 1662061961 -7200 # Node ID dbc8c17a4f81651cccb8346d59ea900e205eb9c8 # Parent f27aad83b42ff1e511a79cb0beed02960c5641b7 Added an error member to the file data structure, changing the client library interface so that client_open returns a structure whose error member may be tested, directly or using the new client_opened function, to determine the reason for failure, this being done in preference to having a global, shared errno variable. Updated the tests for the above library changes, also making test configuration file naming consistent with executable naming, and introducing better output to assess the successful completion of tests. diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_block.cfg --- a/conf/dstest_block.cfg Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ --- vim:set ft=lua: - -local L4 = require("L4"); - -local l = L4.default_loader; - -local server = l:new_channel(); - -l:startv({ - caps = { - server = server:svr(), - }, - log = { "server", "r" }, - }, - "rom/block_server", "10"); - -l:startv({ - caps = { - server = server, - }, - log = { "client", "g" }, - }, - "rom/dstest_block_client", "rom/dstest_block.cfg", 1024, 1024); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_block.list --- a/conf/dstest_block.list Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -entry dstest_block -roottask moe rom/dstest_block.cfg -module dstest_block.cfg -module l4re -module ned -module dstest_block_client -module block_server -module lib4re-c.so -module lib4re-c-util.so -module lib4re.so -module lib4re-util.so -module libc_be_l4refile.so -module libc_be_l4re.so -module libc_be_socket_noop.so -module libc_support_misc.so -module libdl.so -module libipc.so -module libl4sys-direct.so -module libl4sys.so -module libl4util.so -module libld-l4.so -module libpthread.so -module libstdc++.so -module libsupc++.so -module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_block_client.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_block_client.cfg Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,23 @@ +-- vim:set ft=lua: + +local L4 = require("L4"); + +local l = L4.default_loader; + +local server = l:new_channel(); + +l:startv({ + caps = { + server = server:svr(), + }, + log = { "server", "r" }, + }, + "rom/block_server", "10"); + +l:startv({ + caps = { + server = server, + }, + log = { "client", "g" }, + }, + "rom/dstest_block_client", "rom/dstest_block_client.cfg", 1024, 1024); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_block_client.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_block_client.list Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,25 @@ +entry dstest_block_client +roottask moe rom/dstest_block_client.cfg +module dstest_block_client.cfg +module l4re +module ned +module dstest_block_client +module block_server +module lib4re-c.so +module lib4re-c-util.so +module lib4re.so +module lib4re-util.so +module libc_be_l4refile.so +module libc_be_l4re.so +module libc_be_socket_noop.so +module libc_support_misc.so +module libdl.so +module libipc.so +module libl4sys-direct.so +module libl4sys.so +module libl4util.so +module libld-l4.so +module libpthread.so +module libstdc++.so +module libsupc++.so +module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_block_client_simple.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_block_client_simple.cfg Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,23 @@ +-- vim:set ft=lua: + +local L4 = require("L4"); + +local l = L4.default_loader; + +local server = l:new_channel(); + +l:startv({ + caps = { + server = server:svr(), + }, + log = { "server", "r" }, + }, + "rom/block_server", "10"); + +l:startv({ + caps = { + server = server, + }, + log = { "client", "g" }, + }, + "rom/dstest_block_client_simple", "rom/dstest_block_client_simple.cfg"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_block_client_simple.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_block_client_simple.list Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,25 @@ +entry dstest_block_client_simple +roottask moe rom/dstest_block_client_simple.cfg +module dstest_block_client_simple.cfg +module l4re +module ned +module dstest_block_client_simple +module block_server +module lib4re-c.so +module lib4re-c-util.so +module lib4re.so +module lib4re-util.so +module libc_be_l4refile.so +module libc_be_l4re.so +module libc_be_socket_noop.so +module libc_support_misc.so +module libdl.so +module libipc.so +module libl4sys-direct.so +module libl4sys.so +module libl4util.so +module libld-l4.so +module libpthread.so +module libstdc++.so +module libsupc++.so +module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_block_simple.cfg --- a/conf/dstest_block_simple.cfg Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ --- vim:set ft=lua: - -local L4 = require("L4"); - -local l = L4.default_loader; - -local server = l:new_channel(); - -l:startv({ - caps = { - server = server:svr(), - }, - log = { "server", "r" }, - }, - "rom/block_server", "10"); - -l:startv({ - caps = { - server = server, - }, - log = { "client", "g" }, - }, - "rom/dstest_block_client_simple", "rom/dstest_block_simple.cfg"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_block_simple.list --- a/conf/dstest_block_simple.list Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -entry dstest_block_simple -roottask moe rom/dstest_block_simple.cfg -module dstest_block_simple.cfg -module l4re -module ned -module dstest_block_client_simple -module block_server -module lib4re-c.so -module lib4re-c-util.so -module lib4re.so -module lib4re-util.so -module libc_be_l4refile.so -module libc_be_l4re.so -module libc_be_socket_noop.so -module libc_support_misc.so -module libdl.so -module libipc.so -module libl4sys-direct.so -module libl4sys.so -module libl4util.so -module libld-l4.so -module libpthread.so -module libstdc++.so -module libsupc++.so -module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_ext2fs.cfg --- a/conf/dstest_ext2fs.cfg Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ --- vim:set ft=lua: - -local L4 = require("L4"); - -local l = L4.default_loader; - -local blocksvr = l:new_channel(); - -l:startv({ - caps = { - server = blocksvr:svr(), - }, - log = { "blocksvr", "r" }, - }, - "rom/block_server", "10"); - -l:startv({ - caps = { - server = blocksvr, - }, - log = { "client", "r" }, - }, - "rom/dstest_ext2fs_client", "server", "rom/e2test.fs"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_ext2fs.list --- a/conf/dstest_ext2fs.list Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -entry dstest_ext2fs -roottask moe rom/dstest_ext2fs.cfg -module dstest_ext2fs.cfg -module e2test.fs -module l4re -module ned -module block_server -module dstest_ext2fs_client -module lib4re-c.so -module lib4re-c-util.so -module lib4re.so -module lib4re-util.so -module libc_be_l4refile.so -module libc_be_l4re.so -module libc_be_socket_noop.so -module libc_support_misc.so -module libdl.so -module libipc.so -module libl4sys-direct.so -module libl4sys.so -module libl4util.so -module libld-l4.so -module libpthread.so -module libstdc++.so -module libsupc++.so -module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_ext2fs_client.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_ext2fs_client.cfg Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,23 @@ +-- vim:set ft=lua: + +local L4 = require("L4"); + +local l = L4.default_loader; + +local blocksvr = l:new_channel(); + +l:startv({ + caps = { + server = blocksvr:svr(), + }, + log = { "blocksvr", "r" }, + }, + "rom/block_server", "10"); + +l:startv({ + caps = { + server = blocksvr, + }, + log = { "client", "g" }, + }, + "rom/dstest_ext2fs_client", "server", "rom/e2test.fs"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_ext2fs_client.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_ext2fs_client.list Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,26 @@ +entry dstest_ext2fs_client +roottask moe rom/dstest_ext2fs_client.cfg +module dstest_ext2fs_client.cfg +module e2test.fs +module l4re +module ned +module block_server +module dstest_ext2fs_client +module lib4re-c.so +module lib4re-c-util.so +module lib4re.so +module lib4re-util.so +module libc_be_l4refile.so +module libc_be_l4re.so +module libc_be_socket_noop.so +module libc_support_misc.so +module libdl.so +module libipc.so +module libl4sys-direct.so +module libl4sys.so +module libl4util.so +module libld-l4.so +module libpthread.so +module libstdc++.so +module libsupc++.so +module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_file.cfg --- a/conf/dstest_file.cfg Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ --- vim:set ft=lua: - -local L4 = require("L4"); - -local l = L4.default_loader; - -local blocksvr = l:new_channel(); - -l:startv({ - caps = { - server = blocksvr:svr(), - }, - log = { "blocksvr", "r" }, - }, - "rom/block_server", "10"); - -local ext2svr = l:new_channel(); - -l:startv({ - caps = { - blocksvr = blocksvr, - ext2svr = ext2svr:svr(), - }, - log = { "ext2svr", "y" }, - }, - "rom/ext2_server", "blocksvr", "rom/e2test.fs", "10", "ext2svr"); - --- Obtain user filesystems with umask 0022 (18). - -local open_for_user = 6; -local ext2svr_paulb = L4.cast(L4.Proto.Factory, ext2svr):create(open_for_user, 1000, 1000, 18); - -l:startv({ - caps = { - server = ext2svr_paulb, - }, - log = { "client", "g" }, - }, - -- program, file to create - "rom/dstest_file_client", "home/paulb/new file"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_file.list --- a/conf/dstest_file.list Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -entry dstest_file -roottask moe rom/dstest_file.cfg -module dstest_file.cfg -module e2test.fs -module l4re -module ned -module dstest_file_client -module ext2_server -module block_server -module lib4re-c.so -module lib4re-c-util.so -module lib4re.so -module lib4re-util.so -module libc_be_l4refile.so -module libc_be_l4re.so -module libc_be_socket_noop.so -module libc_support_misc.so -module libdl.so -module libipc.so -module libl4sys-direct.so -module libl4sys.so -module libl4util.so -module libld-l4.so -module libpthread.so -module libstdc++.so -module libsupc++.so -module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_file_client.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_file_client.cfg Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,40 @@ +-- vim:set ft=lua: + +local L4 = require("L4"); + +local l = L4.default_loader; + +local blocksvr = l:new_channel(); + +l:startv({ + caps = { + server = blocksvr:svr(), + }, + log = { "blocksvr", "r" }, + }, + "rom/block_server", "10"); + +local ext2svr = l:new_channel(); + +l:startv({ + caps = { + blocksvr = blocksvr, + ext2svr = ext2svr:svr(), + }, + log = { "ext2svr", "y" }, + }, + "rom/ext2_server", "blocksvr", "rom/e2test.fs", "10", "ext2svr"); + +-- Obtain user filesystems with umask 0022 (18). + +local open_for_user = 6; +local ext2svr_paulb = L4.cast(L4.Proto.Factory, ext2svr):create(open_for_user, 1000, 1000, 18); + +l:startv({ + caps = { + server = ext2svr_paulb, + }, + log = { "client", "g" }, + }, + -- program, file to create + "rom/dstest_file_client", "home/paulb/new file"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_file_client.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_file_client.list Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,27 @@ +entry dstest_file_client +roottask moe rom/dstest_file_client.cfg +module dstest_file_client.cfg +module e2test.fs +module l4re +module ned +module dstest_file_client +module ext2_server +module block_server +module lib4re-c.so +module lib4re-c-util.so +module lib4re.so +module lib4re-util.so +module libc_be_l4refile.so +module libc_be_l4re.so +module libc_be_socket_noop.so +module libc_support_misc.so +module libdl.so +module libipc.so +module libl4sys-direct.so +module libl4sys.so +module libl4util.so +module libld-l4.so +module libpthread.so +module libstdc++.so +module libsupc++.so +module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_file_readdir.cfg --- a/conf/dstest_file_readdir.cfg Thu Sep 01 21:40:39 2022 +0200 +++ b/conf/dstest_file_readdir.cfg Thu Sep 01 21:52:41 2022 +0200 @@ -47,5 +47,5 @@ }, log = { "client", "g" }, }, - -- program, directory to read - "rom/dstest_file_readdir", "home/paulb/many"); + -- program, directory to read, count of entries (files plus special entries) + "rom/dstest_file_readdir", "home/paulb/many", "402"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_host.cfg --- a/conf/dstest_host.cfg Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ --- vim:set ft=lua: - -local L4 = require("L4"); - -local l = L4.default_loader; - -local server = l:new_channel(); - -l:startv({ - caps = { - server = server:svr(), - }, - log = { "server", "r" }, - }, - "rom/host_server", "10"); - -l:startv({ - caps = { - server = server, - }, - log = { "client", "g" }, - }, - "rom/dstest_host_client", "rom/dstest_host.cfg", 1024, 1024); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_host.list --- a/conf/dstest_host.list Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -entry dstest_host -roottask moe rom/dstest_host.cfg -module dstest_host.cfg -module l4re -module ned -module dstest_host_client -module host_server -module lib4re-c.so -module lib4re-c-util.so -module lib4re.so -module lib4re-util.so -module libc_be_l4refile.so -module libc_be_l4re.so -module libc_be_socket_noop.so -module libc_support_misc.so -module libdl.so -module libipc.so -module libl4sys-direct.so -module libl4sys.so -module libl4util.so -module libld-l4.so -module libpthread.so -module libstdc++.so -module libsupc++.so -module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_host_client.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_host_client.cfg Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,23 @@ +-- vim:set ft=lua: + +local L4 = require("L4"); + +local l = L4.default_loader; + +local server = l:new_channel(); + +l:startv({ + caps = { + server = server:svr(), + }, + log = { "server", "r" }, + }, + "rom/host_server", "10"); + +l:startv({ + caps = { + server = server, + }, + log = { "client", "g" }, + }, + "rom/dstest_host_client", "rom/dstest_host_client.cfg", 1024, 1024); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_host_client.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_host_client.list Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,25 @@ +entry dstest_host_client +roottask moe rom/dstest_host_client.cfg +module dstest_host_client.cfg +module l4re +module ned +module dstest_host_client +module host_server +module lib4re-c.so +module lib4re-c-util.so +module lib4re.so +module lib4re-util.so +module libc_be_l4refile.so +module libc_be_l4re.so +module libc_be_socket_noop.so +module libc_support_misc.so +module libdl.so +module libipc.so +module libl4sys-direct.so +module libl4sys.so +module libl4util.so +module libld-l4.so +module libpthread.so +module libstdc++.so +module libsupc++.so +module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_host_readdir.cfg --- a/conf/dstest_host_readdir.cfg Thu Sep 01 21:40:39 2022 +0200 +++ b/conf/dstest_host_readdir.cfg Thu Sep 01 21:52:41 2022 +0200 @@ -31,4 +31,4 @@ }, log = { "client", "g" }, }, - "rom/dstest_file_readdir", "rom"); + "rom/dstest_file_readdir", "rom", "23"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_pipe.cfg --- a/conf/dstest_pipe.cfg Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ --- vim:set ft=lua: - -local L4 = require("L4"); - -local l = L4.default_loader; - -local server = l:new_channel(); - -l:startv({ - caps = { - server = server:svr(), - }, - log = { "server", "r" }, - }, - "rom/pipe_server", "10"); - -l:start({ - caps = { - pipes = server, - }, - log = { "client", "g" }, - }, - "rom/dstest_pipe_client"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_pipe.list --- a/conf/dstest_pipe.list Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -entry dstest_pipe -roottask moe rom/dstest_pipe.cfg -module dstest_pipe.cfg -module l4re -module ned -module dstest_pipe_client -module pipe_server -module lib4re-c.so -module lib4re-c-util.so -module lib4re.so -module lib4re-util.so -module libc_be_l4refile.so -module libc_be_l4re.so -module libc_be_socket_noop.so -module libc_support_misc.so -module libdl.so -module libipc.so -module libl4sys-direct.so -module libl4sys.so -module libl4util.so -module libld-l4.so -module libpthread.so -module libstdc++.so -module libsupc++.so -module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_pipe_client.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_pipe_client.cfg Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,23 @@ +-- vim:set ft=lua: + +local L4 = require("L4"); + +local l = L4.default_loader; + +local server = l:new_channel(); + +l:startv({ + caps = { + server = server:svr(), + }, + log = { "server", "r" }, + }, + "rom/pipe_server", "10"); + +l:start({ + caps = { + pipes = server, + }, + log = { "client", "g" }, + }, + "rom/dstest_pipe_client"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_pipe_client.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_pipe_client.list Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,25 @@ +entry dstest_pipe_client +roottask moe rom/dstest_pipe_client.cfg +module dstest_pipe_client.cfg +module l4re +module ned +module dstest_pipe_client +module pipe_server +module lib4re-c.so +module lib4re-c-util.so +module lib4re.so +module lib4re-util.so +module libc_be_l4refile.so +module libc_be_l4re.so +module libc_be_socket_noop.so +module libc_support_misc.so +module libdl.so +module libipc.so +module libl4sys-direct.so +module libl4sys.so +module libl4util.so +module libld-l4.so +module libpthread.so +module libstdc++.so +module libsupc++.so +module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_test.cfg --- a/conf/dstest_test.cfg Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ --- vim:set ft=lua: - -local L4 = require("L4"); - -local l = L4.default_loader; - -local server = l:new_channel(); - -l:startv({ - caps = { - server = server:svr(), - }, - log = { "server", "r" }, - }, - "rom/test_server", "40"); - -l:start({ - caps = { - server = server, - }, - log = { "client1", "g" }, - }, - "rom/dstest_test_client"); - -l:start({ - caps = { - server = server, - }, - log = { "client2", "b" }, - }, - "rom/dstest_test_client"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_test.list --- a/conf/dstest_test.list Thu Sep 01 21:40:39 2022 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -entry dstest_test -roottask moe rom/dstest_test.cfg -module dstest_test.cfg -module l4re -module ned -module dstest_test_client -module test_server -module lib4re-c.so -module lib4re-c-util.so -module lib4re.so -module lib4re-util.so -module libc_be_l4refile.so -module libc_be_l4re.so -module libc_be_socket_noop.so -module libc_support_misc.so -module libdl.so -module libipc.so -module libl4sys-direct.so -module libl4sys.so -module libl4util.so -module libld-l4.so -module libpthread.so -module libstdc++.so -module libsupc++.so -module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_test_client.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_test_client.cfg Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,31 @@ +-- vim:set ft=lua: + +local L4 = require("L4"); + +local l = L4.default_loader; + +local server = l:new_channel(); + +l:startv({ + caps = { + server = server:svr(), + }, + log = { "server", "r" }, + }, + "rom/test_server", "40"); + +l:start({ + caps = { + server = server, + }, + log = { "client1", "g" }, + }, + "rom/dstest_test_client"); + +l:start({ + caps = { + server = server, + }, + log = { "client2", "b" }, + }, + "rom/dstest_test_client"); diff -r f27aad83b42f -r dbc8c17a4f81 conf/dstest_test_client.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_test_client.list Thu Sep 01 21:52:41 2022 +0200 @@ -0,0 +1,25 @@ +entry dstest_test_client +roottask moe rom/dstest_test_client.cfg +module dstest_test_client.cfg +module l4re +module ned +module dstest_test_client +module test_server +module lib4re-c.so +module lib4re-c-util.so +module lib4re.so +module lib4re-util.so +module libc_be_l4refile.so +module libc_be_l4re.so +module libc_be_socket_noop.so +module libc_support_misc.so +module libdl.so +module libipc.so +module libl4sys-direct.so +module libl4sys.so +module libl4util.so +module libld-l4.so +module libpthread.so +module libstdc++.so +module libsupc++.so +module libuc_c.so diff -r f27aad83b42f -r dbc8c17a4f81 docs/wiki/Client_Library --- a/docs/wiki/Client_Library Thu Sep 01 21:40:39 2022 +0200 +++ b/docs/wiki/Client_Library Thu Sep 01 21:52:41 2022 +0200 @@ -9,13 +9,21 @@ <> +== Header Files == + +The following header files are pertinent to client library usage: + +|| '''File''' || '''Description''' || +|| `fsclient/client.h` || Client functions and data structures || +|| `systypes/fcntl.h` || Flag values for opening operations || + == File Data Structures == Since files are accessed using file references, the `file_t` data structure is used to wrap such references and other relevant state. Thus, such structures can be broadly regarded as similar to the traditional `FILE` data structure. -The fields of the `file_t` data structure are as follows: +The members of the `file_t` data structure are as follows: || '''Field''' || '''Description''' || || `ref` || A reference to the component providing file content || @@ -29,6 +37,10 @@ || `can_block` || Notification flags for blocking access to the file || || `notifications`|| Notification flags set for the file || || `flags` || The flags used to open the file || +|| `error` || Any failure or error condition on the file || + +Generally, these members should not be accessed directly, mostly being +reserved for use by the client library itself. == Client Programming Interface == @@ -38,23 +50,63 @@ === Files === -Files are opened and closed using the following functions: +Files are opened using the following function returning a file data structure: {{{ file_t *client_open(const char *name, flags_t flags); }}} -Each file endpoint may be closed using `client_close`. +To test whether the file was successfully open, the following function should +be invoked, this returning a true (non-zero) value if the file was +successfully opened: + +{{{ +int client_opened(file_t *file); +}}} + +Each file should be closed using `client_close` regardless of whether the file +was successfully opened. + +==== Example ==== + +{{{ +file_t *file = client_open("somefile", O_RDONLY); + +if (client_opened(file)) +{ + /* Perform operations on file. */ +} + +client_close(file); +}}} === Pipes === -Pipes are opened using a special function: +Pipes are opened using a special function returning an error code, setting the +supplied reader and writer endpoint parameters: {{{ long client_pipe(file_t **reader, file_t **writer, flags_t flags); }}} -Each pipe endpoint may be closed using `client_close`. +Each returned pipe endpoint may be closed using `client_close`. If an error +condition is reported using a non-zero value, the endpoints will not be +retained and will therefore not need to be closed: the error condition is +communicated purely via the return value. + +==== Example ==== + +{{{ +file_t *reader, *writer; + +if (!client_pipe(&reader, &writer, 0)) +{ + /* Perform operations on pipe. */ +} + +client_close(reader); +client_close(writer); +}}} === Closing Files and Pipes === @@ -94,9 +146,33 @@ memory, a function can be used to explicitly reference memory for file access: {{{ -void *client_mmap(file_t *file, offset_t position, offset_t length); +void *client_mmap(file_t *file, offset_t position, offset_t length, + offset_t start_visible, offset_t end_visible, + l4re_rm_flags_t region_flags); }}} +Here, a portion of the indicated `file` is exposed in a memory region, with +the memory region corresponding to the contents of the file starting at the +given `position` in the file and having a span of the given `length` in bytes. + +Additional parameters control masking of the file content. If `start_visible` +and `end_visible` are both non-zero, then they indicate a visible span in the +file. Such limits are applied to the mapped region, with locations +corresponding to positions before `start_visible` and positions after +`end_visible` yielding zero byte values. + +The `region_flags` indicate the memory access properties of the mapped region +in the task obtaining it. For example, where a region will be populated with +code, the `L4RE_DS_F_RX` flag would be appropriate, this indicating that the +region will be read and also have its contents run or executed. + +'''Note:''' Currently, when masking is applied to a file, any write operations +will cause the modified memory to be copied and modified, as opposed to +causing modifications to the underlying file content. This behaviour may +eventually be more configurable. + +=== Accessing Pipe Content in Memory Regions === + Pipes support a different mechanism for navigation involving the following functions: diff -r f27aad83b42f -r dbc8c17a4f81 libfsclient/include/fsclient/client.h --- a/libfsclient/include/fsclient/client.h Thu Sep 01 21:40:39 2022 +0200 +++ b/libfsclient/include/fsclient/client.h Thu Sep 01 21:52:41 2022 +0200 @@ -47,6 +47,10 @@ long client_pipe(file_t **reader, file_t **writer, flags_t flags); long client_pipe_using(file_t **reader, file_t **writer, flags_t flags, l4_cap_idx_t server); +/* File status testing. */ + +int client_opened(file_t *file); + /* Other file operations. */ long client_mkdir(const char *path, mode_t mode); diff -r f27aad83b42f -r dbc8c17a4f81 libfsclient/include/fsclient/file.h --- a/libfsclient/include/fsclient/file.h Thu Sep 01 21:40:39 2022 +0200 +++ b/libfsclient/include/fsclient/file.h Thu Sep 01 21:52:41 2022 +0200 @@ -79,6 +79,10 @@ flags_t flags; + /* Any failure or error condition on the file. */ + + long error; + } file_t; diff -r f27aad83b42f -r dbc8c17a4f81 libfsclient/lib/src/client.cc --- a/libfsclient/lib/src/client.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/libfsclient/lib/src/client.cc Thu Sep 01 21:52:41 2022 +0200 @@ -135,7 +135,9 @@ /* Within the current pipe region, synchronise with the pipe object. */ else + { return client_current_region(file); + } } } @@ -148,8 +150,8 @@ static int _operation_blocking(file_t *file, int reading) { return (file->can_block && !(file->notifications & NOTIFY_PEER_CLOSED) && ( - (reading && !file_data_available(file)) || - (!reading && !file_data_space(file)))); + (reading && !file_data_available(file)) || + (!reading && !file_data_space(file)))); } @@ -264,12 +266,9 @@ if (file == NULL) return NULL; - if (file_open(file, name, flags, server)) - { - free(file); - return NULL; - } + /* Return any allocated structure even if an error occurs. */ + file->error = file_open(file, name, flags, server); return file; } @@ -296,10 +295,7 @@ file_t *reader = client_opendir_at(file); - if (reader == NULL) - return NULL; - - /* Release the directory and return the reader. */ + /* Release the directory and return the reader even if an error occurs. */ client_close(file); return reader; @@ -311,7 +307,7 @@ file_t *client_opendir_at(file_t *file) { - if (file == NULL) + if (!client_opened(file)) return NULL; file_t *reader = (file_t *) malloc(sizeof(file_t)); @@ -319,26 +315,23 @@ if (reader == NULL) return NULL; - long err = directory_opendir(file, reader); + /* Return any allocated structure even if an error occurs. */ - if (err) - return NULL; + reader->error = directory_opendir(file, reader); /* Set blocking read mode to be able to conveniently read directory entries - from the stream. */ + from the stream. If this fails, the error is set on the structure, but the + stream will be open. */ - if (client_set_blocking(reader, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED)) - { - client_close(reader); - return NULL; - } + if (!reader->error) + reader->error = client_set_blocking(reader, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED); return reader; } -/* Open a pipe object. */ +/* Open a pipe object, returning any error condition. */ long client_pipe(file_t **reader, file_t **writer, flags_t flags) { @@ -349,6 +342,9 @@ long client_pipe_using(file_t **reader, file_t **writer, flags_t flags, l4_cap_idx_t server) { + *reader = NULL; + *writer = NULL; + if (l4_is_invalid_cap(server)) return -L4_EINVAL; @@ -387,6 +383,15 @@ +/* Determine whether a file has been successfully opened. */ + +int client_opened(file_t *file) +{ + return (file != NULL) && !file->error; +} + + + /* Make a directory in the filesystem. */ long client_mkdir(const char *path, mode_t mode) @@ -463,7 +468,7 @@ long client_current_region(file_t *file) { - if (file == NULL) + if (!client_opened(file)) return -L4_EINVAL; return pipe_current(file); @@ -475,7 +480,7 @@ long client_flush(file_t *file) { - if (file == NULL) + if (!client_opened(file)) return -L4_EINVAL; /* Flush and retain most buffer settings. */ @@ -491,8 +496,8 @@ offset_t start_visible, offset_t end_visible, l4re_rm_flags_t region_flags) { - if ((file == NULL) || file_mmap(file, position, length, start_visible, - end_visible, region_flags)) + if (!client_opened(file) || file_mmap(file, position, length, start_visible, + end_visible, region_flags)) return NULL; return file->memory; @@ -504,7 +509,7 @@ long client_next_region(file_t *file) { - if (file == NULL) + if (!client_opened(file)) return -L4_EINVAL; return pipe_next(file); @@ -584,7 +589,7 @@ offset_t client_read(file_t *file, void *buf, offset_t count) { - if (file == NULL) + if (!client_opened(file)) return 0; /* Map memory if none has been mapped so far. */ @@ -640,7 +645,7 @@ offset_t client_seek(file_t *file, offset_t offset, int whence) { - if (file == NULL) + if (!client_opened(file)) return 0; offset_t position, current = file_data_current_position(file), change; @@ -743,7 +748,7 @@ long client_subscribe(file_t *file, notify_flags_t flags, file_notifier_t *notifier) { - if (file == NULL) + if (!client_opened(file)) return -L4_EINVAL; return file_notify_subscribe(file, flags, notifier); @@ -755,7 +760,7 @@ long client_tell(file_t *file) { - if (file == NULL) + if (!client_opened(file)) return -L4_EINVAL; return file_data_current_position(file); @@ -767,7 +772,7 @@ long client_unsubscribe(file_t *file, file_notifier_t *notifier) { - if (file == NULL) + if (!client_opened(file)) return -L4_EINVAL; return file_notify_unsubscribe(file, notifier); @@ -779,7 +784,7 @@ long client_wait_file(file_t *file, file_notifier_t *notifier) { - if (file == NULL) + if (!client_opened(file)) return -L4_EINVAL; return file_notify_wait_file(file, notifier); @@ -799,7 +804,7 @@ offset_t client_write(file_t *file, const void *buf, offset_t count) { - if (file == NULL) + if (!client_opened(file)) return 0; /* Map memory if none has been mapped so far. */ diff -r f27aad83b42f -r dbc8c17a4f81 libfsclient/lib/src/file.cc --- a/libfsclient/lib/src/file.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/libfsclient/lib/src/file.cc Thu Sep 01 21:52:41 2022 +0200 @@ -91,6 +91,7 @@ file->can_block = 0; file->notifications = 0; file->flags = 0; + file->error = 0; } diff -r f27aad83b42f -r dbc8c17a4f81 libfsserver/lib/generic/pager.cc --- a/libfsserver/lib/generic/pager.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/libfsserver/lib/generic/pager.cc Thu Sep 01 21:52:41 2022 +0200 @@ -66,7 +66,8 @@ return L4_EOK; } -/* Resize the underlying file. */ +/* Resize the file. This will only resize the underlying file where masking and + copy-on-write mapping is not being performed. */ long Pager::resize(offset_t *size) { @@ -87,7 +88,7 @@ _start = trunc(position, PAGE_SIZE); _size = round(position + length, PAGE_SIZE) - _start; - /* Return the start and end positions plus populated extent. */ + /* Return the start and end positions plus file size. */ *start_pos = _start; *end_pos = _start + _size; diff -r f27aad83b42f -r dbc8c17a4f81 test_files/mk_e2test.sh --- a/test_files/mk_e2test.sh Thu Sep 01 21:40:39 2022 +0200 +++ b/test_files/mk_e2test.sh Thu Sep 01 21:52:41 2022 +0200 @@ -55,6 +55,11 @@ OPTIONS='-u 1000 -g 1000' +# Test parameters. +# See: tests/dstest_file_readdir.cfg + +MANY_FILES_COUNT=400 + # Define a convenience function for e2access invocation. e2access() @@ -99,7 +104,7 @@ # Populate the directory with plenty of files. -for N in `seq 1 400`; do +for N in `seq 1 $MANY_FILES_COUNT`; do echo "Contents of #$N." > "file-$N".txt done diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_block_client.cc --- a/tests/dstest_block_client.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_block_client.cc Thu Sep 01 21:52:41 2022 +0200 @@ -33,36 +33,47 @@ -static void show(file_t *file, unsigned long step, unsigned long sample) +static void show(file_t *file, offset_t step, offset_t sample) { /* Allocate a buffer for sampling from the file. */ char buf[sample + 1]; - for (unsigned long offset = 0; offset < file_populated_span(file); offset += step) + for (offset_t offset = 0; offset < file_populated_span(file); offset += step) { - unsigned long remaining = file_populated_span(file) - offset; - unsigned long sample_remaining = remaining < sample ? remaining : sample; + offset_t remaining = file_populated_span(file) - offset; + offset_t sample_remaining = remaining < sample ? remaining : sample; printf("%ld bytes from %p...\n", sample_remaining, (file->memory + offset)); memcpy(buf, (file->memory + offset), sample_remaining); buf[sample_remaining] = '\0'; - unsigned long leading = 0; + offset_t leading = 0; char *outbuf = buf; + /* Skip leading zero bytes. */ + while ((*outbuf == '\0') && (leading < sample_remaining)) { outbuf++; leading++; } - if (leading) - printf("[%ld zero bytes]\n", leading); + offset_t trailing = 0; + char *outbuf_end = outbuf + strlen(outbuf), *end = buf + sample_remaining - 1; - printf("%s\n", outbuf); + while ((*end == '\0') && (end >= outbuf_end)) + { + end--; + trailing++; + } + printf("----\n%s\n----\n", outbuf); + + printf("[%ld zero bytes at start]\n", leading); + printf("[%ld bytes shown]\n", strlen(outbuf)); printf("[%ld bytes after string]\n", sample_remaining - leading - strlen(outbuf)); + printf("[%ld zero bytes at end]\n", trailing); } } @@ -77,8 +88,8 @@ /* Obtain filename and access parameters. */ char *filename = argv[1]; - unsigned long step = atoi(argv[2]); - unsigned long sample = atoi(argv[3]); + offset_t step = atoi(argv[2]); + offset_t sample = atoi(argv[3]); /* Obtain access to the filesystem. */ @@ -95,10 +106,13 @@ return 1; } - /* A region of the file is mapped. Here, the start and length will not provide - page-aligned offsets, but the region is nevertheless not masked. */ + offset_t original_size = file.size; - err = file_mmap(&file, 10, 290, 0, 0, file_region_flags(file.flags)); + /* A region of the file is mapped. Here, the start and length is not provided + as page-aligned offsets, but the region is nevertheless not masked, and the + region limits will be page-aligned in any case. */ + + err = file_mmap(&file, 10, original_size - 20, 0, 0, file_region_flags(file.flags)); if (err) { @@ -106,16 +120,23 @@ return 1; } + printf("Region %ld...%ld populated size %ld size %ld.\n", file.start_pos, file.end_pos, file_populated_span(&file), file.size); printf("File contents:\n"); show(&file, step, sample); printf("File shown.\n"); + printf("Expected...\n" + "[0 zero bytes at start]\n" + "[%ld bytes shown]\n" + "[0 bytes after string]\n" + "[0 zero bytes at end]\n\n", + original_size); /* A region of the file is mapped. Here, the resulting offsets will be used to define a masked region. */ - err = file_mmap(&file, 10, 290, 10, 290, file_region_flags(file.flags)); + err = file_mmap(&file, 10, original_size - 20, 10, original_size - 10, file_region_flags(file.flags)); if (err) { @@ -123,18 +144,27 @@ return 1; } + printf("Region %ld...%ld populated size %ld size %ld.\n", file.start_pos, file.end_pos, file_populated_span(&file), file.size); printf("File contents:\n"); show(&file, step, sample); printf("File shown.\n"); + printf("Expected...\n" + "[10 zero bytes at start]\n" + "[%ld bytes shown]\n" + "[%ld bytes after string]\n" + "[%ld zero bytes at end]\n\n", + original_size - 20, 10UL, 10UL); /* Resizing must occur before writing beyond the end of file. Otherwise, the data may get discarded if the supporting flexpage needs to be flushed. */ - offset_t old_size = file_populated_span(&file); - offset_t new_region = round(old_size, page(1)); - offset_t new_size = new_region + old_size; + offset_t old_populated_size = file_populated_span(&file); + offset_t old_size = file.size; + offset_t old_populated_size_rounded = round(old_populated_size, page(1)); + offset_t new_size = old_populated_size_rounded + old_populated_size; + offset_t new_region = round(new_size, page(1)); printf("Resize to %ld...\n", new_size); @@ -147,10 +177,12 @@ } printf("Resized file...\n"); + printf("Region %ld...%ld populated size %ld size %ld.\n", file.start_pos, file.end_pos, file_populated_span(&file), file.size); + printf("Expected %ld...%ld populated size %ld size %ld.\n\n", 0UL, old_populated_size_rounded, old_populated_size_rounded, new_size); /* Re-map to avoid masking the region. */ - err = file_mmap(&file, 10, new_size - 20, 0, 0, file_region_flags(file.flags)); + err = file_mmap(&file, 0, new_size, 0, 0, file_region_flags(file.flags)); if (err) { @@ -158,27 +190,52 @@ return 1; } - /* Copy the sampled data to another file region. */ + printf("Remapped file without masking...\n"); + printf("Region %ld...%ld populated size %ld size %ld.\n", file.start_pos, file.end_pos, file_populated_span(&file), file.size); + printf("Expected %ld...%ld populated size %ld size %ld.\n\n", 0UL, new_region, old_populated_size, old_size); - printf("Copy data to %ld...\n", new_region); + printf("Resize to %ld...\n", new_size); - for (unsigned long offset = 0; offset < old_size; offset += step) + err = file_resize(&file, new_size); + + if (err) { - printf("Copying to %ld...\n", new_region + offset); - memcpy(file.memory + new_region + offset, file.memory + offset, sample); - if (step > sample) - memset(file.memory + new_region + offset + sample, 0, step - sample); + printf("Could not resize file: %s\n", l4sys_errtostr(err)); + return 1; } + printf("Resized file...\n"); + printf("Region %ld...%ld populated size %ld size %ld.\n", file.start_pos, file.end_pos, file_populated_span(&file), file.size); + printf("Expected %ld...%ld populated size %ld size %ld.\n\n", 0UL, round(new_size, page(1)), new_size, new_size); + + /* Copy the file data to another file region. */ + + printf("Copy data to %ld...\n", old_populated_size_rounded); + + memcpy(file.memory + old_populated_size_rounded, file.memory, old_size); + + printf("Region %ld...%ld populated size %ld size %ld.\n", file.start_pos, file.end_pos, file_populated_span(&file), file.size); printf("File contents:\n"); show(&file, step, sample); printf("File shown.\n"); + printf("Expected...\n" + "[0 zero bytes at start]\n" + "[%ld bytes shown]\n" + "[%ld bytes after string]\n" + "[%ld zero bytes at end]\n" + "...\n" + "[0 zero bytes at start]\n" + "[%ld bytes shown]\n" + "[0 bytes after string]\n" + "[0 zero bytes at end]\n\n", + original_size, sample - original_size, sample - original_size, + original_size); /* Re-map to mask the region again. */ - err = file_mmap(&file, 0, new_size, 10, new_size - 20, file_region_flags(file.flags)); + err = file_mmap(&file, 0, new_size, 10, new_size - 10, file_region_flags(file.flags)); if (err) { @@ -186,12 +243,26 @@ return 1; } + printf("Region %ld...%ld populated size %ld size %ld.\n", file.start_pos, file.end_pos, file_populated_span(&file), file.size); printf("File contents:\n"); show(&file, step, sample); printf("File shown.\n"); + printf("Expected...\n" + "[10 zero bytes at start]\n" + "[%ld bytes shown]\n" + "[%ld bytes after string]\n" + "[%ld zero bytes at end]\n" + "...\n" + "[0 zero bytes at start]\n" + "[%ld bytes shown]\n" + "[10 bytes after string]\n" + "[10 zero bytes at end]\n", + original_size - 10, sample - original_size, sample - original_size, + original_size - 10); + printf("End of test.\n"); return 0; } diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_block_client_simple.cc --- a/tests/dstest_block_client_simple.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_block_client_simple.cc Thu Sep 01 21:52:41 2022 +0200 @@ -45,8 +45,9 @@ file = client_open(filename, O_RDWR); - if (file == NULL) + if (!client_opened(file)) { + client_close(file); printf("Could not obtain file.\n"); return 1; } @@ -54,6 +55,8 @@ /* Copy the sampled data to another file region. */ offset_t size = file->size; + offset_t new_size = size * (repetition + 1); + char buffer[size]; offset_t nread = client_read(file, buffer, size); @@ -83,7 +86,8 @@ } } - printf("File is now %ld in size.\n", file->size); + printf("File now has size %ld.\n", file->size); + printf("File has expected size %ld: %s\n", new_size, new_size == file->size ? "True" : "False"); printf("Seek to start...\n"); @@ -96,10 +100,8 @@ offset_t position = 0; - while (position < file->size) + while ((nread = client_read(file, buffer, size)) > 0) { - offset_t nread = client_read(file, buffer, size); - if ((nread != size) && (nread != file->size - position)) { printf("Could not read file section: %ld instead of %ld or remaining %ld bytes.\n", @@ -111,8 +113,8 @@ position += nread; } - printf("File shown.\n"); - + printf("File shown in its entirety: %s\n", position == file->size ? "True" : "False"); + printf("End of test.\n"); return 0; } diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_exec.cc --- a/tests/dstest_exec.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_exec.cc Thu Sep 01 21:52:41 2022 +0200 @@ -316,7 +316,14 @@ return 1; } - printf("Finished.\n"); + printf("Finished program initiation.\n"); + printf("End of test.\n"); + + /* NOTE: Should be able to obtain a notification for when the program + finishes, which might be done using a capability deletion IRQ. + Eventually, this program will operate as a server, invoking new + programs and handling termination. This test would then merely + involve the invocation of a utility function. */ while (1) l4_sleep_forever(); diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_ext2fs_client.cc --- a/tests/dstest_ext2fs_client.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_ext2fs_client.cc Thu Sep 01 21:52:41 2022 +0200 @@ -1,7 +1,7 @@ /* - * Test dataspace operations. + * Test libext2fs operations on L4Re-provided files. * - * Copyright (C) 2020, 2021 Paul Boddie + * Copyright (C) 2020, 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -55,7 +55,7 @@ } printf("Access completed.\n"); - + printf("End of test.\n"); return 0; } diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_file_access.cc --- a/tests/dstest_file_access.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_file_access.cc Thu Sep 01 21:52:41 2022 +0200 @@ -47,13 +47,14 @@ file_t *reader = client_opendir(dirname); - if (reader == NULL) + if (!client_opened(reader)) { + client_close(reader); printf("Could not read from directory: %s\n", dirname); continue; } - printf("Reading...\n"); + printf(" Reading...\n"); struct dirent *dirent; @@ -67,31 +68,31 @@ sprintf(path, "%s/%s", dirname, filename); - printf("Attempt to read %s...\n", filename); + printf(" Attempt to read %s...\n", filename); file_t *file = client_open(path, O_RDONLY); - if (file == NULL) - printf("Could not open file: %s\n", filename); + if (!client_opened(file)) + printf(" Could not open file: %s\n", filename); else { char buffer[32]; offset_t nread = client_read(file, buffer, 32); - fputs("Start of file: ", stdout); + fputs(" Start of file:\n----\n", stdout); fwrite(buffer, sizeof(char), nread, stdout); - fputs("\n", stdout); - - client_close(file); + fputs("\n----\n", stdout); } + client_close(file); free(dirent); } - printf("Directory shown.\n"); - + client_close(reader); + printf("Closing directory %s.\n\n", dirname); } + printf("End of test.\n"); return 0; } diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_file_client.cc --- a/tests/dstest_file_client.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_file_client.cc Thu Sep 01 21:52:41 2022 +0200 @@ -111,26 +111,21 @@ if (!(*(buffer + nread - 1))) printf("Warning: length before zero region is %ld\n", strlen(buffer)); -#if 0 - for (offset_t i = 0; i < nread; i += 60) - { - fwrite(buffer + i, sizeof(char), nread - i > 60 ? 60 : nread - i, stdout); - fputs("\n", stdout); - } -#endif nread = client_read(file, buffer, size); } /* Without any more content, a peer closed event should terminate reading - from the pipe. */ + from the file. */ if (file->notifications & NOTIFY_PEER_CLOSED) break; + /* Otherwise, write some data to the file for the other party. */ + write_data(file, region++); } - printf("Data shown.\n"); + printf("Data written: %s\n", region == 26 ? "True" : "False"); } int main(int argc, char *argv[]) @@ -147,8 +142,10 @@ file1 = client_open(filename, O_RDWR | O_CREAT); file2 = client_open(filename, O_RDWR); - if ((file1 == NULL) || (file2 == NULL)) + if (!client_opened(file1) || !client_opened(file2)) { + client_close(file1); + client_close(file2); printf("Could not obtain files.\n"); return 1; } @@ -162,6 +159,8 @@ for (int i = 0; i < 2; i++) activities[i]->join(); + + printf("End of test.\n"); } // vim: tabstop=2 expandtab shiftwidth=2 diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_file_mapping.cc --- a/tests/dstest_file_mapping.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_file_mapping.cc Thu Sep 01 21:52:41 2022 +0200 @@ -1,5 +1,5 @@ /* - * Test dataspace operations. + * Test manual mapping of dataspace content. * * Copyright (C) 2020, 2021, 2022 Paul Boddie * @@ -109,8 +109,7 @@ printf("%s\n", buf); } - printf("File shown.\n"); - + printf("End of test.\n"); return 0; } diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_file_monitor.cc --- a/tests/dstest_file_monitor.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_file_monitor.cc Thu Sep 01 21:52:41 2022 +0200 @@ -34,6 +34,12 @@ +/* Number of files to open in the test. */ + +static const int FILES_TO_OPEN = 10; + + + /* Open files in the directory given by filename. */ static void open_files(const char *filename) @@ -46,7 +52,7 @@ return; } - for (int i = 0; i < 10; i++) + for (int i = 0; i < FILES_TO_OPEN; i++) { sprintf(buffer, "%s/file%02d", filename, i); @@ -67,7 +73,9 @@ return; } - while (1) + int expected; + + for (expected = FILES_TO_OPEN; expected; expected--) { /* Wait for notification of content. */ @@ -81,6 +89,8 @@ printf("Notified with conditions:%s\n", directory->notifications & NOTIFY_FILE_OPENED ? " file opened" : ""); } + + printf("Notified for all expected files: %s\n", expected ? "False" : "True"); } @@ -99,8 +109,9 @@ file_t *directory = client_open(filename, O_DIRECTORY); - if (directory == NULL) + if (!client_opened(directory)) { + client_close(directory); printf("Could not open directory.\n"); return 1; } @@ -115,6 +126,8 @@ for (int i = 0; i < 2; i++) activities[i]->join(); + printf("Expected %d 'file opened' notifications.\n", FILES_TO_OPEN); + printf("End of test.\n"); return 0; } diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_file_readdir.cc --- a/tests/dstest_file_readdir.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_file_readdir.cc Thu Sep 01 21:52:41 2022 +0200 @@ -34,20 +34,22 @@ int main(int argc, char *argv[]) { - if (argc < 2) + if (argc < 3) { - printf("Need a directory name.\n"); + printf("Need a directory name and an expected number of entries.\n"); return 1; } char *filename = argv[1]; + int entries = atoi(argv[2]); printf("Opening %s...\n", filename); file_t *reader = client_opendir(filename); - if (reader == NULL) + if (!client_opened(reader)) { + client_close(reader); printf("Could not read from directory.\n"); return 1; } @@ -55,6 +57,7 @@ printf("Reading...\n"); struct dirent *dirent; + int found = 0; while ((dirent = client_readdir(reader)) != NULL) { @@ -69,6 +72,7 @@ if (client_stat(path, &st)) { + client_close(reader); printf("Could not obtain metadata for file: %s\n", dirent->d_name); return 1; } @@ -97,16 +101,19 @@ 0, 0, ""); free(dirent); + found++; } printf("Directory shown.\n"); + printf("Found expected number of entries: %s\n", found == entries ? "True" : "False"); /* Open again, reading a single entry only. */ reader = client_opendir(filename); - if (reader == NULL) + if (!client_opened(reader)) { + client_close(reader); printf("Could not read from directory.\n"); return 1; } @@ -121,6 +128,7 @@ printf("Entry shown.\n"); + printf("End of test.\n"); return 0; } diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_file_readdir_concurrent.cc --- a/tests/dstest_file_readdir_concurrent.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_file_readdir_concurrent.cc Thu Sep 01 21:52:41 2022 +0200 @@ -36,8 +36,11 @@ file_t *reader = client_opendir(filename); struct dirent *dirent; - if (reader == NULL) + if (!client_opened(reader)) + { + client_close(reader); return 1; + } *found = 0; @@ -70,7 +73,8 @@ printf("Files found: %d\n", original); - struct dirent *dirent; + /* Operate on files with sequence numbering in a certain range. */ + int filenum_base = 1000, filenum = filenum_base; int to_create = 100, remaining = to_create; char buffer[strlen(filename) + strlen("/file-XXXX.txt") + 10]; @@ -78,16 +82,23 @@ int found = 0; file_t *files[to_create]; + /* Open a directory for reading. */ + printf("Opening %s...\n", filename); file_t *reader = client_opendir(filename); - if (reader == NULL) + if (!client_opened(reader)) { + client_close(reader); printf("Could not read from directory.\n"); return 1; } + /* Read entries from the directory. */ + + struct dirent *dirent; + printf("Reading...\n"); while ((dirent = client_readdir(reader)) != NULL) @@ -103,8 +114,9 @@ file_t *file = client_open(buffer, O_RDWR | O_CREAT); - if (file == NULL) + if (!client_opened(file)) { + client_close(file); printf("Could not open file: %s\n", buffer); return 1; } @@ -183,6 +195,7 @@ } printf("Files still open: %d (%d)\n", found, to_create); + printf("All created files still open: %s\n", found == to_create ? "True" : "False"); /* Close the files. */ @@ -200,7 +213,8 @@ } printf("Files found: %d (%d)\n", found, original); - + printf("Removed all surplus files: %s\n", found == original ? "True" : "False"); + printf("End of test.\n"); return 0; } diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_file_remove.cc --- a/tests/dstest_file_remove.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_file_remove.cc Thu Sep 01 21:52:41 2022 +0200 @@ -84,8 +84,9 @@ file = client_open(filename, O_RDONLY); - if (file == NULL) + if (!client_opened(file)) { + client_close(file); printf("Could not open file: %s\n", filename); return 1; } @@ -112,7 +113,7 @@ file_t *file_new = client_open(filename, O_RDONLY); - if (file_new != NULL) + if (client_opened(file_new)) { printf("File should be absent: %s\n", filename); return 1; @@ -120,8 +121,9 @@ file_new = client_open(filename, O_RDWR | O_CREAT); - if (file_new == NULL) + if (!client_opened(file_new)) { + client_close(file_new); printf("File should be present: %s\n", filename); return 1; } @@ -138,8 +140,7 @@ client_close(file); client_close(file_new); - printf("End of tests.\n"); - + printf("End of test.\n"); return 0; } diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_file_rename.cc --- a/tests/dstest_file_rename.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_file_rename.cc Thu Sep 01 21:52:41 2022 +0200 @@ -38,8 +38,9 @@ { file_t *reader = client_opendir(filename); - if (reader == NULL) + if (!client_opened(reader)) { + client_close(reader); printf("Could not read from directory.\n"); return 1; } @@ -82,8 +83,9 @@ file_t *reader = client_opendir(filename); - if (reader == NULL) + if (!client_opened(reader)) { + client_close(reader); printf("Could not read from directory.\n"); return 1; } @@ -138,8 +140,9 @@ reader = client_opendir(filename); - if (reader == NULL) + if (!client_opened(reader)) { + client_close(reader); printf("Could not read from directory.\n"); return 1; } @@ -170,8 +173,7 @@ if (show_directory(newdir, to_rename)) return 1; - printf("End of tests.\n"); - + printf("End of test.\n"); return 0; } diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_pipe_client.cc --- a/tests/dstest_pipe_client.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_pipe_client.cc Thu Sep 01 21:52:41 2022 +0200 @@ -1,7 +1,7 @@ /* * Test pipe operations. * - * Copyright (C) 2020, 2021 Paul Boddie + * Copyright (C) 2020, 2021, 2022 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -34,12 +34,18 @@ +/* Common size and iteration details. */ + +const offset_t TO_TRANSFER = 600; +const int NUMBER_OF_ITERATIONS = 3; + + + /* Use the writer to fill the pipe with data. */ static void write_pipe(file_t *writer, int number) { - offset_t size = 600; - char buffer[size]; + char buffer[TO_TRANSFER]; long err; /* Make writers blocking to permit synchronisation. */ @@ -50,15 +56,15 @@ return; } - for (int loop = 0; loop < 3; loop++) + for (int loop = 0; loop < NUMBER_OF_ITERATIONS; loop++) { for (int region = 0; region < 26; region++) { - memset(buffer, (int) 'a' + region, size); + memset(buffer, (int) 'a' + region, TO_TRANSFER); - offset_t nwritten = client_write(writer, buffer, size); + offset_t nwritten = client_write(writer, buffer, TO_TRANSFER); - printf("Written %ld/%ld in #%d of %d/%d to pipe #%d...\n", nwritten, size, region, loop, 2, number); + printf("Written %ld/%ld in #%d of %d/%d to pipe #%d...\n", nwritten, TO_TRANSFER, region, loop, 2, number); } sleep(1); @@ -73,7 +79,7 @@ static void read_pipes(file_t *reader1, file_t *reader2) { - offset_t size = 600, totals[] = {0, 0}; + offset_t totals[] = {0, 0}; unsigned int active = 2; long err; file_t *reader; @@ -93,7 +99,7 @@ while (1) { - char buffer[size]; + char buffer[TO_TRANSFER]; offset_t nread; /* Wait for notification of content. */ @@ -118,21 +124,14 @@ printf("Pipe #%d notified with conditions:%s%s\n", p + 1, reader->notifications & NOTIFY_PEER_CLOSED ? " closed" : "", reader->notifications & NOTIFY_CONTENT_AVAILABLE ? " content" : ""); - nread = client_read(reader, buffer, size); + nread = client_read(reader, buffer, TO_TRANSFER); while (nread) { totals[p] += nread; - printf("Read %ld/%ld, total %ld, first %c, last %c, from pipe #%d...\n", nread, size, totals[p], *buffer, *(buffer + nread - 1), p + 1); -#if 0 - for (offset_t i = 0; i < nread; i += 60) - { - fwrite(buffer + i, sizeof(char), nread - i > 60 ? 60 : nread - i, stdout); - fputs("\n", stdout); - } -#endif - nread = client_read(reader, buffer, size); + printf("Read %ld/%ld, total %ld, first %c, last %c, from pipe #%d...\n", nread, TO_TRANSFER, totals[p], *buffer, *(buffer + nread - 1), p + 1); + nread = client_read(reader, buffer, TO_TRANSFER); } /* Without any more content, a peer closed event should terminate reading @@ -150,7 +149,11 @@ client_close(reader2); client_notifier_close(notifier); - printf("Data shown.\n"); + for (int p = 0; p < 2; p++) + { + printf("Data received for pipe #%d: %ld\n", p, totals[p]); + printf("Data shown for pipe #%d: %s\n", p, totals[p] == TO_TRANSFER * 26 * NUMBER_OF_ITERATIONS ? "True" : "False"); + } } int main(void) diff -r f27aad83b42f -r dbc8c17a4f81 tests/dstest_test_client.cc --- a/tests/dstest_test_client.cc Thu Sep 01 21:40:39 2022 +0200 +++ b/tests/dstest_test_client.cc Thu Sep 01 21:52:41 2022 +0200 @@ -237,6 +237,8 @@ t = time(NULL) - t; printf("Activities completed in %ld seconds (with %ld threads not started).\n", t, errors); + printf("All threads started: %s\n", errors ? "False" : "True"); + printf("End of test.\n"); return 0; }