Skip to content

Commit b911ec3

Browse files
caveguyjun-ping
authored andcommitted
BugID:21666905:[exmaple]add linkkit testsuites
Change-Id: I7e60a5a5c9918bf01547fc85320658001f785e62 Reviewed-on: http://yuncode.alibaba-inc.com/220253 Tested-by: 李诚 lc122798 <lc122798@alibaba-inc.com> Reviewed-by: 杨骁 yusheng.yx <yusheng.yx@alibaba-inc.com> Reviewed-by: 于海龙 hailong.yhl <hailong.yhl@alibaba-inc.com>
1 parent f38c794 commit b911ec3

62 files changed

Lines changed: 20584 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (C) 2015-2018 Alibaba Group Holding Limited
3+
*/
4+
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#include <string.h>
8+
#include <stdarg.h>
9+
10+
#include "aos/kernel.h"
11+
#include "aos/log.h"
12+
#include "aos/yloop.h"
13+
14+
#include "netmgr.h"
15+
#include "app_entry.h"
16+
17+
#ifdef CSP_LINUXHOST
18+
#include <signal.h>
19+
#endif
20+
21+
static char linkkit_started = 0;
22+
23+
static app_main_paras_t entry_paras;
24+
25+
typedef void (*task_fun)(void *);
26+
27+
static void wifi_service_event(input_event_t *event, void *priv_data)
28+
{
29+
if (event->type != EV_WIFI) {
30+
return;
31+
}
32+
33+
if (event->code != CODE_WIFI_ON_GOT_IP) {
34+
return;
35+
}
36+
37+
netmgr_ap_config_t config;
38+
memset(&config, 0, sizeof(netmgr_ap_config_t));
39+
netmgr_get_ap_config(&config);
40+
LOG("wifi_service_event config.ssid %s", config.ssid);
41+
if (strcmp(config.ssid, "adha") == 0 || strcmp(config.ssid, "aha") == 0) {
42+
//clear_wifi_ssid();
43+
return;
44+
}
45+
46+
if (!linkkit_started) {
47+
aos_task_new("iotx_example",(task_fun)linkkit_main,(void *)&entry_paras,1024*10);
48+
linkkit_started = 1;
49+
}
50+
}
51+
52+
#ifdef TEST_LOOP
53+
const char *input_data[2]= {"mqttapp","loop"};
54+
#endif
55+
int application_start(int argc, char **argv)
56+
{
57+
#ifdef CSP_LINUXHOST
58+
signal(SIGPIPE, SIG_IGN);
59+
#endif
60+
61+
#ifdef TEST_LOOP
62+
argc = 2;
63+
argv = (char **)input_data;
64+
#endif
65+
entry_paras.argc = argc;
66+
entry_paras.argv = argv;
67+
68+
#ifdef WITH_SAL
69+
sal_init();
70+
#endif
71+
72+
#ifdef MDAL_MAL_ICA_TEST
73+
HAL_MDAL_MAL_Init();
74+
#endif
75+
76+
aos_set_log_level(AOS_LL_DEBUG);
77+
78+
netmgr_init();
79+
80+
aos_register_event_filter(EV_WIFI, wifi_service_event, NULL);
81+
82+
netmgr_start(false);
83+
84+
aos_loop_run();
85+
86+
return 0;
87+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (C) 2015-2018 Alibaba Group Holding Limited
3+
*/
4+
5+
#ifndef __APP_ENTRY_H__
6+
#define __APP_ENTRY_H__
7+
8+
#include "aos/kernel.h"
9+
10+
typedef struct {
11+
int argc;
12+
char **argv;
13+
}app_main_paras_t;
14+
15+
int linkkit_main(void *paras);
16+
#endif

example/linkkit_testsuites/cut.c

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
#include "cut.h"
2+
3+
struct cut_runtime cut;
4+
5+
static char suite_pattern[64];
6+
static char case_pattern[64];
7+
8+
static void _filter(int argc, char **argv)
9+
{
10+
int i = 0;
11+
struct cut_case *c = NULL;
12+
if (argc == 2 && 0 == strcmp(argv[1], "all")) {
13+
return;
14+
}
15+
16+
for (i = 0; i < cut.ccnt_total; i++) {
17+
c = cut.clist[i];
18+
if ((argc == 2 && (0 != strcmp(c->sname, argv[1]))) ||
19+
(argc == 3 && (0 != strcmp(c->sname, argv[1]) || 0 != strcmp(c->cname, argv[2])))) {
20+
21+
if (!(argc == 2 && strlen(suite_pattern) && strstr(c->sname, suite_pattern))) {
22+
cut.clist[i]->skip = 1;
23+
cut.ccnt_skip++;
24+
}
25+
}
26+
}
27+
}
28+
29+
static void _usage(const char *me)
30+
{
31+
cut_printf("Usage: %s [OPTION] S-FILTER [C-FILTER]\n\n" \
32+
"OPTION:\n" \
33+
" --verbose: verbose when exec cases\n" \
34+
" --list: list cases\n" \
35+
" --count: print case count\n" \
36+
"\n" \
37+
"S-FILTER: suite name filter, e.g. '%s all' means run all suites\n" \
38+
"C-FILTER: case name filter\n", me, me);
39+
}
40+
41+
static int _verbose_opt = 0;
42+
static int _parse_arg(int argc, char **argv)
43+
{
44+
if (argc >= 2) {
45+
if (0 == strcmp(argv[1], "--list")) {
46+
int i = 0;
47+
int cnt = 0;
48+
for (i = 0; i < cut.ccnt_total; i++) {
49+
struct cut_case *c = cut.clist[i];
50+
if (argc == 2 ||
51+
(argc == 3 && 0 == strcmp(argv[2], "all")) ||
52+
(argc == 3 && 0 == strcmp(c->sname, argv[2])) ||
53+
(argc == 3 && strlen(suite_pattern) && strstr(c->sname, suite_pattern)) ||
54+
(argc == 4 && strlen(suite_pattern) && strlen(case_pattern) && strstr(c->sname, suite_pattern)
55+
&& strstr(c->cname, case_pattern)) ||
56+
(argc == 4 && 0 == strcmp(c->sname, argv[2]) && 0 == strcmp(c->cname, argv[3]))) {
57+
cut_printf(" [%02d] %s.%s\n", ++cnt, c->sname, c->cname);
58+
}
59+
}
60+
cut_printf("\n");
61+
cut_printf("In total %d case(s), matched %d case(s)\n", cut.ccnt_total, cnt);
62+
cut_printf("\n");
63+
return 0;
64+
}
65+
if (0 == strcmp(argv[1], "--count")) {
66+
cut_printf("total %d case(s).\n", cut.ccnt_total);
67+
return 0;
68+
}
69+
if (0 == strcmp(argv[1], "--help")) {
70+
_usage(argv[0]);
71+
return 0;
72+
}
73+
}
74+
75+
return 1;
76+
}
77+
78+
int cut_main(int argc, char **argv)
79+
{
80+
int i = 0, j = 0, cnt = 0;
81+
char tmpbuf[128];
82+
char *pos;
83+
84+
if (argc >= 2) {
85+
86+
int idx = 1;
87+
char *q = NULL;
88+
89+
if (!strcmp(argv[1], "--list") || !strncmp(argv[1], "--verbose", strlen("--verbose"))) {
90+
idx += 1;
91+
}
92+
93+
if (idx < argc) {
94+
95+
if ((q = strchr(argv[idx], '%')) != NULL) {
96+
strncpy(suite_pattern, argv[idx], q - argv[idx]);
97+
}
98+
idx += 1;
99+
if (idx < argc) {
100+
if ((q = strchr(argv[idx], '%')) != NULL) {
101+
strncpy(case_pattern, argv[idx], q - argv[idx]);
102+
}
103+
}
104+
}
105+
}
106+
107+
if (0 == _parse_arg(argc, argv)) {
108+
return 0;
109+
}
110+
111+
if (argc >= 2 && !strncmp(argv[1], "--verbose", strlen("--verbose"))) {
112+
_verbose_opt = 1;
113+
argc --;
114+
argv ++;
115+
}
116+
117+
_filter(argc, argv);
118+
119+
for (; i < cut.ccnt_total; i++) {
120+
pos = tmpbuf;
121+
122+
cut.ccur = cut.clist[i];
123+
if (cut.ccur->skip) {
124+
continue;
125+
}
126+
127+
memset(tmpbuf, 0, sizeof(tmpbuf));
128+
pos += cut_snprintf(pos,
129+
sizeof(tmpbuf),
130+
"TEST [%02d/%02d] %s.%s ",
131+
++cnt,
132+
cut.ccnt_total - cut.ccnt_skip,
133+
cut.ccur->sname,
134+
cut.ccur->cname);
135+
for (j = 80 - strlen(tmpbuf); j >= 0; --j) {
136+
pos += sprintf(pos, "%s", ".");
137+
}
138+
if (_verbose_opt) {
139+
pos += sprintf(pos, " [%sEXEC%s]\n", COL_YEL, COL_DEF);
140+
cut_printf("%s", tmpbuf);
141+
pos -= 19;
142+
}
143+
HAL_SleepMs(15000);
144+
TRY {
145+
if (cut.ccur->setup)
146+
{
147+
cut.ccur->setup(cut.ccur->data, cut.ccur);
148+
}
149+
cut.ccur->run(cut.ccur->data, (struct cut_case *)cut.ccur);
150+
if (cut.ccur->teardown)
151+
{
152+
cut.ccur->teardown(cut.ccur->data);
153+
}
154+
155+
pos += sprintf(pos, " [%sSUCC%s]\n", COL_GRE, COL_DEF);
156+
cut_printf("%s", tmpbuf);
157+
158+
cut.ccnt_pass++;
159+
continue;
160+
}
161+
EXCEPT {
162+
163+
pos += sprintf(pos, " [%sFAIL%s]\n", COL_RED, COL_DEF);
164+
cut_printf("%s", tmpbuf);
165+
166+
cut.ccnt_fail++;
167+
continue;
168+
}
169+
}
170+
171+
cut_printf("\n");
172+
cut_printf("===========================================================================\n");
173+
if (cut.ccnt_fail > 0) {
174+
cut_printf("FAIL LIST:\n");
175+
for (i = 0; i < cut.ccnt_fail; i++) {
176+
cut_printf(" [%02d] %s\n", i + 1, cut.cerrmsg[i]);
177+
cut_free(cut.cerrmsg[i]);
178+
}
179+
cut_printf("---------------------------------------------------------------------------\n");
180+
}
181+
cut_printf("SUMMARY:\n" \
182+
" TOTAL: %d\n" \
183+
" SKIPPED: %d\n" \
184+
" MATCHED: %d\n" \
185+
" PASS: %d\n" \
186+
" FAILED: %d\n", cut.ccnt_total, cut.ccnt_skip,
187+
cut.ccnt_total - cut.ccnt_skip, cut.ccnt_pass, cut.ccnt_fail);
188+
cut_printf("===========================================================================\n");
189+
190+
return cut.ccnt_fail;
191+
192+
}
193+

0 commit comments

Comments
 (0)