提交 a99f2070 编写于 作者: 青杠 提交者: YiluMao

add backlight/button/lcd/uvoice/unzip test cases

上级 beed5e1d
/*
* Copyright (C) 2020-2023 Alibaba Group Holding Limited
*/
#include <stdio.h>
#include <sched.h>
#include <pthread.h>
#include <yunit/yunit.h>
extern void backlight_test_init(void);
extern void backlight_test_onoff(void);
extern void backlight_test_silent_reset(void);
extern void backlight_test_get_status(void);
static int init(void)
{
return 0;
}
static int cleanup(void)
{
return 0;
}
static void setup(void)
{
}
static void teardown(void)
{
}
static void setup_pri_save(void)
{
}
static void teardown_pri_restore(void)
{
}
static yunit_test_case_t aos_backlight_testcases[] = {
{"backlight_test_init", backlight_test_init},
{"backlight_test_onoff", backlight_test_onoff},
{"backlight_test_silent_reset", backlight_test_silent_reset},
{"backlight_test_get_status", backlight_test_get_status},
YUNIT_TEST_CASE_NULL};
static yunit_test_suite_t suites[] = {
{"backlight", init, cleanup, setup, teardown, aos_backlight_testcases},
YUNIT_TEST_SUITE_NULL};
void aos_backlight_test(void)
{
yunit_add_test_suites(suites);
}
AOS_TESTCASE(aos_backlight_test);
/*
* Copyright (C) 2015-2023 Alibaba Group Holding Limited
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <yunit/yunit.h>
#include "aos/kernel.h"
/* module name used by log print*/
#define MODULE_NAME "backlight_test"
/* test backlight init */
void backlight_test_init(void)
{
int ret;
ret=aos_lcd_backlight_on();
for (uint8_t i = 0; i < 5; i++) {
ret = aos_lcd_backlight(i*20);
aos_lcd_backlight_valid();
aos_msleep(2000);
YUNIT_ASSERT_EQUAL(ret, 0);
}
}
/* test backlight onoff */
void backlight_test_onoff(void)
{
int ret;
aos_lcd_backlight_off();
YUNIT_ASSERT_EQUAL(ret, 0);
aos_msleep(2000);
aos_lcd_backlight_on();
YUNIT_ASSERT_EQUAL(ret, 0);
aos_msleep(2000);
aos_lcd_backlight_toggle();
YUNIT_ASSERT_EQUAL(ret, 0);
aos_msleep(2000);
}
/* test backlight silent_reset */
void backlight_test_silent_reset(void)
{
int ret;
ret = aos_lcd_backlight(5);
YUNIT_ASSERT_EQUAL(ret, 0);
aos_lcd_backlight_valid_for_silent_reset();
YUNIT_ASSERT_EQUAL(ret, 0);
}
/* test backlight get_status */
void backlight_test_get_status(void)
{
int ret;
uint8_t onoff, level;
ret = aos_lcd_backlight_status(&onoff, &level);
YUNIT_ASSERT_EQUAL(ret, 0);
printf("[%s] backlight status onoff=%d level=%d \n", MODULE_NAME, onoff, level);
}
/*
* Copyright (C) 2020-2023 Alibaba Group Holding Limited
*/
#include <stdio.h>
#include <yunit/yunit.h>
extern void button_test_init(void);
static int init(void)
{
return 0;
}
static int cleanup(void)
{
return 0;
}
static void setup(void)
{
}
static void teardown(void)
{
}
static yunit_test_case_t aos_button_testcases[] = {
{"button_test_init", button_test_init}, YUNIT_TEST_CASE_NULL};
static yunit_test_suite_t suites[] = {
{"button", init, cleanup, setup, teardown, aos_button_testcases},
YUNIT_TEST_SUITE_NULL};
void aos_button_test(void)
{
yunit_add_test_suites(suites);
}
AOS_TESTCASE(aos_button_test);
\ No newline at end of file
/*
* Copyright (C) 2015-2023 Alibaba Group Holding Limited
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "aos/kernel.h"
#include <aos_button.h>
#include <yunit/yunit.h>
/* module name used by log print*/
#define MODULE_NAME "button_test"
/* module parameters */
aos_key_cfg_t button_cfg;
static uint8_t button_short_press_flag = 0;
static uint8_t button_long_press_flag = 0;
static void _short_press_handler() { button_short_press_flag = 1; }
static void _long_press_handler() { button_long_press_flag = 1; }
/* test button init */
void button_test_init(void)
{
int ret;
button_cfg.short_press_max_ms = 500;
button_cfg.long_press_min_ms = 1000;
button_cfg.short_press_handler = _short_press_handler;
button_cfg.long_press_handler = _long_press_handler;
ret = aos_key_init(button_cfg);
YUNIT_ASSERT_EQUAL(ret, 0);
printf("please short press button");
aos_msleep(2000);
YUNIT_ASSERT_EQUAL(button_short_press_flag, 1);
printf("please long press button for 1s");
aos_msleep(2000);
YUNIT_ASSERT_EQUAL(button_long_press_flag, 1);
}
\ No newline at end of file
......@@ -24,30 +24,10 @@ static uint8_t sem_flag = 0;
void kv_test_init(void)
{
int ret;
//ret=aos_hal_flash_init(HAL_PARTITION_APPLICATION);
ret=aos_hal_flash_init(HAL_PARTITION_APPLICATION);
YUNIT_ASSERT_EQUAL(ret, 0);
}
#if 0
/* test kv item */
void kv_test_item(void)
{
int ret;
int set_len = strlen(test_val);
int get_len;
char get_value[32] = {0};
ret = kv_item_set(test_key, test_val, set_len, 1); /* set kv item */
YUNIT_ASSERT_EQUAL(ret, 0);
ret = kv_item_get(test_key, get_value, &get_len); /* get kv item */
YUNIT_ASSERT_EQUAL(ret, 0);
YUNIT_ASSERT_EQUAL(get_len, set_len);
ret = strcmp(get_value, test_val);
YUNIT_ASSERT_EQUAL(ret, 0);
ret = kv_item_delete(test_key); /* del kv item */
YUNIT_ASSERT_EQUAL(ret, 0);
}
#endif
/* test kv flash */
void kv_test_flash(void)
{
......
......@@ -39,10 +39,10 @@ static void teardown_pri_restore(void)
}
static yunit_test_case_t aos_kv_testcases[] = {
//{ "kv_test_init", kv_test_init},
//{ "kv_test_flash", kv_test_flash},
//{ "kv_test_lock", kv_test_lock},
//{ "kv_test_malloc", kv_test_malloc},
{ "kv_test_init", kv_test_init},
{ "kv_test_flash", kv_test_flash},
{ "kv_test_lock", kv_test_lock},
{ "kv_test_malloc", kv_test_malloc},
{ "kv_test_task", kv_test_task},
YUNIT_TEST_CASE_NULL
};
......
/*
* Copyright (C) 2015-2023 Alibaba Group Holding Limited
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <aos_lcd.h>
#include <yunit/yunit.h>
#include "aos/kernel.h"
#define YELLOW 0xFFE0
#define BLUE 0x001F
/* module name used by log print*/
#define MODULE_NAME "lcd_test"
/* module parameters */
#define area_image_w 10
#define area_image_h 10
uint16_t *area_image = NULL;
/* test lcd init */
void lcd_test_init(void)
{
int ret;
ret = aos_hal_lcd_init(1);
YUNIT_ASSERT_EQUAL(ret, 0);
}
/* test lcd onoff */
void lcd_test_onoff(void)
{
int ret;
ret = aos_hal_lcd_display_on();
YUNIT_ASSERT_EQUAL(ret, 0);
ret = aos_hal_lcd_display_off();
YUNIT_ASSERT_EQUAL(ret, 0);
}
/* test lcd image */
static void color_prepare(uint16_t color) {
area_image = (uint16_t*)aos_malloc(area_image_w*area_image_h*2);
for (int i = 0; i <(area_image_w*area_image_h); i++) {
area_image[i] = color;
}
}
void lcd_test_image(void)
{
int ret;
color_prepare(YELLOW);
ret=aos_hal_lcd_image(0,0,area_image_w,area_image_h,area_image);
YUNIT_ASSERT_EQUAL(ret, 0);
aos_msleep(500);
ret = aos_hal_lcd_clear(BLUE);
YUNIT_ASSERT_EQUAL(ret, 0);
aos_msleep(500);
aos_free(area_image);
}
/* test lcd finalize */
void lcd_test_finalize(void)
{
int ret;
ret = aos_hal_lcd_display_off();
YUNIT_ASSERT_EQUAL(ret, 0);
}
\ No newline at end of file
/*
* Copyright (C) 2020-2023 Alibaba Group Holding Limited
*/
#include <stdio.h>
#include <sched.h>
#include <pthread.h>
#include <yunit/yunit.h>
extern void lcd_test_init(void);
extern void lcd_test_onoff(void);
extern void lcd_test_image(void);
extern void lcd_test_finalize(void);
static int init(void)
{
return 0;
}
static int cleanup(void)
{
return 0;
}
static void setup(void)
{
}
static void teardown(void)
{
}
static void setup_pri_save(void)
{
}
static void teardown_pri_restore(void)
{
}
static yunit_test_case_t aos_lcd_testcases[] = {
{ "lcd_test_init", lcd_test_init},
{ "lcd_test_onoff", lcd_test_onoff},
{ "lcd_test_image", lcd_test_image},
{ "lcd_test_finalize", lcd_test_finalize},
YUNIT_TEST_CASE_NULL
};
static yunit_test_suite_t suites[] = {
{ "lcd", init, cleanup, setup, teardown, aos_lcd_testcases },
YUNIT_TEST_SUITE_NULL
};
void aos_lcd_test(void)
{
yunit_add_test_suites(suites);
}
AOS_TESTCASE(aos_lcd_test);
\ No newline at end of file
/*
* Copyright (C) 2020-2023 Alibaba Group Holding Limited
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <ztest.h>
#include "aos/vfs.h"
#include "aos_unzip.h"
#define ZIP_FILE "/jsamp/test.zip"
#define UNZIP_FILE "/jsamp/unzip/test.txt"
#define UNZIP_DIR "/jsamp/unzip"
const char test_zip_str[] = {
0x50, 0x4B, 0x03, 0x04, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x8C, 0xDA, 0x56,
0x6E, 0x93, 0xF4, 0x30, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00,
0x1C, 0x00, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x74, 0x78, 0x74, 0x55, 0x54, 0x09, 0x00,
0x03, 0x16, 0x5C, 0x99, 0x64, 0x17, 0x5C, 0x99, 0x64, 0x75, 0x78, 0x0B, 0x00, 0x01,
0x04, 0xF6, 0x01, 0x00, 0x00, 0x04, 0x14, 0x00, 0x00, 0x00, 0x74, 0x68, 0x69, 0x73,
0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x0A, 0x50, 0x4B,
0x01, 0x02, 0x1E, 0x03, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x8C, 0xDA, 0x56,
0x6E, 0x93, 0xF4, 0x30, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xA4, 0x81, 0x00, 0x00,
0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x2E, 0x74, 0x78, 0x74, 0x55, 0x54, 0x05, 0x00,
0x03, 0x16, 0x5C, 0x99, 0x64, 0x75, 0x78, 0x0B, 0x00, 0x01, 0x04, 0xF6, 0x01, 0x00,
0x00, 0x04, 0x14, 0x00, 0x00, 0x00, 0x50, 0x4B, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x01, 0x00, 0x4E, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00};
static int test_aos_uz(void)
{
int file;
int res;
size_t str_len;
const char test_str[] = "this is a test.";
char str_buff[80];
// create and write file
file = aos_open(ZIP_FILE, O_CREAT | O_RDWR);
zassert_true(file >= 0, "Failed create file [%d], errno [%d]\n", file, errno);
if (file < 0)
{
aos_close(file);
return TC_FAIL;
}
res = aos_write(file, (char *)test_zip_str, sizeof(test_zip_str));
zassert_true(res >= 0, "Failed writing to file [%d]\n", (int)res);
if (res < 0)
{
aos_close(file);
return TC_FAIL;
}
aos_close(file);
printf("File created and written successfully\n");
// unzip files
res = aos_unzip(ZIP_FILE, UNZIP_DIR);
zassert_equal(res, 0, "aos_unzip failed\n");
if (res != 0)
{
TC_PRINT("Failed unzip file [%d]\n", file);
return TC_FAIL;
}
// check if files existance
file = aos_open(UNZIP_DIR "/test.txt", O_RDONLY);
if (file < 0)
{
TC_PRINT("Not found - unzip file [%d] not found \n", file);
return TC_FAIL;
}
res = aos_read(file, str_buff, strlen(test_str));
if (res < 0)
{
TC_PRINT("Failed reading file [%d]\n", (int)res);
aos_close(file);
return TC_FAIL;
}
if (strcmp(test_str, str_buff))
{
TC_PRINT("Error - Data read does not match data written\n");
TC_PRINT("Data read:\"%s\"\n\n", str_buff);
return TC_FAIL;
}
res = aos_close(file);
// clear files
aos_remove(ZIP_FILE);
aos_remove(UNZIP_FILE);
aos_rmdir(UNZIP_DIR);
return TC_PASS;
}
void test_aos_unzip(void)
{
YUNIT_ASSERT(test_aos_uz() == TC_PASS)
}
/*
* Copyright (C) 2020-2023 Alibaba Group Holding Limited
*/
#include "yunit/yunit.h"
extern void test_aos_unzip(void);
static int init(void)
{
return 0;
}
static int cleanup(void)
{
return 0;
}
static void setup(void)
{
}
static void teardown(void)
{
}
void aos_uz_test(void)
{
yunit_test_suite_t *suite;
suite = yunit_add_test_suite("uzapi", init, cleanup, setup, teardown);
yunit_add_test_case(suite, "aos_unzip", test_aos_unzip);
}
AOS_TESTCASE(aos_uz_test);
/*
* Copyright (C) 2015-2023 Alibaba Group Holding Limited
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <uvoice_audio.h>
#include <uvoice_pcm.h>
#include <yunit/yunit.h>
#include "aos/kernel.h"
/* module name used by log print*/
#define MODULE_NAME "pcm_test"
/* configure of export pa */
//#define EXIST_EX_PA
#define PA_ACTIVE_HIGH 1
#define PA_PIN 20
#define PA_DELAY_MS 500
struct external_pa_info pa_info;
/* configure of pcm */
#define EXIST_EX_PA
#define PCM_RATE 48000
#define PCM_CHANNEL 1
#define PCM_PERIOD_SIZE 4
#define PCM_PERIOD_COUNT 5
#define PCM_FORMAT PCM_FORMAT_S16_LE
struct pcm_device *pcm;
/* configure of snd */
uint8_t * sound_data;
int sound_len = 0;
#define SOUND_LEN_MAX 1000
/* test pcm init */
void pcm_test_init(void)
{
int ret;
#ifdef EXIST_EX_PA
pa_info.active_high = PA_ACTIVE_HIGH;
pa_info.pin = PA_PIN;
pa_info.delay_ms = PA_DELAY_MS;
ret = uvoice_extpa_config(&pa_info);
YUNIT_ASSERT_EQUAL(ret, 0);
#endif
ret = uvoice_pcm_init();
YUNIT_ASSERT_EQUAL(ret, 0);
uvoice_pcm_notify(PCM_MSG_WRITE_DONE);
}
/* test pcm open */
void pcm_test_open(void)
{
int ret;
pcm->config.rate = PCM_RATE;
pcm->config.channels = PCM_CHANNEL;
pcm->config.period_size = PCM_PERIOD_SIZE;
pcm->config.period_count = PCM_PERIOD_COUNT;
pcm->config.format = PCM_FORMAT;
ret = uvoice_pcm_open(pcm);
YUNIT_ASSERT_EQUAL(ret, 0);
}
/* test pcm setpath and read */
void pcm_test_read(void)
{
int ret;
ret = uvoice_set_path(pcm, SND_DEVICE_IN_PRIMARY_MIC);
YUNIT_ASSERT_EQUAL(ret, 0);
sound_data = aos_malloc(SOUND_LEN_MAX);
ret = uvoice_pcm_read(pcm,sound_data,SOUND_LEN_MAX);
YUNIT_ASSERT_TRUE(ret>0);
sound_len = ret;
}
/* test pcm setpath and write */
void pcm_test_write(void)
{
int ret;
ret = uvoice_set_path(pcm, SND_DEVICE_OUT_SPEAKER);
YUNIT_ASSERT_EQUAL(ret, 0);
ret = uvoice_pcm_write(pcm,sound_data,sound_len);
YUNIT_ASSERT_TRUE(ret>0);
aos_free(sound_data);
}
/* test pcm setup */
void pcm_test_setup(void)
{
int ret;
pcm->config.period_size=PCM_PERIOD_SIZE*2;
ret=uvoice_pcm_setup(pcm);
YUNIT_ASSERT_EQUAL(ret, 0);
}
/* test pcm mute snd */
void pcm_test_mute(void)
{
int ret;
ret = uvoice_dev_mute(pcm, SND_DEVICE_OUT_SPEAKER,1);
YUNIT_ASSERT_EQUAL(ret, 0);
}
/* test pcm silence */
void pcm_test_silence(void)
{
int ret;
ret = uvoice_pcm_silence(pcm);
YUNIT_ASSERT_EQUAL(ret, 0);
}
/* test pcm flush */
void pcm_test_flush(void)
{
int ret;
ret = uvoice_pcm_flush(pcm);
YUNIT_ASSERT_EQUAL(ret, 0);
}
/* test pcm close */
void pcm_test_close(void)
{
int ret;
ret = uvoice_pcm_close(pcm);
YUNIT_ASSERT_EQUAL(ret, 0);
}
\ No newline at end of file
/*
* Copyright (C) 2020-2023 Alibaba Group Holding Limited
*/
#include <stdio.h>
#include <sched.h>
#include <pthread.h>
#include <yunit/yunit.h>
extern void pcm_test_init(void);
extern void pcm_test_open(void);
extern void pcm_test_read(void);
extern void pcm_test_write(void);
extern void pcm_test_setup(void);
extern void pcm_test_mute(void);
extern void pcm_test_silence(void);
extern void pcm_test_flush(void);
extern void pcm_test_close(void);
static int init(void)
{
return 0;
}
static int cleanup(void)
{
return 0;
}
static void setup(void)
{
}
static void teardown(void)
{
}
static void setup_pri_save(void)
{
}
static void teardown_pri_restore(void)
{
}
static yunit_test_case_t aos_uvoice_testcases[] = {
{ "pcm_test_init", pcm_test_init},
{ "pcm_test_open", pcm_test_open},
{ "pcm_test_read", pcm_test_read},
{ "pcm_test_write", pcm_test_write},
{ "pcm_test_setup", pcm_test_setup},
{ "pcm_test_mute", pcm_test_mute},
{ "pcm_test_silence", pcm_test_silence},
{ "pcm_test_flush", pcm_test_flush},
{ "pcm_test_close", pcm_test_close},
YUNIT_TEST_CASE_NULL
};
static yunit_test_suite_t suites[] = {
{ "uvoice", init, cleanup, setup, teardown, aos_uvoice_testcases },
YUNIT_TEST_SUITE_NULL
};
void aos_uvoice_test(void)
{
yunit_add_test_suites(suites);
}
AOS_TESTCASE(aos_uvoice_test);
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册