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