s390x: fix size + content of STSI blocks
[qemu/ar7.git] / tests / test-char.c
blob911e3f6e8df3f78d173c707604f6a39162d652c7
1 #include "qemu/osdep.h"
2 #include <glib/gstdio.h>
4 #include "qemu-common.h"
5 #include "qemu/config-file.h"
6 #include "qemu/sockets.h"
7 #include "chardev/char-fe.h"
8 #include "chardev/char-mux.h"
9 #include "sysemu/sysemu.h"
10 #include "qapi/error.h"
11 #include "qom/qom-qobject.h"
12 #include "qmp-commands.h"
14 static bool quit;
16 typedef struct FeHandler {
17 int read_count;
18 int last_event;
19 char read_buf[128];
20 } FeHandler;
22 static void main_loop(void)
24 quit = false;
25 do {
26 main_loop_wait(false);
27 } while (!quit);
30 static int fe_can_read(void *opaque)
32 FeHandler *h = opaque;
34 return sizeof(h->read_buf) - h->read_count;
37 static void fe_read(void *opaque, const uint8_t *buf, int size)
39 FeHandler *h = opaque;
41 g_assert_cmpint(size, <=, fe_can_read(opaque));
43 memcpy(h->read_buf + h->read_count, buf, size);
44 h->read_count += size;
45 quit = true;
48 static void fe_event(void *opaque, int event)
50 FeHandler *h = opaque;
52 h->last_event = event;
53 if (event != CHR_EVENT_BREAK) {
54 quit = true;
58 #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
59 #ifdef _WIN32
60 static void char_console_test_subprocess(void)
62 QemuOpts *opts;
63 Chardev *chr;
65 opts = qemu_opts_create(qemu_find_opts("chardev"), "console-label",
66 1, &error_abort);
67 qemu_opt_set(opts, "backend", "console", &error_abort);
69 chr = qemu_chr_new_from_opts(opts, NULL);
70 g_assert_nonnull(chr);
72 qemu_chr_write_all(chr, (const uint8_t *)"CONSOLE", 7);
74 qemu_opts_del(opts);
75 object_unparent(OBJECT(chr));
78 static void char_console_test(void)
80 g_test_trap_subprocess("/char/console/subprocess", 0, 0);
81 g_test_trap_assert_passed();
82 g_test_trap_assert_stdout("CONSOLE");
84 #endif
85 static void char_stdio_test_subprocess(void)
87 Chardev *chr;
88 CharBackend be;
89 int ret;
91 chr = qemu_chr_new("label", "stdio");
92 g_assert_nonnull(chr);
94 qemu_chr_fe_init(&be, chr, &error_abort);
95 qemu_chr_fe_set_open(&be, true);
96 ret = qemu_chr_fe_write(&be, (void *)"buf", 4);
97 g_assert_cmpint(ret, ==, 4);
99 qemu_chr_fe_deinit(&be, true);
102 static void char_stdio_test(void)
104 g_test_trap_subprocess("/char/stdio/subprocess", 0, 0);
105 g_test_trap_assert_passed();
106 g_test_trap_assert_stdout("buf");
108 #endif
110 static void char_ringbuf_test(void)
112 QemuOpts *opts;
113 Chardev *chr;
114 CharBackend be;
115 char *data;
116 int ret;
118 opts = qemu_opts_create(qemu_find_opts("chardev"), "ringbuf-label",
119 1, &error_abort);
120 qemu_opt_set(opts, "backend", "ringbuf", &error_abort);
122 qemu_opt_set(opts, "size", "5", &error_abort);
123 chr = qemu_chr_new_from_opts(opts, NULL);
124 g_assert_null(chr);
125 qemu_opts_del(opts);
127 opts = qemu_opts_create(qemu_find_opts("chardev"), "ringbuf-label",
128 1, &error_abort);
129 qemu_opt_set(opts, "backend", "ringbuf", &error_abort);
130 qemu_opt_set(opts, "size", "2", &error_abort);
131 chr = qemu_chr_new_from_opts(opts, &error_abort);
132 g_assert_nonnull(chr);
133 qemu_opts_del(opts);
135 qemu_chr_fe_init(&be, chr, &error_abort);
136 ret = qemu_chr_fe_write(&be, (void *)"buff", 4);
137 g_assert_cmpint(ret, ==, 4);
139 data = qmp_ringbuf_read("ringbuf-label", 4, false, 0, &error_abort);
140 g_assert_cmpstr(data, ==, "ff");
141 g_free(data);
143 data = qmp_ringbuf_read("ringbuf-label", 4, false, 0, &error_abort);
144 g_assert_cmpstr(data, ==, "");
145 g_free(data);
147 qemu_chr_fe_deinit(&be, true);
149 /* check alias */
150 opts = qemu_opts_create(qemu_find_opts("chardev"), "memory-label",
151 1, &error_abort);
152 qemu_opt_set(opts, "backend", "memory", &error_abort);
153 qemu_opt_set(opts, "size", "2", &error_abort);
154 chr = qemu_chr_new_from_opts(opts, NULL);
155 g_assert_nonnull(chr);
156 object_unparent(OBJECT(chr));
157 qemu_opts_del(opts);
160 static void char_mux_test(void)
162 QemuOpts *opts;
163 Chardev *chr, *base;
164 char *data;
165 FeHandler h1 = { 0, }, h2 = { 0, };
166 CharBackend chr_be1, chr_be2;
168 muxes_realized = true; /* done after machine init */
169 opts = qemu_opts_create(qemu_find_opts("chardev"), "mux-label",
170 1, &error_abort);
171 qemu_opt_set(opts, "backend", "ringbuf", &error_abort);
172 qemu_opt_set(opts, "size", "128", &error_abort);
173 qemu_opt_set(opts, "mux", "on", &error_abort);
174 chr = qemu_chr_new_from_opts(opts, &error_abort);
175 g_assert_nonnull(chr);
176 qemu_opts_del(opts);
178 qemu_chr_fe_init(&chr_be1, chr, &error_abort);
179 qemu_chr_fe_set_handlers(&chr_be1,
180 fe_can_read,
181 fe_read,
182 fe_event,
183 NULL,
184 &h1,
185 NULL, true);
187 qemu_chr_fe_init(&chr_be2, chr, &error_abort);
188 qemu_chr_fe_set_handlers(&chr_be2,
189 fe_can_read,
190 fe_read,
191 fe_event,
192 NULL,
193 &h2,
194 NULL, true);
195 qemu_chr_fe_take_focus(&chr_be2);
197 base = qemu_chr_find("mux-label-base");
198 g_assert_cmpint(qemu_chr_be_can_write(base), !=, 0);
200 qemu_chr_be_write(base, (void *)"hello", 6);
201 g_assert_cmpint(h1.read_count, ==, 0);
202 g_assert_cmpint(h2.read_count, ==, 6);
203 g_assert_cmpstr(h2.read_buf, ==, "hello");
204 h2.read_count = 0;
206 g_assert_cmpint(h1.last_event, !=, 42); /* should be MUX_OUT or OPENED */
207 g_assert_cmpint(h2.last_event, !=, 42); /* should be MUX_IN or OPENED */
208 /* sending event on the base broadcast to all fe, historical reasons? */
209 qemu_chr_be_event(base, 42);
210 g_assert_cmpint(h1.last_event, ==, 42);
211 g_assert_cmpint(h2.last_event, ==, 42);
212 qemu_chr_be_event(chr, -1);
213 g_assert_cmpint(h1.last_event, ==, 42);
214 g_assert_cmpint(h2.last_event, ==, -1);
216 /* switch focus */
217 qemu_chr_be_write(base, (void *)"\1c", 2);
218 g_assert_cmpint(h1.last_event, ==, CHR_EVENT_MUX_IN);
219 g_assert_cmpint(h2.last_event, ==, CHR_EVENT_MUX_OUT);
220 qemu_chr_be_event(chr, -1);
221 g_assert_cmpint(h1.last_event, ==, -1);
222 g_assert_cmpint(h2.last_event, ==, CHR_EVENT_MUX_OUT);
224 qemu_chr_be_write(base, (void *)"hello", 6);
225 g_assert_cmpint(h2.read_count, ==, 0);
226 g_assert_cmpint(h1.read_count, ==, 6);
227 g_assert_cmpstr(h1.read_buf, ==, "hello");
228 h1.read_count = 0;
230 /* remove first handler */
231 qemu_chr_fe_set_handlers(&chr_be1, NULL, NULL, NULL, NULL,
232 NULL, NULL, true);
233 qemu_chr_be_write(base, (void *)"hello", 6);
234 g_assert_cmpint(h1.read_count, ==, 0);
235 g_assert_cmpint(h2.read_count, ==, 0);
237 qemu_chr_be_write(base, (void *)"\1c", 2);
238 qemu_chr_be_write(base, (void *)"hello", 6);
239 g_assert_cmpint(h1.read_count, ==, 0);
240 g_assert_cmpint(h2.read_count, ==, 6);
241 g_assert_cmpstr(h2.read_buf, ==, "hello");
242 h2.read_count = 0;
244 /* print help */
245 qemu_chr_be_write(base, (void *)"\1?", 2);
246 data = qmp_ringbuf_read("mux-label-base", 128, false, 0, &error_abort);
247 g_assert_cmpint(strlen(data), !=, 0);
248 g_free(data);
250 qemu_chr_fe_deinit(&chr_be1, false);
251 qemu_chr_fe_deinit(&chr_be2, true);
254 typedef struct SocketIdleData {
255 GMainLoop *loop;
256 Chardev *chr;
257 bool conn_expected;
258 CharBackend *be;
259 CharBackend *client_be;
260 } SocketIdleData;
262 static gboolean char_socket_test_idle(gpointer user_data)
264 SocketIdleData *data = user_data;
266 if (object_property_get_bool(OBJECT(data->chr), "connected", NULL)
267 == data->conn_expected) {
268 quit = true;
269 return FALSE;
272 return TRUE;
275 static void socket_read(void *opaque, const uint8_t *buf, int size)
277 SocketIdleData *data = opaque;
279 g_assert_cmpint(size, ==, 1);
280 g_assert_cmpint(*buf, ==, 'Z');
282 size = qemu_chr_fe_write(data->be, (const uint8_t *)"hello", 5);
283 g_assert_cmpint(size, ==, 5);
286 static int socket_can_read(void *opaque)
288 return 10;
291 static void socket_read_hello(void *opaque, const uint8_t *buf, int size)
293 g_assert_cmpint(size, ==, 5);
294 g_assert(strncmp((char *)buf, "hello", 5) == 0);
296 quit = true;
299 static int socket_can_read_hello(void *opaque)
301 return 10;
304 static void char_socket_test(void)
306 Chardev *chr = qemu_chr_new("server", "tcp:127.0.0.1:0,server,nowait");
307 Chardev *chr_client;
308 QObject *addr;
309 QDict *qdict;
310 const char *port;
311 SocketIdleData d = { .chr = chr };
312 CharBackend be;
313 CharBackend client_be;
314 char *tmp;
316 d.be = &be;
317 d.client_be = &be;
319 g_assert_nonnull(chr);
320 g_assert(!object_property_get_bool(OBJECT(chr), "connected", &error_abort));
322 addr = object_property_get_qobject(OBJECT(chr), "addr", &error_abort);
323 qdict = qobject_to_qdict(addr);
324 port = qdict_get_str(qdict, "port");
325 tmp = g_strdup_printf("tcp:127.0.0.1:%s", port);
326 QDECREF(qdict);
328 qemu_chr_fe_init(&be, chr, &error_abort);
329 qemu_chr_fe_set_handlers(&be, socket_can_read, socket_read,
330 NULL, NULL, &d, NULL, true);
332 chr_client = qemu_chr_new("client", tmp);
333 qemu_chr_fe_init(&client_be, chr_client, &error_abort);
334 qemu_chr_fe_set_handlers(&client_be, socket_can_read_hello,
335 socket_read_hello,
336 NULL, NULL, &d, NULL, true);
337 g_free(tmp);
339 d.conn_expected = true;
340 guint id = g_idle_add(char_socket_test_idle, &d);
341 g_source_set_name_by_id(id, "test-idle");
342 g_assert_cmpint(id, >, 0);
343 main_loop();
345 g_assert(object_property_get_bool(OBJECT(chr), "connected", &error_abort));
346 g_assert(object_property_get_bool(OBJECT(chr_client),
347 "connected", &error_abort));
349 qemu_chr_write_all(chr_client, (const uint8_t *)"Z", 1);
350 main_loop();
352 object_unparent(OBJECT(chr_client));
354 d.conn_expected = false;
355 g_idle_add(char_socket_test_idle, &d);
356 main_loop();
358 object_unparent(OBJECT(chr));
361 #ifndef _WIN32
362 static void char_pipe_test(void)
364 gchar *tmp_path = g_dir_make_tmp("qemu-test-char.XXXXXX", NULL);
365 gchar *tmp, *in, *out, *pipe = g_build_filename(tmp_path, "pipe", NULL);
366 Chardev *chr;
367 CharBackend be;
368 int ret, fd;
369 char buf[10];
370 FeHandler fe = { 0, };
372 in = g_strdup_printf("%s.in", pipe);
373 if (mkfifo(in, 0600) < 0) {
374 abort();
376 out = g_strdup_printf("%s.out", pipe);
377 if (mkfifo(out, 0600) < 0) {
378 abort();
381 tmp = g_strdup_printf("pipe:%s", pipe);
382 chr = qemu_chr_new("pipe", tmp);
383 g_assert_nonnull(chr);
384 g_free(tmp);
386 qemu_chr_fe_init(&be, chr, &error_abort);
388 ret = qemu_chr_fe_write(&be, (void *)"pipe-out", 9);
389 g_assert_cmpint(ret, ==, 9);
391 fd = open(out, O_RDWR);
392 ret = read(fd, buf, sizeof(buf));
393 g_assert_cmpint(ret, ==, 9);
394 g_assert_cmpstr(buf, ==, "pipe-out");
395 close(fd);
397 fd = open(in, O_WRONLY);
398 ret = write(fd, "pipe-in", 8);
399 g_assert_cmpint(ret, ==, 8);
400 close(fd);
402 qemu_chr_fe_set_handlers(&be,
403 fe_can_read,
404 fe_read,
405 fe_event,
406 NULL,
407 &fe,
408 NULL, true);
410 main_loop();
412 g_assert_cmpint(fe.read_count, ==, 8);
413 g_assert_cmpstr(fe.read_buf, ==, "pipe-in");
415 qemu_chr_fe_deinit(&be, true);
417 g_assert(g_unlink(in) == 0);
418 g_assert(g_unlink(out) == 0);
419 g_assert(g_rmdir(tmp_path) == 0);
420 g_free(in);
421 g_free(out);
422 g_free(tmp_path);
423 g_free(pipe);
425 #endif
427 static int make_udp_socket(int *port)
429 struct sockaddr_in addr = { 0, };
430 socklen_t alen = sizeof(addr);
431 int ret, sock = qemu_socket(PF_INET, SOCK_DGRAM, 0);
433 g_assert_cmpint(sock, >, 0);
434 addr.sin_family = AF_INET ;
435 addr.sin_addr.s_addr = htonl(INADDR_ANY);
436 addr.sin_port = 0;
437 ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
438 g_assert_cmpint(ret, ==, 0);
439 ret = getsockname(sock, (struct sockaddr *)&addr, &alen);
440 g_assert_cmpint(ret, ==, 0);
442 *port = ntohs(addr.sin_port);
443 return sock;
446 static void char_udp_test_internal(Chardev *reuse_chr, int sock)
448 struct sockaddr_in other;
449 SocketIdleData d = { 0, };
450 Chardev *chr;
451 CharBackend *be;
452 socklen_t alen = sizeof(other);
453 int ret;
454 char buf[10];
455 char *tmp = NULL;
457 if (reuse_chr) {
458 chr = reuse_chr;
459 be = chr->be;
460 } else {
461 int port;
462 sock = make_udp_socket(&port);
463 tmp = g_strdup_printf("udp:127.0.0.1:%d", port);
464 chr = qemu_chr_new("client", tmp);
465 g_assert_nonnull(chr);
467 be = g_alloca(sizeof(CharBackend));
468 qemu_chr_fe_init(be, chr, &error_abort);
471 d.chr = chr;
472 qemu_chr_fe_set_handlers(be, socket_can_read_hello, socket_read_hello,
473 NULL, NULL, &d, NULL, true);
474 ret = qemu_chr_write_all(chr, (uint8_t *)"hello", 5);
475 g_assert_cmpint(ret, ==, 5);
477 ret = recvfrom(sock, buf, sizeof(buf), 0,
478 (struct sockaddr *)&other, &alen);
479 g_assert_cmpint(ret, ==, 5);
480 ret = sendto(sock, buf, 5, 0, (struct sockaddr *)&other, alen);
481 g_assert_cmpint(ret, ==, 5);
483 main_loop();
485 if (!reuse_chr) {
486 close(sock);
487 qemu_chr_fe_deinit(be, true);
489 g_free(tmp);
492 static void char_udp_test(void)
494 char_udp_test_internal(NULL, 0);
497 #ifdef HAVE_CHARDEV_SERIAL
498 static void char_serial_test(void)
500 QemuOpts *opts;
501 Chardev *chr;
503 opts = qemu_opts_create(qemu_find_opts("chardev"), "serial-id",
504 1, &error_abort);
505 qemu_opt_set(opts, "backend", "serial", &error_abort);
506 qemu_opt_set(opts, "path", "/dev/null", &error_abort);
508 chr = qemu_chr_new_from_opts(opts, NULL);
509 g_assert_nonnull(chr);
510 /* TODO: add more tests with a pty */
511 object_unparent(OBJECT(chr));
513 /* test tty alias */
514 qemu_opt_set(opts, "backend", "tty", &error_abort);
515 chr = qemu_chr_new_from_opts(opts, NULL);
516 g_assert_nonnull(chr);
517 object_unparent(OBJECT(chr));
519 qemu_opts_del(opts);
521 #endif
523 #ifndef _WIN32
524 static void char_file_fifo_test(void)
526 Chardev *chr;
527 CharBackend be;
528 char *tmp_path = g_dir_make_tmp("qemu-test-char.XXXXXX", NULL);
529 char *fifo = g_build_filename(tmp_path, "fifo", NULL);
530 char *out = g_build_filename(tmp_path, "out", NULL);
531 ChardevFile file = { .in = fifo,
532 .has_in = true,
533 .out = out };
534 ChardevBackend backend = { .type = CHARDEV_BACKEND_KIND_FILE,
535 .u.file.data = &file };
536 FeHandler fe = { 0, };
537 int fd, ret;
539 if (mkfifo(fifo, 0600) < 0) {
540 abort();
543 fd = open(fifo, O_RDWR);
544 ret = write(fd, "fifo-in", 8);
545 g_assert_cmpint(ret, ==, 8);
547 chr = qemu_chardev_new("label-file", TYPE_CHARDEV_FILE, &backend,
548 &error_abort);
550 qemu_chr_fe_init(&be, chr, &error_abort);
551 qemu_chr_fe_set_handlers(&be,
552 fe_can_read,
553 fe_read,
554 fe_event,
555 NULL,
556 &fe, NULL, true);
558 g_assert_cmpint(fe.last_event, !=, CHR_EVENT_BREAK);
559 qmp_chardev_send_break("label-foo", NULL);
560 g_assert_cmpint(fe.last_event, !=, CHR_EVENT_BREAK);
561 qmp_chardev_send_break("label-file", NULL);
562 g_assert_cmpint(fe.last_event, ==, CHR_EVENT_BREAK);
564 main_loop();
566 close(fd);
568 g_assert_cmpint(fe.read_count, ==, 8);
569 g_assert_cmpstr(fe.read_buf, ==, "fifo-in");
571 qemu_chr_fe_deinit(&be, true);
573 g_unlink(fifo);
574 g_free(fifo);
575 g_unlink(out);
576 g_free(out);
577 g_rmdir(tmp_path);
578 g_free(tmp_path);
580 #endif
582 static void char_file_test_internal(Chardev *ext_chr, const char *filepath)
584 char *tmp_path = g_dir_make_tmp("qemu-test-char.XXXXXX", NULL);
585 char *out;
586 Chardev *chr;
587 char *contents = NULL;
588 ChardevFile file = {};
589 ChardevBackend backend = { .type = CHARDEV_BACKEND_KIND_FILE,
590 .u.file.data = &file };
591 gsize length;
592 int ret;
594 if (ext_chr) {
595 chr = ext_chr;
596 out = g_strdup(filepath);
597 file.out = out;
598 } else {
599 out = g_build_filename(tmp_path, "out", NULL);
600 file.out = out;
601 chr = qemu_chardev_new(NULL, TYPE_CHARDEV_FILE, &backend,
602 &error_abort);
604 ret = qemu_chr_write_all(chr, (uint8_t *)"hello!", 6);
605 g_assert_cmpint(ret, ==, 6);
607 ret = g_file_get_contents(out, &contents, &length, NULL);
608 g_assert(ret == TRUE);
609 g_assert_cmpint(length, ==, 6);
610 g_assert(strncmp(contents, "hello!", 6) == 0);
612 if (!ext_chr) {
613 object_unref(OBJECT(chr));
614 g_unlink(out);
616 g_free(contents);
617 g_rmdir(tmp_path);
618 g_free(tmp_path);
619 g_free(out);
622 static void char_file_test(void)
624 char_file_test_internal(NULL, NULL);
627 static void char_null_test(void)
629 Error *err = NULL;
630 Chardev *chr;
631 CharBackend be;
632 int ret;
634 chr = qemu_chr_find("label-null");
635 g_assert_null(chr);
637 chr = qemu_chr_new("label-null", "null");
638 chr = qemu_chr_find("label-null");
639 g_assert_nonnull(chr);
641 g_assert(qemu_chr_has_feature(chr,
642 QEMU_CHAR_FEATURE_FD_PASS) == false);
643 g_assert(qemu_chr_has_feature(chr,
644 QEMU_CHAR_FEATURE_RECONNECTABLE) == false);
646 /* check max avail */
647 qemu_chr_fe_init(&be, chr, &error_abort);
648 qemu_chr_fe_init(&be, chr, &err);
649 error_free_or_abort(&err);
651 /* deinit & reinit */
652 qemu_chr_fe_deinit(&be, false);
653 qemu_chr_fe_init(&be, chr, &error_abort);
655 qemu_chr_fe_set_open(&be, true);
657 qemu_chr_fe_set_handlers(&be,
658 fe_can_read,
659 fe_read,
660 fe_event,
661 NULL,
662 NULL, NULL, true);
664 ret = qemu_chr_fe_write(&be, (void *)"buf", 4);
665 g_assert_cmpint(ret, ==, 4);
667 qemu_chr_fe_deinit(&be, true);
670 static void char_invalid_test(void)
672 Chardev *chr;
674 chr = qemu_chr_new("label-invalid", "invalid");
675 g_assert_null(chr);
678 static int chardev_change(void *opaque)
680 return 0;
683 static int chardev_change_denied(void *opaque)
685 return -1;
688 static void char_hotswap_test(void)
690 char *chr_args;
691 Chardev *chr;
692 CharBackend be;
694 gchar *tmp_path = g_dir_make_tmp("qemu-test-char.XXXXXX", NULL);
695 char *filename = g_build_filename(tmp_path, "file", NULL);
696 ChardevFile file = { .out = filename };
697 ChardevBackend backend = { .type = CHARDEV_BACKEND_KIND_FILE,
698 .u.file.data = &file };
699 ChardevReturn *ret;
701 int port;
702 int sock = make_udp_socket(&port);
703 g_assert_cmpint(sock, >, 0);
705 chr_args = g_strdup_printf("udp:127.0.0.1:%d", port);
707 chr = qemu_chr_new("chardev", chr_args);
708 qemu_chr_fe_init(&be, chr, &error_abort);
710 /* check that chardev operates correctly */
711 char_udp_test_internal(chr, sock);
713 /* set the handler that denies the hotswap */
714 qemu_chr_fe_set_handlers(&be, NULL, NULL,
715 NULL, chardev_change_denied, NULL, NULL, true);
717 /* now, change is denied and has to keep the old backend operating */
718 ret = qmp_chardev_change("chardev", &backend, NULL);
719 g_assert(!ret);
720 g_assert(be.chr == chr);
722 char_udp_test_internal(chr, sock);
724 /* now allow the change */
725 qemu_chr_fe_set_handlers(&be, NULL, NULL,
726 NULL, chardev_change, NULL, NULL, true);
728 /* has to succeed now */
729 ret = qmp_chardev_change("chardev", &backend, &error_abort);
730 g_assert(be.chr != chr);
732 close(sock);
733 chr = be.chr;
735 /* run the file chardev test */
736 char_file_test_internal(chr, filename);
738 object_unparent(OBJECT(chr));
740 qapi_free_ChardevReturn(ret);
741 g_unlink(filename);
742 g_free(filename);
743 g_rmdir(tmp_path);
744 g_free(tmp_path);
745 g_free(chr_args);
748 int main(int argc, char **argv)
750 qemu_init_main_loop(&error_abort);
751 socket_init();
753 g_test_init(&argc, &argv, NULL);
755 module_call_init(MODULE_INIT_QOM);
756 qemu_add_opts(&qemu_chardev_opts);
758 g_test_add_func("/char/null", char_null_test);
759 g_test_add_func("/char/invalid", char_invalid_test);
760 g_test_add_func("/char/ringbuf", char_ringbuf_test);
761 g_test_add_func("/char/mux", char_mux_test);
762 #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
763 #ifdef _WIN32
764 g_test_add_func("/char/console/subprocess", char_console_test_subprocess);
765 g_test_add_func("/char/console", char_console_test);
766 #endif
767 g_test_add_func("/char/stdio/subprocess", char_stdio_test_subprocess);
768 g_test_add_func("/char/stdio", char_stdio_test);
769 #endif
770 #ifndef _WIN32
771 g_test_add_func("/char/pipe", char_pipe_test);
772 #endif
773 g_test_add_func("/char/file", char_file_test);
774 #ifndef _WIN32
775 g_test_add_func("/char/file-fifo", char_file_fifo_test);
776 #endif
777 g_test_add_func("/char/socket", char_socket_test);
778 g_test_add_func("/char/udp", char_udp_test);
779 #ifdef HAVE_CHARDEV_SERIAL
780 g_test_add_func("/char/serial", char_serial_test);
781 #endif
782 g_test_add_func("/char/hotswap", char_hotswap_test);
784 return g_test_run();