L4Re/departure

Changeset

513:7f39fb2e0f38
2023-03-13 Paul Boddie raw files shortlog changelog graph Expanded the execution test payload to test filesystem access.
conf/dstest_exec.cfg (file) test_files/Control (file) test_files/programs/Makefile (file) test_files/programs/dstest_exec_payload.c (file)
     1.1 --- a/conf/dstest_exec.cfg	Fri Mar 10 18:54:41 2023 +0100
     1.2 +++ b/conf/dstest_exec.cfg	Mon Mar 13 00:40:16 2023 +0100
     1.3 @@ -59,4 +59,4 @@
     1.4      },
     1.5      log = { "client", "g" },
     1.6    },
     1.7 -  "rom/dstest_exec", "home/paulb/dstest_exec_payload", "hello", "world");
     1.8 +  "rom/dstest_exec", "home/paulb/dstest_exec_payload", "home/paulb/LICENCE.txt", "21");
     2.1 --- a/test_files/Control	Fri Mar 10 18:54:41 2023 +0100
     2.2 +++ b/test_files/Control	Mon Mar 13 00:40:16 2023 +0100
     2.3 @@ -1,3 +1,3 @@
     2.4  provides: fstest_files
     2.5 -requires: libc libstdc++ libexec libipc
     2.6 +requires: libc libstdc++ libexec libfsclient libsystypes l4re_c-util
     2.7  maintainer: paul@boddie.org.uk
     3.1 --- a/test_files/programs/Makefile	Fri Mar 10 18:54:41 2023 +0100
     3.2 +++ b/test_files/programs/Makefile	Mon Mar 13 00:40:16 2023 +0100
     3.3 @@ -7,6 +7,6 @@
     3.4  
     3.5  SRC_C_dstest_exec_payload	= dstest_exec_payload.c
     3.6  
     3.7 -REQUIRES_LIBS	= libc
     3.8 +REQUIRES_LIBS	= libc libfsclient l4re_c-util libsystypes
     3.9  
    3.10  include $(L4DIR)/mk/prog.mk
     4.1 --- a/test_files/programs/dstest_exec_payload.c	Fri Mar 10 18:54:41 2023 +0100
     4.2 +++ b/test_files/programs/dstest_exec_payload.c	Mon Mar 13 00:40:16 2023 +0100
     4.3 @@ -1,7 +1,7 @@
     4.4  /*
     4.5   * A test of executing code in a new task.
     4.6   *
     4.7 - * Copyright (C) 2022 Paul Boddie <paul@boddie.org.uk>
     4.8 + * Copyright (C) 2022, 2023 Paul Boddie <paul@boddie.org.uk>
     4.9   *
    4.10   * This program is free software; you can redistribute it and/or
    4.11   * modify it under the terms of the GNU General Public License as
    4.12 @@ -19,19 +19,152 @@
    4.13   * Boston, MA  02110-1301, USA
    4.14   */
    4.15  
    4.16 +#include <l4/re/env.h>
    4.17 +#include <l4/sys/err.h>
    4.18 +
    4.19  #include <stdio.h>
    4.20 +#include <stdlib.h>
    4.21 +#include <string.h>
    4.22 +
    4.23 +#include <fsclient/client.h>
    4.24 +#include <systypes/env.h>
    4.25 +#include <systypes/fcntl.h>
    4.26 +
    4.27 +
    4.28 +
    4.29 +/* Read a line from the file. */
    4.30 +
    4.31 +static int readline(file_t *file, int *lineno, char **start, char **end)
    4.32 +{
    4.33 +  static char buf[256];
    4.34 +  static offset_t current = 0, limit = 0;
    4.35 +  char *newline = NULL;
    4.36 +
    4.37 +  do
    4.38 +  {
    4.39 +    /* Obtain file content. */
    4.40 +
    4.41 +    if (!limit)
    4.42 +    {
    4.43 +      limit = client_read(file, buf, 256);
    4.44 +
    4.45 +      if (!limit)
    4.46 +      {
    4.47 +        *start = NULL;
    4.48 +        *end = NULL;
    4.49 +        return 0;
    4.50 +      }
    4.51 +
    4.52 +      current = 0;
    4.53 +
    4.54 +      /* Start of line at start of buffer. */
    4.55 +
    4.56 +      if (newline != NULL)
    4.57 +      {
    4.58 +        current += 1;
    4.59 +        *start = buf;
    4.60 +        *end = (char *) memchr(buf + current, (int) '\n', limit - current);
    4.61 +
    4.62 +        if (*end == NULL)
    4.63 +          *end = buf + limit;
    4.64 +
    4.65 +        return 1;
    4.66 +      }
    4.67 +    }
    4.68 +
    4.69 +    /* Find newline. */
    4.70 +
    4.71 +    newline = (char *) memchr(buf + current, (int) '\n', limit);
    4.72 +
    4.73 +    if (newline != NULL)
    4.74 +    {
    4.75 +      (*lineno)++;
    4.76 +      current = newline - (char *) buf + 1;
    4.77 +
    4.78 +      /* Start of line before end of buffer. */
    4.79 +
    4.80 +      if (current < limit)
    4.81 +      {
    4.82 +        *start = newline + 1;
    4.83 +        *end = (char *) memchr(buf + current, (int) '\n', limit - current);
    4.84 +
    4.85 +        if (*end == NULL)
    4.86 +          *end = buf + limit;
    4.87 +
    4.88 +        return 1;
    4.89 +      }
    4.90 +
    4.91 +      /* Otherwise, reset the buffer to read the start of line. */
    4.92 +
    4.93 +      else
    4.94 +        limit = 0;
    4.95 +    }
    4.96 +
    4.97 +    /* No newline: read more data. */
    4.98 +
    4.99 +    else
   4.100 +      limit = 0;
   4.101 +  }
   4.102 +  while (1);
   4.103 +}
   4.104  
   4.105  
   4.106  
   4.107  int main(int argc, char *argv[])
   4.108  {
   4.109 -  int i;
   4.110 +  file_t *file;
   4.111 +  int i, lineno;
   4.112 +  char *start, *end;
   4.113  
   4.114    printf("Hello from %s (%d)!\n", argc > 0 ? argv[0] : "exec_payload.c", argc);
   4.115  
   4.116    for (i = 0; i < argc; i++)
   4.117      printf("Arg #%d: %s\n", i, argv[i]);
   4.118  
   4.119 +  if (argc < 2)
   4.120 +    return 1;
   4.121 +
   4.122 +  printf("Filesystem is %lx\n", l4re_env_get_cap(ENV_FILESYSTEM_SERVER_NAME));
   4.123 +  printf("Opening file %s...\n", argv[1]);
   4.124 +
   4.125 +  file = client_open(argv[1], O_RDONLY);
   4.126 +
   4.127 +  if (!client_opened(file))
   4.128 +  {
   4.129 +    if (file != NULL)
   4.130 +      printf("Error: %s\n", l4sys_errtostr(file->error));
   4.131 +    else
   4.132 +      printf("Could not open file.\n");
   4.133 +
   4.134 +    while (1);
   4.135 +  }
   4.136 +
   4.137 +  lineno = atoi(argv[2]);
   4.138 +
   4.139 +  printf("Finding line %d...\n", lineno);
   4.140 +
   4.141 +  i = 1;
   4.142 +  while (i < lineno)
   4.143 +    if (!readline(file, &i, &start, &end))
   4.144 +      break;
   4.145 +
   4.146 +  printf("Showing line %d...\n", lineno);
   4.147 +
   4.148 +  while (i == lineno)
   4.149 +  {
   4.150 +    fwrite(start, sizeof(char), end - start, stdout);
   4.151 +    if (!readline(file, &i, &start, &end))
   4.152 +      break;
   4.153 +  }
   4.154 +
   4.155 +  fputs("\n\n", stdout);
   4.156 +
   4.157 +  printf("Closing file...\n");
   4.158 +
   4.159 +  client_close(file);
   4.160 +  client_notifier_close(client_notifier_task());
   4.161 +
   4.162 +  printf("Terminating.\n");
   4.163    return 0;
   4.164  }
   4.165