acassis commented on code in PR #3278:
URL: https://github.com/apache/nuttx-apps/pull/3278#discussion_r2649057713


##########
testing/nuts/dstructs/cbuf.c:
##########
@@ -0,0 +1,698 @@
+/****************************************************************************
+ * apps/testing/nuts/dstructs/cbuf.c
+ *
+ * SPDX-License-Identifier: Apache-2.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/circbuf.h>
+
+#include "tests.h"
+
+#ifdef CONFIG_TESTING_NUTS_DSTRUCTS_CBUF
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBUF_SIZE (16)
+#define CBUF_HALFSIZE (CBUF_SIZE / 2)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct circbuf_s g_cbuf;
+static uint8_t g_buf[CBUF_SIZE];
+static uint8_t g_popbuf[CBUF_SIZE] =
+{
+    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: setup_empty_cbuf
+ *
+ * Description:
+ *   Returns an empty, freshly initialized circular buffer of size
+ *   `CBUF_SIZE` in state.
+ ****************************************************************************/
+
+static int setup_empty_cbuf(void **state)
+{
+  *state = &g_cbuf;
+  return circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+}
+
+/****************************************************************************
+ * Name: setup_partial_cbuf
+ *
+ * Description:
+ *   Returns a circular buffer of size `CBUF_SIZE` which is not empty but is
+ *   not full.
+ ****************************************************************************/
+
+static int setup_partial_cbuf(void **state)
+{
+  int err;
+  *state = &g_cbuf;
+  err = circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+
+  if (err)
+    {
+      return err;
+    }
+
+  if (circbuf_write(&g_cbuf, g_popbuf, CBUF_HALFSIZE) != CBUF_HALFSIZE)
+    {
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: setup_full_cbuf
+ *
+ * Description:
+ *   Returns a circular buffer which is full.
+ ****************************************************************************/
+
+static int setup_full_cbuf(void **state)
+{
+  int err;
+  *state = &g_cbuf;
+  err = circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+
+  if (err)
+    {
+      return err;
+    }
+
+  if (circbuf_write(&g_cbuf, g_popbuf, sizeof(g_popbuf)) != sizeof(g_popbuf))
+    {
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: teardown_cbuf
+ *
+ * Description:
+ *   Uninitializes a circular buffer.
+ ****************************************************************************/
+
+static int teardown_cbuf(void **state)
+{
+  circbuf_uninit(*state);
+  if (circbuf_is_init(*state)) return -1;

Review Comment:
   Ditto



##########
testing/nuts/dstructs/cbuf.c:
##########
@@ -0,0 +1,698 @@
+/****************************************************************************
+ * apps/testing/nuts/dstructs/cbuf.c
+ *
+ * SPDX-License-Identifier: Apache-2.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/circbuf.h>
+
+#include "tests.h"
+
+#ifdef CONFIG_TESTING_NUTS_DSTRUCTS_CBUF
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBUF_SIZE (16)
+#define CBUF_HALFSIZE (CBUF_SIZE / 2)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct circbuf_s g_cbuf;
+static uint8_t g_buf[CBUF_SIZE];
+static uint8_t g_popbuf[CBUF_SIZE] =
+{
+    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: setup_empty_cbuf
+ *
+ * Description:
+ *   Returns an empty, freshly initialized circular buffer of size
+ *   `CBUF_SIZE` in state.
+ ****************************************************************************/
+
+static int setup_empty_cbuf(void **state)
+{
+  *state = &g_cbuf;
+  return circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+}
+
+/****************************************************************************
+ * Name: setup_partial_cbuf
+ *
+ * Description:
+ *   Returns a circular buffer of size `CBUF_SIZE` which is not empty but is
+ *   not full.
+ ****************************************************************************/
+
+static int setup_partial_cbuf(void **state)
+{
+  int err;
+  *state = &g_cbuf;
+  err = circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+
+  if (err)
+    {
+      return err;
+    }
+
+  if (circbuf_write(&g_cbuf, g_popbuf, CBUF_HALFSIZE) != CBUF_HALFSIZE)
+    {
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: setup_full_cbuf
+ *
+ * Description:
+ *   Returns a circular buffer which is full.
+ ****************************************************************************/
+
+static int setup_full_cbuf(void **state)
+{
+  int err;
+  *state = &g_cbuf;
+  err = circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+
+  if (err)
+    {
+      return err;
+    }
+
+  if (circbuf_write(&g_cbuf, g_popbuf, sizeof(g_popbuf)) != sizeof(g_popbuf))
+    {
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: teardown_cbuf
+ *
+ * Description:
+ *   Uninitializes a circular buffer.
+ ****************************************************************************/
+
+static int teardown_cbuf(void **state)
+{
+  circbuf_uninit(*state);
+  if (circbuf_is_init(*state)) return -1;
+  return 0;
+}
+
+/****************************************************************************
+ * Name: init_static
+ *
+ * Description:
+ *   Tests that a statically initialized circular buffer functions properly.
+ ****************************************************************************/
+
+static void init_static(void **state)
+{
+  UNUSED(state);
+  uint8_t bbuf[CBUF_SIZE];
+  struct circbuf_s cbuf = CIRCBUF_INITIALIZER(bbuf, sizeof(bbuf));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(sizeof(bbuf), circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(sizeof(bbuf), circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: init_local
+ *
+ * Description:
+ *   Tests that a circular buffer can be initialized with a local buffer, and
+ *   subsequently uninitialized.
+ ****************************************************************************/
+
+static void init_local(void **state)
+{
+  UNUSED(state);
+  struct circbuf_s cbuf;
+  uint8_t bbuf[CBUF_SIZE];
+  assert_int_equal(0, circbuf_init(&cbuf, bbuf, sizeof(bbuf)));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(sizeof(bbuf), circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(sizeof(bbuf), circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: init_malloc
+ *
+ * Description:
+ *   Tests that a circular buffer can be initialized using an internally
+ *   malloc'd buffer and subsequently uninitialized.
+ ****************************************************************************/
+
+static void init_malloc(void **state)
+{
+  UNUSED(state);
+  struct circbuf_s cbuf;
+  assert_int_equal(0, circbuf_init(&cbuf, NULL, 16));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(16, circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(16, circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: empty_postinit
+ *
+ * Description:
+ *   Tests that a circular buffer is empty right after being initialized.
+ ****************************************************************************/
+
+static void empty_postinit(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+
+  assert_true(circbuf_is_empty(cbuf));
+  assert_false(circbuf_is_full(cbuf));
+  assert_uint_equal(0, circbuf_used(cbuf));
+  assert_uint_equal(CBUF_SIZE, circbuf_space(cbuf));
+}
+
+/****************************************************************************
+ * Name: fail_peek_empty
+ *
+ * Description:
+ *   Tests that circbuf_peek peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_peek_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_peek(cbuf, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: peekat_empty
+ *
+ * Description:
+ *   Tests that circbuf_peekat peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_peekat_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_peekat(cbuf, 0, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: fail_read_empty
+ *
+ * Description:
+ *   Tests that circbuf_read peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_read_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_read(cbuf, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: fail_skip_empty
+ *
+ * Description:
+ *   Tests that circbuf_skip can only skip zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_skip_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  assert_int_equal(0, circbuf_skip(cbuf, 1));
+  assert_int_equal(0, circbuf_skip(cbuf, 10));
+  assert_int_equal(0, circbuf_skip(cbuf, CBUF_SIZE + 1));
+}
+
+/****************************************************************************
+ * Name: empty_equal_pointers
+ *
+ * Description:
+ *   Tests that an empty circular buffer has the same value for the read and
+ *   write pointer.
+ ****************************************************************************/
+
+static void empty_equal_pointers(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  size_t sz;
+  void *rptr;
+  void *wptr;
+  rptr = circbuf_get_readptr(cbuf, &sz);
+  assert_non_null(rptr);
+  assert_uint_equal(0, sz);
+  wptr = circbuf_get_writeptr(cbuf, &sz);
+  assert_non_null(wptr);
+  assert_uint_equal(CBUF_SIZE, sz);
+  assert_ptr_equal(rptr, wptr);
+}
+
+/****************************************************************************
+ * Name: partial_init
+ *
+ * Description:
+ *   Tests that a circbuf partially initialized with some data has the
+ *   correct attributes.
+ ****************************************************************************/
+
+static void partial_init(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  assert_true(circbuf_is_init(cbuf));
+  assert_false(circbuf_is_empty(cbuf));
+  assert_false(circbuf_is_full(cbuf));
+  assert_uint_equal(CBUF_SIZE, circbuf_size(cbuf));
+  assert_uint_equal(CBUF_HALFSIZE, circbuf_used(cbuf));
+  assert_uint_not_equal(0, circbuf_space(cbuf));
+  assert_uint_not_equal(0, circbuf_used(cbuf));
+}
+
+/****************************************************************************
+ * Name: partial_not_equal_pointers
+ *
+ * Description:
+ *   Tests that a partially full circular buffer has different read and write
+ *   pointers.
+ ****************************************************************************/
+
+static void partial_not_equal_pointers(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  size_t sz;
+  void *rptr;
+  void *wptr;
+  rptr = circbuf_get_readptr(cbuf, &sz);

Review Comment:
   Please add empty line before rptr =



##########
testing/nuts/dstructs/cbuf.c:
##########
@@ -0,0 +1,698 @@
+/****************************************************************************
+ * apps/testing/nuts/dstructs/cbuf.c
+ *
+ * SPDX-License-Identifier: Apache-2.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/circbuf.h>
+
+#include "tests.h"
+
+#ifdef CONFIG_TESTING_NUTS_DSTRUCTS_CBUF
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBUF_SIZE (16)
+#define CBUF_HALFSIZE (CBUF_SIZE / 2)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct circbuf_s g_cbuf;
+static uint8_t g_buf[CBUF_SIZE];
+static uint8_t g_popbuf[CBUF_SIZE] =
+{
+    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: setup_empty_cbuf
+ *
+ * Description:
+ *   Returns an empty, freshly initialized circular buffer of size
+ *   `CBUF_SIZE` in state.
+ ****************************************************************************/
+
+static int setup_empty_cbuf(void **state)
+{
+  *state = &g_cbuf;
+  return circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+}
+
+/****************************************************************************
+ * Name: setup_partial_cbuf
+ *
+ * Description:
+ *   Returns a circular buffer of size `CBUF_SIZE` which is not empty but is
+ *   not full.
+ ****************************************************************************/
+
+static int setup_partial_cbuf(void **state)
+{
+  int err;
+  *state = &g_cbuf;
+  err = circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+
+  if (err)
+    {
+      return err;
+    }
+
+  if (circbuf_write(&g_cbuf, g_popbuf, CBUF_HALFSIZE) != CBUF_HALFSIZE)
+    {
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: setup_full_cbuf
+ *
+ * Description:
+ *   Returns a circular buffer which is full.
+ ****************************************************************************/
+
+static int setup_full_cbuf(void **state)
+{
+  int err;
+  *state = &g_cbuf;
+  err = circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+
+  if (err)
+    {
+      return err;
+    }
+
+  if (circbuf_write(&g_cbuf, g_popbuf, sizeof(g_popbuf)) != sizeof(g_popbuf))
+    {
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: teardown_cbuf
+ *
+ * Description:
+ *   Uninitializes a circular buffer.
+ ****************************************************************************/
+
+static int teardown_cbuf(void **state)
+{
+  circbuf_uninit(*state);
+  if (circbuf_is_init(*state)) return -1;
+  return 0;
+}
+
+/****************************************************************************
+ * Name: init_static
+ *
+ * Description:
+ *   Tests that a statically initialized circular buffer functions properly.
+ ****************************************************************************/
+
+static void init_static(void **state)
+{
+  UNUSED(state);
+  uint8_t bbuf[CBUF_SIZE];
+  struct circbuf_s cbuf = CIRCBUF_INITIALIZER(bbuf, sizeof(bbuf));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(sizeof(bbuf), circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(sizeof(bbuf), circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: init_local
+ *
+ * Description:
+ *   Tests that a circular buffer can be initialized with a local buffer, and
+ *   subsequently uninitialized.
+ ****************************************************************************/
+
+static void init_local(void **state)
+{
+  UNUSED(state);
+  struct circbuf_s cbuf;
+  uint8_t bbuf[CBUF_SIZE];
+  assert_int_equal(0, circbuf_init(&cbuf, bbuf, sizeof(bbuf)));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(sizeof(bbuf), circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(sizeof(bbuf), circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: init_malloc
+ *
+ * Description:
+ *   Tests that a circular buffer can be initialized using an internally
+ *   malloc'd buffer and subsequently uninitialized.
+ ****************************************************************************/
+
+static void init_malloc(void **state)
+{
+  UNUSED(state);
+  struct circbuf_s cbuf;
+  assert_int_equal(0, circbuf_init(&cbuf, NULL, 16));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(16, circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(16, circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: empty_postinit
+ *
+ * Description:
+ *   Tests that a circular buffer is empty right after being initialized.
+ ****************************************************************************/
+
+static void empty_postinit(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+
+  assert_true(circbuf_is_empty(cbuf));
+  assert_false(circbuf_is_full(cbuf));
+  assert_uint_equal(0, circbuf_used(cbuf));
+  assert_uint_equal(CBUF_SIZE, circbuf_space(cbuf));
+}
+
+/****************************************************************************
+ * Name: fail_peek_empty
+ *
+ * Description:
+ *   Tests that circbuf_peek peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_peek_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_peek(cbuf, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: peekat_empty
+ *
+ * Description:
+ *   Tests that circbuf_peekat peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_peekat_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_peekat(cbuf, 0, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: fail_read_empty
+ *
+ * Description:
+ *   Tests that circbuf_read peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_read_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_read(cbuf, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: fail_skip_empty
+ *
+ * Description:
+ *   Tests that circbuf_skip can only skip zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_skip_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  assert_int_equal(0, circbuf_skip(cbuf, 1));
+  assert_int_equal(0, circbuf_skip(cbuf, 10));
+  assert_int_equal(0, circbuf_skip(cbuf, CBUF_SIZE + 1));
+}
+
+/****************************************************************************
+ * Name: empty_equal_pointers
+ *
+ * Description:
+ *   Tests that an empty circular buffer has the same value for the read and
+ *   write pointer.
+ ****************************************************************************/
+
+static void empty_equal_pointers(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  size_t sz;
+  void *rptr;
+  void *wptr;
+  rptr = circbuf_get_readptr(cbuf, &sz);
+  assert_non_null(rptr);
+  assert_uint_equal(0, sz);
+  wptr = circbuf_get_writeptr(cbuf, &sz);
+  assert_non_null(wptr);
+  assert_uint_equal(CBUF_SIZE, sz);
+  assert_ptr_equal(rptr, wptr);
+}
+
+/****************************************************************************
+ * Name: partial_init
+ *
+ * Description:
+ *   Tests that a circbuf partially initialized with some data has the
+ *   correct attributes.
+ ****************************************************************************/
+
+static void partial_init(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  assert_true(circbuf_is_init(cbuf));
+  assert_false(circbuf_is_empty(cbuf));
+  assert_false(circbuf_is_full(cbuf));
+  assert_uint_equal(CBUF_SIZE, circbuf_size(cbuf));
+  assert_uint_equal(CBUF_HALFSIZE, circbuf_used(cbuf));
+  assert_uint_not_equal(0, circbuf_space(cbuf));
+  assert_uint_not_equal(0, circbuf_used(cbuf));
+}
+
+/****************************************************************************
+ * Name: partial_not_equal_pointers
+ *
+ * Description:
+ *   Tests that a partially full circular buffer has different read and write
+ *   pointers.
+ ****************************************************************************/
+
+static void partial_not_equal_pointers(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  size_t sz;
+  void *rptr;
+  void *wptr;
+  rptr = circbuf_get_readptr(cbuf, &sz);
+  assert_non_null(rptr);
+  assert_uint_not_equal(0, sz);
+  wptr = circbuf_get_writeptr(cbuf, &sz);

Review Comment:
   Please add empty line before "wptr =" to separate lines



##########
testing/nuts/dstructs/cbuf.c:
##########
@@ -0,0 +1,698 @@
+/****************************************************************************
+ * apps/testing/nuts/dstructs/cbuf.c
+ *
+ * SPDX-License-Identifier: Apache-2.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/circbuf.h>
+
+#include "tests.h"
+
+#ifdef CONFIG_TESTING_NUTS_DSTRUCTS_CBUF
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBUF_SIZE (16)
+#define CBUF_HALFSIZE (CBUF_SIZE / 2)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct circbuf_s g_cbuf;
+static uint8_t g_buf[CBUF_SIZE];
+static uint8_t g_popbuf[CBUF_SIZE] =
+{
+    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: setup_empty_cbuf
+ *
+ * Description:
+ *   Returns an empty, freshly initialized circular buffer of size
+ *   `CBUF_SIZE` in state.
+ ****************************************************************************/
+
+static int setup_empty_cbuf(void **state)
+{
+  *state = &g_cbuf;
+  return circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+}
+
+/****************************************************************************
+ * Name: setup_partial_cbuf
+ *
+ * Description:
+ *   Returns a circular buffer of size `CBUF_SIZE` which is not empty but is
+ *   not full.
+ ****************************************************************************/
+
+static int setup_partial_cbuf(void **state)
+{
+  int err;
+  *state = &g_cbuf;
+  err = circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+
+  if (err)
+    {
+      return err;
+    }
+
+  if (circbuf_write(&g_cbuf, g_popbuf, CBUF_HALFSIZE) != CBUF_HALFSIZE)
+    {
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: setup_full_cbuf
+ *
+ * Description:
+ *   Returns a circular buffer which is full.
+ ****************************************************************************/
+
+static int setup_full_cbuf(void **state)
+{
+  int err;
+  *state = &g_cbuf;
+  err = circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+
+  if (err)
+    {
+      return err;
+    }
+
+  if (circbuf_write(&g_cbuf, g_popbuf, sizeof(g_popbuf)) != sizeof(g_popbuf))
+    {
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: teardown_cbuf
+ *
+ * Description:
+ *   Uninitializes a circular buffer.
+ ****************************************************************************/
+
+static int teardown_cbuf(void **state)
+{
+  circbuf_uninit(*state);
+  if (circbuf_is_init(*state)) return -1;
+  return 0;
+}
+
+/****************************************************************************
+ * Name: init_static
+ *
+ * Description:
+ *   Tests that a statically initialized circular buffer functions properly.
+ ****************************************************************************/
+
+static void init_static(void **state)
+{
+  UNUSED(state);
+  uint8_t bbuf[CBUF_SIZE];
+  struct circbuf_s cbuf = CIRCBUF_INITIALIZER(bbuf, sizeof(bbuf));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(sizeof(bbuf), circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(sizeof(bbuf), circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: init_local
+ *
+ * Description:
+ *   Tests that a circular buffer can be initialized with a local buffer, and
+ *   subsequently uninitialized.
+ ****************************************************************************/
+
+static void init_local(void **state)
+{
+  UNUSED(state);
+  struct circbuf_s cbuf;
+  uint8_t bbuf[CBUF_SIZE];
+  assert_int_equal(0, circbuf_init(&cbuf, bbuf, sizeof(bbuf)));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(sizeof(bbuf), circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(sizeof(bbuf), circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: init_malloc
+ *
+ * Description:
+ *   Tests that a circular buffer can be initialized using an internally
+ *   malloc'd buffer and subsequently uninitialized.
+ ****************************************************************************/
+
+static void init_malloc(void **state)
+{
+  UNUSED(state);
+  struct circbuf_s cbuf;
+  assert_int_equal(0, circbuf_init(&cbuf, NULL, 16));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(16, circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(16, circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: empty_postinit
+ *
+ * Description:
+ *   Tests that a circular buffer is empty right after being initialized.
+ ****************************************************************************/
+
+static void empty_postinit(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+
+  assert_true(circbuf_is_empty(cbuf));
+  assert_false(circbuf_is_full(cbuf));
+  assert_uint_equal(0, circbuf_used(cbuf));
+  assert_uint_equal(CBUF_SIZE, circbuf_space(cbuf));
+}
+
+/****************************************************************************
+ * Name: fail_peek_empty
+ *
+ * Description:
+ *   Tests that circbuf_peek peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_peek_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_peek(cbuf, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: peekat_empty
+ *
+ * Description:
+ *   Tests that circbuf_peekat peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_peekat_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_peekat(cbuf, 0, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: fail_read_empty
+ *
+ * Description:
+ *   Tests that circbuf_read peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_read_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_read(cbuf, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: fail_skip_empty
+ *
+ * Description:
+ *   Tests that circbuf_skip can only skip zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_skip_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  assert_int_equal(0, circbuf_skip(cbuf, 1));
+  assert_int_equal(0, circbuf_skip(cbuf, 10));
+  assert_int_equal(0, circbuf_skip(cbuf, CBUF_SIZE + 1));
+}
+
+/****************************************************************************
+ * Name: empty_equal_pointers
+ *
+ * Description:
+ *   Tests that an empty circular buffer has the same value for the read and
+ *   write pointer.
+ ****************************************************************************/
+
+static void empty_equal_pointers(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  size_t sz;
+  void *rptr;
+  void *wptr;
+  rptr = circbuf_get_readptr(cbuf, &sz);

Review Comment:
   Suggestion: include an empty line to separate rptr block



##########
testing/nuts/dstructs/cbuf.c:
##########
@@ -0,0 +1,698 @@
+/****************************************************************************
+ * apps/testing/nuts/dstructs/cbuf.c
+ *
+ * SPDX-License-Identifier: Apache-2.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/circbuf.h>
+
+#include "tests.h"
+
+#ifdef CONFIG_TESTING_NUTS_DSTRUCTS_CBUF
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define CBUF_SIZE (16)
+#define CBUF_HALFSIZE (CBUF_SIZE / 2)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct circbuf_s g_cbuf;
+static uint8_t g_buf[CBUF_SIZE];
+static uint8_t g_popbuf[CBUF_SIZE] =
+{
+    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: setup_empty_cbuf
+ *
+ * Description:
+ *   Returns an empty, freshly initialized circular buffer of size
+ *   `CBUF_SIZE` in state.
+ ****************************************************************************/
+
+static int setup_empty_cbuf(void **state)
+{
+  *state = &g_cbuf;
+  return circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+}
+
+/****************************************************************************
+ * Name: setup_partial_cbuf
+ *
+ * Description:
+ *   Returns a circular buffer of size `CBUF_SIZE` which is not empty but is
+ *   not full.
+ ****************************************************************************/
+
+static int setup_partial_cbuf(void **state)
+{
+  int err;
+  *state = &g_cbuf;
+  err = circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+
+  if (err)
+    {
+      return err;
+    }
+
+  if (circbuf_write(&g_cbuf, g_popbuf, CBUF_HALFSIZE) != CBUF_HALFSIZE)
+    {
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: setup_full_cbuf
+ *
+ * Description:
+ *   Returns a circular buffer which is full.
+ ****************************************************************************/
+
+static int setup_full_cbuf(void **state)
+{
+  int err;
+  *state = &g_cbuf;
+  err = circbuf_init(&g_cbuf, g_buf, sizeof(g_buf));
+
+  if (err)
+    {
+      return err;
+    }
+
+  if (circbuf_write(&g_cbuf, g_popbuf, sizeof(g_popbuf)) != sizeof(g_popbuf))
+    {
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: teardown_cbuf
+ *
+ * Description:
+ *   Uninitializes a circular buffer.
+ ****************************************************************************/
+
+static int teardown_cbuf(void **state)
+{
+  circbuf_uninit(*state);
+  if (circbuf_is_init(*state)) return -1;
+  return 0;
+}
+
+/****************************************************************************
+ * Name: init_static
+ *
+ * Description:
+ *   Tests that a statically initialized circular buffer functions properly.
+ ****************************************************************************/
+
+static void init_static(void **state)
+{
+  UNUSED(state);
+  uint8_t bbuf[CBUF_SIZE];
+  struct circbuf_s cbuf = CIRCBUF_INITIALIZER(bbuf, sizeof(bbuf));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(sizeof(bbuf), circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(sizeof(bbuf), circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: init_local
+ *
+ * Description:
+ *   Tests that a circular buffer can be initialized with a local buffer, and
+ *   subsequently uninitialized.
+ ****************************************************************************/
+
+static void init_local(void **state)
+{
+  UNUSED(state);
+  struct circbuf_s cbuf;
+  uint8_t bbuf[CBUF_SIZE];
+  assert_int_equal(0, circbuf_init(&cbuf, bbuf, sizeof(bbuf)));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(sizeof(bbuf), circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(sizeof(bbuf), circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: init_malloc
+ *
+ * Description:
+ *   Tests that a circular buffer can be initialized using an internally
+ *   malloc'd buffer and subsequently uninitialized.
+ ****************************************************************************/
+
+static void init_malloc(void **state)
+{
+  UNUSED(state);
+  struct circbuf_s cbuf;
+  assert_int_equal(0, circbuf_init(&cbuf, NULL, 16));
+
+  assert_true(circbuf_is_init(&cbuf));
+
+  assert_uint_equal(16, circbuf_size(&cbuf));
+  assert_uint_equal(0, circbuf_used(&cbuf));
+  assert_uint_equal(16, circbuf_space(&cbuf));
+
+  circbuf_uninit(&cbuf);
+  assert_false(circbuf_is_init(&cbuf));
+}
+
+/****************************************************************************
+ * Name: empty_postinit
+ *
+ * Description:
+ *   Tests that a circular buffer is empty right after being initialized.
+ ****************************************************************************/
+
+static void empty_postinit(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+
+  assert_true(circbuf_is_empty(cbuf));
+  assert_false(circbuf_is_full(cbuf));
+  assert_uint_equal(0, circbuf_used(cbuf));
+  assert_uint_equal(CBUF_SIZE, circbuf_space(cbuf));
+}
+
+/****************************************************************************
+ * Name: fail_peek_empty
+ *
+ * Description:
+ *   Tests that circbuf_peek peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_peek_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_peek(cbuf, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: peekat_empty
+ *
+ * Description:
+ *   Tests that circbuf_peekat peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_peekat_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_peekat(cbuf, 0, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: fail_read_empty
+ *
+ * Description:
+ *   Tests that circbuf_read peeks zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_read_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  uint8_t buf;
+  assert_int_equal(0, circbuf_read(cbuf, &buf, sizeof(buf)));
+}
+
+/****************************************************************************
+ * Name: fail_skip_empty
+ *
+ * Description:
+ *   Tests that circbuf_skip can only skip zero bytes from an empty circbuf.
+ ****************************************************************************/
+
+static void fail_skip_empty(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  assert_int_equal(0, circbuf_skip(cbuf, 1));
+  assert_int_equal(0, circbuf_skip(cbuf, 10));
+  assert_int_equal(0, circbuf_skip(cbuf, CBUF_SIZE + 1));
+}
+
+/****************************************************************************
+ * Name: empty_equal_pointers
+ *
+ * Description:
+ *   Tests that an empty circular buffer has the same value for the read and
+ *   write pointer.
+ ****************************************************************************/
+
+static void empty_equal_pointers(void **state)
+{
+  struct circbuf_s *cbuf = *state;
+  size_t sz;
+  void *rptr;
+  void *wptr;
+  rptr = circbuf_get_readptr(cbuf, &sz);
+  assert_non_null(rptr);
+  assert_uint_equal(0, sz);
+  wptr = circbuf_get_writeptr(cbuf, &sz);

Review Comment:
   Suggestion: add an empty line to separate wptr block



##########
testing/nuts/devices/devurandom.c:
##########
@@ -0,0 +1,271 @@
+/****************************************************************************
+ * apps/testing/nuts/devices/devurandom.c
+ *
+ * SPDX-License-Identifier: Apache-2.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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "tests.h"
+
+#ifdef CONFIG_TESTING_NUTS_DEVICES_DEVURANDOM
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DEVURANDOM "/dev/urandom"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: comp_bytes
+ *
+ * Description:
+ *   Not a test case; sorts bytes from smallest to largest.
+ ****************************************************************************/
+
+static int comp_bytes(const void *p1, const void *p2)
+{
+  const uint8_t *a = p1;
+  const uint8_t *b = p2;
+  if (*a == *b) return 0;
+  if (*a < *b) return -1;
+  return 1;
+}
+
+/****************************************************************************
+ * Name: open_rdonly
+ *
+ * Description:
+ *   Test open/close operation of the urandom device in read only mode.
+ ****************************************************************************/
+
+static void open_rdonly(void **state)
+{
+  UNUSED(state);
+  int fd;
+  fd = open(DEVURANDOM, O_RDONLY);
+  assert_true(fd >= 0);
+  assert_int_equal(0, close(fd));
+}
+
+/****************************************************************************
+ * Name: open_rdwr
+ *
+ * Description:
+ *   Test open/close operation of the urandom device in read/write mode.
+ ****************************************************************************/
+
+static void open_rdwr(void **state)
+{
+  UNUSED(state);
+  int fd;
+  fd = open(DEVURANDOM, O_RDWR);
+  assert_true(fd >= 0);
+  assert_int_equal(0, close(fd));
+}
+
+/****************************************************************************
+ * Name: open_wronly
+ *
+ * Description:
+ *   Test open/close operation of the urandom device in write only mode.
+ ****************************************************************************/
+
+static void open_wronly(void **state)
+{
+  UNUSED(state);
+  int fd;
+  fd = open(DEVURANDOM, O_WRONLY);
+  assert_true(fd >= 0);
+  assert_int_equal(0, close(fd));
+}
+
+/****************************************************************************
+ * Name: readzero
+ *
+ * Description:
+ *   Test that reading zero from /dev/urandom does nothing.
+ ****************************************************************************/
+
+static void readzero(void **state)
+{
+  UNUSED(state);
+  int fd;
+  uint8_t buf[16];
+  fd = open(DEVURANDOM, O_RDONLY);
+  assert_true(fd >= 0);
+
+  memset(buf, 0xa5, sizeof(buf));
+  assert_int_equal(0, read(fd, buf, 0));
+
+  /* Ensure buffer is unchanged */
+
+  for (unsigned i = 0; i < sizeof(buf); i++)
+    {
+      assert_true(0xa5 == buf[i]);
+    }
+
+  assert_int_equal(0, close(fd));
+}
+
+/****************************************************************************
+ * Name: writezero
+ *
+ * Description:
+ *   Test that writing zero bytes does nothing.
+ ****************************************************************************/
+
+static void writezero(void **state)
+{
+  UNUSED(state);
+  int fd;
+  char buf[16];
+  fd = open(DEVURANDOM, O_WRONLY);
+  assert_true(fd >= 0);
+
+  memset(buf, 0xa5a5, sizeof(buf));
+  assert_int_equal(0, write(fd, buf, 0));
+
+  assert_int_equal(0, close(fd));
+}
+
+/****************************************************************************
+ * Name: readlarge
+ *
+ * Description:
+ *   Test that reading a full buffer overwrites all its contents with a
+ *   random character.
+ ****************************************************************************/
+
+static void readlarge(void **state)
+{
+  UNUSED(state);
+  int fd;
+  uint8_t buf[32];
+  unsigned count;
+  fd = open(DEVURANDOM, O_RDONLY);
+  assert_true(fd >= 0);
+
+  memset(buf, 0xa5, sizeof(buf));
+  assert_int_equal(sizeof(buf), read(fd, buf, sizeof(buf)));
+
+  count = 0;
+  for (unsigned int i = 0; i < sizeof(buf); i++)
+    {
+      if (buf[i] == 0xa5) count++;
+    }
+
+  /* With 256 possible byte values and 32 draws, the chances that we see
+   * more than 2 bytes unchanged is < 0.001 %
+   */
+
+  assert_true(count <= 2);
+
+  assert_int_equal(0, close(fd));
+}
+
+/****************************************************************************
+ * Name: uniform
+ *
+ * Description:
+ *   Perform the Kolmogorov-Smirnov test for uniformity to ensure a uniform
+ *   random distribution of returned bytes with a 0.05 significance level.
+ ****************************************************************************/
+
+static void uniformity_check(void **state)
+{
+  UNUSED(state);
+  int fd;
+  uint8_t buf[50];
+  float d_plus;
+  float d_minus;
+  float d;
+  float temp_plus;
+  float temp_minus;
+  fd = open(DEVURANDOM, O_RDONLY);
+  assert_true(fd >= 0);
+
+  /* Get sampled bytes and sort them in ascending order */
+
+  memset(buf, 0xa5, sizeof(buf));
+  assert_int_equal(sizeof(buf), read(fd, buf, sizeof(buf)));
+
+  qsort(buf, sizeof(buf), sizeof(uint8_t), comp_bytes);
+
+  /* Calculate D+ and D- */
+
+  d_plus = -(float)buf[0];
+  d_minus = (float)buf[0] + 1.0f / (float)sizeof(buf);
+  for (unsigned int i = 0; i < (float)sizeof(buf); i++)
+    {
+      temp_plus = (float)i / (float)sizeof(buf) - (float)buf[i];
+      temp_minus = (float)buf[i] - ((float)(i - 1) / (float)sizeof(buf));
+
+      if (temp_plus > d_plus) d_plus = temp_plus;
+      if (temp_minus > d_minus) d_minus = temp_minus;

Review Comment:
   Ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to