Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: test-file-cache - build expected error strings using strerror #214

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/lib/test-file-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,10 @@ static void test_file_cache_errors(void)
size_t size;

/* file does not exist and we try large enough mapping */
test_expect_error_string("fstat(.test_file_cache) failed: "
"Bad file descriptor");
const char *errstr =
t_strdup_printf("fstat(.test_file_cache) failed: %s",
strerror(EBADF));
test_expect_error_string(errstr);
test_assert(file_cache_read(cache, 0, 2*1024*1024) == -1);
const unsigned char *map = file_cache_get_map(cache, &size);
test_assert(size == 0);
Expand All @@ -259,17 +261,16 @@ static void test_file_cache_errors(void)
.rlim_cur = 1,
.rlim_max = rl_cur.rlim_max
};
const char *errstr =
t_strdup_printf("mmap_anon(.test_file_cache, %zu) failed: "
"Cannot allocate memory", page_size);
errstr = t_strdup_printf("mmap_anon(.test_file_cache, %zu) failed: %s",
page_size, strerror(ENOMEM));
test_assert(setrlimit(RLIMIT_AS, &rl_new) == 0);
test_expect_error_string(errstr);
test_assert(file_cache_set_size(cache, 1024) == -1);
test_assert(setrlimit(RLIMIT_AS, &rl_cur) == 0);

/* same for mremap */
errstr = t_strdup_printf("mremap_anon(.test_file_cache, %zu) failed: "
"Cannot allocate memory", page_size*2);
errstr = t_strdup_printf("mremap_anon(.test_file_cache, %zu) failed: %s",
page_size*2, strerror(ENOMEM));
test_assert(file_cache_set_size(cache, 1) == 0);
test_assert(setrlimit(RLIMIT_AS, &rl_new) == 0);
test_expect_error_string(errstr);
Expand Down