Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / lustre / tests / lutf / src / lutf.h
1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4  * This file is part of Lustre, http://www.lustre.org/
5  *
6  * lustre/tests/lutf/lutf.h
7  *
8  * Author: Amir Shehata <ashehata@whamcloud.com>
9  *
10  */
11
12 #ifndef LUTF_H
13 #define LUTF_H
14
15 #include <stdbool.h>
16 #include <stdio.h>
17 #include <stdarg.h>
18 #include <time.h>
19 #include <sys/stat.h>
20 #include "lutf_common.h"
21 #include "lutf_agent.h"
22 #include "lutf_message.h"
23
24 extern FILE *out;
25 extern char *outlog;
26
27 #define OUT_LOG_NAME "lutf_out.log"
28 #define OUT_PY_LOG "lutf_py.log"
29 #define LARGE_LOG_FILE 400000000 /* 400 MB */
30
31 static inline void lutf_log_print(bool error, char *color1, char *color2,
32                                   char *file, int line, char *fmt, ...)
33 {
34         time_t debugnow;
35         int di;
36         char debugtimestr[30];
37         struct stat st;
38         va_list args;
39
40         /* check if the log file has grown too large */
41         stat(outlog, &st);
42         if (st.st_size > LARGE_LOG_FILE)
43                 out = freopen(outlog, "w", out);
44
45         time(&debugnow);
46         ctime_r(&debugnow, debugtimestr);
47         for (di = 0; di < 30; di++) {
48                 if (debugtimestr[di] == '\n')
49                         debugtimestr[di] = '\0';
50         }
51
52         fprintf(out, "%s%s %s:%s:%d " RESET "%s- ", color1,
53                 (error) ? "ERROR" : "", debugtimestr, file, line, color2);
54         va_start(args, fmt);
55         vfprintf(out, fmt, args);
56         va_end(args);
57         fprintf(out, RESET"\n");
58         fflush(out);
59 }
60
61 #define PERROR(fmt, args...) lutf_log_print(true, BOLDRED, RED, __FILE__, __LINE__, fmt, ## args)
62 #define PDEBUG(fmt, args...) lutf_log_print(false, BOLDGREEN, GREEN, __FILE__, __LINE__, fmt, ## args)
63
64 typedef struct hb_info_s {
65         struct sockaddr_in master_address;
66         int agent_telnet_port;
67         char node_name[MAX_STR_LEN];
68 } hb_info_t;
69
70 typedef struct lutf_listener_info_s {
71         lutf_type_t type;
72         int listen_port;
73         hb_info_t hb_info;
74 } lutf_listener_info_t;
75
76 typedef struct lutf_config_params_s {
77         lutf_listener_info_t l_info;
78         lutf_run_mode_t shell; /* run in [non]-interactive or daemon mode */
79         char *cfg_path; /* path to config file */
80         char *lutf_path; /* path to lutf */
81         char *py_path; /* other python specific paths */
82         char *master_name; /* name of master. Important if I'm an agent */
83         char *suite; /* name of suite to run. Run all if not present */
84         char *suite_list; /* list of suites to run. Takes precedence
85                              over single suite parameter */
86         char *script; /* name of script to run. Suite must be specified */
87         char *pattern; /* file match pattern */
88         char *results_file; /* path to results file */
89         char *tmp_dir; /* directory to put temporary files */
90         struct cYAML *agents; /* list of agents to wait for before
91                                * starting the test
92                                */
93 } lutf_config_params_t;
94
95 extern lutf_config_params_t g_lutf_cfg;
96
97 static inline const char *lutf_rc2str(lutf_rc_t rc)
98 {
99         static const char * const str[] = {
100                 [EN_LUTF_RC_OK] = "RC_OK",
101                 [EN_LUTF_RC_FAIL*-1] = "RC_FAIL",
102                 [EN_LUTF_RC_SYS_ERR*-1] = "RC_SYSTEM_ERROR",
103                 [EN_LUTF_RC_BAD_VERSION*-1] = "RC_BAD_VERSION",
104                 [EN_LUTF_RC_SOCKET_FAIL*-1] = "RC_SOCKET_FAIL",
105                 [EN_LUTF_RC_BIND_FAILED*-1] = "RC_BIND_FAIL",
106                 [EN_LUTF_RC_LISTEN_FAILED*-1] = "RC_LISTEN_FAIL",
107                 [EN_LUTF_RC_CLIENT_CLOSED*-1] = "RC_CLIENT_CLOSED",
108                 [EN_LUTF_RC_ERR_THREAD_STARTUP*-1] = "RC_ERR_THREAD_START",
109                 [EN_LUTF_RC_AGENT_NOT_FOUND*-1] = "RC_AGENT_NOT_FOUND",
110                 [EN_LUTF_RC_PY_IMPORT_FAIL*-1] = "RC_PY_IMPORT_FAIL",
111                 [EN_LUTF_RC_PY_SCRIPT_FAIL*-1] = "RC_PY_SCRIPT_FAIL",
112                 [EN_LUTF_RC_RPC_FAIL*-1] = "RC_RPC_FAIL",
113                 [EN_LUTF_RC_OOM*-1] = "RC_OOM",
114                 [EN_LUTF_RC_BAD_PARAM*-1] = "RC_BAD_PARAM",
115                 [EN_LUTF_RC_BAD_ADDR*-1] = "RC_BAD_ADDR",
116                 [EN_LUTF_RC_MISSING_PARAM*-1] = "RC_MISSING_PARAM",
117                 [EN_LUTF_RC_TIMEOUT*-1] = "RC_TIMEOUT",
118         };
119
120         if (rc <= EN_LUTF_RC_MAX)
121                 return "BAD RC";
122
123         rc *= -1;
124
125         return str[rc];
126 }
127
128 int establishTCPConnection(unsigned long uiAddress,
129                            int iPort,
130                            bool b_non_block,
131                            bool endian);
132
133
134 lutf_rc_t sendTcpMessage(int iTcpSocket, char *pcBody, int iBodySize);
135
136 lutf_rc_t lutf_send_msg(int fd, char *msg, size_t msg_size,
137                         lutf_msg_type_t type);
138
139 lutf_rc_t populateMsgHdr(int rsocket, char *msg_hdr,
140                          int msg_type, int msg_size,
141                          int lutf_version_number);
142
143 lutf_rc_t readTcpMessage(int iFd, char *pcBuffer,
144                          int iBufferSize, int iTimeout);
145
146 lutf_rc_t closeTcpConnection(int iTcpSocket);
147
148 #endif /* LUTF_H */