Commit a5bde70d authored by Anas Nashif's avatar Anas Nashif Committed by Anas Nashif
Browse files

tests: add ringbuffer api test and combine original test



We already have a test for ring buffers, this combines it with an API
test.

Signed-off-by: default avatarAnas Nashif <anas.nashif@intel.com>
parent 8375fb76
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
CONFIG_ZTEST=y
CONFIG_RING_BUFFER=y
CONFIG_PRINTK=y
CONFIG_SYS_LOG=y
CONFIG_ENTROPY_GENERATOR=y
+0 −2
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ extern void atomic_test(void);
extern void bitfield_test(void);
extern void intmath_test(void);
extern void printk_test(void);
extern void ring_buffer_test(void);
extern void slist_test(void);
extern void dlist_test(void);
extern void rand32_test(void);
@@ -45,7 +44,6 @@ void test_main(void)
#ifdef CONFIG_PRINTK
			 ztest_unit_test(printk_test),
#endif
			 ztest_unit_test(ring_buffer_test),
			 ztest_unit_test(slist_test),
			 ztest_unit_test(dlist_test),
			 ztest_unit_test(rand32_test),
+0 −69
Original line number Diff line number Diff line
/* test_ring_buf.c: Simple ring buffer test application */

/*
 * Copyright (c) 2015 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <ztest.h>
#include <ring_buffer.h>
#include <logging/sys_log.h>

SYS_RING_BUF_DECLARE_POW2(ring_buf, 8);

char data[] = "ABCDEFGHIJKLMNOPQRSTUVWX";
#define TYPE    1
#define VALUE   2

#define INITIAL_SIZE    2

void ring_buffer_test(void)
{
	int ret, put_count, i;
	u32_t getdata[6];
	u8_t getsize, getval;
	u16_t gettype;
	int dsize = INITIAL_SIZE;

	put_count = 0;
	while (1) {
		ret = sys_ring_buf_put(&ring_buf, TYPE, VALUE,
				       (u32_t *)data, dsize);
		if (ret == -EMSGSIZE) {
			SYS_LOG_DBG("ring buffer is full");
			break;
		}
		SYS_LOG_DBG("inserted %d chunks, %d remaining", dsize,
			    sys_ring_buf_space_get(&ring_buf));
		dsize = (dsize + 1) % SIZE32_OF(data);
		put_count++;
	}

	getsize = INITIAL_SIZE - 1;
	ret = sys_ring_buf_get(&ring_buf, &gettype, &getval, getdata, &getsize);
	if (ret != -EMSGSIZE) {
		SYS_LOG_DBG("Allowed retreival with insufficient destination buffer space");
		zassert_true((getsize == INITIAL_SIZE), "Correct size wasn't reported back to the caller");
	}

	for (i = 0; i < put_count; i++) {
		getsize = SIZE32_OF(getdata);
		ret = sys_ring_buf_get(&ring_buf, &gettype, &getval, getdata,
				       &getsize);
		zassert_true((ret == 0), "Couldn't retrieve a stored value");
		SYS_LOG_DBG("got %u chunks of type %u and val %u, %u remaining",
			    getsize, gettype, getval,
			    sys_ring_buf_space_get(&ring_buf));

		zassert_true((memcmp((char *)getdata, data, getsize * sizeof(u32_t)) == 0),
			     "data corrupted");
		zassert_true((gettype == TYPE), "type information corrupted");
		zassert_true((getval == VALUE), "value information corrupted");
	}

	getsize = SIZE32_OF(getdata);
	ret = sys_ring_buf_get(&ring_buf, &gettype, &getval, getdata,
			       &getsize);
	zassert_true((ret == -EAGAIN), "Got data out of an empty buffer");
}
+5 −0
Original line number Diff line number Diff line
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
+3 −0
Original line number Diff line number Diff line
CONFIG_ZTEST=y
CONFIG_IRQ_OFFLOAD=y
CONFIG_RING_BUFFER=y
Loading