tests: move individual common tests into one test

We have many tests that are being built as stand-alone binaries for no good
reason. Those can be put in one single test to speed up testing and CI
verification.

Currently we do support the following in test_common:

- byteorder
- printk
- intmath
- slist
- atomic
- ring_buf

In addition, the test now uses the ztest framework.

Change-Id: I656ac7f4acf48b7de4ec81c9f5dafc9dea3da911
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2016-10-30 15:06:06 -04:00
parent ea607625a3
commit 5058bb75bc
37 changed files with 624 additions and 712 deletions

View file

@ -1,55 +0,0 @@
Title: Atomic Operations
Description:
This test verifies that atomic operations manipulate data as expected.
They currently do not test atomicity.
---------------------------------------------------------------------------
Building and Running Project:
This nanokernel project outputs to the console. It can be built and executed
on QEMU as follows:
make qemu
---------------------------------------------------------------------------
Troubleshooting:
Problems caused by out-dated project information can be addressed by
issuing one of the following commands then rebuilding the project:
make clean # discard results of previous builds
# but keep existing configuration info
or
make pristine # discard results of previous builds
# and restore pre-defined configuration info
---------------------------------------------------------------------------
Sample Output:
tc_start() - Test atomic operation primitives
Test atomic_cas()
Test atomic_add()
Test atomic_sub()
Test atomic_inc()
Test atomic_dec()
Test atomic_get()
Test atomic_set()
Test atomic_clear()
Test atomic_or()
Test atomic_xor()
Test atomic_and()
Test atomic_nand()
Test atomic_test_bit()
Test atomic_test_and_clear_bit()
Test atomic_test_and_set_bit()
Test atomic_clear_bit()
Test atomic_set_bit()
===================================================================
PASS - main.
===================================================================
PROJECT EXECUTION SUCCESSFUL

View file

@ -1,3 +0,0 @@
ccflags-y += -I${ZEPHYR_BASE}/tests/include
obj-y = atomic.o

View file

@ -1,164 +0,0 @@
/*
* Copyright (c) 2015 Intel Corporation
*
* Licensed 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 <zephyr.h>
#include <atomic.h>
#include <tc_util.h>
#define CHECK_OUTPUT(expr, val) do { \
atomic_val_t x = (expr); \
if (x != (val)) { \
failed++; \
TC_ERROR(#expr" != " #val " got %d\n", x); \
} \
} while (0)
#define CHECK_TRUTH(expr, val) CHECK_OUTPUT(!!(expr), !!(val))
void main(void)
{
int failed, rv, i;
atomic_t target, orig;
atomic_val_t value;
atomic_val_t oldvalue;
failed = 0;
TC_START("Test atomic operation primitives");
TC_PRINT("Test atomic_cas()\n");
target = 4;
value = 5;
oldvalue = 6;
CHECK_OUTPUT(atomic_cas(&target, oldvalue, value), 0);
target = 6;
CHECK_OUTPUT(atomic_cas(&target, oldvalue, value), 1);
CHECK_OUTPUT(target, value);
TC_PRINT("Test atomic_add()\n");
target = 1;
value = 2;
CHECK_OUTPUT(atomic_add(&target, value), 1);
CHECK_OUTPUT(target, 3);
TC_PRINT("Test atomic_sub()\n");
target = 10;
value = 2;
CHECK_OUTPUT(atomic_sub(&target, value), 10);
CHECK_OUTPUT(target, 8);
TC_PRINT("Test atomic_inc()\n");
target = 5;
CHECK_OUTPUT(atomic_inc(&target), 5);
CHECK_OUTPUT(target, 6);
TC_PRINT("Test atomic_dec()\n");
target = 2;
CHECK_OUTPUT(atomic_dec(&target), 2);
CHECK_OUTPUT(target, 1);
TC_PRINT("Test atomic_get()\n");
target = 50;
CHECK_OUTPUT(atomic_get(&target), 50);
TC_PRINT("Test atomic_set()\n");
target = 42;
value = 77;
CHECK_OUTPUT(atomic_set(&target, value), 42);
CHECK_OUTPUT(target, value);
TC_PRINT("Test atomic_clear()\n");
target = 100;
CHECK_OUTPUT(atomic_clear(&target), 100);
CHECK_OUTPUT(target, 0);
TC_PRINT("Test atomic_or()\n");
target = 0xFF00;
value = 0x0F0F;
CHECK_OUTPUT(atomic_or(&target, value), 0xFF00);
CHECK_OUTPUT(target, 0xFF0F);
TC_PRINT("Test atomic_xor()\n");
target = 0xFF00;
value = 0x0F0F;
CHECK_OUTPUT(atomic_xor(&target, value), 0xFF00);
CHECK_OUTPUT(target, 0xF00F);
TC_PRINT("Test atomic_and()\n");
target = 0xFF00;
value = 0x0F0F;
CHECK_OUTPUT(atomic_and(&target, value), 0xFF00);
CHECK_OUTPUT(target, 0x0F00);
TC_PRINT("Test atomic_nand()\n");
target = 0xFF00;
value = 0x0F0F;
CHECK_OUTPUT(atomic_nand(&target, value), 0xFF00);
CHECK_OUTPUT(target, 0xFFFFF0FF);
TC_PRINT("Test atomic_test_bit()\n");
for (i = 0; i < 32; i++) {
target = 0x0F0F0F0F;
CHECK_TRUTH(atomic_test_bit(&target, i),
(target & (1 << i)));
}
TC_PRINT("Test atomic_test_and_clear_bit()\n");
for (i = 0; i < 32; i++) {
orig = 0x0F0F0F0F;
target = orig;
CHECK_TRUTH(atomic_test_and_clear_bit(&target, i),
(orig & (1 << i)));
CHECK_OUTPUT(target, orig & ~(1 << i));
}
TC_PRINT("Test atomic_test_and_set_bit()\n");
for (i = 0; i < 32; i++) {
orig = 0x0F0F0F0F;
target = orig;
CHECK_TRUTH(atomic_test_and_set_bit(&target, i),
(orig & (1 << i)));
CHECK_OUTPUT(target, orig | (1 << i));
}
TC_PRINT("Test atomic_clear_bit()\n");
for (i = 0; i < 32; i++) {
orig = 0x0F0F0F0F;
target = orig;
atomic_clear_bit(&target, i);
CHECK_OUTPUT(target, orig & ~(1 << i));
}
TC_PRINT("Test atomic_set_bit()\n");
for (i = 0; i < 32; i++) {
orig = 0x0F0F0F0F;
target = orig;
atomic_set_bit(&target, i);
CHECK_OUTPUT(target, orig | (1 << i));
}
if (failed) {
TC_PRINT("%d tests failed\n", failed);
rv = TC_FAIL;
} else {
rv = TC_PASS;
}
TC_END_RESULT(rv);
TC_END_REPORT(rv);
}

View file

@ -1,5 +0,0 @@
BOARD ?= qemu_x86
KERNEL_TYPE ?= unified
CONF_FILE = prj.conf
include $(ZEPHYR_BASE)/Makefile.inc

View file

@ -1 +0,0 @@
CONFIG_ZTEST=y

View file

@ -1,3 +0,0 @@
include $(ZEPHYR_BASE)/tests/Makefile.test
obj-y = byteorder.o

View file

@ -1,4 +0,0 @@
[test]
tags = byteorder
arch_whitelist = x86 arm arc
kernel = unified

View file

@ -1,4 +1,5 @@
KERNEL_TYPE = unified
CONF_FILE ?= prj.conf
BOARD ?= qemu_x86
include $(ZEPHYR_BASE)/Makefile.inc

View file

@ -0,0 +1,4 @@
CONFIG_ZTEST=y
CONFIG_RING_BUFFER=y
CONFIG_PRINTK=y
CONFIG_SYS_LOG=y

View file

@ -0,0 +1,6 @@
include $(ZEPHYR_BASE)/tests/Makefile.test
obj-y += main.o atomic.o byteorder.o intmath.o printk.o
obj-y += ring_buf.o
obj-y += slist.o
obj-n += bitfield.o

View file

@ -0,0 +1,141 @@
/*
* Copyright (c) 2015 Intel Corporation
*
* Licensed 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 <ztest.h>
#include <atomic.h>
void atomic_test(void)
{
int i;
atomic_t target, orig;
atomic_val_t value;
atomic_val_t oldvalue;
target = 4;
value = 5;
oldvalue = 6;
/* atomic_cas() */
assert_true((atomic_cas(&target, oldvalue, value) == 0), "atomic_cas");
target = 6;
assert_true((atomic_cas(&target, oldvalue, value) == 1), "atomic_cas");
assert_true((target == value), "atomic_cas");
/* atomic_add() */
target = 1;
value = 2;
assert_true((atomic_add(&target, value) == 1), "atomic_add");
assert_true((target == 3), "atomic_add");
/* atomic_sub() */
target = 10;
value = 2;
assert_true((atomic_sub(&target, value) == 10), "atomic_sub");
assert_true((target == 8), "atomic_sub");
/* atomic_inc() */
target = 5;
assert_true((atomic_inc(&target) == 5), "atomic_inc");
assert_true((target == 6), "atomic_inc");
/* atomic_dec() */
target = 2;
assert_true((atomic_dec(&target) == 2), "atomic_dec");
assert_true((target == 1), "atomic_dec");
/* atomic_get() */
target = 50;
assert_true((atomic_get(&target) == 50), "atomic_get");
/* atomic_set() */
target = 42;
value = 77;
assert_true((atomic_set(&target, value) == 42), "atomic_set");
assert_true((target == value), "atomic_set");
/* atomic_clear() */
target = 100;
assert_true((atomic_clear(&target) == 100), "atomic_clear");
assert_true((target == 0), "atomic_clear");
/* atomic_or() */
target = 0xFF00;
value = 0x0F0F;
assert_true((atomic_or(&target, value) == 0xFF00), "atomic_or");
assert_true((target == 0xFF0F), "atomic_or");
/* atomic_xor() */
target = 0xFF00;
value = 0x0F0F;
assert_true((atomic_xor(&target, value) == 0xFF00), "atomic_xor");
assert_true((target == 0xF00F), "atomic_xor");
/* atomic_and() */
target = 0xFF00;
value = 0x0F0F;
assert_true((atomic_and(&target, value) == 0xFF00), "atomic_and");
assert_true((target == 0x0F00), "atomic_and");
/* atomic_nand() */
target = 0xFF00;
value = 0x0F0F;
assert_true((atomic_nand(&target, value) == 0xFF00), "atomic_nand");
assert_true((target == 0xFFFFF0FF), "atomic_nand");
/* atomic_test_bit() */
for (i = 0; i < 32; i++) {
target = 0x0F0F0F0F;
assert_true(!!(atomic_test_bit(&target, i) == !!(target & (1 << i))),
"atomic_test_bit");
}
/* atomic_test_and_clear_bit() */
for (i = 0; i < 32; i++) {
orig = 0x0F0F0F0F;
target = orig;
assert_true(!!(atomic_test_and_clear_bit(&target, i)) == !!(orig & (1 << i)),
"atomic_test_and_clear_bit");
assert_true(target == (orig & ~(1 << i)), "atomic_test_and_clear_bit");
}
/* atomic_test_and_set_bit() */
for (i = 0; i < 32; i++) {
orig = 0x0F0F0F0F;
target = orig;
assert_true(!!(atomic_test_and_set_bit(&target, i)) == !!(orig & (1 << i)),
"atomic_test_and_set_bit");
assert_true(target == (orig | (1 << i)), "atomic_test_and_set_bit");
}
/* atomic_clear_bit() */
for (i = 0; i < 32; i++) {
orig = 0x0F0F0F0F;
target = orig;
atomic_clear_bit(&target, i);
assert_true(target == (orig & ~(1 << i)), "atomic_clear_bit");
}
/* atomic_set_bit() */
for (i = 0; i < 32; i++) {
orig = 0x0F0F0F0F;
target = orig;
atomic_set_bit(&target, i);
assert_true(target == (orig | (1 << i)), "atomic_set_bit");
}
}

View file

@ -0,0 +1,195 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed 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 <ztest.h>
#define BIT_INDEX(bit) (bit >> 3)
#define BIT_VAL(bit) (1 << (bit & 0x7))
#define BITFIELD_SIZE 512
void bitfield_test(void)
{
uint32_t b1 = 0;
unsigned char b2[BITFIELD_SIZE >> 3] = { 0 };
int test_rv;
unsigned int bit;
int ret;
for (bit = 0; bit < 32; ++bit) {
sys_set_bit((mem_addr_t)&b1, bit);
assert_true(b1 == (1 << bit), "sys_set_bit failed on bit");
assert_true((sys_test_bit((mem_addr_t)&b1, bit) == 0), "sys_test_bit did not detect bit");
sys_clear_bit((mem_addr_t)&b1, bit);
assert_true((b1 == 0), "sys_clear_bit failed for bit");
assert_true((sys_test_bit((mem_addr_t)&b1, bit) == 0), "sys_test_bit erroneously detected bit");
assert_true((sys_test_and_set_bit((mem_addr_t)&b1, bit) == 0), "sys_test_and_set_bit erroneously detected bit");
assert_true((b1 == (1 << bit)), "sys_test_and_set_bit");
printk("%d\n", sys_test_and_set_bit((mem_addr_t)&b1, bit));
assert_true((sys_test_and_set_bit((mem_addr_t)&b1, bit) == 0), "sys_test_and_set_bit");
}
#if 0
if (b1 != (1 << bit)) {
b1 = (1 << bit);
TC_PRINT("sys_test_and_set_bit did not set bit %d\n",
bit);
failed++;
}
ret = sys_test_and_set_bit((mem_addr_t)&b1, bit);
if (!ret) {
TC_PRINT("sys_test_and_set_bit did not detect bit %d\n",
bit);
failed++;
}
if (b1 != (1 << bit)) {
b1 = (1 << bit);
TC_PRINT("sys_test_and_set_bit cleared bit %d\n",
bit);
failed++;
}
ret = sys_test_and_clear_bit((mem_addr_t)&b1, bit);
if (!ret) {
TC_PRINT("sys_test_and_clear_bit did not detect bit %d\n",
bit);
failed++;
}
if (b1 != 0) {
b1 = 0;
TC_PRINT("sys_test_and_clear_bit did not clear bit %d\n",
bit);
failed++;
}
ret = sys_test_and_clear_bit((mem_addr_t)&b1, bit);
if (ret) {
TC_PRINT("sys_test_and_clear_bit erroneously detected bit %d\n",
bit);
failed++;
}
if (b1 != 0) {
b1 = 0;
TC_PRINT("sys_test_and_clear_bit set bit %d\n",
bit);
failed++;
}
}
for (bit = 0; bit < BITFIELD_SIZE; ++bit) {
sys_bitfield_set_bit((mem_addr_t)b2, bit);
if (b2[BIT_INDEX(bit)] != BIT_VAL(bit)) {
TC_PRINT("got %d expected %d\n", b2[BIT_INDEX(bit)],
BIT_VAL(bit));
TC_PRINT("sys_bitfield_set_bit failed for bit %d\n",
bit);
b2[BIT_INDEX(bit)] = BIT_VAL(bit);
failed++;
}
if (!sys_bitfield_test_bit((mem_addr_t)b2, bit)) {
TC_PRINT("sys_bitfield_test_bit did not detect bit %d\n",
bit);
failed++;
}
sys_bitfield_clear_bit((mem_addr_t)b2, bit);
if (b2[BIT_INDEX(bit)] != 0) {
b2[BIT_INDEX(bit)] = 0;
TC_PRINT("sys_bitfield_clear_bit failed for bit %d\n",
bit);
failed++;
}
if (sys_bitfield_test_bit((mem_addr_t)b2, bit)) {
TC_PRINT("sys_bitfield_test_bit erroneously detected bit %d\n",
bit);
failed++;
}
ret = sys_bitfield_test_and_set_bit((mem_addr_t)b2, bit);
if (ret) {
TC_PRINT("sys_bitfield_test_and_set_bit erroneously detected bit %d\n",
bit);
failed++;
}
if (b2[BIT_INDEX(bit)] != BIT_VAL(bit)) {
b2[BIT_INDEX(bit)] = BIT_VAL(bit);
TC_PRINT("sys_bitfield_test_and_set_bit did not set bit %d\n",
bit);
failed++;
}
ret = sys_bitfield_test_and_set_bit((mem_addr_t)b2, bit);
if (!ret) {
TC_PRINT("sys_bitfield_test_and_set_bit did not detect bit %d\n",
bit);
failed++;
}
if (b2[BIT_INDEX(bit)] != BIT_VAL(bit)) {
b2[BIT_INDEX(bit)] = BIT_VAL(bit);
TC_PRINT("sys_bitfield_test_and_set_bit cleared bit %d\n",
bit);
failed++;
}
ret = sys_bitfield_test_and_clear_bit((mem_addr_t)b2, bit);
if (!ret) {
TC_PRINT("sys_bitfield_test_and_clear_bit did not detect bit %d\n",
bit);
failed++;
}
if (b2[BIT_INDEX(bit)] != 0) {
b2[BIT_INDEX(bit)] = 0;
TC_PRINT("sys_bitfield_test_and_clear_bit did not clear bit %d\n",
bit);
failed++;
}
ret = sys_bitfield_test_and_clear_bit((mem_addr_t)b2, bit);
if (ret) {
TC_PRINT("sys_bitfield_test_and_clear_bit erroneously detected bit %d\n",
bit);
failed++;
}
if (b2[BIT_INDEX(bit)] != 0) {
b2[BIT_INDEX(bit)] = 0;
TC_PRINT("sys_bitfield_test_and_clear_bit set bit %d\n",
bit);
failed++;
}
}
if (failed) {
TC_PRINT("%d tests failed\n", failed);
test_rv = TC_FAIL;
} else {
test_rv = TC_PASS;
}
TC_END_RESULT(test_rv);
TC_END_REPORT(test_rv);
#endif
}

View file

@ -19,7 +19,7 @@
#include <misc/byteorder.h>
static void byteorder_test_memcpy_swap(void)
void byteorder_test_memcpy_swap(void)
{
uint8_t buf_orig[8] = { 0x00, 0x01, 0x02, 0x03,
0x04, 0x05, 0x06, 0x07 };
@ -36,7 +36,7 @@ static void byteorder_test_memcpy_swap(void)
"Swap memcpy failed");
}
static void byteorder_test_mem_swap(void)
void byteorder_test_mem_swap(void)
{
uint8_t buf_orig_1[8] = { 0x00, 0x01, 0x02, 0x03,
0x04, 0x05, 0x06, 0x07 };
@ -58,11 +58,3 @@ static void byteorder_test_mem_swap(void)
"Swapping buffer failed");
}
void test_main(void)
{
ztest_test_suite(byteorder_test,
ztest_unit_test(byteorder_test_memcpy_swap),
ztest_unit_test(byteorder_test_mem_swap));
ztest_run_test_suite(byteorder_test);
}

View file

@ -14,46 +14,29 @@
* limitations under the License.
*/
#include <zephyr.h>
#include <tc_util.h>
#include <ztest.h>
void main(void)
void intmath_test(void)
{
/* Declaring volatile so the compiler doesn't try to optimize any
/*
* Declaring volatile so the compiler doesn't try to optimize any
* of the math away at build time
*/
volatile uint64_t bignum, ba, bb;
volatile uint32_t num, a, b;
int rv = TC_PASS;
TC_START("Integer math functions");
ba = 0x00000012ABCDEF12ULL;
bb = 0x0000001000000111ULL;
bignum = ba * bb;
if (bignum != 0xbcdf0509369bf232ULL) {
TC_PRINT("64-bit multiplication failed\n");
rv = TC_FAIL;
}
assert_true((bignum == 0xbcdf0509369bf232ULL), "64-bit multiplication failed");
a = 30000;
b = 5872;
num = a * b;
if (num != 176160000) {
TC_PRINT("32-bit multiplication failed\n");
rv = TC_FAIL;
}
assert_true((num == 176160000), "32-bit multiplication failed");
a = 234424432;
b = 98982;
num = a / b;
if (num != 2368) {
TC_PRINT("32-bit division failed\n");
rv = TC_FAIL;
}
TC_END_RESULT(rv);
TC_END_REPORT(rv);
assert_true((num == 2368), "32-bit division failed");
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed 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 <ztest.h>
extern void byteorder_test_memcpy_swap(void);
extern void byteorder_test_mem_swap(void);
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);
void test_main(void)
{
ztest_test_suite(common_test,
ztest_unit_test(byteorder_test_memcpy_swap),
ztest_unit_test(byteorder_test_mem_swap),
ztest_unit_test(atomic_test),
ztest_unit_test(printk_test),
ztest_unit_test(ring_buffer_test),
ztest_unit_test(slist_test),
ztest_unit_test(intmath_test)
);
ztest_run_test_suite(common_test);
}

View file

@ -14,10 +14,7 @@
* limitations under the License.
*/
#include <zephyr.h>
#include <atomic.h>
#include <tc_util.h>
#include <ztest.h>
#define BUF_SZ 1024
@ -28,9 +25,9 @@ extern int (*_char_out)(int);
int (*_old_char_out)(int);
char *expected = "22 113 10000 32768 40000 22\n"
"p 112 -10000 -32768 -40000 -22\n"
"0xcafebabe 0x0000beef\n"
;
"p 112 -10000 -32768 -40000 -22\n"
"0xcafebabe 0x0000beef\n"
;
size_t stv = 22;
@ -39,7 +36,8 @@ unsigned short int usi = 10000;
unsigned int ui = 32768;
unsigned long ul = 40000;
/* FIXME we know printk doesn't have full support for 64-bit values.
/* FIXME
* we know printk doesn't have full support for 64-bit values.
* at least show it can print uint64_t values less than 32-bits wide
*/
unsigned long long ull = 22;
@ -61,12 +59,8 @@ static int ram_console_out(int character)
return _old_char_out(character);
}
void main(void)
void printk_test(void)
{
int rv;
TC_START("Test printk output correctness");
_old_char_out = _char_out;
_char_out = ram_console_out;
@ -75,13 +69,5 @@ void main(void)
printk("0x%x %p\n", hex, ptr);
ram_console[pos] = '\0';
if (strcmp(ram_console, expected)) {
rv = TC_FAIL;
printk("EXPECTED:\n%s", expected);
} else {
rv = TC_PASS;
}
TC_END_RESULT(rv);
TC_END_REPORT(rv);
assert_true((strcmp(ram_console, expected) == 0), "printk failed");
}

View file

@ -16,9 +16,9 @@
* limitations under the License.
*/
#include <zephyr.h>
#include <tc_util.h>
#include <ztest.h>
#include <misc/ring_buffer.h>
#include <misc/sys_log.h>
SYS_RING_BUF_DECLARE_POW2(ring_buf, 8);
@ -28,26 +28,23 @@ char data[] = "ABCDEFGHIJKLMNOPQRSTUVWX";
#define INITIAL_SIZE 2
void main(void)
void ring_buffer_test(void)
{
int ret, put_count, i, rv;
int ret, put_count, i;
uint32_t getdata[6];
uint8_t getsize, getval;
uint16_t gettype;
int dsize = INITIAL_SIZE;
TC_START("Test ring buffers");
rv = TC_FAIL;
put_count = 0;
while (1) {
ret = sys_ring_buf_put(&ring_buf, TYPE, VALUE,
(uint32_t *)data, dsize);
if (ret == -EMSGSIZE) {
printk("ring buffer is full\n");
SYS_LOG_DBG("ring buffer is full");
break;
}
printk("inserted %d chunks, %d remaining\n", dsize,
SYS_LOG_DBG("inserted %d chunks, %d remaining", dsize,
sys_ring_buf_space_get(&ring_buf));
dsize = (dsize + 1) % SIZE32_OF(data);
put_count++;
@ -56,52 +53,27 @@ void main(void)
getsize = INITIAL_SIZE - 1;
ret = sys_ring_buf_get(&ring_buf, &gettype, &getval, getdata, &getsize);
if (ret != -EMSGSIZE) {
printk("Allowed retreival with insufficient destination buffer space\n");
if (getsize != INITIAL_SIZE)
printk("Correct size wasn't reported back to the caller\n");
goto done;
SYS_LOG_DBG("Allowed retreival with insufficient destination buffer space");
assert_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);
if (ret < 0) {
printk("Couldn't retrieve a stored value (%d)\n",
ret);
goto done;
}
printk("got %u chunks of type %u and val %u, %u remaining\n",
assert_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));
if (memcmp((char *)getdata, data, getsize * sizeof(uint32_t))) {
printk("data corrupted\n");
goto done;
}
if (gettype != TYPE) {
printk("type information corrupted\n");
goto done;
}
if (getval != VALUE) {
printk("value information corrupted\n");
goto done;
}
assert_true((memcmp((char *)getdata, data, getsize * sizeof(uint32_t)) == 0),
"data corrupted");
assert_true((gettype == TYPE), "type information corrupted");
assert_true((getval == VALUE), "value information corrupted");
}
getsize = SIZE32_OF(getdata);
ret = sys_ring_buf_get(&ring_buf, &gettype, &getval, getdata,
&getsize);
if (ret != -EAGAIN) {
printk("Got data out of an empty buffer");
goto done;
}
printk("empty buffer detected\n");
rv = TC_PASS;
done:
printk("head: %d tail: %d\n", ring_buf.head, ring_buf.tail);
TC_END_RESULT(rv);
TC_END_REPORT(rv);
assert_true((ret == -EAGAIN), "Got data out of an empty buffer");
}

View file

@ -0,0 +1,202 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed 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 <ztest.h>
#include <misc/slist.h>
static sys_slist_t test_list;
static sys_snode_t test_node_1;
static sys_snode_t test_node_2;
static sys_snode_t test_node_3;
static sys_snode_t test_node_4;
static inline bool verify_emptyness(sys_slist_t *list)
{
sys_snode_t *node;
sys_snode_t *s_node;
int count;
if (!sys_slist_is_empty(list)) {
return false;
}
if (sys_slist_peek_head(list)) {
return false;
}
if (sys_slist_peek_tail(list)) {
return false;
}
count = 0;
SYS_SLIST_FOR_EACH_NODE(list, node) {
count++;
}
if (count) {
return false;
}
SYS_SLIST_FOR_EACH_NODE_SAFE(list, node, s_node) {
count++;
}
if (count) {
return false;
}
return true;
}
static inline bool verify_content_amount(sys_slist_t *list, int amount)
{
sys_snode_t *node;
sys_snode_t *s_node;
int count;
if (sys_slist_is_empty(list)) {
return false;
}
if (!sys_slist_peek_head(list)) {
return false;
}
if (!sys_slist_peek_tail(list)) {
return false;
}
count = 0;
SYS_SLIST_FOR_EACH_NODE(list, node) {
count++;
}
if (count != amount) {
return false;
}
count = 0;
SYS_SLIST_FOR_EACH_NODE_SAFE(list, node, s_node) {
count++;
}
if (count != amount) {
return false;
}
return true;
}
static inline bool verify_tail_head(sys_slist_t *list,
sys_snode_t *head,
sys_snode_t *tail,
bool same)
{
if (sys_slist_peek_head(list) != head) {
return false;
}
if (sys_slist_peek_tail(list) != tail) {
return false;
}
if (same) {
if (sys_slist_peek_head(list) != sys_slist_peek_tail(list)) {
return false;
}
} else {
if (sys_slist_peek_head(list) == sys_slist_peek_tail(list)) {
return false;
}
}
return true;
}
void slist_test(void)
{
sys_slist_init(&test_list);
assert_true((verify_emptyness(&test_list)), "test_list should be empty");
/* Appending node 1 */
sys_slist_append(&test_list, &test_node_1);
assert_true((verify_content_amount(&test_list, 1)), "test_list has wrong content");
assert_true((verify_tail_head(&test_list, &test_node_1, &test_node_1, true)), "test_list head/tail are wrong");
/* Finding and removing node 1 */
sys_slist_find_and_remove(&test_list, &test_node_1);
assert_true((verify_emptyness(&test_list)), "test_list should be empty");
/* Prepending node 1 */
sys_slist_prepend(&test_list, &test_node_1);
assert_true((verify_content_amount(&test_list, 1)), "test_list has wrong content");
assert_true((verify_tail_head(&test_list, &test_node_1, &test_node_1, true)), "test_list head/tail are wrong");
/* Removing node 1 */
sys_slist_remove(&test_list, NULL, &test_node_1);
assert_true((verify_emptyness(&test_list)), "test_list should be empty");
/* Appending node 1 */
sys_slist_append(&test_list, &test_node_1);
/* Prepending node 2 */
sys_slist_prepend(&test_list, &test_node_2);
assert_true((verify_content_amount(&test_list, 2)), "test_list has wrong content");
assert_true((verify_tail_head(&test_list, &test_node_2, &test_node_1, false)), "test_list head/tail are wrong");
/* Appending node 3 */
sys_slist_append(&test_list, &test_node_3);
assert_true((verify_content_amount(&test_list, 3)), "test_list has wrong content");
assert_true((verify_tail_head(&test_list, &test_node_2, &test_node_3, false)), "test_list head/tail are wrong");
assert_true((sys_slist_peek_next(&test_node_2) == &test_node_1), "test_list node links are wrong");
/* Inserting node 4 after node 2 */
sys_slist_insert(&test_list, &test_node_2, &test_node_4);
assert_true((verify_tail_head(&test_list, &test_node_2, &test_node_3, false)), "test_list head/tail are wrong");
assert_true((sys_slist_peek_next(&test_node_2) == &test_node_4), "test_list node links are wrong");
/* Finding and removing node 1 */
sys_slist_find_and_remove(&test_list, &test_node_1);
assert_true((verify_content_amount(&test_list, 3)), "test_list has wrong content");
assert_true((verify_tail_head(&test_list, &test_node_2, &test_node_3, false)), "test_list head/tail are wrong");
/* Removing node 3 */
sys_slist_remove(&test_list, &test_node_4, &test_node_3);
assert_true((verify_content_amount(&test_list, 2)), "test_list has wrong content");
assert_true((verify_tail_head(&test_list, &test_node_2, &test_node_4, false)), "test_list head/tail are wrong");
/* Removing node 4 */
sys_slist_remove(&test_list, &test_node_2, &test_node_4);
assert_true((verify_content_amount(&test_list, 1)), "test_list has wrong content");
assert_true((verify_tail_head(&test_list, &test_node_2, &test_node_2, true)), "test_list head/tail are wrong");
/* Removing node 2 */
sys_slist_remove(&test_list, NULL, &test_node_2);
assert_true((verify_emptyness(&test_list)), "test_list should be empty");
}

View file

@ -1,6 +0,0 @@
KERNEL_TYPE = unified
BOARD ?= qemu_nios2
CONF_FILE = prj.conf
include ${ZEPHYR_BASE}/Makefile.inc

View file

@ -1,3 +0,0 @@
This test case is to ensure that integer math is handled correctly
on Nios II, either through native instruction support, runtime emulation
via unimplemented instruction exceptions, or use of GCC integer math routines.

View file

@ -1,3 +0,0 @@
ccflags-y += -I${ZEPHYR_BASE}/tests/include
obj-y = main.o

View file

@ -1,3 +0,0 @@
[test]
tags = core
kernel = unified

View file

@ -1,4 +0,0 @@
KERNEL_TYPE = unified
BOARD ?= qemu_x86
include $(ZEPHYR_BASE)/Makefile.inc

View file

@ -1,3 +0,0 @@
ccflags-y += -I${ZEPHYR_BASE}/tests/include
obj-y = test_printk.o

View file

@ -1,3 +0,0 @@
[test]
tags = core
kernel = unified

View file

@ -1,5 +0,0 @@
KERNEL_TYPE = unified
BOARD ?= qemu_x86
CONF_FILE = prj.conf
include $(ZEPHYR_BASE)/Makefile.inc

View file

@ -1,2 +0,0 @@
CONFIG_RING_BUFFER=y

View file

@ -1,4 +0,0 @@
ccflags-y += -I${ZEPHYR_BASE}/tests/include
obj-y = test_ring_buf.o

View file

@ -1,4 +0,0 @@
[test]
tags = core
# On ARC, it needs more time
timeout = 180

View file

@ -1,5 +0,0 @@
KERNEL_TYPE = unified
BOARD ?= qemu_x86
CONF_FILE = prj.conf
include ${ZEPHYR_BASE}/Makefile.inc

View file

@ -1,50 +0,0 @@
Title: Test slist
Description:
A simple application verifying slist API and its functionalities
--------------------------------------------------------------------------------
Building and Running Project:
This nanokernel project outputs to the console. It can be built and executed
on QEMU as follows:
make qemu
--------------------------------------------------------------------------------
Troubleshooting:
Problems caused by out-dated project information can be addressed by
issuing one of the following commands then rebuilding the project:
make clean # discard results of previous builds
# but keep existing configuration info
or
make pristine # discard results of previous builds
# and restore pre-defined configuration info
--------------------------------------------------------------------------------
Sample Output:
Starting slist test
- Initializing the list
- Appending node 1
- Finding and removing node 1
- Prepending node 1
- Removing node 1
- Appending node 1
- Prepending node 2
- Appending node 3
- Inserting node 4 after node 2
- Finding and removing node 1
- Removing node 3
- Removing node 4
- Removing node 2
===================================================================
PASS - main.
===================================================================
PROJECT EXECUTION SUCCESSFUL

View file

@ -1 +0,0 @@
# use default configuration settings

View file

@ -1,3 +0,0 @@
ccflags-y += -I${ZEPHYR_BASE}/tests/include
obj-y = slist.o

View file

@ -1,277 +0,0 @@
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed 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 <zephyr.h>
#include <tc_util.h>
#include <misc/slist.h>
static sys_slist_t test_list;
static sys_snode_t test_node_1;
static sys_snode_t test_node_2;
static sys_snode_t test_node_3;
static sys_snode_t test_node_4;
static inline bool verify_emptyness(sys_slist_t *list)
{
sys_snode_t *node;
sys_snode_t *s_node;
int count;
if (!sys_slist_is_empty(list)) {
return false;
}
if (sys_slist_peek_head(list)) {
return false;
}
if (sys_slist_peek_tail(list)) {
return false;
}
count = 0;
SYS_SLIST_FOR_EACH_NODE(list, node) {
count++;
}
if (count) {
return false;
}
SYS_SLIST_FOR_EACH_NODE_SAFE(list, node, s_node) {
count++;
}
if (count) {
return false;
}
return true;
}
static inline bool verify_content_amount(sys_slist_t *list, int amount)
{
sys_snode_t *node;
sys_snode_t *s_node;
int count;
if (sys_slist_is_empty(list)) {
return false;
}
if (!sys_slist_peek_head(list)) {
return false;
}
if (!sys_slist_peek_tail(list)) {
return false;
}
count = 0;
SYS_SLIST_FOR_EACH_NODE(list, node) {
count++;
}
if (count != amount) {
return false;
}
count = 0;
SYS_SLIST_FOR_EACH_NODE_SAFE(list, node, s_node) {
count++;
}
if (count != amount) {
return false;
}
return true;
}
static inline bool verify_tail_head(sys_slist_t *list,
sys_snode_t *head,
sys_snode_t *tail,
bool same)
{
if (sys_slist_peek_head(list) != head) {
return false;
}
if (sys_slist_peek_tail(list) != tail) {
return false;
}
if (same) {
if (sys_slist_peek_head(list) != sys_slist_peek_tail(list)) {
return false;
}
} else {
if (sys_slist_peek_head(list) == sys_slist_peek_tail(list)) {
return false;
}
}
return true;
}
void main(void)
{
int status = TC_FAIL;
TC_PRINT("Starting slist test\n");
TC_PRINT(" - Initializing the list\n");
sys_slist_init(&test_list);
if (!verify_emptyness(&test_list)) {
TC_ERROR("*** test_list should be empty\n");
goto end;
}
TC_PRINT(" - Appending node 1\n");
sys_slist_append(&test_list, &test_node_1);
if (!verify_content_amount(&test_list, 1)) {
TC_ERROR("*** test_list has wrong content\n");
goto end;
}
if (!verify_tail_head(&test_list, &test_node_1, &test_node_1, true)) {
TC_ERROR("*** test_list head/tail are wrong\n");
goto end;
}
TC_PRINT(" - Finding and removing node 1\n");
sys_slist_find_and_remove(&test_list, &test_node_1);
if (!verify_emptyness(&test_list)) {
TC_ERROR("*** test_list should be empty\n");
goto end;
}
TC_PRINT(" - Prepending node 1\n");
sys_slist_prepend(&test_list, &test_node_1);
if (!verify_content_amount(&test_list, 1)) {
TC_ERROR("*** test_list has wrong content\n");
goto end;
}
if (!verify_tail_head(&test_list, &test_node_1, &test_node_1, true)) {
TC_ERROR("*** test_list head/tail are wrong\n");
goto end;
}
TC_PRINT(" - Removing node 1\n");
sys_slist_remove(&test_list, NULL, &test_node_1);
if (!verify_emptyness(&test_list)) {
TC_ERROR("*** test_list should be empty\n");
goto end;
}
TC_PRINT(" - Appending node 1\n");
sys_slist_append(&test_list, &test_node_1);
TC_PRINT(" - Prepending node 2\n");
sys_slist_prepend(&test_list, &test_node_2);
if (!verify_content_amount(&test_list, 2)) {
TC_ERROR("*** test_list has wrong content\n");
goto end;
}
if (!verify_tail_head(&test_list, &test_node_2, &test_node_1, false)) {
TC_ERROR("*** test_list head/tail are wrong\n");
goto end;
}
TC_PRINT(" - Appending node 3\n");
sys_slist_append(&test_list, &test_node_3);
if (!verify_content_amount(&test_list, 3)) {
TC_ERROR("*** test_list has wrong content\n");
goto end;
}
if (!verify_tail_head(&test_list, &test_node_2, &test_node_3, false)) {
TC_ERROR("*** test_list head/tail are wrong\n");
goto end;
}
if (sys_slist_peek_next(&test_node_2) != &test_node_1) {
TC_ERROR("*** test_list node links are wrong\n");
goto end;
}
TC_PRINT(" - Inserting node 4 after node 2\n");
sys_slist_insert(&test_list, &test_node_2, &test_node_4);
if (!verify_tail_head(&test_list, &test_node_2, &test_node_3, false)) {
TC_ERROR("*** test_list head/tail are wrong\n");
goto end;
}
if (sys_slist_peek_next(&test_node_2) != &test_node_4) {
TC_ERROR("*** test_list node links are wrong\n");
goto end;
}
TC_PRINT(" - Finding and removing node 1\n");
sys_slist_find_and_remove(&test_list, &test_node_1);
if (!verify_content_amount(&test_list, 3)) {
TC_ERROR("*** test_list has wrong content\n");
goto end;
}
if (!verify_tail_head(&test_list, &test_node_2, &test_node_3, false)) {
TC_ERROR("*** test_list head/tail are wrong\n");
goto end;
}
TC_PRINT(" - Removing node 3\n");
sys_slist_remove(&test_list, &test_node_4, &test_node_3);
if (!verify_content_amount(&test_list, 2)) {
TC_ERROR("*** test_list has wrong content\n");
goto end;
}
if (!verify_tail_head(&test_list, &test_node_2, &test_node_4, false)) {
TC_ERROR("*** test_list head/tail are wrong\n");
goto end;
}
TC_PRINT(" - Removing node 4\n");
sys_slist_remove(&test_list, &test_node_2, &test_node_4);
if (!verify_content_amount(&test_list, 1)) {
TC_ERROR("*** test_list has wrong content\n");
goto end;
}
if (!verify_tail_head(&test_list, &test_node_2, &test_node_2, true)) {
TC_ERROR("*** test_list head/tail are wrong\n");
goto end;
}
TC_PRINT(" - Removing node 2\n");
sys_slist_remove(&test_list, NULL, &test_node_2);
if (!verify_emptyness(&test_list)) {
TC_ERROR("*** test_list should be empty\n");
goto end;
}
status = TC_PASS;
end:
TC_END_RESULT(status);
TC_END_REPORT(status);
}

View file

@ -1,2 +0,0 @@
[test]
tags = core