Whamcloud - gitweb
LU-13569 tests: Check LNet Health recovery logic
[fs/lustre-release.git] / lustre / tests / mpi / lp_utils.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program 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  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  */
26 /*
27  * This file is part of Lustre, http://www.lustre.org/
28  *
29  * lustre/tests/lp_utils.h
30  *
31  * Author: You Feng <youfeng@clusterfs.com>
32  */
33
34 #ifndef __LP_UTILS_H__
35 #define __LP_UTILS_H__
36
37 #include <linux/lustre/lustre_user.h>
38
39 #define FAILF(fmt, ...) \
40 do { \
41         printf("%s: Process %d (%s)\n", timestamp(), rank, hostname); \
42         if (debug) \
43                 printf("\tFAILED in %s:%d:%s()\n", \
44                        __FILE__, __LINE__, __func__); \
45         else \
46                 printf("\tFAILED in %s()\n", __func__); \
47         printf(fmt, ##__VA_ARGS__); \
48         fflush(stdout); \
49         MPI_Abort(MPI_COMM_WORLD, 1); \
50 } while (0)
51
52 #define FAIL(msg)       FAILF("%s", (msg))
53
54 #ifndef MAX
55 #define MAX(a, b)       ((a) > (b) ? (b) : (a))
56 #endif
57
58 #define FILEMODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH
59 #define MAX_FILENAME_LEN 512
60
61 extern int verbose;
62 extern int debug;
63
64 extern int rank;
65 extern int size;
66
67 extern char hostname[];
68 extern char *timestamp();
69 extern char *testdir;
70
71 extern void begin(char *str);
72 extern void end(char *str);
73
74 extern void dump_diff(char *orig_buf, char *buf, int len, long off);
75 extern void lp_gethostname(void);
76
77 extern void create_file(char *name, long filesize, int fill);
78 extern void fill_file(char *name, long filesize);
79
80 #define LP_STAT_FMT \
81  \
82 "Stat error:\n \
83 \tfields\t\tvalue\told value\n \
84 \tst_dev\t\t%d\t%d\n \
85 \tst_ino\t\t%d\t%d\n \
86 \tst_mode\t\t%o\t%o\n \
87 \tst_nlink\t%d\t%d\n \
88 \tst_uid\t\t%d\t%d\n \
89 \tst_gid\t\t%d\t%d\n \
90 \tst_rdev\t\t%x.%x\t%x.%x\n \
91 \tst_size\t\t%lu\t%lu\n \
92 \tst_blksize\t%d\t%d\n \
93 \tst_blocks\t%u\t%u\n \
94 \tst_atime\t%d\t%d\n \
95 \tst_mtime\t%d\t%d\n \
96 \tst_ctime\t%d\t%d\n"
97                                                                                 
98 #define LP_STAT_ARGS \
99  \
100 (int)state->st_dev, (int)old_state->st_dev, \
101 (int)state->st_ino, (int)old_state->st_ino, \
102 state->st_mode & 07777, old_state->st_mode & 07777, \
103 (int)state->st_nlink, (int)old_state->st_nlink, \
104 state->st_uid, old_state->st_uid, \
105 state->st_gid, old_state->st_gid, \
106 (int)((state->st_rdev >> 8) & 0xff), (int)(state->st_rdev & 0xff), \
107 (int)((old_state->st_rdev >> 8) & 0xff), (int)(old_state->st_rdev & 0xff), \
108 (unsigned long)state->st_size, (unsigned long)old_state->st_size, \
109 (int)state->st_blksize, (int)old_state->st_blksize, \
110 (unsigned int)state->st_blocks, (unsigned int)old_state->st_blocks, \
111 (int)state->st_atime, (int)old_state->st_atime, \
112 (int)state->st_mtime, (int)old_state->st_mtime, \
113 (int)state->st_ctime, (int)old_state->st_ctime
114
115 extern void check_stat(char *filename, struct stat *state, struct stat *old_state);
116 extern void remove_file(char *name);
117 extern void remove_file_or_dir(char *name);
118 extern void fill_stride(char *buf, int buf_size, long long rank, long long _off);
119
120 #endif /* __LP_UTILS_H__ */