L4Re/departure

Annotated tests/dstest_exec_many.cc

644:1625ea971bf8
7 months ago Paul Boddie Merged changes from the default branch. libc_newlib
paul@525 1
/*
paul@525 2
 * A test of executing code in new tasks and threads.
paul@525 3
 *
paul@615 4
 * Copyright (C) 2022, 2023, 2024 Paul Boddie <paul@boddie.org.uk>
paul@525 5
 *
paul@525 6
 * This program is free software; you can redistribute it and/or
paul@525 7
 * modify it under the terms of the GNU General Public License as
paul@525 8
 * published by the Free Software Foundation; either version 2 of
paul@525 9
 * the License, or (at your option) any later version.
paul@525 10
 *
paul@525 11
 * This program is distributed in the hope that it will be useful,
paul@525 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@525 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@525 14
 * GNU General Public License for more details.
paul@525 15
 *
paul@525 16
 * You should have received a copy of the GNU General Public License
paul@525 17
 * along with this program; if not, write to the Free Software
paul@525 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
paul@525 19
 * Boston, MA  02110-1301, USA
paul@525 20
 */
paul@525 21
paul@525 22
#include <l4/sys/err.h>
paul@525 23
paul@525 24
#include <fsclient/process.h>
paul@525 25
#include <systypes/format.h>
paul@525 26
paul@525 27
#include <stdio.h>
paul@525 28
#include <stdlib.h>
paul@525 29
paul@525 30
paul@525 31
paul@525 32
int main(int argc, char *argv[])
paul@525 33
{
paul@525 34
  long err;
paul@525 35
paul@525 36
  if (argc < 3)
paul@525 37
  {
paul@525 38
    printf("Need a number and the program to run.\n");
paul@525 39
    return 1;
paul@525 40
  }
paul@525 41
paul@525 42
  int num_processes = atoi(argv[1]);
paul@525 43
paul@525 44
  for (int i = 1; i <= num_processes; i++)
paul@525 45
  {
paul@525 46
    printf("[%d/%d] Start process...\n", i, num_processes);
paul@525 47
paul@525 48
    /* Start a process for the given program. */
paul@525 49
paul@578 50
    process_t *process;
paul@578 51
paul@615 52
    err = process_spawn(argc - 2, (const char **) argv + 2, NULL, NULL, &process);
paul@525 53
paul@525 54
    if (err)
paul@525 55
    {
paul@525 56
      printf("Could not start process: %s\n", l4sys_errtostr(err));
paul@525 57
      return 1;
paul@525 58
    }
paul@525 59
paul@525 60
    printf("Finished program initiation.\n");
paul@525 61
paul@525 62
    /* Wait for a signal from the process. */
paul@525 63
paul@578 64
    notify_flags_t flags;
paul@578 65
    notify_values_t values;
paul@578 66
paul@578 67
    err = process_wait(process, &flags, &values);
paul@525 68
paul@525 69
    if (err)
paul@525 70
    {
paul@525 71
      printf("Could not wait for process: %s\n", l4sys_errtostr(err));
paul@525 72
      return 1;
paul@525 73
    }
paul@525 74
paul@559 75
    printf("[%d/%d] End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", i, num_processes, flags, values.sig, values.val);
paul@525 76
  }
paul@525 77
paul@525 78
  printf("End of test.\n");
paul@525 79
  return 0;
paul@525 80
}
paul@525 81
paul@525 82
/* vim: tabstop=2 expandtab shiftwidth=2
paul@525 83
*/