Skip to content
Permalink
Browse files

tests/drivers/counter: add test for counter_cmos.c

Add a simple test to verify that the CMOS counter counts at 1Hz.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
  • Loading branch information...
Charles E. Youse authored and andrewboie committed Jun 14, 2019
1 parent 783a43e commit 13b4c17bf76c1e221d2b64ddc7f5b017440d7619
@@ -0,0 +1,9 @@
# Copyright (c) 2019 Intel Corp.
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

target_sources(app PRIVATE src/main.c)
@@ -0,0 +1,3 @@
CONFIG_COUNTER=y
CONFIG_ZTEST=y
CONFIG_COUNTER_CMOS=y
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2019 Intel Corp.
* SPDX-License-Identifier: Apache-2.0
*/

#include <counter.h>
#include <ztest.h>
#include <kernel.h>

/*
* Basic test to ensure that the clock is ticking at roughly 1Hz.
*/

#define DELAY_MS 1200 /* pause 1.2 seconds should always pass */
#define MIN_BOUND 1 /* counter must report at least MIN_BOUND .. */
#define MAX_BOUND 2 /* .. but at most MAX_BOUND seconds elapsed */

void test_cmos_rate(void)
{
struct device *cmos;
u32_t start, elapsed;

cmos = device_get_binding("CMOS");
zassert_true(cmos != NULL, "can't find CMOS counter device");

start = counter_read(cmos);
k_sleep(DELAY_MS);
elapsed = counter_read(cmos) - start;

zassert_true(elapsed >= MIN_BOUND, "busted minimum bound");
zassert_true(elapsed <= MAX_BOUND, "busted maximum bound");
}

void test_main(void)
{
ztest_test_suite(test_cmos_counter, ztest_unit_test(test_cmos_rate));
ztest_run_test_suite(test_cmos_counter);
}
@@ -0,0 +1,4 @@
tests:
counter.cmos:
tags: drivers
arch_whitelist: x86

0 comments on commit 13b4c17

Please sign in to comment.
You can’t perform that action at this time.