]> git.proxmox.com Git - spiceterm.git/blame - test_display_base.c
remove test code
[spiceterm.git] / test_display_base.c
CommitLineData
cc04455b
DM
1#include <stdlib.h>
2#include <math.h>
3#include <string.h>
4#include <stdio.h>
5#include <unistd.h>
6#include <signal.h>
7#include <wait.h>
8#include <sys/select.h>
9#include <sys/types.h>
10#include <getopt.h>
11
4219b121 12#include "glyphs.h"
cc04455b 13#include <spice.h>
474762d8 14#include <spice/enums.h>
cc04455b
DM
15#include <spice/macros.h>
16#include <spice/qxl_dev.h>
17
18#include "test_display_base.h"
cc04455b
DM
19
20#define MEM_SLOT_GROUP_ID 0
21
22#define NOTIFY_DISPLAY_BATCH (SINGLE_PART/2)
23#define NOTIFY_CURSOR_BATCH 10
24
65007123
DM
25/* these colours are from linux kernel drivers/char/vt.c */
26/* the default colour table, for VGA+ colour systems */
27int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
28 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
29int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
30 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
31int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
32 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
33
cc04455b
DM
34/* Parts cribbed from spice-display.h/.c/qxl.c */
35
36typedef struct SimpleSpiceUpdate {
37 QXLCommandExt ext; // first
38 QXLDrawable drawable;
39 QXLImage image;
40 uint8_t *bitmap;
41} SimpleSpiceUpdate;
42
cc04455b
DM
43static void test_spice_destroy_update(SimpleSpiceUpdate *update)
44{
45 if (!update) {
46 return;
47 }
48 if (update->drawable.clip.type != SPICE_CLIP_TYPE_NONE) {
49 uint8_t *ptr = (uint8_t*)update->drawable.clip.data;
50 free(ptr);
51 }
9f9c8d83
DM
52 g_free(update->bitmap);
53 g_free(update);
cc04455b
DM
54}
55
56#define DEFAULT_WIDTH 640
57#define DEFAULT_HEIGHT 320
58
59#define SINGLE_PART 4
60static const int angle_parts = 64 / SINGLE_PART;
61static int unique = 1;
62static int color = -1;
63static int c_i = 0;
64
cc04455b
DM
65__attribute__((noreturn))
66static void sigchld_handler(int signal_num) // wait for the child process and exit
67{
68 int status;
69 wait(&status);
70 exit(0);
71}
72
cc04455b
DM
73static void set_cmd(QXLCommandExt *ext, uint32_t type, QXLPHYSICAL data)
74{
75 ext->cmd.type = type;
76 ext->cmd.data = data;
77 ext->cmd.padding = 0;
78 ext->group_id = MEM_SLOT_GROUP_ID;
79 ext->flags = 0;
80}
81
82static void simple_set_release_info(QXLReleaseInfo *info, intptr_t ptr)
83{
84 info->id = ptr;
85 //info->group_id = MEM_SLOT_GROUP_ID;
86}
87
7b4a7650
DM
88// We shall now have a ring of commands, so that we can update
89// it from a separate thread - since get_command is called from
90// the worker thread, and we need to sometimes do an update_area,
91// which cannot be done from red_worker context (not via dispatcher,
92// since you get a deadlock, and it isn't designed to be done
93// any other way, so no point testing that).
94
95
96static void push_command(Test *test, QXLCommandExt *ext)
97{
98 g_mutex_lock(test->command_mutex);
99
100 while (test->commands_end - test->commands_start >= COMMANDS_SIZE) {
101 g_cond_wait(test->command_cond, test->command_mutex);
102 }
103 g_assert(test->commands_end - test->commands_start < COMMANDS_SIZE);
104 test->commands[test->commands_end % COMMANDS_SIZE] = ext;
105 test->commands_end++;
106 g_mutex_unlock(test->command_mutex);
107
108 test->qxl_worker->wakeup(test->qxl_worker);
109}
110
9f9c8d83 111/* bitmap are freed, so they must be allocated with g_malloc */
cc04455b
DM
112SimpleSpiceUpdate *test_spice_create_update_from_bitmap(uint32_t surface_id,
113 QXLRect bbox,
4219b121 114 uint8_t *bitmap)
cc04455b
DM
115{
116 SimpleSpiceUpdate *update;
117 QXLDrawable *drawable;
118 QXLImage *image;
119 uint32_t bw, bh;
120
121 bh = bbox.bottom - bbox.top;
122 bw = bbox.right - bbox.left;
123
9f9c8d83 124 update = g_new0(SimpleSpiceUpdate, 1);
cc04455b
DM
125 update->bitmap = bitmap;
126 drawable = &update->drawable;
127 image = &update->image;
128
129 drawable->surface_id = surface_id;
130
131 drawable->bbox = bbox;
4219b121 132 drawable->clip.type = SPICE_CLIP_TYPE_NONE;
cc04455b
DM
133 drawable->effect = QXL_EFFECT_OPAQUE;
134 simple_set_release_info(&drawable->release_info, (intptr_t)update);
135 drawable->type = QXL_DRAW_COPY;
136 drawable->surfaces_dest[0] = -1;
137 drawable->surfaces_dest[1] = -1;
138 drawable->surfaces_dest[2] = -1;
139
140 drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;
141 drawable->u.copy.src_bitmap = (intptr_t)image;
142 drawable->u.copy.src_area.right = bw;
143 drawable->u.copy.src_area.bottom = bh;
144
145 QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, unique);
146 image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
147 image->bitmap.flags = QXL_BITMAP_DIRECT | QXL_BITMAP_TOP_DOWN;
148 image->bitmap.stride = bw * 4;
149 image->descriptor.width = image->bitmap.x = bw;
150 image->descriptor.height = image->bitmap.y = bh;
151 image->bitmap.data = (intptr_t)bitmap;
152 image->bitmap.palette = 0;
153 image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
154
155 set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable);
156
157 return update;
158}
159
65007123 160static SimpleSpiceUpdate *test_draw_char(Test *test, int x, int y, int c, int fg, int bg)
cc04455b
DM
161{
162 int top, left;
163 uint8_t *dst;
164 uint8_t *bitmap;
165 int bw, bh;
9462ba15 166 int i, j;
cc04455b
DM
167 QXLRect bbox;
168
8a22eb4f
DM
169 left = x*8;
170 top = y*16;
26c64941 171
77133eee 172 // printf("DRAWCHAR %d %d %d\n", left, top, c);
8a22eb4f 173
cc04455b
DM
174 unique++;
175
26c64941
DM
176 bw = 8;
177 bh = 16;
cc04455b 178
9f9c8d83 179 bitmap = dst = g_malloc(bw * bh * 4);
cc04455b 180
9462ba15
DM
181 unsigned char *data = vt_font_data + c*16;
182 unsigned char d = *data;
183
65007123
DM
184 g_assert(fg >= 0 && fg < 16);
185 g_assert(bg >= 0 && bg < 16);
186
187 unsigned char fgc_red = default_red[fg];
188 unsigned char fgc_blue = default_blu[fg];
189 unsigned char fgc_green = default_grn[fg];
190 unsigned char bgc_red = default_red[bg];
191 unsigned char bgc_blue = default_blu[bg];
192 unsigned char bgc_green = default_grn[bg];
9f9c8d83 193
9462ba15
DM
194 for (j = 0; j < 16; j++) {
195 for (i = 0; i < 8; i++) {
196 if ((i&7) == 0) {
197 d=*data;
198 data++;
199 }
200 if (d&0x80) {
9f9c8d83
DM
201 *(dst) = fgc_blue;
202 *(dst+1) = fgc_green;
203 *(dst+2) = fgc_red;
204 *(dst+3) = 0;
205 } else {
206 *(dst) = bgc_blue;
207 *(dst+1) = bgc_green;
208 *(dst+2) = bgc_red;
9462ba15
DM
209 *(dst+3) = 0;
210 }
211 d<<=1;
212 dst += 4;
213 }
cc04455b
DM
214 }
215
216 bbox.left = left; bbox.top = top;
217 bbox.right = left + bw; bbox.bottom = top + bh;
9462ba15 218
8a22eb4f 219 return test_spice_create_update_from_bitmap(0, bbox, bitmap);
cc04455b
DM
220}
221
7b4a7650
DM
222void test_spice_scroll(Test *test, int x1, int y1, int x2, int y2, int src_x, int src_y)
223{
224 SimpleSpiceUpdate *update;
225 QXLDrawable *drawable;
226 QXLRect bbox;
227
228 int surface_id = 0; // fixme
229
230 update = g_new0(SimpleSpiceUpdate, 1);
231 drawable = &update->drawable;
232
233 bbox.left = x1;
234 bbox.top = y1;
235 bbox.right = x2;
236 bbox.bottom = y2;
237
238 drawable->surface_id = surface_id;
239
240 drawable->bbox = bbox;
241 drawable->clip.type = SPICE_CLIP_TYPE_NONE;
242 drawable->effect = QXL_EFFECT_OPAQUE;
243 simple_set_release_info(&drawable->release_info, (intptr_t)update);
244 drawable->type = QXL_COPY_BITS;
245 drawable->surfaces_dest[0] = -1;
246 drawable->surfaces_dest[1] = -1;
247 drawable->surfaces_dest[2] = -1;
248
249 drawable->u.copy_bits.src_pos.x = src_x;
250 drawable->u.copy_bits.src_pos.y = src_y;
251
252 set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable);
253
254 push_command(test, &update->ext);
255}
256
257void test_spice_clear(Test *test, int x1, int y1, int x2, int y2)
258{
259 SimpleSpiceUpdate *update;
260 QXLDrawable *drawable;
261 QXLRect bbox;
262
263 int surface_id = 0; // fixme
264
265 update = g_new0(SimpleSpiceUpdate, 1);
266 drawable = &update->drawable;
267
268 bbox.left = x1;
269 bbox.top = y1;
270 bbox.right = x2;
271 bbox.bottom = y2;
272
273 drawable->surface_id = surface_id;
274
275 drawable->bbox = bbox;
276 drawable->clip.type = SPICE_CLIP_TYPE_NONE;
277 drawable->effect = QXL_EFFECT_OPAQUE;
278 simple_set_release_info(&drawable->release_info, (intptr_t)update);
279 drawable->type = QXL_DRAW_BLACKNESS;
280 drawable->surfaces_dest[0] = -1;
281 drawable->surfaces_dest[1] = -1;
282 drawable->surfaces_dest[2] = -1;
283
284 set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable);
285
286 push_command(test, &update->ext);
287}
288
cc04455b
DM
289static void create_primary_surface(Test *test, uint32_t width,
290 uint32_t height)
291{
292 QXLWorker *qxl_worker = test->qxl_worker;
293 QXLDevSurfaceCreate surface = { 0, };
294
295 g_assert(height <= MAX_HEIGHT);
296 g_assert(width <= MAX_WIDTH);
297 g_assert(height > 0);
298 g_assert(width > 0);
299
300 surface.format = SPICE_SURFACE_FMT_32_xRGB;
301 surface.width = test->primary_width = width;
302 surface.height = test->primary_height = height;
303 surface.stride = -width * 4; /* negative? */
304 surface.mouse_mode = TRUE; /* unused by red_worker */
305 surface.flags = 0;
306 surface.type = 0; /* unused by red_worker */
307 surface.position = 0; /* unused by red_worker */
308 surface.mem = (uint64_t)&test->primary_surface;
309 surface.group_id = MEM_SLOT_GROUP_ID;
310
311 test->width = width;
312 test->height = height;
313
314 qxl_worker->create_primary_surface(qxl_worker, 0, &surface);
315}
316
317QXLDevMemSlot slot = {
318.slot_group_id = MEM_SLOT_GROUP_ID,
319.slot_id = 0,
320.generation = 0,
321.virt_start = 0,
322.virt_end = ~0,
323.addr_delta = 0,
324.qxl_ram_size = ~0,
325};
326
327static void attache_worker(QXLInstance *qin, QXLWorker *_qxl_worker)
328{
329 Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
330
331 if (test->qxl_worker) {
332 if (test->qxl_worker != _qxl_worker)
333 printf("%s ignored, %p is set, ignoring new %p\n", __func__,
334 test->qxl_worker, _qxl_worker);
335 else
336 printf("%s ignored, redundant\n", __func__);
337 return;
338 }
339 printf("%s\n", __func__);
340 test->qxl_worker = _qxl_worker;
341 test->qxl_worker->add_memslot(test->qxl_worker, &slot);
342 create_primary_surface(test, DEFAULT_WIDTH, DEFAULT_HEIGHT);
343 test->qxl_worker->start(test->qxl_worker);
344}
345
346static void set_compression_level(QXLInstance *qin, int level)
347{
348 printf("%s\n", __func__);
349}
350
351static void set_mm_time(QXLInstance *qin, uint32_t mm_time)
352{
353}
cc04455b
DM
354static void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
355{
356 memset(info, 0, sizeof(*info));
357 info->num_memslots = 1;
358 info->num_memslots_groups = 1;
359 info->memslot_id_bits = 1;
360 info->memslot_gen_bits = 1;
aae93060 361 info->n_surfaces = 1;
cc04455b
DM
362}
363
cc04455b
DM
364// called from spice_server thread (i.e. red_worker thread)
365static int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
366{
63a34f43
DM
367 Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
368 int res = FALSE;
369
370 g_mutex_lock(test->command_mutex);
371
372 if ((test->commands_end - test->commands_start) == 0) {
373 res = FALSE;
374 goto ret;
cc04455b 375 }
63a34f43
DM
376
377 *ext = *test->commands[test->commands_start % COMMANDS_SIZE];
378 g_assert(test->commands_start < test->commands_end);
379 test->commands_start++;
380 g_cond_signal(test->command_cond);
381
382 res = TRUE;
383
384ret:
385 g_mutex_unlock(test->command_mutex);
386 return res;
cc04455b
DM
387}
388
cc04455b
DM
389static int req_cmd_notification(QXLInstance *qin)
390{
391 Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
392
8a22eb4f 393 //test->core->timer_start(test->wakeup_timer, test->wakeup_ms);
cc04455b
DM
394 return TRUE;
395}
f6cb554c 396
cc04455b
DM
397static void release_resource(QXLInstance *qin, struct QXLReleaseInfoExt release_info)
398{
399 QXLCommandExt *ext = (QXLCommandExt*)(unsigned long)release_info.info->id;
400 //printf("%s\n", __func__);
401 g_assert(release_info.group_id == MEM_SLOT_GROUP_ID);
402 switch (ext->cmd.type) {
403 case QXL_CMD_DRAW:
404 test_spice_destroy_update((void*)ext);
405 break;
406 case QXL_CMD_SURFACE:
407 free(ext);
408 break;
409 case QXL_CMD_CURSOR: {
410 QXLCursorCmd *cmd = (QXLCursorCmd *)(unsigned long)ext->cmd.data;
411 if (cmd->type == QXL_CURSOR_SET) {
412 free(cmd);
413 }
414 free(ext);
415 break;
416 }
417 default:
418 abort();
419 }
420}
421
422#define CURSOR_WIDTH 32
423#define CURSOR_HEIGHT 32
424
425static struct {
426 QXLCursor cursor;
427 uint8_t data[CURSOR_WIDTH * CURSOR_HEIGHT * 4]; // 32bit per pixel
428} cursor;
429
430static void cursor_init()
431{
432 cursor.cursor.header.unique = 0;
433 cursor.cursor.header.type = SPICE_CURSOR_TYPE_COLOR32;
434 cursor.cursor.header.width = CURSOR_WIDTH;
435 cursor.cursor.header.height = CURSOR_HEIGHT;
436 cursor.cursor.header.hot_spot_x = 0;
437 cursor.cursor.header.hot_spot_y = 0;
438 cursor.cursor.data_size = CURSOR_WIDTH * CURSOR_HEIGHT * 4;
439
440 // X drivers addes it to the cursor size because it could be
441 // cursor data information or another cursor related stuffs.
442 // Otherwise, the code will break in client/cursor.cpp side,
443 // that expect the data_size plus cursor information.
444 // Blame cursor protocol for this. :-)
445 cursor.cursor.data_size += 128;
446 cursor.cursor.chunk.data_size = cursor.cursor.data_size;
447 cursor.cursor.chunk.prev_chunk = cursor.cursor.chunk.next_chunk = 0;
448}
449
450static int get_cursor_command(QXLInstance *qin, struct QXLCommandExt *ext)
451{
452 Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
453 static int color = 0;
454 static int set = 1;
455 static int x = 0, y = 0;
456 QXLCursorCmd *cursor_cmd;
457 QXLCommandExt *cmd;
458
459 if (!test->cursor_notify) {
460 return FALSE;
461 }
462
463 test->cursor_notify--;
464 cmd = calloc(sizeof(QXLCommandExt), 1);
465 cursor_cmd = calloc(sizeof(QXLCursorCmd), 1);
466
467 cursor_cmd->release_info.id = (unsigned long)cmd;
468
469 if (set) {
470 cursor_cmd->type = QXL_CURSOR_SET;
471 cursor_cmd->u.set.position.x = 0;
472 cursor_cmd->u.set.position.y = 0;
473 cursor_cmd->u.set.visible = TRUE;
474 cursor_cmd->u.set.shape = (unsigned long)&cursor;
475 // Only a white rect (32x32) as cursor
476 memset(cursor.data, 255, sizeof(cursor.data));
477 set = 0;
478 } else {
479 cursor_cmd->type = QXL_CURSOR_MOVE;
480 cursor_cmd->u.position.x = x++ % test->primary_width;
481 cursor_cmd->u.position.y = y++ % test->primary_height;
482 }
483
484 cmd->cmd.data = (unsigned long)cursor_cmd;
485 cmd->cmd.type = QXL_CMD_CURSOR;
486 cmd->group_id = MEM_SLOT_GROUP_ID;
487 cmd->flags = 0;
488 *ext = *cmd;
489 //printf("%s\n", __func__);
490 return TRUE;
491}
492
493static int req_cursor_notification(QXLInstance *qin)
494{
495 printf("%s\n", __func__);
496 return TRUE;
497}
498
499static void notify_update(QXLInstance *qin, uint32_t update_id)
500{
501 printf("%s\n", __func__);
502}
503
504static int flush_resources(QXLInstance *qin)
505{
506 printf("%s\n", __func__);
507 return TRUE;
508}
509
510static int client_monitors_config(QXLInstance *qin,
511 VDAgentMonitorsConfig *monitors_config)
512{
513 if (!monitors_config) {
514 printf("%s: NULL monitors_config\n", __func__);
515 } else {
516 printf("%s: %d\n", __func__, monitors_config->num_of_monitors);
517 }
518 return 0;
519}
520
521static void set_client_capabilities(QXLInstance *qin,
522 uint8_t client_present,
523 uint8_t caps[58])
524{
525 Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
526
527 printf("%s: present %d caps %d\n", __func__, client_present, caps[0]);
528 if (test->on_client_connected && client_present) {
529 test->on_client_connected(test);
530 }
531 if (test->on_client_disconnected && !client_present) {
532 test->on_client_disconnected(test);
533 }
534}
535
6faab5d5
DM
536static int client_count = 0;
537
538static void client_connected(Test *test)
539{
540 printf("Client connected\n");
541 client_count++;
542}
543
544static void client_disconnected(Test *test)
545{
546
547 if (client_count > 0) {
548 client_count--;
549 printf("Client disconnected\n");
550 exit(0); // fixme: cleanup?
551 }
552}
553
f6cb554c
DM
554static void do_conn_timeout(void *opaque)
555{
556 Test *test = opaque;
557
558 if (client_count <= 0) {
559 printf("do_conn_timeout\n");
560 exit (0); // fixme: cleanup?
561 }
562}
563
564
cc04455b
DM
565QXLInterface display_sif = {
566 .base = {
567 .type = SPICE_INTERFACE_QXL,
568 .description = "test",
569 .major_version = SPICE_INTERFACE_QXL_MAJOR,
570 .minor_version = SPICE_INTERFACE_QXL_MINOR
571 },
572 .attache_worker = attache_worker,
573 .set_compression_level = set_compression_level,
574 .set_mm_time = set_mm_time,
575 .get_init_info = get_init_info,
576
577 /* the callbacks below are called from spice server thread context */
578 .get_command = get_command,
579 .req_cmd_notification = req_cmd_notification,
580 .release_resource = release_resource,
581 .get_cursor_command = get_cursor_command,
582 .req_cursor_notification = req_cursor_notification,
583 .notify_update = notify_update,
584 .flush_resources = flush_resources,
585 .client_monitors_config = client_monitors_config,
586 .set_client_capabilities = set_client_capabilities,
587};
588
589/* interface for tests */
590void test_add_display_interface(Test* test)
591{
592 spice_server_add_interface(test->server, &test->qxl_instance.base);
593}
594
595static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
596{
6faab5d5 597// printf("%s: %d\n", __func__, len);
cc04455b
DM
598 return len;
599}
600
601static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
602{
6faab5d5 603// printf("%s: %d\n", __func__, len);
cc04455b
DM
604 return 0;
605}
606
607static void vmc_state(SpiceCharDeviceInstance *sin, int connected)
608{
6faab5d5 609// printf("%s: %d\n", __func__, connected);
cc04455b
DM
610}
611
612static SpiceCharDeviceInterface vdagent_sif = {
613 .base.type = SPICE_INTERFACE_CHAR_DEVICE,
614 .base.description = "test spice virtual channel char device",
615 .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
616 .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
617 .state = vmc_state,
618 .write = vmc_write,
619 .read = vmc_read,
620};
621
622SpiceCharDeviceInstance vdagent_sin = {
623 .base = {
624 .sif = &vdagent_sif.base,
625 },
626 .subtype = "vdagent",
627};
628
629void test_add_agent_interface(SpiceServer *server)
630{
631 spice_server_add_interface(server, &vdagent_sin.base);
632}
633
8a22eb4f
DM
634static int my_charcode = 65;
635static int my_posx = 0;
474762d8
DM
636static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag)
637{
8a22eb4f
DM
638 Test *test = SPICE_CONTAINEROF(sin, Test, keyboard_sin);
639
640 printf("KEYCODE %u %p\n", frag, test);
641
474762d8
DM
642}
643
22e5ba02
DM
644void test_draw_update_char(Test *test, int x, int y, int c, TextAttributes attrib)
645{
646 int fg, bg;
647
648 if (attrib.invers) {
649 bg = attrib.fgcol;
650 fg = attrib.bgcol;
651 } else {
652 bg = attrib.bgcol;
653 fg = attrib.fgcol;
654 }
655
656 if (attrib.bold) {
657 fg += 8;
658 }
659
660 // unsuported attributes = (attrib.blink || attrib.unvisible)
661
662 //if (attrib.uline) {
663 //rfbDrawLine (vt->screen, rx, ry + 14, rxe, ry + 14, fg);
664 //}
665
666 SimpleSpiceUpdate *update;
65007123 667 update = test_draw_char(test, x, y, c, fg, bg);
63a34f43 668 push_command(test, &update->ext);
22e5ba02
DM
669}
670
474762d8
DM
671static uint8_t kbd_get_leds(SpiceKbdInstance *sin)
672{
673 return 0;
674}
675
676static SpiceKbdInterface keyboard_sif = {
677 .base.type = SPICE_INTERFACE_KEYBOARD ,
678 .base.description = "spiceterm keyboard device",
679 .base.major_version = SPICE_INTERFACE_KEYBOARD_MAJOR,
680 .base.minor_version = SPICE_INTERFACE_KEYBOARD_MINOR,
681 .push_scan_freg = kbd_push_key,
682 .get_leds = kbd_get_leds,
683};
684
8a22eb4f 685void test_add_keyboard_interface(Test* test)
474762d8 686{
8a22eb4f 687 spice_server_add_interface(test->server, &test->keyboard_sin.base);
474762d8
DM
688}
689
cc04455b
DM
690Test *test_new(SpiceCoreInterface *core)
691{
692 int port = 5912;
693 Test *test = g_new0(Test, 1);
694 SpiceServer* server = spice_server_new();
695
63a34f43
DM
696 test->command_cond = g_cond_new();
697 test->command_mutex = g_mutex_new();
698
6faab5d5
DM
699 test->on_client_connected = client_connected,
700 test->on_client_disconnected = client_disconnected,
701
cc04455b
DM
702 test->qxl_instance.base.sif = &display_sif.base;
703 test->qxl_instance.id = 0;
704
8a22eb4f
DM
705 test->keyboard_sin.base.sif = &keyboard_sif.base;
706
cc04455b
DM
707 test->core = core;
708 test->server = server;
8a22eb4f 709
cc04455b
DM
710 test->cursor_notify = NOTIFY_CURSOR_BATCH;
711 // some common initialization for all display tests
712 printf("TESTER: listening on port %d (unsecure)\n", port);
713 spice_server_set_port(server, port);
714 spice_server_set_noauth(server);
1d7f2da4
DM
715 int res = spice_server_init(server, core);
716 if (res != 0) {
717 g_error("spice_server_init failed, res = %d\n", res);
718 }
cc04455b
DM
719
720 cursor_init();
cc04455b 721 test->has_secondary = 0;
f6cb554c
DM
722
723 int timeout = 10; // max time to wait for client connection
724 test->conn_timeout_timer = core->timer_add(do_conn_timeout, test);
725 test->core->timer_start(test->conn_timeout_timer, timeout*1000);
726
cc04455b
DM
727 return test;
728}
729
cc04455b
DM
730
731__attribute__((noreturn))
732void usage(const char *argv0, const int exitcode)
733{
cc04455b 734
7f30e760 735 printf("usage: %s\n", argv0);
cc04455b
DM
736 exit(exitcode);
737}
738
739void spice_test_config_parse_args(int argc, char **argv)
740{
741 struct option options[] = {
7f30e760 742// {"automated-tests", no_argument, &has_automated_tests, 1},
cc04455b
DM
743 {NULL, 0, NULL, 0},
744 };
745 int option_index;
746 int val;
747
748 while ((val = getopt_long(argc, argv, "", options, &option_index)) != -1) {
749 switch (val) {
750 case '?':
751 printf("unrecognized option '%s'\n", argv[optind - 1]);
752 usage(argv[0], EXIT_FAILURE);
753 case 0:
754 break;
755 }
756 }
757
758 if (argc > optind) {
759 printf("unknown argument '%s'\n", argv[optind]);
760 usage(argv[0], EXIT_FAILURE);
761 }
cc04455b
DM
762 return;
763}