Re: [PATCH v2 1/1] newlib01: Check exit procs for global FILE obj

2022-03-28 Thread Joel Sherrill
I don't see anything obviously wrong but I don't have any idea what the
test is actually trying to exercise.

How about some comments and is there a doc file in this test directory that
needs updating?

--joel

On Mon, Mar 28, 2022 at 4:04 AM Matthew Joyce <
matthew.jo...@embedded-brains.de> wrote:

> From: Matt Joyce 
>
> ---
>  testsuites/libtests/newlib01/init.c | 110 ++--
>  1 file changed, 88 insertions(+), 22 deletions(-)
>
> diff --git a/testsuites/libtests/newlib01/init.c
> b/testsuites/libtests/newlib01/init.c
> index c58154023b..bba187e8e2 100644
> --- a/testsuites/libtests/newlib01/init.c
> +++ b/testsuites/libtests/newlib01/init.c
> @@ -28,6 +28,8 @@ const char rtems_test_name[] = "NEWLIB 1";
>
>  static const char file_path[] = "/file";
>
> +static const char file_path2[] = "/file2";
> +
>  typedef enum {
>INIT,
>OPEN,
> @@ -39,6 +41,8 @@ typedef struct {
>rtems_id main_task_id;
>rtems_id worker_task_id;
>test_state current;
> +  FILE *glob_file_stream;
> +  int glob_fd;
>  } test_context;
>
>  static test_context test_instance;
> @@ -59,7 +63,7 @@ static void wait(void)
>rtems_test_assert(sc == RTEMS_SUCCESSFUL);
>  }
>
> -static void worker_task(rtems_task_argument arg)
> +static void thread_specific_worker(rtems_task_argument arg)
>  {
>test_context *ctx = &test_instance;
>struct _reent *reent = _REENT;
> @@ -90,6 +94,30 @@ static void worker_task(rtems_task_argument arg)
>rtems_test_assert(0);
>  }
>
> +static void global_file_object_worker(rtems_task_argument arg)
> +{
> +  test_context *ctx = &test_instance;
> +  FILE *fp;
> +  char buf[1] = { 'y' };
> +  size_t n;
> +  int fd;
> +
> +  fp = ctx->glob_file_stream = fopen(&file_path2[0], "w");
> +  rtems_test_assert(fp != NULL);
> +
> +  /* Get file descriptor of new global file stream, store it in text
> context */
> +  fd = fileno(fp);
> +  rtems_test_assert(fd != -1);
> +  ctx->glob_fd = fd;
> +
> +  n = fwrite(&buf[0], sizeof(buf), 1, fp);
> +  rtems_test_assert(n == 1);
> +
> +  wake_up_main(ctx);
> +
> +  rtems_test_assert(0);
> +}
> +
>  static int handler_open(
>rtems_libio_t *iop,
>const char *path,
> @@ -250,9 +278,34 @@ static const IMFS_node_control node_control =
> IMFS_GENERIC_INITIALIZER(
>IMFS_node_destroy_default
>  );
>
> -static void test_thread_specific_close(test_context *ctx)
> +static void task_create_and_delete_helper(
> +  test_context *ctx,
> +  rtems_task_entry entry
> +)
>  {
>rtems_status_code sc;
> +
> +  sc = rtems_task_create(
> +  rtems_build_name('W', 'O', 'R', 'K'),
> +  2,
> +  RTEMS_MINIMUM_STACK_SIZE,
> +  RTEMS_DEFAULT_MODES,
> +  RTEMS_DEFAULT_ATTRIBUTES,
> +  &ctx->worker_task_id
> +  );
> +  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> +
> +  sc = rtems_task_start(ctx->worker_task_id, entry, 0);
> +  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> +
> +  wait();
> +
> +  sc = rtems_task_delete(ctx->worker_task_id);
> +  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> +}
> +
> +static void test_thread_specific_close(test_context *ctx)
> +{
>int rv;
>rtems_resource_snapshot snapshot;
>
> @@ -266,23 +319,7 @@ static void test_thread_specific_close(test_context
> *ctx)
>);
>rtems_test_assert(rv == 0);
>
> -  sc = rtems_task_create(
> -rtems_build_name('W', 'O', 'R', 'K'),
> -2,
> -RTEMS_MINIMUM_STACK_SIZE,
> -RTEMS_DEFAULT_MODES,
> -RTEMS_DEFAULT_ATTRIBUTES,
> -&ctx->worker_task_id
> -  );
> -  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> -
> -  sc = rtems_task_start(ctx->worker_task_id, worker_task, 0);
> -  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> -
> -  wait();
> -
> -  sc = rtems_task_delete(ctx->worker_task_id);
> -  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> +  task_create_and_delete_helper(ctx, thread_specific_worker);
>
>rv = unlink(&file_path[0]);
>rtems_test_assert(rv == 0);
> @@ -290,6 +327,11 @@ static void test_thread_specific_close(test_context
> *ctx)
>rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
>  }
>
> +static void test_global_file_object_close(test_context *ctx)
> +{
> +  task_create_and_delete_helper(ctx, global_file_object_worker);
> +}
> +
>  /*
>   * This exit handler will be called last among the functions registered
> with
>   * atexit(). Check that stdio file descriptors are closed. The Newlib
> cleanup
> @@ -298,6 +340,7 @@ static void test_thread_specific_close(test_context
> *ctx)
>   */
>  static void check_after_libio_exit(void)
>  {
> +  test_context *ctx = &test_instance;
>struct stat unused;
>int rv;
>
> @@ -319,6 +362,11 @@ static void check_after_libio_exit(void)
>rtems_test_assert(stdin->_flags != 0);
>rtems_test_assert(stdout->_flags != 0);
>rtems_test_assert(stderr->_flags != 0);
> +
> +  /* Global file tests. Global fd still open at this point. */
> +  rv = fstat(ctx->glob_fd, &unused);
> +  rtems_test_assert(rv == 0);
> +  rtems_test_assert(ctx->glob_file_stream->_flags != 0);
>  }
>
>  static void r

