You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/09/29 01:34:10 UTC

[03/49] incubator-mynewt-core git commit: move cbmem into util/

move cbmem into util/


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/09aec6cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/09aec6cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/09aec6cc

Branch: refs/heads/develop
Commit: 09aec6cc8fb99d9feec93b94b8c455d28d27b877
Parents: 54fbe73
Author: Sterling Hughes <st...@apache.org>
Authored: Wed Sep 28 16:56:03 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Wed Sep 28 18:32:22 2016 -0700

----------------------------------------------------------------------
 libs/util/include/util/cbmem.h   |  66 --------
 libs/util/src/cbmem.c            | 277 ----------------------------------
 libs/util/test/src/cbmem_test.c  | 176 ---------------------
 sys/log/include/log/log.h        |   2 +-
 sys/log/src/log_cbmem.c          |   2 +-
 sys/log/src/log_console.c        |   2 +-
 sys/log/src/log_shell.c          |  20 +--
 util/cbmem/test/src/cbmem_test.c |  36 ++---
 8 files changed, 31 insertions(+), 550 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/09aec6cc/libs/util/include/util/cbmem.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/cbmem.h b/libs/util/include/util/cbmem.h
deleted file mode 100644
index 42decfb..0000000
--- a/libs/util/include/util/cbmem.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 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.
- */
-#ifndef __UTIL_CBMEM_H__ 
-#define __UTIL_CBMEM_H__
-
-#include <os/os.h>
-
-struct cbmem_entry_hdr {
-    uint16_t ceh_len;
-    uint16_t ceh_flags;
-} __attribute__((packed));
-
-struct cbmem {
-    struct os_mutex c_lock;
-
-    struct cbmem_entry_hdr *c_entry_start;
-    struct cbmem_entry_hdr *c_entry_end;
-    uint8_t *c_buf;
-    uint8_t *c_buf_end;
-    uint8_t *c_buf_cur_end;
-};
-
-struct cbmem_iter {
-    struct cbmem_entry_hdr *ci_start;
-    struct cbmem_entry_hdr *ci_cur;
-    struct cbmem_entry_hdr *ci_end;
-};
-
-#define CBMEM_ENTRY_SIZE(__p) (sizeof(struct cbmem_entry_hdr) \
-        + ((struct cbmem_entry_hdr *) (__p))->ceh_len)
-#define CBMEM_ENTRY_NEXT(__p) ((struct cbmem_entry_hdr *) \
-        ((uint8_t *) (__p) + CBMEM_ENTRY_SIZE(__p)))
-
-typedef int (*cbmem_walk_func_t)(struct cbmem *, struct cbmem_entry_hdr *, 
-        void *arg);
-
-int cbmem_lock_acquire(struct cbmem *cbmem);
-int cbmem_lock_release(struct cbmem *cbmem);
-int cbmem_init(struct cbmem *cbmem, void *buf, uint32_t buf_len);
-int cbmem_append(struct cbmem *cbmem, void *data, uint16_t len);
-void cbmem_iter_start(struct cbmem *cbmem, struct cbmem_iter *iter);
-struct cbmem_entry_hdr *cbmem_iter_next(struct cbmem *cbmem, 
-        struct cbmem_iter *iter);
-int cbmem_read(struct cbmem *cbmem, struct cbmem_entry_hdr *hdr, void *buf, 
-        uint16_t off, uint16_t len);
-int cbmem_walk(struct cbmem *cbmem, cbmem_walk_func_t walk_func, void *arg);
-
-int cbmem_flush(struct cbmem *);
-
-#endif /* __UTIL_CBMEM_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/09aec6cc/libs/util/src/cbmem.c
----------------------------------------------------------------------
diff --git a/libs/util/src/cbmem.c b/libs/util/src/cbmem.c
deleted file mode 100644
index 05051ae..0000000
--- a/libs/util/src/cbmem.c
+++ /dev/null
@@ -1,277 +0,0 @@
-/**
- * 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.
- */
-
-#include <os/os.h>
-#include <string.h>
-
-#include "util/cbmem.h" 
-
-
-int 
-cbmem_init(struct cbmem *cbmem, void *buf, uint32_t buf_len)
-{
-    os_mutex_init(&cbmem->c_lock);
-
-    memset(cbmem, 0, sizeof(*cbmem));
-    cbmem->c_buf = buf;
-    cbmem->c_buf_end = buf + buf_len;
-
-    return (0);
-}
-
-int 
-cbmem_lock_acquire(struct cbmem *cbmem) 
-{
-    int rc;
-
-    if (!os_started()) {
-        return (0);
-    }
-
-    rc = os_mutex_pend(&cbmem->c_lock, OS_WAIT_FOREVER);
-    if (rc != 0) {
-        goto err;
-    }
-
-    return (0);
-err:
-    return (rc);
-}
-
-int 
-cbmem_lock_release(struct cbmem *cbmem)
-{
-    int rc;
-
-    if (!os_started()) {
-        return (0);
-    }
-
-    rc = os_mutex_release(&cbmem->c_lock);
-    if (rc != 0) {
-        goto err;
-    }
-
-    return (0);
-err:
-    return (rc);
-}
-
-
-int 
-cbmem_append(struct cbmem *cbmem, void *data, uint16_t len)
-{
-    struct cbmem_entry_hdr *dst;
-    uint8_t *start;
-    uint8_t *end;
-    int rc;
-
-    rc = cbmem_lock_acquire(cbmem);
-    if (rc != 0) {
-        goto err;
-    }
-
-    if (cbmem->c_entry_end) {
-        dst = CBMEM_ENTRY_NEXT(cbmem->c_entry_end);
-    } else {
-        dst = (struct cbmem_entry_hdr *) cbmem->c_buf;
-    }
-    end = (uint8_t *) dst + len + sizeof(*dst);
-
-    /* If this item would take us past the end of this buffer, then adjust 
-     * the item to the beginning of the buffer.
-     */
-    if (end > cbmem->c_buf_end) {
-        cbmem->c_buf_cur_end = (uint8_t *) dst;
-        dst = (struct cbmem_entry_hdr *) cbmem->c_buf;
-        end = (uint8_t *) dst + len + sizeof(*dst);
-        if ((uint8_t *) cbmem->c_entry_start >= cbmem->c_buf_cur_end) {
-            cbmem->c_entry_start = (struct cbmem_entry_hdr *) cbmem->c_buf;
-        }
-    }
-
-    /* If the destination is prior to the start, and would overrwrite the 
-     * start of the buffer, move start forward until you don't overwrite it
-     * anymore.
-     */
-    start = (uint8_t *) cbmem->c_entry_start;
-    if (start && (uint8_t *) dst < start + CBMEM_ENTRY_SIZE(start) && 
-            end > start) {
-        while (start < end) {
-            start = (uint8_t *) CBMEM_ENTRY_NEXT(start);
-            if (start == cbmem->c_buf_cur_end) {
-                start = cbmem->c_buf;
-                break;
-            }
-        }
-        cbmem->c_entry_start = (struct cbmem_entry_hdr *) start;
-    }
-
-    /* Copy the entry into the log 
-     */
-    dst->ceh_len = len;
-    memcpy((uint8_t *) dst + sizeof(*dst), data, len);
-
-    cbmem->c_entry_end = dst;
-    if (!cbmem->c_entry_start) {
-        cbmem->c_entry_start = dst;
-    }
-
-    rc = cbmem_lock_release(cbmem);
-    if (rc != 0) {
-        goto err;
-    }
-
-    return (0);
-err:
-    return (-1);
-}
-
-void 
-cbmem_iter_start(struct cbmem *cbmem, struct cbmem_iter *iter)
-{
-    iter->ci_start = cbmem->c_entry_start;
-    iter->ci_cur = cbmem->c_entry_start;
-    iter->ci_end = cbmem->c_entry_end;
-}
-
-struct cbmem_entry_hdr *
-cbmem_iter_next(struct cbmem *cbmem, struct cbmem_iter *iter)
-{
-    struct cbmem_entry_hdr *hdr;
-
-    if (iter->ci_start > iter->ci_end) {
-        hdr = iter->ci_cur;
-        iter->ci_cur = CBMEM_ENTRY_NEXT(iter->ci_cur);
-
-        if ((uint8_t *) iter->ci_cur >= cbmem->c_buf_cur_end) {
-            iter->ci_cur = (struct cbmem_entry_hdr *) cbmem->c_buf;
-            iter->ci_start = (struct cbmem_entry_hdr *) cbmem->c_buf;
-        }
-    } else {
-        hdr = iter->ci_cur;
-        if (!iter->ci_cur) {
-            goto err;
-        }
-
-        if (hdr == CBMEM_ENTRY_NEXT(iter->ci_end)) {
-            hdr = NULL;
-        } else {
-            iter->ci_cur = CBMEM_ENTRY_NEXT(iter->ci_cur);
-        }
-    }
-
-err:
-    return (hdr);
-}
-
-int
-cbmem_flush(struct cbmem *cbmem)
-{
-    int rc;
-
-    rc = cbmem_lock_acquire(cbmem);
-    if (rc != 0) {
-        goto err;
-    }
-
-    cbmem->c_entry_start = NULL;
-    cbmem->c_entry_end = NULL;
-    cbmem->c_buf_cur_end = NULL;
-
-    rc = cbmem_lock_release(cbmem);
-    if (rc != 0) {
-        goto err;
-    }
-
-    return (0);
-err:
-    return (rc);
-}
-
-int 
-cbmem_read(struct cbmem *cbmem, struct cbmem_entry_hdr *hdr, void *buf, 
-        uint16_t off, uint16_t len)
-{
-    int rc;
-
-    rc = cbmem_lock_acquire(cbmem);
-    if (rc != 0) {
-        goto err;
-    }
-
-    /* Only read the maximum number of bytes, if we exceed that, 
-     * truncate the read.
-     */
-    if (off + len > hdr->ceh_len) {
-        len = hdr->ceh_len - off;
-    }
-
-    if (off > hdr->ceh_len) {
-        rc = -1;
-        cbmem_lock_release(cbmem);
-        goto err;
-    }
-
-    memcpy(buf, (uint8_t *) hdr + sizeof(*hdr) + off, len);
-
-    rc = cbmem_lock_release(cbmem);
-    if (rc != 0) {
-        goto err;
-    }
-
-    return (len);
-err:
-    return (-1);
-}
-
-int 
-cbmem_walk(struct cbmem *cbmem, cbmem_walk_func_t walk_func, void *arg)
-{
-    struct cbmem_entry_hdr *hdr;
-    struct cbmem_iter iter;
-    int rc;
-
-    rc = cbmem_lock_acquire(cbmem);
-    if (rc != 0) {
-        goto err;
-    }
-
-    cbmem_iter_start(cbmem, &iter);
-    while (1) {
-        hdr = cbmem_iter_next(cbmem, &iter);
-        if (hdr == NULL) {
-            break;
-        }
-
-        rc = walk_func(cbmem, hdr, arg);
-        if (rc == 1) {
-            break;
-        }
-    }
-
-    rc = cbmem_lock_release(cbmem);
-    if (rc != 0) {
-        goto err;
-    }
-
-    return (0);
-err:
-    return (rc);
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/09aec6cc/libs/util/test/src/cbmem_test.c
----------------------------------------------------------------------
diff --git a/libs/util/test/src/cbmem_test.c b/libs/util/test/src/cbmem_test.c
deleted file mode 100644
index b486334..0000000
--- a/libs/util/test/src/cbmem_test.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/**
- * 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.
- */
-#include <stdio.h>
-#include <string.h>
-
-#include "testutil/testutil.h"
-#include "util/cbmem.h" 
-
-#define CBMEM1_BUF_SIZE (64 * 1024)
-
-struct cbmem cbmem1;
-uint8_t cbmem1_buf[CBMEM1_BUF_SIZE];
-uint8_t cbmem1_entry[1024];
-
-/*
- * Things to test.
- *
- * - Wrap of the circular buffer.  
- * - Reading through all entries.
- */
-
-static void
-setup_cbmem1(void)
-{
-    int i;
-    int rc;
-
-    rc = cbmem_init(&cbmem1, cbmem1_buf, CBMEM1_BUF_SIZE);
-    TEST_ASSERT_FATAL(rc == 0, "cbmem_init() failed, non-zero RC = %d", rc);
-
-    memset(cbmem1_entry, 0xff, sizeof(cbmem1_entry));
-
-    /* Insert 65 1024 entries, and overflow buffer.  
-     * This should overflow two entries, because the buffer is sized for 64 
-     * entries, and then the headers themselves will eat into one of the entries, 
-     * so there should be a total of 63 entries.
-     * Ensure no data corruption.
-     */
-    for (i = 0; i < 65; i++) {
-        cbmem1_entry[0] = i;
-        rc = cbmem_append(&cbmem1, cbmem1_entry, sizeof(cbmem1_entry));
-        TEST_ASSERT_FATAL(rc == 0, "Could not append entry %d, rc = %d", i, rc);
-    }
-}
-
-static int 
-cbmem_test_case_1_walk(struct cbmem *cbmem, struct cbmem_entry_hdr *hdr, 
-        void *arg)
-{
-    uint8_t expected;
-    uint8_t actual;
-    int rc;
-
-    expected = *(uint8_t *) arg;
-
-    rc = cbmem_read(cbmem, hdr, &actual, 0, sizeof(actual));
-    TEST_ASSERT_FATAL(rc == 1, "Couldn't read 1 byte from cbmem");
-    TEST_ASSERT_FATAL(actual == expected, 
-            "Actual doesn't equal expected (%d = %d)", actual, expected);
-
-    *(uint8_t *) arg = ++expected;
-
-    return (0);
-}
-
-TEST_CASE(cbmem_test_case_1) 
-{
-    int i;
-    int rc;
-
-    /* i starts at 2, for the 2 overwritten entries. */
-    i = 2;
-    rc = cbmem_walk(&cbmem1, cbmem_test_case_1_walk, &i);
-    TEST_ASSERT_FATAL(rc == 0, "Could not walk cbmem tree!  rc = %d", rc);
-    TEST_ASSERT_FATAL(i == 65, 
-            "Did not go through every element of walk, %d processed", i - 2);
-
-}
-
-TEST_CASE(cbmem_test_case_2)
-{
-    struct cbmem_entry_hdr *hdr;
-    struct cbmem_iter iter;
-    uint8_t i;
-    uint8_t val;
-    int rc;
-
-    i = 2;
-    cbmem_iter_start(&cbmem1, &iter);
-    while (1) {
-        hdr = cbmem_iter_next(&cbmem1, &iter);
-        if (hdr == NULL) {
-            break;
-        }
-
-        rc = cbmem_read(&cbmem1, hdr, &val, 0, sizeof(val));
-        TEST_ASSERT_FATAL(rc == 1, "Couldn't read 1 byte from cbmem");
-        TEST_ASSERT_FATAL(val == i, "Entry index does not match %d vs %d", 
-                val, i);
-
-        i++;
-    }
-
-    /* i starts at 2, for the 2 overwritten entries */
-    TEST_ASSERT_FATAL(i == 65, 
-            "Did not iterate through all 63 elements of CBMEM1, processed %d", 
-            i - 2);
-}
-
-TEST_CASE(cbmem_test_case_3)
-{
-    struct cbmem_entry_hdr *hdr;
-    struct cbmem_iter iter;
-    uint16_t off;
-    uint16_t len;
-    uint8_t buf[128];
-    int i;
-    int rc;
-
-    i = 0;
-    cbmem_iter_start(&cbmem1, &iter);
-    while (1) {
-        hdr = cbmem_iter_next(&cbmem1, &iter);
-        if (hdr == NULL) {
-            break;
-        }
-        
-        /* first ensure we can read the entire entry */
-        off = 0;
-        len = 0;
-        while (1) {
-            rc = cbmem_read(&cbmem1, hdr, buf, off, sizeof(buf));
-            TEST_ASSERT_FATAL(rc >= 0,
-                    "Error reading from buffer rc=%d, off=%d,len=%d", rc, off, 
-                    sizeof(buf));
-            if (rc == 0) {
-                break;
-            }
-            off += rc;
-            len += rc;
-        }
-        TEST_ASSERT_FATAL(len == 1024, 
-                "Couldn't read full entry, expected %d got %d", 1024, len);
-        i++;
-
-        /* go apesh*t, and read data out of bounds, see what we get. */
-        rc = cbmem_read(&cbmem1, hdr, buf, 2048, sizeof(buf));
-        TEST_ASSERT_FATAL(rc < 0, 
-                "Reading invalid should return error, instead %d returned.",
-                rc);
-    }
-}
-
-TEST_SUITE(cbmem_test_suite)
-{
-    setup_cbmem1();
-    cbmem_test_case_1();
-    cbmem_test_case_2();
-    cbmem_test_case_3();
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/09aec6cc/sys/log/include/log/log.h
----------------------------------------------------------------------
diff --git a/sys/log/include/log/log.h b/sys/log/include/log/log.h
index 48deb0b..d02c44d 100644
--- a/sys/log/include/log/log.h
+++ b/sys/log/include/log/log.h
@@ -21,7 +21,7 @@
 
 #include "syscfg/syscfg.h"
 #include "log/ignore.h"
-#include "util/cbmem.h"
+#include "cbmem/cbmem.h"
 
 #include <os/queue.h>
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/09aec6cc/sys/log/src/log_cbmem.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log_cbmem.c b/sys/log/src/log_cbmem.c
index 0caa17b..4efafc8 100644
--- a/sys/log/src/log_cbmem.c
+++ b/sys/log/src/log_cbmem.c
@@ -17,7 +17,7 @@
  * under the License.
  */
 #include <os/os.h>
-#include <util/cbmem.h>
+#include <cbmem/cbmem.h>
 #include "log/log.h"
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/09aec6cc/sys/log/src/log_console.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log_console.c b/sys/log/src/log_console.c
index 73814da..5fb2065 100644
--- a/sys/log/src/log_console.c
+++ b/sys/log/src/log_console.c
@@ -18,7 +18,7 @@
  */
 
 #include <os/os.h>
-#include <util/cbmem.h>
+#include <cbmem/cbmem.h>
 #include <console/console.h>
 #include "log/log.h"
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/09aec6cc/sys/log/src/log_shell.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log_shell.c b/sys/log/src/log_shell.c
index 7188b5d..f7503f7 100644
--- a/sys/log/src/log_shell.c
+++ b/sys/log/src/log_shell.c
@@ -6,7 +6,7 @@
  * 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,
@@ -19,7 +19,7 @@
 
 #include "syscfg/syscfg.h"
 
-/* This whole file is conditionally compiled based on whether the 
+/* This whole file is conditionally compiled based on whether the
  * log package is configured to use the shell (MYNEWT_VAL(LOG_CLI)).
  */
 
@@ -29,20 +29,20 @@
 #include <string.h>
 
 #include "os/os.h"
-#include "util/cbmem.h"
+#include "cbmem/cbmem.h"
 #include "log/log.h"
 #include "shell/shell.h"
 #include "console/console.h"
 
-static int 
-shell_log_dump_entry(struct log *log, void *arg, void *dptr, uint16_t len) 
+static int
+shell_log_dump_entry(struct log *log, void *arg, void *dptr, uint16_t len)
 {
     struct log_entry_hdr ueh;
     char data[128];
     int dlen;
     int rc;
 
-    rc = log_read(log, dptr, &ueh, 0, sizeof(ueh)); 
+    rc = log_read(log, dptr, &ueh, 0, sizeof(ueh));
     if (rc != sizeof(ueh)) {
         goto err;
     }
@@ -55,8 +55,8 @@ shell_log_dump_entry(struct log *log, void *arg, void *dptr, uint16_t len)
     }
     data[rc] = 0;
 
-    /* XXX: This is evil.  newlib printf does not like 64-bit 
-     * values, and this causes memory to be overwritten.  Cast to a 
+    /* XXX: This is evil.  newlib printf does not like 64-bit
+     * values, and this causes memory to be overwritten.  Cast to a
      * unsigned 32-bit value for now.
      */
     console_printf("[%lu] %s\n", (unsigned long) ueh.ue_ts, data);
@@ -66,7 +66,7 @@ err:
     return (rc);
 }
 
-int 
+int
 shell_log_dump_all_cmd(int argc, char **argv)
 {
     struct log *log;
@@ -96,6 +96,6 @@ err:
     return (rc);
 }
 
-#endif 
+#endif
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/09aec6cc/util/cbmem/test/src/cbmem_test.c
----------------------------------------------------------------------
diff --git a/util/cbmem/test/src/cbmem_test.c b/util/cbmem/test/src/cbmem_test.c
index b486334..755908c 100644
--- a/util/cbmem/test/src/cbmem_test.c
+++ b/util/cbmem/test/src/cbmem_test.c
@@ -6,7 +6,7 @@
  * 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,
@@ -20,7 +20,7 @@
 #include <string.h>
 
 #include "testutil/testutil.h"
-#include "util/cbmem.h" 
+#include "cbmem/cbmem.h"
 
 #define CBMEM1_BUF_SIZE (64 * 1024)
 
@@ -31,7 +31,7 @@ uint8_t cbmem1_entry[1024];
 /*
  * Things to test.
  *
- * - Wrap of the circular buffer.  
+ * - Wrap of the circular buffer.
  * - Reading through all entries.
  */
 
@@ -46,9 +46,9 @@ setup_cbmem1(void)
 
     memset(cbmem1_entry, 0xff, sizeof(cbmem1_entry));
 
-    /* Insert 65 1024 entries, and overflow buffer.  
-     * This should overflow two entries, because the buffer is sized for 64 
-     * entries, and then the headers themselves will eat into one of the entries, 
+    /* Insert 65 1024 entries, and overflow buffer.
+     * This should overflow two entries, because the buffer is sized for 64
+     * entries, and then the headers themselves will eat into one of the entries,
      * so there should be a total of 63 entries.
      * Ensure no data corruption.
      */
@@ -59,8 +59,8 @@ setup_cbmem1(void)
     }
 }
 
-static int 
-cbmem_test_case_1_walk(struct cbmem *cbmem, struct cbmem_entry_hdr *hdr, 
+static int
+cbmem_test_case_1_walk(struct cbmem *cbmem, struct cbmem_entry_hdr *hdr,
         void *arg)
 {
     uint8_t expected;
@@ -71,7 +71,7 @@ cbmem_test_case_1_walk(struct cbmem *cbmem, struct cbmem_entry_hdr *hdr,
 
     rc = cbmem_read(cbmem, hdr, &actual, 0, sizeof(actual));
     TEST_ASSERT_FATAL(rc == 1, "Couldn't read 1 byte from cbmem");
-    TEST_ASSERT_FATAL(actual == expected, 
+    TEST_ASSERT_FATAL(actual == expected,
             "Actual doesn't equal expected (%d = %d)", actual, expected);
 
     *(uint8_t *) arg = ++expected;
@@ -79,7 +79,7 @@ cbmem_test_case_1_walk(struct cbmem *cbmem, struct cbmem_entry_hdr *hdr,
     return (0);
 }
 
-TEST_CASE(cbmem_test_case_1) 
+TEST_CASE(cbmem_test_case_1)
 {
     int i;
     int rc;
@@ -88,7 +88,7 @@ TEST_CASE(cbmem_test_case_1)
     i = 2;
     rc = cbmem_walk(&cbmem1, cbmem_test_case_1_walk, &i);
     TEST_ASSERT_FATAL(rc == 0, "Could not walk cbmem tree!  rc = %d", rc);
-    TEST_ASSERT_FATAL(i == 65, 
+    TEST_ASSERT_FATAL(i == 65,
             "Did not go through every element of walk, %d processed", i - 2);
 
 }
@@ -111,15 +111,15 @@ TEST_CASE(cbmem_test_case_2)
 
         rc = cbmem_read(&cbmem1, hdr, &val, 0, sizeof(val));
         TEST_ASSERT_FATAL(rc == 1, "Couldn't read 1 byte from cbmem");
-        TEST_ASSERT_FATAL(val == i, "Entry index does not match %d vs %d", 
+        TEST_ASSERT_FATAL(val == i, "Entry index does not match %d vs %d",
                 val, i);
 
         i++;
     }
 
     /* i starts at 2, for the 2 overwritten entries */
-    TEST_ASSERT_FATAL(i == 65, 
-            "Did not iterate through all 63 elements of CBMEM1, processed %d", 
+    TEST_ASSERT_FATAL(i == 65,
+            "Did not iterate through all 63 elements of CBMEM1, processed %d",
             i - 2);
 }
 
@@ -140,14 +140,14 @@ TEST_CASE(cbmem_test_case_3)
         if (hdr == NULL) {
             break;
         }
-        
+
         /* first ensure we can read the entire entry */
         off = 0;
         len = 0;
         while (1) {
             rc = cbmem_read(&cbmem1, hdr, buf, off, sizeof(buf));
             TEST_ASSERT_FATAL(rc >= 0,
-                    "Error reading from buffer rc=%d, off=%d,len=%d", rc, off, 
+                    "Error reading from buffer rc=%d, off=%d,len=%d", rc, off,
                     sizeof(buf));
             if (rc == 0) {
                 break;
@@ -155,13 +155,13 @@ TEST_CASE(cbmem_test_case_3)
             off += rc;
             len += rc;
         }
-        TEST_ASSERT_FATAL(len == 1024, 
+        TEST_ASSERT_FATAL(len == 1024,
                 "Couldn't read full entry, expected %d got %d", 1024, len);
         i++;
 
         /* go apesh*t, and read data out of bounds, see what we get. */
         rc = cbmem_read(&cbmem1, hdr, buf, 2048, sizeof(buf));
-        TEST_ASSERT_FATAL(rc < 0, 
+        TEST_ASSERT_FATAL(rc < 0,
                 "Reading invalid should return error, instead %d returned.",
                 rc);
     }