提交 83d6df46 编写于 作者: C cheng_jinsong

add init trace

Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
上级 ba5ad488
......@@ -26,7 +26,9 @@
"load_persist_params ",
"bootchart start",
"chown access_token access_token /dev/access_token_id",
"chmod 0666 /dev/access_token_id"
"chmod 0666 /dev/access_token_id",
"trigger init-hitrace",
"trigger init-trace"
]
}, {
"name" : "init",
......@@ -191,6 +193,11 @@
"chmod 0773 /data/misc/trace",
"chmod 0775 /data/misc/wmtrace"
]
}, {
"name" : "init-trace",
"cmds" : [
"init_trace start"
]
}
]
}
# Copyright (c) 2020-2022 Huawei Device Co., Ltd.
# Copyright (c) 2023 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
......@@ -27,6 +27,10 @@ group("static_modules") {
if (build_selinux) {
deps += [ "selinux:libselinuxadp_static" ]
}
deps += [
"trace:inittrace_cfg",
"trace:libinittrace_static",
]
}
}
......@@ -35,6 +39,7 @@ group("modulesgroup") {
deps = [
"bootchart:bootchart",
"reboot:rebootmodule",
"trace:inittrace",
"udid:udidmodule",
]
if (build_seccomp) {
......
......@@ -189,7 +189,7 @@ static int BootEventTraversal(ListNode *node, void *root)
static int SaveServiceBootEvent()
{
if (g_bootEventEnable == 0) {
if (!GetBootEventEnable()) {
return 0;
}
time_t nowTime = time(NULL);
......@@ -408,13 +408,13 @@ static void SetServiceBootEventFork(SERVICE_INFO_CTX *serviceCtx)
return;
}
static int GetBootEventFlag(const HOOK_INFO *info, void *cookie)
int GetBootEventEnable(void)
{
char bootEventOpen[6] = ""; // 6 is length of bool value
uint32_t len = sizeof(bootEventOpen);
SystemReadParam("persist.init.bootevent.enable", bootEventOpen, &len);
if (strcmp(bootEventOpen, "true") != 0) {
g_bootEventEnable = 0;
if (strcmp(bootEventOpen, "true") == 0 || strcmp(bootEventOpen, "1") == 0) {
return 1;
}
return 0;
}
......@@ -435,5 +435,4 @@ MODULE_CONSTRUCTOR(void)
InitAddClearServiceHook(ClearServiceBootEvent);
InitAddServiceParseHook(ServiceParseBootEventHook);
InitAddGlobalInitHook(0, ParamSetBootEventHook);
InitAddPostPersistParamLoadHook(0, GetBootEventFlag);
}
......@@ -245,6 +245,10 @@ static int BootCompleteCmd(const HOOK_INFO *hookInfo, void *executionContext)
HookMgrDel(GetBootStageHookMgr(), INIT_JOB_PARSE, NULL);
// clear cmd
RemoveCmdExecutor("loadSelinuxPolicy", -1);
PluginExecCmdByName("init_trace", "stop");
// uninstall module of inittrace
InitModuleMgrUnInstall("inittrace");
return 0;
}
......@@ -255,3 +259,9 @@ MODULE_CONSTRUCTOR(void)
// Depends on parameter service
InitAddPostPersistParamLoadHook(0, InitDebugHook);
}
MODULE_DESTRUCTOR(void)
{
const char *clearBootEventArgv[] = {"bootevent"};
PluginExecCmd("clear", ARRAY_LENGTH(clearBootEventArgv), clearBootEventArgv);
}
......@@ -65,6 +65,7 @@ const ParamCmdInfo *GetServiceCtl(size_t *size)
{"ohos.servicectrl.uninstall", "uninstall", "uninstall" },
{"ohos.servicectrl.clear", "clear", "clear" },
{"ohos.servicectrl.bootchart", "bootchart", "bootchart" },
{"ohos.servicectrl.init_trace", "init_trace", "init_trace" },
{"ohos.servicectrl.timer_start", "timer_start", "timer_start " },
{"ohos.servicectrl.timer_stop", "timer_stop", "timer_stop" },
{"ohos.servicectrl.cmd", "cmd", "initcmd"},
......@@ -93,6 +94,8 @@ const ParamCmdInfo *GetOtherSpecial(size_t *size)
static const ParamCmdInfo other[] = {
{"bootevent.", "bootevent.", "bootevent"},
{"persist.init.debug.", "persist.init.debug.", "setloglevel"},
// for hitrace start, need interrupt init trace
{"debug.hitrace.enable.state", "debug.hitrace.enable.state.", "init_trace"},
};
*size = ARRAY_LENGTH(other);
return other;
......
......@@ -35,15 +35,16 @@
#define PLUGIN_LOGI(fmt, ...) STARTUP_LOGI(PLUGIN_DOMAIN, PLUGIN_LABEL, fmt, ##__VA_ARGS__)
#define PLUGIN_LOGE(fmt, ...) STARTUP_LOGE(PLUGIN_DOMAIN, PLUGIN_LABEL, fmt, ##__VA_ARGS__)
#define PLUGIN_LOGV(fmt, ...) STARTUP_LOGV(PLUGIN_DOMAIN, PLUGIN_LABEL, fmt, ##__VA_ARGS__)
#define PLUGIN_LOGW(fmt, ...) STARTUP_LOGW(PLUGIN_DOMAIN, PLUGIN_LABEL, fmt, ##__VA_ARGS__)
#define PLUGIN_CHECK(ret, exper, ...) \
if (!(ret)) { \
PLUGIN_LOGE(__VA_ARGS__); \
exper; \
}
#define PLUGIN_ONLY_CHECK(ret, exper, ...) \
#define PLUGIN_ONLY_LOG(ret, ...) \
if (!(ret)) { \
exper; \
PLUGIN_LOGE(__VA_ARGS__); \
}
#define HOOKID(name) HOOK_ID_##name
......@@ -53,4 +54,6 @@ enum HOOK_ID_ {
HOOKID(BOOTEVENT),
HOOKID(BOOTEVENT_MAX) = HOOK_ID_BOOTEVENT + 10,
};
int GetBootEventEnable(void);
#endif
# Copyright (c) 2023 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("//base/startup/init/begetd.gni")
import("//build/ohos.gni")
comm_include = [
".",
"..",
"../../include",
"../../include/param",
]
ohos_shared_library("inittrace") {
sources = [ "init_trace.c" ]
include_dirs = comm_include
include_dirs += [ "//third_party/zlib" ]
deps = [
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/cJSON:cjson",
"//third_party/zlib:libz",
]
external_deps = [ "init:libinit_module_engine" ]
part_name = "init"
subsystem_name = "startup"
if (target_cpu == "arm64") {
module_install_dir = "lib64/init"
} else {
module_install_dir = "lib/init"
}
}
config("inittrace_static_config") {
include_dirs = comm_include
}
ohos_prebuilt_etc("inittrace_cfg") {
source = "init_trace.cfg"
part_name = "init"
subsystem_name = "startup"
}
ohos_source_set("libinittrace_static") {
sources = [ "init_trace_static.c" ]
include_dirs = comm_include
public_configs = [ ":inittrace_static_config" ]
public_configs += [ "../../../interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
part_name = "init"
subsystem_name = "startup"
}
此差异已折叠。
{
"compress" : false,
"KERNEL" : [
{
"name" : "disk",
"description" : "Disk I/O",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/f2fs/f2fs_sync_file_enter/enable",
"events/f2fs/f2fs_sync_file_exit/enable",
"events/f2fs/f2fs_write_begin/enable",
"events/f2fs/f2fs_write_end/enable",
"events/ext4/ext4_da_write_begin/enable",
"events/ext4/ext4_da_write_end/enable",
"events/ext4/ext4_sync_file_enter/enable",
"events/ext4/ext4_sync_file_exit/enable",
"events/block/block_rq_issue/enable",
"events/block/block_rq_complete/enable"
]
},
{
"name" : "mmc",
"description" : "eMMC commands",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/mmc/enable"
]
},
{
"name" : "zbinder",
"description" : "OpenHarmony binder communication",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/zbinder/enable"
]
},
{
"name" : "ufs",
"description" : "UFS commands",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/ufs/enable"
]
},
{
"name" : "irq",
"description" : "IRQ Events",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/irq/enable",
"events/ipi/enable"
]
},
{
"name" : "irqoff",
"description" : "IRQ-disabled code section tracing",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/preemptirq/irq_enable/enable",
"events/preemptirq/irq_disable/enable"
]
},
{
"name" : "i2c",
"description" : "I2C Events",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/i2c/enable" ,
"events/i2c/i2c_read/enable" ,
"events/i2c/i2c_write/enable" ,
"events/i2c/i2c_result/enable" ,
"events/i2c/i2c_reply/enable" ,
"events/i2c/smbus_read/enable" ,
"events/i2c/smbus_write/enable" ,
"events/i2c/smbus_result/enable" ,
"events/i2c/smbus_reply/enable"
]
},
{
"name" : "regulators",
"description" : "Voltage and Current Regulators",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/regulator/enable"
]
},
{
"name" : "membus",
"description" : "Memory Bus Utilization",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/memory_bus/enable"
]
},
{
"name" : "freq",
"description" : "CPU Frequency",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/power/cpu_frequency/enable",
"events/power/clock_set_rate/enable",
"events/power/clock_disable/enable",
"events/power/clock_enable/enable",
"events/clk/clk_set_rate/enable",
"events/clk/clk_disable/enable",
"events/clk/clk_enable/enable",
"events/power/cpu_frequency_limits/enable"
]
},
{
"name" : "idle",
"description" : "CPU Idle",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/power/cpu_idle/enable"
]
},
{
"name" : "load",
"description" : "CPU Load",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/cpufreq_interactive/enable"
]
},
{
"name" : "sched",
"description" : "CPU Scheduling",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/sched/sched_switch/enable",
"events/sched/sched_wakeup/enable",
"events/sched/sched_wakeup_new/enable",
"events/sched/sched_waking/enable",
"events/sched/sched_blocked_reason/enable",
"events/sched/sched_pi_setprio/enable",
"events/sched/sched_process_exit/enable",
"events/cgroup/enable",
"events/oom/oom_score_adj_update/enable",
"events/task/task_rename/enable",
"events/task/task_newtask/enable"
]
},
{
"name" : "preemptoff",
"description" : "Preempt-disabled code section tracing",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/preemptirq/preempt_enable/enable",
"events/preemptirq/preempt_disable/enable"
]
},
{
"name" : "binder",
"description" : "Binder kernel Info",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/binder/binder_transaction/enable",
"events/binder/binder_transaction_received/enable",
"events/binder/binder_transaction_alloc_buf/enable",
"events/binder/binder_set_priority/enable",
"events/binder/binder_lock/enable",
"events/binder/binder_locked/enable",
"events/binder/binder_unlock/enable"
]
},
{
"name" : "sync",
"description" : "Synchronization",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/dma_fence/enable"
]
},
{
"name" : "workq",
"description" : "Kernel Workqueues",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/workqueue/enable"
]
},
{
"name" : "memreclaim",
"description" : "Kernel Memory Reclaim",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/vmscan/mm_vmscan_direct_reclaim_begin/enable",
"events/vmscan/mm_vmscan_direct_reclaim_end/enable",
"events/vmscan/mm_vmscan_kswapd_wake/enable",
"events/vmscan/mm_vmscan_kswapd_sleep/enable",
"events/lowmemorykiller/enable"
]
},
{
"name" : "pagecache",
"description" : "Page cache",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/filemap/enable"
]
},
{
"name" : "memory",
"description" : "memory",
"tag" : 0,
"type" : "KERNEL",
"sys-files" : [
"events/kmem/rss_stat/enable",
"events/kmem/ion_heap_grow/enable",
"events/kmem/ion_heap_shrink/enable"
]
}
],
"USER" : [
{
"name" : "ohos",
"description" : "OpenHarmony",
"tag" : 30,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "ability",
"description" : "Ability Manager",
"tag" : 31,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "zcamera",
"description" : "OpenHarmony Camera Module",
"tag" : 32,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "zmedia",
"description" : "OpenHarmony Media Module",
"tag" : 33,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "zimage",
"description" : "OpenHarmony Image Module",
"tag" : 34,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "zaudio",
"description" : "OpenHarmony Audio Module",
"tag" : 35,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "distributeddatamgr",
"description" : "Distributed Data Manager",
"tag" : 36,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "mdfs",
"description" : "Mobile Distributed File System",
"tag" : 37,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "graphic",
"description" : "Graphic Module",
"tag" : 38,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "ace",
"description" : "ACE development framework",
"tag" : 39,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "notification",
"description" : "Notification Module",
"tag" : 40,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "misc",
"description" : "misc Module",
"tag" : 41,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "multimodalinput",
"description" : "Multimodal Input Module",
"tag" : 42,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "sensors",
"description" : "Sensors Module",
"tag" : 43,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "msdp",
"description" : "Multimodal Sensor Data Platform",
"tag" : 44,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "dsoftbus",
"description" : "Distributed Softbus",
"tag" : 45,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "rpc",
"description" : "RPC and IPC",
"tag" : 46,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "ark",
"description" : "ARK Module",
"tag" : 47,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "window",
"description" : "Window Manager",
"tag" : 48,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "accessibility",
"description" : "Accessibility Manager",
"tag" : 61,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "account",
"description" : "Account Manager",
"tag" : 49,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "dhfwk",
"description" : "Distributed Hardware FWK",
"tag" : 52,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "dscreen",
"description" : "Distributed Screen",
"tag" : 50,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "daudio",
"description" : "Distributed Audio",
"tag" : 27,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "dinput",
"description" : "Distributed Input",
"tag" : 59,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "devicemanager",
"description" : "Device Manager",
"tag" : 54,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "samgr",
"description" : "samgr",
"tag" : 55,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "dsched",
"description" : "Distributed Schedule",
"tag" : 57,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "deviceprofile",
"description" : "Device Profile",
"tag" : 58,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "huks",
"description" : "Universal KeyStore",
"tag" : 25,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "dlpcre",
"description" : "Dlp Credential Service",
"tag" : 21,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "app",
"description" : "APP Module",
"tag" : 62,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "dcamera",
"description" : "Distributed Camera",
"tag" : 51,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "gresource",
"description" : "Global Resource Manager",
"tag" : 53,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "power",
"description" : "power Manager",
"tag" : 56,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "bluetooth",
"description" : "communicatio bluetooth",
"tag" : 60,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "filemanagement",
"description" : "filemanagement",
"tag" : 29,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "dslm",
"description" : "device security level",
"tag" : 28,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "useriam",
"description" : "useriam",
"tag" : 26,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "nweb",
"description" : "nweb",
"tag" : 24,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "net",
"description" : "net",
"tag" : 23,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "accesscontrol",
"description" : "Access Control Module",
"tag" : 22,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "interconn",
"description" : "Interconnection subsystem",
"tag" : 20,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "usb",
"description" : "usb subsystem",
"tag" : 19,
"type" : "USER",
"sys-files" : [
]
},
{
"name" : "hdf",
"description" : "hdf subsystem",
"tag" : 18,
"type" : "USER",
"sys-files" : [
]
}
]
}
/*
* Copyright (c) 2023 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 <string.h>
#include "init_module_engine.h"
#include "plugin_adapter.h"
static int InitTraceEarlyHook(const HOOK_INFO *info, void *cookie)
{
if (GetBootEventEnable()) {
PLUGIN_LOGI("init trace enabled.");
#ifndef STARTUP_INIT_TEST
InitModuleMgrInstall("inittrace");
#endif
return 0;
}
return 0;
}
MODULE_CONSTRUCTOR(void)
{
// Depends on parameter service
InitAddPostPersistParamLoadHook(0, InitTraceEarlyHook);
}
......@@ -336,7 +336,7 @@ INIT_LOCAL_API int GetServiceCtrlInfo(const char *name, const char *value, Servi
const ParamCmdInfo *other = GetOtherSpecial(&size);
for (size_t i = 0; i < size; i++) {
if (strncmp(name, other[i].name, strlen(other[i].name)) == 0) {
return CreateCtrlInfo(ctrlInfo, other[i].cmd, strlen(other[i].name), 0, "%s.%s", name, value);
return CreateCtrlInfo(ctrlInfo, other[i].cmd, strlen(other[i].replace), 0, "%s.%s", name, value);
}
}
return 0;
......
......@@ -255,6 +255,7 @@ ohos_unittest("init_unittest") {
"//utils/system/safwk/native/include",
"//third_party/bounds_checking_function/include",
"//third_party/cJSON",
"//third_party/zlib",
"//base/security/access_token/interfaces/innerkits/token_setproc/include",
"//base/security/access_token/interfaces/innerkits/nativetoken/include",
"//base/startup/init/services/sandbox/include",
......@@ -271,6 +272,7 @@ ohos_unittest("init_unittest") {
"//third_party/googletest:gmock",
"//third_party/googletest:gtest",
"//third_party/mbedtls:mbedtls_shared",
"//third_party/zlib:libz",
]
defines = [
......@@ -371,5 +373,11 @@ ohos_unittest("init_unittest") {
defines += [ "PARAM_FEATURE_DEVICEINFO" ]
}
sources += [
"//base/startup/init/services/modules/trace/init_trace.c",
"//base/startup/init/services/modules/trace/init_trace_static.c",
"//base/startup/init/test/unittest/modules/trace_unittest.cpp",
]
cflags_cc = [ "-fexceptions" ]
}
/*
* Copyright (c) 2023 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 "bootstage.h"
#include "init_utils.h"
#include "init_cmds.h"
#include "init_cmdexecutor.h"
#include "param_stub.h"
#include "securec.h"
using namespace std;
using namespace testing::ext;
namespace init_ut {
static const char *g_content =
"\"KERNEL\" : ["
"{"
"\"name\" : \"disk\","
"\"description\" : \"Disk I/O\","
"\"tag\" : 0,"
"\"type\" : \"KERNEL\","
"\"sys-files\" : ["
"\"events/f2fs/f2fs_sync_file_enter/enable\","
"\"events/f2fs/f2fs_sync_file_exit/enable\","
"\"events/f2fs/f2fs_write_begin/enable\","
"\"events/f2fs/f2fs_write_end/enable\","
"\"events/ext4/ext4_da_write_begin/enable\","
"\"events/ext4/ext4_da_write_end/enable\","
"\"events/ext4/ext4_sync_file_enter/enable\","
"\"events/ext4/ext4_sync_file_exit/enable\","
"\"events/block/block_rq_issue/enable\","
"\"events/block/block_rq_complete/enable\""
"]"
"},"
"{"
"\"name\" : \"mmc\","
"\"description\" : \"eMMC commands\","
"\"tag\" : 0,"
"\"type\" : \"KERNEL\","
"\"sys-files\" : ["
"\"events/mmc/enable\""
"]"
"}"
"],"
"\"USER\" : ["
"{"
"\"name\" : \"ohos\","
"\"description\" : \"OpenHarmony\","
"\"tag\" : 30,"
"\"type\" : \"USER\","
"\"sys-files\" : ["
"]"
"},"
"{"
"\"name\" : \"ability\","
"\"description\" : \"Ability Manager\","
"\"tag\" : 31,"
"\"type\" : \"USER\","
"\"sys-files\" : ["
"]"
"},"
"{"
"\"name\" : \"usb\","
"\"description\" : \"usb subsystem\","
"\"tag\" : 19,"
"\"type\" : \"USER\","
"\"sys-files\" : ["
"]"
"}"
"]"
"}";
void CreateInitTraceConfig(int compress)
{
std::string config = "{ \"compress\" : ";
if (!compress) {
config += "false,";
} else {
config += "true, ";
}
config += g_content;
// create trace cfg
CreateTestFile(STARTUP_INIT_UT_PATH"/system/etc/init_trace.cfg", config.c_str());
}
class TraceUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
void SetUp() {};
void TearDown() {};
};
HWTEST_F(TraceUnitTest, TraceTest_001, TestSize.Level1)
{
// open switch for trace
uint32_t dataIndex = 0;
WriteParam("persist.init.bootevent.enable", "true", &dataIndex, 0);
HookMgrExecute(GetBootStageHookMgr(), INIT_POST_PERSIST_PARAM_LOAD, NULL, NULL);
// close switch for trace
WriteParam("persist.init.bootevent.enable", "false", &dataIndex, 0);
HookMgrExecute(GetBootStageHookMgr(), INIT_POST_PERSIST_PARAM_LOAD, NULL, NULL);
}
HWTEST_F(TraceUnitTest, TraceTest_002, TestSize.Level1)
{
CreateInitTraceConfig(1);
// start trace
PluginExecCmdByName("init_trace", "start");
// for run 1 s
sleep(1);
// stop trace
PluginExecCmdByName("init_trace", "stop");
}
HWTEST_F(TraceUnitTest, TraceTest_003, TestSize.Level1)
{
CreateInitTraceConfig(0);
// start trace
PluginExecCmdByName("init_trace", "start");
// for run 1 s
sleep(1);
// stop trace
PluginExecCmdByName("init_trace", "stop");
}
HWTEST_F(TraceUnitTest, TraceTest_004, TestSize.Level1)
{
std::string cmdArgs = "/system/etc/init_trace.cfg ";
cmdArgs += STARTUP_INIT_UT_PATH"/system/etc/init_trace.cfg";
DoCmdByName("copy ", cmdArgs.c_str());
// start trace
PluginExecCmdByName("init_trace", "start");
// for run 1 s
sleep(1);
// stop trace
PluginExecCmdByName("init_trace", "stop");
}
HWTEST_F(TraceUnitTest, TraceTest_005, TestSize.Level1)
{
// start trace
PluginExecCmdByName("init_trace", "start");
// for run 1 s
sleep(1);
// interrupt trace
PluginExecCmdByName("init_trace", "1");
}
} // namespace init_ut
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册