提交 b8bc27e5 编写于 作者: W wangyulie

优化用例

Signed-off-by: Nwangyulie <wanglieyu@126.com>
上级 63c5763c
......@@ -252,8 +252,6 @@ static napi_value SubmitQueueFfrtTask(napi_env env, napi_callback_info info)
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_cancel(task1);
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,
......@@ -269,13 +267,63 @@ static napi_value SubmitQueueFfrtTask(napi_env env, napi_callback_info info)
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_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);
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);
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;
}
EXTERN_C_START
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 }
{ "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 }
};
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
......@@ -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('ActsAbilityTest', function () {
describe('ActsFfrtTest', 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,15 +36,35 @@ 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('assertContain',0, function () {
it('submitSimpleFfrtTask',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);
expect(flag2).assertEqual(3);
expect(flag3).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);
})
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册