提交 48559044 编写于 作者: D dhy308

Add libc-test case for TDD

Signed-off-by: Ndhy308 <tony.gan@huawei.com>
上级 9836671d
......@@ -78,3 +78,36 @@ config("config_runtest") {
libs = [ "//${target_out_dir}/libtest.a" ]
}
config("config_unittest") {
include_dirs = [ "." ]
cflags_c = [
"-pipe",
"-std=c99",
"-ffreestanding",
"-nostdinc",
"-D_POSIX_C_SOURCE=200809L",
"-Wall",
"-Wno-unused",
"-Wno-unused-function",
"-Wno-missing-braces",
"-Wno-overflow",
"-Wno-unknown-pragmas",
"-Wno-unsupported-floating-point-opt",
"-Wno-parentheses",
"-fno-builtin",
"-frounding-math",
"-Werror=implicit-function-declaration",
"-Werror=implicit-int",
"-Werror=pointer-sign",
"-Werror=pointer-arith",
"-Wno-error=unused-function",
"-g",
"-D_FILE_OFFSET_BITS=64",
]
ldflags = [ "-nostdlib" ]
libs = [ "//${target_out_dir}/libtest.a" ]
}
......@@ -26,6 +26,9 @@ int main(int argc, char **argv)
char set_thread_name[] = "THREADFOO";
char default_name[] = "pthread_getname";
rc = pthread_getname_np(pthread_self(), thread_name, 0);
if (rc != ERANGE) errExitEN(rc, "pthread_getname_np(invalid args[len]) failed");
rc = pthread_getname_np(pthread_self(), thread_name, NAMELEN);
if (rc != 0) errExitEN(rc, "pthread_getname_np failed");
if(strcmp(thread_name, default_name) != 0) perror("pthread name comparison failed");
......
......@@ -22,6 +22,14 @@
#define FILE_MODE_ALL (0777)
#ifdef open64
#undef open64
#endif
#ifdef openat64
#undef openat64
#endif
/**
* @tc.name : open_0010
* @tc.desc : test open normal condition
......@@ -104,6 +112,19 @@ static void open_0030(void)
return;
}
/**
* @tc.name : open_0040
* @tc.desc : test open only O_RDWR
* @tc.level : Level 1
*/
static void open_0040(void)
{
int fd = open("/proc/version", O_RDWR);
TEST(fd != -1);
close(fd);
return;
}
/**
* @tc.name : openat_0010
......@@ -187,6 +208,20 @@ static void openat_0030(void)
return;
}
/**
* @tc.name : openat_0040
* @tc.desc : test openat only O_RDWR
* @tc.level : Level 1
*/
static void openat_0040(void)
{
int fd = openat(AT_FDCWD, "/proc/version", O_RDWR);
TEST(fd != -1);
close(fd);
return;
}
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
/**
* @tc.name : open64_0010
......@@ -270,6 +305,19 @@ static void open64_0030(void)
return;
}
/**
* @tc.name : open64_0040
* @tc.desc : test open64 only O_RDWR
* @tc.level : Level 1
*/
static void open64_0040(void)
{
int fd = open64("/proc/version", O_RDWR);
TEST(fd != -1);
close(fd);
return;
}
/**
* @tc.name : openat64_0010
......@@ -352,22 +400,40 @@ static void openat64_0030(void)
return;
}
/**
* @tc.name : openat64_0040
* @tc.desc : test openat64 only O_RDWR
* @tc.level : Level 1
*/
static void openat64_0040(void)
{
int fd = openat64(AT_FDCWD, "/proc/version", O_RDWR);
TEST(fd != -1);
close(fd);
return;
}
#endif
int main(int argc, char *argv[]) {
open_0010();
open_0020();
open_0030();
open_0040();
openat_0010();
openat_0020();
openat_0030();
openat_0040();
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
open64_0010();
open64_0020();
open64_0030();
open64_0040();
openat64_0010();
openat64_0020();
openat64_0030();
openat64_0040();
#endif
return t_status;
}
\ No newline at end of file
......@@ -73,6 +73,20 @@ static void poll_0020(void)
return;
}
/**
* @tc.name : poll_0030
* @tc.desc : test poll with two fds and param count is 1
* @tc.level : Level 1
*/
static void poll_0030(void)
{
nfds_t fd_count = atoi("1");
struct pollfd buf[2] = {{0, POLLIN, 0}, {1, POLLIN, 0}};
TEST(poll(buf, fd_count, 1) == 1);
return;
}
#ifdef _GNU_SOURCE
/**
* @tc.name : ppoll_0010
......@@ -126,14 +140,31 @@ static void ppoll_0020(void)
return;
}
/**
* @tc.name : ppoll_0030
* @tc.desc : test ppoll with two fds and param count is 1
* @tc.level : Level 1
*/
static void ppoll_0030(void)
{
nfds_t fd_count = atoi("1");
struct pollfd buf[2] = {{0, POLLIN, 0}, {1, POLLIN, 0}};
struct timespec ts = { .tv_nsec = PPOLL_TIMESPEC_NSEC };
TEST(ppoll(buf, fd_count, &ts, NULL) == 1);
return;
}
#endif
int main(int argc, char *argv[]) {
poll_0010();
poll_0020();
poll_0030();
#ifdef _GNU_SOURCE
ppoll_0010();
ppoll_0020();
ppoll_0030();
#endif
return t_status;
......
......@@ -56,6 +56,7 @@ static void stdio_dynamic_chk_001(void)
EXPECT_STREQ(hello_world, buf);
fclose(fp);
return;
}
/**
......@@ -89,7 +90,7 @@ static void stdio_dynamic_chk_002(void)
for (size_t i = read_size; i < bufferSize; ++i) {
EXPECT_EQ('\xff', buf[i]);
}
return;
}
/**
......@@ -117,7 +118,7 @@ static void stdio_dynamic_chk_003(void)
break;
case 0:
fread(buf, 1, ct, fp);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -127,6 +128,7 @@ static void stdio_dynamic_chk_003(void)
break;
}
fclose(fp);
return;
}
/**
......@@ -155,7 +157,7 @@ static void stdio_dynamic_chk_004(void)
break;
case 0:
fwrite(buf, 1, ct, fp);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -165,6 +167,7 @@ static void stdio_dynamic_chk_004(void)
break;
}
fclose(fp);
return;
}
/**
......@@ -184,6 +187,7 @@ static void stdio_dynamic_chk_005(void)
EXPECT_TRUE(get != NULL);
EXPECT_TRUE(strcmp(hello_world, get) == 0);
fclose(fp);
return;
}
/**
......@@ -212,6 +216,7 @@ static void stdio_dynamic_chk_006(void)
EXPECT_TRUE(get3 != NULL);
EXPECT_TRUE(strcmp("hello boy!", get3) == 0);
fclose(fp);
return;
}
/**
......@@ -240,7 +245,7 @@ static void stdio_dynamic_chk_007(void)
break;
case 0:
fgets(buf, n, fp);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -250,6 +255,7 @@ static void stdio_dynamic_chk_007(void)
break;
}
fclose(fp);
return;
}
/**
......@@ -262,6 +268,7 @@ static void stdio_dynamic_chk_008(void)
char buf[] = "world";
sprintf(buf, "hello");
EXPECT_TRUE(strcmp(buf, "hello") == 0);
return;
}
/**
......@@ -277,6 +284,7 @@ static void stdio_dynamic_chk_009(void)
char value[] = "hello : world!";
EXPECT_TRUE(strcmp(buf, value) == 0);
return;
}
......@@ -303,7 +311,7 @@ static void stdio_dynamic_chk_010(void)
break;
case 0:
sprintf(buf, "hello : %s", "world!");
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -312,6 +320,7 @@ static void stdio_dynamic_chk_010(void)
kill(pid, SIGCONT);
break;
}
return;
}
/**
......@@ -339,7 +348,7 @@ static void stdio_dynamic_chk_011(void)
break;
case 0: // 10 > sizeof buf
snprintf(buf, printSize, "hello : %s", "world!");
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -348,6 +357,7 @@ static void stdio_dynamic_chk_011(void)
kill(pid, SIGCONT);
break;
}
return;
}
......@@ -394,7 +404,7 @@ static void stdio_dynamic_chk_012(void)
break;
case 0:
vsnprintf_test("hello : %s", "world!");
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -403,6 +413,7 @@ static void stdio_dynamic_chk_012(void)
kill(pid, SIGCONT);
break;
}
return;
}
/**
......@@ -425,7 +436,7 @@ static void stdio_dynamic_chk_013(void)
break;
case 0:
vsprintf_test("%s", "0123456789");
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -434,6 +445,7 @@ static void stdio_dynamic_chk_013(void)
kill(pid, SIGCONT);
break;
}
return;
}
int main()
......
......@@ -852,6 +852,11 @@ static void test_memset_0020()
return;
}
/**
* @tc.name : test_strlen_0010
* @tc.desc : Ability to test the strlen normal condition
* @tc.level : Level 0
*/
static void test_strlen_0010()
{
struct sigaction sigabrt = {
......@@ -881,6 +886,36 @@ static void test_strlen_0010()
return;
}
/**
* @tc.name : test_strlen_0020
* @tc.desc : Ability to test the strlen with NULL
* @tc.level : Level 2
*/
static void test_strlen_0020()
{
struct sigaction sigabrt = {
.sa_handler = SignalHandler,
};
sigaction(SIGABRT, &sigabrt, NULL);
int status;
int pid = fork();
switch (pid) {
case -1:
t_error("fork failed: %s\n", strerror(errno));
break;
case 0:
strlen(NULL);
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
kill(pid, SIGCONT);
break;
}
return;
}
int main(int argc, char *argv[]) {
test_strcat_0010();
test_strcat_0020();
......@@ -907,7 +942,8 @@ int main(int argc, char *argv[]) {
test_memcpy_0010();
test_memcpy_0020();
test_strlen_0010();
test_strlen_0020();
#ifdef _GNU_SOURCE
test_mempcpy_0010();
test_mempcpy_0020();
......
......@@ -46,7 +46,6 @@ static void unistd_dynamic_chk_001(void)
case 0:
getcwd(buf, n);
exit(0);
break;
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -55,6 +54,7 @@ static void unistd_dynamic_chk_001(void)
kill(pid, SIGCONT);
break;
}
return;
}
/**
......@@ -84,7 +84,7 @@ static void unistd_dynamic_chk_002(void)
break;
case 0:
pread(fd, buf, n, 0);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -94,6 +94,7 @@ static void unistd_dynamic_chk_002(void)
break;
}
close(fd);
return;
}
/**
......@@ -123,7 +124,7 @@ static void unistd_dynamic_chk_003(void)
break;
case 0:
pread(fd, buf, n, 0);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -133,6 +134,7 @@ static void unistd_dynamic_chk_003(void)
break;
}
close(fd);
return;
}
......@@ -163,7 +165,7 @@ static void unistd_dynamic_chk_004(void)
break;
case 0:
pread64(fd, buf, n, 0);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -173,6 +175,7 @@ static void unistd_dynamic_chk_004(void)
break;
}
close(fd);
return;
}
/**
......@@ -202,7 +205,7 @@ static void unistd_dynamic_chk_005(void)
break;
case 0:
pread64(fd, buf, n, 0);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -212,6 +215,7 @@ static void unistd_dynamic_chk_005(void)
break;
}
close(fd);
return;
}
/**
......@@ -240,7 +244,7 @@ static void unistd_dynamic_chk_006(void)
break;
case 0:
pwrite64(fd, buf, n, 0);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -250,6 +254,7 @@ static void unistd_dynamic_chk_006(void)
break;
}
close(fd);
return;
}
/**
......@@ -278,7 +283,7 @@ static void unistd_dynamic_chk_007(void)
break;
case 0:
pwrite64(fd, buf, n, 0);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -288,6 +293,7 @@ static void unistd_dynamic_chk_007(void)
break;
}
close(fd);
return;
}
......@@ -318,7 +324,7 @@ static void unistd_dynamic_chk_008(void)
break;
case 0:
pwrite(fd, buf, n, 0);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -328,6 +334,7 @@ static void unistd_dynamic_chk_008(void)
break;
}
close(fd);
return;
}
/**
......@@ -357,7 +364,7 @@ static void unistd_dynamic_chk_009(void)
break;
case 0:
pwrite(fd, buf, n, 0);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -367,6 +374,7 @@ static void unistd_dynamic_chk_009(void)
break;
}
close(fd);
return;
}
/**
......@@ -394,7 +402,7 @@ static void unistd_dynamic_chk_010(void)
break;
case 0:
read(fd, buf, n);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -404,6 +412,7 @@ static void unistd_dynamic_chk_010(void)
break;
}
close(fd);
return;
}
/**
......@@ -431,7 +440,7 @@ static void unistd_dynamic_chk_011(void)
break;
case 0:
read(fd, buf, n);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -441,6 +450,7 @@ static void unistd_dynamic_chk_011(void)
break;
}
close(fd);
return;
}
/**
......@@ -470,7 +480,7 @@ static void unistd_dynamic_chk_012(void)
break;
case 0:
write(fd, buf, n);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -480,6 +490,7 @@ static void unistd_dynamic_chk_012(void)
break;
}
close(fd);
return;
}
/**
......@@ -509,7 +520,7 @@ static void unistd_dynamic_chk_013(void)
break;
case 0:
write(fd, buf, n);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -519,6 +530,7 @@ static void unistd_dynamic_chk_013(void)
break;
}
close(fd);
return;
}
/**
......@@ -546,7 +558,7 @@ static void unistd_dynamic_chk_014(void)
break;
case 0:
readlink(path, buf, n);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -555,6 +567,7 @@ static void unistd_dynamic_chk_014(void)
kill(pid, SIGCONT);
break;
}
return;
}
/**
......@@ -582,7 +595,7 @@ static void unistd_dynamic_chk_015(void)
break;
case 0:
readlink(path, buf, n);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -591,6 +604,7 @@ static void unistd_dynamic_chk_015(void)
kill(pid, SIGCONT);
break;
}
return;
}
/**
* @tc.name : readlinkat
......@@ -618,7 +632,7 @@ static void unistd_dynamic_chk_016(void)
break;
case 0:
readlinkat(AT_FDCWD, path, buf, n);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -627,6 +641,7 @@ static void unistd_dynamic_chk_016(void)
kill(pid, SIGCONT);
break;
}
return;
}
/**
......@@ -655,7 +670,7 @@ static void unistd_dynamic_chk_017(void)
break;
case 0:
readlinkat(AT_FDCWD, path, buf, n);
break;
exit(0);
default:
waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0);
......@@ -664,6 +679,7 @@ static void unistd_dynamic_chk_017(void)
kill(pid, SIGCONT);
break;
}
return;
}
int main(int argc, char *argv[])
{
......
......@@ -222,12 +222,39 @@ static void fatal_message_0050(void)
pthread_join(fatalMessageThread2, NULL);
}
/**
* @tc.name : set_fatal_message
* @tc.desc : Test the function of null message.
* @tc.level : Level 0
*/
static void fatal_message_0060(void)
{
const char* msg = NULL;
fatal_msg_t *fatal_message = NULL;
int pidParent = 0;
int pidChild = 0;
pid_t fpid;
fpid = fork();
if (fpid < 0) {
t_printf("error in fork!");
} else if (fpid == 0) {
pidChild = getpid();
set_fatal_message(msg);
fatal_message = get_fatal_message();
EXPECT_TRUE(fatal_message->msg == msg);
exit(pidChild);
}
}
TEST_FUN G_Fun_Array[] = {
fatal_message_0010,
fatal_message_0020,
fatal_message_0030,
fatal_message_0040,
fatal_message_0050,
fatal_message_0060,
};
int main(void)
......
# 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.
import("//build/test.gni")
import("../../../test_template.gni")
import("test_src_functionalext_legacy.gni")
foreach(s, functionalext_legacy_test) {
test_unittest(s) {
target_dir = "functionalext/legacy"
}
}
group("functionalext_legacy_test") {
testonly = true
deps = []
foreach(s, functionalext_legacy_test) {
deps += [ ":${s}" ]
}
}
# 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.
functionalext_legacy_test = [ "ulimit" ]
/**
* 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.
*/
#include <ulimit.h>
#include <stdlib.h>
#include "functionalext.h"
#define MAX_FILE_SIZE 4096
/**
* @tc.name : ulimit_0100
* @tc.desc : Test ulimit() with UL_SETFSIZE
* @tc.level : Level 0
*/
static void ulimit_0100(void)
{
int cmd = UL_SETFSIZE;
long result = ulimit(cmd, MAX_FILE_SIZE);
if (result < 0) {
EXPECT_PTRNE("ulimit_0100", result, 0);
return;
}
EXPECT_LONGEQ("ulimit_0100", MAX_FILE_SIZE, result);
}
/**
* @tc.name : ulimit_0200
* @tc.desc : Test ulimit() with UL_GETFSIZE
* @tc.level : Level 1
*/
static void ulimit_0200(void)
{
int cmd = UL_GETFSIZE;
long result = ulimit(cmd);
if (result < 0) {
EXPECT_PTRNE("ulimit_0200", result, 0);
return;
}
EXPECT_LONGEQ("ulimit_0200", MAX_FILE_SIZE, result);
}
int main(void)
{
ulimit_0100();
ulimit_0200();
return t_status;
}
\ No newline at end of file
/**
* 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.
*/
#include <libintl.h>
#include <locale.h>
#include <stdlib.h>
#include "functionalext.h"
#define PACKAGE "test_dcngettext"
/**
* @tc.name : dcngettext_0100
* @tc.desc : Get string from dcngettext() with mo file
* This case need push the test_dcngettext.mo file of the current path to remote board
* The remote path should be "${test_src_dir}/zh_CN/LC_MESSAGES/test_dcngettext.mo"
* @tc.level : Level 0
*/
static void dcngettext_0100(void)
{
char *msgid = "hello";
setlocale(LC_ALL, "zh_CN");
bindtextdomain(PACKAGE, ".");
textdomain(PACKAGE);
char *result = dcngettext(PACKAGE, msgid, 0, 1, LC_MESSAGES);
if (!result) {
EXPECT_PTRNE("dcngettext_0100", result, NULL);
return;
}
EXPECT_TRUE("dcngettext_0100", strlen(result) > 0);
EXPECT_STREQ("dcngettext_0100", "nihao", result);
}
int main(void)
{
dcngettext_0100();
return t_status;
}
\ No newline at end of file
......@@ -127,6 +127,23 @@ void nl_langinfo_0500()
EXPECT_STREQ("nl_langinfo_0500", ptr, "UTF-8");
}
/**
* @tc.name : nl_langinfo_0600
* @tc.desc : Assert whether the return value result is not "C.UTF-8"
* when the function nl_langinfo passes in the "65535" parameter
* @tc.level : Level 2
*/
void nl_langinfo_0600()
{
char *lo = setlocale(LC_ALL, "");
if (!lo) {
EXPECT_PTRNE("nl_langinfo_0600", lo, NULL);
return;
}
char *ptr = nl_langinfo(RADIXCHAR - 1);
EXPECT_STREQ("nl_langinfo_0600", ptr, "C.UTF-8");
}
int main(void)
{
langinfo_0100();
......@@ -134,5 +151,6 @@ int main(void)
nl_langinfo_0300();
nl_langinfo_0400();
nl_langinfo_0500();
nl_langinfo_0600();
return t_status;
}
\ No newline at end of file
......@@ -12,6 +12,7 @@
# limitations under the License.
functionalext_locale_test = [
"dcngettext",
"duplocale",
"langinfo",
"localeconv",
......
# 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.
import("../../../test_template.gni")
import("test_src_functionalext_sched.gni")
foreach(s, functionalext_sched_list) {
test_unittest(s) {
target_dir = "functionalext/sched"
}
}
group("functionalext_sched_test") {
testonly = true
deps = []
foreach(s, functionalext_sched_list) {
deps += [ ":${s}" ]
}
}
/*
* 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.
*/
#include <sched.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "functionalext.h"
#include "test.h"
typedef void (*TEST_FUN)(void);
/**
* @tc.name : sched_setparam
* @tc.desc : Test the function of sched_setparam.
* @tc.level : Level 2
*/
static void sched_setparam_0010(void)
{
pid_t pid;
pid = getpid();
EXPECT_EQ("sched_setparam_0010", sched_setparam(pid, NULL), -1);
}
TEST_FUN G_Fun_Array[] = {
sched_setparam_0010,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
return t_status;
}
\ No newline at end of file
#
# 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.
#
functionalext_sched_list = [ "sched_setparam" ]
......@@ -40,8 +40,23 @@ void clone_0100(void)
EXPECT_NE("clone_0100", cpid, -1);
}
/**
* @tc.name : clone_0200
* @tc.desc : Parameter flags is 0.
* @tc.level : Level 2
*/
void clone_0200(void)
{
void *stack = malloc(STACK_SIZE);
int cpid = -1;
cpid = clone((int (*)(void *))test, (char *)stack + STACK_SIZE, 0, NULL);
sleep(1);
EXPECT_NE("clone_0100", cpid, -1);
}
int main(int argc, char *argv[])
{
clone_0100();
clone_0200();
return t_status;
}
\ No newline at end of file
/*
* 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.
*/
#include <errno.h>
#include <shadow.h>
#include <string.h>
#include "test.h"
/**
* @tc.name : getspnam_r_0100
* @tc.desc : Get user database files. Test precondtions: /etc/shadow.
* @tc.level : Level 0
*/
void getspnam_r_0100(void)
{
errno = 0;
char buf[512];
gid_t gid = 0;
struct spwd *spwd;
struct spwd spwd_storage;
const char *spwd_name = "root";
int result = getspnam_r(spwd_name, &spwd_storage, buf, sizeof(buf), &spwd);
if (result != 0) {
t_error("%s getgrnam_r failed\n", __func__);
}
}
int main(int argc, char *argv[])
{
getspnam_r_0100();
return t_status;
}
\ No newline at end of file
......@@ -22,4 +22,5 @@ functionalext_supplement_passwd_test = [
"getgrouplist",
"getgrgid_r",
"getgrnam_r",
"getspnam_r",
]
......@@ -25,4 +25,7 @@ functionalext_list = [
"supplement:functionalext_supplement_test",
"fortify:functionalext_fortify_test",
"symver:functionalext_symver_test",
"sched:functionalext_sched_test",
"unittest:functionalext_unittest_test",
"legacy:functionalext_legacy_test",
]
......@@ -147,6 +147,19 @@ void pthread_cond_timedwait_monotonic_np_0010(void)
EXPECT_EQ(pthread_mutex_destroy(&mutex), 0);
}
/**
* @tc.number : pthread_cond_timedwait_monotonic_np_0020
* @tc.desc : Test whether the pthread_cond_timedwait_monotonic_np is invalid
* @tc.level : Level 2
*/
void pthread_cond_timedwait_monotonic_np_0020(void)
{
pthread_cond_t *cond = (pthread_cond_t *)NULL;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
struct timespec ts = {0};
EXPECT_EQ(pthread_cond_timedwait_monotonic_np(cond, &mutex, &ts), EINVAL);
}
/**
* @tc.number : pthread_cond_timeout_np_0010
* @tc.desc : Test whether the pthread_cond_timeout_np is normal
......@@ -707,6 +720,7 @@ TEST_FUN G_Fun_Array[] = {
pthread_cond_timedwait_0020,
pthread_cond_timedwait_time64_0010,
pthread_cond_timedwait_monotonic_np_0010,
pthread_cond_timedwait_monotonic_np_0020,
pthread_cond_timeout_np_0010,
pthread_cond_clockwait_0010,
pthread_cond_timedwait_Time_0010,
......
......@@ -301,6 +301,20 @@ static void pthread_mutex_timedlock_monotonic_np_0020(void)
/********************************************* Test case dividing line ***********************************************/
/**
* @tc.name : pthread_mutex_timedlock_monotonic_np_0030
* @tc.desc : test pthread_mutex_timedlock_monotonic_np_0030 with invalid args
* @tc.level : Level 2
*/
static void pthread_mutex_timedlock_monotonic_np_0030(void)
{
pthread_mutex_t *mtx = (pthread_mutex_t *)NULL;
struct timespec ts = {0};
TEST(pthread_mutex_timedlock_monotonic_np(mtx, &ts) == EINVAL);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadLockTimeoutNPOut(void *arg)
{
pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
......@@ -379,6 +393,7 @@ int main(void)
pthread_mutex_clocklock_0060();
pthread_mutex_timedlock_monotonic_np_0010();
pthread_mutex_timedlock_monotonic_np_0020();
pthread_mutex_timedlock_monotonic_np_0030();
pthread_mutex_lock_timeout_np_0010();
pthread_mutex_lock_timeout_np_0020();
......
......@@ -269,6 +269,17 @@ static void pthread_rwlock_timedrdlock_monotonic_np_0020(void)
TEST(pthread_rwlock_destroy(&g_rwlock6) == 0);
}
/**
* @tc.name : pthread_rwlock_timedrdlock_monotonic_np_0030
* @tc.desc : test pthread_rwlock_timedrdlock_monotonic_np with invalid rwlock
* @tc.level : Level 2
*/
static void pthread_rwlock_timedrdlock_monotonic_np_0030(void)
{
struct timespec ts = {0};
TEST(pthread_rwlock_timedrdlock_monotonic_np((pthread_rwlock_t *)NULL, &ts) == EINVAL);
}
int main(void)
{
pthread_rwlock_clockrdlock_0010();
......@@ -277,6 +288,7 @@ int main(void)
pthread_rwlock_clockrdlock_0040();
pthread_rwlock_timedrdlock_monotonic_np_0010();
pthread_rwlock_timedrdlock_monotonic_np_0020();
pthread_rwlock_timedrdlock_monotonic_np_0030();
return t_status;
}
\ No newline at end of file
......@@ -328,6 +328,17 @@ void pthread_rwlock_timedwrlock_0100(void)
EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock4), 0);
}
/**
* @tc.number : pthread_rwlock_timedwrlock_0110
* @tc.desc : Test the case of pthread_rwlock_timedwrlock_monotonic_np with invalid rwlock
* @tc.level : Level 2
*/
void pthread_rwlock_timedwrlock_0110(void)
{
struct timespec ts = {0};
EXPECT_EQ(pthread_rwlock_timedwrlock_monotonic_np((pthread_rwlock_t *)NULL, &ts), EINVAL);
}
TEST_FUN G_Fun_Array[] = {
pthread_rwlock_timedwrlock_0010,
pthread_rwlock_timedwrlock_0020,
......@@ -339,6 +350,7 @@ TEST_FUN G_Fun_Array[] = {
pthread_rwlock_timedwrlock_0080,
pthread_rwlock_timedwrlock_0090,
pthread_rwlock_timedwrlock_0100,
pthread_rwlock_timedwrlock_0110,
};
int main(void)
......
......@@ -15,6 +15,7 @@
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include "gmtime_data.h"
#include "functionalext.h"
......@@ -50,8 +51,22 @@ void gmtime_r_0100(void)
}
}
/**
* @tc.name : gmtime_r_0200
* @tc.desc : test gmtime_r() with invalid input paramter
* @tc.level : Level 2
*/
void gmtime_r_0200(void)
{
time_t invalid_time = INT_MAX * 31622400LL + 1;
struct tm res = {0};
struct tm *gmtm = gmtime_r(&invalid_time, &res);
EXPECT_TRUE("gmtime_r_0200", NULL == (void *)gmtm);
}
int main(void)
{
gmtime_r_0100();
gmtime_r_0200();
return t_status;
}
\ No newline at end of file
......@@ -229,6 +229,40 @@ void strptime_0900(void)
EXPECT_STREQ("strptime_0900", "2021-9-30", buffResult);
}
/**
* @tc.name : strptime_1000
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 1
*/
void strptime_1000(void)
{
const char *buffer = "2021-01-23";
struct tm tmTime = {0};
char *result = strptime(buffer, "%G", &tmTime);
char buffResult[gBufferSize];
int cnt = sprintf(buffResult, "%s", result);
EXPECT_TRUE("strptime_1000", cnt > 0);
EXPECT_STREQ("strptime_1000", "-01-23", buffResult);
}
/**
* @tc.name : strptime_1100
* @tc.desc : according to different time zones, convert a string to a time
* type according to a specific time format
* @tc.level : Level 1
*/
void strptime_1100(void)
{
const char *buffer = "23";
struct tm tmTime = {0};
strptime(buffer, "%j", &tmTime);
char buffResult[gBufferSize];
int cnt = sprintf(buffResult, "%d", tmTime.tm_yday);
EXPECT_TRUE("strptime_1100", cnt > 0);
EXPECT_STREQ("strptime_1100", "22", buffResult);
}
int main(void)
{
strptime_0100();
......@@ -240,5 +274,7 @@ int main(void)
strptime_0700();
strptime_0800();
strptime_0900();
strptime_1000();
strptime_1100();
return t_status;
}
\ No newline at end of file
# 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.
import("../../../test_template.gni")
ohos_executable("unittest_ldso_ns_config") {
subsystem_name = "musl"
part_name = "libc-test"
sources = [ "unit_test_ldso_ns_config.c" ]
include_dirs = [
"${musl_src_base}/ldso",
"//${test_dir}/src/common",
"//${test_dir}/src/functionalext/common",
"${musl_src_base}/src/include",
"${musl_src_base}/include",
"${musl_src_base}/src/internal",
]
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
libs = [ "${musl_lib_dir}/libc.a" ]
}
ohos_executable("unittest_ldso_namesapce") {
subsystem_name = "musl"
part_name = "libc-test"
sources = [
"${musl_src_base}/ldso/namespace.c",
"unit_test_ldso_namespace.c",
"unit_test_mock_molloc.c",
"unit_test_mock_strops.c",
]
include_dirs = [
"${musl_src_base}/ldso",
"//${test_dir}/src/common",
"//${test_dir}/src/functionalext/common",
"${musl_src_base}/src/include",
"${musl_src_base}/include",
"${musl_src_base}/src/internal",
]
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
}
ohos_executable("unittest_ldso_ld_log") {
subsystem_name = "musl"
part_name = "libc-test"
sources = [
"${musl_src_base}/ldso/ld_log.c",
"unit_test_ldso_ld_log.c",
"unit_test_mock_hilog_adapter.c",
]
include_dirs = [
"${musl_src_base}/ldso",
"//${test_dir}/src/common",
"//${test_dir}/src/functionalext/common",
"${musl_src_base}/src/include",
"${musl_src_base}/include",
"${musl_src_base}/src/internal",
"//${test_dir}/src/functionalext/unittest",
]
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
defines = [ "OHOS_ENABLE_PARAMETER" ]
}
ohos_executable("unittest_ldso_dynlink") {
subsystem_name = "musl"
part_name = "libc-test"
sources = [ "unit_test_ldso_dynlink.c" ]
include_dirs = [
"${musl_src_base}/ldso",
"//${test_dir}/src/common",
"//${test_dir}/src/functionalext/common",
"${musl_src_base}/src/include",
"${musl_src_base}/include",
"${musl_src_base}/src/internal",
]
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
libs = [ "${musl_lib_dir}/libc.a" ]
}
ohos_executable("unittest_hilog_adapter") {
subsystem_name = "musl"
part_name = "libc-test"
sources = [ "unit_test_hilog_adapter.c" ]
include_dirs = [
"//${test_dir}/src/functionalext/common",
"//${test_dir}/src/common",
"${musl_src_base}/src/internal",
]
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
libs = [ "${musl_lib_dir}/libc.a" ]
}
ohos_executable("unittest_hilog_vsnprint") {
subsystem_name = "musl"
part_name = "libc-test"
sources = [ "unit_test_hilog_vsnprint_f_p.c" ]
include_dirs = [
"//${test_dir}/src/functionalext/common",
"//${test_dir}/src/common",
"${musl_src_base}/src/hilog",
]
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
libs = [ "${musl_lib_dir}/libc.a" ]
}
ohos_executable("unittest_hook_preinit") {
subsystem_name = "musl"
part_name = "libc-test"
sources = [ "unit_test_hook_preinit.c" ]
include_dirs = [
"${musl_src_base}/src/hook",
"//${test_dir}/src/common",
"//${test_dir}/src/functionalext/common",
"${musl_src_base}/src/include",
"${musl_src_base}/include",
"${musl_src_base}/src/internal",
]
configs = [ "//third_party/musl/libc-test/src/common:config_unittest" ]
deps = [ "//third_party/musl:create_porting_src" ]
if(musl_unit_test_flag){
defines = [ "UNIT_TEST_STATIC" ]
}
libs = [ "${musl_lib_dir}/libc.a" ]
}
group("functionalext_unittest_test") {
testonly = true
deps = [
":unittest_hilog_adapter",
":unittest_hilog_vsnprint",
":unittest_hook_preinit",
":unittest_ldso_dynlink",
":unittest_ldso_ld_log",
":unittest_ldso_namesapce",
":unittest_ldso_ns_config",
]
}
/**
* 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.
*/
#include <stdint.h>
int SystemReadParam(char *name, char *buffer, uint32_t *length);
\ No newline at end of file
/*
* 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.
*/
#include <hilog_adapter.h>
#include "functionalext.h"
#include "test.h"
#define MUSL_LOG_TYPE LOG_CORE
#define MUSL_LOG_DOMAIN 0xD003F00
#define MUSL_LOG_TAG "MUSL"
#define LOG_ERROR 6
#define MUSL_LOGE(...) ((void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_ERROR, MUSL_LOG_DOMAIN, MUSL_LOG_TAG, __VA_ARGS__))
/**
* @tc.name : reboot_0010
* @tc.desc : test HiLogAdapterPrint after musl_log_reset
* @tc.level : Level 2
*/
static void HiLogAdapterPrint_0010(void)
{
musl_log_reset();
int ret = HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_ERROR, MUSL_LOG_DOMAIN, MUSL_LOG_TAG, "a");
EXPECT_EQ("HiLogAdapterPrint_0010", ret, -1);
}
int main(void)
{
HiLogAdapterPrint_0010();
return t_status;
}
/*
* 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.
*/
#include "test.h"
#include <vsnprintf_s_p.h>
#include "functionalext.h"
#define MAX_LOG_LEN 1024 /* maximum length of a log, include '\0' */
#define MAX_TAG_LEN 32 /* log tag size, include '\0' */
#define SECUREC_STRING_MAX_LEN 0x7fffffffUL
typedef void (*TEST_FUN)(void);
static int vsprintf_test(char *strDest, size_t destMax, size_t count, int priv, const char *fmt, ...)
{
int ret;
va_list ap;
va_start(ap, fmt);
ret = vsnprintfp_s(strDest, destMax, count, priv, fmt, ap);
va_end(ap);
return ret;
}
/**
* @tc.name : vsnprintfp_s_0010
* @tc.desc : test vsnprintf normal condition
* @tc.level : Level 0
*/
static void vsnprintfp_s_0010(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "MUSL";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, true, fmt);
EXPECT_TRUE("vsnprintfp_s_0010", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0010", buf, "MUSL");
}
/**
* @tc.name : vsnprintfp_s_0020
* @tc.desc : test vsnprintf both param buf and fmt are NULL
* @tc.level : Level 2
*/
static void vsnprintfp_s_0020(void)
{
char *buf = NULL;
char *fmt = NULL;
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, true, fmt);
EXPECT_TRUE("vsnprintfp_s_0020", ret < 0);
}
/**
* @tc.name : vsnprintfp_s_0030
* @tc.desc : test vsnprintf param destMax is smaller than count
* @tc.level : Level 1
*/
static void vsnprintfp_s_0030(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "MUSL";
int ret = vsprintf_test(buf, MAX_LOG_LEN - 1, MAX_LOG_LEN, true, fmt);
EXPECT_TRUE("vsnprintfp_s_0030", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0030", buf, "MUSL");
}
/**
* @tc.name : vsnprintfp_s_0040
* @tc.desc : test vsnprintf param fmt with %s
* @tc.level : Level 1
*/
static void vsnprintfp_s_0040(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%s";
int ret = vsprintf_test(buf, MAX_LOG_LEN - 1, MAX_LOG_LEN, false, fmt, "MUSL");
EXPECT_TRUE("vsnprintfp_s_0040", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0040", buf, "MUSL");
}
/**
* @tc.name : vsnprintfp_s_0050
* @tc.desc : test vsnprintf param destMax is 0
* @tc.level : Level 2
*/
static void vsnprintfp_s_0050(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "MUSL";
int ret = vsprintf_test(buf, 0, MAX_LOG_LEN - 1, true, fmt);
EXPECT_TRUE("vsnprintfp_s_0050", ret < 0);
EXPECT_STREQ("vsnprintfp_s_0050", buf, "");
}
/**
* @tc.name : vsnprintfp_s_0060
* @tc.desc : test vsnprintf param destMax is greater than SECUREC_STRING_MAX_LEN
* @tc.level : Level 2
*/
static void vsnprintfp_s_0060(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "MUSL";
int ret = vsprintf_test(buf, SECUREC_STRING_MAX_LEN + 1, MAX_LOG_LEN - 1, true, fmt);
EXPECT_TRUE("vsnprintfp_s_0060", ret < 0);
EXPECT_STREQ("vsnprintfp_s_0060", buf, "");
}
/**
* @tc.name : vsnprintfp_s_0070
* @tc.desc : test vsnprintf param count is greater than SECUREC_STRING_MAX_LEN
* @tc.level : Level 2
*/
static void vsnprintfp_s_0070(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "MUSL";
int ret = vsprintf_test(buf, MAX_LOG_LEN - 1, SECUREC_STRING_MAX_LEN + 1, true, fmt);
EXPECT_TRUE("vsnprintfp_s_0070", ret < 0);
EXPECT_STREQ("vsnprintfp_s_0070", buf, "");
}
/**
* @tc.name : vsnprintfp_s_0080
* @tc.desc : test vsnprintf param fmt is NULL
* @tc.level : Level 2
*/
static void vsnprintfp_s_0080(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = NULL;
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, true, fmt);
EXPECT_TRUE("vsnprintfp_s_0080", ret < 0);
}
/**
* @tc.name : vsnprintfp_s_0090
* @tc.desc : test vsnprintf param count is less than buf's size
* @tc.level : Level 2
*/
static void vsnprintfp_s_0090(void)
{
char buf[2] = {0};
char *fmt = "%s";
int ret = vsprintf_test(buf, 1, 1, false, fmt, "test_test");
EXPECT_TRUE("vsnprintfp_s_0090", ret < 0);
}
/**
* @tc.name : vsnprintfp_s_0100
* @tc.desc : test vsnprintf param fmt is ""
* @tc.level : Level 1
*/
static void vsnprintfp_s_0100(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, true, fmt);
EXPECT_TRUE("vsnprintfp_s_0100", ret == 0);
EXPECT_STREQ("vsnprintfp_s_0100", buf, "");
}
/**
* @tc.name : vsnprintfp_s_0110
* @tc.desc : test vsnprintf param fmt is "%02d"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0110(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%02d";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 2);
EXPECT_TRUE("vsnprintfp_s_0110", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0110", buf, "02");
}
/**
* @tc.name : vsnprintfp_s_0120
* @tc.desc : test vsnprintf param fmt is "%p"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0120(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%p";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, &buf[0]);
EXPECT_TRUE("vsnprintfp_s_0120", ret > 0);
EXPECT_TRUE("vsnprintfp_s_0120", strlen(buf) > 0);
}
/**
* @tc.name : vsnprintfp_s_0130
* @tc.desc : test vsnprintf param fmt is "%S"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0130(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%S";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, "Test");
EXPECT_TRUE("vsnprintfp_s_0130", ret < 0);
}
/**
* @tc.name : vsnprintfp_s_0140
* @tc.desc : test vsnprintf param fmt is "%c"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0140(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%c";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 'a');
EXPECT_TRUE("vsnprintfp_s_0140", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0140", buf, "a");
}
/**
* @tc.name : vsnprintfp_s_0150
* @tc.desc : test vsnprintf param fmt is "%lu"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0150(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%lu";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 21);
EXPECT_TRUE("vsnprintfp_s_0150", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0150", buf, "21");
}
/**
* @tc.name : vsnprintfp_s_0160
* @tc.desc : test vsnprintf param fmt is "%.3f, %2.2f"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0160(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%.3f, %2.2f";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 3.14, 2.2);
EXPECT_TRUE("vsnprintfp_s_0160", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0160", buf, "3.140, 2.20");
}
/**
* @tc.name : vsnprintfp_s_0170
* @tc.desc : test vsnprintf param fmt is "%% %n\n"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0170(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%% %n\n";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, true, fmt);
EXPECT_TRUE("vsnprintfp_s_0170", ret < 0);
}
/**
* @tc.name : vsnprintfp_s_0180
* @tc.desc : test vsnprintf param fmt is "%F"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0180(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%F";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 3.14);
EXPECT_TRUE("vsnprintfp_s_0180", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0180", buf, "3.140000");
}
/**
* @tc.name : vsnprintfp_s_0190
* @tc.desc : test vsnprintf param fmt is "%x"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0190(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%x";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 61);
EXPECT_TRUE("vsnprintfp_s_0190", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0190", buf, "3d");
}
/**
* @tc.name : vsnprintfp_s_0200
* @tc.desc : test vsnprintf param fmt is "%X"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0200(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%X";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 61);
EXPECT_TRUE("vsnprintfp_s_0200", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0200", buf, "3D");
}
/**
* @tc.name : vsnprintfp_s_0210
* @tc.desc : test vsnprintf param fmt is "%5d*"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0210(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "*%5d*";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 1024);
EXPECT_TRUE("vsnprintfp_s_0210", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0210", buf, "* 1024*");
}
/**
* @tc.name : vsnprintfp_s_0220
* @tc.desc : test vsnprintf param fmt is "%% %n\n"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0220(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%#0*X";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 8, 128);
EXPECT_TRUE("vsnprintfp_s_0220", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0220", buf, "0X000080");
}
/**
* @tc.name : vsnprintfp_s_0230
* @tc.desc : test vsnprintf param fmt is "%+d"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0230(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%+d";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 22);
EXPECT_TRUE("vsnprintfp_s_0230", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0230", buf, "+22");
}
/**
* @tc.name : vsnprintfp_s_0240
* @tc.desc : test vsnprintf param fmt is "%-d"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0240(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%-d";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 22);
EXPECT_TRUE("vsnprintfp_s_0240", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0240", buf, "22");
}
/**
* @tc.name : vsnprintfp_s_0250
* @tc.desc : test vsnprintf param fmt is "%ho"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0250(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%ho";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 9);
EXPECT_TRUE("vsnprintfp_s_0250", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0250", buf, "11");
}
/**
* @tc.name : vsnprintfp_s_0260
* @tc.desc : test vsnprintf param fmt is "%Le"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0260(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%Le";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 10000);
EXPECT_TRUE("vsnprintfp_s_0260", ret == 0);
}
/**
* @tc.name : vsnprintfp_s_0270
* @tc.desc : test vsnprintf param fmt is "%{public}d"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0270(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%{public}d";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, true, fmt, 22);
EXPECT_TRUE("vsnprintfp_s_0270", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0270", buf, "22");
}
/**
* @tc.name : vsnprintfp_s_0280
* @tc.desc : test vsnprintf param fmt is "%{private}d"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0280(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%{private}d";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, true, fmt, 22);
EXPECT_TRUE("vsnprintfp_s_0280", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0280", buf, "<private>");
}
/**
* @tc.name : vsnprintfp_s_0290
* @tc.desc : test vsnprintf param fmt is "%C"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0290(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%C";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 'a');
EXPECT_TRUE("vsnprintfp_s_0290", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0290", buf, "a");
}
/**
* @tc.name : vsnprintfp_s_0300
* @tc.desc : test vsnprintf param fmt is "%c"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0300(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%c";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 'a');
EXPECT_TRUE("vsnprintfp_s_0300", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0300", buf, "a");
}
/**
* @tc.name : vsnprintfp_s_0310
* @tc.desc : test vsnprintf param fmt is "%I64 %hho"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0310(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%I64o %hho";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 2, 3);
EXPECT_TRUE("vsnprintfp_s_0310", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0310", buf, "6040000000003 66");
}
/**
* @tc.name : vsnprintfp_s_0320
* @tc.desc : test vsnprintf param fmt is "%.3f"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0320(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "%.3f";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 3.14);
EXPECT_TRUE("vsnprintfp_s_0320", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0320", buf, "3.140");
}
/**
* @tc.name : vsnprintfp_s_0330
* @tc.desc : test vsnprintf param fmt is "%{private}f"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0330(void)
{
char buf[2] = {0};
char *fmt = "%{private}f";
int ret = vsprintf_test(buf, 2, 1, false, fmt, 3.14);
EXPECT_TRUE("vsnprintfp_s_0330", ret < 0);
EXPECT_STREQ("vsnprintfp_s_0330", buf, "3");
}
/**
* @tc.name : vsnprintfp_s_0340
* @tc.desc : test vsnprintf param fmt is "% d"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0340(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "% d";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt, 2);
EXPECT_TRUE("vsnprintfp_s_0340", ret > 0);
EXPECT_STREQ("vsnprintfp_s_0340", buf, " 2");
}
/**
* @tc.name : vsnprintfp_s_0350
* @tc.desc : test vsnprintf param fmt is "*%t*"
* @tc.level : Level 1
*/
static void vsnprintfp_s_0350(void)
{
char buf[MAX_LOG_LEN] = {0};
char *fmt = "*%t*";
int ret = vsprintf_test(buf, MAX_LOG_LEN, MAX_LOG_LEN - 1, false, fmt);
EXPECT_TRUE("vsnprintfp_s_0350", ret < 0);
}
TEST_FUN G_Fun_Array[] = {
vsnprintfp_s_0010, vsnprintfp_s_0020, vsnprintfp_s_0030, vsnprintfp_s_0040, vsnprintfp_s_0050,
vsnprintfp_s_0060, vsnprintfp_s_0070, vsnprintfp_s_0080, vsnprintfp_s_0090, vsnprintfp_s_0100,
vsnprintfp_s_0110, vsnprintfp_s_0120, vsnprintfp_s_0130, vsnprintfp_s_0140, vsnprintfp_s_0150,
vsnprintfp_s_0160, vsnprintfp_s_0170, vsnprintfp_s_0180, vsnprintfp_s_0190, vsnprintfp_s_0200,
vsnprintfp_s_0210, vsnprintfp_s_0220, vsnprintfp_s_0230, vsnprintfp_s_0240, vsnprintfp_s_0250,
vsnprintfp_s_0260, vsnprintfp_s_0270, vsnprintfp_s_0280, vsnprintfp_s_0290, vsnprintfp_s_0300,
vsnprintfp_s_0310, vsnprintfp_s_0320, vsnprintfp_s_0330, vsnprintfp_s_0340, vsnprintfp_s_0350,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
return t_status;
}
/**
* 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.
*/
#include "test.h"
#include "functionalext.h"
typedef void (*TEST_FUN)(void);
#ifdef UNIT_TEST_STATIC
enum EnumHookMode;
int parse_hook_variable(enum EnumHookMode* mode, char* path, int size);
/**
* @tc.name : preinit_test_0010
* @tc.desc : test
* @tc.level : Level 2
*/
static void preinit_test_0010(void)
{
int ret = parse_hook_variable(NULL, NULL, 0);
EXPECT_EQ(preinit_test_0010, ret, -1);
}
bool get_proc_name(pid_t pid, char *buf, unsigned int buf_len);
/**
* @tc.name : preinit_test_0020
* @tc.desc : test
* @tc.level : Level 2
*/
static void preinit_test_0020(void)
{
int ret = get_proc_name(0, NULL, 0);
EXPECT_EQ(preinit_test_0020, ret, false);
}
void clear_function_table();
/**
* @tc.name : preinit_test_0030
* @tc.desc : test
* @tc.level : Level 2
*/
static void preinit_test_0030(void)
{
clear_function_table();
EXPECT_TRUE(preinit_test_0030, true);
}
void get_memleak_hook_param();
/**
* @tc.name : preinit_test_0040
* @tc.desc : test
* @tc.level : Level 2
*/
static void preinit_test_0040(void)
{
get_memleak_hook_param();
EXPECT_TRUE(preinit_test_0040, true);
}
void __restore_hook_function_table();
/**
* @tc.name : preinit_test_0050
* @tc.desc : test
* @tc.level : Level 2
*/
static void preinit_test_0050(void)
{
__restore_hook_function_table();
EXPECT_TRUE(preinit_test_0050, true);
}
void __install_malloc_hook();
/**
* @tc.name : preinit_test_0060
* @tc.desc : test
* @tc.level : Level 2
*/
static void preinit_test_0060(void)
{
__install_malloc_hook();
EXPECT_TRUE(preinit_test_0060, true);
}
#endif
TEST_FUN G_Fun_Array[] = {
#ifdef UNIT_TEST_STATIC
preinit_test_0010,
preinit_test_0020,
preinit_test_0030,
preinit_test_0040,
preinit_test_0050,
preinit_test_0060,
#endif
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
return t_status;
}
\ No newline at end of file
/**
* 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.
*/
#include <errno.h>
#include "test.h"
#include "dlfcn.h"
#include "namespace.h"
#include "functionalext.h"
typedef void (*TEST_FUN)(void);
/**
* @tc.name : dynlink_test_0010
* @tc.desc : dlns_set_namespace_lib_path test
* @tc.level : Level 2
*/
static void dynlink_test_0010(void)
{
int ret = dlns_set_namespace_lib_path(NULL, NULL);
EXPECT_EQ(dynlink_test_0010, ret, EINVAL);
}
/**
* @tc.name : dynlink_test_0020
* @tc.desc : dlns_set_namespace_lib_path test
* @tc.level : Level 2
*/
static void dynlink_test_0020(void)
{
int ret = dlns_set_namespace_lib_path("abc", "abc");
EXPECT_EQ(dynlink_test_0020, ret, ENOKEY);
}
/**
* @tc.name : dynlink_test_0030
* @tc.desc : dlns_set_namespace_lib_path test
* @tc.level : Level 1
*/
static void dynlink_test_0030(void)
{
int ret = dlns_set_namespace_lib_path("default", "/data");
EXPECT_EQ(dynlink_test_0030, ret, 0);
}
/**
* @tc.name : dynlink_test_0040
* @tc.desc : dlns_set_namespace_separated test
* @tc.level : Level 2
*/
static void dynlink_test_0040(void)
{
int ret = dlns_set_namespace_separated(NULL, true);
EXPECT_EQ(dynlink_test_0040, ret, EINVAL);
}
/**
* @tc.name : dynlink_test_0050
* @tc.desc : dlns_set_namespace_separated test
* @tc.level : Level 2
*/
static void dynlink_test_0050(void)
{
int ret = dlns_set_namespace_separated("abc", true);
EXPECT_EQ(dynlink_test_0050, ret, ENOKEY);
}
/**
* @tc.name : dynlink_test_0060
* @tc.desc : dlns_set_namespace_separated test
* @tc.level : Level 0
*/
static void dynlink_test_0060(void)
{
int ret = dlns_set_namespace_separated("default", true);
EXPECT_EQ(dynlink_test_0060, ret, 0);
}
/**
* @tc.name : dynlink_test_0070
* @tc.desc : dlns_set_namespace_permitted_paths test
* @tc.level : Level 2
*/
static void dynlink_test_0070(void)
{
int ret = dlns_set_namespace_permitted_paths(NULL, NULL);
EXPECT_EQ(dynlink_test_0070, ret, EINVAL);
}
/**
* @tc.name : dynlink_test_0080
* @tc.desc : dlns_set_namespace_permitted_paths test
* @tc.level : Level 2
*/
static void dynlink_test_0080(void)
{
int ret = dlns_set_namespace_permitted_paths("abc", "abc");
EXPECT_EQ(dynlink_test_0080, ret, ENOKEY);
}
/**
* @tc.name : dynlink_test_0090
* @tc.desc : dlns_set_namespace_permitted_paths test
* @tc.level : Level 0
*/
static void dynlink_test_0090(void)
{
int ret = dlns_set_namespace_permitted_paths("default", "/data");
EXPECT_EQ(dynlink_test_0090, ret, 0);
}
/**
* @tc.name : dynlink_test_0100
* @tc.desc : dlns_set_namespace_allowed_libs test
* @tc.level : Level 2
*/
static void dynlink_test_0100(void)
{
int ret = dlns_set_namespace_allowed_libs(NULL, NULL);
EXPECT_EQ(dynlink_test_0100, ret, EINVAL);
}
/**
* @tc.name : dynlink_test_0110
* @tc.desc : dlns_set_namespace_allowed_libs test
* @tc.level : Level 2
*/
static void dynlink_test_0110(void)
{
int ret = dlns_set_namespace_allowed_libs("abc", "abc");
EXPECT_EQ(dynlink_test_0110, ret, ENOKEY);
}
/**
* @tc.name : dynlink_test_0120
* @tc.desc : dlns_set_namespace_allowed_libs test
* @tc.level : Level 0
*/
static void dynlink_test_0120(void)
{
int ret = dlns_set_namespace_allowed_libs("default", "/data");
EXPECT_EQ(dynlink_test_0120, ret, 0);
}
TEST_FUN G_Fun_Array[] = {
dynlink_test_0010,
dynlink_test_0020,
dynlink_test_0030,
dynlink_test_0040,
dynlink_test_0050,
dynlink_test_0060,
dynlink_test_0070,
dynlink_test_0080,
dynlink_test_0090,
dynlink_test_0100,
dynlink_test_0110,
dynlink_test_0120,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
return t_status;
}
\ No newline at end of file
/**
* 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.
*/
#include "test.h"
#include "ld_log.h"
#include "functionalext.h"
typedef void (*TEST_FUN)(void);
/**
* @tc.name : strops_test_0010
* @tc.desc : strlwc test args null
* @tc.level : Level 0
*/
static void ld_log_test_0010(void)
{
ld_log_reset();
EXPECT_TRUE(ld_log_test_0010, true);
}
TEST_FUN G_Fun_Array[] = {
ld_log_test_0010,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
return t_status;
}
\ No newline at end of file
/**
* 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.
*/
#include "test.h"
#include "namespace.h"
#include "functionalext.h"
typedef void (*TEST_FUN)(void);
struct dso {
char* name;
};
/**
* @tc.name : namespace_test_0010
* @tc.desc : ns_free test arg is null
* @tc.level : Level 2
*/
static void namespace_test_0010(void)
{
ns_free(NULL);
EXPECT_TRUE(namespace_test_0010, true);
}
/**
* @tc.name : namespace_test_0020
* @tc.desc : ns_free test
* @tc.level : Level 0
*/
static void namespace_test_0020(void)
{
ns_t ns;
int tmp = 1;
ns.ns_dsos = (dsolist*)&tmp;
ns.ns_name = (char*)&tmp;
ns.env_paths = (char*)&tmp;
ns.lib_paths = (char*)&tmp;
ns.asan_lib_paths = (char*)&tmp;
ns.permitted_paths = NULL;
ns.asan_permitted_paths = NULL;
ns.allowed_libs = NULL;
ns_inherit_list list;
list.num = 1;
ns_inherit inherit;
inherit.shared_libs = NULL;
ns_inherit* pInherit = &inherit;
list.inherits = &pInherit;
ns.ns_inherits = &list;
ns_free(&ns);
EXPECT_TRUE(namespace_test_0020, true);
}
/**
* @tc.name : namespace_test_0030
* @tc.desc : ns_free test
* @tc.level : Level 2
*/
static void namespace_test_0030(void)
{
ns_t ns;
ns.ns_dsos = NULL;
ns.ns_name = NULL;
ns.env_paths = NULL;
ns.lib_paths = NULL;
ns.asan_lib_paths = NULL;
ns.permitted_paths = NULL;
ns.asan_permitted_paths = NULL;
ns.allowed_libs = NULL;
ns.ns_inherits = NULL;
ns_free(&ns);
EXPECT_TRUE(namespace_test_0030, true);
}
/**
* @tc.name : namespace_test_0040
* @tc.desc : ns_add_dso test
* @tc.level : Level 2
*/
static void namespace_test_0040(void)
{
ns_add_dso(NULL, NULL);
EXPECT_TRUE(namespace_test_0040, true);
}
/**
* @tc.name : namespace_test_0050
* @tc.desc : ns_add_dso test
* @tc.level : Level 2
*/
static void namespace_test_0050(void)
{
ns_t ns;
ns_add_dso(&ns, NULL);
EXPECT_TRUE(namespace_test_0050, true);
}
/**
* @tc.name : namespace_test_0060
* @tc.desc : ns_add_dso test
* @tc.level : Level 2
*/
static void namespace_test_0060(void)
{
struct dso d;
ns_add_dso(NULL, &d);
EXPECT_TRUE(namespace_test_0060, true);
}
/**
* @tc.name : namespace_test_0070
* @tc.desc : ns_add_dso test
* @tc.level : Level 1
*/
static void namespace_test_0070(void)
{
ns_t ns;
struct dso d;
dsolist list;
list.num = 1;
list.size = 1;
ns.ns_dsos = &list;
ns_add_dso(&ns, &d);
EXPECT_EQ(namespace_test_0070, list.size, 2);
}
/**
* @tc.name : namespace_test_0080
* @tc.desc : nslist_add_ns test
* @tc.level : Level 1
*/
static void namespace_test_0080(void)
{
ns_t ns;
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
nslist_add_ns(&ns);
EXPECT_TRUE(namespace_test_0080, true);
}
/**
* @tc.name : namespace_test_0090
* @tc.desc : nslist_add_ns test
* @tc.level : Level 2
*/
static void namespace_test_0090(void)
{
nslist_add_ns(NULL);
EXPECT_TRUE(namespace_test_0090, true);
}
/**
* @tc.name : namespace_test_0100
* @tc.desc : ns_set_name test
* @tc.level : Level 2
*/
static void namespace_test_0100(void)
{
ns_set_name(NULL, NULL);
EXPECT_TRUE(namespace_test_0100, true);
}
/**
* @tc.name : namespace_test_0110
* @tc.desc : ns_set_name test
* @tc.level : Level 2
*/
static void namespace_test_0110(void)
{
ns_t ns;
ns_set_name(&ns, NULL);
EXPECT_TRUE(namespace_test_0110, true);
}
/**
* @tc.name : namespace_test_0120
* @tc.desc : ns_set_name test
* @tc.level : Level 2
*/
static void namespace_test_0120(void)
{
ns_set_name(NULL, "abc");
EXPECT_TRUE(namespace_test_0120, true);
}
/**
* @tc.name : namespace_test_0130
* @tc.desc : ns_set_env_paths test
* @tc.level : Level 2
*/
static void namespace_test_0130(void)
{
ns_set_env_paths(NULL, "abc");
EXPECT_TRUE(namespace_test_0130, true);
}
/**
* @tc.name : namespace_test_0140
* @tc.desc : ns_set_env_paths test
* @tc.level : Level 1
*/
static void namespace_test_0140(void)
{
ns_t ns;
ns.env_paths = NULL;
ns_set_env_paths(&ns, "abc");
EXPECT_EQ(namespace_test_0140, strcmp(ns.env_paths, "abc"), 0);
}
/**
* @tc.name : namespace_test_0150
* @tc.desc : ns_set_env_paths test
* @tc.level : Level 1
*/
static void namespace_test_0150(void)
{
ns_t ns;
ns.env_paths = "abc";
ns_set_env_paths(&ns, "abc");
EXPECT_EQ(namespace_test_0150, strcmp(ns.env_paths, "abc"), 0);
}
/**
* @tc.name : namespace_test_0160
* @tc.desc : ns_set_env_paths test
* @tc.level : Level 2
*/
static void namespace_test_0160(void)
{
ns_t ns;
ns.env_paths = NULL;
ns_set_env_paths(&ns, NULL);
EXPECT_EQ(namespace_test_0160, ns.env_paths, NULL);
}
/**
* @tc.name : namespace_test_0170
* @tc.desc : ns_set_env_paths test
* @tc.level : Level 2
*/
static void namespace_test_0170(void)
{
ns_t ns;
ns.env_paths = "abc";
ns_set_env_paths(&ns, NULL);
EXPECT_EQ(namespace_test_0170, ns.env_paths, NULL);
}
/**
* @tc.name : namespace_test_0180
* @tc.desc : ns_set_asan_lib_paths test
* @tc.level : Level 2
*/
static void namespace_test_0180(void)
{
ns_set_asan_lib_paths(NULL, "abc");
EXPECT_TRUE(namespace_test_0180, true);
}
/**
* @tc.name : namespace_test_0190
* @tc.desc : ns_set_asan_lib_paths test
* @tc.level : Level 1
*/
static void namespace_test_0190(void)
{
ns_t ns;
ns.asan_lib_paths = NULL;
ns_set_asan_lib_paths(&ns, "abc");
EXPECT_EQ(namespace_test_0190, strcmp(ns.asan_lib_paths, "abc"), 0);
}
/**
* @tc.name : namespace_test_0200
* @tc.desc : ns_set_asan_lib_paths test
* @tc.level : Level 1
*/
static void namespace_test_0200(void)
{
ns_t ns;
ns.asan_lib_paths = "abc";
ns_set_asan_lib_paths(&ns, "abc");
EXPECT_EQ(namespace_test_0200, strcmp(ns.asan_lib_paths, "abc"), 0);
}
/**
* @tc.name : namespace_test_0210
* @tc.desc : ns_set_asan_lib_paths test
* @tc.level : Level 2
*/
static void namespace_test_0210(void)
{
ns_t ns;
ns.asan_lib_paths = NULL;
ns_set_asan_lib_paths(&ns, NULL);
EXPECT_EQ(namespace_test_0210, ns.asan_lib_paths, NULL);
}
/**
* @tc.name : namespace_test_0220
* @tc.desc : ns_set_asan_lib_paths test
* @tc.level : Level 1
*/
static void namespace_test_0220(void)
{
ns_t ns;
ns.asan_lib_paths = "abc";
ns_set_asan_lib_paths(&ns, NULL);
EXPECT_EQ(namespace_test_0220, ns.asan_lib_paths, NULL);
}
/**
* @tc.name : namespace_test_0230
* @tc.desc : ns_set_permitted_paths test
* @tc.level : Level 1
*/
static void namespace_test_0230(void)
{
ns_t ns;
strlist list;
ns.permitted_paths = &list;
ns_set_permitted_paths(&ns, NULL);
EXPECT_EQ(namespace_test_0230, ns.permitted_paths, NULL);
}
/**
* @tc.name : namespace_test_0240
* @tc.desc : ns_set_permitted_paths test
* @tc.level : Level 2
*/
static void namespace_test_0240(void)
{
ns_set_permitted_paths(NULL, NULL);
EXPECT_TRUE(namespace_test_0240, true);
}
/**
* @tc.name : namespace_test_0250
* @tc.desc : ns_set_permitted_paths test
* @tc.level : Level 2
*/
static void namespace_test_0250(void)
{
ns_t ns;
ns.permitted_paths = NULL;
ns_set_permitted_paths(&ns, NULL);
EXPECT_EQ(namespace_test_0250, ns.permitted_paths, NULL);
}
/**
* @tc.name : namespace_test_0260
* @tc.desc : ns_set_asan_permitted_paths test
* @tc.level : Level 1
*/
static void namespace_test_0260(void)
{
ns_t ns;
strlist list;
ns.asan_permitted_paths = &list;
ns_set_asan_permitted_paths(&ns, NULL);
EXPECT_EQ(namespace_test_0260, ns.asan_permitted_paths, NULL);
}
/**
* @tc.name : namespace_test_0270
* @tc.desc : ns_set_asan_permitted_paths test
* @tc.level : Level 2
*/
static void namespace_test_0270(void)
{
ns_set_asan_permitted_paths(NULL, NULL);
EXPECT_TRUE(namespace_test_0270, true);
}
/**
* @tc.name : namespace_test_0280
* @tc.desc : ns_set_asan_permitted_paths test
* @tc.level : Level 1
*/
static void namespace_test_0280(void)
{
ns_t ns;
ns.asan_permitted_paths = NULL;
ns_set_asan_permitted_paths(&ns, NULL);
EXPECT_EQ(namespace_test_0280, ns.asan_permitted_paths, NULL);
}
/**
* @tc.name : namespace_test_0290
* @tc.desc : ns_set_separated test
* @tc.level : Level 2
*/
static void namespace_test_0290(void)
{
ns_set_separated(NULL, false);
EXPECT_TRUE(namespace_test_0290, true);
}
/**
* @tc.name : namespace_test_0300
* @tc.desc : ns_set_allowed_libs test
* @tc.level : Level 2
*/
static void namespace_test_0300(void)
{
ns_set_allowed_libs(NULL, "abc");
EXPECT_TRUE(namespace_test_0300, true);
}
/**
* @tc.name : namespace_test_0310
* @tc.desc : ns_set_allowed_libs test
* @tc.level : Level 1
*/
static void namespace_test_0310(void)
{
ns_t ns;
ns.allowed_libs = NULL;
ns_set_allowed_libs(&ns, "abc");
EXPECT_EQ(namespace_test_0310, (ns.allowed_libs != NULL), true);
}
/**
* @tc.name : namespace_test_0320
* @tc.desc : ns_set_allowed_libs test
* @tc.level : Level 0
*/
static void namespace_test_0320(void)
{
ns_t ns;
strlist list;
ns.allowed_libs = &list;
ns_set_allowed_libs(&ns, "abc");
EXPECT_EQ(namespace_test_0320, (ns.allowed_libs != NULL), true);
}
/**
* @tc.name : namespace_test_0330
* @tc.desc : ns_set_allowed_libs test
* @tc.level : Level 1
*/
static void namespace_test_0330(void)
{
ns_t ns;
ns.allowed_libs = NULL;
ns_set_allowed_libs(&ns, NULL);
EXPECT_EQ(namespace_test_0330, ns.allowed_libs, NULL);
}
/**
* @tc.name : namespace_test_0400
* @tc.desc : ns_set_allowed_libs test
* @tc.level : Level 1
*/
static void namespace_test_0400(void)
{
ns_t ns;
strlist list;
ns.allowed_libs = &list;
ns_set_allowed_libs(&ns, NULL);
EXPECT_EQ(namespace_test_0400, ns.allowed_libs, NULL);
}
/**
* @tc.name : namespace_test_0340
* @tc.desc : ns_add_inherit test
* @tc.level : Level 2
*/
static void namespace_test_0340(void)
{
ns_t ns;
ns_add_inherit(&ns, NULL, NULL);
EXPECT_TRUE(namespace_test_0340, true);
}
/**
* @tc.name : namespace_test_0350
* @tc.desc : ns_add_inherit test
* @tc.level : Level 2
*/
static void namespace_test_0350(void)
{
ns_add_inherit(NULL, NULL, NULL);
EXPECT_TRUE(namespace_test_0350, true);
}
/**
* @tc.name : namespace_test_0360
* @tc.desc : ns_add_inherit test
* @tc.level : Level 2
*/
static void namespace_test_0360(void)
{
ns_t ns;
ns_add_inherit(NULL, &ns, NULL);
EXPECT_TRUE(namespace_test_0360, true);
}
/**
* @tc.name : namespace_test_0370
* @tc.desc : is_accessible test
* @tc.level : Level 1
*/
static void namespace_test_0370(void)
{
ns_t ns;
ns.separated = true;
bool ret = is_accessible(&ns, NULL , true, true);
EXPECT_EQ(namespace_test_0370, ret, false);
}
/**
* @tc.name : namespace_test_0380
* @tc.desc : is_accessible test
* @tc.level : Level 1
*/
static void namespace_test_0380(void)
{
ns_t ns;
ns.separated = false;
bool ret = is_accessible(&ns, NULL, true, false);
EXPECT_EQ(namespace_test_0380, ret, false);
}
/**
* @tc.name : namespace_test_0390
* @tc.desc : is_accessible test
* @tc.level : Level 1
*/
static void namespace_test_0390(void)
{
ns_t ns;
ns.separated = false;
strlist list;
list.num = 1;
char *name = "test.so";
list.strs = &name;
ns.allowed_libs = &list;
ns.env_paths = NULL;
ns.lib_paths = NULL;
ns.asan_lib_paths = NULL;
ns.asan_permitted_paths = NULL;
ns.permitted_paths = NULL;
bool ret = is_accessible(&ns, "/data/test.so", true, false);
EXPECT_EQ(namespace_test_0390, ret, false);
}
/**
* @tc.name : namespace_test_0410
* @tc.desc : is_sharable test
* @tc.level : Level 0
*/
static void namespace_test_0410(void)
{
bool ret = is_sharable(NULL, NULL);
EXPECT_EQ(namespace_test_0410, ret, true);
}
TEST_FUN G_Fun_Array[] = {
namespace_test_0010,
namespace_test_0020,
namespace_test_0030,
namespace_test_0040,
namespace_test_0050,
namespace_test_0060,
namespace_test_0070,
namespace_test_0080,
namespace_test_0090,
namespace_test_0100,
namespace_test_0110,
namespace_test_0120,
namespace_test_0130,
namespace_test_0140,
namespace_test_0150,
namespace_test_0160,
namespace_test_0170,
namespace_test_0180,
namespace_test_0190,
namespace_test_0200,
namespace_test_0210,
namespace_test_0220,
namespace_test_0230,
namespace_test_0250,
namespace_test_0260,
namespace_test_0270,
namespace_test_0280,
namespace_test_0290,
namespace_test_0300,
namespace_test_0310,
namespace_test_0320,
namespace_test_0330,
namespace_test_0340,
namespace_test_0350,
namespace_test_0360,
namespace_test_0370,
namespace_test_0380,
namespace_test_0390,
namespace_test_0400,
namespace_test_0410,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
return t_status;
}
/**
* 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.
*/
#include "test.h"
#include "ns_config.h"
#include "functionalext.h"
typedef void (*TEST_FUN)(void);
/**
* @tc.name : ns_config_0010
* @tc.desc : test error config
* @tc.level : Level 1
*/
static void ns_config_test_0010(void)
{
ns_configor* configor = NULL;
configor = configor_init();
configor->set_error_callback(NULL);
configor_free();
EXPECT_TRUE(ns_config_test_0010, true);
}
int errorback(const char* format, ...)
{
return 0;
}
/**
* @tc.name : ns_config_0030
* @tc.desc : test error config
* @tc.level : Level 0
*/
static void ns_config_test_0020(void)
{
ns_configor* configor = NULL;
configor = configor_init();
configor->set_error_callback(&errorback);
configor_free();
EXPECT_TRUE(ns_config_test_0020, true);
}
/**
* @tc.name : ns_config_0030
* @tc.desc : test parse config
* @tc.level : Level 2
*/
static void ns_config_test_0030(void)
{
ns_configor* configor = NULL;
configor = configor_init();
configor->set_error_callback(NULL);
int ret = configor->parse("ttttttttt.txt", "ttttttttt");
configor_free();
EXPECT_EQ(ns_config_test_0030, ret, -2);
}
/**
* @tc.name : ns_config_0040
* @tc.desc : test get_namespaces
* @tc.level : Level 2
*/
static void ns_config_test_0040(void)
{
ns_configor* configor = NULL;
configor = configor_init();
strlist *ret = configor->get_namespaces();
configor_free();
EXPECT_EQ(ns_config_test_0040, ret, NULL);
}
/**
* @tc.name : ns_config_0050
* @tc.desc : test get_namespaces
* @tc.level : Level 2
*/
static void ns_config_test_0050(void)
{
ns_configor* configor = NULL;
configor = configor_init();
kvlist kv;
kv.num = 1;
char *key = "a";
char *val = "b";
kv.key = &key;
kv.val = &val;
configor->kvs = &kv;
strlist *ret = configor->get_namespaces();
configor_free();
EXPECT_EQ(ns_config_test_0050, ret, NULL);
}
/**
* @tc.name : ns_config_0060
* @tc.desc : test get_namespaces
* @tc.level : Level 2
*/
static void ns_config_test_0060(void)
{
ns_configor* configor = NULL;
configor = configor_init();
kvlist kv;
kv.num = 1;
char *key = "added.nslist";
char *val = "b";
kv.key = &key;
kv.val = &val;
configor->kvs = &kv;
strlist *ret = configor->get_namespaces();
configor_free();
EXPECT_EQ(ns_config_test_0060, ret, NULL);
}
/**
* @tc.name : ns_config_0070
* @tc.desc : test get_lib_paths
* @tc.level : Level 2
*/
static void ns_config_test_0070(void)
{
ns_configor* configor = NULL;
configor = configor_init();
char* ret = configor->get_lib_paths(NULL);
configor_free();
EXPECT_EQ(ns_config_test_0070, ret, NULL);
}
/**
* @tc.name : ns_config_0080
* @tc.desc : test get_lib_paths
* @tc.level : Level 2
*/
static void ns_config_test_0080(void)
{
ns_configor* configor = NULL;
configor = configor_init();
char* ret = configor->get_lib_paths("test");
configor_free();
EXPECT_EQ(ns_config_test_0080, ret, NULL);
}
/**
* @tc.name : ns_config_0090
* @tc.desc : test get_asan_lib_paths
* @tc.level : Level 2
*/
static void ns_config_test_0090(void)
{
ns_configor* configor = NULL;
configor = configor_init();
char* ret = configor->get_asan_lib_paths(NULL);
configor_free();
EXPECT_EQ(ns_config_test_0090, ret, NULL);
}
/**
* @tc.name : ns_config_0100
* @tc.desc : test get_asan_lib_paths
* @tc.level : Level 2
*/
static void ns_config_test_0100(void)
{
ns_configor* configor = NULL;
configor = configor_init();
char* ret = configor->get_asan_lib_paths("test");
configor_free();
EXPECT_EQ(ns_config_test_0100, ret, NULL);
}
TEST_FUN G_Fun_Array[] = {
ns_config_test_0010,
ns_config_test_0020,
ns_config_test_0030,
ns_config_test_0040,
ns_config_test_0050,
ns_config_test_0060,
ns_config_test_0070,
ns_config_test_0080,
ns_config_test_0090,
ns_config_test_0100,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
return t_status;
}
\ No newline at end of file
/**
* 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.
*/
#include <hilog_adapter.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#define SECOND_CALLED 2
static int flag = 0;
bool is_musl_log_enable()
{
return true;
}
int SystemReadParam(char *name, char *buffer, uint32_t *length)
{
flag++;
if (flag == SECOND_CALLED)
{
return 1;
} else {
return 0;
}
}
\ No newline at end of file
/**
* 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.
*/
#include "malloc_impl.h"
static char buf[80] = "abcde";
void *internal_malloc(size_t n)
{
return (void*)buf;
}
void internal_free(void *p)
{}
void *internal_calloc(size_t m, size_t n)
{
return (void*)buf;
}
void *internal_realloc(void* p, size_t n)
{
buf[n+1] = '\0';
return (void*)buf;
}
\ No newline at end of file
/*
* 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.
*/
#include <ctype.h>
#include "strops.h"
/* string to lower */
void strlwc(char *str)
{
if (str == NULL) return;
while (*str != '\0') {
*str = (char)tolower(*str);
str++ ;
}
return;
}
/* trim head and tail spaces of string */
size_t strtrim(char *str)
{
char *last = NULL;
char *dest = str;
if (str == NULL) return 0;
last = str + strlen(str);
while (isspace((int)*str) && *str) str++;
while (last > str) {
if (!isspace((int)*(last-1))) break;
last--;
}
*last = (char)0;
memmove(dest, str, last-str+1);
return last-str;
}
static strlist slist;
static char* list[2];
strlist *strsplit(const char *str, const char *split_s)
{
if(!str) return NULL;
slist.num = 2;
slist.size = 16;
slist.strs = list;
slist.strs[0] = "/data/test";
slist.strs[1] = "/etc";
return &slist;
}
#define STR_DEFAULT_SIZE 16
strlist *strlist_alloc(size_t size)
{
return NULL;
}
static void strlist_realloc(strlist *strs)
{
}
void strlist_free(strlist *strs)
{
}
void strlist_set(strlist *strs,const char *str)
{
if (!strs || !str) return;
if (strs->num == strs->size) {
strlist_realloc(strs);
}
if (strs->num < strs->size) {
strs->strs[strs->num] = ld_strdup(str);
if (strs->strs[strs->num]) strs->num++;
}
}
static char starupbuf[80];
char *ld_strdup(const char *s)
{
size_t l = strlen(s);
return memcpy(starupbuf, s, l+1);
}
\ No newline at end of file
......@@ -20,6 +20,8 @@ musl_lib_dir =
test_lib_dir = "musl/libc-test-lib"
musl_src_base = "${root_out_dir}/obj/${musl_base_dir}/${musl_ported_dir}"
template("test_unittest") {
assert(defined(invoker.target_name),
"file name is required in target ${target_name}")
......
......@@ -69,3 +69,8 @@ declare_args() {
product_path = ""
}
}
declare_args() {
# for unit test
musl_unit_test_flag = false
}
......@@ -714,6 +714,10 @@ template("musl_libs") {
defines = [ "OHOS_ENABLE_PARAMETER" ]
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
}
if(musl_unit_test_flag){
defines += [ "UNIT_TEST_STATIC" ]
}
configs -= musl_inherited_configs
......
......@@ -36,6 +36,12 @@ which need be escaped.
#include <malloc.h>
#include "musl_log.h"
#ifdef UNIT_TEST_STATIC
#define UT_STATIC
#else
#define UT_STATIC static
#endif
void* ohos_malloc_hook_init_function(size_t bytes);
static struct MallocDispatchType __ohos_malloc_hook_init_dispatch = {
......@@ -79,7 +85,7 @@ static void get_native_hook_param(char *buf, unsigned int buf_len)
#endif
}
static void get_memleak_hook_param()
UT_STATIC void get_memleak_hook_param()
{
#ifdef OHOS_ENABLE_PARAMETER
const char *key = kMemTrackPropertyEnable;
......@@ -94,7 +100,7 @@ static void get_memleak_hook_param()
#endif
}
static int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
UT_STATIC int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
{
if (!mode || !path || size <= 0) {
return -1;
......@@ -145,7 +151,7 @@ static int parse_hook_variable(enum EnumHookMode* mode, char* path, int size)
return 0;
}
static bool get_proc_name(pid_t pid, char *buf, unsigned int buf_len)
UT_STATIC bool get_proc_name(pid_t pid, char *buf, unsigned int buf_len)
{
if (pid <= 0) {
return false;
......@@ -282,7 +288,7 @@ static bool init_hook_functions(void* shared_library_handler, struct MallocDispa
return true;
}
static void clear_function_table()
UT_STATIC void clear_function_table()
{
for (size_t i = 0; i < LAST_FUNCTION; i++) {
function_of_shared_lib[i] = NULL;
......@@ -469,7 +475,7 @@ static void __set_default_malloc()
atomic_store_explicit(&__musl_libc_globals.current_dispatch_table, (volatile const long long)NULL, memory_order_seq_cst);
}
static void __restore_hook_function_table()
UT_STATIC void __restore_hook_function_table()
{
for (size_t i = 0; i < LAST_FUNCTION; i++) {
if (__get_memleak_hook_flag()) {
......@@ -480,7 +486,7 @@ static void __restore_hook_function_table()
}
}
static void __install_malloc_hook()
UT_STATIC void __install_malloc_hook()
{
if (__get_memleak_hook_flag()) {
return;
......
......@@ -20,7 +20,9 @@
#include <stdarg.h>
#include <stdbool.h>
#ifndef hidden
#define hidden __attribute__((visibility("hidden")))
#endif
// Log type
typedef enum {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册