-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup Wasm test case #4
Open
HoTBAIzZY
wants to merge
4
commits into
open-vela:dev
Choose a base branch
from
HoTBAIzZY:zzy-dev3
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c382659
feat: add test module and libc test cases
no1wudi ee6a25e
test: Only enable wasm test if WAMR enabled
no1wudi 49103b3
frameworks/wasm: Add kvdb missing interface in frameworks
zhuanglinx ae58458
wasm:remove CONFIG_INTERPRETERS_WAMR_EXTERNAL_MODULE_REGISTRY
yangkun27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# All new code should follow Webkit style guide | ||
|
||
BasedOnStyle: WebKit | ||
SortIncludes: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# Wasm 模块 | ||
# 介绍 | ||
|
||
[简体中文|[English](./README.md)] | ||
|
||
Openvela Wasm 框架提供了额外的模块和 SDK 来构建 `WebAssembly` 应用程序。 | ||
Vela Wasm 框架提供了额外的模块和 SDK 来构建 WebAssembly 应用程序。 | ||
|
||
## 项目结构 | ||
# 项目结构 | ||
|
||
```tree | ||
├── chre | ||
|
@@ -16,21 +16,21 @@ Openvela Wasm 框架提供了额外的模块和 SDK 来构建 `WebAssembly` 应 | |
└── README_zh-cn.md | ||
``` | ||
|
||
* `chre`:该模块提供了从 Context Hub Runtime Environment 到 Wasm 运行时的功能。 | ||
* `libc`: 用于 Wasm 的 C 标准库。 | ||
* `memory`: Wasm 和原生代码之间的内存访问管理。 | ||
* `vela-sysroot`: 用于构建 WebAssembly 应用程序的额外头文件集合。 | ||
* `vendor`: 第三方芯片供应商的 Wasm 应用程序 SDK。 | ||
* `chre`: 该模块提供了从 Context Hub Runtime Environment 到 Wasm 运行时的功能 | ||
* `libc`: 用于 Wasm 的 C 标准库 | ||
* `memory`: Wasm 和原生代码之间的内存访问管理 | ||
* `vela-sysroot`: 用于构建 WebAssembly 应用程序的额外头文件集合 | ||
* `vendor`: 第三方芯片供应商的 Wasm 应用程序 SDK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
|
||
## 如何使用 | ||
# 如何使用 | ||
|
||
### Wasm 运行时的功能模块 | ||
## Wasm 运行时的功能模块 | ||
|
||
目前仅支持 WAMR(WebAssembly Micro Runtime),您如果要使用该功能模块: | ||
1. 在 `menuconfig` 中启用 `WAMR`。 | ||
2. 在相应的子菜单中启用 `WASM_LIBC`(libc)或 `WASM_MEMORY_OPERATIONS`(memory)。 | ||
3. libc 或 memory 的功能可在 `iwasm` 命令行工具中使用,并可以直接在 Wasm 应用程序中使用。 | ||
1. 在 menuconfig 中启用 WAMR。 | ||
2. 在相应的子菜单中启用 `WASM_LIBC`(libc)或 `WASM_MEMORY_OPERATIONS`(内存)。 | ||
3. libc 或 memory 的功能将在 `iwasm` 命令行工具中可用,并可以直接在 Wasm 应用程序中使用。 | ||
|
||
### 使用 SDK 构建 Wasm 应用程序 | ||
## 使用 SDK 构建 Wasm 应用程序 | ||
|
||
`vendor` 目录提供了第三方芯片供应商的 SDK 集合,目前仅支持 `bouffalo lab` 的 BL616。要使用 SDK 构建应用程序,您可以参考以下文档:[BL616 SDK](./vendor/bouffalo/README.md) | ||
`vendor` 目录提供了第三方芯片供应商的 SDK 集合,目前仅支持 bouffalo lab 的 BL616。要使用 SDK 构建应用程序,您可以参考以下文档:[BL616 SDK](./vendor/bouffalo/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# ############################################################################## | ||
# apps/frameworks/chre/CMakeLists.txt | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more contributor | ||
# license agreements. See the NOTICE file distributed with this work for | ||
# additional information regarding copyright ownership. The ASF licenses this | ||
# file to you under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
# | ||
# ############################################################################## | ||
|
||
if(CONFIG_KVDB AND CONFIG_INTERPRETERS_WAMR) | ||
|
||
target_sources(apps PRIVATE kvdb.c) | ||
# register WAMR mod | ||
nuttx_add_wamrmod(MODS kvdb) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
############################################################################ | ||
# apps/frameworks/runtimes/wasm/chre/Make.defs | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. The | ||
# ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance with the | ||
# License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
############################################################################ | ||
|
||
ifeq ($(CONFIG_KVDB)$(CONFIG_INTERPRETERS_WAMR),yy) | ||
CONFIGURED_APPS += $(APPDIR)/frameworks/runtimes/wasm/kvdb | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
############################################################################ | ||
# apps/frameworks/wasm/chre/Makefile | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. The | ||
# ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance with the | ||
# License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
############################################################################ | ||
|
||
include $(APPDIR)/Make.defs | ||
|
||
CSRCS += kvdb.c | ||
|
||
# To delete the Kconfig file, an empty preconfig needs to be added. | ||
preconfig:: | ||
|
||
# Set WAMR_MODULE_NAME and include Module.mk to add this module to the list of | ||
# builtin modules for the WAMR runtime. WAMR_MODULE_NAME must be unique across all | ||
# modules in system. | ||
|
||
WAMR_MODULE_NAME = kvdb | ||
|
||
include $(APPDIR)/interpreters/wamr/Module.mk | ||
include $(APPDIR)/Application.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2024 Xiaomi Corperation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <stdint.h> | ||
#include <sys/param.h> | ||
|
||
#include "kvdb.h" | ||
#include "wasm_export.h" | ||
|
||
/**************************************************************************** | ||
* Private Functions | ||
****************************************************************************/ | ||
|
||
static int property_set_buffer_wrapper(wasm_exec_env_t env, | ||
const char* key, | ||
const void* value, | ||
size_t size) | ||
{ | ||
return property_set_buffer(key, value, size); | ||
} | ||
|
||
static NativeSymbol g_kvdb_symbols[] = { | ||
EXPORT_WASM_API_WITH_SIG2(property_set_buffer, "($*i)i"), | ||
}; | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
bool wamr_module_kvdb_register(void) | ||
{ | ||
/* Add frameworks section init hook here */ | ||
|
||
return wasm_runtime_register_natives("env", g_kvdb_symbols, | ||
nitems(g_kvdb_symbols)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# Copyright (C) 2024 Xiaomi Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
menu "Test" | ||
|
||
config WASM_TEST_PRIORITY | ||
int "task priority" | ||
default 100 | ||
|
||
config WASM_TEST_STACKSIZE | ||
int "stack size" | ||
default DEFAULT_TASK_STACKSIZE | ||
|
||
config WASM_TEST_LIBC | ||
bool "Enable libc test" | ||
default n | ||
depends on WASM_LIBC && TESTING_CMOCKA | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# Copyright (C) 2024 Xiaomi Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
ifneq ($(CONFIG_INTERPRETERS_WAMR),) | ||
CONFIGURED_APPS += $(APPDIR)/frameworks/runtimes/wasm/test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add ifneq/endif |
||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# Copyright (C) 2024 Xiaomi Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
include $(APPDIR)/Make.defs | ||
|
||
PRIORITY = $(CONFIG_WASM_TEST_PRIORITY) | ||
STACKSIZE = $(CONFIG_WASM_TEST_STACKSIZE) | ||
|
||
ifneq ($(CONFIG_WASM_TEST_LIBC),) | ||
PROGNAME += cmocka_wasm_test_libc | ||
MAINSRC += libc_test.c | ||
endif | ||
|
||
# If any test case enabled, then enable the test module | ||
|
||
ifneq ($(PROGNAME),) | ||
ifneq ($(MAINSRC),) | ||
MODULE = y | ||
endif | ||
endif | ||
|
||
generated: | ||
mkdir -p generated | ||
|
||
# Rule to compile the libc proxy module | ||
|
||
generated/libc.wasm: proxy/libc.c generated | ||
$(WASI_SDK_PATH)/bin/clang --target=wasm32 -O3 -flto --sysroot=$(APPDIR)/frameworks/runtimes/wasm/vela-sysroot -nostdlib -z stack-size=4096 -Wl,--initial-memory=65536 -o generated/libc.wasm proxy/libc.c -Wl,--no-entry -Wl,--export-all -Wl,--allow-undefined | ||
|
||
generated/libc_wasm_array.c: generated/libc.wasm | ||
xxd -i $< > $@ | ||
|
||
context:: generated/libc_wasm_array.c | ||
|
||
distclean:: | ||
$(call DELDIR, generated) | ||
|
||
include $(APPDIR)/Application.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Introduction | ||
|
||
This directory contains the test cases for the libc API provided by Wasm runtimes. | ||
|
||
# Requirements | ||
|
||
1. **Test Cases**: The test cases should cover all the built-in libc functions of WAMR and addons implemented by ourselves. | ||
2. **Framework**: We should use CMocka as the test framework. | ||
3. **Execution**: Should have a shell command in nsh to run all the test cases. | ||
|
||
# Design | ||
|
||
For this task, we should call the Wasm runtime API to call libc functions and compare the result with expected value. But we can not directly call the internal function of Wasm runtime because it is not exposed directly. | ||
So we need a proxy module that could be able to expose the internal APIs of Wasm runtime to us. | ||
|
||
# Implementation | ||
|
||
In order to test the API from https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c, we need to create a proxy module that contains some proxy functions like this: | ||
```c | ||
void *malloc_proxy(size_t size) { | ||
return malloc(size); | ||
} | ||
``` | ||
|
||
Then we can call the malloc function in Wasm runtime through `malloc_proxy` and compare the result with expected value in native code. | ||
|
||
# Proxy Module | ||
|
||
The source code of proxy module is located at: proxy/libc.c | ||
|
||
You can use this command to build the proxy module: | ||
```sh | ||
$(WASI_SDK_PATH)/bin/clang --target=wasm32 -O3 -flto --sysroot=PWD/frameworks/runtimes/wasm/vela-sysroot -nostdlib -z stack-size=4096 -Wl,--initial-memory=65536 -o proxy/libc.wasm proxy/libc.c -Wl,--no-entry -Wl,--export-all | ||
``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's creae a new patch to change vela-sysroot to sysroot