Debian Codegraph @

tests/meminfo_nohuge.c

raw symbols SCIP
1 /*
2 * libhugetlbfs - Easy use of Linux hugepages
3 * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #define _GNU_SOURCE
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <dlfcn.h>
28 #include <stdarg.h>
29
30 #include <hugetlbfs.h>
31
32 #include "hugetests.h"
33
34 /* We override the normal open, so libhugetlbfs gets a /proc/meminfo
35 * which doesn't contain any hugepage information */
36 int open(const char *path, int flags, ...)
37 {
38 int (*old_open)(const char *, int, ...);
39 int fd;
40
41 if (strcmp(path, "/proc/meminfo") == 0) {
42 FILE *f;
43
44 f = popen("/bin/grep -vi ^hugepage /proc/meminfo", "r");
45 return fileno(f);
46 }
47
48 if (strcmp(path, "/proc/mounts") == 0) {
49 FILE *f;
50
51 f = popen("/bin/grep -vi hugetlbfs /proc/mounts", "r");
52 return fileno(f);
53 }
54
55 old_open = dlsym(RTLD_NEXT, "open");
56 if (flags & O_CREAT) {
57 va_list ap;
58
59 va_start(ap, flags);
60 fd = (*old_open)(path, flags, va_arg(ap, mode_t));
61 va_end(ap);
62 return fd;
63 } else {
64 return (*old_open)(path, flags);
65 }
66 }
67
68 int main(int argc, char *argv[])
69 {
70 long hpage_size;
71
72 test_init(argc, argv);
73
74 hpage_size = gethugepagesize();
75 if (hpage_size == -1)
76 PASS();
77
78 FAIL("Mysteriously found a hugepage size of %ld\n", hpage_size);
79 }