summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmit Shah <amit.shah@redhat.com>2009-12-01 17:35:27 +0530
committerAmit Shah <amit.shah@redhat.com>2009-12-22 12:36:01 +0530
commit1e23247ab9e95426aa56c88fbe697e05a48ddcbf (patch)
treed0cf647c8cb8b35569992c644a85af8e32756515
parent1f0c17b470fa3d9b1cdbc11790ed847eb24b6b77 (diff)
downloadtest-virtserial-1e23247ab9e95426aa56c88fbe697e05a48ddcbf.tar.gz
test-virtserial-1e23247ab9e95426aa56c88fbe697e05a48ddcbf.tar.xz
test-virtserial-1e23247ab9e95426aa56c88fbe697e05a48ddcbf.zip
autotest: add function pointers to our test routines in an array
This is so that the main routine doesn't need to know the function name of the test to run. Signed-off-by: Amit Shah <amit.shah@redhat.com>
-rw-r--r--auto-virtserial.c61
1 files changed, 39 insertions, 22 deletions
diff --git a/auto-virtserial.c b/auto-virtserial.c
index 9a3e49a..b7016a1 100644
--- a/auto-virtserial.c
+++ b/auto-virtserial.c
@@ -1055,6 +1055,24 @@ out_close:
return err;
}
+static int(*test_functions[TEST_END])(int) = {
+ test_open,
+ test_close,
+ test_multiple_open,
+ test_sysfs_and_udev,
+ test_read_without_host,
+ test_blocking_read,
+ test_nonblocking_read,
+ test_poll,
+ test_guest_throttle,
+ test_host_throttle,
+ test_guest_caching,
+ test_host_caching,
+ test_host_file_send,
+ test_guest_file_send,
+ test_console,
+};
+
static void post_test_cleanup(int nr)
{
char buf[BUF_LENGTH];
@@ -1085,12 +1103,12 @@ skip_guest:
host_close_chardev(nr);
}
-static int run_test(int (test)(int nr), int nr, int test_nr)
+static int run_test(int test_nr, int nr)
{
int ret = 0;
if (tests[test_nr]) {
- ret = (test)(nr);
+ ret = test_functions[test_nr](nr);
post_test_cleanup(nr);
}
return ret;
@@ -1106,48 +1124,47 @@ static int start_tests(void)
* qemu version.
*/
- run_test(test_open, 2, TEST_OPEN);
- run_test(test_close, 2, TEST_CLOSE);
- run_test(test_multiple_open, 2, TEST_MULTI_OPEN);
+ run_test(TEST_OPEN, 2);
+ run_test(TEST_CLOSE, 2);
+ run_test(TEST_MULTI_OPEN, 2);
- run_test(test_sysfs_and_udev, 2, TEST_SYSFS_UDEV);
+ run_test(TEST_SYSFS_UDEV, 2);
- run_test(test_read_without_host, 2, TEST_READ_WO_HOST);
+ run_test(TEST_READ_WO_HOST, 2);
- run_test(test_blocking_read, 2, TEST_BLOCKING_READ);
- run_test(test_nonblocking_read, 2, TEST_NOBLOCK_READ);
+ run_test(TEST_BLOCKING_READ, 2);
+ run_test(TEST_NOBLOCK_READ, 2);
- run_test(test_poll, 2, TEST_POLL);
+ run_test(TEST_POLL, 2);
/* Throttling is not enabled on this port */
- run_test(test_guest_throttle, 2, TEST_G_THROTTLE);
+ run_test(TEST_G_THROTTLE, 2);
/* Throttling is enabled on this port */
- run_test(test_guest_throttle, 4, TEST_G_THROTTLE);
+ run_test(TEST_G_THROTTLE, 4);
/* Throttling is not enabled on this port */
- run_test(test_host_throttle, 2, TEST_H_THROTTLE);
+ run_test(TEST_H_THROTTLE, 2);
/* Throttling is enabled on this port */
- run_test(test_host_throttle, 4, TEST_H_THROTTLE);
+ run_test(TEST_H_THROTTLE, 4);
/* Caching is enabled on this port */
- run_test(test_guest_caching, 2, TEST_G_CACHING);
+ run_test(TEST_G_CACHING, 2);
/* Caching is not enabled on this port */
- run_test(test_guest_caching, 3, TEST_G_CACHING);
+ run_test(TEST_G_CACHING, 3);
/* Caching is enabled on this port */
- run_test(test_host_caching, 2, TEST_H_CACHING);
+ run_test(TEST_H_CACHING, 2);
/* Caching is not enabled on this port */
- run_test(test_host_caching, 3, TEST_H_CACHING);
+ run_test(TEST_H_CACHING, 3);
/* Sends a big file across, compares sha1sums */
- run_test(test_host_file_send, 2, TEST_H_FILE_SEND);
+ run_test(TEST_H_FILE_SEND, 2);
/* Sends a big file across, compares sha1sums */
- run_test(test_guest_file_send, 2, TEST_G_FILE_SEND);
-
+ run_test(TEST_G_FILE_SEND, 2);
}
/* The console test should work in any case. */
- run_test(test_console, 0, TEST_CONSOLE);
+ run_test(TEST_CONSOLE, 0);
return 0;
}