Files
OpenCellular/test/timer_dos.c
Vic (Chun-Ju) Yang 4e7e33f6e7 Move pseudo random number generator to common
We have three copies of the same pseudo random number generator in our
test codes. Let's consolidate them into a single copy in test_util.

BUG=chrome-os-partner:19235
TEST=Pass all tests
BRANCH=None

Change-Id: I7ea0b3476f3cfe6944855f19861e3c86af35807e
Signed-off-by: Vic (Chun-Ju) Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/181085
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2013-12-27 07:50:47 +00:00

51 lines
1.0 KiB
C

/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Tasks for timer test.
*/
#include "common.h"
#include "console.h"
#include "task.h"
#include "test_util.h"
#include "timer.h"
#include "util.h"
/* period between 500us and 128ms */
#define PERIOD_US(num) (((num % 256) + 1) * 500)
#define TEST_TIME (3 * SECOND)
int task_timer(void *seed)
{
uint32_t num = (uint32_t)seed;
task_id_t id = task_get_current();
timestamp_t start;
while (1) {
task_wait_event(-1);
ccprintf("\n[Timer task %d]\n", id);
start = get_time();
while (get_time().val - start.val < TEST_TIME) {
/* Wait for a "random" period */
task_wait_event(PERIOD_US(num));
ccprintf("%01d\n", id);
/* next pseudo random delay */
num = prng(num);
}
}
return EC_SUCCESS;
}
void run_test(void)
{
task_wake(TASK_ID_TMRD);
task_wake(TASK_ID_TMRC);
task_wake(TASK_ID_TMRB);
task_wake(TASK_ID_TMRA);
}