提交 87406405 编写于 作者: D dhy308 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/third_party_musl into release_sigchain_0113

Issue: I6AEEI
Test: Build & Boot Devices
Signed-off-by: Ndhy308 <tony.gan@huawei.com>
...@@ -78,3 +78,36 @@ config("config_runtest") { ...@@ -78,3 +78,36 @@ config("config_runtest") {
libs = [ "//${target_out_dir}/libtest.a" ] 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) ...@@ -26,6 +26,9 @@ int main(int argc, char **argv)
char set_thread_name[] = "THREADFOO"; char set_thread_name[] = "THREADFOO";
char default_name[] = "pthread_getname"; char default_name[] = "pthread_getname";
rc = pthread_getname_np(pthread_self(), thread_name, NAMELEN-1);
if (rc != ERANGE) errExitEN(rc, "pthread_getname_np(invalid args[len]) failed");
rc = pthread_getname_np(pthread_self(), thread_name, NAMELEN); rc = pthread_getname_np(pthread_self(), thread_name, NAMELEN);
if (rc != 0) errExitEN(rc, "pthread_getname_np failed"); if (rc != 0) errExitEN(rc, "pthread_getname_np failed");
if(strcmp(thread_name, default_name) != 0) perror("pthread name comparison failed"); if(strcmp(thread_name, default_name) != 0) perror("pthread name comparison failed");
......
...@@ -18,10 +18,19 @@ ...@@ -18,10 +18,19 @@
#include <string.h> #include <string.h>
#include <sys/wait.h> #include <sys/wait.h>
#include "fortify_test.h" #include "fortify_test.h"
#include "functionalext.h"
#include "test.h" #include "test.h"
#define FILE_MODE_ALL (0777) #define FILE_MODE_ALL (0777)
#ifdef open64
#undef open64
#endif
#ifdef openat64
#undef openat64
#endif
/** /**
* @tc.name : open_0010 * @tc.name : open_0010
* @tc.desc : test open normal condition * @tc.desc : test open normal condition
...@@ -104,6 +113,19 @@ static void open_0030(void) ...@@ -104,6 +113,19 @@ static void open_0030(void)
return; 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);
EXPECT_NE(open_0040, fd, -1);
close(fd);
return;
}
/** /**
* @tc.name : openat_0010 * @tc.name : openat_0010
...@@ -187,6 +209,20 @@ static void openat_0030(void) ...@@ -187,6 +209,20 @@ static void openat_0030(void)
return; 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);
EXPECT_NE(openat_0040, fd, -1);
close(fd);
return;
}
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
/** /**
* @tc.name : open64_0010 * @tc.name : open64_0010
...@@ -270,6 +306,19 @@ static void open64_0030(void) ...@@ -270,6 +306,19 @@ static void open64_0030(void)
return; 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);
EXPECT_NE(open64_0040, fd, -1);
close(fd);
return;
}
/** /**
* @tc.name : openat64_0010 * @tc.name : openat64_0010
...@@ -352,22 +401,40 @@ static void openat64_0030(void) ...@@ -352,22 +401,40 @@ static void openat64_0030(void)
return; 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);
EXPECT_NE(openat64_0040, fd, -1);
close(fd);
return;
}
#endif #endif
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
open_0010(); open_0010();
open_0020(); open_0020();
open_0030(); open_0030();
open_0040();
openat_0010(); openat_0010();
openat_0020(); openat_0020();
openat_0030(); openat_0030();
openat_0040();
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
open64_0010(); open64_0010();
open64_0020(); open64_0020();
open64_0030(); open64_0030();
open64_0040();
openat64_0010(); openat64_0010();
openat64_0020(); openat64_0020();
openat64_0030(); openat64_0030();
openat64_0040();
#endif #endif
return t_status; return t_status;
} }
\ No newline at end of file
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <string.h> #include <string.h>
#include <sys/wait.h> #include <sys/wait.h>
#include "fortify_test.h" #include "fortify_test.h"
#include "functionalext.h"
#include "test.h" #include "test.h"
#define PPOLL_TIMESPEC_NSEC (100) #define PPOLL_TIMESPEC_NSEC (100)
...@@ -73,6 +74,20 @@ static void poll_0020(void) ...@@ -73,6 +74,20 @@ static void poll_0020(void)
return; return;
} }
/**
* @tc.name : poll_0030
* @tc.desc : test poll with buf's size greater than fd_count, return fd_count
* @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}};
EXPECT_EQ(poll_0030, poll(buf, fd_count, 1), 1);
return;
}
#ifdef _GNU_SOURCE #ifdef _GNU_SOURCE
/** /**
* @tc.name : ppoll_0010 * @tc.name : ppoll_0010
...@@ -126,14 +141,31 @@ static void ppoll_0020(void) ...@@ -126,14 +141,31 @@ static void ppoll_0020(void)
return; return;
} }
/**
* @tc.name : ppoll_0030
* @tc.desc : test poll with buf's size greater than fd_count, return fd_count
* @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 };
EXPECT_EQ(ppoll_0030, ppoll(buf, fd_count, &ts, NULL), 1);
return;
}
#endif #endif
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
poll_0010(); poll_0010();
poll_0020(); poll_0020();
poll_0030();
#ifdef _GNU_SOURCE #ifdef _GNU_SOURCE
ppoll_0010(); ppoll_0010();
ppoll_0020(); ppoll_0020();
ppoll_0030();
#endif #endif
return t_status; return t_status;
......
...@@ -56,6 +56,7 @@ static void stdio_dynamic_chk_001(void) ...@@ -56,6 +56,7 @@ static void stdio_dynamic_chk_001(void)
EXPECT_STREQ(hello_world, buf); EXPECT_STREQ(hello_world, buf);
fclose(fp); fclose(fp);
return;
} }
/** /**
...@@ -89,7 +90,7 @@ static void stdio_dynamic_chk_002(void) ...@@ -89,7 +90,7 @@ static void stdio_dynamic_chk_002(void)
for (size_t i = read_size; i < bufferSize; ++i) { for (size_t i = read_size; i < bufferSize; ++i) {
EXPECT_EQ('\xff', buf[i]); EXPECT_EQ('\xff', buf[i]);
} }
return;
} }
/** /**
...@@ -117,7 +118,7 @@ static void stdio_dynamic_chk_003(void) ...@@ -117,7 +118,7 @@ static void stdio_dynamic_chk_003(void)
break; break;
case 0: case 0:
fread(buf, 1, ct, fp); fread(buf, 1, ct, fp);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -127,6 +128,7 @@ static void stdio_dynamic_chk_003(void) ...@@ -127,6 +128,7 @@ static void stdio_dynamic_chk_003(void)
break; break;
} }
fclose(fp); fclose(fp);
return;
} }
/** /**
...@@ -155,7 +157,7 @@ static void stdio_dynamic_chk_004(void) ...@@ -155,7 +157,7 @@ static void stdio_dynamic_chk_004(void)
break; break;
case 0: case 0:
fwrite(buf, 1, ct, fp); fwrite(buf, 1, ct, fp);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -165,6 +167,7 @@ static void stdio_dynamic_chk_004(void) ...@@ -165,6 +167,7 @@ static void stdio_dynamic_chk_004(void)
break; break;
} }
fclose(fp); fclose(fp);
return;
} }
/** /**
...@@ -184,6 +187,7 @@ static void stdio_dynamic_chk_005(void) ...@@ -184,6 +187,7 @@ static void stdio_dynamic_chk_005(void)
EXPECT_TRUE(get != NULL); EXPECT_TRUE(get != NULL);
EXPECT_TRUE(strcmp(hello_world, get) == 0); EXPECT_TRUE(strcmp(hello_world, get) == 0);
fclose(fp); fclose(fp);
return;
} }
/** /**
...@@ -212,6 +216,7 @@ static void stdio_dynamic_chk_006(void) ...@@ -212,6 +216,7 @@ static void stdio_dynamic_chk_006(void)
EXPECT_TRUE(get3 != NULL); EXPECT_TRUE(get3 != NULL);
EXPECT_TRUE(strcmp("hello boy!", get3) == 0); EXPECT_TRUE(strcmp("hello boy!", get3) == 0);
fclose(fp); fclose(fp);
return;
} }
/** /**
...@@ -240,7 +245,7 @@ static void stdio_dynamic_chk_007(void) ...@@ -240,7 +245,7 @@ static void stdio_dynamic_chk_007(void)
break; break;
case 0: case 0:
fgets(buf, n, fp); fgets(buf, n, fp);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -250,6 +255,7 @@ static void stdio_dynamic_chk_007(void) ...@@ -250,6 +255,7 @@ static void stdio_dynamic_chk_007(void)
break; break;
} }
fclose(fp); fclose(fp);
return;
} }
/** /**
...@@ -262,6 +268,7 @@ static void stdio_dynamic_chk_008(void) ...@@ -262,6 +268,7 @@ static void stdio_dynamic_chk_008(void)
char buf[] = "world"; char buf[] = "world";
sprintf(buf, "hello"); sprintf(buf, "hello");
EXPECT_TRUE(strcmp(buf, "hello") == 0); EXPECT_TRUE(strcmp(buf, "hello") == 0);
return;
} }
/** /**
...@@ -277,6 +284,7 @@ static void stdio_dynamic_chk_009(void) ...@@ -277,6 +284,7 @@ static void stdio_dynamic_chk_009(void)
char value[] = "hello : world!"; char value[] = "hello : world!";
EXPECT_TRUE(strcmp(buf, value) == 0); EXPECT_TRUE(strcmp(buf, value) == 0);
return;
} }
...@@ -303,7 +311,7 @@ static void stdio_dynamic_chk_010(void) ...@@ -303,7 +311,7 @@ static void stdio_dynamic_chk_010(void)
break; break;
case 0: case 0:
sprintf(buf, "hello : %s", "world!"); sprintf(buf, "hello : %s", "world!");
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -312,6 +320,7 @@ static void stdio_dynamic_chk_010(void) ...@@ -312,6 +320,7 @@ static void stdio_dynamic_chk_010(void)
kill(pid, SIGCONT); kill(pid, SIGCONT);
break; break;
} }
return;
} }
/** /**
...@@ -339,7 +348,7 @@ static void stdio_dynamic_chk_011(void) ...@@ -339,7 +348,7 @@ static void stdio_dynamic_chk_011(void)
break; break;
case 0: // 10 > sizeof buf case 0: // 10 > sizeof buf
snprintf(buf, printSize, "hello : %s", "world!"); snprintf(buf, printSize, "hello : %s", "world!");
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -348,6 +357,7 @@ static void stdio_dynamic_chk_011(void) ...@@ -348,6 +357,7 @@ static void stdio_dynamic_chk_011(void)
kill(pid, SIGCONT); kill(pid, SIGCONT);
break; break;
} }
return;
} }
...@@ -394,7 +404,7 @@ static void stdio_dynamic_chk_012(void) ...@@ -394,7 +404,7 @@ static void stdio_dynamic_chk_012(void)
break; break;
case 0: case 0:
vsnprintf_test("hello : %s", "world!"); vsnprintf_test("hello : %s", "world!");
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -403,6 +413,7 @@ static void stdio_dynamic_chk_012(void) ...@@ -403,6 +413,7 @@ static void stdio_dynamic_chk_012(void)
kill(pid, SIGCONT); kill(pid, SIGCONT);
break; break;
} }
return;
} }
/** /**
...@@ -425,7 +436,7 @@ static void stdio_dynamic_chk_013(void) ...@@ -425,7 +436,7 @@ static void stdio_dynamic_chk_013(void)
break; break;
case 0: case 0:
vsprintf_test("%s", "0123456789"); vsprintf_test("%s", "0123456789");
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -434,6 +445,7 @@ static void stdio_dynamic_chk_013(void) ...@@ -434,6 +445,7 @@ static void stdio_dynamic_chk_013(void)
kill(pid, SIGCONT); kill(pid, SIGCONT);
break; break;
} }
return;
} }
int main() int main()
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <string.h> #include <string.h>
#include <sys/wait.h> #include <sys/wait.h>
#include "fortify_test.h" #include "fortify_test.h"
#include "functionalext.h"
#include "test.h" #include "test.h"
#include "../../../../porting/linux/user/include/fortify/fortify.h" #include "../../../../porting/linux/user/include/fortify/fortify.h"
...@@ -852,6 +853,11 @@ static void test_memset_0020() ...@@ -852,6 +853,11 @@ static void test_memset_0020()
return; return;
} }
/**
* @tc.name : test_strlen_0010
* @tc.desc : Ability to test the strlen normal condition
* @tc.level : Level 0
*/
static void test_strlen_0010() static void test_strlen_0010()
{ {
struct sigaction sigabrt = { struct sigaction sigabrt = {
...@@ -881,6 +887,36 @@ static void test_strlen_0010() ...@@ -881,6 +887,36 @@ static void test_strlen_0010()
return; 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);
EXPECT_EQ(test_strlen_0020, WIFEXITED(status), 0);
kill(pid, SIGCONT);
break;
}
return;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
test_strcat_0010(); test_strcat_0010();
test_strcat_0020(); test_strcat_0020();
...@@ -907,7 +943,8 @@ int main(int argc, char *argv[]) { ...@@ -907,7 +943,8 @@ int main(int argc, char *argv[]) {
test_memcpy_0010(); test_memcpy_0010();
test_memcpy_0020(); test_memcpy_0020();
test_strlen_0010(); test_strlen_0010();
test_strlen_0020();
#ifdef _GNU_SOURCE #ifdef _GNU_SOURCE
test_mempcpy_0010(); test_mempcpy_0010();
test_mempcpy_0020(); test_mempcpy_0020();
......
...@@ -46,7 +46,6 @@ static void unistd_dynamic_chk_001(void) ...@@ -46,7 +46,6 @@ static void unistd_dynamic_chk_001(void)
case 0: case 0:
getcwd(buf, n); getcwd(buf, n);
exit(0); exit(0);
break;
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -55,6 +54,7 @@ static void unistd_dynamic_chk_001(void) ...@@ -55,6 +54,7 @@ static void unistd_dynamic_chk_001(void)
kill(pid, SIGCONT); kill(pid, SIGCONT);
break; break;
} }
return;
} }
/** /**
...@@ -84,7 +84,7 @@ static void unistd_dynamic_chk_002(void) ...@@ -84,7 +84,7 @@ static void unistd_dynamic_chk_002(void)
break; break;
case 0: case 0:
pread(fd, buf, n, 0); pread(fd, buf, n, 0);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -94,6 +94,7 @@ static void unistd_dynamic_chk_002(void) ...@@ -94,6 +94,7 @@ static void unistd_dynamic_chk_002(void)
break; break;
} }
close(fd); close(fd);
return;
} }
/** /**
...@@ -123,7 +124,7 @@ static void unistd_dynamic_chk_003(void) ...@@ -123,7 +124,7 @@ static void unistd_dynamic_chk_003(void)
break; break;
case 0: case 0:
pread(fd, buf, n, 0); pread(fd, buf, n, 0);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -133,6 +134,7 @@ static void unistd_dynamic_chk_003(void) ...@@ -133,6 +134,7 @@ static void unistd_dynamic_chk_003(void)
break; break;
} }
close(fd); close(fd);
return;
} }
...@@ -163,7 +165,7 @@ static void unistd_dynamic_chk_004(void) ...@@ -163,7 +165,7 @@ static void unistd_dynamic_chk_004(void)
break; break;
case 0: case 0:
pread64(fd, buf, n, 0); pread64(fd, buf, n, 0);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -173,6 +175,7 @@ static void unistd_dynamic_chk_004(void) ...@@ -173,6 +175,7 @@ static void unistd_dynamic_chk_004(void)
break; break;
} }
close(fd); close(fd);
return;
} }
/** /**
...@@ -202,7 +205,7 @@ static void unistd_dynamic_chk_005(void) ...@@ -202,7 +205,7 @@ static void unistd_dynamic_chk_005(void)
break; break;
case 0: case 0:
pread64(fd, buf, n, 0); pread64(fd, buf, n, 0);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -212,6 +215,7 @@ static void unistd_dynamic_chk_005(void) ...@@ -212,6 +215,7 @@ static void unistd_dynamic_chk_005(void)
break; break;
} }
close(fd); close(fd);
return;
} }
/** /**
...@@ -240,7 +244,7 @@ static void unistd_dynamic_chk_006(void) ...@@ -240,7 +244,7 @@ static void unistd_dynamic_chk_006(void)
break; break;
case 0: case 0:
pwrite64(fd, buf, n, 0); pwrite64(fd, buf, n, 0);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -250,6 +254,7 @@ static void unistd_dynamic_chk_006(void) ...@@ -250,6 +254,7 @@ static void unistd_dynamic_chk_006(void)
break; break;
} }
close(fd); close(fd);
return;
} }
/** /**
...@@ -278,7 +283,7 @@ static void unistd_dynamic_chk_007(void) ...@@ -278,7 +283,7 @@ static void unistd_dynamic_chk_007(void)
break; break;
case 0: case 0:
pwrite64(fd, buf, n, 0); pwrite64(fd, buf, n, 0);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -288,6 +293,7 @@ static void unistd_dynamic_chk_007(void) ...@@ -288,6 +293,7 @@ static void unistd_dynamic_chk_007(void)
break; break;
} }
close(fd); close(fd);
return;
} }
...@@ -318,7 +324,7 @@ static void unistd_dynamic_chk_008(void) ...@@ -318,7 +324,7 @@ static void unistd_dynamic_chk_008(void)
break; break;
case 0: case 0:
pwrite(fd, buf, n, 0); pwrite(fd, buf, n, 0);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -328,6 +334,7 @@ static void unistd_dynamic_chk_008(void) ...@@ -328,6 +334,7 @@ static void unistd_dynamic_chk_008(void)
break; break;
} }
close(fd); close(fd);
return;
} }
/** /**
...@@ -357,7 +364,7 @@ static void unistd_dynamic_chk_009(void) ...@@ -357,7 +364,7 @@ static void unistd_dynamic_chk_009(void)
break; break;
case 0: case 0:
pwrite(fd, buf, n, 0); pwrite(fd, buf, n, 0);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -367,6 +374,7 @@ static void unistd_dynamic_chk_009(void) ...@@ -367,6 +374,7 @@ static void unistd_dynamic_chk_009(void)
break; break;
} }
close(fd); close(fd);
return;
} }
/** /**
...@@ -394,7 +402,7 @@ static void unistd_dynamic_chk_010(void) ...@@ -394,7 +402,7 @@ static void unistd_dynamic_chk_010(void)
break; break;
case 0: case 0:
read(fd, buf, n); read(fd, buf, n);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -404,6 +412,7 @@ static void unistd_dynamic_chk_010(void) ...@@ -404,6 +412,7 @@ static void unistd_dynamic_chk_010(void)
break; break;
} }
close(fd); close(fd);
return;
} }
/** /**
...@@ -431,7 +440,7 @@ static void unistd_dynamic_chk_011(void) ...@@ -431,7 +440,7 @@ static void unistd_dynamic_chk_011(void)
break; break;
case 0: case 0:
read(fd, buf, n); read(fd, buf, n);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -441,6 +450,7 @@ static void unistd_dynamic_chk_011(void) ...@@ -441,6 +450,7 @@ static void unistd_dynamic_chk_011(void)
break; break;
} }
close(fd); close(fd);
return;
} }
/** /**
...@@ -470,7 +480,7 @@ static void unistd_dynamic_chk_012(void) ...@@ -470,7 +480,7 @@ static void unistd_dynamic_chk_012(void)
break; break;
case 0: case 0:
write(fd, buf, n); write(fd, buf, n);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -480,6 +490,7 @@ static void unistd_dynamic_chk_012(void) ...@@ -480,6 +490,7 @@ static void unistd_dynamic_chk_012(void)
break; break;
} }
close(fd); close(fd);
return;
} }
/** /**
...@@ -509,7 +520,7 @@ static void unistd_dynamic_chk_013(void) ...@@ -509,7 +520,7 @@ static void unistd_dynamic_chk_013(void)
break; break;
case 0: case 0:
write(fd, buf, n); write(fd, buf, n);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -519,6 +530,7 @@ static void unistd_dynamic_chk_013(void) ...@@ -519,6 +530,7 @@ static void unistd_dynamic_chk_013(void)
break; break;
} }
close(fd); close(fd);
return;
} }
/** /**
...@@ -546,7 +558,7 @@ static void unistd_dynamic_chk_014(void) ...@@ -546,7 +558,7 @@ static void unistd_dynamic_chk_014(void)
break; break;
case 0: case 0:
readlink(path, buf, n); readlink(path, buf, n);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -555,6 +567,7 @@ static void unistd_dynamic_chk_014(void) ...@@ -555,6 +567,7 @@ static void unistd_dynamic_chk_014(void)
kill(pid, SIGCONT); kill(pid, SIGCONT);
break; break;
} }
return;
} }
/** /**
...@@ -582,7 +595,7 @@ static void unistd_dynamic_chk_015(void) ...@@ -582,7 +595,7 @@ static void unistd_dynamic_chk_015(void)
break; break;
case 0: case 0:
readlink(path, buf, n); readlink(path, buf, n);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -591,6 +604,7 @@ static void unistd_dynamic_chk_015(void) ...@@ -591,6 +604,7 @@ static void unistd_dynamic_chk_015(void)
kill(pid, SIGCONT); kill(pid, SIGCONT);
break; break;
} }
return;
} }
/** /**
* @tc.name : readlinkat * @tc.name : readlinkat
...@@ -618,7 +632,7 @@ static void unistd_dynamic_chk_016(void) ...@@ -618,7 +632,7 @@ static void unistd_dynamic_chk_016(void)
break; break;
case 0: case 0:
readlinkat(AT_FDCWD, path, buf, n); readlinkat(AT_FDCWD, path, buf, n);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -627,6 +641,7 @@ static void unistd_dynamic_chk_016(void) ...@@ -627,6 +641,7 @@ static void unistd_dynamic_chk_016(void)
kill(pid, SIGCONT); kill(pid, SIGCONT);
break; break;
} }
return;
} }
/** /**
...@@ -655,7 +670,7 @@ static void unistd_dynamic_chk_017(void) ...@@ -655,7 +670,7 @@ static void unistd_dynamic_chk_017(void)
break; break;
case 0: case 0:
readlinkat(AT_FDCWD, path, buf, n); readlinkat(AT_FDCWD, path, buf, n);
break; exit(0);
default: default:
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
TEST(WIFEXITED(status) == 0); TEST(WIFEXITED(status) == 0);
...@@ -664,6 +679,7 @@ static void unistd_dynamic_chk_017(void) ...@@ -664,6 +679,7 @@ static void unistd_dynamic_chk_017(void)
kill(pid, SIGCONT); kill(pid, SIGCONT);
break; break;
} }
return;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
......
...@@ -31,6 +31,14 @@ ...@@ -31,6 +31,14 @@
t_error("[%s] failed\n"); \ t_error("[%s] failed\n"); \
} while (0) } while (0)
#define FORK(fpid) \
do \
{ \
if (fpid < 0) { \
t_error("error in fork!");\
} \
} while (0)
typedef void (*TEST_FUN)(void); typedef void (*TEST_FUN)(void);
static const int WAIT_TIME = 1; static const int WAIT_TIME = 1;
...@@ -61,9 +69,8 @@ static void fatal_message_0020(void) ...@@ -61,9 +69,8 @@ static void fatal_message_0020(void)
pid_t fpid; pid_t fpid;
fpid = fork(); fpid = fork();
if (fpid < 0) { FORK(fpid);
t_printf("error in fork!"); if (fpid == 0) {
} else if (fpid == 0) {
pidChild = getpid(); pidChild = getpid();
set_fatal_message(msg); set_fatal_message(msg);
fatal_message = get_fatal_message(); fatal_message = get_fatal_message();
...@@ -96,9 +103,8 @@ static void fatal_message_0030(void) ...@@ -96,9 +103,8 @@ static void fatal_message_0030(void)
// start process // start process
fpid = fork(); fpid = fork();
if (fpid < 0) { FORK(fpid);
t_printf("error in fork!"); if (fpid == 0) {
} else if (fpid == 0) {
pidChild = getpid(); pidChild = getpid();
} else { } else {
pidParent = getpid(); pidParent = getpid();
...@@ -148,9 +154,8 @@ static void fatal_message_0040(void) ...@@ -148,9 +154,8 @@ static void fatal_message_0040(void)
// start process // start process
fpid = fork(); fpid = fork();
if (fpid < 0) { FORK(fpid);
t_printf("error in fork!"); if (fpid == 0) {
} else if (fpid == 0) {
pidChild = getpid(); pidChild = getpid();
} else { } else {
pidParent = getpid(); pidParent = getpid();
...@@ -222,12 +227,37 @@ static void fatal_message_0050(void) ...@@ -222,12 +227,37 @@ static void fatal_message_0050(void)
pthread_join(fatalMessageThread2, NULL); 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 pidChild = 0;
pid_t fpid;
fpid = fork();
FORK(fpid);
if (fpid == 0) {
pidChild = getpid();
set_fatal_message(msg);
fatal_message = get_fatal_message();
EXPECT_TRUE(fatal_message == NULL);
exit(pidChild);
}
}
TEST_FUN G_Fun_Array[] = { TEST_FUN G_Fun_Array[] = {
fatal_message_0010, fatal_message_0010,
fatal_message_0020, fatal_message_0020,
fatal_message_0030, fatal_message_0030,
fatal_message_0040, fatal_message_0040,
fatal_message_0050, fatal_message_0050,
fatal_message_0060,
}; };
int main(void) 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() ...@@ -127,6 +127,23 @@ void nl_langinfo_0500()
EXPECT_STREQ("nl_langinfo_0500", ptr, "UTF-8"); 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) int main(void)
{ {
langinfo_0100(); langinfo_0100();
...@@ -134,5 +151,6 @@ int main(void) ...@@ -134,5 +151,6 @@ int main(void)
nl_langinfo_0300(); nl_langinfo_0300();
nl_langinfo_0400(); nl_langinfo_0400();
nl_langinfo_0500(); nl_langinfo_0500();
nl_langinfo_0600();
return t_status; return t_status;
} }
\ No newline at end of file
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# limitations under the License. # limitations under the License.
functionalext_locale_test = [ functionalext_locale_test = [
"dcngettext",
"duplocale", "duplocale",
"langinfo", "langinfo",
"localeconv", "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 : When param is NULL, call 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) ...@@ -40,8 +40,23 @@ void clone_0100(void)
EXPECT_NE("clone_0100", cpid, -1); 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_0200", cpid, -1);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
clone_0100(); clone_0100();
clone_0200();
return t_status; 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 "functionalext.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);
EXPECT_EQ(getspnam_r_0100, result, 0);
EXPECT_PTRNE(getspnam_r_0100, spwd, NULL);
EXPECT_EQ(getspnam_r_0100, strcmp(spwd_name, spwd->sp_namp), 0);
}
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 = [ ...@@ -22,4 +22,5 @@ functionalext_supplement_passwd_test = [
"getgrouplist", "getgrouplist",
"getgrgid_r", "getgrgid_r",
"getgrnam_r", "getgrnam_r",
"getspnam_r",
] ]
...@@ -26,4 +26,7 @@ functionalext_list = [ ...@@ -26,4 +26,7 @@ functionalext_list = [
"fortify:functionalext_fortify_test", "fortify:functionalext_fortify_test",
"symver:functionalext_symver_test", "symver:functionalext_symver_test",
"sigchain:functionalext_sigchain_test", "sigchain:functionalext_sigchain_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) ...@@ -147,6 +147,19 @@ void pthread_cond_timedwait_monotonic_np_0010(void)
EXPECT_EQ(pthread_mutex_destroy(&mutex), 0); 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.number : pthread_cond_timeout_np_0010
* @tc.desc : Test whether the pthread_cond_timeout_np is normal * @tc.desc : Test whether the pthread_cond_timeout_np is normal
...@@ -707,6 +720,7 @@ TEST_FUN G_Fun_Array[] = { ...@@ -707,6 +720,7 @@ TEST_FUN G_Fun_Array[] = {
pthread_cond_timedwait_0020, pthread_cond_timedwait_0020,
pthread_cond_timedwait_time64_0010, pthread_cond_timedwait_time64_0010,
pthread_cond_timedwait_monotonic_np_0010, pthread_cond_timedwait_monotonic_np_0010,
pthread_cond_timedwait_monotonic_np_0020,
pthread_cond_timeout_np_0010, pthread_cond_timeout_np_0010,
pthread_cond_clockwait_0010, pthread_cond_clockwait_0010,
pthread_cond_timedwait_Time_0010, pthread_cond_timedwait_Time_0010,
......
...@@ -301,6 +301,20 @@ static void pthread_mutex_timedlock_monotonic_np_0020(void) ...@@ -301,6 +301,20 @@ static void pthread_mutex_timedlock_monotonic_np_0020(void)
/********************************************* Test case dividing line ***********************************************/ /********************************************* 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};
EXPECT_EQ(pthread_mutex_timedlock_monotonic_np(mtx, &ts), EINVAL);
}
/********************************************* Test case dividing line ***********************************************/
static void *PthreadLockTimeoutNPOut(void *arg) static void *PthreadLockTimeoutNPOut(void *arg)
{ {
pthread_mutex_t *mtx = (pthread_mutex_t*)arg; pthread_mutex_t *mtx = (pthread_mutex_t*)arg;
...@@ -379,6 +393,7 @@ int main(void) ...@@ -379,6 +393,7 @@ int main(void)
pthread_mutex_clocklock_0060(); pthread_mutex_clocklock_0060();
pthread_mutex_timedlock_monotonic_np_0010(); pthread_mutex_timedlock_monotonic_np_0010();
pthread_mutex_timedlock_monotonic_np_0020(); pthread_mutex_timedlock_monotonic_np_0020();
pthread_mutex_timedlock_monotonic_np_0030();
pthread_mutex_lock_timeout_np_0010(); pthread_mutex_lock_timeout_np_0010();
pthread_mutex_lock_timeout_np_0020(); pthread_mutex_lock_timeout_np_0020();
......
...@@ -269,6 +269,17 @@ static void pthread_rwlock_timedrdlock_monotonic_np_0020(void) ...@@ -269,6 +269,17 @@ static void pthread_rwlock_timedrdlock_monotonic_np_0020(void)
TEST(pthread_rwlock_destroy(&g_rwlock6) == 0); 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};
EXPECT_EQ(pthread_rwlock_timedrdlock_monotonic_np((pthread_rwlock_t *)NULL, &ts), EINVAL);
}
int main(void) int main(void)
{ {
pthread_rwlock_clockrdlock_0010(); pthread_rwlock_clockrdlock_0010();
...@@ -277,6 +288,7 @@ int main(void) ...@@ -277,6 +288,7 @@ int main(void)
pthread_rwlock_clockrdlock_0040(); pthread_rwlock_clockrdlock_0040();
pthread_rwlock_timedrdlock_monotonic_np_0010(); pthread_rwlock_timedrdlock_monotonic_np_0010();
pthread_rwlock_timedrdlock_monotonic_np_0020(); pthread_rwlock_timedrdlock_monotonic_np_0020();
pthread_rwlock_timedrdlock_monotonic_np_0030();
return t_status; return t_status;
} }
\ No newline at end of file
...@@ -328,6 +328,17 @@ void pthread_rwlock_timedwrlock_0100(void) ...@@ -328,6 +328,17 @@ void pthread_rwlock_timedwrlock_0100(void)
EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock4), 0); 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[] = { TEST_FUN G_Fun_Array[] = {
pthread_rwlock_timedwrlock_0010, pthread_rwlock_timedwrlock_0010,
pthread_rwlock_timedwrlock_0020, pthread_rwlock_timedwrlock_0020,
...@@ -339,6 +350,7 @@ TEST_FUN G_Fun_Array[] = { ...@@ -339,6 +350,7 @@ TEST_FUN G_Fun_Array[] = {
pthread_rwlock_timedwrlock_0080, pthread_rwlock_timedwrlock_0080,
pthread_rwlock_timedwrlock_0090, pthread_rwlock_timedwrlock_0090,
pthread_rwlock_timedwrlock_0100, pthread_rwlock_timedwrlock_0100,
pthread_rwlock_timedwrlock_0110,
}; };
int main(void) int main(void)
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <limits.h>
#include "gmtime_data.h" #include "gmtime_data.h"
#include "functionalext.h" #include "functionalext.h"
...@@ -50,8 +51,22 @@ void gmtime_r_0100(void) ...@@ -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) int main(void)
{ {
gmtime_r_0100(); gmtime_r_0100();
gmtime_r_0200();
return t_status; return t_status;
} }
\ No newline at end of file
...@@ -229,6 +229,40 @@ void strptime_0900(void) ...@@ -229,6 +229,40 @@ void strptime_0900(void)
EXPECT_STREQ("strptime_0900", "2021-9-30", buffResult); 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) int main(void)
{ {
strptime_0100(); strptime_0100();
...@@ -240,5 +274,7 @@ int main(void) ...@@ -240,5 +274,7 @@ int main(void)
strptime_0700(); strptime_0700();
strptime_0800(); strptime_0800();
strptime_0900(); strptime_0900();
strptime_1000();
strptime_1100();
return t_status; return t_status;
} }
\ No newline at end of file
# 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("../../../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 = [
"//base/startup/init/services/param/base:parameterbase",
"//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" ]
}
group("functionalext_unittest_test") {
testonly = true
deps = [
":unittest_hilog_adapter",
":unittest_hilog_vsnprint",
":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 <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 <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 : Test dlns_set_namespace_lib_path with invalid input
* @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 : Test dlns_set_namespace_lib_path with invalid input
* @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 : Set path for default lib use dlns_set_namespace_lib_path
* @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 : Test dlns_set_namespace_separated with invalid input
* @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 : Test dlns_set_namespace_separated with invalid input
* @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 : Set separated for default lib use dlns_set_namespace_separated
* @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 : Test dlns_set_namespace_permitted_paths with invalid input
* @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 : Test dlns_set_namespace_permitted_paths with invalid input
* @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 : Set path for default lib use dlns_set_namespace_permitted_paths
* @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 : Test dlns_set_namespace_allowed_libs with invalid input
* @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 : Test dlns_set_namespace_allowed_libs with invalid input
* @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 : Set allowed libs for default lib use dlns_set_namespace_allowed_libs
* @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 : ld_log_test_0010
* @tc.desc : test ld_log_reset normal condition.
* @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 normal condition
* @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 arg ns's memebers are NULL
* @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 args are NULL
* @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 arg dso is NULL
* @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 arg ns is NULL
* @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 normal condition
* @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 many times
* @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 arg is NULL
* @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 args are NULL
* @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 arg name is NULL
* @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 arg ns is NULL
* @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 arg ns is NULL
* @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 arg ns.env_paths is NULL
* @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 arg ns.env_paths is equal to arg name
* @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 arg name is NULL and ns.env_paths is NULL
* @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 arg name is NULL and ns.env_paths is not NULL
* @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 arg ns is NULL
* @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 arg ns.asan_lib_paths is NULL
* @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 arg ns.asan_lib_paths is equal to arg name
* @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 arg name is NULL and ns.asan_lib_paths is NULL
* @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 arg name is NULL and ns.asan_lib_paths is not NULL
* @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 arg permitted_paths is NULL and ns.permitted_paths is not NULL
* @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 args are NULL
* @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 arg permitted_paths is NULL and ns.permitted_paths is NULL
* @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 arg asan_permitted_paths is NULL and ns.asan_permitted_paths is not NULL
* @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 args are NULL
* @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 arg asan_permitted_paths is NULL and ns.asan_permitted_paths is NULL
* @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 arg ns is NULL and separated is false
* @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 arg ns is NULL
* @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 arg ns is ns.allowed_libs NULL
* @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 normal condition
* @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 allowed_libs is NULL and ns.allowed_libs is NULL
* @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 allowed_libs is NULL and ns.allowed_libs is not NULL
* @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 arg ns_inherited and shared_libs are NULL
* @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 args are NULL
* @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 arg ns and shared_libs are NULL
* @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 arg lib_pathname is NULL
* @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 args is (&ns, NULL, true, false) and ns.separated is false
* @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 args is (&ns, "/data/test.so", true, false) and ns.separated is false
* @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 args are NULL
* @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 : Set default error callback for configor
* @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 : Set custom error callback for configor
* @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 with invalid input
* @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 with invalid input
* @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 with invalid input
* @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 with invalid input
* @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 with invalid input
* @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 with invalid input
* @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 with invalid input
* @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 with invalid input
* @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>
bool is_musl_log_enable()
{
return true;
}
bool get_bool_sysparam(CachedHandle cachedhandle)
{
return true;
}
\ 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 = ...@@ -20,6 +20,8 @@ musl_lib_dir =
test_lib_dir = "musl/libc-test-lib" test_lib_dir = "musl/libc-test-lib"
musl_src_base = "${root_out_dir}/obj/${musl_base_dir}/${musl_ported_dir}"
template("test_unittest") { template("test_unittest") {
assert(defined(invoker.target_name), assert(defined(invoker.target_name),
"file name is required in target ${target_name}") "file name is required in target ${target_name}")
......
...@@ -730,6 +730,13 @@ template("musl_libs") { ...@@ -730,6 +730,13 @@ template("musl_libs") {
"//build/config/compiler:compiler", "//build/config/compiler:compiler",
":soft_hook", ":soft_hook",
] ]
cflags = [
"-mllvm",
"--instcombine-max-iterations=0",
"-ffp-contract=fast",
"-O3",
]
} }
source_set("soft_musl_jemalloc") { source_set("soft_musl_jemalloc") {
......
...@@ -198,6 +198,19 @@ musl_lib_arm64 = [ ...@@ -198,6 +198,19 @@ musl_lib_arm64 = [
"//third_party/musl:soft_librt(//build/toolchain/ohos:ohos_clang_arm64)", "//third_party/musl:soft_librt(//build/toolchain/ohos:ohos_clang_arm64)",
] ]
musl_lib_x86_64 = [
"//third_party/musl:soft_musl_crt_install_action(//build/toolchain/ohos:ohos_clang_x86_64)",
"//third_party/musl:soft_libc_musl_static(//build/toolchain/ohos:ohos_clang_x86_64)",
"//third_party/musl:soft_libm(//build/toolchain/ohos:ohos_clang_x86_64)",
"//third_party/musl:soft_libdl(//build/toolchain/ohos:ohos_clang_x86_64)",
"//third_party/musl:soft_libpthread(//build/toolchain/ohos:ohos_clang_x86_64)",
"//third_party/musl:soft_libcrypt(//build/toolchain/ohos:ohos_clang_x86_64)",
"//third_party/musl:soft_libutil(//build/toolchain/ohos:ohos_clang_x86_64)",
"//third_party/musl:soft_libxnet(//build/toolchain/ohos:ohos_clang_x86_64)",
"//third_party/musl:soft_libresolv(//build/toolchain/ohos:ohos_clang_x86_64)",
"//third_party/musl:soft_librt(//build/toolchain/ohos:ohos_clang_x86_64)",
]
## arm-linux-ohos asm directory ## arm-linux-ohos asm directory
ohos_ndk_copy("musl_arm_uapi_arm32") { ohos_ndk_copy("musl_arm_uapi_arm32") {
dest_dir = "$ndk_os_irrelevant_out_dir/sysroot/usr/include/arm-linux-ohos" dest_dir = "$ndk_os_irrelevant_out_dir/sysroot/usr/include/arm-linux-ohos"
...@@ -332,3 +345,35 @@ ohos_copy("musl_ndk_libs_aarch64") { ...@@ -332,3 +345,35 @@ ohos_copy("musl_ndk_libs_aarch64") {
outputs = [ "$ndk_os_irrelevant_out_dir/sysroot/usr/lib/aarch64-linux-ohos/{{source_file_part}}" ] outputs = [ "$ndk_os_irrelevant_out_dir/sysroot/usr/lib/aarch64-linux-ohos/{{source_file_part}}" ]
} }
ohos_copy("musl_ndk_libs_x86_64") {
deps = musl_lib_x86_64
crt_dir = "${root_build_dir}/obj/third_party/musl/usr/lib/x86_64-linux-ohos"
sources = [
"${crt_dir}/Scrt1.o",
"${crt_dir}/crt1.o",
"${crt_dir}/crti.o",
"${crt_dir}/crtn.o",
"${crt_dir}/rcrt1.o",
]
sources += [ get_label_info(deps[0], "target_out_dir") +
"/usr/lib/x86_64-linux-ohos/libc.a" ]
sources += [ get_label_info(deps[0], "target_out_dir") +
"/usr/lib/x86_64-linux-ohos/libdl.a" ]
sources += [ get_label_info(deps[0], "target_out_dir") +
"/usr/lib/x86_64-linux-ohos/libm.a" ]
sources += [ get_label_info(deps[0], "target_out_dir") +
"/usr/lib/x86_64-linux-ohos/libcrypt.a" ]
sources += [ get_label_info(deps[0], "target_out_dir") +
"/usr/lib/x86_64-linux-ohos/libpthread.a" ]
sources += [ get_label_info(deps[0], "target_out_dir") +
"/usr/lib/x86_64-linux-ohos/libresolv.a" ]
sources += [ get_label_info(deps[0], "target_out_dir") +
"/usr/lib/x86_64-linux-ohos/librt.a" ]
sources += [ get_label_info(deps[0], "target_out_dir") +
"/usr/lib/x86_64-linux-ohos/libutil.a" ]
sources += [ get_label_info(deps[0], "target_out_dir") +
"/usr/lib/x86_64-linux-ohos/libxnet.a" ]
outputs = [ "$ndk_os_irrelevant_out_dir/sysroot/usr/lib/x86_64-linux-ohos/{{source_file_part}}" ]
}
...@@ -39,7 +39,9 @@ ...@@ -39,7 +39,9 @@
#ifdef OHOS_ENABLE_PARAMETER #ifdef OHOS_ENABLE_PARAMETER
#include "sys_param.h" #include "sys_param.h"
#endif #endif
#ifdef LOAD_ORDER_RANDOMIZATION
#include "zip_archive.h" #include "zip_archive.h"
#endif
static void error(const char *, ...); static void error(const char *, ...);
...@@ -255,6 +257,8 @@ static void preload_deps(struct dso *p, struct loadtasks *tasks); ...@@ -255,6 +257,8 @@ static void preload_deps(struct dso *p, struct loadtasks *tasks);
static void run_loadtasks(struct loadtasks *tasks, struct reserved_address_params *reserved_params); static void run_loadtasks(struct loadtasks *tasks, struct reserved_address_params *reserved_params);
static void assign_tls(struct dso *p); static void assign_tls(struct dso *p);
static void load_preload(char *s, ns_t *ns, struct loadtasks *tasks); static void load_preload(char *s, ns_t *ns, struct loadtasks *tasks);
static void open_library_by_path(const char *name, const char *s, struct loadtask *task, struct zip_info *z_info);
static void handle_asan_path_open_by_task(int fd, const char *name, ns_t *namespace, struct loadtask *task, struct zip_info *z_info);
#endif #endif
/* Sharing relro */ /* Sharing relro */
...@@ -1199,12 +1203,21 @@ static void unmap_library(struct dso *dso) ...@@ -1199,12 +1203,21 @@ static void unmap_library(struct dso *dso)
for (i=0; i<dso->loadmap->nsegs; i++) { for (i=0; i<dso->loadmap->nsegs; i++) {
if (!dso->loadmap->segs[i].p_memsz) if (!dso->loadmap->segs[i].p_memsz)
continue; continue;
munmap((void *)dso->loadmap->segs[i].addr, if (!is_dlclose_debug_enable()) {
dso->loadmap->segs[i].p_memsz); munmap((void *)dso->loadmap->segs[i].addr,
dso->loadmap->segs[i].p_memsz);
} else {
(void)mprotect((void *)dso->loadmap->segs[i].addr,
dso->loadmap->segs[i].p_memsz, PROT_NONE);
}
} }
internal_free(dso->loadmap); internal_free(dso->loadmap);
} else if (dso->map && dso->map_len) { } else if (dso->map && dso->map_len) {
munmap(dso->map, dso->map_len); if (!is_dlclose_debug_enable()) {
munmap(dso->map, dso->map_len);
} else {
mprotect(dso->map, dso->map_len, PROT_NONE);
}
} }
} }
...@@ -3980,6 +3993,194 @@ void* dlopen_ext(const char *file, int mode, const dl_extinfo *extinfo) ...@@ -3980,6 +3993,194 @@ void* dlopen_ext(const char *file, int mode, const dl_extinfo *extinfo)
} }
#ifdef LOAD_ORDER_RANDOMIZATION #ifdef LOAD_ORDER_RANDOMIZATION
static void open_library_by_path(const char *name, const char *s, struct loadtask *task, struct zip_info *z_info)
{
char *buf = task->buf;
size_t buf_size = sizeof task->buf;
size_t l;
for (;;) {
s += strspn(s, ":\n");
l = strcspn(s, ":\n");
if (l-1 >= INT_MAX) return;
if (snprintf(buf, buf_size, "%.*s/%s", (int)l, s, name) < buf_size) {
char *separator = strstr(buf, ZIP_FILE_PATH_SEPARATOR);
if (separator != NULL) {
int res = open_uncompressed_library_in_zipfile(buf, z_info, separator);
if (res == 0) {
task->fd = z_info->fd;
task->file_offset = z_info->file_offset;
break;
} else {
memset(z_info->path_buf, 0, sizeof(z_info->path_buf));
}
} else {
if ((task->fd = open(buf, O_RDONLY|O_CLOEXEC))>=0) break;
}
}
s += l;
}
return;
}
static void handle_asan_path_open_by_task(int fd, const char *name, ns_t *namespace, struct loadtask *task,
struct zip_info *z_info)
{
LD_LOGD("handle_asan_path_open_by_task fd:%{public}d, name:%{public}s , namespace:%{public}s .",
fd,
name,
namespace ? namespace->ns_name : "NULL");
if (fd == -1 && (namespace->asan_lib_paths || namespace->lib_paths)) {
if (namespace->lib_paths && namespace->asan_lib_paths) {
size_t newlen = strlen(namespace->asan_lib_paths) + strlen(namespace->lib_paths) + 2;
char *new_lib_paths = internal_malloc(newlen);
memset(new_lib_paths, 0, newlen);
strcpy(new_lib_paths, namespace->asan_lib_paths);
strcat(new_lib_paths, ":");
strcat(new_lib_paths, namespace->lib_paths);
open_library_by_path(name, new_lib_paths, task, z_info);
LD_LOGD("handle_asan_path_open_by_task open_library_by_path new_lib_paths:%{public}s ,fd: %{public}d.",
new_lib_paths,
task->fd);
internal_free(new_lib_paths);
} else if (namespace->asan_lib_paths) {
open_library_by_path(name, namespace->asan_lib_paths, task, z_info);
LD_LOGD("handle_asan_path_open_by_task open_library_by_path asan_lib_paths:%{public}s ,fd: %{public}d.",
namespace->asan_lib_paths,
task->fd);
} else {
open_library_by_path(name, namespace->lib_paths, task, z_info);
LD_LOGD("handle_asan_path_open_by_task open_library_by_path lib_paths:%{public}s ,fd: %{public}d.",
namespace->lib_paths,
task->fd);
}
}
return;
}
/* Used to get an uncompress library offset in zip file, then we can use the offset to mmap the library directly. */
int open_uncompressed_library_in_zipfile(const char *path, struct zip_info *z_info, char *separator)
{
struct local_file_header zip_file_header;
struct central_dir_entry c_dir_entry;
struct zip_end_locator end_locator;
/* Use "'!/' to split the path into zipfile path and library path in zipfile.
* For example:
* - path: x/xx/xxx.zip!/x/xx/xxx.so
* - zipfile path: x/xx/xxx.zip
* - library path in zipfile: x/xx/xxx.so */
if (strlcpy(z_info->path_buf, path, PATH_BUF_SIZE) >= PATH_BUF_SIZE) {
LD_LOGE("Open uncompressed library: input path %{public}s is too long.", path);
return -1;
}
z_info->path_buf[separator - path] = '\0';
z_info->file_path_index = separator - path + 2;
char *zip_file_path = z_info->path_buf;
char *lib_path = &z_info->path_buf[z_info->file_path_index];
if (zip_file_path == NULL || lib_path == NULL) {
LD_LOGE("Open uncompressed library: get zip and lib path failed.");
return -1;
}
LD_LOGD("Open uncompressed library: input path: %{public}s, zip file path: %{public}s, library path: %{public}s.",
path, zip_file_path, lib_path);
// Get zip file length
FILE *zip_file = fopen(zip_file_path, "re");
if (zip_file == NULL) {
LD_LOGE("Open uncompressed library: fopen %{public}s failed.", zip_file_path);
return -1;
}
if (fseek(zip_file, 0, SEEK_END) != 0) {
LD_LOGE("Open uncompressed library: fseek SEEK_END failed.");
fclose(zip_file);
return -1;
}
int64_t zip_file_len = ftell(zip_file);
if (zip_file_len == -1) {
LD_LOGE("Open uncompressed library: get zip file length failed.");
fclose(zip_file);
return -1;
}
// Read end of central directory record.
size_t end_locator_len = sizeof(end_locator);
size_t end_locator_pos = zip_file_len - end_locator_len;
if (fseek(zip_file, end_locator_pos, SEEK_SET) != 0) {
LD_LOGE("Open uncompressed library: fseek end locator position failed.");
fclose(zip_file);
return -1;
}
if (fread(&end_locator, sizeof(end_locator), 1, zip_file) != 1 || end_locator.signature != EOCD_SIGNATURE) {
LD_LOGE("Open uncompressed library: fread end locator failed.");
fclose(zip_file);
return -1;
}
char file_name[PATH_BUF_SIZE];
uint64_t current_dir_pos = end_locator.offset;
for (uint16_t i = 0; i < end_locator.total_entries; i++) {
// Read central dir entry.
if (fseek(zip_file, current_dir_pos, SEEK_SET) != 0) {
LD_LOGE("Open uncompressed library: fseek current centra dir entry position failed.");
fclose(zip_file);
return -1;
}
if (fread(&c_dir_entry, sizeof(c_dir_entry), 1, zip_file) != 1 || c_dir_entry.signature != CENTRAL_SIGNATURE) {
LD_LOGE("Open uncompressed library: fread centra dir entry failed.");
fclose(zip_file);
return -1;
}
if (fread(file_name, c_dir_entry.name_size, 1, zip_file) != 1) {
LD_LOGE("Open uncompressed library: fread file name failed.");
fclose(zip_file);
return -1;
}
if (strcmp(file_name, lib_path) == 0) {
// Read local file header.
if (fseek(zip_file, c_dir_entry.local_header_offset, SEEK_SET) != 0) {
LD_LOGE("Open uncompressed library: fseek local file header failed.");
fclose(zip_file);
return -1;
}
if (fread(&zip_file_header, sizeof(zip_file_header), 1, zip_file) != 1) {
LD_LOGE("Open uncompressed library: fread local file header failed.");
fclose(zip_file);
return -1;
}
if (zip_file_header.signature != LOCAL_FILE_HEADER_SIGNATURE) {
LD_LOGE("Open uncompressed library: read local file header signature error.");
fclose(zip_file);
return -1;
}
z_info->file_offset = c_dir_entry.local_header_offset + sizeof(zip_file_header) +
zip_file_header.name_size + zip_file_header.extra_size;
if (zip_file_header.compression_method != COMPRESS_STORED || z_info->file_offset % PAGE_SIZE != 0) {
LD_LOGE("Open uncompressed library: open %{public}s in %{public}s failed because of misalignment or saved with compression."
"compress method %{public}d, file offset %{public}lu",
lib_path, zip_file_path, zip_file_header.compression_method, z_info->file_offset);
fclose(zip_file);
return -2;
}
z_info->found = true;
break;
}
memset(file_name, 0, sizeof(file_name));
current_dir_pos += sizeof(c_dir_entry);
current_dir_pos += c_dir_entry.name_size + c_dir_entry.extra_size + c_dir_entry.comment_size;
}
if(!z_info->found) {
LD_LOGE("Open uncompressed library: %{public}s was not found in %{public}s.", lib_path, zip_file_path);
fclose(zip_file);
return -3;
}
z_info->fd = fileno(zip_file);
return 0;
}
static bool map_library_header(struct loadtask *task) static bool map_library_header(struct loadtask *task)
{ {
off_t off_start; off_t off_start;
...@@ -4374,7 +4575,7 @@ static bool load_library_header(struct loadtask *task) ...@@ -4374,7 +4575,7 @@ static bool load_library_header(struct loadtask *task)
task->file_offset = z_info.file_offset; task->file_offset = z_info.file_offset;
} }
} else { } else {
LD_LOGE("Open uncompressed library in zip file failed, res = %{public}d", res); LD_LOGE("Open uncompressed library in zip file failed, name:%{public}s res:%{public}d", name, res);
return false; return false;
} }
} else { } else {
...@@ -4399,22 +4600,22 @@ static bool load_library_header(struct loadtask *task) ...@@ -4399,22 +4600,22 @@ static bool load_library_header(struct loadtask *task)
} }
task->fd = -1; task->fd = -1;
if (namespace->env_paths) { if (namespace->env_paths) {
task->fd = path_open(name, namespace->env_paths, task->buf, sizeof task->buf); open_library_by_path(name, namespace->env_paths, task, &z_info);
} }
for (task->p = needed_by; task->fd == -1 && task->p; task->p = task->p->needed_by) { for (task->p = needed_by; task->fd == -1 && task->p; task->p = task->p->needed_by) {
if (fixup_rpath(task->p, task->buf, sizeof task->buf) < 0) { if (fixup_rpath(task->p, task->buf, sizeof task->buf) < 0) {
task->fd = INVALID_FD_INHIBIT_FURTHER_SEARCH; /* Inhibit further search. */ task->fd = INVALID_FD_INHIBIT_FURTHER_SEARCH; /* Inhibit further search. */
} }
if (task->p->rpath) { if (task->p->rpath) {
task->fd = path_open(name, task->p->rpath, task->buf, sizeof task->buf); open_library_by_path(name, task->p->rpath, task, &z_info);
} }
} }
if (g_is_asan) { if (g_is_asan) {
task->fd = handle_asan_path_open(task->fd, name, namespace, task->buf, sizeof task->buf); handle_asan_path_open_by_task(task->fd, name, namespace, task, &z_info);
LD_LOGD("load_library handle_asan_path_open fd:%{public}d.", task->fd); LD_LOGD("load_library handle_asan_path_open_by_task fd:%{public}d.", task->fd);
} else { } else {
if (task->fd == -1 && namespace->lib_paths) { if (task->fd == -1 && namespace->lib_paths) {
task->fd = path_open(name, namespace->lib_paths, task->buf, sizeof task->buf); open_library_by_path(name, namespace->lib_paths, task, &z_info);
LD_LOGD("load_library no asan lib_paths path_open fd:%{public}d.", task->fd); LD_LOGD("load_library no asan lib_paths path_open fd:%{public}d.", task->fd);
} }
} }
...@@ -4879,127 +5080,4 @@ static void handle_relro_sharing(struct dso *p, const dl_extinfo *extinfo, ssize ...@@ -4879,127 +5080,4 @@ static void handle_relro_sharing(struct dso *p, const dl_extinfo *extinfo, ssize
if (runtime) longjmp(*rtld_fail, 1); if (runtime) longjmp(*rtld_fail, 1);
} }
} }
}
/* Used to get an uncompress library offset in zip file, then we can use the offset to mmap the library directly. */
int open_uncompressed_library_in_zipfile(const char *path, struct zip_info *z_info, char *separator)
{
struct local_file_header zip_file_header;
struct central_dir_entry c_dir_entry;
struct zip_end_locator end_locator;
/* Use "'!/' to split the path into zipfile path and library path in zipfile.
* For example:
* - path: x/xx/xxx.zip!/x/xx/xxx.so
* - zipfile path: x/xx/xxx.zip
* - library path in zipfile: x/xx/xxx.so */
if (strlcpy(z_info->path_buf, path, PATH_BUF_SIZE) >= PATH_BUF_SIZE) {
LD_LOGE("Open uncompressed library: input path %{public}s is too long.", path);
return -1;
}
z_info->path_buf[separator - path] = '\0';
z_info->file_path_index = separator - path + 2;
char *zip_file_path = z_info->path_buf;
char *lib_path = &z_info->path_buf[z_info->file_path_index];
if (zip_file_path == NULL || lib_path == NULL) {
LD_LOGE("Open uncompressed library: get zip and lib path failed.");
return -1;
}
LD_LOGD("Open uncompressed library: zip file path %{public}s library path %{public}s.", zip_file_path, lib_path);
// Get zip file length
FILE *zip_file = fopen(zip_file_path, "re");
if (zip_file == NULL) {
LD_LOGE("Open uncompressed library: fopen %{public}s failed.", zip_file_path);
return -1;
}
if (fseek(zip_file, 0, SEEK_END) != 0) {
LD_LOGE("Open uncompressed library: fseek SEEK_END failed.");
fclose(zip_file);
return -1;
}
int64_t zip_file_len = ftell(zip_file);
if (zip_file_len == -1) {
LD_LOGE("Open uncompressed library: get zip file length failed.");
fclose(zip_file);
return -1;
}
// Read end of central directory record.
size_t end_locator_len = sizeof(end_locator);
size_t end_locator_pos = zip_file_len - end_locator_len;
if (fseek(zip_file, end_locator_pos, SEEK_SET) != 0) {
LD_LOGE("Open uncompressed library: fseek end locator position failed.");
fclose(zip_file);
return -1;
}
if (fread(&end_locator, sizeof(end_locator), 1, zip_file) != 1 || end_locator.signature != EOCD_SIGNATURE) {
LD_LOGE("Open uncompressed library: fread end locator failed.");
fclose(zip_file);
return -1;
}
char file_name[PATH_BUF_SIZE];
uint64_t current_dir_pos = end_locator.offset;
for (uint16_t i = 0; i < end_locator.total_entries; i++) {
// Read central dir entry.
if (fseek(zip_file, current_dir_pos, SEEK_SET) != 0) {
LD_LOGE("Open uncompressed library: fseek current centra dir entry position failed.");
fclose(zip_file);
return -1;
}
if (fread(&c_dir_entry, sizeof(c_dir_entry), 1, zip_file) != 1 || c_dir_entry.signature != CENTRAL_SIGNATURE) {
LD_LOGE("Open uncompressed library: fread centra dir entry failed.");
fclose(zip_file);
return -1;
}
if (fread(file_name, c_dir_entry.name_size, 1, zip_file) != 1) {
LD_LOGE("Open uncompressed library: fread file name failed.");
fclose(zip_file);
return -1;
}
if (strcmp(file_name, lib_path) == 0) {
// Read local file header.
if (fseek(zip_file, c_dir_entry.local_header_offset, SEEK_SET) != 0) {
LD_LOGE("Open uncompressed library: fseek local file header failed.");
fclose(zip_file);
return -1;
}
if (fread(&zip_file_header, sizeof(zip_file_header), 1, zip_file) != 1) {
LD_LOGE("Open uncompressed library: fread local file header failed.");
fclose(zip_file);
return -1;
}
if (zip_file_header.signature != LOCAL_FILE_HEADER_SIGNATURE) {
LD_LOGE("Open uncompressed library: read local file header signature error.");
fclose(zip_file);
return -1;
}
z_info->file_offset = c_dir_entry.local_header_offset + sizeof(zip_file_header) +
zip_file_header.name_size + zip_file_header.extra_size;
if (zip_file_header.compression_method != COMPRESS_STORED || z_info->file_offset % PAGE_SIZE != 0) {
LD_LOGE("Open uncompressed library: open %{public}s in %{public}s failed because of misalignment or saved with compression."
"compress method %{public}d, file offset %{public}lu",
lib_path, zip_file_path, zip_file_header.compression_method, z_info->file_offset);
fclose(zip_file);
return -2;
}
z_info->found = true;
break;
}
memset(file_name, 0, sizeof(file_name));
current_dir_pos += sizeof(c_dir_entry);
current_dir_pos += c_dir_entry.name_size + c_dir_entry.extra_size + c_dir_entry.comment_size;
}
if(!z_info->found) {
LD_LOGE("Open uncompressed library: %{public}s was not found in %{public}s.", lib_path, zip_file_path);
fclose(zip_file);
return -3;
}
z_info->fd = fileno(zip_file);
return 0;
} }
\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ld_log.h" #include "ld_log.h"
static bool ld_log_enable = false; static bool ld_log_enable = false;
static bool ld_dlclose_debug = false;
#ifdef OHOS_ENABLE_PARAMETER #ifdef OHOS_ENABLE_PARAMETER
#include <fcntl.h> #include <fcntl.h>
...@@ -73,11 +74,21 @@ static bool get_ld_log_value() ...@@ -73,11 +74,21 @@ static bool get_ld_log_value()
} }
return (get_bool_sysparam(app_param_handle) || get_bool_sysparam(all_param_handle)); return (get_bool_sysparam(app_param_handle) || get_bool_sysparam(all_param_handle));
} }
static bool get_ld_debug_dlclose_value()
{
static CachedHandle param_handle = NULL;
if (param_handle == NULL) {
param_handle = CachedParameterCreate("musl.ld.debug.dlclose", "false");
}
return get_bool_sysparam(param_handle);
}
#endif #endif
void ld_log_reset() void ld_log_reset()
{ {
#if (defined(OHOS_ENABLE_PARAMETER)) #if (defined(OHOS_ENABLE_PARAMETER))
ld_dlclose_debug = get_ld_debug_dlclose_value();
if (!is_musl_log_enable()) { if (!is_musl_log_enable()) {
ld_log_enable = false; ld_log_enable = false;
return; return;
...@@ -92,3 +103,8 @@ bool get_ld_log_enable() ...@@ -92,3 +103,8 @@ bool get_ld_log_enable()
{ {
return ld_log_enable; return ld_log_enable;
} }
bool is_dlclose_debug_enable()
{
return ld_dlclose_debug;
}
...@@ -34,6 +34,8 @@ extern "C" { ...@@ -34,6 +34,8 @@ extern "C" {
hidden bool get_ld_log_enable(); hidden bool get_ld_log_enable();
hidden void ld_log_reset(); hidden void ld_log_reset();
hidden bool is_dlclose_debug_enable();
#if ((LD_LOG_LEVEL & LD_LOG_ERROR) && (defined(OHOS_ENABLE_PARAMETER) || defined(ENABLE_MUSL_LOG))) #if ((LD_LOG_LEVEL & LD_LOG_ERROR) && (defined(OHOS_ENABLE_PARAMETER) || defined(ENABLE_MUSL_LOG)))
#define LD_LOGE(...) if (get_ld_log_enable()) { \ #define LD_LOGE(...) if (get_ld_log_enable()) { \
(void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_ERROR, MUSL_LOG_DOMAIN, LD_LOG_TAG, __VA_ARGS__); \ (void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_ERROR, MUSL_LOG_DOMAIN, LD_LOG_TAG, __VA_ARGS__); \
......
...@@ -9,26 +9,44 @@ ...@@ -9,26 +9,44 @@
void* malloc(size_t bytes) void* malloc(size_t bytes)
{ {
volatile const struct MallocDispatchType* dispatch_table = get_current_dispatch_table(); struct MallocDispatchType* dispatch_table = (struct MallocDispatchType *)atomic_load_explicit(
&__musl_libc_globals.current_dispatch_table, memory_order_acquire);
if (__predict_false(dispatch_table != NULL)) { if (__predict_false(dispatch_table != NULL)) {
void*ret = dispatch_table->malloc(bytes); if (__get_memleak_hook_flag()) {
return ret; return dispatch_table->malloc(bytes);
} }
void* result = MuslMalloc(malloc)(bytes); if (!__get_global_hook_flag()) {
if (__predict_false(result == NULL)) { return MuslFunc(malloc)(bytes);
//__musl_log(__MUSL_LOG_WARN, "malloc(%zu) failed: returning null pointer\n", bytes); }
if (!__get_hook_flag()) {
return MuslFunc(malloc)(bytes);
}
return dispatch_table->malloc(bytes);
} }
return result; return MuslFunc(malloc)(bytes);
} }
void free(void* mem) void free(void* mem)
{ {
volatile const struct MallocDispatchType* dispatch_table = get_current_dispatch_table(); struct MallocDispatchType* dispatch_table = (struct MallocDispatchType *)atomic_load_explicit(
&__musl_libc_globals.current_dispatch_table, memory_order_acquire);
if (__predict_false(dispatch_table != NULL)) { if (__predict_false(dispatch_table != NULL)) {
if (__get_memleak_hook_flag()) {
dispatch_table->free(mem);
return;
}
if (!__get_global_hook_flag()) {
MuslFunc(free)(mem);
return;
}
if (!__get_hook_flag()) {
MuslFunc(free)(mem);
return;
}
dispatch_table->free(mem); dispatch_table->free(mem);
} else { return;
MuslMalloc(free)(mem);
} }
MuslFunc(free)(mem);
} }
void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset)
......
...@@ -13,12 +13,19 @@ extern "C" { ...@@ -13,12 +13,19 @@ extern "C" {
#define MuslMalloc(func) func #define MuslMalloc(func) func
#endif #endif
#ifdef USE_JEMALLOC
#define MuslFunc(func) je_ ## func
#else
#define MuslFunc(func) internal_ ## func
#endif
extern void *internal_malloc(size_t);
extern void internal_free(void*);
void *__libc_mmap(void*, size_t, int, int, int, off_t); void *__libc_mmap(void*, size_t, int, int, int, off_t);
int __libc_munmap(void*, size_t); int __libc_munmap(void*, size_t);
void *__libc_malloc(size_t);
void *__libc_calloc(size_t, size_t); void *__libc_calloc(size_t, size_t);
void *__libc_realloc(void *, size_t); void *__libc_realloc(void *, size_t);
void __libc_free(void *);
void *__libc_valloc(size_t); void *__libc_valloc(size_t);
void *__libc_memalign(size_t, size_t); void *__libc_memalign(size_t, size_t);
size_t __libc_malloc_usable_size(void *); size_t __libc_malloc_usable_size(void *);
......
...@@ -40,7 +40,7 @@ void* ohos_malloc_hook_init_function(size_t bytes); ...@@ -40,7 +40,7 @@ void* ohos_malloc_hook_init_function(size_t bytes);
static struct MallocDispatchType __ohos_malloc_hook_init_dispatch = { static struct MallocDispatchType __ohos_malloc_hook_init_dispatch = {
.malloc = ohos_malloc_hook_init_function, .malloc = ohos_malloc_hook_init_function,
.free = MuslMalloc(free), .free = MuslFunc(free),
.mmap = MuslMalloc(mmap), .mmap = MuslMalloc(mmap),
.munmap = MuslMalloc(munmap), .munmap = MuslMalloc(munmap),
.calloc = MuslMalloc(calloc), .calloc = MuslMalloc(calloc),
...@@ -459,7 +459,7 @@ void* ohos_malloc_hook_init_function(size_t bytes) ...@@ -459,7 +459,7 @@ void* ohos_malloc_hook_init_function(size_t bytes)
// __musl_log(__MUSL_LOG_ERROR, "%s: ohos_malloc_hook: failed to pthread_detach\n", getprogname()); // __musl_log(__MUSL_LOG_ERROR, "%s: ohos_malloc_hook: failed to pthread_detach\n", getprogname());
} }
} }
void*ptr = MuslMalloc(malloc)(bytes); void*ptr = MuslFunc(malloc)(bytes);
return ptr; return ptr;
} }
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
struct musl_libc_globals __musl_libc_globals; struct musl_libc_globals __musl_libc_globals;
struct MallocDispatchType __libc_malloc_default_dispatch = { struct MallocDispatchType __libc_malloc_default_dispatch = {
.malloc = MuslMalloc(malloc), .malloc = MuslFunc(malloc),
.free = MuslMalloc(free), .free = MuslFunc(free),
.mmap = MuslMalloc(mmap), .mmap = MuslMalloc(mmap),
.munmap = MuslMalloc(munmap), .munmap = MuslMalloc(munmap),
.calloc = MuslMalloc(calloc), .calloc = MuslMalloc(calloc),
......
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#ifndef hidden
#define hidden __attribute__((visibility("hidden"))) #define hidden __attribute__((visibility("hidden")))
#endif
// Log type // Log type
typedef enum { typedef enum {
......
...@@ -30,11 +30,6 @@ extern int je_mallopt(int param, int value); ...@@ -30,11 +30,6 @@ extern int je_mallopt(int param, int value);
#define inline inline __attribute__((always_inline)) #define inline inline __attribute__((always_inline))
#endif #endif
#ifdef HOOK_ENABLE
void *__libc_malloc(size_t);
void __libc_free(void *p);
#endif
static struct { static struct {
volatile uint64_t binmap; volatile uint64_t binmap;
struct bin bins[BINS_COUNT]; struct bin bins[BINS_COUNT];
...@@ -628,16 +623,16 @@ static void trim(struct chunk *self, size_t n) ...@@ -628,16 +623,16 @@ static void trim(struct chunk *self, size_t n)
} }
#ifdef HOOK_ENABLE #ifdef HOOK_ENABLE
void *__libc_malloc(size_t n)
#else #else
void *malloc(size_t n) void *malloc(size_t n)
#endif
{ {
#ifdef USE_JEMALLOC #ifdef USE_JEMALLOC
return je_malloc(n); return je_malloc(n);
#endif #endif
return internal_malloc(n); return internal_malloc(n);
} }
#endif
void *internal_malloc(size_t n) void *internal_malloc(size_t n)
{ {
...@@ -1245,16 +1240,16 @@ static void quarantine_bin(struct chunk *self) ...@@ -1245,16 +1240,16 @@ static void quarantine_bin(struct chunk *self)
#endif #endif
#ifdef HOOK_ENABLE #ifdef HOOK_ENABLE
void __libc_free(void *p)
#else #else
void free(void *p) void free(void *p)
#endif
{ {
#ifdef USE_JEMALLOC #ifdef USE_JEMALLOC
return je_free(p); return je_free(p);
#endif #endif
return internal_free(p); return internal_free(p);
} }
#endif
void internal_free(void *p) void internal_free(void *p)
{ {
......
...@@ -38,6 +38,7 @@ int sched_yield(void); ...@@ -38,6 +38,7 @@ int sched_yield(void);
#define __CPU_BITTYPE unsigned long int /* mandated by the kernel */ #define __CPU_BITTYPE unsigned long int /* mandated by the kernel */
#ifdef _GNU_SOURCE #ifdef _GNU_SOURCE
#define CSIGNAL 0x000000ff #define CSIGNAL 0x000000ff
#define CLONE_NEWTIME 0x00000080
#define CLONE_VM 0x00000100 #define CLONE_VM 0x00000100
#define CLONE_FS 0x00000200 #define CLONE_FS 0x00000200
#define CLONE_FILES 0x00000400 #define CLONE_FILES 0x00000400
......
...@@ -31,7 +31,6 @@ MUSLPORTINGDIR = get_path_info(".", "abspath") ...@@ -31,7 +31,6 @@ MUSLPORTINGDIR = get_path_info(".", "abspath")
ICCARM_ADAPT_INCLUDE_DIRS = [ "$MUSLPORTINGDIR/include" ] ICCARM_ADAPT_INCLUDE_DIRS = [ "$MUSLPORTINGDIR/include" ]
ICCARM_ADAPT_SRC_COMMON = [ ICCARM_ADAPT_SRC_COMMON = [
"$MUSLPORTINGDIR/src/malloc.c",
"$MUSLPORTINGDIR/src/misc/realpath.c", "$MUSLPORTINGDIR/src/misc/realpath.c",
"$MUSLPORTINGDIR/src/network/htonl.c", "$MUSLPORTINGDIR/src/network/htonl.c",
"$MUSLPORTINGDIR/src/network/htons.c", "$MUSLPORTINGDIR/src/network/htons.c",
......
/*
* Copyright (c) 2022-2022 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdint.h>
#include "securec.h"
#include "los_config.h"
#include "los_memory.h"
#ifdef LOSCFG_LIBC_ICCARM_MALLOC
void *calloc(size_t nitems, size_t size)
{
size_t real_size;
void *ptr = NULL;
if ((nitems == 0) || (size == 0) || (nitems > (UINT32_MAX / size))) {
return NULL;
}
real_size = (size_t)(nitems * size);
ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, real_size);
if (ptr != NULL) {
(void)memset_s(ptr, real_size, 0, real_size);
}
return ptr;
}
void free(void *ptr)
{
if (ptr == NULL) {
return;
}
LOS_MemFree(OS_SYS_MEM_ADDR, ptr);
}
void *malloc(size_t size)
{
if (size == 0) {
return NULL;
}
return LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
}
void *zalloc(size_t size)
{
void *ptr = NULL;
if (size == 0) {
return NULL;
}
ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
if (ptr != NULL) {
(void)memset_s(ptr, size, 0, size);
}
return ptr;
}
void *memalign(size_t boundary, size_t size)
{
if (size == 0) {
return NULL;
}
return LOS_MemAllocAlign(OS_SYS_MEM_ADDR, size, boundary);
}
void *realloc(void *ptr, size_t size)
{
if (ptr == NULL) {
return malloc(size);
}
if (size == 0) {
free(ptr);
return NULL;
}
return LOS_MemRealloc(OS_SYS_MEM_ADDR, ptr, size);
}
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册