summaryrefslogtreecommitdiffstats
path: root/testsuites/fstests
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-02-29 16:14:31 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-03-04 09:30:03 +0100
commitfa44c3903a9da966dae024b7dcd824c8efd5cd34 (patch)
treea3128214888e63830a5a71fa201846e9a2cda803 /testsuites/fstests
parentimfs: Simplify IMFS_create_node() (diff)
downloadrtems-fa44c3903a9da966dae024b7dcd824c8efd5cd34.tar.bz2
imfs: Add IMFS_add_node()
Update #3894.
Diffstat (limited to 'testsuites/fstests')
-rw-r--r--testsuites/fstests/fsimfsgeneric01/init.c206
1 files changed, 172 insertions, 34 deletions
diff --git a/testsuites/fstests/fsimfsgeneric01/init.c b/testsuites/fstests/fsimfsgeneric01/init.c
index dc216181a4..e553f36ce0 100644
--- a/testsuites/fstests/fsimfsgeneric01/init.c
+++ b/testsuites/fstests/fsimfsgeneric01/init.c
@@ -1,11 +1,5 @@
/*
- * Copyright (c) 2012-2014 embedded brains GmbH. All rights reserved.
- *
- * embedded brains GmbH
- * Dornierstr. 4
- * 82178 Puchheim
- * Germany
- * <rtems@embedded-brains.de>
+ * Copyright (C) 2012, 2020 embedded brains GmbH (http://www.embedded-brains.de)
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -13,11 +7,9 @@
*/
#ifdef HAVE_CONFIG_H
- #include "config.h"
+#include "config.h"
#endif
-#include "tmacros.h"
-
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
@@ -29,6 +21,8 @@
#include <rtems/malloc.h>
#include <rtems/libcsupport.h>
+#include <tmacros.h>
+
const char rtems_test_name[] = "FSIMFSGENERIC 1";
typedef enum {
@@ -302,28 +296,18 @@ static const IMFS_node_control node_control = {
.node_destroy = node_destroy
};
-static void test_imfs_make_generic_node(void)
+static void test_node_operations(const char *path)
{
- test_state state = TEST_NEW;
- int rv = 0;
- int fd = 0;
- const char *path = "generic";
- char buf [1];
- ssize_t n = 0;
- off_t off = 0;
+ int rv;
+ int fd;
+ char buf[1];
+ ssize_t n;
+ off_t off;
struct iovec iov = {
- .iov_base = &buf [0],
+ .iov_base = &buf[0],
.iov_len = (int) sizeof(buf)
};
- rv = IMFS_make_generic_node(
- path,
- S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
- &node_control,
- &state
- );
- rtems_test_assert(rv == 0);
-
fd = open(path, O_RDWR);
rtems_test_assert(fd >= 0);
@@ -336,7 +320,7 @@ static void test_imfs_make_generic_node(void)
rv = ioctl(fd, 0);
rtems_test_assert(rv == 0);
- off = lseek(fd, off, SEEK_SET);
+ off = lseek(fd, 0, SEEK_SET);
rtems_test_assert(off == 0);
rv = ftruncate(fd, 0);
@@ -362,7 +346,24 @@ static void test_imfs_make_generic_node(void)
rv = unlink(path);
rtems_test_assert(rv == 0);
+}
+
+static void test_imfs_make_generic_node(void)
+{
+ static const char path[] = "generic";
+ test_state state;
+ int rv;
+
+ state = TEST_NEW;
+ rv = IMFS_make_generic_node(
+ path,
+ S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
+ &node_control,
+ &state
+ );
+ rtems_test_assert(rv == 0);
+ test_node_operations(path);
rtems_test_assert(state == TEST_DESTROYED);
}
@@ -402,16 +403,20 @@ static int other_clone(rtems_filesystem_location_info_t *loc)
return (*imfs_ops->clonenod_h)(loc);
}
+static rtems_filesystem_mount_table_entry_t *get_imfs_mt_entry(void)
+{
+ return (rtems_filesystem_mount_table_entry_t *)
+ rtems_chain_first(&rtems_filesystem_mount_table);
+}
+
static void test_imfs_make_generic_node_errors(void)
{
- int rv = 0;
- const char *path = "generic";
- rtems_chain_control *chain = &rtems_filesystem_mount_table;
- rtems_filesystem_mount_table_entry_t *mt_entry =
- (rtems_filesystem_mount_table_entry_t *) rtems_chain_first(chain);
+ static const char path[] = "generic";
+ rtems_filesystem_mount_table_entry_t *mt_entry;
rtems_filesystem_operations_table other_ops;
- void *opaque = NULL;
rtems_resource_snapshot before;
+ void *opaque;
+ int rv;
rtems_resource_snapshot_take(&before);
@@ -427,6 +432,7 @@ static void test_imfs_make_generic_node_errors(void)
rtems_test_assert(rtems_resource_snapshot_check(&before));
errno = 0;
+ mt_entry = get_imfs_mt_entry();
imfs_ops = mt_entry->ops;
other_ops = *imfs_ops;
other_ops.clonenod_h = other_clone;
@@ -478,12 +484,142 @@ static void test_imfs_make_generic_node_errors(void)
rtems_test_assert(rtems_resource_snapshot_check(&before));
}
+static void user_node_destroy(IMFS_jnode_t *node)
+{
+ test_state *state = IMFS_generic_get_context_by_node(node);
+
+ rtems_test_assert(*state == TEST_REMOVED);
+ *state = TEST_DESTROYED;
+}
+
+static const IMFS_node_control user_node_control = {
+ .handlers = &node_handlers,
+ .node_initialize = node_initialize,
+ .node_remove = node_remove,
+ .node_destroy = user_node_destroy
+};
+
+static void test_imfs_add_node(void)
+{
+ static const char path[] = "/";
+ static const char name[] = "node";
+ size_t namelen = sizeof(name) - 1;
+ void *opaque;
+ rtems_resource_snapshot before;
+ IMFS_generic_t node = IMFS_GENERIC_NODE_INITIALIZER(
+ &user_node_control,
+ name,
+ namelen,
+ S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO
+ );
+ test_state state;
+ int rv;
+
+ /* Ensure that sure no dynamic memory is used */
+ opaque = rtems_heap_greedy_allocate(NULL, 0);
+
+ rtems_resource_snapshot_take(&before);
+
+ state = TEST_NEW;
+ rv = IMFS_add_node(path, &node.Node, &state);
+ rtems_test_assert(rv == 0);
+
+ test_node_operations(name);
+ rtems_test_assert(state == TEST_DESTROYED);
+
+ rtems_test_assert(rtems_resource_snapshot_check(&before));
+ rtems_heap_greedy_free(opaque);
+}
+
+static void test_imfs_add_node_errors(void)
+{
+ static const char path[] = "/";
+ static const char name[] = "node";
+ size_t namelen = sizeof(name) - 1;
+ const char invalid_name[] = "/node";
+ size_t invalid_namelen = sizeof(invalid_name) - 1;
+ IMFS_jnode_t node = IMFS_NODE_INITIALIZER(
+ &user_node_control,
+ name,
+ namelen,
+ S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO
+ );
+ IMFS_jnode_t invalid_mode_node = IMFS_NODE_INITIALIZER(
+ &user_node_control,
+ name,
+ namelen,
+ S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO
+ );
+ IMFS_jnode_t init_error_node = IMFS_NODE_INITIALIZER(
+ &node_initialization_error_control,
+ name,
+ namelen,
+ S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO
+ );
+ IMFS_jnode_t invalid_name_node = IMFS_NODE_INITIALIZER(
+ &user_node_control,
+ invalid_name,
+ invalid_namelen,
+ S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO
+ );
+ rtems_filesystem_mount_table_entry_t *mt_entry;
+ rtems_filesystem_operations_table other_ops;
+ void *opaque;
+ rtems_resource_snapshot before;
+ int rv;
+
+ /* Ensure that sure no dynamic memory is used */
+ opaque = rtems_heap_greedy_allocate(NULL, 0);
+
+ rtems_resource_snapshot_take(&before);
+
+ errno = 0;
+ rv = IMFS_add_node(path, &invalid_mode_node, NULL);
+ rtems_test_assert(rv == -1);
+ rtems_test_assert(errno == EINVAL);
+ rtems_test_assert(rtems_resource_snapshot_check(&before));
+
+ errno = 0;
+ mt_entry = get_imfs_mt_entry();
+ imfs_ops = mt_entry->ops;
+ other_ops = *imfs_ops;
+ other_ops.clonenod_h = other_clone;
+ mt_entry->ops = &other_ops;
+ rv = IMFS_add_node(path, &node, NULL);
+ mt_entry->ops = imfs_ops;
+ rtems_test_assert(rv == -1);
+ rtems_test_assert(errno == ENOTSUP);
+ rtems_test_assert(rtems_resource_snapshot_check(&before));
+
+ errno = 0;
+ rv = IMFS_add_node(path, &init_error_node, NULL);
+ rtems_test_assert(rv == -1);
+ rtems_test_assert(errno == EIO);
+ rtems_test_assert(rtems_resource_snapshot_check(&before));
+
+ errno = 0;
+ rv = IMFS_add_node("/nil/nada", &node, NULL);
+ rtems_test_assert(rv == -1);
+ rtems_test_assert(errno == ENOENT);
+ rtems_test_assert(rtems_resource_snapshot_check(&before));
+
+ errno = 0;
+ rv = IMFS_add_node(path, &invalid_name_node, NULL);
+ rtems_test_assert(rv == -1);
+ rtems_test_assert(errno == EINVAL);
+ rtems_test_assert(rtems_resource_snapshot_check(&before));
+
+ rtems_heap_greedy_free(opaque);
+}
+
static void Init(rtems_task_argument arg)
{
TEST_BEGIN();
test_imfs_make_generic_node();
test_imfs_make_generic_node_errors();
+ test_imfs_add_node();
+ test_imfs_add_node_errors();
TEST_END();
rtems_test_exit(0);
@@ -496,6 +632,8 @@ static void Init(rtems_task_argument arg)
#define CONFIGURE_MAXIMUM_TASKS 1
+#define CONFIGURE_UNIFIED_WORK_AREAS
+
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE