MOS Source Code
Loading...
Searching...
No Matches
test_downwards_stack.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "test_engine_impl.h"
4
6#include <mos_stdlib.h>
7
9{
11 stack_init(&stack, (void *) 12345, 6789);
12 MOS_TEST_CHECK(stack.top, 12345 + 6789);
13 MOS_TEST_CHECK(stack.head, 12345 + 6789);
14 MOS_TEST_CHECK(stack.capacity, 6789);
15 stack_deinit(&stack);
16
17 MOS_TEST_CHECK(stack.top, (ptr_t) NULL);
18 MOS_TEST_CHECK(stack.head, (ptr_t) NULL);
19 MOS_TEST_CHECK(stack.capacity, 0);
20}
21
23{
24 downwards_stack_t stack = { 0 };
25 void *addr = kmalloc(4096);
26 stack_init(&stack, addr, 4096);
27
28 ptr_t stack_bottom = (ptr_t) addr + 4096;
29 MOS_TEST_CHECK(stack.capacity, 4096);
30 MOS_TEST_CHECK(stack.head, stack_bottom);
31 MOS_TEST_CHECK(stack.top, stack_bottom);
32
33 int pushed_1[10] = { 12345, 54321, 67890, 98765, 43210, 56789, 1234, 54321, 67890, 98765 };
34
35 stack_push(&stack, pushed_1, sizeof(pushed_1));
36 MOS_TEST_CHECK(stack.top, stack_bottom);
37 MOS_TEST_CHECK(stack.head, stack_bottom - sizeof(pushed_1));
38 MOS_TEST_CHECK(stack.capacity, 4096);
39
40 int pushed_2[10] = { 4444, 5555, 6666, 7777, 8888, 9999, 10101, 11011, 12012, 13013 };
41 stack_push(&stack, pushed_2, sizeof(pushed_2));
42 MOS_TEST_CHECK(stack.top, stack_bottom);
43 MOS_TEST_CHECK(stack.head, stack_bottom - sizeof(pushed_1) - sizeof(pushed_2));
44 MOS_TEST_CHECK(stack.capacity, 4096);
45
46 int tmp[10] = { 0 };
47 stack_pop(&stack, sizeof(tmp), tmp);
48 MOS_TEST_CHECK(stack.top, stack_bottom);
49 MOS_TEST_CHECK(stack.head, stack_bottom - sizeof(pushed_1));
50 MOS_TEST_CHECK(stack.capacity, 4096);
51 MOS_TEST_CHECK(tmp[0], pushed_2[0]);
52 MOS_TEST_CHECK(tmp[1], pushed_2[1]);
53 MOS_TEST_CHECK(tmp[2], pushed_2[2]);
54 MOS_TEST_CHECK(tmp[3], pushed_2[3]);
55 MOS_TEST_CHECK(tmp[4], pushed_2[4]);
56 MOS_TEST_CHECK(tmp[5], pushed_2[5]);
57 MOS_TEST_CHECK(tmp[6], pushed_2[6]);
58 MOS_TEST_CHECK(tmp[7], pushed_2[7]);
59 MOS_TEST_CHECK(tmp[8], pushed_2[8]);
60 MOS_TEST_CHECK(tmp[9], pushed_2[9]);
61
62 stack_pop(&stack, sizeof(tmp), tmp);
63 MOS_TEST_CHECK(stack.top, stack_bottom);
64 MOS_TEST_CHECK(stack.head, stack_bottom);
65 MOS_TEST_CHECK(stack.capacity, 4096);
66 MOS_TEST_CHECK(tmp[0], pushed_1[0]);
67 MOS_TEST_CHECK(tmp[1], pushed_1[1]);
68 MOS_TEST_CHECK(tmp[2], pushed_1[2]);
69 MOS_TEST_CHECK(tmp[3], pushed_1[3]);
70 MOS_TEST_CHECK(tmp[4], pushed_1[4]);
71 MOS_TEST_CHECK(tmp[5], pushed_1[5]);
72 MOS_TEST_CHECK(tmp[6], pushed_1[6]);
73 MOS_TEST_CHECK(tmp[7], pushed_1[7]);
74 MOS_TEST_CHECK(tmp[8], pushed_1[8]);
75 MOS_TEST_CHECK(tmp[9], pushed_1[9]);
76
77 stack_deinit(&stack);
78 kfree(addr);
79}
MOSAPI void stack_deinit(downwards_stack_t *stack)
Definition stack.c:17
MOSAPI void stack_init(downwards_stack_t *stack, void *mem_region_bottom, size_t size)
Definition stack.c:8
MOSAPI void stack_pop(downwards_stack_t *stack, size_t size, void *data)
Definition stack.c:43
MOSAPI void * stack_push(downwards_stack_t *stack, const void *data, size_t size)
Definition stack.c:32
#define NULL
Definition pb_syshdr.h:46
size_t capacity
Definition stack.h:18
static void stack_init_deinit(mos_test_result_t *, bool *, bool *)
static void stack_push_pop_stack(mos_test_result_t *, bool *, bool *)
#define MOS_TEST_CHECK(actual, expected)
#define MOS_TEST_CASE(_TestName)
unsigned long ptr_t
Definition types.h:25