xref: /qemu/tests/qtest/rtas-test.c (revision 0472b2e5)
11e8a1faeSThomas Huth #include "qemu/osdep.h"
21e8a1faeSThomas Huth #include "qemu/cutils.h"
3907b5105SMarc-André Lureau #include "libqtest.h"
41e8a1faeSThomas Huth 
51e8a1faeSThomas Huth #include "libqos/libqos-spapr.h"
61e8a1faeSThomas Huth #include "libqos/rtas.h"
71e8a1faeSThomas Huth 
run_test_rtas_get_time_of_day(const char * machine)8fc8c745dSAlexey Kardashevskiy static void run_test_rtas_get_time_of_day(const char *machine)
91e8a1faeSThomas Huth {
101e8a1faeSThomas Huth     QOSState *qs;
111e8a1faeSThomas Huth     struct tm tm;
121e8a1faeSThomas Huth     uint32_t ns;
131e8a1faeSThomas Huth     uint64_t ret;
141e8a1faeSThomas Huth     time_t t1, t2;
151e8a1faeSThomas Huth 
16*0472b2e5SDaniel P. Berrangé     qs = qtest_spapr_boot("%s", machine);
171e8a1faeSThomas Huth 
181e8a1faeSThomas Huth     t1 = time(NULL);
191e8a1faeSThomas Huth     ret = qrtas_get_time_of_day(qs->qts, &qs->alloc, &tm, &ns);
201e8a1faeSThomas Huth     g_assert_cmpint(ret, ==, 0);
211e8a1faeSThomas Huth     t2 = mktimegm(&tm);
221e8a1faeSThomas Huth     g_assert(t2 - t1 < 5); /* 5 sec max to run the test */
231e8a1faeSThomas Huth 
241e8a1faeSThomas Huth     qtest_shutdown(qs);
251e8a1faeSThomas Huth }
261e8a1faeSThomas Huth 
test_rtas_get_time_of_day(void)27fc8c745dSAlexey Kardashevskiy static void test_rtas_get_time_of_day(void)
28fc8c745dSAlexey Kardashevskiy {
29fc8c745dSAlexey Kardashevskiy     run_test_rtas_get_time_of_day("-machine pseries");
30fc8c745dSAlexey Kardashevskiy }
31fc8c745dSAlexey Kardashevskiy 
test_rtas_get_time_of_day_vof(void)32fc8c745dSAlexey Kardashevskiy static void test_rtas_get_time_of_day_vof(void)
33fc8c745dSAlexey Kardashevskiy {
34fc8c745dSAlexey Kardashevskiy     run_test_rtas_get_time_of_day("-machine pseries,x-vof=on");
35fc8c745dSAlexey Kardashevskiy }
36fc8c745dSAlexey Kardashevskiy 
main(int argc,char * argv[])371e8a1faeSThomas Huth int main(int argc, char *argv[])
381e8a1faeSThomas Huth {
391e8a1faeSThomas Huth     const char *arch = qtest_get_arch();
401e8a1faeSThomas Huth 
411e8a1faeSThomas Huth     g_test_init(&argc, &argv, NULL);
421e8a1faeSThomas Huth 
431e8a1faeSThomas Huth     if (strcmp(arch, "ppc64")) {
4464ed6f92SPaolo Bonzini         g_printerr("RTAS requires qemu-system-ppc64\n");
451e8a1faeSThomas Huth         exit(EXIT_FAILURE);
461e8a1faeSThomas Huth     }
471e8a1faeSThomas Huth     qtest_add_func("rtas/get-time-of-day", test_rtas_get_time_of_day);
48fc8c745dSAlexey Kardashevskiy     qtest_add_func("rtas/get-time-of-day-vof", test_rtas_get_time_of_day_vof);
491e8a1faeSThomas Huth 
501e8a1faeSThomas Huth     return g_test_run();
511e8a1faeSThomas Huth }
52