mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-23 07:00:17 +00:00
hnpsample code upload
Signed-off-by: 郭桦炜 <guohuawei1@huawei.com>
This commit is contained in:
parent
e10d32d37c
commit
4aece17410
@ -66,6 +66,7 @@ group("moduletest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":AppSpawnModuleTest" ]
|
||||
deps += [ "hnp_sample:hnpsample" ]
|
||||
if (appspawn_test_cmd) {
|
||||
deps += [ ":AppSpawnTest" ]
|
||||
}
|
||||
|
50
test/moduletest/hnp_sample/BUILD.gn
Normal file
50
test/moduletest/hnp_sample/BUILD.gn
Normal file
@ -0,0 +1,50 @@
|
||||
# Copyright (c) 2024 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/appspawn/appspawn.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
ohos_executable("hnpsample") {
|
||||
sources = [ "src/hnpsample/hnpsample.c" ]
|
||||
|
||||
ldflags = [
|
||||
"-Wl,-rpath=../lib",
|
||||
"-Wl,--disable-new-dtags",
|
||||
]
|
||||
|
||||
include_dirs = []
|
||||
|
||||
configs = []
|
||||
|
||||
deps = [ ":hnpsamplelib" ]
|
||||
|
||||
external_deps = []
|
||||
|
||||
install_enable = true
|
||||
subsystem_name = "${subsystem_name}"
|
||||
part_name = "${part_name}"
|
||||
}
|
||||
|
||||
ohos_shared_library("hnpsamplelib") {
|
||||
include_dirs = []
|
||||
|
||||
sources = [ "src/hnpsample/hnpsamplelib.c" ]
|
||||
configs = []
|
||||
defines = []
|
||||
cflags = []
|
||||
external_deps = []
|
||||
|
||||
install_enable = true
|
||||
subsystem_name = "${subsystem_name}"
|
||||
part_name = "${part_name}"
|
||||
}
|
@ -0,0 +1 @@
|
||||
This is hnp sample config file.
|
66
test/moduletest/hnp_sample/src/hnpsample/hnpsample.c
Normal file
66
test/moduletest/hnp_sample/src/hnpsample/hnpsample.c
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "hnpsamplelib.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define HNPSAMPLE_INDEX_2 2
|
||||
#define MAX_DELAY_TIME 60
|
||||
|
||||
// hnpsample软件功能包括:读取cfg文件并打印内容,执行依赖的so函数。通过argv[1]参数控制运行的时间,单位s
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int sectime = 0;
|
||||
int ch;
|
||||
|
||||
printf("\nstart hnp sample");
|
||||
|
||||
if (argc == HNPSAMPLE_INDEX_2) {
|
||||
sectime = atoi(argv[1]);
|
||||
if (sectime > MAX_DELAY_TIME) {
|
||||
sectime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 读取配置文件内容并打印
|
||||
FILE *file = fopen("../cfg/hnpsample.cfg", "r");
|
||||
if (file != NULL) {
|
||||
printf("\ncfg file content:\n");
|
||||
while ((ch = fgetc(file)) != EOF) {
|
||||
putchar(ch);
|
||||
}
|
||||
printf("\ncfg file end.");
|
||||
fclose(file);
|
||||
} else {
|
||||
printf("\n open cfg=../cfg/hnpsample.cfg failed.");
|
||||
}
|
||||
|
||||
// 调用依赖so的函数并进行相应延时处理
|
||||
HnpSampleLibDelay(sectime);
|
||||
|
||||
printf("\nhnp sample end");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
34
test/moduletest/hnp_sample/src/hnpsample/hnpsamplelib.c
Normal file
34
test/moduletest/hnp_sample/src/hnpsample/hnpsamplelib.c
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void HnpSampleLibDelay(int sectime)
|
||||
{
|
||||
printf("\nhnp sample lib delay time=%d.start", sectime);
|
||||
sleep(sectime);
|
||||
printf("\nhnp sample lib delay end");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
29
test/moduletest/hnp_sample/src/hnpsample/hnpsamplelib.h
Normal file
29
test/moduletest/hnp_sample/src/hnpsample/hnpsamplelib.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 HNP_SAMPLELIB_H
|
||||
#define HNP_SAMPLELIB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void HnpSampleLibDelay(int sectime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user