# HG changeset patch # User Paul Boddie # Date 1679185103 -3600 # Node ID 9e465646b8590e0426839ce5b5ffc4dfc3ce2166 # Parent 86d76cd9a8d37e082a4cb72b59b4511d8f1c28c7 Made a separate test payload and program for file-related testing. diff -r 86d76cd9a8d3 -r 9e465646b859 conf/dstest_exec_many.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_exec_many.cfg Sun Mar 19 01:18:23 2023 +0100 @@ -0,0 +1,66 @@ +-- vim:set ft=lua: + +local L4 = require("L4"); + +local l = L4.default_loader; + +local pipe_server = l:new_channel(); + +l:startv({ + caps = { + pipeserver = pipe_server:svr(), + jdb = L4.Env.jdb, -- to set the server name + }, + log = { "pipes", "r" }, + }, + "rom/pipe_server", "10"); + +local block_server = l:new_channel(); + +l:startv({ + caps = { + fsserver = block_server:svr(), + jdb = L4.Env.jdb, -- to set the server name + }, + log = { "blocks", "r" }, + }, + "rom/block_server", "10"); + +local ext2server = l:new_channel(); + +l:startv({ + caps = { + blockserver = block_server, + pipeserver = pipe_server, + fsserver = ext2server:svr(), + jdb = L4.Env.jdb, -- to set the server name + }, + log = { "ext2", "y" }, + }, + "rom/ext2_server", "blockserver", "rom/e2test.fs", "20", "fsserver"); + +-- Obtain user filesystems with umask 0022 (18). + +local open_for_user = 6; +local ext2server_paulb = L4.cast(L4.Proto.Factory, ext2server):create(open_for_user, 1000, 1000, 18); + +local process_server = l:new_channel(); + +l:startv({ + caps = { + fsserver = ext2server_paulb, + prserver = process_server:svr(), + jdb = L4.Env.jdb, -- to set the server name + }, + log = { "process", "y" }, + }, + "rom/process_server", "home/paulb/exec_region_mapper"); + +l:startv({ + caps = { + fsserver = ext2server_paulb, + prserver = process_server, + }, + log = { "client", "g" }, + }, + "rom/dstest_exec_many", "20", "home/paulb/clip", "home/paulb/LICENCE.txt", "21", "1"); diff -r 86d76cd9a8d3 -r 9e465646b859 conf/dstest_exec_many.list --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf/dstest_exec_many.list Sun Mar 19 01:18:23 2023 +0100 @@ -0,0 +1,29 @@ +entry dstest_exec_many +roottask moe rom/dstest_exec_many.cfg +module dstest_exec_many.cfg +module e2test.fs +module l4re +module ned +module dstest_exec_many +module ext2_server +module block_server +module pipe_server +module process_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 86d76cd9a8d3 -r 9e465646b859 test_files/programs/Makefile --- a/test_files/programs/Makefile Sun Mar 19 00:49:19 2023 +0100 +++ b/test_files/programs/Makefile Sun Mar 19 01:18:23 2023 +0100 @@ -1,10 +1,12 @@ PKGDIR ?= .. L4DIR ?= $(PKGDIR)/../../.. -TARGET = dstest_exec_payload +TARGET = clip dstest_exec_payload MODE = static +SRC_C_clip = clip.c + SRC_C_dstest_exec_payload = dstest_exec_payload.c REQUIRES_LIBS = libc libfsclient l4re_c-util libsystypes diff -r 86d76cd9a8d3 -r 9e465646b859 test_files/programs/clip.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test_files/programs/clip.c Sun Mar 19 01:18:23 2023 +0100 @@ -0,0 +1,157 @@ +/* + * Show lines from a file. + * + * Copyright (C) 2022, 2023 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 + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include + +#include +#include +#include + +#include +#include +#include + + + +/* Read a line from the file. */ + +static int readline(file_t *file, int *lineno, char **start, char **end) +{ + static char buf[256]; + static offset_t current = 0, limit = 0; + char *newline = NULL; + + do + { + /* Obtain file content. */ + + if (!limit) + { + limit = client_read(file, buf, 256); + + if (!limit) + { + *start = NULL; + *end = NULL; + return 0; + } + + current = 0; + + /* Start of line at start of buffer. */ + + if (newline != NULL) + { + current += 1; + *start = buf; + *end = (char *) memchr(buf + current, (int) '\n', limit - current); + + if (*end == NULL) + *end = buf + limit; + + return 1; + } + } + + /* Find newline. */ + + newline = (char *) memchr(buf + current, (int) '\n', limit - current); + + if (newline != NULL) + { + (*lineno)++; + current = newline - (char *) buf + 1; + + /* Start of line before end of buffer. */ + + if (current < limit) + { + *start = newline + 1; + *end = (char *) memchr(buf + current, (int) '\n', limit - current); + + if (*end == NULL) + *end = buf + limit; + + return 1; + } + + /* Otherwise, reset the buffer to read the start of line. */ + + else + limit = 0; + } + + /* No newline: read more data. */ + + else + limit = 0; + } + while (1); +} + + + +int main(int argc, char *argv[]) +{ + file_t *file; + int i, startline, numlines; + char *start, *end; + + if (argc < 4) + return 1; + + file = client_open(argv[1], O_RDONLY); + + if (!client_opened(file)) + { + if (file != NULL) + printf("Error: %s\n", l4sys_errtostr(file->error)); + else + printf("Could not open file.\n"); + + while (1); + } + + startline = atoi(argv[2]); + numlines = atoi(argv[3]); + + i = 1; + while (i < startline) + if (!readline(file, &i, &start, &end)) + break; + + while (i < startline + numlines) + { + fwrite(start, sizeof(char), end - start, stdout); + if (!readline(file, &i, &start, &end)) + break; + } + + fputs("\n\n", stdout); + + client_close(file); + client_notifier_close(client_notifier_task()); + + return 0; +} + +/* vim: tabstop=2 expandtab shiftwidth=2 +*/ diff -r 86d76cd9a8d3 -r 9e465646b859 test_files/programs/dstest_exec_payload.c --- a/test_files/programs/dstest_exec_payload.c Sun Mar 19 00:49:19 2023 +0100 +++ b/test_files/programs/dstest_exec_payload.c Sun Mar 19 01:18:23 2023 +0100 @@ -19,151 +19,17 @@ * Boston, MA 02110-1301, USA */ -#include -#include - #include -#include -#include - -#include -#include -#include - - - -/* Read a line from the file. */ - -static int readline(file_t *file, int *lineno, char **start, char **end) -{ - static char buf[256]; - static offset_t current = 0, limit = 0; - char *newline = NULL; - - do - { - /* Obtain file content. */ - - if (!limit) - { - limit = client_read(file, buf, 256); - - if (!limit) - { - *start = NULL; - *end = NULL; - return 0; - } - - current = 0; - - /* Start of line at start of buffer. */ - - if (newline != NULL) - { - current += 1; - *start = buf; - *end = (char *) memchr(buf + current, (int) '\n', limit - current); - - if (*end == NULL) - *end = buf + limit; - - return 1; - } - } - - /* Find newline. */ - - newline = (char *) memchr(buf + current, (int) '\n', limit - current); - - if (newline != NULL) - { - (*lineno)++; - current = newline - (char *) buf + 1; - - /* Start of line before end of buffer. */ - - if (current < limit) - { - *start = newline + 1; - *end = (char *) memchr(buf + current, (int) '\n', limit - current); - - if (*end == NULL) - *end = buf + limit; - - return 1; - } - - /* Otherwise, reset the buffer to read the start of line. */ - - else - limit = 0; - } - - /* No newline: read more data. */ - - else - limit = 0; - } - while (1); -} int main(int argc, char *argv[]) { - file_t *file; - int i, lineno; - char *start, *end; - - printf("Hello from %s (%d)!\n", argc > 0 ? argv[0] : "exec_payload.c", argc); + int i; for (i = 0; i < argc; i++) printf("Arg #%d: %s\n", i, argv[i]); - if (argc < 2) - return 1; - - printf("Filesystem is %lx\n", l4re_env_get_cap(ENV_FILESYSTEM_SERVER_NAME)); - printf("Opening file %s...\n", argv[1]); - - file = client_open(argv[1], O_RDONLY); - - if (!client_opened(file)) - { - if (file != NULL) - printf("Error: %s\n", l4sys_errtostr(file->error)); - else - printf("Could not open file.\n"); - - while (1); - } - - lineno = atoi(argv[2]); - - printf("Finding line %d...\n", lineno); - - i = 1; - while (i < lineno) - if (!readline(file, &i, &start, &end)) - break; - - printf("Showing line %d...\n", lineno); - - while (i == lineno) - { - fwrite(start, sizeof(char), end - start, stdout); - if (!readline(file, &i, &start, &end)) - break; - } - - fputs("\n\n", stdout); - - printf("Closing file...\n"); - - client_close(file); - client_notifier_close(client_notifier_task()); - printf("Terminating.\n"); return 0; } diff -r 86d76cd9a8d3 -r 9e465646b859 tests/Makefile --- a/tests/Makefile Sun Mar 19 00:49:19 2023 +0100 +++ b/tests/Makefile Sun Mar 19 01:18:23 2023 +0100 @@ -17,6 +17,7 @@ dstest_test_client \ dstest_map_test \ dstest_exec \ + dstest_exec_many \ dstest_file_mapping MODE = static @@ -67,8 +68,9 @@ SRC_CC_dstest_test_client = dstest_test_client.cc -PLAIN_SRC_CC_dstest_exec = dstest_exec.cc -SRC_CC_dstest_exec = $(PLAIN_SRC_CC_dstest_exec) $(CLIENT_INTERFACES_SRC_CC_dstest_exec) +SRC_CC_dstest_exec = dstest_exec.cc + +SRC_CC_dstest_exec_many = dstest_exec_many.cc PLAIN_SRC_CC_dstest_file_mapping = dstest_file_mapping.cc SRC_CC_dstest_file_mapping = $(PLAIN_SRC_CC_dstest_file_mapping) $(CLIENT_INTERFACES_SRC_CC_dstest_file_mapping) diff -r 86d76cd9a8d3 -r 9e465646b859 tests/dstest_exec.cc --- a/tests/dstest_exec.cc Sun Mar 19 00:49:19 2023 +0100 +++ b/tests/dstest_exec.cc Sun Mar 19 01:18:23 2023 +0100 @@ -1,5 +1,5 @@ /* - * Support for executing code in new tasks and threads. + * A test of executing code in new tasks and threads. * * Copyright (C) 2022, 2023 Paul Boddie * @@ -19,9 +19,7 @@ * Boston, MA 02110-1301, USA */ -#include #include -#include #include #include @@ -42,11 +40,15 @@ /* Create a new process structure. */ - process_t *process = process_new(); + process_t process; + + process_init(&process); + + printf("Start process...\n"); /* Start a process for the given program. */ - err = process_start(process, argc - 1, argv + 1); + err = process_start(&process, argc - 1, argv + 1); if (err) { @@ -62,7 +64,7 @@ /* Subscribe to the process for notifications. */ - err = process_notify_subscribe(process, NOTIFY_TASK_SIGNAL, notifier); + err = process_notify_subscribe(&process, NOTIFY_TASK_SIGNAL, notifier); if (err) { @@ -72,7 +74,7 @@ /* Wait for a signal from the process. */ - err = process_notify_wait_process(process, notifier); + err = process_notify_wait_process(&process, notifier); if (err) { @@ -80,11 +82,12 @@ return 1; } - notify_flags_t flags = process_notifications(process); - notify_values_t values = process_notification_values(process); + notify_flags_t flags = process_notifications(&process); + notify_values_t values = process_notification_values(&process); - printf("Notified with flags: %" pFMTnotify_flags "x\n", flags); - printf("Notified with values: %ld, %ld\n", values.sig, values.val); + process_close(&process); + + printf("End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", flags, values.sig, values.val); printf("End of test.\n"); return 0; diff -r 86d76cd9a8d3 -r 9e465646b859 tests/dstest_exec_many.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/dstest_exec_many.cc Sun Mar 19 01:18:23 2023 +0100 @@ -0,0 +1,103 @@ +/* + * A test of executing code in new tasks and threads. + * + * Copyright (C) 2022, 2023 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 + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#include + +#include +#include + +#include +#include + + + +int main(int argc, char *argv[]) +{ + long err; + + if (argc < 3) + { + printf("Need a number and the program to run.\n"); + return 1; + } + + int num_processes = atoi(argv[1]); + + /* Create a new process structure. */ + + process_t process; + + process_init(&process); + + for (int i = 1; i <= num_processes; i++) + { + printf("[%d/%d] Start process...\n", i, num_processes); + + /* Start a process for the given program. */ + + err = process_start(&process, argc - 2, argv + 2); + + if (err) + { + printf("Could not start process: %s\n", l4sys_errtostr(err)); + return 1; + } + + printf("Finished program initiation.\n"); + + /* Obtain the common notifier. */ + + process_notifier_t *notifier = process_notify_task(); + + /* Subscribe to the process for notifications. */ + + err = process_notify_subscribe(&process, NOTIFY_TASK_SIGNAL, notifier); + + if (err) + { + printf("Could not subscribe to process: %s\n", l4sys_errtostr(err)); + return 1; + } + + /* Wait for a signal from the process. */ + + err = process_notify_wait_process(&process, notifier); + + if (err) + { + printf("Could not wait for process: %s\n", l4sys_errtostr(err)); + return 1; + } + + notify_flags_t flags = process_notifications(&process); + notify_values_t values = process_notification_values(&process); + + process_close(&process); + + printf("[%d/%d] End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", i, num_processes, flags, values.sig, values.val); + } + + printf("End of test.\n"); + return 0; +} + +/* vim: tabstop=2 expandtab shiftwidth=2 +*/