diff options
author | Thomas Huth <thuth@redhat.com> | 2021-03-10 07:33:14 +0100 |
---|---|---|
committer | Thomas Huth <thuth@redhat.com> | 2021-03-12 15:46:30 +0100 |
commit | da668aa15b99150a8595c491aee00d5d2426aaf9 (patch) | |
tree | 0463b0a303e807bdab46460f6c702be611bd7179 /tests/test-timed-average.c | |
parent | 363fc963054d8e82cfd55fa9b9aa130692a8dbd7 (diff) |
tests: Move unit tests into a separate directory
The main tests directory still looks very crowded, and it's not
clear which files are part of a unit tests and which belong to
a different test subsystem. Let's clean up the mess and move the
unit tests to a separate directory.
Message-Id: <20210310063314.1049838-1-thuth@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/test-timed-average.c')
-rw-r--r-- | tests/test-timed-average.c | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/tests/test-timed-average.c b/tests/test-timed-average.c deleted file mode 100644 index 82c92500df..0000000000 --- a/tests/test-timed-average.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Timed average computation tests - * - * Copyright Nodalink, EURL. 2014 - * - * Authors: - * BenoƮt Canet <benoit.canet@nodalink.com> - * - * This work is licensed under the terms of the GNU LGPL, version 2 or later. - * See the COPYING.LIB file in the top-level directory. - */ - -#include "qemu/osdep.h" -#include "sysemu/cpu-timers.h" -#include "qemu/timed-average.h" - -/* This is the clock for QEMU_CLOCK_VIRTUAL */ -static int64_t my_clock_value; - -int64_t cpu_get_clock(void) -{ - return my_clock_value; -} - -static void account(TimedAverage *ta) -{ - timed_average_account(ta, 1); - timed_average_account(ta, 5); - timed_average_account(ta, 2); - timed_average_account(ta, 4); - timed_average_account(ta, 3); -} - -static void test_average(void) -{ - TimedAverage ta; - uint64_t result; - int i; - - /* we will compute some average on a period of 1 second */ - timed_average_init(&ta, QEMU_CLOCK_VIRTUAL, NANOSECONDS_PER_SECOND); - - result = timed_average_min(&ta); - g_assert(result == 0); - result = timed_average_avg(&ta); - g_assert(result == 0); - result = timed_average_max(&ta); - g_assert(result == 0); - - for (i = 0; i < 100; i++) { - account(&ta); - result = timed_average_min(&ta); - g_assert(result == 1); - result = timed_average_avg(&ta); - g_assert(result == 3); - result = timed_average_max(&ta); - g_assert(result == 5); - my_clock_value += NANOSECONDS_PER_SECOND / 10; - } - - my_clock_value += NANOSECONDS_PER_SECOND * 100; - - result = timed_average_min(&ta); - g_assert(result == 0); - result = timed_average_avg(&ta); - g_assert(result == 0); - result = timed_average_max(&ta); - g_assert(result == 0); - - for (i = 0; i < 100; i++) { - account(&ta); - result = timed_average_min(&ta); - g_assert(result == 1); - result = timed_average_avg(&ta); - g_assert(result == 3); - result = timed_average_max(&ta); - g_assert(result == 5); - my_clock_value += NANOSECONDS_PER_SECOND / 10; - } -} - -int main(int argc, char **argv) -{ - /* tests in the same order as the header function declarations */ - g_test_init(&argc, &argv, NULL); - g_test_add_func("/timed-average/average", test_average); - return g_test_run(); -} - |