#include #include #include #include #include #include "asmsh_check.h" #include "mmap_parse.h" #define PARSE_FD_SAMPLE "samples/procfs_pid_maps" #define PARSE_FD_SAMPLE_SM "samples/procfs_pid_maps_sm" typedef struct { child_mmap_t map; char *line; } mmap_linecheck_t; START_TEST (test_parse_line) { child_mmap_t res; size_t i; mmap_linecheck_t lcheck[] = { {{(void*)0x123456, (void*)0x654321, MAP_PRIVATE, 0, 0, 0, "[stack]"}, "123456-654321 ---p 00000000 0:0 0 [stack]"}, {{(void*)0, (void*)0x1000, PROT_READ | PROT_WRITE | PROT_EXEC | MAP_SHARED, 1, (13<<8)+12, 123, "[stack]"}, "0-01000 rwxs 00000001 13:12 123 [stack]"}, {{(void*)0x35b1800000, (void*)0x35b1820000, PROT_READ | PROT_EXEC | MAP_PRIVATE, 0x1f000, (8<<8)+2, 135522, "/usr/lib64/ld-2.15.so"}, "35b1800000-35b1820000 r-xp 0001f000 08:02 135522 /usr/lib64/ld-2.15.so"}, }; for(i=0; istart, res->start); ck_assert_ptr_eq(check->stop, res->stop); ck_assert_int_eq(check->perm, res->perm); ck_assert_int_eq(check->offset, res->offset); ck_assert_mem_eq(&check->device, &res->device, sizeof(check->device)); ck_assert_mem_eq(&check->inode, &res->inode, sizeof(check->inode)); ck_assert_str_eq(check->pathname, res->pathname); } ck_assert_int_eq(i, maps.size); close(fd); } END_TEST START_TEST(test_mmap_get_invalid) { child_mmap_l maps; int ret = child_mmap_get(-1, &maps); ck_assert_int_eq(ret, -1); } END_TEST START_TEST(test_mmap_get_self) { child_mmap_l maps; pid_t spid = getpid(); child_mmap_init(&maps); int ret = child_mmap_get(spid, &maps); ck_assert_int_eq(ret, 0); } END_TEST START_TEST(test_shrink_map) { child_mmap_l maps; int ret, fd; fd = open(PARSE_FD_SAMPLE, O_RDONLY); if(fd < 0) { perror("Unable to open sample"); ck_abort_msg("Unable to open sample"); } child_mmap_init(&maps); ret = child_mmap_get_fd(fd, &maps); ck_assert_int_eq(ret, 0); close(fd); fd = open(PARSE_FD_SAMPLE_SM, O_RDONLY); if(fd < 0) { perror("Unable to open sample"); ck_abort_msg("Unable to open sample"); } ret = child_mmap_get_fd(fd, &maps); ck_assert_int_eq(ret, 0); close(fd); } ASMSH_CHECK_START("/proc/[pid]/map file parser", "parsing tests") ASMSH_ADD_TEST(test_parse_line); ASMSH_ADD_TEST(test_parse_fd); ASMSH_ADD_TEST(test_mmap_get_invalid); ASMSH_ADD_TEST(test_mmap_get_self); ASMSH_ADD_TEST(test_shrink_map); ASMSH_CHECK_END