xref: /openbmc/qemu/tests/test-qht-par.c (revision 8fdf0387)
1 /*
2  * Copyright (C) 2016, Emilio G. Cota <cota@braap.org>
3  *
4  * License: GNU GPL, version 2 or later.
5  *   See the COPYING file in the top-level directory.
6  */
7 #include "qemu/osdep.h"
8 #include <glib.h>
9 
10 #define TEST_QHT_STRING "tests/qht-bench 1>/dev/null 2>&1 -R -S0.1 -D10000 -N1 "
11 
12 static void test_qht(int n_threads, int update_rate, int duration)
13 {
14     char *str;
15     int rc;
16 
17     str = g_strdup_printf(TEST_QHT_STRING "-n %d -u %d -d %d",
18                           n_threads, update_rate, duration);
19     rc = system(str);
20     g_free(str);
21     g_assert_cmpint(rc, ==, 0);
22 }
23 
24 static void test_2th0u1s(void)
25 {
26     test_qht(2, 0, 1);
27 }
28 
29 static void test_2th20u1s(void)
30 {
31     test_qht(2, 20, 1);
32 }
33 
34 static void test_2th0u5s(void)
35 {
36     test_qht(2, 0, 5);
37 }
38 
39 static void test_2th20u5s(void)
40 {
41     test_qht(2, 20, 5);
42 }
43 
44 int main(int argc, char *argv[])
45 {
46     g_test_init(&argc, &argv, NULL);
47 
48     if (g_test_quick()) {
49         g_test_add_func("/qht/parallel/2threads-0%updates-1s", test_2th0u1s);
50         g_test_add_func("/qht/parallel/2threads-20%updates-1s", test_2th20u1s);
51     } else {
52         g_test_add_func("/qht/parallel/2threads-0%updates-5s", test_2th0u5s);
53         g_test_add_func("/qht/parallel/2threads-20%updates-5s", test_2th20u5s);
54     }
55     return g_test_run();
56 }
57