Enable aarch64 support, add component test framework and test suite (#211)

and refine aot call indirect op
This commit is contained in:
wenyongh
2020-03-24 19:04:29 +08:00
committed by GitHub
parent 8ae161b779
commit 01e85144f4
77 changed files with 3293 additions and 288 deletions

View File

@ -0,0 +1,16 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
void on_init()
{
printf("Hello, I was installed.\n");
}
void on_destroy()
{
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */
}

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
void res1_handler(request_t *request)
{
response_t response[1];
attr_container_t *payload;
printf("### user resource 1 handler called\n");
printf("###### dump request ######\n");
printf("sender: %lu\n", request->sender);
printf("url: %s\n", request->url);
printf("action: %d\n", request->action);
printf("payload:\n");
if (request->payload
!= NULL&& request->payload_len > 0 && request->fmt == FMT_ATTR_CONTAINER)
attr_container_dump((attr_container_t *) request->payload);
printf("#### dump request end ###\n");
payload = attr_container_create("wasm app response payload");
if (payload == NULL)
return;
attr_container_set_string(&payload, "key1", "value1");
attr_container_set_string(&payload, "key2", "value2");
make_response_for_request(request, response);
set_response(response, CONTENT_2_05,
FMT_ATTR_CONTAINER, (const char *)payload, attr_container_get_serialize_length(payload));
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
api_response_send(response);
attr_container_destroy(payload);
}
void res2_handler(request_t *request)
{
response_t response[1];
make_response_for_request(request, response);
set_response(response, DELETED_2_02, 0, NULL, 0);
api_response_send(response);
printf("### user resource 2 handler called\n");
}
void on_init()
{
/* register resource uri */
api_register_resource_handler("/res1", res1_handler);
api_register_resource_handler("/res2", res2_handler);
}
void on_destroy()
{
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/timer_wasm_app.h"
#include "wa-inc/request.h"
int num = 0;
void publish_overheat_event()
{
attr_container_t *event;
event = attr_container_create("event");
attr_container_set_string(&event, "warning", "temperature is over high");
printf("###app publish event begin ###\n");
api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event,
attr_container_get_serialize_length(event));
printf("###app publish event end ###\n");
attr_container_destroy(event);
}
/* Timer callback */
void timer1_update(user_timer_t timer)
{
printf("Timer update %d\n", num++);
publish_overheat_event();
}
void start_timer()
{
user_timer_t timer;
/* set up a timer */
timer = api_timer_create(1000, true, false, timer1_update);
api_timer_restart(timer, 1000);
}
void on_init()
{
start_timer();
}
void on_destroy()
{
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */
}

View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
uint32 mid;
unsigned long sender;
void my_response_handler(response_t *response, void *user_data)
{
attr_container_t *payload;
printf("### user resource 1 handler called\n");
payload = attr_container_create("wasm app response payload");
if (payload == NULL)
return;
attr_container_set_string(&payload, "key1", "value1");
attr_container_set_string(&payload, "key2", "value2");
response->mid = mid;
response->reciever = sender;
set_response(response, CONTENT_2_05,
FMT_ATTR_CONTAINER, (const char *)payload, attr_container_get_serialize_length(payload));
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
api_response_send(response);
attr_container_destroy(payload);
}
static void test_send_request(const char *url, const char *tag)
{
request_t request[1];
init_request(request, (char *)url, COAP_PUT, 0, NULL, 0);
api_send_request(request, my_response_handler, (void *)tag);
}
void res1_handler(request_t *request)
{
mid = request->mid;
sender = request->sender;
test_send_request("url1", "a general request");
}
void res2_handler(request_t *request)
{
mid = request->mid;
sender = request->sender;
test_send_request("/app/App1/url1", "a general request");
}
void on_init()
{
/* register resource uri */
api_register_resource_handler("/res1", res1_handler);
api_register_resource_handler("/res2", res2_handler);
}
void on_destroy()
{
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
void res1_handler(request_t *request)
{
response_t response[1];
attr_container_t *payload;
printf("[resp] ### user resource 1 handler called\n");
printf("[resp] ###### dump request ######\n");
printf("[resp] sender: %lu\n", request->sender);
printf("[resp] url: %s\n", request->url);
printf("[resp] action: %d\n", request->action);
printf("[resp] payload:\n");
if (request->payload != NULL && request->fmt == FMT_ATTR_CONTAINER)
attr_container_dump((attr_container_t *) request->payload);
printf("[resp] #### dump request end ###\n");
payload = attr_container_create("wasm app response payload");
if (payload == NULL)
return;
attr_container_set_string(&payload, "key1", "value1");
attr_container_set_string(&payload, "key2", "value2");
make_response_for_request(request, response);
set_response(response, CONTENT_2_05,
FMT_ATTR_CONTAINER, (const char *)payload, attr_container_get_serialize_length(payload));
printf("[resp] response payload len %d\n",
attr_container_get_serialize_length(payload));
printf("[resp] reciver: %lu, mid:%d\n", response->reciever, response->mid);
api_response_send(response);
attr_container_destroy(payload);
}
void on_init()
{
/* register resource uri */
api_register_resource_handler("/url1", res1_handler);
}
void on_destroy()
{
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/timer_wasm_app.h"
#include "wa-inc/request.h"
int num = 0;
void publish_overheat_event()
{
attr_container_t *event;
event = attr_container_create("event");
attr_container_set_string(&event, "warning", "temperature is over high");
printf("###app publish event begin ###\n");
api_publish_event("alert/overheat", FMT_ATTR_CONTAINER, event,
attr_container_get_serialize_length(event));
printf("###app publish event end ###\n");
attr_container_destroy(event);
}
/* Timer callback */
void timer1_update(user_timer_t timer)
{
printf("Timer update %d\n", num++);
publish_overheat_event();
}
void start_timer()
{
user_timer_t timer;
/* set up a timer */
timer = api_timer_create(1000, true, false, timer1_update);
api_timer_restart(timer, 1000);
}
void on_init()
{
start_timer();
}
void on_destroy()
{
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
uint32 mid;
unsigned long sender;
void over_heat_event_handler(request_t *request)
{
response_t response[1];
attr_container_t *payload;
payload = attr_container_create("wasm app response payload");
if (payload == NULL)
return;
attr_container_set_string(&payload, "key1", "value1");
attr_container_set_string(&payload, "key2", "value2");
response->mid = mid;
response->reciever = sender;
set_response(response, CONTENT_2_05,
FMT_ATTR_CONTAINER, (const char *)payload, attr_container_get_serialize_length(payload));
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
api_response_send(response);
attr_container_destroy(payload);
}
void res1_handler(request_t *request)
{
mid = request->mid;
sender = request->sender;
api_subscribe_event("alert/overheat", over_heat_event_handler);
}
void on_init()
{
/* register resource uri */
api_register_resource_handler("/res1", res1_handler);
}
void on_destroy()
{
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */
}

View File

@ -0,0 +1,76 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
#include "wa-inc/timer_wasm_app.h"
/* User global variable */
int num = 0;
/* Timer callback */
void timer1_update(user_timer_t timer)
{
if (num < 2)
num++;
}
void res1_handler(request_t *request)
{
user_timer_t timer;
/* set up a timer */
timer = api_timer_create(1000, true, false, timer1_update);
api_timer_restart(timer, 1000);
response_t response[1];
make_response_for_request(request, response);
set_response(response, CONTENT_2_05,
FMT_ATTR_CONTAINER, NULL, 0);
api_response_send(response);
}
void res2_handler(request_t *request)
{
response_t response[1];
attr_container_t *payload;
if (num == 2) {
attr_container_t *payload;
printf("### user resource 1 handler called\n");
payload = attr_container_create("wasm app response payload");
if (payload == NULL)
return;
attr_container_set_int(&payload, "num", num);
make_response_for_request(request, response);
set_response(response, CONTENT_2_05,
FMT_ATTR_CONTAINER, (const char *)payload,
attr_container_get_serialize_length(payload));
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
api_response_send(response);
attr_container_destroy(payload);
}
}
void on_init()
{
/* register resource uri */
api_register_resource_handler("/res1", res1_handler);
api_register_resource_handler("/check_timer", res2_handler);
}
void on_destroy()
{
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
#include "wa-inc/sensor.h"
uint32 mid;
unsigned long sender;
/* Sensor event callback*/
void sensor_event_handler(sensor_t sensor, attr_container_t *event,
void *user_data)
{
printf("### app get sensor event\n");
response_t response[1];
attr_container_t *payload;
payload = attr_container_create("wasm app response payload");
if (payload == NULL)
return;
attr_container_set_string(&payload, "key1", "value1");
attr_container_set_string(&payload, "key2", "value2");
response->mid = mid;
response->reciever = sender;
set_response(response, CONTENT_2_05,
FMT_ATTR_CONTAINER, (const char *)payload, attr_container_get_serialize_length(payload));
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
api_response_send(response);
attr_container_destroy(payload);
}
void res1_handler(request_t *request)
{
mid = request->mid;
sender = request->sender;
sensor_t sensor;
char *user_data;
attr_container_t *config;
printf("### app on_init 1\n");
/* open a sensor */
user_data = malloc(100);
printf("### app on_init 2\n");
sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data);
printf("### app on_init 3\n");
/* config the sensor */
sensor_config(sensor, 2000, 0, 0);
printf("### app on_init 4\n");
}
void on_init()
{
/* register resource uri */
api_register_resource_handler("/res1", res1_handler);
}
void on_destroy()
{
/* real destroy work including killing timer and closing sensor is accomplished in wasm app library version of on_destroy() */
}

View File

@ -0,0 +1,67 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "wasm_app.h"
#include "wa-inc/request.h"
#include "wa-inc/sensor.h"
uint32 mid;
unsigned long sender;
sensor_t sensor;
/* Sensor event callback*/
void sensor_event_handler(sensor_t sensor, attr_container_t *event, void *user_data) {
printf("### app get sensor event\n");
response_t response[1];
attr_container_t *payload;
payload = attr_container_create("wasm app response payload");
if (payload == NULL)
return;
attr_container_set_string(&payload, "key1", "value1");
response->mid = mid;
response->reciever = sender;
set_response(response,
CONTENT_2_05,
FMT_ATTR_CONTAINER,
(const char *)payload,
attr_container_get_serialize_length(payload));
printf("reciver: %lu, mid:%d\n", response->reciever, response->mid);
api_response_send(response);
attr_container_destroy(payload);
}
void res1_handler(request_t *request)
{
mid = request->mid;
sender = request->sender;
char *user_data;
attr_container_t *config;
printf("### app on_init 1\n");
/* open a sensor */
user_data = malloc(100);
printf("### app on_init 2\n");
sensor = sensor_open("sensor_test", 0, sensor_event_handler, user_data);
printf("### app on_init 3\n");
}
void on_init()
{
/* register resource uri */
api_register_resource_handler("/res1", res1_handler);
}
void on_destroy()
{
if(NULL != sensor){
sensor_close(sensor);
}
}

View File

@ -0,0 +1,39 @@
#
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
. ../../../set_dev_env.sh
CC=/opt/wasi-sdk/bin/clang
APP_DIR=$PWD
WAMR_DIR=${APP_DIR}/../../../../../
SDK_DIR=${WAMR_DIR}/wamr-sdk/out/simple-host-interp
APP_FRAMEWORK_DIR=${SDK_DIR}/app-sdk/wamr-app-framework
DEPS_DIR=${WAMR_DIR}/core/deps
for i in `ls *.c`
do
APP_SRC="$i"
OUT_FILE=${i%.*}.wasm
/opt/wasi-sdk/bin/clang -O3 \
-Wno-int-conversion \
-I${APP_FRAMEWORK_DIR}/include \
-I${DEPS_DIR} \
--target=wasm32 -O3 -z stack-size=4096 -Wl,--initial-memory=65536 \
--sysroot=${SDK_DIR}/app-sdk/libc-builtin-sysroot \
-L${APP_FRAMEWORK_DIR}/lib -lapp_framework \
-Wl,--allow-undefined-file=${SDK_DIR}/app-sdk/libc-builtin-sysroot/share/defined-symbols.txt \
-Wl,--no-threads,--strip-all,--no-entry -nostdlib \
-Wl,--export=on_init -Wl,--export=on_destroy \
-Wl,--export=on_request -Wl,--export=on_response \
-Wl,--export=on_sensor_event -Wl,--export=on_timer_callback \
-Wl,--export=on_connection_data \
-o ${OUT_FILE} \
${APP_SRC}
if [ -f ${OUT_FILE} ]; then
echo "build ${OUT_FILE} success"
else
echo "build ${OUT_FILE} fail"
fi
done