Description: add dinput

Match-id-baa4cab7681e213ab809335dc283e618fbc196e0
This commit is contained in:
xxxx
2022-05-17 15:06:49 +08:00
parent 714d72661b
commit 41d96f51f7
28 changed files with 1848 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
* 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.
-->
<info>
<process>dhardware</process>
<systemability> <!-- Declare a sytem ability and its profile -->
<name>4809</name> <!-- Declare the name of system ability -->
<libpath>libdinput_source.z.so</libpath> <!-- Declare the path of .so file which includes the system ability; Note: 1 .so file can have 1 to N system abilities. -->
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on, using ";" as separator among names. If there are dependencies, it needs to check if all those dependencies are avliable in service manager before starting the system ability. -->
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are avaliable before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
<distributed>true</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not. -->
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
</systemability>
</info>
+27
View File
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
* 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.
-->
<info>
<process>dhardware</process>
<systemability> <!-- Declare a sytem ability and its profile -->
<name>4810</name> <!-- Declare the name of system ability -->
<libpath>libdinput_sink.z.so</libpath> <!-- Declare the path of .so file which includes the system ability; Note: 1 .so file can have 1 to N system abilities. -->
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on, using ";" as separator among names. If there are dependencies, it needs to check if all those dependencies are avliable in service manager before starting the system ability. -->
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are avaliable before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
<distributed>true</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not. -->
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
</systemability>
</info>
+32
View File
@@ -0,0 +1,32 @@
# 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("//build/ohos.gni")
import("//drivers/adapter/uhdf2/uhdf.gni")
import("//build/ohos/sa_profile/sa_profile.gni")
ohos_sa_profile("distributed_input_source_sa_profile") {
sources = [
"4809.xml"
]
part_name = "distributed_input"
}
ohos_sa_profile("distributed_input_sink_sa_profile") {
sources = [
"4810.xml"
]
part_name = "distributed_input"
}
+21
View File
@@ -0,0 +1,21 @@
# 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.
group("test") {
testonly = true
deps = [
"system:system",
"fuzztest:fuzztest",
]
}
+23
View File
@@ -0,0 +1,23 @@
# 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.
group("fuzztest") {
testonly = true
deps = [
"distributedinputkit_fuzzer:fuzztest",
"distributedinputclient_fuzzer:fuzztest",
"distributedinputsinktransport_fuzzer:fuzztest",
"distributedinputsourcetransport_fuzzer:fuzztest",
]
}
@@ -0,0 +1,95 @@
# 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.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("//foundation/distributedhardware/distributedinput/distributedinput.gni")
##############################fuzztest##########################################
ohos_fuzztest("DistributedInputClientFuzzTest") {
module_out_path = "distributedinput_stander/system"
# fuzz_config_file = "//foundation/distributedhardware/distributedinput/test/fuzztest/distributedinputclient_fuzzer"
include_dirs = [
"include",
"${distributedinput_path}/interfaces/inner_kits/include",
"${distributedinput_path}/interfaces/ipc/include",
"${distributedinput_path}/services/source/sourcemanager/include",
"${distributedinput_path}/services/sink/sinkmanager/include",
"${distributedinput_path}/frameworks/include",
"${distributedinput_path}/sourcehandler/include",
"${distributedinput_path}/sinkhandler/include",
"${distributedinput_path}/inputdevicehandler/include",
"//foundation/distributedhardware/distributedhardwarefwk/common/utils/include",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"${service_common}/include",
"${common_path}/include",
"//third_party/json/include",
"//foundation/distributedhardware/distributedhardwarefwk/common/log/include",
"//foundation/distributedhardware/distributedhardwarefwk/common/utils/include",
"//foundation/distributedhardware/distributedhardwarefwk/utils/include/log",
"//foundation/distributedhardware/distributedhardwarefwk/utils/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"distributed_input_client_fuzzer.cpp",
]
deps = [
"${distributedinput_path}/interfaces/inner_kits:libdinput_sdk",
"${distributedinput_path}/services/source/sourcemanager:libdinput_source",
"${distributedinput_path}/services/source/inputinject:libdinput_inject",
"${distributedinput_path}/services/source/transport:libdinput_source_trans",
"${distributedinput_path}/services/sink/sinkmanager:libdinput_sink",
"${distributedinput_path}/services/sink/inputcollector:libdinput_collector",
"${distributedinput_path}/services/sink/transport:libdinput_sink_trans",
"${distributedinput_path}/sourcehandler:libdinput_source_handler",
"${distributedinput_path}/sinkhandler:libdinput_sink_handler",
"${distributedinput_path}/inputdevicehandler:libdinput_handler",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//utils/native/base:utils",
]
external_deps = [
"dsoftbus_standard:softbus_client",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"hiviewdfx_hilog_native:libhilog",
"samgr_standard:samgr_proxy",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DistributedInputClientFuzzTest\"",
"LOG_DOMAIN=0xD004100",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = [
":DistributedInputClientFuzzTest",
]
}
###############################################################################
@@ -0,0 +1 @@
FUZZ
@@ -0,0 +1,86 @@
/*
* 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.
*/
#include "distributed_input_client_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iostream>
#include <refbase.h>
#include <thread>
#include "constants_dinput.h"
#include "distributed_input_handler.h"
#include "distributed_input_kit.h"
#include "distributed_input_sink_handler.h"
#include "distributed_input_source_handler.h"
#include "i_distributed_sink_input.h"
#include "i_distributed_source_input.h"
namespace OHOS {
namespace DistributedHardware {
class TestRegisterInputCallback : public OHOS::DistributedHardware::RegisterCallback {
public:
TestRegisterInputCallback() = default;
virtual ~TestRegisterInputCallback() = default;
virtual int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status,
const std::string &data) override {
return 0;
}
};
class TestUnregisterInputCallback : public OHOS::DistributedHardware::UnregisterCallback {
public:
TestUnregisterInputCallback() = default;
virtual ~TestUnregisterInputCallback() = default;
virtual int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status,
const std::string &data) override {
return 0;
}
};
void RegisterDistributedHardwareFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
std::string rDevId(reinterpret_cast<const char*>(data), size);
std::string rDhId(reinterpret_cast<const char*>(data), size);
std::string version(reinterpret_cast<const char*>(data), size);
std::string attrs(reinterpret_cast<const char*>(data), size);
EnableParam enableParam;
enableParam.version = version;
enableParam.attrs = attrs;
std::shared_ptr<TestRegisterInputCallback> registerCb = std::make_shared<TestRegisterInputCallback>();
std::shared_ptr<TestUnregisterInputCallback> unregisterCb = std::make_shared<TestUnregisterInputCallback>();
int32_t ret = DistributedInput::DistributedInputSourceHandler::GetInstance().RegisterDistributedHardware(
rDevId, rDhId, enableParam, registerCb);
ret = DistributedInput::DistributedInputSourceHandler::GetInstance().UnregisterDistributedHardware(
rDevId, rDhId, unregisterCb);
}
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DistributedHardware::RegisterDistributedHardwareFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,23 @@
/*
* 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.
*/
#ifndef DISTRIBUTED_INPUT_CLIENT_FUZZER_H
#define DISTRIBUTED_INPUT_CLIENT_FUZZER_H
#define FUZZ_PROJECT_NAME "distributedinputclient_fuzzer"
#endif // DISTRIBUTED_INPUT_CLIENT_FUZZER_H
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -0,0 +1,95 @@
# 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.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("//foundation/distributedhardware/distributedinput/distributedinput.gni")
##############################fuzztest##########################################
ohos_fuzztest("DistributedInputKitFuzzTest") {
module_out_path = "distributedinput_stander/system"
# fuzz_config_file = "//foundation/distributedhardware/distributedinput/test/fuzztest/distributedinputkit_fuzzer"
include_dirs = [
"include",
"${distributedinput_path}/interfaces/inner_kits/include",
"${distributedinput_path}/interfaces/ipc/include",
"${distributedinput_path}/services/source/sourcemanager/include",
"${distributedinput_path}/services/sink/sinkmanager/include",
"${distributedinput_path}/frameworks/include",
"${distributedinput_path}/sourcehandler/include",
"${distributedinput_path}/sinkhandler/include",
"${distributedinput_path}/inputdevicehandler/include",
"//foundation/distributedhardware/distributedhardwarefwk/common/utils/include",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"${service_common}/include",
"${common_path}/include",
"//third_party/json/include",
"//foundation/distributedhardware/distributedhardwarefwk/common/log/include",
"//foundation/distributedhardware/distributedhardwarefwk/common/utils/include",
"//foundation/distributedhardware/distributedhardwarefwk/utils/include/log",
"//foundation/distributedhardware/distributedhardwarefwk/utils/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"distributed_input_kit_fuzzer.cpp",
]
deps = [
"${distributedinput_path}/interfaces/inner_kits:libdinput_sdk",
"${distributedinput_path}/services/source/sourcemanager:libdinput_source",
"${distributedinput_path}/services/source/inputinject:libdinput_inject",
"${distributedinput_path}/services/source/transport:libdinput_source_trans",
"${distributedinput_path}/services/sink/sinkmanager:libdinput_sink",
"${distributedinput_path}/services/sink/inputcollector:libdinput_collector",
"${distributedinput_path}/services/sink/transport:libdinput_sink_trans",
"${distributedinput_path}/sourcehandler:libdinput_source_handler",
"${distributedinput_path}/sinkhandler:libdinput_sink_handler",
"${distributedinput_path}/inputdevicehandler:libdinput_handler",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//utils/native/base:utils",
]
external_deps = [
"dsoftbus_standard:softbus_client",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"hiviewdfx_hilog_native:libhilog",
"samgr_standard:samgr_proxy",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DistributedInputKitFuzzTest\"",
"LOG_DOMAIN=0xD004100",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = [
":DistributedInputKitFuzzTest",
]
}
###############################################################################
@@ -0,0 +1 @@
FUZZ
@@ -0,0 +1,129 @@
/*
* 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.
*/
#include "distributed_input_kit_fuzzer.h"
#include <cstddef>
#include <cstdint>
#include "i_distributed_sink_input.h"
#include "i_distributed_source_input.h"
#include "distributed_input_kit.h"
#include "distributed_input_sink_handler.h"
#include "distributed_input_source_handler.h"
#include "distributed_input_handler.h"
#include "prepare_d_input_call_back_stub.h"
#include "unprepare_d_input_call_back_stub.h"
#include "start_d_input_call_back_stub.h"
#include "stop_d_input_call_back_stub.h"
#include "constants_dinput.h"
#include <thread>
#include <functional>
#include <iostream>
#include <refbase.h>
namespace OHOS {
namespace DistributedHardware {
class TestPrepareDInputCallback :
public OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub {
public:
TestPrepareDInputCallback() = default;
virtual ~TestPrepareDInputCallback() = default;
void OnResult(const std::string& deviceId, const int32_t& status) {};
};
class TestUnprepareDInputCallback :
public OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub {
public:
TestUnprepareDInputCallback() = default;
virtual ~TestUnprepareDInputCallback() = default;
void OnResult(const std::string& deviceId, const int32_t& status) {};
};
class TestStartDInputCallback :
public OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub {
public:
void OnResult(const std::string& devId, const uint32_t& inputTypes, const int32_t& status) {};
};
class TestStopDInputCallback :
public OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub {
public:
TestStopDInputCallback() = default;
virtual ~TestStopDInputCallback() = default;
void OnResult(const std::string& devId, const uint32_t& inputTypes, const int32_t& status) {};
};
void PrepareInputFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
std::string networkId(reinterpret_cast<const char*>(data), size);
OHOS::sptr<TestPrepareDInputCallback> prepareCb = new(std::nothrow) TestPrepareDInputCallback();
OHOS::sptr<TestUnprepareDInputCallback> unprepareCb = new(std::nothrow) TestUnprepareDInputCallback();
DistributedInput::DistributedInputKit::PrepareRemoteInput(networkId, prepareCb);
DistributedInput::DistributedInputKit::UnprepareRemoteInput(networkId, unprepareCb);
}
void StartRemoteInputFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
std::string dhId(reinterpret_cast<const char*>(data), size);
uint32_t inputTypes = *(reinterpret_cast<const uint32_t*>(data));
OHOS::sptr<TestStartDInputCallback> startCb = new(std::nothrow) TestStartDInputCallback();
OHOS::sptr<TestStopDInputCallback> stopCb = new(std::nothrow) TestStopDInputCallback();
DistributedInput::DistributedInputKit::StartRemoteInput(dhId, inputTypes, startCb);
DistributedInput::DistributedInputKit::StopRemoteInput(dhId, inputTypes, stopCb);
}
void IsNeedFilterOutFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
std::string deviceId(reinterpret_cast<const char*>(data), size);
int32_t pressedKey = *(reinterpret_cast<const int32_t*>(data));
int32_t keyCode = *(reinterpret_cast<const int32_t*>(data));
int32_t keyAction = *(reinterpret_cast<const int32_t*>(data));
DistributedInput::BusinessEvent event;
event.pressedKeys.push_back(pressedKey);
event.keyAction = keyCode;
event.keyAction = keyAction;
DistributedInput::DistributedInputKit::IsNeedFilterOut(deviceId, event);
}
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DistributedHardware::PrepareInputFuzzTest(data, size);
OHOS::DistributedHardware::StartRemoteInputFuzzTest(data, size);
OHOS::DistributedHardware::IsNeedFilterOutFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,23 @@
/*
* 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.
*/
#ifndef DISTRIBUTED_INPUT_KIT_FUZZER_H
#define DISTRIBUTED_INPUT_KIT_FUZZER_H
#define FUZZ_PROJECT_NAME "distributedinputkit_fuzzer"
#endif // DISTRIBUTED_INPUT_KIT_FUZZER_H
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -0,0 +1,79 @@
# 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.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("//foundation/distributedhardware/distributedinput/distributedinput.gni")
##############################fuzztest##########################################
ohos_fuzztest("DistributedInputSinkTransportFuzzTest") {
module_out_path = "distributedinput_stander/system"
# fuzz_config_file = "//foundation/distributedhardware/distributedinput/test/fuzztest/distributedinputsinktransport_fuzzer"
include_dirs = [
"//foundation/distributedhardware/distributedinput/services/sink/transport/include",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"${common_path}/include",
"${fwk_common_path}/log/include",
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include/log",
"${fwk_utils_path}/include",
"${service_common}/include",
"//third_party/json/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"//foundation/distributedhardware/distributedinput/services/sink/transport/src/distributed_input_sink_switch.cpp",
"//foundation/distributedhardware/distributedinput/services/sink/transport/src/distributed_input_sink_transport.cpp",
"distributed_input_sink_transport_fuzzer.cpp",
]
deps = [
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//utils/native/base:utils",
"${fwk_utils_path}:distributedhardwareutils",
"//foundation/communication/dsoftbus/sdk:softbus_client",
]
external_deps = [
"dsoftbus_standard:softbus_client",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"hiviewdfx_hilog_native:libhilog",
"samgr_standard:samgr_proxy",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DistributedInputSinkTransportFuzzTest\"",
"LOG_DOMAIN=0xD004100",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = [
":DistributedInputSinkTransportFuzzTest",
]
}
###############################################################################
@@ -0,0 +1 @@
FUZZ
@@ -0,0 +1,90 @@
/*
* 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.
*/
#include "distributed_input_sink_transport_fuzzer.h"
#include "distributed_input_sink_transport.h"
#include <thread>
#include <functional>
#include <iostream>
#include <refbase.h>
#include "constants_dinput.h"
namespace OHOS {
namespace DistributedHardware {
void RespPrepareRemoteInputFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
std::string smsg(reinterpret_cast<const char*>(data), size);
DistributedInput::DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg);
DistributedInput::DistributedInputSinkTransport::GetInstance().RespUnprepareRemoteInput(sessionId, smsg);
}
void RespStartRemoteInputFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
std::string smsg(reinterpret_cast<const char*>(data), size);
DistributedInput::DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg);
DistributedInput::DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg);
}
void OnSessionOpenedFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
int32_t result = *(reinterpret_cast<const int32_t*>(data));
DistributedInput::DistributedInputSinkTransport::GetInstance().OnSessionOpened(sessionId, result);
DistributedInput::DistributedInputSinkTransport::GetInstance().OnSessionClosed(sessionId);
}
void OnBytesReceivedFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
const char *msg = reinterpret_cast<const char *>(data);
uint16_t dataLen = *(reinterpret_cast<const uint16_t*>(data));
DistributedInput::DistributedInputSinkTransport::GetInstance().OnBytesReceived(sessionId, msg, dataLen);
}
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DistributedHardware::RespPrepareRemoteInputFuzzTest(data, size);
OHOS::DistributedHardware::RespStartRemoteInputFuzzTest(data, size);
OHOS::DistributedHardware::OnSessionOpenedFuzzTest(data, size);
OHOS::DistributedHardware::OnBytesReceivedFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,23 @@
/*
* 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.
*/
#ifndef DISTRIBUTED_INPUT_SINK_TRANSPORT_FUZZER_H
#define DISTRIBUTED_INPUT_SINK_TRANSPORT_FUZZER_H
#define FUZZ_PROJECT_NAME "distributedinputsinktransport_fuzzer"
#endif // DISTRIBUTED_INPUT_SINK_TRANSPORT_FUZZER_H
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -0,0 +1,81 @@
# 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.
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/test.gni")
import("//foundation/distributedhardware/distributedinput/distributedinput.gni")
##############################fuzztest##########################################
ohos_fuzztest("DistributedInputSourceTransportFuzzTest") {
module_out_path = "distributedinput_stander/system"
# fuzz_config_file = "//foundation/distributedhardware/distributedinput/test/fuzztest/distributedinputsourcetransport_fuzzer"
include_dirs = [
"//foundation/distributedhardware/distributedinput/services/source/transport/include",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"${common_path}/include",
"//utils/native/base/include",
"${fwk_common_path}/log/include",
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include/log",
"${fwk_utils_path}/include",
"${service_common}/include",
"//third_party/json/include",
"//foundation/distributedhardware/distributedinput/services/source/transport/test/sourcetransunittest/mock",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"//foundation/distributedhardware/distributedinput/services/source/transport/src/distributed_input_source_transport.cpp",
"distributed_input_source_transport_fuzzer.cpp",
]
deps = [
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//utils/native/base:utils",
"${fwk_utils_path}:distributedhardwareutils",
"//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk",
]
external_deps = [
"dsoftbus_standard:softbus_client",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"hiviewdfx_hilog_native:libhilog",
"samgr_standard:samgr_proxy",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"DistributedInputSourceTransportFuzzTest\"",
"LOG_DOMAIN=0xD004100",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = [
":DistributedInputSourceTransportFuzzTest",
]
}
###############################################################################
@@ -0,0 +1 @@
FUZZ
@@ -0,0 +1,79 @@
/*
* 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.
*/
#include "distributed_input_source_transport_fuzzer.h"
#include "distributed_input_source_transport.h"
#include <cstddef>
#include <cstdint>
#include "constants_dinput.h"
#include <thread>
#include <functional>
#include <iostream>
#include <refbase.h>
namespace OHOS {
namespace DistributedHardware {
void OpenInputSoftbusFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
std::string remoteDevId(reinterpret_cast<const char*>(data), size);
std::string hwId(reinterpret_cast<const char*>(data), size);
DistributedInput::DistributedInputSourceTransport::GetInstance().OpenInputSoftbus(remoteDevId, hwId);
DistributedInput::DistributedInputSourceTransport::GetInstance().CloseInputSoftbus(remoteDevId, hwId);
}
void OnSessionOpenedFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
int32_t result = *(reinterpret_cast<const int32_t*>(data));
DistributedInput::DistributedInputSourceTransport::GetInstance().OnSessionOpened(sessionId, result);
DistributedInput::DistributedInputSourceTransport::GetInstance().OnSessionClosed(sessionId);
}
void OnBytesReceivedFuzzTest(const uint8_t* data, size_t size)
{
if ((data == nullptr) || (size <= 0)) {
return;
}
int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
const char *msg = reinterpret_cast<const char *>(data);
uint16_t dataLen = *(reinterpret_cast<const uint16_t*>(data));
DistributedInput::DistributedInputSourceTransport::GetInstance().OnBytesReceived(sessionId, msg, dataLen);
}
}
}
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DistributedHardware::OpenInputSoftbusFuzzTest(data, size);
OHOS::DistributedHardware::OnSessionOpenedFuzzTest(data, size);
OHOS::DistributedHardware::OnBytesReceivedFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,23 @@
/*
* 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.
*/
#ifndef DISTRIBUTED_INPUT_SOURCE_TRANSPORT_FUZZER_H
#define DISTRIBUTED_INPUT_SOURCE_TRANSPORT_FUZZER_H
#define FUZZ_PROJECT_NAME "distributedinputsourcetransport_fuzzer"
#endif // DISTRIBUTED_INPUT_SOURCE_TRANSPORT_FUZZER_H
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
+98
View File
@@ -0,0 +1,98 @@
# 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("//build/test.gni")
import("//foundation/distributedhardware/distributedinput/distributedinput.gni")
module_out_path = "distributedinput_stander/system"
group("system") {
testonly = true
deps = [
":distributed_input_test",
]
}
## UnitTest distributed_input_test {{{
ohos_unittest("distributed_input_test") {
module_out_path = module_out_path
include_dirs = [
"include",
"${distributedinput_path}/interfaces/inner_kits/include",
"${distributedinput_path}/interfaces/inner_kits/src",
"${distributedinput_path}/interfaces/ipc/include",
"${distributedinput_path}/interfaces/ipc/src",
"${distributedinput_path}/services/source/sourcemanager/include",
"${distributedinput_path}/services/sink/sinkmanager/include",
"${distributedinput_path}/frameworks/include",
"${distributedinput_path}/sourcehandler/include",
"${distributedinput_path}/sinkhandler/include",
"${distributedinput_path}/inputdevicehandler/include",
"//utils/native/base/include",
"//utils/system/safwk/native/include",
"${service_common}/include",
"${common_path}/include",
"${fwk_common_path}/log/include",
"${fwk_common_path}/utils/include",
"${fwk_utils_path}/include/log",
"${fwk_utils_path}/include",
"//third_party/json/include",
]
sources = [
"src/distributed_input_test.cpp",
]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Dprivate=public",
"-Dprotected=public",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"distributedinpututtest\"",
"LOG_DOMAIN=0xD004100",
]
deps = [
"${distributedinput_path}/interfaces/inner_kits:libdinput_sdk",
"${distributedinput_path}/services/source/sourcemanager:libdinput_source",
"${distributedinput_path}/services/source/inputinject:libdinput_inject",
"${distributedinput_path}/services/source/transport:libdinput_source_trans",
"${distributedinput_path}/services/sink/sinkmanager:libdinput_sink",
"${distributedinput_path}/services/sink/inputcollector:libdinput_collector",
"${distributedinput_path}/services/sink/transport:libdinput_sink_trans",
"${distributedinput_path}/sourcehandler:libdinput_source_handler",
"${distributedinput_path}/sinkhandler:libdinput_sink_handler",
"${distributedinput_path}/inputdevicehandler:libdinput_handler",
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
"//utils/native/base:utils",
"${fwk_utils_path}:distributedhardwareutils",
]
external_deps = [
"dsoftbus_standard:softbus_client",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"hiviewdfx_hilog_native:libhilog",
"samgr_standard:samgr_proxy",
]
cflags_cc = [ "-DHILOG_ENABLE" ]
}
## UnitTest distributed_input_test }}}
@@ -0,0 +1,133 @@
/*
* 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.
*/
#ifndef DISRIBUTED_INPUT_TEST_H
#define DISRIBUTED_INPUT_TEST_H
#include "i_distributed_sink_input.h"
#include "i_distributed_source_input.h"
#include "distributed_input_kit.h"
#include "distributed_input_sink_handler.h"
#include "distributed_input_source_handler.h"
#include "distributed_input_handler.h"
#include "prepare_d_input_call_back_stub.h"
#include "unprepare_d_input_call_back_stub.h"
#include "start_d_input_call_back_stub.h"
#include "stop_d_input_call_back_stub.h"
#include "constants_dinput.h"
#include <thread>
#include <functional>
#include <iostream>
#include <gtest/gtest.h>
#include <refbase.h>
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class DistributedInputTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
void StartSourceSa();
void StartSinkSa();
void GetHardWhereInfo();
void GetDeviceInfo();
void RegisterDistributedHardware();
void UnregisterDistributedHardware();
void PrepareRemoteInput();
void UnprepareRemoteInput();
void StartRemoteInput();
void StopRemoteInput();
void IsStartDistributedInput();
void IsNeedFilterOut();
void StopSourceSa();
void StopSinkSa();
void Help();
void SwitchCase(int32_t in);
class TestRegisterInputCallback : public OHOS::DistributedHardware::RegisterCallback {
public:
TestRegisterInputCallback() = default;
virtual ~TestRegisterInputCallback() = default;
virtual int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status,
const std::string &data) override;
};
class TestUnregisterInputCallback : public OHOS::DistributedHardware::UnregisterCallback {
public:
TestUnregisterInputCallback() = default;
virtual ~TestUnregisterInputCallback() = default;
virtual int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status,
const std::string &data) override;
};
class TestPluginListener : public OHOS::DistributedHardware::PluginListener {
public:
TestPluginListener() = default;
virtual ~TestPluginListener() = default;
virtual void PluginHardware(const std::string &dhId, const std::string &attrs) override;
virtual void UnPluginHardware(const std::string &dhId) override;
};
class TestPrepareDInputCallback :
public OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub {
public:
TestPrepareDInputCallback() = default;
virtual ~TestPrepareDInputCallback() = default;
void OnResult(const std::string& deviceId, const int32_t& status);
};
class TestUnprepareDInputCallback :
public OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub {
public:
TestUnprepareDInputCallback() = default;
virtual ~TestUnprepareDInputCallback() = default;
void OnResult(const std::string& deviceId, const int32_t& status);
};
class TestStartDInputCallback :
public OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub {
public:
void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status);
};
class TestStopDInputCallback :
public OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub {
public:
TestStopDInputCallback() = default;
virtual ~TestStopDInputCallback() = default;
void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status);
};
OHOS::DistributedHardware::EnableParam enableParam;
std::shared_ptr<TestRegisterInputCallback> registerCb = nullptr;
std::shared_ptr<TestUnregisterInputCallback> unregisterCb = nullptr;
std::shared_ptr<TestPluginListener> pluginListener;
OHOS::sptr<TestPrepareDInputCallback> prepareCb;
OHOS::sptr<TestUnprepareDInputCallback> unprepareCb;
OHOS::sptr<TestStartDInputCallback> startCb;
OHOS::sptr<TestStopDInputCallback> stopCb;
};
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
#endif // DISRIBUTED_INPUT_TEST_H
+557
View File
@@ -0,0 +1,557 @@
/*
* 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.
*/
#include "distributed_input_test.h"
#include "idistributed_hardware_source.h"
#include "ipc_skeleton.h"
#include "softbus_bus_center.h"
#include "nlohmann/json.hpp"
#include <cstring>
#include <unistd.h>
#include <thread>
using namespace testing::ext;
using namespace OHOS::DistributedHardware::DistributedInput;
using namespace std;
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
namespace {
const int32_t TEST_START_SINK = 1;
const int32_t TEST_START_SOURCE = 2;
const int32_t TEST_GET_DEVICEINFO = 3;
const int32_t TEST_GET_HARDWAREINFO = 4;
const int32_t TEST_IS_START_INPUT = 5;
const int32_t TEST_IS_NEED_FILTEROUT = 6;
const int32_t TEST_STOP_SINK = 7;
const int32_t TEST_STOP_SOURCE = 8;
const int32_t TEST_HELP = 9;
const int32_t TEST_REGISTERHARDWARE = 11;
const int32_t TEST_PREPAREREMOTE = 12;
const int32_t TEST_STARTREMOTE = 13;
const int32_t TEST_STOPREMOTE = 14;
const int32_t TEST_UN_PREPAREREMOTE = 15;
const int32_t TEST_UN_REGISTERHARDWARE = 16;
}
void DistributedInputTest::SetUp()
{
}
void DistributedInputTest::TearDown()
{
}
void DistributedInputTest::SetUpTestCase()
{
}
void DistributedInputTest::TearDownTestCase()
{
}
void DistributedInputTest::TestPluginListener::PluginHardware(
const std::string &dhId, const std::string &attrs)
{
std::cout << std::endl;
std::cout << "TestPluginListener::PluginHardware " << std::endl;
std::cout << "dhId::" << dhId <<std::endl;
std::cout << "attrs::" << attrs <<std::endl;
std::cout << "Enter the case No : " <<std::endl;
}
void DistributedInputTest::TestPluginListener::UnPluginHardware(
const std::string &dhId)
{
std::cout << std::endl;
std::cout << "TestPluginListener::UnPluginHardware " << std::endl;
std::cout << "dhId::" << dhId <<std::endl;
std::cout << "Enter the case No : " <<std::endl;
}
int32_t DistributedInputTest::TestRegisterInputCallback::OnRegisterResult(
const std::string &devId, const std::string &dhId, int32_t status, const std::string &data)
{
std::cout << std::endl;
std::cout << "RegisterInputCallback::OnRegisterResult " << std::endl;
std::cout << "devId::" << devId <<std::endl;
std::cout << "dhId::" << dhId <<std::endl;
std::cout << "status::" << status <<std::endl;
std::cout << "Enter the case No : " <<std::endl;
return SUCCESS;
}
int32_t DistributedInputTest::TestUnregisterInputCallback::OnUnregisterResult(
const std::string &devId, const std::string &dhId, int32_t status, const std::string &data)
{
std::cout << std::endl;
std::cout << "UnregisterInputCallback::OnUnregisterResult " << std::endl;
std::cout << "devId::" << devId <<std::endl;
std::cout << "dhId::" << dhId <<std::endl;
std::cout << "status::" << status <<std::endl;
std::cout << "Enter the case No : " <<std::endl;
return SUCCESS;
}
void DistributedInputTest::TestPrepareDInputCallback::OnResult(
const std::string& deviceId, const int32_t& status)
{
std::cout << std::endl;
std::cout << "IPrepareDInputCallback::OnResult " << std::endl;
std::cout << "deviceId::" << deviceId <<std::endl;
std::cout << "status::" << status <<std::endl;
std::cout << "Enter the case No : " <<std::endl;
return;
}
void DistributedInputTest::TestUnprepareDInputCallback::OnResult(
const std::string& deviceId, const int32_t& status)
{
std::cout << std::endl;
std::cout << "IUnprepareDInputCallback::OnResult " << std::endl;
std::cout << "deviceId::" << deviceId <<std::endl;
std::cout << "status::" << status <<std::endl;
std::cout << "Enter the case No : " <<std::endl;
return;
}
void DistributedInputTest::TestStartDInputCallback::OnResult(
const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status)
{
std::cout << std::endl;
std::cout << "IStartDInputCallback::OnResult " << std::endl;
std::cout << "deviceId::" << deviceId <<std::endl;
std::cout << "inputTypes::" << inputTypes <<std::endl;
std::cout << "status::" << status <<std::endl;
std::cout << "Enter the case No : " <<std::endl;
return;
}
void DistributedInputTest::TestStopDInputCallback::OnResult(
const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status)
{
std::cout << std::endl;
std::cout << "TestStopDInputCallback::OnResult " << std::endl;
std::cout << "deviceId::" << deviceId <<std::endl;
std::cout << "inputTypes::" << inputTypes <<std::endl;
std::cout << "status::" << status <<std::endl;
std::cout << "Enter the case No : " <<std::endl;
return;
}
void DistributedInputTest::StartSourceSa()
{
std::cout << "StartSourceSa::start " << std::endl;
int ret = DistributedInputSourceHandler::GetInstance().InitSource("");
if (ret == SUCCESS) {
std::cout << "StartSourceSa is succese! " << std::endl;
} else {
std::cout << "StartSourceSa is fall! " << std::endl;
}
std::cout << "StartSourceSa::end " << std::endl;
}
void DistributedInputTest::StartSinkSa()
{
std::cout << "StartSinkSa::start " << std::endl;
int ret = DistributedInputSinkHandler::GetInstance().InitSink("");
if (ret == SUCCESS) {
std::cout << "StartSinkSa is succese! " << std::endl;
} else {
std::cout << "StartSinkSa is fall! " << std::endl;
}
std::cout << "StartSinkSa::end " << std::endl;
}
void DistributedInputTest::GetHardWhereInfo()
{
std::cout << "GetHardWhereInfo::start " << std::endl;
std::cout << "HarewareInfo::" << std::endl;
DistributedInputHandler::GetInstance().Initialize();
std::vector<OHOS::DistributedHardware::DHItem> items = DistributedInputHandler::GetInstance().Query();
int index = 0;
for (auto item : items) {
std::cout << "dhId :: " << std::endl;
std::cout << item.dhId << std::endl;
std::cout << "attrs:: " << std::endl;
index = 0;
while ((index = item.attrs.find(' ', index)) != string::npos) {
item.attrs.erase(index, 1);
}
std::cout << item.attrs << std::endl;
}
std::cout << "GetHardWhereInfo::end " << std::endl;
}
void DistributedInputTest::GetDeviceInfo()
{
std::cout << "GetDeviceInfo::start " << std::endl;
NodeBasicInfo *info = NULL;
int32_t infoNum = 0;
GetAllNodeDeviceInfo("ohos.distributedhardware.devicemanager", &info, &infoNum);
std::cout << "DeviceInfo::" << std::endl;
for (int32_t i = 0; i < infoNum; i++) {
std::cout << "networkId::" << std::endl;
std::cout << info->networkId << std::endl;
std::cout << "deviceName::" << std::endl;
std::cout << info->deviceName << std::endl;
std::cout << std::endl;
info++;
}
std::cout << "GetDeviceInfo::end " << std::endl;
}
void DistributedInputTest::IsStartDistributedInput()
{
std::cout << "IsStartDistributedInput::start " << std::endl;
uint32_t inputType = 0;
std::cout << "inputType::";
std::cin >> inputType;
DInputServerType type = DistributedInputKit::IsStartDistributedInput(inputType);
if (type == DInputServerType::SOURCE_SERVER_TYPE) {
std::cout << "The inputed type is using in source sa! " << std::endl;
} else if (type == DInputServerType::SINK_SERVER_TYPE) {
std::cout << "The inputed type is using in sink sa! " << std::endl;
} else {
std::cout << "No sa is using! " << std::endl;
}
std::cout << "IsStartDistributedInput::end " << std::endl;
}
void DistributedInputTest::IsNeedFilterOut()
{
std::cout << "IsNeedFilterOut::start " << std::endl;
string deviceId = "";
int32_t pressedKey1 = 0;
int32_t pressedKey2 = 0;
int32_t keyCode = 0;
int32_t keyAction = 0;
BusinessEvent event;
std::cout << "deviceId::";
std::cin >> deviceId;
std::cout << "BusinessEvent::" << std::endl;
std::cout << "pressedKey1::";
std::cin >> pressedKey1;
std::cout << "pressedKey2::";
std::cin >> pressedKey2;
std::cout << "keyCode::";
std::cin >> keyCode;
std::cout << "keyAction::";
std::cin >> keyAction;
event.pressedKeys.push_back(pressedKey1);
event.pressedKeys.push_back(pressedKey2);
event.keyCode = keyCode;
event.keyAction = keyAction;
bool ret = DistributedInputKit::IsNeedFilterOut(deviceId, event);
if (ret == true) {
std::cout << " Result::true ! " << std::endl;
std::cout << " The businessEvent is not in the white list ! " << std::endl;
std::cout << " The businessEvent take effect at the source! " << std::endl;
} else {
std::cout << " Result::false ! " << std::endl;
std::cout << " The businessEvent is in the white list ! " << std::endl;
std::cout << " The businessEvent don`t take effect at the source! " << std::endl;
}
std::cout << "IsNeedFilterOut::end " << std::endl;
}
void DistributedInputTest::RegisterDistributedHardware()
{
std::cout << "RegisterDistributedHardware::start " << std::endl;
string rDevId = "";
string rDhId = "";
string attrs = "";
std::cout << "devId::";
std::cin >> rDevId;
std::cout << "dhId::";
std::cin >> rDhId;
std::cout << "params::";
std::cin >> attrs;
enableParam.version = "1.0";
enableParam.attrs = attrs;
registerCb = std::make_shared<TestRegisterInputCallback>();
int32_t ret = DistributedInputSourceHandler::GetInstance().RegisterDistributedHardware(
rDevId, rDhId, enableParam, registerCb);
if (ret == SUCCESS) {
std::cout << "RegisterDistributedHardware is succese! " << std::endl;
} else {
std::cout << "RegisterDistributedHardware is fall! " << std::endl;
}
std::cout << "RegisterDistributedHardware::end " << std::endl;
}
void DistributedInputTest::PrepareRemoteInput()
{
std::cout << "PrepareRemoteInput::start " << std::endl;
string rDevId = "";
std::cout << "devId::";
std::cin >> rDevId;
prepareCb = new(std::nothrow) TestPrepareDInputCallback();
int32_t ret = DistributedInputKit::PrepareRemoteInput(rDevId, prepareCb);
if (ret == SUCCESS) {
std::cout << "PrepareRemoteInput is succese! " << std::endl;
} else {
std::cout << "PrepareRemoteInput is fall! " << std::endl;
}
std::cout << "PrepareRemoteInput::end " << std::endl;
}
void DistributedInputTest::UnprepareRemoteInput()
{
std::cout << "UnprepareRemoteInput::start " << std::endl;
string rDevId = "";
std::cout << "devId::";
std::cin >> rDevId;
unprepareCb = new(std::nothrow) TestUnprepareDInputCallback();
int32_t ret = DistributedInputKit::UnprepareRemoteInput(rDevId, unprepareCb);
if (ret == SUCCESS) {
std::cout << "UnprepareRemoteInput is succese! " << std::endl;
} else {
std::cout << "UnprepareRemoteInput is fall! " << std::endl;
}
std::cout << "UnprepareRemoteInput::end " << std::endl;
}
void DistributedInputTest::StartRemoteInput()
{
std::cout << "StartRemoteInput::start " << std::endl;
std::cout << "You can input 1 ~ 7" << std::endl;
std::cout << "1:mouse " << std::endl;
std::cout << "2:keyboard " << std::endl;
std::cout << "4:touch " << std::endl;
std::cout << "7:all " << std::endl;
string rDevId = "";
uint32_t rInputType = 0;
std::cout << "inputType::";
std::cin >> rInputType;
std::cout << "devId::";
std::cin >> rDevId;
startCb = new(std::nothrow) TestStartDInputCallback();
int32_t ret = DistributedInputKit::StartRemoteInput(rDevId, rInputType, startCb);
if (ret == SUCCESS) {
std::cout << "StartRemoteInput is succese! " << std::endl;
} else {
std::cout << "StartRemoteInput is fall! " << std::endl;
}
std::cout << "StartRemoteInput::end " << std::endl;
}
void DistributedInputTest::StopRemoteInput()
{
std::cout << "StopRemoteInput::start " << std::endl;
std::cout << "You can input 1 ~ 7" << std::endl;
std::cout << "1:mouse " << std::endl;
std::cout << "2:keyboard " << std::endl;
std::cout << "4:touch " << std::endl;
std::cout << "7:all " << std::endl;
string rDevId = "";
uint32_t rInputType = 0;
std::cout << "devId::";
std::cin >> rDevId;
std::cout << "inputType::";
std::cin >> rInputType;
stopCb = new(std::nothrow) TestStopDInputCallback();
int32_t ret = DistributedInputKit::StopRemoteInput(rDevId, rInputType, stopCb);
if (ret == SUCCESS) {
std::cout << "StopRemoteInput is succese! " << std::endl;
} else {
std::cout << "StopRemoteInput is fall! " << std::endl;
}
std::cout << "StopRemoteInput::end " << std::endl;
}
void DistributedInputTest::UnregisterDistributedHardware()
{
std::cout << "UnregisterDistributedHardware::start " << std::endl;
string rDevId = "";
string rDhId = "";
string attrs = "";
std::cout << "devId::";
std::cin >> rDevId;
std::cout << "dhId::";
std::cin >> rDhId;
unregisterCb = std::make_shared<TestUnregisterInputCallback>();
int32_t ret = DistributedInputSourceHandler::GetInstance().UnregisterDistributedHardware(
rDevId, rDhId, unregisterCb);
if (ret == SUCCESS) {
std::cout << "UnregisterDistributedHardware is succese! " << std::endl;
} else {
std::cout << "UnregisterDistributedHardware is fall! " << std::endl;
}
std::cout << "UnregisterDistributedHardware::end " << std::endl;
}
void DistributedInputTest::StopSourceSa()
{
std::cout << "StopSourceSa::start " << std::endl;
int ret = DistributedInputSourceHandler::GetInstance().ReleaseSource();
if (ret == SUCCESS) {
std::cout << "StopSourceSa is succese! " << std::endl;
} else {
std::cout << "StopSourceSa is fall! " << std::endl;
}
std::cout << "StopSourceSa::end " << std::endl;
}
void DistributedInputTest::StopSinkSa()
{
std::cout << "StopSinkSa::start " << std::endl;
int ret = DistributedInputSinkHandler::GetInstance().ReleaseSink();
if (ret == SUCCESS) {
std::cout << "StopSinkSa is succese! " << std::endl;
} else {
std::cout << "StopSinkSa is fall! " << std::endl;
}
std::cout << "StopSinkSa::end " << std::endl;
}
void DistributedInputTest::Help()
{
std::cout << "************************************************************" << std::endl;
std::cout << "Welcome to the dinput source test demo!" << std::endl;
std::cout << "1 ::StartSinkSa " << std::endl;
std::cout << "2 ::StartSourceSa " << std::endl;
std::cout << "3 ::GetDeviceInfo " << std::endl;
std::cout << "4 ::GetHardWhereInfo " << std::endl;
std::cout << "5 ::IsStartDistributedInput " << std::endl;
std::cout << "6 ::IsNeedFilterOut " << std::endl;
std::cout << "7 ::StopSinkSa " << std::endl;
std::cout << "8 ::StopSourceSa " << std::endl;
std::cout << "9 ::Help " << std::endl;
std::cout << "0 ::Exit " << std::endl;
std::cout << "11::RegisterDistributedHardware " << std::endl;
std::cout << "12::PrepareRemoteInput " << std::endl;
std::cout << "13::StartRemoteInput " << std::endl;
std::cout << "14::StopRemoteInput " << std::endl;
std::cout << "15::UnprepareRemoteInput " << std::endl;
std::cout << "16::UnregisterDistributedHardware " << std::endl;
std::cout << "************************************************************" << std::endl;
}
void DistributedInputTest::SwitchCase(int32_t in)
{
switch (in) {
case TEST_START_SINK:
StartSinkSa();
break;
case TEST_START_SOURCE:
StartSourceSa();
break;
case TEST_GET_DEVICEINFO:
GetDeviceInfo();
break;
case TEST_GET_HARDWAREINFO:
GetHardWhereInfo();
break;
case TEST_IS_START_INPUT:
IsStartDistributedInput();
break;
case TEST_IS_NEED_FILTEROUT:
IsNeedFilterOut();
break;
case TEST_STOP_SINK:
StopSinkSa();
break;
case TEST_STOP_SOURCE:
StopSourceSa();
break;
case TEST_HELP:
Help();
break;
case TEST_REGISTERHARDWARE:
RegisterDistributedHardware();
break;
case TEST_PREPAREREMOTE:
PrepareRemoteInput();
break;
case TEST_STARTREMOTE:
StartRemoteInput();
break;
case TEST_STOPREMOTE:
StopRemoteInput();
break;
case TEST_UN_PREPAREREMOTE:
UnprepareRemoteInput();
break;
case TEST_UN_REGISTERHARDWARE:
UnregisterDistributedHardware();
break;
default:
break;
}
}
HWTEST_F(DistributedInputTest, SystemTest01, testing::ext::TestSize.Level0)
{
Help();
pluginListener = std::make_shared<TestPluginListener>();
DistributedInputHandler::GetInstance().RegisterPluginListener(pluginListener);
int32_t in;
while (true) {
std::cout << std::endl;
std::cout << "Enter the case No : " << std::endl;
std::cin >> in;
if (in == 0) {
registerCb = nullptr;
unregisterCb = nullptr;
prepareCb = nullptr;
unprepareCb = nullptr;
startCb = nullptr;
stopCb = nullptr;
break;
}
SwitchCase(in);
}
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS