Commit 01339a99 authored by Kirill Smelkov's avatar Kirill Smelkov

X CHECK_MRU -> CHECK_MRU + CHECK_DIRTY

parent a30e0568
......@@ -223,44 +223,77 @@ int M(VMA *vma, pgoff_t idx) { return bitmap_test_bit(vma->page_ismappedv, idx)
ok1(!pagemap_get(&(fileh)->pagemap, (pgoffset))); \
} while (0)
/* _check_mru checks that ram has MRU pages as specified by pagev */
void _check_mru(RAM *ram, Page *mruok[], int nok, const char *func, const char *file, int line) {
Page **mruv = NULL, *page;
int n = 0, i;
struct list_head *hlru = ram->lru_list.prev;
// collect actual mru
while (hlru != &ram->lru_list) {
page = list_entry(hlru, typeof(*page), lru);
n++;
mruv = realloc(mruv, n*sizeof(*mruv));
mruv[n-1] = page;
hlru = hlru->prev;
}
/* _assert_pagev asserts that two page vectors are the same */
void _assert_pagev(const char *subj, Page **vok, int nok, Page **pagev, int n,
const char *func, const char *file, int line)
{
int i;
if (!(n == nok && !memcmp(mruv, mruok, n*sizeof(*mruok)))) {
fprintf(stderr, "check_mru: different\n");
if (!(n == nok && !memcmp(pagev, vok, n*sizeof(*pagev)))) {
fprintf(stderr, "%s: different\n", subj);
fprintf(stderr, "have: [");
for (i=0; i<n; i++)
fprintf(stderr, "%sp%ld", (i > 0 ? ", " : ""), mruv[i]->f_pgoffset);
fprintf(stderr, "%sp%ld", (i > 0 ? ", " : ""), pagev[i]->f_pgoffset);
fprintf(stderr, "]\n");
fprintf(stderr, "want: [");
for (i=0; i<nok; i++)
fprintf(stderr, "%sp%ld", (i > 0 ? ", " : ""), mruok[i]->f_pgoffset);
fprintf(stderr, "%sp%ld", (i > 0 ? ", " : ""), vok[i]->f_pgoffset);
fprintf(stderr, "]\n");
_gen_result(0, func, file, line, "check_mru failed");
_gen_result(0, func, file, line, "%s failed", subj);
}
}
/* _check_mru checks that ram has MRU pages as specified by pagev */
void _check_mru(RAM *ram, Page *mruok[], int nok, const char *func, const char *file, int line) {
Page **mruv = NULL, *page;
int n = 0;
struct list_head *h;
// collect mruv
list_for_each_backwardly(h, &ram->lru_list) {
page = list_entry(h, typeof(*page), lru);
n++;
mruv = realloc(mruv, n*sizeof(*mruv));
mruv[n-1] = page;
}
_assert_pagev("check_mru", mruok, nok, mruv, n, func, file, line);
free(mruv);
}
/* CHECK_MRU(ram, ...pagev) - check that ram has MRU pages as expected */
/* CHECK_MRU(ram, ...pagev) - assert that ram has MRU pages as expected */
#define CHECK_MRU(ram, ...) do { \
Page *__mruok[] = {__VA_ARGS__}; \
_check_mru(ram, __mruok, ARRAY_SIZE(__mruok), __func__, __FILE__, __LINE__); \
} while(0)
void _check_dity(BigFileH *fileh, Page *dirtyok[], int nok, const char *func, const char *file, int line) {
Page **dirtyv = NULL, *page;
int n = 0;
struct list_head *h;
// collect dirtyv
list_for_each(h, &fileh->dirty_pages) {
page = list_entry(h, typeof(*page), in_dirty);
n++;
dirtyv = realloc(dirtyv, n*sizeof(*dirtyv));
dirtyv[n-1] = page;
}
_assert_pagev("check_dirty", dirtyok, nok, dirtyv, n, func, file, line);
free(dirtyv);
}
/* CHECK_DIRTY(fileh, ...pagev) - assert that fileh has dirty pages as expected */
#define CHECK_DIRTY(fileh, ...) do { \
Page *__dirtyok[] = {__VA_ARGS__}; \
_check_dirty(fileh, __dirtyok, ARRAY_SIZE(__dirtyok), __func__, __FILE__, __LINE__); \
} while(0)
/* vma_on_pagefault() assumes virtmem_lock is taken by caller and can ask it to
* retry. Handle fault to the end, like on_pagefault() does. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment