From 787901d6741dc2748997775d522bd02231b3267b Mon Sep 17 00:00:00 2001 From: yudechen Date: Tue, 16 Aug 2022 17:53:33 +0800 Subject: [PATCH] add syscap define check. Signed-off-by: yudechen Change-Id: I64f6a9d25913672393fd7c059478a5b52ebbcc15 --- BUILD.gn | 29 ++++++++++++++++++++++++- interfaces/inner_api/syscap_interface.c | 2 +- test/syscap_define_check.c | 21 ++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 test/syscap_define_check.c diff --git a/BUILD.gn b/BUILD.gn index 93eaa57..27354b8 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -24,7 +24,34 @@ sources_platform_common = [ "./src/endian_internal.c", ] +ohos_executable("syscap_define_check_bin") { + include_dirs = [ "include" ] + sources = [ "./test/syscap_define_check.c" ] + + if (is_mingw) { + defines += [ "_POSIX_" ] + } + + subsystem_name = "developtools" + part_name = "syscap_codec" +} + +build_ext_component("syscap_define_check") { + deps = [ ":syscap_define_check_bin(//build/toolchain/linux:clang_x64)" ] + exec_path = rebase_path(root_out_dir) + + if (defined(ohos_lite)) { + cmd = "${exec_path}/clang_x64/syscap_define_check_bin" + } else { + cmd = "${exec_path}/clang_x64/developtools/syscap_codec/syscap_define_check_bin" + } + + command = "chmod 777 $cmd" + command += " && $cmd" +} + ohos_executable("syscap_tool_bin") { + deps = [ ":syscap_define_check" ] output_name = "syscap_tool" install_enable = true include_dirs = [ "src" ] @@ -37,7 +64,7 @@ ohos_executable("syscap_tool_bin") { sources = [ "./src/main.c" ] sources += sources_platform_common - deps = [ "//third_party/bounds_checking_function:libsec_static" ] + deps += [ "//third_party/bounds_checking_function:libsec_static" ] if (defined(ohos_lite)) { deps += [ "//build/lite/config/component/cJSON:cjson_static" ] diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 1d5c618..b55f356 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -161,7 +161,7 @@ bool EncodePrivateSyscap(char **output, int *outputLen) return false; } - int priLen = bufferLen - PCID_MAIN_BYTES - 1; + uint32_t priLen = bufferLen - PCID_MAIN_BYTES - 1; if (priLen <= 0) { *outputLen = 0; return false; diff --git a/test/syscap_define_check.c b/test/syscap_define_check.c new file mode 100644 index 0000000..d17fc51 --- /dev/null +++ b/test/syscap_define_check.c @@ -0,0 +1,21 @@ +#include +#include +#include +#include "syscap_define.h" + +int main() +{ + size_t size = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); + // printf("size = %lu\n", size); + int flag = 0; + + for (int i = 0; i < size; i++) { + if (g_arraySyscap[i].num != i) { + printf("[Error]: %s -> num(%u) should be %d.\n", g_arraySyscap[i].str, g_arraySyscap[i].num, i); + flag++; + } + } + // if (flag == 0) return 0; + // else exit(1); + exit(1); +} \ No newline at end of file