Skip to content

Commit 6279f4d

Browse files
committed
bsp: k230: add testcases for drivers
Signed-off-by: Wang Chen <[email protected]>
1 parent c5f0ae8 commit 6279f4d

17 files changed

+2393
-0
lines changed

bsp/k230/testcase/SConscript

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# for module compiling
2+
import os
3+
from building import *
4+
5+
cwd = GetCurrentDir()
6+
objs = []
7+
list = os.listdir(cwd)
8+
9+
for d in list:
10+
path = os.path.join(cwd, d)
11+
if os.path.isfile(os.path.join(path, 'SConscript')):
12+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
13+
14+
Return('objs')

bsp/k230/testcase/kernel/Kconfig

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
menu "Kernel Testcase"
2+
3+
config UTEST_MMU_TC
4+
bool "MMU test"
5+
default n
6+
7+
config UTEST_ADC
8+
bool "ADC test"
9+
default n
10+
11+
config RT_USING_GPIO
12+
bool "GPIO test"
13+
default n
14+
15+
config RT_USING_SPI
16+
bool "SPI test"
17+
default n
18+
19+
config UTEST_OTP
20+
bool "OTP test"
21+
default n
22+
23+
config UTEST_WDT
24+
bool "WatchDog test"
25+
default n
26+
27+
config UTEST_TS
28+
bool "TS test"
29+
default n
30+
31+
config UTEST_GPIO
32+
bool "GPIO test"
33+
default n
34+
35+
config UTEST_PWM
36+
bool "PWM test"
37+
default n
38+
39+
config UTEST_HWTIMER
40+
bool "hwtimer test"
41+
default n
42+
43+
config UTEST_RTC
44+
bool "rtc test"
45+
default n
46+
47+
endmenu

bsp/k230/testcase/kernel/SConscript

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Import('rtconfig')
2+
from building import *
3+
4+
cwd = GetCurrentDir()
5+
src = []
6+
CPPPATH = [cwd]
7+
8+
if GetDepend(['UTEST_MMU_TC']):
9+
src += ['mmu_tc.c']
10+
11+
if GetDepend(['UTEST_I2C_OV9282']):
12+
src += ['i2c_unitest_ov9282.c']
13+
14+
if GetDepend(['UTEST_I2C_TMP103']):
15+
src += ['i2c_unitest_tmp103.c']
16+
17+
if GetDepend(['UTEST_ADC']):
18+
src += ['adc_tc.c']
19+
20+
if GetDepend(['UTEST_GPIO']):
21+
src += ['gpio_unitest_rw.c']
22+
23+
if GetDepend(['UTEST_GPIO']):
24+
src += ['gpio_unitest_irq.c']
25+
26+
if GetDepend(['UTEST_SPI_NAND']):
27+
src += ['spi_nandflash_w25n01gv.c']
28+
29+
if GetDepend(['UTEST_OTP']):
30+
src += ['otp_tc.c']
31+
32+
if GetDepend(['UTEST_WDT']):
33+
src += ['wdt_irq_tc.c']
34+
35+
if GetDepend(['UTEST_TS']):
36+
src += ['ts_tc.c']
37+
38+
if GetDepend(['UTEST_PWM']):
39+
src += ['pwm_tc.c']
40+
41+
if GetDepend(['UTEST_HWTIMER']):
42+
src += ['hwtimer_tc.c']
43+
44+
if GetDepend(['UTEST_RTC']):
45+
src += ['rtc_tc.c']
46+
47+
group = DefineGroup('utestcases', src, depend = ['RT_USING_UTEST'], CPPPATH = CPPPATH)
48+
49+
Return('group')

