Ticket #17895: hugetests.h

File hugetests.h, 4.3 KB (added by korli, 2 years ago)
Line 
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 * MECHANTABILITY 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#ifndef _HUGETESTS_H
21#define _HUGETESTS_H
22
23#include <errno.h>
24#include <string.h>
25#include <unistd.h>
26
27//#include "libhugetlbfs_privutils.h"
28//#include "libhugetlbfs_testprobes.h"
29
30#define DEBUG
31
32/* Test return codes */
33#define RC_PASS 0
34#define RC_CONFIG 1
35#define RC_FAIL 2
36#define RC_XFAIL 3 /* Expected Failure */
37#define RC_XPASS 4 /* Unexpected Pass */
38#define RC_BUG 99
39
40#define FOURGB (1UL << 32)
41
42extern int verbose_test;
43extern char *test_name;
44void check_free_huge_pages(int nr_pages_needed);
45void check_must_be_root(void);
46void check_hugetlb_shm_group(void);
47void check_online_cpus(int[], int);
48void test_init(int argc, char *argv[]);
49int test_addr_huge(void *p);
50unsigned long long get_mapping_page_size(void *p);
51long read_meminfo(const char *tag);
52ino_t get_addr_inode(void *p);
53int range_is_mapped(unsigned long low, unsigned long high);
54
55#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
56#define PALIGN(p, a) ((void *)ALIGN((unsigned long)(p), (a)))
57
58#ifndef barrier
59# ifdef mb
60# define barrier() mb()
61# else
62# define barrier() __asm__ __volatile__ ("" : : : "memory")
63# endif
64#endif
65
66/* Each test case must define this function */
67void cleanup(void);
68
69#define verbose_printf(...) \
70 if (verbose_test) { \
71 printf(__VA_ARGS__); \
72 fflush(stdout); \
73 }
74#define ERR "ERR: "
75#define ERROR(fmt, args...) fprintf(stderr, ERR fmt, ## args)
76
77
78#define PASS() \
79 do { \
80 cleanup(); \
81 printf("PASS\n"); \
82 exit(RC_PASS); \
83 } while (0)
84
85#define PASS_INCONCLUSIVE() \
86 do { \
87 cleanup(); \
88 printf("PASS (inconclusive)\n"); \
89 exit(RC_PASS); \
90 } while (0)
91
92#define IRRELEVANT() \
93 do { \
94 cleanup(); \
95 printf("PASS (irrelevant)\n"); \
96 exit(RC_PASS); \
97 } while (0)
98
99/* Look out, gcc extension below... */
100#define FAIL(fmt, ...) \
101 do { \
102 cleanup(); \
103 printf("FAIL\t" fmt "\n", ##__VA_ARGS__); \
104 exit(RC_FAIL); \
105 } while (0)
106
107#define CONFIG(fmt, ...) \
108 do { \
109 cleanup(); \
110 printf("Bad configuration: " fmt "\n", ##__VA_ARGS__); \
111 exit(RC_CONFIG); \
112 } while (0)
113
114#define TEST_BUG(fmt, ...) \
115 do { \
116 cleanup(); \
117 printf("BUG in testsuite: " fmt "\n", ##__VA_ARGS__); \
118 exit(RC_BUG); \
119 } while (0)
120
121/* stressutils.c stuff */
122int remove_shmid(int shmid);
123
124extern long gethugepagesize (void) __attribute__ ((weak));
125
126static inline long check_hugepagesize()
127{
128 long __hpage_size = gethugepagesize();
129 if (__hpage_size < 0) {
130 if (errno == ENOSYS)
131 CONFIG("No hugepage kernel support\n");
132 else if (errno == EOVERFLOW)
133 CONFIG("Hugepage size too large");
134 else
135 CONFIG("Hugepage size (%s)", strerror(errno));
136 }
137 return __hpage_size;
138}
139
140static inline void check_if_gigantic_page(void)
141{
142 long page_size, hpage_size, max_order;
143 FILE *fp;
144
145 page_size = sysconf(_SC_PAGESIZE);
146 hpage_size = gethugepagesize();
147 fp = popen("cat /proc/pagetypeinfo | "
148 "awk '/Free pages count per migrate type at order/ "
149 "{print $NF}'", "r");
150 if (!fp || fscanf(fp, "%lu", &max_order) < 0)
151 FAIL("Couldn't determine max page allocation order");
152
153 pclose(fp);
154 if (hpage_size > ((1 << max_order) * page_size))
155 CONFIG("Gigantic pages are not supported");
156}
157
158int using_system_hpage_size(const char *mount);
159
160/* WARNING: Racy -- use for test cases only! */
161int kernel_has_private_reservations(void);
162
163#if 1
164int hugetlbfs_unlinked_fd(int size);
165#ifndef B_PAGE_SIZE
166#define B_PAGE_SIZE 4096
167#endif
168long gethugepagesize() { return B_PAGE_SIZE; }
169#endif
170
171#endif /* _HUGETESTS_H */