1 /*
2  * Copyright © 2021 Manuel Stoeckl
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 #ifndef WAYPIPE_TESTCOMMON_H
26 #define WAYPIPE_TESTCOMMON_H
27 
28 #include "main.h"
29 #include "parsing.h"
30 #include "util.h"
31 
32 /** a simple log handler to STDOUT for use by test programs */
33 void test_log_handler(const char *file, int line, enum log_level level,
34 		const char *fmt, ...);
35 void test_atomic_log_handler(const char *file, int line, enum log_level level,
36 		const char *fmt, ...);
37 
38 extern uint64_t time_value;
39 extern uint64_t local_time_offset;
40 
41 void *read_file_into_mem(const char *path, size_t *len);
42 struct msg {
43 	uint32_t *data;
44 	int len;
45 	int *fds;
46 	int nfds;
47 };
48 struct test_state {
49 	struct main_config config;
50 	struct globals glob;
51 	bool display_side;
52 	bool failed;
53 	/* messages received from the other side */
54 	int nrcvd;
55 	struct msg *rcvd;
56 	uint64_t local_time_offset;
57 };
58 
59 void send_wayland_msg(struct test_state *src, const struct msg msg,
60 		struct transfer_queue *queue);
61 void receive_wire(struct test_state *src, struct transfer_queue *queue);
62 
63 void send_protocol_msg(struct test_state *src, struct test_state *dst,
64 		const struct msg msg);
65 int setup_state(struct test_state *s, bool display_side, bool has_gpu);
66 void cleanup_state(struct test_state *s);
67 
68 #endif /* WAYPIPE_TESTCOMMON_H */
69