Re: GSoC: Hello World Patch

2022-03-28 Thread Joel Sherrill
Looks good. Email (or send it to me on Discord) a screenshot in gdb with
that program.

Then add yourself  to https://devel.rtems.org/wiki/GSoC/2022

Feel free to discuss any projects you are interested in here or Discord.

On Mon, Mar 28, 2022 at 1:10 PM Kamlesh Bharodiya 
wrote:

> Hi,
>
> I would like to participate in the GSoC 2022 Program. I have built and run
> the Hello World Program. Please find below: (also attaching the patch)
>
> commit bdd1ae76926135fbadc7920eefe6a303342e4a19 (HEAD -> master)
> Author: Kamlesh_Bharodiya 
> Date:   Sun Mar 27 22:22:47 2022 +0530
>
> [GSoC Entry] Modified Hello World Test
>
> diff --git a/testsuites/samples/hello/init.c
> b/testsuites/samples/hello/init.c
> index 34ded37c55..f4288833f9 100644
> --- a/testsuites/samples/hello/init.c
> +++ b/testsuites/samples/hello/init.c
> @@ -22,7 +22,7 @@ static rtems_task Init(
>  {
>rtems_print_printer_fprintf_putc(&rtems_test_printer);
>TEST_BEGIN();
> -  printf( "Hello World\n" );
> +  printf( "Hello to the World of RTEMS\n" );
>TEST_END();
>rtems_test_exit( 0 );
>  }
>
> Regards,
> Kamlesh
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


GSoC: Hello World Patch

2022-03-28 Thread Kamlesh Bharodiya
Hi,

I would like to participate in the GSoC 2022 Program. I have built and run
the Hello World Program. Please find below: (also attaching the patch)

commit bdd1ae76926135fbadc7920eefe6a303342e4a19 (HEAD -> master)
Author: Kamlesh_Bharodiya 
Date:   Sun Mar 27 22:22:47 2022 +0530

[GSoC Entry] Modified Hello World Test

diff --git a/testsuites/samples/hello/init.c
b/testsuites/samples/hello/init.c
index 34ded37c55..f4288833f9 100644
--- a/testsuites/samples/hello/init.c
+++ b/testsuites/samples/hello/init.c
@@ -22,7 +22,7 @@ static rtems_task Init(
 {
   rtems_print_printer_fprintf_putc(&rtems_test_printer);
   TEST_BEGIN();
-  printf( "Hello World\n" );
+  printf( "Hello to the World of RTEMS\n" );
   TEST_END();
   rtems_test_exit( 0 );
 }

Regards,
Kamlesh
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2 1/1] newlib01: Check exit procs for global FILE obj

2022-03-28 Thread Matthew Joyce
From: Matt Joyce 

---
 testsuites/libtests/newlib01/init.c | 110 ++--
 1 file changed, 88 insertions(+), 22 deletions(-)

diff --git a/testsuites/libtests/newlib01/init.c 
b/testsuites/libtests/newlib01/init.c
index c58154023b..bba187e8e2 100644
--- a/testsuites/libtests/newlib01/init.c
+++ b/testsuites/libtests/newlib01/init.c
@@ -28,6 +28,8 @@ const char rtems_test_name[] = "NEWLIB 1";
 
 static const char file_path[] = "/file";
 
+static const char file_path2[] = "/file2";
+
 typedef enum {
   INIT,
   OPEN,
@@ -39,6 +41,8 @@ typedef struct {
   rtems_id main_task_id;
   rtems_id worker_task_id;
   test_state current;
+  FILE *glob_file_stream;
+  int glob_fd;
 } test_context;
 
 static test_context test_instance;
@@ -59,7 +63,7 @@ static void wait(void)
   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
 }
 
-static void worker_task(rtems_task_argument arg)
+static void thread_specific_worker(rtems_task_argument arg)
 {
   test_context *ctx = &test_instance;
   struct _reent *reent = _REENT;
@@ -90,6 +94,30 @@ static void worker_task(rtems_task_argument arg)
   rtems_test_assert(0);
 }
 
+static void global_file_object_worker(rtems_task_argument arg)
+{
+  test_context *ctx = &test_instance;
+  FILE *fp;
+  char buf[1] = { 'y' };
+  size_t n;
+  int fd;
+
+  fp = ctx->glob_file_stream = fopen(&file_path2[0], "w");
+  rtems_test_assert(fp != NULL);
+
+  /* Get file descriptor of new global file stream, store it in text context */
+  fd = fileno(fp);
+  rtems_test_assert(fd != -1);
+  ctx->glob_fd = fd;
+
+  n = fwrite(&buf[0], sizeof(buf), 1, fp);
+  rtems_test_assert(n == 1);
+
+  wake_up_main(ctx);
+
+  rtems_test_assert(0);
+}
+
 static int handler_open(
   rtems_libio_t *iop,
   const char *path,
@@ -250,9 +278,34 @@ static const IMFS_node_control node_control = 
IMFS_GENERIC_INITIALIZER(
   IMFS_node_destroy_default
 );
 
-static void test_thread_specific_close(test_context *ctx)
+static void task_create_and_delete_helper(
+  test_context *ctx,
+  rtems_task_entry entry
+)
 {
   rtems_status_code sc;
+
+  sc = rtems_task_create(
+  rtems_build_name('W', 'O', 'R', 'K'),
+  2,
+  RTEMS_MINIMUM_STACK_SIZE,
+  RTEMS_DEFAULT_MODES,
+  RTEMS_DEFAULT_ATTRIBUTES,
+  &ctx->worker_task_id
+  );
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  sc = rtems_task_start(ctx->worker_task_id, entry, 0);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  wait();
+
+  sc = rtems_task_delete(ctx->worker_task_id);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static void test_thread_specific_close(test_context *ctx)
+{
   int rv;
   rtems_resource_snapshot snapshot;
 
@@ -266,23 +319,7 @@ static void test_thread_specific_close(test_context *ctx)
   );
   rtems_test_assert(rv == 0);
 
-  sc = rtems_task_create(
-rtems_build_name('W', 'O', 'R', 'K'),
-2,
-RTEMS_MINIMUM_STACK_SIZE,
-RTEMS_DEFAULT_MODES,
-RTEMS_DEFAULT_ATTRIBUTES,
-&ctx->worker_task_id
-  );
-  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
-
-  sc = rtems_task_start(ctx->worker_task_id, worker_task, 0);
-  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
-
-  wait();
-
-  sc = rtems_task_delete(ctx->worker_task_id);
-  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+  task_create_and_delete_helper(ctx, thread_specific_worker);
 
   rv = unlink(&file_path[0]);
   rtems_test_assert(rv == 0);
@@ -290,6 +327,11 @@ static void test_thread_specific_close(test_context *ctx)
   rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
 }
 
+static void test_global_file_object_close(test_context *ctx)
+{
+  task_create_and_delete_helper(ctx, global_file_object_worker);
+}
+
 /*
  * This exit handler will be called last among the functions registered with
  * atexit(). Check that stdio file descriptors are closed. The Newlib cleanup
@@ -298,6 +340,7 @@ static void test_thread_specific_close(test_context *ctx)
  */
 static void check_after_libio_exit(void)
 {
+  test_context *ctx = &test_instance;
   struct stat unused;
   int rv;
 
@@ -319,6 +362,11 @@ static void check_after_libio_exit(void)
   rtems_test_assert(stdin->_flags != 0);
   rtems_test_assert(stdout->_flags != 0);
   rtems_test_assert(stderr->_flags != 0);
+
+  /* Global file tests. Global fd still open at this point. */
+  rv = fstat(ctx->glob_fd, &unused);
+  rtems_test_assert(rv == 0);
+  rtems_test_assert(ctx->glob_file_stream->_flags != 0);
 }
 
 static void register_exit_handler_before_libio_exit(void)
@@ -342,7 +390,7 @@ RTEMS_SYSINIT_ITEM(register_exit_handler_before_libio_exit,
  * cleanup procedures have been called. Therefore, stdio file descriptors
  * should be open and stdio FILE object flags should be non-zero.
  */
-static void test_exit_handling(void)
+static void test_exit_handling(test_context *ctx)
 {
   struct stat unused;
   int rv;
@@ -360,6 +408,14 @@ static void test_exit_handling(void)
   rtems_test_assert(stdout->_flags != 0);
   rtems_test_assert(stderr->_flags != 0);
 
+  /*
+   * Global file descriptor should still be open; global FIL

[PATCH v2 0/1] newlib01: Check exit procs for global FILE obj

2022-03-28 Thread Matthew Joyce
From: Matt Joyce 

v2 removes some duplicate code and unnecessary asserts.

Matt Joyce (1):
  newlib01: Added test of exit procedures for global FILE object

 testsuites/libtests/newlib01/init.c | 110 ++--
 1 file changed, 88 insertions(+), 22 deletions(-)

-- 
2.31.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel