Skip to content

Commit 3f045e0

Browse files
committed
test/zdtm/static/maps02: add MAP_DROPPABLE testcase
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
1 parent 511a663 commit 3f045e0

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

test/zdtm/static/get_smaps_bits.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#define MAP_HUGETLB 0x40000
77
#endif
88

9+
#ifndef MAP_DROPPABLE
10+
#define MAP_DROPPABLE 0x08
11+
#endif
12+
913
#ifndef MADV_HUGEPAGE
1014
#define MADV_HUGEPAGE 14
1115
#endif
@@ -45,6 +49,8 @@ static void parse_vmflags(char *buf, unsigned long *flags, unsigned long *madv)
4549
*flags |= MAP_NORESERVE;
4650
else if (_vmflag_match(tok, "ht"))
4751
*flags |= MAP_HUGETLB;
52+
else if (_vmflag_match(tok, "dp"))
53+
*flags |= MAP_DROPPABLE;
4854

4955
/* madvise() block */
5056
if (_vmflag_match(tok, "sr"))

test/zdtm/static/maps02.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#include "zdtmtst.h"
33
#include "get_smaps_bits.h"
44

5+
#ifndef MAP_DROPPABLE
6+
#define MAP_DROPPABLE 0x08
7+
#endif
8+
59
#ifndef MADV_DONTDUMP
610
#define MADV_DONTDUMP 16
711
#endif
@@ -27,8 +31,14 @@ static int alloc_anon_mmap(struct mmap_data *m, int flags, int adv)
2731
{
2832
m->start = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, flags, -1, 0);
2933
if (m->start == MAP_FAILED) {
30-
pr_perror("mmap failed");
31-
return -1;
34+
if (errno == EINVAL) {
35+
test_msg("mmap failed, no kernel support\n");
36+
*m = (struct mmap_data){};
37+
return 0;
38+
} else {
39+
pr_perror("mmap failed");
40+
return -1;
41+
}
3242
}
3343

3444
if (madvise(m->start, MEM_SIZE, adv)) {
@@ -47,7 +57,7 @@ static int alloc_anon_mmap(struct mmap_data *m, int flags, int adv)
4757

4858
int main(int argc, char **argv)
4959
{
50-
struct mmap_data m[6] = {};
60+
struct mmap_data m[7] = {};
5161
size_t i;
5262

5363
test_init(argc, argv);
@@ -76,6 +86,10 @@ int main(int argc, char **argv)
7686
if (alloc_anon_mmap(&m[5], MAP_PRIVATE | MAP_ANONYMOUS, MADV_WIPEONFORK))
7787
return -1;
7888

89+
test_msg("Alloc droppable\n");
90+
if (alloc_anon_mmap(&m[6], MAP_DROPPABLE | MAP_ANONYMOUS, MADV_NORMAL))
91+
return -1;
92+
7993
test_msg("Fetch existing flags/adv\n");
8094
for (i = 0; i < sizeof(m) / sizeof(m[0]); i++) {
8195
if (get_smaps_bits((unsigned long)m[i].start, &m[i].orig_flags, &m[i].orig_madv))

0 commit comments

Comments
 (0)