Skip to content

Commit 9deda30

Browse files
jerome-jutteauoutscale-mgo
authored andcommitted
vhost: add ping, tcp and udp tests between two vm
ref #334 Signed-off-by: Jerome Jutteau <[email protected]>
1 parent ae54e2c commit 9deda30

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

tests/vhost/test-vhost.c

+113
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,121 @@ static void test_vhost_destroy(void)
655655
pg_vhost_stop();
656656
}
657657

658+
/* qemu_duo_* create a graph to test ping/iperf/tcp/udp:
659+
* <qemu>--[vhost]--[vhost]--<qemu>
660+
*
661+
* 1. init graph with qemu_duo_new()
662+
* 2. ssh some commands using pg_util_ssh()
663+
* 3. clean graph with qemu_duo_destroy()
664+
*/
665+
666+
struct qemu_duo_test_params {
667+
pthread_t graph_thread;
668+
int stop;
669+
struct pg_brick *vhost[2];
670+
uint16_t port[2];
671+
int qemu_pid[2];
672+
char *ip[2];
673+
};
674+
675+
static void *qemu_duo_internal_thread(void *arg) {
676+
struct qemu_duo_test_params *p = (struct qemu_duo_test_params *)arg;
677+
struct pg_error *error = NULL;
678+
uint16_t count;
679+
680+
p->stop = 0;
681+
while (!p->stop) {
682+
pg_brick_poll(p->vhost[0], &count, &error);
683+
pg_brick_poll(p->vhost[1], &count, &error);
684+
}
685+
return NULL;
686+
}
687+
688+
static void qemu_duo_new(struct qemu_duo_test_params *p)
689+
{
690+
struct pg_error *error = NULL;
691+
char *tmp;
692+
char *mac;
693+
const char *socket_path;
694+
695+
g_assert(!pg_vhost_start("/tmp", &error));
696+
g_assert(!error);
697+
for (int i = 0; i < 2; i++) {
698+
tmp = g_strdup_printf("vhost-%i", i);
699+
p->vhost[i] = pg_vhost_new(tmp, 0, &error);
700+
g_free(tmp);
701+
g_assert(!error);
702+
g_assert(p->vhost[i]);
703+
socket_path = pg_vhost_socket_path(p->vhost[i], &error);
704+
g_assert(socket_path);
705+
g_assert(!error);
706+
707+
mac = g_strdup_printf("52:54:00:12:34:%02i", i);
708+
p->qemu_pid[i] = pg_util_spawn_qemu(socket_path, NULL,
709+
mac, NULL,
710+
glob_vm_path,
711+
glob_vm_key_path,
712+
glob_hugepages_path,
713+
&error);
714+
g_free(mac);
715+
g_assert(!error);
716+
g_assert(p->qemu_pid[i]);
717+
p->port[i] = ssh_port_id;
718+
ssh_port_id++;
719+
720+
p->ip[i] = g_strdup_printf("42.0.0.%i", i + 1);
721+
g_assert(!pg_util_ssh("localhost", p->port[i], glob_vm_key_path,
722+
"ifconfig ens4 up"));
723+
g_assert(!pg_util_ssh("localhost", p->port[i], glob_vm_key_path,
724+
"ip addr add %s/24 dev ens4", p->ip[i]));
725+
}
726+
727+
g_assert(!pg_brick_link(p->vhost[0], p->vhost[1], &error));
728+
g_assert(!error);
729+
g_assert(!pthread_create(&p->graph_thread, NULL,
730+
&qemu_duo_internal_thread, p));
731+
}
732+
733+
static void qemu_duo_destroy(struct qemu_duo_test_params *p)
734+
{
735+
int exit_status;
736+
void *ret;
737+
p->stop = 1;
738+
pthread_join(p->graph_thread, &ret);
739+
for (int i = 0; i < 2; i++) {
740+
kill(p->qemu_pid[i], SIGKILL);
741+
waitpid(p->qemu_pid[i], &exit_status, 0);
742+
g_spawn_close_pid(p->qemu_pid[i]);
743+
g_free(p->ip[i]);
744+
pg_brick_destroy(p->vhost[i]);
745+
}
746+
pg_vhost_stop();
747+
}
748+
749+
static void test_vhost_net_classics(void)
750+
{
751+
struct qemu_duo_test_params p;
752+
753+
qemu_duo_new(&p);
754+
for (int i = 0; i < 2; i++) {
755+
g_assert(!pg_util_ssh("localhost", p.port[i], glob_vm_key_path,
756+
"ping -c 1 -W 3 %s", p.ip[(i + 1) % 2]));
757+
g_assert(!pg_util_ssh("localhost", p.port[(i + 1) % 2],
758+
glob_vm_key_path, "iperf3 -s -D"));
759+
usleep(100000);
760+
g_assert(!pg_util_ssh("localhost", p.port[i], glob_vm_key_path,
761+
"iperf3 -t 1 -c %s", p.ip[(i + 1) % 2]));
762+
usleep(100000);
763+
g_assert(!pg_util_ssh("localhost", p.port[i], glob_vm_key_path,
764+
"iperf3 -t 1 -u -c %s",
765+
p.ip[(i + 1) % 2]));
766+
}
767+
qemu_duo_destroy(&p);
768+
}
769+
658770
void test_vhost(void)
659771
{
772+
pg_test_add_func("/vhost/net_classics", test_vhost_net_classics);
660773
pg_test_add_func("/vhost/flow", test_vhost_flow);
661774
pg_test_add_func("/vhost/multivm", test_vhost_multivm);
662775
pg_test_add_func("/vhost/fd", test_vhost_fd_loop);

0 commit comments

Comments
 (0)