summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2012-02-14 17:30:50 +0200
committerAlon Levy <alevy@redhat.com>2012-02-14 17:30:50 +0200
commite4a92b177ab89d17505a3bc013a2c927b55c50da (patch)
tree2fa39ff87faef92e6b7cf37fdc86420fff8bcaed /server
parent33bd5d27971c8ec4c0843c5674d0c0afd449a568 (diff)
downloadspice-e4a92b177ab89d17505a3bc013a2c927b55c50da.tar.gz
spice-e4a92b177ab89d17505a3bc013a2c927b55c50da.tar.xz
spice-e4a92b177ab89d17505a3bc013a2c927b55c50da.zip
server/tests: use getopt_long
Diffstat (limited to 'server')
-rw-r--r--server/tests/test_display_base.c47
-rw-r--r--server/tests/test_display_base.h3
-rw-r--r--server/tests/test_display_streaming.c4
3 files changed, 32 insertions, 22 deletions
diff --git a/server/tests/test_display_base.c b/server/tests/test_display_base.c
index 48f59d2c..811e901b 100644
--- a/server/tests/test_display_base.c
+++ b/server/tests/test_display_base.c
@@ -1,4 +1,3 @@
-
#include <config.h>
#include <stdlib.h>
#include <math.h>
@@ -9,7 +8,10 @@
#include <wait.h>
#include <sys/select.h>
#include <sys/types.h>
+#include <getopt.h>
+
#include <spice/qxl_dev.h>
+
#include "test_display_base.h"
#include "red_channel.h"
#include "test_util.h"
@@ -649,32 +651,43 @@ SpiceServer* test_init(SpiceCoreInterface *core)
return server;
}
-void check_automated(int argc, char **argv)
+void init_automated()
{
struct sigaction sa;
- if (argc == 1) {
- return;
- }
-
- if (argc > 2) {
- goto invalid_option;
- }
-
- if (strcmp(argv[1], "--automated-tests") != 0) {
- goto invalid_option;
- }
-
- has_automated_tests = 1;
-
memset(&sa, 0, sizeof sa);
sa.sa_handler = &sigchld_handler;
sigaction(SIGCHLD, &sa, NULL);
+}
+
+void spice_test_config_parse_args(int argc, char **argv)
+{
+ struct option options[] = {
+#ifdef AUTOMATED_TESTS
+ {"automated-tests", no_argument, &has_automated_tests, 1},
+#endif
+ {NULL, 0, NULL, 0},
+ };
+ int option_index;
+ int val;
+
+ while ((val = getopt_long(argc, argv, "", options, &option_index)) != -1) {
+ switch (val) {
+ case '?':
+ printf("unrecognized option %s", argv[optind]);
+ goto invalid_option;
+ case 0:
+ break;
+ }
+ }
+ if (has_automated_tests) {
+ init_automated();
+ }
return;
invalid_option:
printf("Invalid option!\n"
- "Please, check README before run tests!\n" );
+ "usage: %s [--automated-tests]\n", argv[0]);
exit(0);
}
diff --git a/server/tests/test_display_base.h b/server/tests/test_display_base.h
index 4aeaf5f3..0ed41cb8 100644
--- a/server/tests/test_display_base.h
+++ b/server/tests/test_display_base.h
@@ -10,8 +10,7 @@ void test_set_simple_command_list(int* commands, int num_commands);
void test_add_display_interface(SpiceServer *server);
SpiceServer* test_init(SpiceCoreInterface* core);
-/* Used for automated tests */
-void check_automated(int argc, char **argv);
+void spice_test_config_parse_args(int argc, char **argv);
// simple queue for commands
enum {
diff --git a/server/tests/test_display_streaming.c b/server/tests/test_display_streaming.c
index 5052991d..1b81d766 100644
--- a/server/tests/test_display_streaming.c
+++ b/server/tests/test_display_streaming.c
@@ -20,9 +20,7 @@ SpiceServer *server;
int main(int argc, char **argv)
{
-#ifdef AUTOMATED_TESTS
- check_automated(argc, argv);
-#endif
+ spice_test_config_parse_args(argc, argv);
core = basic_event_loop_init();
server = test_init(core);
spice_server_set_streaming_video(server, SPICE_STREAM_VIDEO_ALL);