You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/12/17 11:39:05 UTC

[GitHub] utzig closed pull request #12: Travis integration

utzig closed pull request #12: Travis integration
URL: https://github.com/apache/mynewt-nffs/pull/12
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..49ed667
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,53 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+language: go
+
+_addons: &addon_conf
+
+go:
+  - "1.10"
+
+git:
+  depth: false
+
+matrix:
+  include:
+    - os: linux
+      addons:
+        apt:
+          sources:
+            - ubuntu-toolchain-r-test
+          packages:
+            - gcc-7-multilib
+            - linux-libc-dev:i386
+
+before_install:
+  - printenv
+  - go version
+
+install:
+  - mkdir -p $HOME/bin
+  - export PATH=$HOME/bin:$PATH
+  - ./ci/install.sh
+
+before_script:
+  - newt version
+  - gcc --version
+
+script:
+  - newt test test
diff --git a/ci/install.sh b/ci/install.sh
new file mode 100755
index 0000000..6352b78
--- /dev/null
+++ b/ci/install.sh
@@ -0,0 +1,34 @@
+#!/bin/bash -x
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+pushd $HOME
+git clone --depth=1 https://github.com/apache/mynewt-newt
+[[ $? -ne 0 ]] && exit 1
+
+pushd mynewt-newt && ./build.sh
+[[ $? -ne 0 ]] && exit 1
+
+cp newt/newt $HOME/bin
+popd
+popd
+
+ln -s /usr/bin/gcc-7 $HOME/bin/gcc
+
+mkdir -p repos/apache-mynewt-core
+git clone --depth=1 https://github.com/apache/mynewt-core repos/apache-mynewt-core
diff --git a/include/nffs/nffs.h b/include/nffs/nffs.h
index 56c9930..ea50b74 100644
--- a/include/nffs/nffs.h
+++ b/include/nffs/nffs.h
@@ -213,6 +213,9 @@ struct nffs_block {
 };
 
 struct nffs_file {
+#if !__ZEPHYR__
+    struct fs_ops *fops;
+#endif
     struct nffs_inode_entry *nf_inode_entry;
     uint32_t nf_offset;
     uint8_t nf_access_flags;
@@ -280,11 +283,16 @@ struct nffs_cache_inode {
 };
 
 struct nffs_dirent {
+#if !__ZEPHYR__
     struct fs_ops *fops;
+#endif
     struct nffs_inode_entry *nde_inode_entry;
 };
 
 struct nffs_dir {
+#if !__ZEPHYR__
+    struct fs_ops *fops;
+#endif
     struct nffs_inode_entry *nd_parent_inode_entry;
     struct nffs_dirent nd_dirent;
 };
@@ -328,7 +336,11 @@ extern void *nffs_dir_mem;
 extern uint32_t nffs_hash_next_file_id;
 extern uint32_t nffs_hash_next_dir_id;
 extern uint32_t nffs_hash_next_block_id;
-extern struct nffs_area nffs_areas[CONFIG_NFFS_FILESYSTEM_MAX_AREAS];
+#if NFFS_CONFIG_USE_HEAP
+struct nffs_area *nffs_areas;
+#else
+extern struct nffs_area nffs_areas[NFFS_CONFIG_MAX_AREAS];
+#endif
 extern uint8_t nffs_num_areas;
 extern uint8_t nffs_scratch_area_idx;
 extern uint16_t nffs_block_max_data_sz;
@@ -566,6 +578,8 @@ int nffs_write_to_file(struct nffs_file *file, const void *data, int len);
 #else
 
 /* Default to Mynewt */
+#include "log/log.h"
+#include "testutil/testutil.h"
 
 #define NFFS_LOG(lvl, ...) \
     LOG_ ## lvl(&nffs_log, LOG_MODULE_NFFS, __VA_ARGS__)
diff --git a/include/nffs/os.h b/include/nffs/os.h
index e983cbc..d2c6585 100644
--- a/include/nffs/os.h
+++ b/include/nffs/os.h
@@ -21,7 +21,9 @@
 #define H_OS_
 
 #include <stdint.h>
+#if __ZEPHYR__
 #include <kernel.h>
+#endif
 #include <nffs/config.h>
 
 #ifdef __cplusplus
diff --git a/pkg.yml b/pkg.yml
index 276f456..7369772 100644
--- a/pkg.yml
+++ b/pkg.yml
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-pkg.name: fs/nffs
+pkg.name: "nffs"
 pkg.description: Newtron Flash File System.
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
@@ -27,12 +27,12 @@ pkg.keywords:
     - ffs
 
 pkg.deps:
-    - fs/fs
-    - util/crc
-    - hw/hal
-    - kernel/os
-    - test/testutil
-    - sys/flash_map
+    - "@apache-mynewt-core/fs/fs"
+    - "@apache-mynewt-core/util/crc"
+    - "@apache-mynewt-core/hw/hal"
+    - "@apache-mynewt-core/kernel/os"
+    - "@apache-mynewt-core/test/testutil"
+    - "@apache-mynewt-core/sys/flash_map"
 pkg.req_apis:
     - log
     - stats
diff --git a/project.yml b/project.yml
new file mode 100644
index 0000000..d510407
--- /dev/null
+++ b/project.yml
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+project.name: "apache-mynewt-nffs"
+
+project.repositories:
+    - apache-mynewt-core
+
+# Use github's distribution mechanism for core ASF libraries.
+# This provides mirroring automatically for us.
+repository.apache-mynewt-core:
+    type: github
+    vers: 0-dev
+    user: apache
+    repo: mynewt-core
diff --git a/src/nffs_dir.c b/src/nffs_dir.c
index 5d8bc90..f232bc1 100644
--- a/src/nffs_dir.c
+++ b/src/nffs_dir.c
@@ -22,6 +22,12 @@
 #include <nffs/nffs.h>
 #include <nffs/os.h>
 
+#if !__ZEPHYR__
+#include "fs/fs.h"
+#include "fs/fs_if.h"
+struct fs_ops nffs_ops;
+#endif
+
 static struct nffs_dir *
 nffs_dir_alloc(void)
 {
@@ -74,6 +80,9 @@ nffs_dir_open(const char *path, struct nffs_dir **out_dir)
     dir->nd_parent_inode_entry = parent_inode_entry;
     nffs_inode_inc_refcnt(dir->nd_parent_inode_entry);
     memset(&dir->nd_dirent, 0, sizeof dir->nd_dirent);
+#if !__ZEPHYR__
+    dir->fops = &nffs_ops;
+#endif
 
     *out_dir = dir;
 
@@ -104,6 +113,9 @@ nffs_dir_read(struct nffs_dir *dir, struct nffs_dirent **out_dirent)
     }
 
     nffs_inode_inc_refcnt(child);
+#if !__ZEPHYR__
+    dir->nd_dirent.fops = &nffs_ops;
+#endif
     *out_dirent = &dir->nd_dirent;
 
     return 0;
diff --git a/src/nffs_file.c b/src/nffs_file.c
index 4be4f5f..b02db98 100644
--- a/src/nffs_file.c
+++ b/src/nffs_file.c
@@ -22,6 +22,12 @@
 #include <nffs/nffs.h>
 #include <nffs/os.h>
 
+#if !__ZEPHYR__
+#include "fs/fs.h"
+#include "fs/fs_if.h"
+struct fs_ops nffs_ops;
+#endif
+
 static struct nffs_file *
 nffs_file_alloc(void)
 {
@@ -242,6 +248,9 @@ nffs_file_open(struct nffs_file **out_file, const char *path,
     }
     nffs_inode_inc_refcnt(file->nf_inode_entry);
     file->nf_access_flags = access_flags;
+#if !__ZEPHYR__
+    file->fops = &nffs_ops;
+#endif
 
     *out_file = file;
 
diff --git a/src/nffs_gc.c b/src/nffs_gc.c
index 4613053..bfc45bf 100644
--- a/src/nffs_gc.c
+++ b/src/nffs_gc.c
@@ -19,7 +19,9 @@
 
 #include <assert.h>
 #include <string.h>
+#if __ZEPHYR__
 #include <kernel.h>
+#endif
 #include <nffs/nffs.h>
 
 /**
diff --git a/src/nffs_hash.c b/src/nffs_hash.c
index d2f42ec..925d51e 100644
--- a/src/nffs_hash.c
+++ b/src/nffs_hash.c
@@ -20,7 +20,9 @@
 #include <stddef.h>
 #include <string.h>
 #include <assert.h>
+#if __ZEPHYR__
 #include <kernel.h>
+#endif
 #include <nffs/nffs.h>
 
 struct nffs_hash_list *nffs_hash;
diff --git a/src/nffs_misc.c b/src/nffs_misc.c
index fd55ef9..aecae4c 100644
--- a/src/nffs_misc.c
+++ b/src/nffs_misc.c
@@ -20,7 +20,9 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+#if __ZEPHYR__
 #include <kernel.h>
+#endif
 #include <nffs/nffs.h>
 #include <nffs/os.h>
 
diff --git a/test/pkg.yml b/test/pkg.yml
index 9e64e71..7e87228 100644
--- a/test/pkg.yml
+++ b/test/pkg.yml
@@ -15,18 +15,18 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-pkg.name: fs/nffs/test
+pkg.name: "test"
 pkg.type: unittest
 pkg.description: "NFFS unit tests."
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
 
-pkg.deps: 
-    - fs/nffs
-    - test/testutil
+pkg.deps:
+    - "@apache-mynewt-nffs/nffs"
+    - "@apache-mynewt-core/test/testutil"
 
 pkg.deps.SELFTEST:
-    - sys/console/stub
-    - sys/log/full
-    - sys/stats/stub
+    - "@apache-mynewt-core/sys/console/stub"
+    - "@apache-mynewt-core/sys/log/full"
+    - "@apache-mynewt-core/sys/stats/stub"
diff --git a/test/src/nffs_os_mynewt.c b/test/src/nffs_os_mynewt.c
new file mode 100644
index 0000000..7afff32
--- /dev/null
+++ b/test/src/nffs_os_mynewt.c
@@ -0,0 +1,427 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#if !__ZEPHYR__
+
+#include <os/mynewt.h>
+#include "fs/fs.h"
+#include "fs/fs_if.h"
+#include "nffs/nffs.h"
+#include <crc/crc16.h>
+#include "nffs_test_utils.h"
+
+static struct os_mutex nffs_mutex;
+struct nffs_config nffs_config;
+struct log nffs_log;
+
+nffs_os_mempool_t nffs_file_pool;
+nffs_os_mempool_t nffs_dir_pool;
+nffs_os_mempool_t nffs_inode_entry_pool;
+nffs_os_mempool_t nffs_block_entry_pool;
+nffs_os_mempool_t nffs_cache_inode_pool;
+nffs_os_mempool_t nffs_cache_block_pool;
+
+void *nffs_file_mem;
+void *nffs_dir_mem;
+void *nffs_inode_mem;
+void *nffs_block_entry_mem;
+void *nffs_cache_inode_mem;
+void *nffs_cache_block_mem;
+
+int
+nffs_os_mempool_init(void)
+{
+    int rc;
+
+    assert(nffs_file_mem != NULL);
+    rc = os_mempool_init(&nffs_file_pool, nffs_config.nc_num_files,
+            sizeof(struct nffs_file), nffs_file_mem, "nffs_file_pool");
+    assert(rc == 0);
+
+    rc = os_mempool_init(&nffs_dir_pool, nffs_config.nc_num_dirs,
+            sizeof(struct nffs_dir), nffs_dir_mem, "nffs_dir_pool");
+    assert(rc == 0);
+
+    rc = os_mempool_init(&nffs_inode_entry_pool, nffs_config.nc_num_inodes,
+            sizeof(struct nffs_inode_entry), nffs_inode_mem,
+            "nffs_inode_entry_pool");
+    assert(rc == 0);
+
+    rc = os_mempool_init(&nffs_block_entry_pool, nffs_config.nc_num_blocks,
+            sizeof(struct nffs_hash_entry), nffs_block_entry_mem,
+            "nffs_block_entry_pool");
+    assert(rc == 0);
+
+    rc = os_mempool_init(&nffs_cache_inode_pool, nffs_config.nc_num_cache_inodes,
+            sizeof(struct nffs_cache_inode), nffs_cache_inode_mem,
+            "nffs_cache_inode_pool");
+    assert(rc == 0);
+
+    rc = os_mempool_init(&nffs_cache_block_pool, nffs_config.nc_num_cache_blocks,
+            sizeof(struct nffs_cache_block), nffs_cache_block_mem,
+            "nffs_cache_inode_pool");
+    assert(rc == 0);
+
+    return rc;
+}
+
+void *
+nffs_os_mempool_get(nffs_os_mempool_t *pool)
+{
+    return os_memblock_get(pool);
+}
+
+int
+nffs_os_mempool_free(nffs_os_mempool_t *pool, void *block)
+{
+    return os_memblock_put(pool, block);
+}
+
+int
+nffs_os_flash_read(uint8_t id, uint32_t address, void *dst, uint32_t num_bytes)
+{
+    return hal_flash_read(id, address, dst, num_bytes);
+}
+
+int
+nffs_os_flash_write(uint8_t id, uint32_t address, const void *src,
+        uint32_t num_bytes)
+{
+    return hal_flash_write(id, address, src, num_bytes);
+}
+
+int
+nffs_os_flash_erase(uint8_t id, uint32_t address, uint32_t num_bytes)
+{
+    return hal_flash_erase(id, address, num_bytes);
+}
+
+int nffs_os_flash_info(uint8_t id, uint32_t sector, uint32_t *address,
+        uint32_t *size)
+{
+    assert(0);
+    return 0;
+}
+
+uint16_t
+nffs_os_crc16_ccitt(uint16_t initial_crc, const void *buf, int len, int final)
+{
+    (void)final;
+    return crc16_ccitt(initial_crc, buf, len);
+}
+
+const struct nffs_config nffs_config_dflt = {
+    .nc_num_inodes = 100,
+    .nc_num_blocks = 100,
+    .nc_num_files = 4,
+    .nc_num_cache_inodes = 4,
+    .nc_num_cache_blocks = 64,
+    .nc_num_dirs = 4,
+};
+
+void
+nffs_config_init(void)
+{
+    if (nffs_config.nc_num_inodes == 0) {
+        nffs_config.nc_num_inodes = nffs_config_dflt.nc_num_inodes;
+    }
+    if (nffs_config.nc_num_blocks == 0) {
+        nffs_config.nc_num_blocks = nffs_config_dflt.nc_num_blocks;
+    }
+    if (nffs_config.nc_num_files == 0) {
+        nffs_config.nc_num_files = nffs_config_dflt.nc_num_files;
+    }
+    if (nffs_config.nc_num_cache_inodes == 0) {
+        nffs_config.nc_num_cache_inodes = nffs_config_dflt.nc_num_cache_inodes;
+    }
+    if (nffs_config.nc_num_cache_blocks == 0) {
+        nffs_config.nc_num_cache_blocks = nffs_config_dflt.nc_num_cache_blocks;
+    }
+    if (nffs_config.nc_num_dirs == 0) {
+        nffs_config.nc_num_dirs = nffs_config_dflt.nc_num_dirs;
+    }
+}
+
+static int
+nffs_open(const char *path, uint8_t access_flags, struct fs_file **out_fs_file)
+{
+    int rc;
+    struct nffs_file *out_file;
+
+    if (!nffs_misc_ready()) {
+        rc = FS_EUNINIT;
+        goto done;
+    }
+
+    rc = nffs_file_open(&out_file, path, access_flags);
+    if (rc != 0) {
+        goto done;
+    }
+    *out_fs_file = (struct fs_file *)out_file;
+
+done:
+    if (rc != 0) {
+        *out_fs_file = NULL;
+    }
+    return rc;
+}
+
+static int
+nffs_close(struct fs_file *fs_file)
+{
+    if (!fs_file) {
+        return 0;
+    }
+
+    return nffs_file_close((struct nffs_file *)fs_file);
+}
+
+static int
+nffs_seek(struct fs_file *fs_file, uint32_t offset)
+{
+    return nffs_file_seek((struct nffs_file *)fs_file, offset);
+}
+
+static uint32_t
+nffs_getpos(const struct fs_file *fs_file)
+{
+    return ((const struct nffs_file *)fs_file)->nf_offset;
+}
+
+static int
+nffs_file_len(const struct fs_file *fs_file, uint32_t *out_len)
+{
+    return nffs_inode_data_len(
+            ((const struct nffs_file *)fs_file)->nf_inode_entry, out_len);
+}
+
+static int
+nffs_read(struct fs_file *fs_file, uint32_t len, void *out_data,
+          uint32_t *out_len)
+{
+    return nffs_file_read((struct nffs_file *)fs_file, len, out_data, out_len);
+}
+
+static int
+nffs_write(struct fs_file *fs_file, const void *data, int len)
+{
+    if (!nffs_misc_ready()) {
+        return FS_EUNINIT;
+    }
+
+    return nffs_write_to_file((struct nffs_file *)fs_file, data, len);
+}
+
+static int
+nffs_unlink(const char *path)
+{
+    if (!nffs_misc_ready()) {
+        return FS_EUNINIT;
+    }
+
+    return nffs_path_unlink(path);
+}
+
+static int
+nffs_rename(const char *from, const char *to)
+{
+    if (!nffs_misc_ready()) {
+        return FS_EUNINIT;
+    }
+
+    return nffs_path_rename(from, to);
+}
+
+static int
+nffs_mkdir(const char *path)
+{
+    if (!nffs_misc_ready()) {
+        return FS_EUNINIT;
+    }
+
+    return nffs_path_new_dir(path, NULL);
+}
+
+static int
+nffs_opendir(const char *path, struct fs_dir **out_fs_dir)
+{
+    if (!nffs_misc_ready()) {
+        return FS_EUNINIT;
+    }
+
+    return nffs_dir_open(path, (struct nffs_dir **)out_fs_dir);
+}
+
+static int
+nffs_readdir(struct fs_dir *fs_dir, struct fs_dirent **out_fs_dirent)
+{
+    return nffs_dir_read((struct nffs_dir *)fs_dir,
+            (struct nffs_dirent **)out_fs_dirent);
+}
+
+static int
+nffs_closedir(struct fs_dir *fs_dir)
+{
+    return nffs_dir_close((struct nffs_dir *)fs_dir);
+}
+
+static int
+nffs_dirent_name(const struct fs_dirent *fs_dirent, size_t max_len,
+                 char *out_name, uint8_t *out_name_len)
+{
+    struct nffs_dirent *dirent = (struct nffs_dirent *)fs_dirent;
+    assert(dirent != NULL && dirent->nde_inode_entry != NULL);
+    return nffs_inode_read_filename(dirent->nde_inode_entry,
+            max_len, out_name, out_name_len);
+}
+
+static int
+nffs_dirent_is_dir(const struct fs_dirent *fs_dirent)
+{
+    uint32_t id;
+    const struct nffs_dirent *dirent = (const struct nffs_dirent *)fs_dirent;
+
+    assert(dirent != NULL && dirent->nde_inode_entry != NULL);
+    id = dirent->nde_inode_entry->nie_hash_entry.nhe_id;
+    return nffs_hash_id_is_dir(id);
+}
+
+struct fs_ops nffs_ops = {
+    .f_open = nffs_open,
+    .f_close = nffs_close,
+    .f_read = nffs_read,
+    .f_write = nffs_write,
+
+    .f_seek = nffs_seek,
+    .f_getpos = nffs_getpos,
+    .f_filelen = nffs_file_len,
+
+    .f_unlink = nffs_unlink,
+    .f_rename = nffs_rename,
+    .f_mkdir = nffs_mkdir,
+
+    .f_opendir = nffs_opendir,
+    .f_readdir = nffs_readdir,
+    .f_closedir = nffs_closedir,
+
+    .f_dirent_name = nffs_dirent_name,
+    .f_dirent_is_dir = nffs_dirent_is_dir,
+
+    .f_name = "nffs"
+};
+
+/**
+ * Initializes internal nffs memory and data structures.  This must be called
+ * before any nffs operations are attempted.
+ *
+ * @return                  0 on success; nonzero on error.
+ */
+int
+nffs_init(void)
+{
+    int rc;
+
+    log_register("nffs", &nffs_log, &log_console_handler, NULL, LOG_LEVEL_DEBUG);
+
+    nffs_config_init();
+
+    nffs_cache_clear();
+
+    rc = os_mutex_init(&nffs_mutex);
+    if (rc != 0) {
+        return FS_EOS;
+    }
+
+    free(nffs_file_mem);
+    nffs_file_mem = malloc(
+        OS_MEMPOOL_BYTES(nffs_config.nc_num_files, sizeof (struct nffs_file)));
+    if (nffs_file_mem == NULL) {
+        return FS_ENOMEM;
+    }
+
+    free(nffs_inode_mem);
+    nffs_inode_mem = malloc(OS_MEMPOOL_BYTES(
+            nffs_config.nc_num_inodes, sizeof (struct nffs_inode_entry)));
+    if (nffs_inode_mem == NULL) {
+        return FS_ENOMEM;
+    }
+
+    free(nffs_block_entry_mem);
+    nffs_block_entry_mem = malloc(OS_MEMPOOL_BYTES(
+                nffs_config.nc_num_blocks, sizeof (struct nffs_hash_entry)));
+    if (nffs_block_entry_mem == NULL) {
+        return FS_ENOMEM;
+    }
+
+    free(nffs_cache_inode_mem);
+    nffs_cache_inode_mem = malloc(OS_MEMPOOL_BYTES(
+                nffs_config.nc_num_cache_inodes,
+                sizeof (struct nffs_cache_inode)));
+    if (nffs_cache_inode_mem == NULL) {
+        return FS_ENOMEM;
+    }
+
+    free(nffs_cache_block_mem);
+    nffs_cache_block_mem = malloc(OS_MEMPOOL_BYTES(
+            nffs_config.nc_num_cache_blocks,
+            sizeof (struct nffs_cache_block)));
+    if (nffs_cache_block_mem == NULL) {
+        return FS_ENOMEM;
+    }
+
+    free(nffs_dir_mem);
+    nffs_dir_mem = malloc(OS_MEMPOOL_BYTES(
+            nffs_config.nc_num_dirs, sizeof (struct nffs_dir)));
+    if (nffs_dir_mem == NULL) {
+        return FS_ENOMEM;
+    }
+
+    rc = nffs_misc_reset();
+    if (rc != 0) {
+        return rc;
+    }
+
+    fs_register(&nffs_ops);
+    return 0;
+}
+
+void
+nffs_pkg_init(void)
+{
+    /* do nothing */
+}
+
+#endif /* !__ZEPHYR__ */
diff --git a/test/src/nffs_test.c b/test/src/nffs_test.c
index 369fc1c..24fc7cf 100644
--- a/test/src/nffs_test.c
+++ b/test/src/nffs_test.c
@@ -45,10 +45,9 @@
 #include "testutil/testutil.h"
 #include "fs/fs.h"
 #include "nffs/nffs.h"
-#include "nffs/nffs_test.h"
-#include "nffs_test_priv.h"
-#include "nffs_priv.h"
 #include "nffs_test.h"
+#include "nffs_test_priv.h"
+#include "nffs_test_utils.h"
 
 #if MYNEWT_VAL(SELFTEST)
 struct nffs_area_desc nffs_selftest_area_descs[] = {
@@ -120,7 +119,7 @@ nffs_test_suite_gen_1_1_init(void)
     tu_suite_set_post_test_cb(nffs_testcase_post, NULL);
     return;
 }
-    
+
 void
 nffs_test_suite_gen_4_32_init(void)
 {
@@ -131,7 +130,7 @@ nffs_test_suite_gen_4_32_init(void)
     tu_suite_set_post_test_cb(nffs_testcase_post, NULL);
     return;
 }
-    
+
 void
 nffs_test_suite_gen_32_1024_init(void)
 {
diff --git a/test/src/nffs_test_debug.c b/test/src/nffs_test_debug.c
index 2e2965d..7013a40 100644
--- a/test/src/nffs_test_debug.c
+++ b/test/src/nffs_test_debug.c
@@ -27,7 +27,6 @@
 #include "nffs/nffs.h"
 #include "nffs_test.h"
 #include "nffs_test_priv.h"
-#include "nffs_priv.h"
 
 int print_verbose;
 
@@ -166,7 +165,7 @@ print_nffs_flash_areas(int verbose)
     int i;
 
     for (i = 0; nffs_current_area_descs[i].nad_length != 0; i++) {
-        if (i > NFFS_MAX_AREAS) {
+        if (i > NFFS_CONFIG_MAX_AREAS) {
             return;
         }
         area.na_offset = nffs_current_area_descs[i].nad_offset;
diff --git a/test/src/nffs_test_utils.c b/test/src/nffs_test_utils.c
index fea07b8..ca1f387 100644
--- a/test/src/nffs_test_utils.c
+++ b/test/src/nffs_test_utils.c
@@ -28,7 +28,7 @@
 #include "nffs/nffs.h"
 #include "nffs_test.h"
 #include "nffs_test_priv.h"
-#include "nffs_priv.h"
+#include "nffs_test_utils.h"
 
 #if 0
 #ifdef ARCH_sim
diff --git a/test/src/nffs_test_utils.h b/test/src/nffs_test_utils.h
index c211a2d..7b7dcad 100644
--- a/test/src/nffs_test_utils.h
+++ b/test/src/nffs_test_utils.h
@@ -28,16 +28,28 @@
 #include "testutil/testutil.h"
 #include "fs/fs.h"
 #include "nffs/nffs.h"
+#include "nffs/os.h"
 #include "nffs_test.h"
 #include "nffs_test_priv.h"
-#include "nffs_priv.h"
 
 #ifdef __cplusplus
 #extern "C" {
 #endif
 
-extern struct nffs_hash_entry *nffs_test_touched_entries;
-int nffs_test_num_touched_entries;
+#define nffs_format(x) nffs_format_full(x)
+#define nffs_detect(x) nffs_restore_full(x)
+
+struct nffs_config {
+    uint32_t nc_num_inodes;
+    uint32_t nc_num_blocks;
+    uint32_t nc_num_files;
+    uint32_t nc_num_dirs;
+    uint32_t nc_num_cache_inodes;
+    uint32_t nc_num_cache_blocks;
+};
+extern struct nffs_config nffs_config;
+
+int nffs_init(void);
 
 extern int flash_native_memset(uint32_t offset, uint8_t c, uint32_t len);
 
diff --git a/test/src/testcases/append_test.c b/test/src/testcases/append_test.c
index e82b6b9..7d6bab5 100644
--- a/test/src/testcases/append_test.c
+++ b/test/src/testcases/append_test.c
@@ -18,6 +18,7 @@
  */
 
 #include "nffs_test_utils.h"
+#include <nffs/nffs.h>
 
 void process_inode_entry(struct nffs_inode_entry *inode_entry, int indent);
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services