提交 0a4c273f 编写于 作者: W wangyulie

修改ffrt的xts模型

Signed-off-by: Nwangyulie <wanglieyu@126.com>
上级 f4a1c7d8
/node_modules
/oh_modules
/local.properties
/.idea
**/build
/.hvigor
.cxx
/.clangd
/.clang-format
/.clang-tidy
**/.test
\ No newline at end of file
{
"app": {
"bundleName": "com.actsffrt.napitest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
},
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
{
"app": {
"bundleName": "com.actsffrt.napitest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}
......@@ -2,7 +2,7 @@
"string": [
{
"name": "app_name",
"value": "FfrtTest"
"value": "MyApplication"
}
]
}
......@@ -10,20 +10,32 @@
# 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.
import("//build/ohos.gni")
import("//test/xts/tools/build/suite.gni")
ohos_app_assist_suite("acts_ffrt_main") {
testonly = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsFfrtMainTest"
part_name = "ffrt"
subsystem_name = "resourceschedule"
}
ohos_js_app_suite("resourceschedule_ffrt_js_test") {
test_hap = true
testonly = true
ohos_js_hap_suite("resourceschedule_ffrt_js_test") {
hap_profile = "./src/main/module.json"
deps = [
":windowStage_js_assets",
":windowStage_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsFfrtNativeTest"
part_name = "ffrt"
subsystem_name = "resourceschedule"
deps = [ ":acts_ffrt_main" ]
part_name = "ffrt"
shared_libraries = [ "./src/main/cpp:ffrtndk" ]
}
ohos_app_scope("windowStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("windowStage_js_assets") {
source_dir = "./src/main/ets"
}
ohos_resources("windowStage_resources") {
sources = [ "./src/main/resources" ]
deps = [ ":windowStage_app_profile" ]
hap_profile = "./src/main/module.json"
}
......@@ -11,8 +11,7 @@
"kits": [
{
"test-file-name": [
"ActsFfrtNativeTest.hap",
"ActsFfrtMainTest.hap"
"ActsFfrtNativeTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
{
"app": {
"signingConfigs": [],
"compileSdkVersion": 10,
"compatibleSdkVersion": 10,
"products": [
{
"name": "default",
"signingConfig": "default",
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
\ No newline at end of file
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
{
"apiType": 'stageMode',
"buildOption": {
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt",
"arguments": "",
"cppFlags": "",
}
},
"targets": [
{
"name": "default",
},
{
"name": "ohosTest",
}
]
}
\ No newline at end of file
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
export { hapTasks } from '@ohos/hvigor-ohos-plugin';
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
{
"license": "",
"devDependencies": {
"@types/libffrtndk.so": "file:./src/main/cpp/types/libffrtndk"
},
"author": "",
"name": "entry",
"description": "Please describe the basic information.",
"main": "",
"version": "1.0.0",
"dependencies": {}
}
export const add: (a: number, b: number) => number;
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
{
"name": "libentry.so",
"types": "./index.d.ts",
"version": "",
"description": "Please describe the basic information."
}
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
{
"name": "libffrtndk.so",
"types": "./index.d.ts",
"version": "",
"description": "Please describe the basic information."
}
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
import UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}
onDestroy() {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
};
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', 5);
})
}
.width('100%')
}
.height('100%')
}
}
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"default",
"tablet"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ts",
"description": "$string:EntryAbility_desc",
"icon": "$media:icon",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
]
}
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "label"
}
]
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
{
"hvigorVersion": "2.4.2",
"dependencies": {
"@ohos/hvigor-ohos-plugin": "2.4.2"
}
}
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
export { appTasks } from '@ohos/hvigor-ohos-plugin';
\ No newline at end of file
#!/bin/bash
# Copyright (c) 2022 Huawei Device Co., Ltd.
# 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.
# ----------------------------------------------------------------------------
# Hvigor startup script, version 1.0.0
#
# Required ENV vars:
# ------------------
# NODE_HOME - location of a Node home dir
# or
# Add /usr/local/nodejs/bin to the PATH environment variable
# ----------------------------------------------------------------------------
HVIGOR_APP_HOME=$(dirname $(readlink -f $0))
HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
warn() {
echo ""
echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
error() {
echo ""
echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
fail() {
error "$@"
exit 1
}
# Determine node to start hvigor wrapper script
if [ -n "${NODE_HOME}" ];then
EXECUTABLE_NODE="${NODE_HOME}/bin/node"
if [ ! -x "$EXECUTABLE_NODE" ];then
fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed"
fi
else
EXECUTABLE_NODE="node"
which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
fi
# Check hvigor wrapper script
if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
fi
# start hvigor-wrapper script
exec "${EXECUTABLE_NODE}" \
"${HVIGOR_WRAPPER_SCRIPT}" "$@"
@rem Copyright (c) 2023 Huawei Device Co., Ltd.
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem http://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Hvigor startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js
set NODE_EXE=node.exe
goto start
:start
@rem Find node.exe
if defined NODE_HOME goto findNodeFromNodeHome
%NODE_EXE% --version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:findNodeFromNodeHome
set NODE_HOME=%NODE_HOME:"=%
set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE%
if exist "%NODE_EXE_PATH%" goto execute
echo.
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
echo.
echo Please set the NODE_HOME variable in your environment to match the
echo location of your NodeJs installation.
goto fail
:execute
@rem Execute hvigor
"%NODE_EXE%" %WRAPPER_MODULE_PATH% %*
if "%ERRORLEVEL%" == "0" goto hvigorwEnd
:fail
exit /b 1
:hvigorwEnd
if "%OS%" == "Windows_NT" endlocal
:end
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
{
"license": "",
"devDependencies": {
"@ohos/hypium": "1.0.6"
},
"author": "",
"name": "ffrttest",
"description": "Please describe the basic information.",
"main": "",
"version": "1.0.0",
"dependencies": {}
}
# Copyright (C) 2022 Huawei Device Co., Ltd.
# 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.
import("//build/config/ohos/config.gni")
import("//build/ohos.gni")
import("//foundation/arkui/napi/napi.gni")
config("config") {
visibility = [ ":*" ]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Wunused-variable",
]
}
config("public_config") {
}
ohos_shared_library("ffrtndk") {
sources = [ "./ffrtndk.cpp" ]
if (!(product_name == "m40")) {
libs = [ rebase_path(libcxx_ndk_shared_file) ]
}
include_dirs = [
"./",
"//foundation/resourceschedule/ffrt/interfaces/kits",
]
configs = [ ":config" ]
subsystem_name = "resourceschedule"
part_name = "ffrt"
external_deps = [
"hilog:libhilog",
"napi:ace_napi",
]
deps = [
"//foundation/resourceschedule/ffrt:ffrt_ndk",
"//foundation/resourceschedule/ffrt/interfaces/kits:libffrt_ndk",
]
output_extension = "so"
}
# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)
project(FfrtTest)
project(MyApplication)
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
......
......@@ -14,18 +14,18 @@
*/
#include "napi/native_api.h"
#include "hilog/log.h"
#include "ffrt/task.h"
#include "ffrt/type_def.h"
#include "ffrt/condition_variable.h"
#include "ffrt/mutex.h"
#include "ffrt/queue.h"
#include "ffrt/sleep.h"
#include "c/task.h"
#include "c/type_def.h"
#include "c/condition_variable.h"
#include "c/mutex.h"
#include "c/queue.h"
#include "c/sleep.h"
#include <string>
#include <unistd.h>
void MyPrint(void* arg)
void my_print(void* arg)
{
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "%{public}s", "hello ffrt\n");
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "%{public}s", "hello ffrt\n");
}
void OnePlusForTest(void* arg)
......@@ -48,17 +48,17 @@ typedef struct {
ffrt_function_t func;
ffrt_function_t after_func;
void* arg;
} CFunction;
} c_function;
typedef struct {
ffrt_cond_t* cond;
int* a;
ffrt_mutex_t* lock_;
} FfrtTuple;
} tuple;
void Func1(void* arg)
void func1(void* arg)
{
FfrtTuple* t = (FfrtTuple*)arg;
tuple* t = (tuple*)arg;
int ret = ffrt_mutex_lock(t->lock_);
if (ret != ffrt_success) {
printf("error\n");
......@@ -81,9 +81,9 @@ void Func1(void* arg)
printf("a = %d", *(t->a));
}
void Func2(void* arg)
void func2(void* arg)
{
FfrtTuple* t = (FfrtTuple*)arg;
tuple* t = (tuple*)arg;
int ret = ffrt_mutex_lock(t->lock_);
if (ret != ffrt_success) {
printf("error\n");
......@@ -99,9 +99,9 @@ void Func2(void* arg)
}
}
void Func3(void* arg)
void func3(void* arg)
{
FfrtTuple* t = (FfrtTuple*)arg;
tuple* t = (tuple*)arg;
int ret = ffrt_mutex_trylock(t->lock_);
if (ret != ffrt_success) {
printf("error\n");
......@@ -127,17 +127,17 @@ void Func3(void* arg)
printf("a = %d", *(t->a));
}
static void FfrtExecFunctionWrapper(void* t)
static void ffrt_exec_function_wrapper(void* t)
{
CFunction* f = (CFunction*)t;
c_function* f = (c_function*)t;
if (f->func) {
f->func(f->arg);
}
}
static void FfrtDestroyFunctionWrapper(void* t)
static void ffrt_destroy_function_wrapper(void* t)
{
CFunction* f = (CFunction*)t;
c_function* f = (c_function*)t;
if (f->after_func) {
f->after_func(f->arg);
}
......@@ -147,30 +147,30 @@ static void FfrtDestroyFunctionWrapper(void* t)
static inline ffrt_function_header_t* ffrt_create_function_wrapper(const ffrt_function_t func,
const ffrt_function_t after_func, void* arg, ffrt_function_kind_t kind_t = ffrt_function_kind_general)
{
FFRT_STATIC_ASSERT(sizeof(CFunction) <= ffrt_auto_managed_function_storage_size,
FFRT_STATIC_ASSERT(sizeof(c_function) <= ffrt_auto_managed_function_storage_size,
size_of_function_must_be_less_than_ffrt_auto_managed_function_storage_size);
CFunction* f = (CFunction*)ffrt_alloc_auto_managed_function_storage_base(kind_t);
f->header.exec = FfrtExecFunctionWrapper;
f->header.destroy = FfrtDestroyFunctionWrapper;
c_function* f = (c_function*)ffrt_alloc_auto_managed_function_storage_base(kind_t);
f->header.exec = ffrt_exec_function_wrapper;
f->header.destroy = ffrt_destroy_function_wrapper;
f->func = func;
f->after_func = after_func;
f->arg = arg;
return (ffrt_function_header_t*)f;
}
static inline void ffrt_submit_c(ffrt_function_t func, void* arg,
const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr)
static inline void ffrt_submit_c(ffrt_function_t func, const ffrt_function_t after_func,
void* arg, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr)
{
ffrt_submit_base(ffrt_create_function_wrapper(func, NULL, arg), in_deps, out_deps, attr);
ffrt_submit_base(ffrt_create_function_wrapper(func, after_func, arg), in_deps, out_deps, attr);
}
static inline ffrt_task_handle_t ffrt_submit_h_c(ffrt_function_t func, void* arg,
const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr)
static inline ffrt_task_handle_t ffrt_submit_h_c(ffrt_function_t func, const ffrt_function_t after_func,
void* arg, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr)
{
return ffrt_submit_h_base(ffrt_create_function_wrapper(func, NULL, arg), in_deps, out_deps, attr);
return ffrt_submit_h_base(ffrt_create_function_wrapper(func, after_func, arg), in_deps, out_deps, attr);
}
void FfrtCvTask(void* arg)
void ffrt_cv_task(void* arg)
{
int* a = (int*) arg;
ffrt_cond_t cond;
......@@ -179,14 +179,14 @@ void FfrtCvTask(void* arg)
printf("error\n");
}
ffrt_mutex_t lock_;
FfrtTuple t = {&cond, a, &lock_};
tuple t = {&cond, a, &lock_};
ret = ffrt_mutex_init(&lock_, NULL);
if (ret != ffrt_success) {
printf("error\n");
}
ffrt_submit_c(Func1, &t, NULL, NULL, NULL);
ffrt_submit_c(Func2, &t, NULL, NULL, NULL);
ffrt_submit_c(Func3, &t, NULL, NULL, NULL);
ffrt_submit_c(func1, NULL, &t, NULL, NULL, NULL);
ffrt_submit_c(func2, NULL, &t, NULL, NULL, NULL);
ffrt_submit_c(func3, NULL, &t, NULL, NULL, NULL);
ffrt_wait();
ffrt_cond_destroy(&cond);
ffrt_mutex_destroy(&lock_);
......@@ -194,23 +194,23 @@ void FfrtCvTask(void* arg)
static napi_value SubmitSimpleFfrtTask(napi_env env, napi_callback_info info)
{
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "%{public}s", "ffrt start\n");
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "%{public}s", "ffrt start\n");
ffrt_task_attr_t attr;
ffrt_task_attr_init(&attr);
ffrt_task_attr_set_qos(&attr, static_cast<ffrt_qos_t>(ffrt_qos_background));
ffrt_task_attr_set_name(&attr, "ffrt_testA");
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "task delay is %{public}d", ffrt_task_attr_get_delay(&attr));
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "task name is %{public}s", ffrt_task_attr_get_name(&attr));
ffrt_task_attr_get_delay(&attr);
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "task name is %{public}s", ffrt_task_attr_get_name(&attr));
ffrt_task_attr_set_delay(&attr, 1000);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "task delay2 is %{public}d", ffrt_task_attr_get_delay(&attr));
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "qos is %{public}d", ffrt_task_attr_get_qos(&attr));
ffrt_task_attr_get_delay(&attr);
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "qos is %{public}d", ffrt_task_attr_get_qos(&attr));
ffrt_task_attr_set_qos(&attr, static_cast<ffrt_qos_t>(ffrt_qos_user_initiated));
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "qos2 is %{public}d", ffrt_task_attr_get_qos(&attr));
ffrt_submit_c(MyPrint, NULL, NULL, NULL, &attr);
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "qos2 is %{public}d", ffrt_task_attr_get_qos(&attr));
ffrt_submit_c(my_print, NULL, NULL, NULL, NULL, &attr);
int result = ffrt_this_task_update_qos(static_cast<ffrt_qos_t>(ffrt_qos_default));
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "update_qos result is %{public}d", result);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "qos3 is %{public}d", ffrt_task_attr_get_qos(&attr));
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "task id is %{public}d", ffrt_this_task_get_id());
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "update_qos result is %{public}d", result);
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "qos3 is %{public}d", ffrt_task_attr_get_qos(&attr));
ffrt_this_task_get_id();
ffrt_usleep(10000);
ffrt_yield();
ffrt_task_attr_destroy(&attr);
......@@ -223,11 +223,11 @@ static napi_value SubmitSimpleFfrtTask(napi_env env, napi_callback_info info)
static napi_value SubmitCondFfrtTask(napi_env env, napi_callback_info info)
{
int a = 0;
ffrt_submit_c(FfrtCvTask, &a, NULL, NULL, NULL);
ffrt_task_handle_t task1 = ffrt_submit_h_c(MyPrint, NULL, NULL, NULL, NULL);
ffrt_submit_c(ffrt_cv_task, NULL, &a, NULL, NULL, NULL);
ffrt_task_handle_t task1 = ffrt_submit_h_c(my_print, NULL, NULL, NULL, NULL, NULL);
ffrt_wait_deps(nullptr);
ffrt_wait();
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "cond task a is %{public}d", a);
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "cond task a is %{public}d", a);
napi_value flag = nullptr;
napi_create_double(env, a, &flag);
ffrt_task_handle_destroy(task1);
......@@ -241,72 +241,20 @@ static napi_value SubmitQueueFfrtTask(napi_env env, napi_callback_info info)
ffrt_queue_attr_t queue_attr;
(void)ffrt_queue_attr_init(&queue_attr);
ffrt_queue_attr_set_qos(&queue_attr, ffrt_qos_default);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "queue task qos is %{public}d",
ffrt_queue_attr_get_qos(&queue_attr));
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "queue task qos is %{public}d", ffrt_queue_attr_get_qos(&queue_attr));
ffrt_queue_attr_set_timeout(&queue_attr, 10000);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "queue task time is %{public}d",
ffrt_queue_attr_get_timeout(&queue_attr));
ffrt_queue_attr_set_callback(&queue_attr,
ffrt_create_function_wrapper(OnePlusForTest, NULL, &b, ffrt_function_kind_queue));
ffrt_queue_attr_get_timeout(&queue_attr);
ffrt_queue_attr_set_callback(&queue_attr, ffrt_create_function_wrapper(OnePlusForTest, NULL, &b, ffrt_function_kind_queue));
ffrt_queue_attr_get_callback(&queue_attr);
ffrt_queue_t queue_handle = ffrt_queue_create(ffrt_queue_serial, "test_queue", &queue_attr);
ffrt_task_handle_t task1 = ffrt_queue_submit_h(queue_handle,
ffrt_create_function_wrapper(OnePlusForTest, NULL, &a, ffrt_function_kind_queue), nullptr);
ffrt_queue_submit(queue_handle,
ffrt_create_function_wrapper(MulipleForTest, nullptr, &a, ffrt_function_kind_queue), nullptr);
ffrt_queue_submit(queue_handle,
ffrt_create_function_wrapper(SubForTest, nullptr, &a, ffrt_function_kind_queue), nullptr);
sleep(2);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "queue task a is %{public}d", a);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "queue task b is %{public}d", b);
napi_value flag = nullptr;
napi_create_double(env, a, &flag);
ffrt_task_handle_destroy(task1);
ffrt_queue_attr_destroy(&queue_attr);
ffrt_queue_destroy(queue_handle);
return flag;
}
static napi_value CancelQueueFfrtTask(napi_env env, napi_callback_info info)
{
int a = 0;
int b = 0;
ffrt_queue_attr_t queue_attr;
(void)ffrt_queue_attr_init(&queue_attr);
ffrt_queue_attr_set_qos(&queue_attr, ffrt_qos_default);
ffrt_queue_attr_set_callback(&queue_attr,
ffrt_create_function_wrapper(OnePlusForTest, NULL, &b, ffrt_function_kind_queue));
ffrt_queue_t queue_handle = ffrt_queue_create(ffrt_queue_serial, "test_queue", &queue_attr);
ffrt_task_handle_t task1 = ffrt_queue_submit_h(queue_handle,
ffrt_create_function_wrapper(OnePlusForTest, NULL, &a, ffrt_function_kind_queue), nullptr);
ffrt_task_handle_t task1 = ffrt_queue_submit_h(queue_handle, ffrt_create_function_wrapper(OnePlusForTest, NULL, &a, ffrt_function_kind_queue), nullptr);
ffrt_queue_cancel(task1);
sleep(2);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "cancel queue task a is %{public}d", a);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "cancel queue task b is %{public}d", b);
napi_value flag = nullptr;
napi_create_double(env, a, &flag);
ffrt_task_handle_destroy(task1);
ffrt_queue_attr_destroy(&queue_attr);
ffrt_queue_destroy(queue_handle);
return flag;
}
static napi_value WaitQueueFfrtTask(napi_env env, napi_callback_info info)
{
int a = 0;
int b = 0;
ffrt_queue_attr_t queue_attr;
(void)ffrt_queue_attr_init(&queue_attr);
ffrt_queue_attr_set_qos(&queue_attr, ffrt_qos_default);
ffrt_queue_attr_set_callback(&queue_attr,
ffrt_create_function_wrapper(OnePlusForTest, NULL, &b, ffrt_function_kind_queue));
ffrt_queue_t queue_handle = ffrt_queue_create(ffrt_queue_serial, "test_queue", &queue_attr);
ffrt_task_handle_t task1 = ffrt_queue_submit_h(queue_handle,
ffrt_create_function_wrapper(OnePlusForTest, NULL, &a, ffrt_function_kind_queue), nullptr);
ffrt_queue_wait(task1);
ffrt_queue_submit(queue_handle, ffrt_create_function_wrapper(MulipleForTest, nullptr, &a, ffrt_function_kind_queue), nullptr);
ffrt_queue_submit(queue_handle, ffrt_create_function_wrapper(SubForTest, nullptr, &a, ffrt_function_kind_queue), nullptr);
sleep(2);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "wait queue task a is %{public}d", a);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "testFFRT", "wait queue task b is %{public}d", b);
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "queue task a is %{public}d", a);
HiLogPrint(LOG_APP, LOG_INFO, 1, "testFFRT", "queue task b is %{public}d", b);
napi_value flag = nullptr;
napi_create_double(env, a, &flag);
ffrt_task_handle_destroy(task1);
......@@ -321,9 +269,7 @@ static napi_value Init(napi_env env, napi_value exports)
napi_property_descriptor desc[] = {
{ "submitSimpleFfrtTask", nullptr, SubmitSimpleFfrtTask, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "submitCondFfrtTask", nullptr, SubmitCondFfrtTask, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "submitQueueFfrtTask", nullptr, SubmitQueueFfrtTask, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "cancelQueueFfrtTask", nullptr, CancelQueueFfrtTask, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "waitQueueFfrtTask", nullptr, WaitQueueFfrtTask, nullptr, nullptr, nullptr, napi_default, nullptr }
{ "submitQueueFfrtTask", nullptr, SubmitQueueFfrtTask, nullptr, nullptr, nullptr, napi_default, nullptr }
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
return exports;
......
export const submitSimpleFfrtTask: () => number;
export const submitCondFfrtTask: () => number;
export const submitQueueFfrtTask: () => number;
export const cancelQueueFfrtTask: () => number;
export const waitQueueFfrtTask: () => number;
\ No newline at end of file
export const submitQueueFfrtTask: () => number;
\ No newline at end of file
{
"name": "libffrtndk.so",
"types": "./index.d.ts",
"version": "",
"description": "Please describe the basic information."
}
\ No newline at end of file
......@@ -38,7 +38,7 @@ export default class TestAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
windowStage.loadContent('testability/pages/Index', (err, data) => {
windowStage.loadContent('TestAbility/pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
......
......@@ -16,7 +16,7 @@ import hilog from '@ohos.hilog';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import ffrtndk from 'libffrtndk.so';
export default function ffrtTest() {
describe('ActsFfrtTest', function () {
describe('ActsAbilityTest', function () {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () {
// Presets an action, which is performed only once before all test cases of the test suite start.
......@@ -36,35 +36,15 @@ export default function ffrtTest() {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('submitSimpleFfrtTask',0, function () {
it('assertContain',0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
var flag = ffrtndk.submitSimpleFfrtTask();
var flag2 = ffrtndk.submitCondFfrtTask();
var flag3 = ffrtndk.submitQueueFfrtTask();
expect(flag).assertEqual(1);
})
it('submitCondFfrtTask',0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
var flag = ffrtndk.submitCondFfrtTask();
expect(flag).assertEqual(3);
})
it('submitQueueFfrtTask',0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
var flag = ffrtndk.submitQueueFfrtTask();
expect(flag).assertEqual(9);
})
it('cancelQueueFfrtTask',0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
var flag = ffrtndk.cancelQueueFfrtTask();
expect(flag).assertEqual(0);
})
it('waitQueueFfrtTask',0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
var flag = ffrtndk.waitQueueFfrtTask();
expect(flag).assertEqual(1);
expect(flag2).assertEqual(3);
expect(flag3).assertEqual(-1);
})
})
}
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* 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.
*/
{
"module": {
"name": "entry_test",
......@@ -19,8 +5,6 @@
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"default",
"tablet",
"phone"
],
"deliveryWithInstall": true,
......@@ -29,7 +13,7 @@
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/testability/TestAbility.ets",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册