tests: add rtc driver test case
the test include 2 ztest cases, verfy below apis: rtc_enable() rtc_disable() rtc_read() rtc_set_config() rtc_set_alarm() rtc_get_pending_int() Change-Id: Ifca2541312c5ec8d450803f1b6e4f5064098e7fe Signed-off-by: jing wang <jing.j.wang@intel.com> Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
638066757f
commit
ed754ecf6d
8 changed files with 291 additions and 0 deletions
4
tests/drivers/rtc/rtc_basic_api/Makefile
Normal file
4
tests/drivers/rtc/rtc_basic_api/Makefile
Normal file
|
@ -0,0 +1,4 @@
|
|||
BOARD ?= quark_se_c1000_devboard
|
||||
CONF_FILE = prj.conf
|
||||
|
||||
include ${ZEPHYR_BASE}/Makefile.inc
|
3
tests/drivers/rtc/rtc_basic_api/prj.conf
Normal file
3
tests/drivers/rtc/rtc_basic_api/prj.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
CONFIG_RTC=y
|
||||
CONFIG_RTC_QMSI=y
|
||||
CONFIG_ZTEST=y
|
3
tests/drivers/rtc/rtc_basic_api/src/Makefile
Normal file
3
tests/drivers/rtc/rtc_basic_api/src/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
include $(ZEPHYR_BASE)/tests/Makefile.test
|
||||
|
||||
obj-y += main.o test_rtc_calendar.o test_rtc_alarm.o
|
32
tests/drivers/rtc/rtc_basic_api/src/main.c
Normal file
32
tests/drivers/rtc/rtc_basic_api/src/main.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup t_driver_rtc
|
||||
* @{
|
||||
* @defgroup t_rtc_basic_api test_rtc_basic_api
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <test_rtc.h>
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(rtc_basic_test,
|
||||
ztest_unit_test(test_rtc_alarm),
|
||||
ztest_unit_test(test_rtc_calendar));
|
||||
ztest_run_test_suite(rtc_basic_test);
|
||||
}
|
36
tests/drivers/rtc/rtc_basic_api/src/test_rtc.h
Normal file
36
tests/drivers/rtc/rtc_basic_api/src/test_rtc.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief RTC cases header file
|
||||
*
|
||||
* Header file for RTC cases
|
||||
*/
|
||||
|
||||
#ifndef __TEST_RTC_H__
|
||||
#define __TEST_RTC_H__
|
||||
|
||||
#include <rtc.h>
|
||||
#include <zephyr.h>
|
||||
#include <ztest.h>
|
||||
|
||||
#define RTC_DEVICE_NAME CONFIG_RTC_0_NAME
|
||||
|
||||
void test_rtc_calendar(void);
|
||||
void test_rtc_alarm(void);
|
||||
|
||||
#endif /* __TEST_RTC_H__ */
|
126
tests/drivers/rtc/rtc_basic_api/src/test_rtc_alarm.c
Normal file
126
tests/drivers/rtc/rtc_basic_api/src/test_rtc_alarm.c
Normal file
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @addtogroup t_rtc_basic_api
|
||||
* @{
|
||||
* @defgroup t_rtc_alarm test_rtc_alarm
|
||||
* @brief TestPurpose: verify RTC alarm work and pending interrupt detected
|
||||
* @details
|
||||
* - Test Steps
|
||||
* -# Enable RTC internal counter
|
||||
* -# Configure RTC with init_val, alarm_val, cb_fn and enable RTC alarm
|
||||
* -# Sleep for while waiting for RTC alarm
|
||||
* -# Reconfigure RTC to alarm 1 second later using rtc_set_alarm()
|
||||
* -# Sleep for while waiting for RTC alarm
|
||||
* -# Disable RTC internal counter and repeat previous operations
|
||||
* - Expected Results
|
||||
* -# When RTC internal counter is enabled, RTC alarm can be invoked using
|
||||
* both rtc_set_config() and rtc_set_alarm()
|
||||
* -# When RTC internal counter is disabled, RTC alarm won't be invoked.
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <test_rtc.h>
|
||||
|
||||
static bool rtc_alarm_up;
|
||||
|
||||
static void rtc_alarm_callback(struct device *rtc_dev)
|
||||
{
|
||||
|
||||
TC_PRINT("%s: Invoked\n", __func__);
|
||||
TC_PRINT("RTC counter: %u\n", rtc_read(rtc_dev));
|
||||
|
||||
/* Verify rtc_get_pending_int() */
|
||||
if (rtc_get_pending_int(rtc_dev)) {
|
||||
TC_PRINT("Catch pending RTC interrupt\n");
|
||||
} else {
|
||||
TC_PRINT("Fail to catch pending RTC interrupt\n");
|
||||
}
|
||||
|
||||
rtc_alarm_up = true;
|
||||
}
|
||||
|
||||
static int test_alarm(void)
|
||||
{
|
||||
struct rtc_config config;
|
||||
struct device *rtc = device_get_binding(RTC_DEVICE_NAME);
|
||||
|
||||
if (!rtc) {
|
||||
TC_PRINT("Cannot get RTC device\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
config.init_val = 0;
|
||||
config.alarm_enable = 1;
|
||||
config.alarm_val = RTC_ALARM_SECOND;
|
||||
config.cb_fn = rtc_alarm_callback;
|
||||
|
||||
rtc_enable(rtc);
|
||||
|
||||
/* 1. Verify rtc_set_config() */
|
||||
rtc_alarm_up = false;
|
||||
if (rtc_set_config(rtc, &config)) {
|
||||
TC_ERROR("Failed to config RTC alarm\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
k_sleep(1500);
|
||||
|
||||
if (!rtc_alarm_up) {
|
||||
TC_PRINT("RTC alarm doesn't work well\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
/* 2. Verify rtc_set_alarm() */
|
||||
rtc_alarm_up = false;
|
||||
if (rtc_set_alarm(rtc, rtc_read(rtc) + RTC_ALARM_SECOND)) {
|
||||
TC_PRINT("Failed to set RTC Alarm\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
k_sleep(1500);
|
||||
|
||||
if (!rtc_alarm_up) {
|
||||
TC_PRINT("RTC alarm doesn't work well\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
/* 3. Verify RTC Alarm disabled after disable internal counter */
|
||||
rtc_disable(rtc);
|
||||
rtc_alarm_up = false;
|
||||
|
||||
if (rtc_set_alarm(rtc, rtc_read(rtc) + RTC_ALARM_SECOND)) {
|
||||
TC_PRINT("Failed to set RTC Alarm\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
k_sleep(1500);
|
||||
|
||||
if (rtc_alarm_up) {
|
||||
TC_PRINT("Failed to disable RTC Alarm\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
TC_PRINT("RTC alarm works well\n");
|
||||
|
||||
return TC_PASS;
|
||||
}
|
||||
|
||||
void test_rtc_alarm(void)
|
||||
{
|
||||
assert_true(test_alarm() == TC_PASS, NULL);
|
||||
}
|
83
tests/drivers/rtc/rtc_basic_api/src/test_rtc_calendar.c
Normal file
83
tests/drivers/rtc/rtc_basic_api/src/test_rtc_calendar.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @addtogroup t_rtc_basic_api
|
||||
* @{
|
||||
* @defgroup t_rtc_calendar test_rtc_calendar
|
||||
* @brief TestPurpose: verify RTC internal counter enable/disable/read work
|
||||
* @details
|
||||
* - Test Steps
|
||||
* -# Enable RTC internal counter
|
||||
* -# Read RTC internal counter and sleep for a while
|
||||
* -# Read RTC internal counter again and compare it with the previous value
|
||||
* -# Disable RTC internal counter and repeat previous operations
|
||||
* - Expected Results
|
||||
* -# When enabled, the values read from RTC internal counter increase.
|
||||
* -# When disabled, the values read from RTC internal counter don't change.
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <test_rtc.h>
|
||||
|
||||
static int test_task(void)
|
||||
{
|
||||
uint32_t val_1 = 0;
|
||||
uint32_t val_2 = 0;
|
||||
struct device *rtc = device_get_binding(RTC_DEVICE_NAME);
|
||||
|
||||
if (!rtc) {
|
||||
TC_PRINT("Cannot get RTC device\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
/* 1. Verify rtc_enable() */
|
||||
rtc_enable(rtc);
|
||||
|
||||
/* 2. Verify rtc_enable() */
|
||||
val_1 = rtc_read(rtc);
|
||||
k_sleep(2000);
|
||||
val_2 = rtc_read(rtc);
|
||||
|
||||
TC_PRINT("val_1: %u, val_2: %u, delta: %lu:%lu\n",
|
||||
val_1, val_2,
|
||||
(val_2 - val_1) / RTC_ALARM_SECOND,
|
||||
(val_2 - val_1) % RTC_ALARM_SECOND);
|
||||
|
||||
if (val_2 <= val_1) {
|
||||
TC_PRINT("RTC doesn't work well\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
/* 3. Verify rtc_disable() */
|
||||
rtc_disable(rtc);
|
||||
|
||||
val_1 = rtc_read(rtc);
|
||||
k_sleep(1000);
|
||||
val_2 = rtc_read(rtc);
|
||||
|
||||
if (val_2 != val_1) {
|
||||
TC_PRINT("Fail to disable RTC\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
return TC_PASS;
|
||||
}
|
||||
|
||||
void test_rtc_calendar(void)
|
||||
{
|
||||
assert_true((test_task() == TC_PASS), NULL);
|
||||
}
|
4
tests/drivers/rtc/rtc_basic_api/testcase.ini
Normal file
4
tests/drivers/rtc/rtc_basic_api/testcase.ini
Normal file
|
@ -0,0 +1,4 @@
|
|||
[test_rtc]
|
||||
tags = drivers
|
||||
arch_whitelist = x86 arc
|
||||
platform_whitelist = quark_se_c1000_devboard arduino_101 quark_d2000_crb
|
Loading…
Add table
Add a link
Reference in a new issue