mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-12 13:15:37 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
60
Living_SDK/test/testcase/utility/cjson_test/cjson_test.c
Normal file
60
Living_SDK/test/testcase/utility/cjson_test/cjson_test.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
|
||||
#include <aos/aos.h>
|
||||
#include <cJSON.h>
|
||||
|
||||
static void test_simple_case(void)
|
||||
{
|
||||
cJSON *obj = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(obj, "a", "b");
|
||||
char *p = cJSON_PrintUnformatted(obj);
|
||||
YUNIT_ASSERT(strcmp(p, "{\"a\":\"b\"}") == 0);
|
||||
cJSON_free(p);
|
||||
|
||||
cJSON_Delete(obj);
|
||||
}
|
||||
|
||||
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_cjson_testcases[] = {
|
||||
{ "simple", test_simple_case },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "cjson", init, cleanup, setup, teardown, aos_cjson_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_cjson(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_cjson);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := cjson_test
|
||||
|
||||
$(NAME)_COMPONENTS += cjson
|
||||
|
||||
$(NAME)_SOURCES += cjson_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
10
Living_SDK/test/testcase/utility/cjson_test/ucube.py
Normal file
10
Living_SDK/test/testcase/utility/cjson_test/ucube.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
cjson_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('cjson_test', src)
|
||||
|
||||
component.add_comp_deps('utility/cjson')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include <aos/types.h>
|
||||
#include "digest_algorithm.h"
|
||||
#include "crc.h"
|
||||
|
||||
static void test_md5(void)
|
||||
{
|
||||
void *md5 = NULL;
|
||||
char *buf_md5 = "asf";
|
||||
unsigned char buf_store[256] = {0};
|
||||
int len = 3;
|
||||
int ret = 0;
|
||||
|
||||
md5 = digest_md5_init();
|
||||
YUNIT_ASSERT(NULL != md5);
|
||||
|
||||
ret = digest_md5_update(md5,buf_md5,len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_md5(buf_md5,len,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
#ifdef CONFIG_AOS_YTS_ALL
|
||||
ret = digest_md5_file("/etc/bash.bashrc",buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
#endif
|
||||
|
||||
ret = digest_md5_final(md5,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_sha256(void)
|
||||
{
|
||||
char *buf_sha256 = "asf";
|
||||
unsigned char buf_store[256] = {0};
|
||||
int len = 3;
|
||||
void *sha256 = NULL;
|
||||
int ret = 0;
|
||||
|
||||
sha256 = digest_sha256_init();
|
||||
YUNIT_ASSERT(NULL != sha256);
|
||||
|
||||
ret = digest_sha256_update(sha256,buf_sha256,len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha256(buf_sha256,len,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha256_final(sha256,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_sha384(void)
|
||||
{
|
||||
char *buf_sha384 = "asf";
|
||||
unsigned char buf_store[256] = {0};
|
||||
int len = 3;
|
||||
void *sha384 = NULL;
|
||||
int ret = 0;
|
||||
|
||||
sha384 = digest_sha384_init();
|
||||
YUNIT_ASSERT(NULL != sha384);
|
||||
|
||||
ret = digest_sha384_update(sha384,buf_sha384,len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha384(buf_sha384,len,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha384_final(sha384,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_sha512(void)
|
||||
{
|
||||
char *buf_sha512 = "asf";
|
||||
unsigned char buf_store[256] = {0};
|
||||
int len = 3;
|
||||
void *sha512 = NULL;
|
||||
int ret = 0;
|
||||
|
||||
sha512 = digest_sha512_init();
|
||||
YUNIT_ASSERT(NULL != sha512);
|
||||
|
||||
ret = digest_sha512_update(sha512,buf_sha512 ,len);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha512(buf_sha512,len,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = digest_sha512_final(sha512,buf_store);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_crc(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char *buf_md5 = "asf";
|
||||
int len = 3;
|
||||
|
||||
ret = utils_crc16((unsigned char *)buf_md5,len);
|
||||
YUNIT_ASSERT(0 != ret);
|
||||
|
||||
ret = utils_crc32((unsigned char *)buf_md5,len);
|
||||
YUNIT_ASSERT(0 != ret);
|
||||
}
|
||||
|
||||
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_digest_algorithm_testcases[] = {
|
||||
{ "test_md5", test_md5},
|
||||
{ "test_sha256", test_sha256},
|
||||
{ "test_sha384 ", test_sha384 },
|
||||
{ "test_sha512 ", test_sha512 },
|
||||
{ "test_crc", test_crc},
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "digest", init, cleanup, setup, teardown, aos_digest_algorithm_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_digest_algorithm(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_digest_algorithm);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
NAME := digest_algorithm_test
|
||||
|
||||
$(NAME)_COMPONENTS += digest_algorithm
|
||||
|
||||
$(NAME)_SOURCES += digest_algorithm_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
digest_algorithm_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('digest_algorithm_test', src)
|
||||
|
||||
component.add_comp_deps('utility/digest_algorithm')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
179
Living_SDK/test/testcase/utility/hashtable_test/hashtable_test.c
Normal file
179
Living_SDK/test/testcase/utility/hashtable_test/hashtable_test.c
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <yunit.h>
|
||||
#include <yts.h>
|
||||
#include "hashtable.h"
|
||||
|
||||
typedef struct {
|
||||
char name[10];
|
||||
char addr[20];
|
||||
char phone[20];
|
||||
} stu_user_info;
|
||||
|
||||
static void *g_ht = NULL;
|
||||
static int g_ht_size = 5;
|
||||
|
||||
static int key_integer = 5;
|
||||
static int val_integer = 10;
|
||||
static const char *key_str = "user_name";
|
||||
static const char *val_str = "tiger";
|
||||
static const char *key_str_2 = "user_info";
|
||||
static stu_user_info val_stu = {"xxxxx", "yyyyyyyy", "zzzzzzzzzzz"};
|
||||
|
||||
static void test_ht_add(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
for (i=0;i<g_ht_size*2;i++) {
|
||||
ret = ht_add(g_ht, &i, sizeof(int *), &i, sizeof(int));
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
for (i=0;i<g_ht_size*2;i++) {
|
||||
int tmp, len;
|
||||
len = sizeof(int);
|
||||
ht_find(g_ht, &i, sizeof(int *), &tmp, &len);
|
||||
YUNIT_ASSERT(i == tmp && len == sizeof(i));
|
||||
ret = ht_del(g_ht, &i, sizeof(i));
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
ret = ht_add(g_ht, &key_integer, sizeof(key_integer), &val_integer, sizeof(int));
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = ht_add(g_ht, &key_integer, sizeof(key_integer), &val_integer, sizeof(int));
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = ht_add(g_ht, key_str, strlen(key_str) + 1, val_str, strlen(val_str) + 1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = ht_add(g_ht, key_str_2, strlen(key_str_2) + 1, &val_stu, sizeof(val_stu));
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
}
|
||||
|
||||
static void test_ht_find(void)
|
||||
{
|
||||
int tmp = 0;
|
||||
int len = 0;
|
||||
len = sizeof(tmp);
|
||||
ht_find(g_ht, &key_integer, sizeof(&key_integer), &tmp, &len);
|
||||
|
||||
YUNIT_ASSERT(tmp == val_integer);
|
||||
|
||||
char tmp_buff[20] = {0};
|
||||
len = sizeof(tmp_buff);
|
||||
ht_find(g_ht, key_str, strlen(key_str) + 1, tmp_buff, &len);
|
||||
YUNIT_ASSERT(0 == strcmp(tmp_buff, val_str));
|
||||
YUNIT_ASSERT(len == strlen(val_str)+1);
|
||||
|
||||
stu_user_info tmp_user ;
|
||||
len = sizeof(tmp_user);
|
||||
ht_find(g_ht, key_str_2, strlen(key_str_2) + 1, &tmp_user, &len);
|
||||
YUNIT_ASSERT(0 == strcmp(tmp_user.name, val_stu.name) || strcmp(tmp_user.phone, val_stu.phone));
|
||||
}
|
||||
|
||||
static void test_ht_del(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char tmp_buff[20] = {0};
|
||||
int len = 0;
|
||||
|
||||
len = sizeof(tmp_buff);
|
||||
ht_find(g_ht, key_str, strlen(key_str) + 1, tmp_buff, &len);
|
||||
YUNIT_ASSERT(0 == strcmp(tmp_buff, val_str));
|
||||
|
||||
ret = ht_del(g_ht, key_str, strlen(key_str) + 1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
len = sizeof(tmp_buff);
|
||||
memset(tmp_buff,0,len);
|
||||
ht_find(g_ht, key_str, strlen(key_str) + 1, tmp_buff, &len);
|
||||
YUNIT_ASSERT(0 != strcmp(tmp_buff, val_str));
|
||||
}
|
||||
|
||||
static void test_ht_lockless(void)
|
||||
{
|
||||
int key_int_1 = 1;
|
||||
int key_int_2 = 2;
|
||||
int key_int_3 = 3;
|
||||
|
||||
char *val_str_1 = "1";
|
||||
char *val_str_2 = "2";
|
||||
char *val_str_3 = "3";
|
||||
|
||||
int ret = 0;
|
||||
char tmp[5] = {0};
|
||||
int len = sizeof(tmp);
|
||||
|
||||
ht_lock(g_ht);
|
||||
ret = ht_add_lockless(g_ht,&key_int_1,sizeof(int *),val_str_1,strlen(val_str_1)+1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = ht_add_lockless(g_ht,&key_int_2,sizeof(int *),val_str_2,strlen(val_str_2)+1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
|
||||
ret = ht_add_lockless(g_ht,&key_int_3,sizeof(int *),val_str_3,strlen(val_str_3)+1);
|
||||
YUNIT_ASSERT(0 == ret);
|
||||
ht_unlock(g_ht);
|
||||
|
||||
char *x = NULL;
|
||||
x = ht_find(g_ht,&key_int_1,sizeof(int *),tmp,&len);
|
||||
YUNIT_ASSERT(0 == strcmp(tmp,val_str_1));
|
||||
YUNIT_ASSERT(0 == strcmp(x,val_str_1));
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
g_ht = ht_init(g_ht_size);
|
||||
YUNIT_ASSERT(NULL != g_ht);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cleanup(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = ht_clear(g_ht);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
ret = ht_destroy(g_ht);
|
||||
YUNIT_ASSERT(ret == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void teardown(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static yunit_test_case_t aos_hashtable_testcases[] = {
|
||||
{ "ht_add", test_ht_add },
|
||||
{ "ht_find", test_ht_find },
|
||||
{ "ht_del", test_ht_del },
|
||||
{ "ht_lockless", test_ht_lockless },
|
||||
YUNIT_TEST_CASE_NULL
|
||||
};
|
||||
|
||||
static yunit_test_suite_t suites[] = {
|
||||
{ "hashtable", init, cleanup, setup, teardown, aos_hashtable_testcases },
|
||||
YUNIT_TEST_SUITE_NULL
|
||||
};
|
||||
|
||||
void test_hashtable(void)
|
||||
{
|
||||
yunit_add_test_suites(suites);
|
||||
}
|
||||
AOS_TESTCASE(test_hashtable);
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
NAME := hashtable_test
|
||||
|
||||
$(NAME)_COMPONENTS += hashtable
|
||||
|
||||
$(NAME)_SOURCES += hashtable_test.c
|
||||
|
||||
$(NAME)_CFLAGS += -Wall -Werror
|
||||
10
Living_SDK/test/testcase/utility/hashtable_test/ucube.py
Normal file
10
Living_SDK/test/testcase/utility/hashtable_test/ucube.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
src = Split('''
|
||||
hashtable_test.c
|
||||
''')
|
||||
|
||||
component = aos_component('hashtable_test', src)
|
||||
|
||||
component.add_comp_deps('utility/hashtable')
|
||||
|
||||
component.add_cflags('-Wall')
|
||||
component.add_cflags('-Werror')
|
||||
Loading…
Add table
Add a link
Reference in a new issue