| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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 |
|
| 33 |
#define RC_PASS 0 |
| 34 |
#define RC_CONFIG 1 |
| 35 |
#define RC_FAIL 2 |
| 36 |
#define RC_XFAIL 3 |
| 37 |
#define RC_XPASS 4 |
| 38 |
#define RC_BUG 99 |
| 39 |
|
| 40 |
#define FOURGB (1UL << 32) |
| 41 |
|
| 42 |
extern int verbose_test; |
| 43 |
extern char *test_name; |
| 44 |
void check_free_huge_pages(int nr_pages_needed); |
| 45 |
void check_must_be_root(void); |
| 46 |
void check_hugetlb_shm_group(void); |
| 47 |
void check_online_cpus(int[], int); |
| 48 |
void test_init(int argc, char *argv[]); |
| 49 |
int test_addr_huge(void *p); |
| 50 |
unsigned long long get_mapping_page_size(void *p); |
| 51 |
long read_meminfo(const char *tag); |
| 52 |
ino_t get_addr_inode(void *p); |
| 53 |
int 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 |
|
| 67 |
void 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 |
|
| 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 |
|
| 122 |
int remove_shmid(int shmid); |
| 123 |
|
| 124 |
extern long gethugepagesize (void) __attribute__ ((weak)); |
| 125 |
|
| 126 |
static 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 |
|
| 140 |
static 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 |
|
| 158 |
int using_system_hpage_size(const char *mount); |
| 159 |
|
| 160 |
|
| 161 |
int kernel_has_private_reservations(void); |
| 162 |
|
| 163 |
#endif |