Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | /* stack.c */
/*
* Copyright (c) 1997-2010, 2013-2014 Wind River Systems, Inc.
*
* 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 "syskernel.h"
struct nano_stack nano_stack_1;
struct nano_stack nano_stack_2;
uint32_t stack1[2];
uint32_t stack2[2];
/**
*
* @brief Initialize stacks for the test
*
* @return N/A
*
*/
void stack_test_init(void)
{
nano_stack_init(&nano_stack_1, stack1);
nano_stack_init(&nano_stack_2, stack2);
}
/**
*
* @brief Stack test fiber
*
* @param par1 Ignored parameter.
* @param par2 Number of test loops.
*
* @return N/A
*
*/
void stack_fiber1(int par1, int par2)
{
int i;
uint32_t data;
ARG_UNUSED(par1);
for (i = 0; i < par2 / 2; i++) {
nano_fiber_stack_pop(&nano_stack_1, &data, TICKS_UNLIMITED);
if (data != 2 * i) {
break;
}
data = 2 * i;
nano_fiber_stack_push(&nano_stack_2, data);
nano_fiber_stack_pop(&nano_stack_1, &data, TICKS_UNLIMITED);
if (data != 2 * i + 1) {
break;
}
data = 2 * i + 1;
nano_fiber_stack_push(&nano_stack_2, data);
}
}
/**
*
* @brief Stack test fiber
*
* @param par1 Address of the counter.
* @param par2 Number of test cycles.
*
* @return N/A
*
*/
void stack_fiber2(int par1, int par2)
{
int i;
uint32_t data;
int * pcounter = (int *) par1;
for (i = 0; i < par2; i++) {
data = i;
nano_fiber_stack_push(&nano_stack_1, data);
nano_fiber_stack_pop(&nano_stack_2, &data, TICKS_UNLIMITED);
if (data != i) {
break;
}
(*pcounter)++;
}
}
/**
*
* @brief Stack test fiber
*
* @param par1 Address of the counter.
* @param par2 Number of test cycles.
*
* @return N/A
*
*/
void stack_fiber3(int par1, int par2)
{
int i;
uint32_t data;
int * pcounter = (int *) par1;
for (i = 0; i < par2; i++) {
data = i;
nano_fiber_stack_push(&nano_stack_1, data);
data = 0xffffffff;
while (!nano_fiber_stack_pop(&nano_stack_2, &data, TICKS_NONE)) {
fiber_yield();
}
if (data != i) {
break;
}
(*pcounter)++;
}
}
/**
*
* @brief The main test entry
*
* @return 1 if success and 0 on failure
*
*/
int stack_test(void)
{
uint32_t t;
int i = 0;
int return_value = 0;
/* test get wait & put fiber functions */
fprintf(output_file, sz_test_case_fmt,
"Stack #1");
fprintf(output_file, sz_description,
"\n\tnano_stack_init"
"\n\tnano_fiber_stack_pop(TICKS_UNLIMITED)"
"\n\tnano_fiber_stack_push");
printf(sz_test_start_fmt);
stack_test_init();
t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, stack_fiber2, (int) &i,
NUMBER_OF_LOOPS, 3, 0);
t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t);
/* test get/yield & put fiber functions */
fprintf(output_file, sz_test_case_fmt,
"Stack #2");
fprintf(output_file, sz_description,
"\n\tnano_stack_init"
"\n\tnano_fiber_stack_pop(TICKS_UNLIMITED)"
"\n\tnano_fiber_stack_pop"
"\n\tnano_fiber_stack_push"
"\n\tfiber_yield");
printf(sz_test_start_fmt);
stack_test_init();
t = BENCH_START();
i = 0;
task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0);
task_fiber_start(fiber_stack2, STACK_SIZE, stack_fiber3, (int) &i,
NUMBER_OF_LOOPS, 3, 0);
t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i, t);
/* test get wait & put fiber/task functions */
fprintf(output_file, sz_test_case_fmt,
"Stack #3");
fprintf(output_file, sz_description,
"\n\tnano_stack_init"
"\n\tnano_fiber_stack_pop(TICKS_UNLIMITED)"
"\n\tnano_fiber_stack_push"
"\n\tnano_task_stack_pop(TICKS_UNLIMITED)"
"\n\tnano_task_stack_push");
printf(sz_test_start_fmt);
stack_test_init();
t = BENCH_START();
task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0,
NUMBER_OF_LOOPS, 3, 0);
for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) {
uint32_t data;
data = 2 * i;
nano_task_stack_push(&nano_stack_1, data);
data = 2 * i + 1;
nano_task_stack_push(&nano_stack_1, data);
nano_task_stack_pop(&nano_stack_2, &data, TICKS_UNLIMITED);
if (data != 2 * i + 1) {
break;
}
nano_task_stack_pop(&nano_stack_2, &data, TICKS_UNLIMITED);
if (data != 2 * i) {
break;
}
}
t = TIME_STAMP_DELTA_GET(t);
return_value += check_result(i * 2, t);
return return_value;
}
|