bsp/k230/testcase/kernel/adc_tc.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/* Copyright 2020 Canaan Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
#include <rtthread.h>
16+
#include <rtdevice.h>
17+
#include <stdlib.h>
18+
#include "utest.h"
19+
20+
#define ADC_DEV_NAME "adc"
21+
#define ADC_MAX_CHANNEL 5 /* On the EVB board, the 6 channel is connected to GND */
22+
23+
static void test_probe(void)
24+
{
25+
rt_adc_device_t adc_dev;
26+
27+
adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
28+
uassert_not_null(adc_dev);
29+
30+
return;
31+
}
32+
33+
static void test_read(void)
34+
{
35+
int i;
36+
rt_err_t ret = RT_EOK;
37+
rt_uint32_t reg_value = 0;
38+
rt_adc_device_t adc_dev;
39+
40+
adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
41+
if (adc_dev == RT_NULL)
42+
{
43+
uassert_false(1);
44+
return;
45+
}
46+
47+
ret = rt_adc_enable(adc_dev, 0);
48+
uassert_int_equal(ret, RT_EOK);
49+
50+
for (i = 0; i < 1; i++)
51+
{
52+
ret = rt_adc_enable(adc_dev, i);
53+
uassert_int_equal(ret, RT_EOK);
54+
55+
reg_value = rt_adc_read(adc_dev, i);
56+
uassert_in_range(reg_value, 0xFF0, 0x1000);
57+
}
58+
59+
for (i = 0; i < ADC_MAX_CHANNEL; i++)
60+
{
61+
ret = rt_adc_disable(adc_dev, i);
62+
uassert_int_equal(ret, RT_EOK);
63+
64+
reg_value = rt_adc_read(adc_dev, i);
65+
uassert_int_equal(reg_value, 0);
66+
}
67+
68+
return;
69+
}
70+
71+
static rt_err_t utest_tc_init(void)
72+
{
73+
74+
return RT_EOK;
75+
}
76+
77+
static rt_err_t utest_tc_cleanup(void)
78+
{
79+
80+
return RT_EOK;
81+
}
82+
83+
static void testcase(void)
84+
{
85+
UTEST_UNIT_RUN(test_probe);
86+
UTEST_UNIT_RUN(test_read);
87+
}
88+
UTEST_TC_EXPORT(testcase, "testcases.kernel.adc_tc", utest_tc_init, utest_tc_cleanup, 100);
89+
90+
/********************* end of file ************************/
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (C) 2022, Canaan Bright Sight Co., Ltd
3+
*
4+
* All enquiries to https://www.canaan-creative.com/
5+
*
6+
*/
7+
#include <unistd.h>
8+
#include <stdio.h>
9+
#include <rtdbg.h>
10+
#include "utest.h"
11+
#include <rtthread.h>
12+
#include <rtdevice.h>
13+
#include "drv_gpio.h"
14+
#define LED_PIN_NUM1 33
15+
#define KEY1_PIN_NUM 32
16+
static int cnt;
17+
static char retn;
18+
static char on;
19+
void key_irq(void *args)
20+
{
21+
cnt++;
22+
if(!on)
23+
{
24+
LOG_W("turn on led!\n");
25+
kd_pin_write(LED_PIN_NUM1, GPIO_PV_LOW);
26+
on = 1;
27+
} else {
28+
LOG_W("turn off led!\n");
29+
kd_pin_write(LED_PIN_NUM1, GPIO_PV_HIGH);
30+
on = 0;
31+
}
32+
if (cnt >= 10) {
33+
retn = 0;
34+
cnt = 0;
35+
}
36+
}
37+
38+
39+
static void gpio_key_led_int(void)
40+
{
41+
retn = 1;
42+
LOG_W("gpio test irq falling\n");
43+
/* led引脚为输出模式 */
44+
kd_pin_mode(LED_PIN_NUM1, GPIO_DM_OUTPUT);
45+
/* 默认高电平 */
46+
kd_pin_write(LED_PIN_NUM1, GPIO_PV_HIGH);
47+
48+
/* 按键1引脚为输入模式 */
49+
kd_pin_mode(KEY1_PIN_NUM, GPIO_DM_INPUT);
50+
/* 绑定中断,上升沿模式,回调函数名为 key_irq */
51+
kd_pin_attach_irq(KEY1_PIN_NUM,GPIO_PE_FALLING, key_irq, RT_NULL);
52+
/* 使能中断 */
53+
kd_pin_irq_enable(KEY1_PIN_NUM, KD_GPIO_IRQ_ENABLE);
54+
while(retn);
55+
kd_pin_detach_irq(KEY1_PIN_NUM);
56+
}
57+
58+
static void gpio_key_led_int1(void)
59+
{
60+
retn = 1;
61+
LOG_W("gpio test irq rising\n");
62+
/* led引脚为输出模式 */
63+
kd_pin_mode(LED_PIN_NUM1, GPIO_DM_OUTPUT);
64+
/* 默认低电平 */
65+
kd_pin_write(LED_PIN_NUM1, GPIO_PV_LOW);
66+
67+
/* 按键1引脚为输入模式 */
68+
kd_pin_mode(KEY1_PIN_NUM, GPIO_DM_INPUT);
69+
/* 绑定中断,上升沿模式,回调函数名为 key_irq */
70+
kd_pin_attach_irq(KEY1_PIN_NUM,GPIO_PE_RISING, key_irq, RT_NULL);
71+
/* 使能中断 */
72+
kd_pin_irq_enable(KEY1_PIN_NUM, KD_GPIO_IRQ_ENABLE);
73+
while(retn);
74+
kd_pin_detach_irq(KEY1_PIN_NUM);
75+
}
76+
77+
static void gpio_key_led_int2(void)
78+
{
79+
retn = 1;
80+
LOG_W("gpio test irq both\n");
81+
/* led引脚为输出模式 */
82+
kd_pin_mode(LED_PIN_NUM1, GPIO_DM_OUTPUT);
83+
/* 默认低电平 */
84+
kd_pin_write(LED_PIN_NUM1, GPIO_PV_LOW);
85+
86+
/* 按键1引脚为输入模式 */
87+
kd_pin_mode(KEY1_PIN_NUM, GPIO_DM_INPUT);
88+
/* 绑定中断,上升沿模式,回调函数名为 key_irq */
89+
kd_pin_attach_irq(KEY1_PIN_NUM,GPIO_PE_BOTH, key_irq, RT_NULL);
90+
/* 使能中断 */
91+
kd_pin_irq_enable(KEY1_PIN_NUM, KD_GPIO_IRQ_ENABLE);
92+
while(retn);
93+
kd_pin_detach_irq(KEY1_PIN_NUM);
94+
}
95+
96+
static void testcase(void)
97+
{
98+
UTEST_UNIT_RUN(gpio_key_led_int);
99+
UTEST_UNIT_RUN(gpio_key_led_int1);
100+
UTEST_UNIT_RUN(gpio_key_led_int2);
101+
}
102+
103+
static rt_err_t utest_tc_init(void)
104+
{
105+
return RT_EOK;
106+
}
107+
static rt_err_t utest_tc_cleanup(void)
108+
{
109+
return RT_EOK;
110+
}
111+
112+
UTEST_TC_EXPORT(testcase, "testcases.kernel.gpio_irq_test", utest_tc_init, utest_tc_cleanup, 100);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2022, Canaan Bright Sight Co., Ltd
3+
*
4+
* All enquiries to https://www.canaan-creative.com/
5+
*
6+
*/
7+
#include <unistd.h>
8+
#include <stdio.h>
9+
#include <rtdbg.h>
10+
#include "utest.h"
11+
#include <rtthread.h>
12+
#include <rtdevice.h>
13+
#include "drv_gpio.h"
14+
#define LED_PIN_NUM1 33
15+
#define KEY1_PIN_NUM 32
16+
17+
static void gpio_input_output_test(void)
18+
{
19+
int cnt = 20;
20+
int level;
21+
LOG_D("gpio input and output test, gpio33 output and gpio32 input, gpio32 will read the level.");
22+
/* led引脚为输出模式 */
23+
kd_pin_mode(LED_PIN_NUM1, GPIO_DM_OUTPUT);
24+
25+
/* key引脚为输入模式 */
26+
kd_pin_mode(KEY1_PIN_NUM, GPIO_DM_INPUT);
27+
28+
while(1)
29+
{
30+
kd_pin_write(LED_PIN_NUM1, GPIO_PV_LOW);
31+
level = kd_pin_read(KEY1_PIN_NUM);
32+
uassert_int_equal(level, GPIO_PV_LOW);
33+
34+
kd_pin_write(LED_PIN_NUM1, GPIO_PV_HIGH);
35+
level = kd_pin_read(KEY1_PIN_NUM);
36+
uassert_int_equal(level, GPIO_PV_HIGH);
37+
38+
rt_thread_mdelay(500);
39+
40+
if(0 == cnt--)
41+
break;
42+
}
43+
}
44+
45+
static void testcase(void)
46+
{
47+
UTEST_UNIT_RUN(gpio_input_output_test);
48+
}
49+
50+
static rt_err_t utest_tc_init(void)
51+
{
52+
return RT_EOK;
53+
}
54+
static rt_err_t utest_tc_cleanup(void)
55+
{
56+
return RT_EOK;
57+
}
58+
59+
UTEST_TC_EXPORT(testcase, "testcases.kernel.gpio_read_write_test", utest_tc_init, utest_tc_cleanup, 100);
60+

0 commit comments

Comments
 (0)