diff options
author | Amit Shah <amit.shah@redhat.com> | 2009-12-01 20:06:19 +0530 |
---|---|---|
committer | Amit Shah <amit.shah@redhat.com> | 2009-12-22 12:36:01 +0530 |
commit | a5bc45f20a8b37a93e4cabb87c0a4b0f9fdcb2bb (patch) | |
tree | c34ab7fd7d2af534fa453b06acfebe8c842caf6a | |
parent | 1e23247ab9e95426aa56c88fbe697e05a48ddcbf (diff) | |
download | test-virtserial-a5bc45f20a8b37a93e4cabb87c0a4b0f9fdcb2bb.tar.gz test-virtserial-a5bc45f20a8b37a93e4cabb87c0a4b0f9fdcb2bb.tar.xz test-virtserial-a5bc45f20a8b37a93e4cabb87c0a4b0f9fdcb2bb.zip |
autotest: put globals fn_name and bools of tests enabled in struct
Signed-off-by: Amit Shah <amit.shah@redhat.com>
-rw-r--r-- | auto-virtserial.c | 199 |
1 files changed, 123 insertions, 76 deletions
diff --git a/auto-virtserial.c b/auto-virtserial.c index b7016a1..f597250 100644 --- a/auto-virtserial.c +++ b/auto-virtserial.c @@ -93,27 +93,6 @@ static struct host_chars { } }; -enum { - TEST_OPEN = 0, - TEST_CLOSE, - TEST_MULTI_OPEN, - TEST_SYSFS_UDEV, - TEST_READ_WO_HOST, - TEST_BLOCKING_READ, - TEST_NOBLOCK_READ, - TEST_POLL, - TEST_G_THROTTLE, - TEST_H_THROTTLE, - TEST_G_CACHING, - TEST_H_CACHING, - TEST_H_FILE_SEND, - TEST_G_FILE_SEND, - TEST_CONSOLE, - TEST_END -}; - -static bool tests[TEST_END]; - static void handle_guest_error(struct guest_packet *gpkt) { char *buf; @@ -1055,22 +1034,90 @@ 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, +enum { + TEST_OPEN = 0, + TEST_CLOSE, + TEST_MULTI_OPEN, + TEST_SYSFS_UDEV, + TEST_READ_WO_HOST, + TEST_BLOCKING_READ, + TEST_NOBLOCK_READ, + TEST_POLL, + TEST_G_THROTTLE, + TEST_H_THROTTLE, + TEST_G_CACHING, + TEST_H_CACHING, + TEST_H_FILE_SEND, + TEST_G_FILE_SEND, + TEST_CONSOLE, + TEST_END +}; + +static struct test_parameters { + int (*test_function)(int); + bool enabled; + bool needs_guestok; +} tests[TEST_END] = { + { + .test_function = test_open, + .needs_guestok = true, + }, + { + .test_function = test_close, + .needs_guestok = true, + }, + { + .test_function = test_multiple_open, + .needs_guestok = true, + }, + { + .test_function = test_sysfs_and_udev, + .needs_guestok = true, + }, + { + .test_function = test_read_without_host, + .needs_guestok = true, + }, + { + .test_function = test_blocking_read, + .needs_guestok = true, + }, + { + .test_function = test_nonblocking_read, + .needs_guestok = true, + }, + { + .test_function = test_poll, + .needs_guestok = true, + }, + { + .test_function = test_guest_throttle, + .needs_guestok = true, + }, + { + .test_function = test_host_throttle, + .needs_guestok = true, + }, + { + .test_function = test_guest_caching, + .needs_guestok = true, + }, + { + .test_function = test_host_caching, + .needs_guestok = true, + }, + { + .test_function = test_host_file_send, + .needs_guestok = true, + }, + { + .test_function = test_guest_file_send, + .needs_guestok = true, + }, + { + .test_function = test_console, + .needs_guestok = false, + }, }; static void post_test_cleanup(int nr) @@ -1107,8 +1154,10 @@ static int run_test(int test_nr, int nr) { int ret = 0; - if (tests[test_nr]) { - ret = test_functions[test_nr](nr); + if (tests[test_nr].enabled) { + if (tests[test_nr].needs_guestok && !guest_ok) + return 0; + ret = tests[test_nr].test_function(nr); post_test_cleanup(nr); } return ret; @@ -1116,53 +1165,51 @@ static int run_test(int test_nr, int nr) static int start_tests(void) { - if (guest_ok) { - /* - * These tests can only be tried when the guest - * program is up. The guest program will terminate in - * case we're running on an incompatible kernel or - * qemu version. - */ + /* + * These tests can only be tried when the guest program is + * up. The guest program will terminate in case we're running + * on an incompatible kernel or qemu version. + */ - run_test(TEST_OPEN, 2); - run_test(TEST_CLOSE, 2); - run_test(TEST_MULTI_OPEN, 2); + run_test(TEST_OPEN, 2); + run_test(TEST_CLOSE, 2); + run_test(TEST_MULTI_OPEN, 2); - run_test(TEST_SYSFS_UDEV, 2); + run_test(TEST_SYSFS_UDEV, 2); - run_test(TEST_READ_WO_HOST, 2); + run_test(TEST_READ_WO_HOST, 2); - run_test(TEST_BLOCKING_READ, 2); - run_test(TEST_NOBLOCK_READ, 2); + run_test(TEST_BLOCKING_READ, 2); + run_test(TEST_NOBLOCK_READ, 2); - run_test(TEST_POLL, 2); + run_test(TEST_POLL, 2); - /* Throttling is not enabled on this port */ - run_test(TEST_G_THROTTLE, 2); - /* Throttling is enabled on this port */ - run_test(TEST_G_THROTTLE, 4); + /* Throttling is not enabled on this port */ + run_test(TEST_G_THROTTLE, 2); + /* Throttling is enabled on this port */ + run_test(TEST_G_THROTTLE, 4); - /* Throttling is not enabled on this port */ - run_test(TEST_H_THROTTLE, 2); - /* Throttling is enabled on this port */ - run_test(TEST_H_THROTTLE, 4); + /* Throttling is not enabled on this port */ + run_test(TEST_H_THROTTLE, 2); + /* Throttling is enabled on this port */ + run_test(TEST_H_THROTTLE, 4); - /* Caching is enabled on this port */ - run_test(TEST_G_CACHING, 2); - /* Caching is not enabled on this port */ - run_test(TEST_G_CACHING, 3); + /* Caching is enabled on this port */ + run_test(TEST_G_CACHING, 2); + /* Caching is not enabled on this port */ + run_test(TEST_G_CACHING, 3); - /* Caching is enabled on this port */ - run_test(TEST_H_CACHING, 2); - /* Caching is not enabled on this port */ - run_test(TEST_H_CACHING, 3); + /* Caching is enabled on this port */ + run_test(TEST_H_CACHING, 2); + /* Caching is not enabled on this port */ + run_test(TEST_H_CACHING, 3); - /* Sends a big file across, compares sha1sums */ - run_test(TEST_H_FILE_SEND, 2); + /* Sends a big file across, compares sha1sums */ + run_test(TEST_H_FILE_SEND, 2); + + /* Sends a big file across, compares sha1sums */ + run_test(TEST_G_FILE_SEND, 2); - /* Sends a big file across, compares sha1sums */ - run_test(TEST_G_FILE_SEND, 2); - } /* The console test should work in any case. */ run_test(TEST_CONSOLE, 0); @@ -1231,7 +1278,7 @@ int main(int argc, const char *argv[]) next: /* mark all tests as 'to be run' */ for (i = 0; i < TEST_END; i++) - tests[i] = true; + tests[i].enabled = true; /* Now we're all set to start our tests. */ start_tests(); |