[rtems commit] libtests/newlib01: New test

Sebastian Huber sebh at rtems.org
Tue Apr 1 12:03:56 UTC 2014


Module:    rtems
Branch:    master
Commit:    3ccfd98bc136f0bf28bf0c4729038fd72aa78679
Changeset: http://git.rtems.org/rtems/commit/?id=3ccfd98bc136f0bf28bf0c4729038fd72aa78679

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Apr  1 09:21:05 2014 +0200

libtests/newlib01: New test

---

 testsuites/libtests/Makefile.am           |    1 +
 testsuites/libtests/configure.ac          |    1 +
 testsuites/libtests/newlib01/Makefile.am  |   19 ++
 testsuites/libtests/newlib01/init.c       |  311 +++++++++++++++++++++++++++++
 testsuites/libtests/newlib01/newlib01.doc |   13 ++
 testsuites/libtests/newlib01/newlib01.scn |    2 +
 6 files changed, 347 insertions(+), 0 deletions(-)

diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am
index 6659b2a..78566b0 100644
--- a/testsuites/libtests/Makefile.am
+++ b/testsuites/libtests/Makefile.am
@@ -1,6 +1,7 @@
 ACLOCAL_AMFLAGS = -I ../aclocal
 
 SUBDIRS = POSIX
+SUBDIRS += newlib01
 SUBDIRS += block17
 SUBDIRS += exit02
 SUBDIRS += exit01
diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac
index c945f44..81dd1fd 100644
--- a/testsuites/libtests/configure.ac
+++ b/testsuites/libtests/configure.ac
@@ -43,6 +43,7 @@ AM_CONDITIONAL(HAS_POSIX,test x"${rtems_cv_RTEMS_POSIX_API}" = x"yes")
 
 # Explicitly list all Makefiles here
 AC_CONFIG_FILES([Makefile
+newlib01/Makefile
 block17/Makefile
 exit02/Makefile
 exit01/Makefile
diff --git a/testsuites/libtests/newlib01/Makefile.am b/testsuites/libtests/newlib01/Makefile.am
new file mode 100644
index 0000000..f30c117
--- /dev/null
+++ b/testsuites/libtests/newlib01/Makefile.am
@@ -0,0 +1,19 @@
+rtems_tests_PROGRAMS = newlib01
+newlib01_SOURCES = init.c
+
+dist_rtems_tests_DATA = newlib01.scn newlib01.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(newlib01_OBJECTS)
+LINK_LIBS = $(newlib01_LDLIBS)
+
+newlib01$(EXEEXT): $(newlib01_OBJECTS) $(newlib01_DEPENDENCIES)
+	@rm -f newlib01$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/libtests/newlib01/init.c b/testsuites/libtests/newlib01/init.c
new file mode 100644
index 0000000..a1443d6
--- /dev/null
+++ b/testsuites/libtests/newlib01/init.c
@@ -0,0 +1,311 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include <rtems.h>
+#include <rtems/imfs.h>
+#include <rtems/libcsupport.h>
+
+#include "tmacros.h"
+
+const char rtems_test_name[] = "NEWLIB 1";
+
+static const char file_path[] = "/file";
+
+typedef enum {
+  INIT,
+  OPEN,
+  WRITTEN,
+  CLOSED
+} test_state;
+
+typedef struct {
+  rtems_id main_task_id;
+  rtems_id worker_task_id;
+  test_state current;
+} test_context;
+
+static test_context test_instance;
+
+static void wake_up_main(const test_context *ctx)
+{
+  rtems_status_code sc;
+
+  sc = rtems_event_transient_send(ctx->main_task_id);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static void wait(void)
+{
+  rtems_status_code sc;
+
+  sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static void worker_task(rtems_task_argument arg)
+{
+  test_context *ctx = &test_instance;
+  FILE *file = freopen(&file_path[0], "r+", stdout);
+  char buf[1] = { 'x' };
+  size_t n;
+
+  rtems_test_assert(file != NULL);
+
+  n = fwrite(&buf[0], sizeof(buf), 1, file);
+  rtems_test_assert(n == 1);
+
+  rtems_test_assert(ctx->current == OPEN);
+
+  wake_up_main(ctx);
+
+  rtems_test_assert(0);
+}
+
+static int handler_open(
+  rtems_libio_t *iop,
+  const char *path,
+  int oflag,
+  mode_t mode
+)
+{
+  test_context *ctx = &test_instance;
+
+  rtems_test_assert(ctx->current == INIT);
+  ctx->current = OPEN;
+
+  return 0;
+}
+
+static int handler_close(
+  rtems_libio_t *iop
+)
+{
+  test_context *ctx = &test_instance;
+
+  rtems_test_assert(ctx->current == WRITTEN);
+  ctx->current = CLOSED;
+
+  return 0;
+}
+
+static ssize_t handler_read(
+  rtems_libio_t *iop,
+  void *buffer,
+  size_t count
+)
+{
+  rtems_test_assert(0);
+
+  return 0;
+}
+
+static ssize_t handler_write(
+  rtems_libio_t *iop,
+  const void *buffer,
+  size_t count
+)
+{
+  test_context *ctx = &test_instance;
+
+  rtems_test_assert(ctx->current == OPEN);
+  ctx->current = WRITTEN;
+
+  iop->offset += count;
+
+  return (ssize_t) count;
+}
+
+static int handler_ioctl(
+  rtems_libio_t *iop,
+  uint32_t request,
+  void *buffer
+)
+{
+  rtems_test_assert(0);
+
+  return 0;
+}
+
+static off_t handler_lseek(
+  rtems_libio_t *iop,
+  off_t length,
+  int whence
+)
+{
+  rtems_test_assert(0);
+
+  return 0;
+}
+
+static int handler_ftruncate(
+  rtems_libio_t *iop,
+  off_t length
+)
+{
+  rtems_test_assert(0);
+
+  return 0;
+}
+
+static int handler_fsync(
+  rtems_libio_t *iop
+)
+{
+  rtems_test_assert(0);
+
+  return 0;
+}
+
+static int handler_fdatasync(
+  rtems_libio_t *iop
+)
+{
+  rtems_test_assert(0);
+
+  return 0;
+}
+
+static int handler_fcntl(
+  rtems_libio_t *iop,
+  int cmd
+)
+{
+  rtems_test_assert(0);
+
+  return 0;
+}
+
+static ssize_t handler_readv(
+  rtems_libio_t *iop,
+  const struct iovec *iov,
+  int iovcnt,
+  ssize_t total
+)
+{
+  rtems_test_assert(0);
+
+  return 0;
+}
+
+static ssize_t handler_writev(
+  rtems_libio_t *iop,
+  const struct iovec *iov,
+  int iovcnt,
+  ssize_t total
+)
+{
+  rtems_test_assert(0);
+
+  return 0;
+}
+
+static const rtems_filesystem_file_handlers_r node_handlers = {
+  .open_h = handler_open,
+  .close_h = handler_close,
+  .read_h = handler_read,
+  .write_h = handler_write,
+  .ioctl_h = handler_ioctl,
+  .lseek_h = handler_lseek,
+  .fstat_h = rtems_filesystem_default_fstat,
+  .ftruncate_h = handler_ftruncate,
+  .fsync_h = handler_fsync,
+  .fdatasync_h = handler_fdatasync,
+  .fcntl_h = handler_fcntl,
+  .readv_h = handler_readv,
+  .writev_h = handler_writev
+};
+
+static const IMFS_node_control node_control = {
+  .imfs_type = IMFS_GENERIC,
+  .handlers = &node_handlers,
+  .node_initialize = IMFS_node_initialize_default,
+  .node_remove = IMFS_node_remove_default,
+  .node_destroy = IMFS_node_destroy_default
+};
+
+static void test(void)
+{
+  test_context *ctx = &test_instance;
+  rtems_status_code sc;
+  int rv;
+  rtems_resource_snapshot snapshot;
+
+  ctx->main_task_id = rtems_task_self();
+
+  rtems_resource_snapshot_take(&snapshot);
+
+  rv = IMFS_make_generic_node(
+    &file_path[0],
+    S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
+    &node_control,
+    NULL
+  );
+  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);
+
+  rv = unlink(&file_path[0]);
+  rtems_test_assert(rv == 0);
+
+  rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
+}
+
+static void Init(rtems_task_argument arg)
+{
+  TEST_BEGIN();
+
+  test();
+
+  TEST_END();
+  rtems_test_exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
+
+#define CONFIGURE_MAXIMUM_TASKS 2
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/libtests/newlib01/newlib01.doc b/testsuites/libtests/newlib01/newlib01.doc
new file mode 100644
index 0000000..0982bb5
--- /dev/null
+++ b/testsuites/libtests/newlib01/newlib01.doc
@@ -0,0 +1,13 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: newlib01
+
+directives:
+
+  - newlib_create_hook()
+  - newlib_delete_hook()
+  - newlib_terminate_hook()
+
+concepts:
+
+  - Ensure that the Newlib hooks works as expected.
diff --git a/testsuites/libtests/newlib01/newlib01.scn b/testsuites/libtests/newlib01/newlib01.scn
new file mode 100644
index 0000000..5a4d997
--- /dev/null
+++ b/testsuites/libtests/newlib01/newlib01.scn
@@ -0,0 +1,2 @@
+*** BEGIN OF TEST NEWLIB 1 ***
+*** END OF TEST NEWLIB 1 ***




More information about the vc mailing list