Switch to environmental variables
authorbdemsky <bdemsky@uci.edu>
Wed, 27 Nov 2019 23:41:04 +0000 (15:41 -0800)
committerbdemsky <bdemsky@uci.edu>
Wed, 27 Nov 2019 23:41:04 +0000 (15:41 -0800)
main.cc
model.cc
model.h

diff --git a/main.cc b/main.cc
index 590a41d27f33c07118592912fc73f582a4624050..5bee8ce6aac0c45e62c34d36c82113f8cdf6892e 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -26,7 +26,7 @@ void param_defaults(struct model_params *params)
        params->threadsnocleanup = false;
 }
 
        params->threadsnocleanup = false;
 }
 
-static void print_usage(const char *program_name, struct model_params *params)
+static void print_usage(struct model_params *params)
 {
        ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
        /* Reset defaults before printing */
 {
        ModelVector<TraceAnalysis *> * registeredanalysis=getRegisteredTraceAnalysis();
        /* Reset defaults before printing */
@@ -37,7 +37,7 @@ static void print_usage(const char *program_name, struct model_params *params)
                "Distributed under the GPLv2\n"
                "Written by Brian Norris and Brian Demsky\n"
                "\n"
                "Distributed under the GPLv2\n"
                "Written by Brian Norris and Brian Demsky\n"
                "\n"
-               "Usage: %s [MODEL-CHECKER OPTIONS] -- [PROGRAM ARGS]\n"
+               "Usage: [MODEL-CHECKER OPTIONS] -- [PROGRAM ARGS]\n"
                "\n"
                "MODEL-CHECKER OPTIONS can be any of the model-checker options listed below. Arguments\n"
                "provided after the `--' (the PROGRAM ARGS) are passed to the user program.\n"
                "\n"
                "MODEL-CHECKER OPTIONS can be any of the model-checker options listed below. Arguments\n"
                "provided after the `--' (the PROGRAM ARGS) are passed to the user program.\n"
@@ -61,7 +61,6 @@ static void print_usage(const char *program_name, struct model_params *params)
                "-d                          Don't allow threads to cleanup\n"
 #endif
                " --                         Program arguments follow.\n\n",
                "-d                          Don't allow threads to cleanup\n"
 #endif
                " --                         Program arguments follow.\n\n",
-               program_name,
                params->verbose,
                params->uninitvalue,
                params->maxexecutions);
                params->verbose,
                params->uninitvalue,
                params->maxexecutions);
@@ -88,8 +87,7 @@ bool install_plugin(char * name) {
        return true;
 }
 
        return true;
 }
 
-static void parse_options(struct model_params *params, int argc, char **argv)
-{
+void parse_options(struct model_params *params) {
        const char *shortopts = "hdnt:o:u:x:v::";
        const struct option longopts[] = {
                {"help", no_argument, NULL, 'h'},
        const char *shortopts = "hdnt:o:u:x:v::";
        const struct option longopts[] = {
                {"help", no_argument, NULL, 'h'},
@@ -101,11 +99,30 @@ static void parse_options(struct model_params *params, int argc, char **argv)
                {0, 0, 0, 0}    /* Terminator */
        };
        int opt, longindex;
                {0, 0, 0, 0}    /* Terminator */
        };
        int opt, longindex;
+       int tmpoptind = optind;
        bool error = false;
        bool error = false;
+       char * options = getenv("C11TESTER");
+
+       if (options == NULL)
+               return;
+       int argc = 1;
+       for(int index = 0;options[index]!=0;index++) {
+               if (options[index] == ' ')
+                       argc++;
+       }
+       argc++; //first parameter is executable name
+       char * argv[argc + 1];
+       argv[0] = NULL;
+       argv[1] = options;
+       for(int index = 0, count = 2;options[index]!=0;index++) {
+               if (options[index]==' ')
+                       argv[count++] = &options[index];
+       }
+
        while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
                switch (opt) {
                case 'h':
        while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
                switch (opt) {
                case 'h':
-                       print_usage(argv[0], params);
+                       print_usage(params);
                        break;
                case 'd':
                        params->threadsnocleanup = true;
                        break;
                case 'd':
                        params->threadsnocleanup = true;
@@ -139,23 +156,13 @@ static void parse_options(struct model_params *params, int argc, char **argv)
                }
        }
 
                }
        }
 
-       /* Pass remaining arguments to user program */
-       params->argc = argc - (optind - 1);
-       params->argv = argv + (optind - 1);
-
-       /* Reset program name */
-       params->argv[0] = argv[0];
-
-       /* Reset (global) optind for potential use by user program */
-       optind = 1;
+       /* Restore (global) optind for potential use by user program */
+       optind = tmpoptind;
 
        if (error)
 
        if (error)
-               print_usage(argv[0], params);
+               print_usage(params);
 }
 
 }
 
-int main_argc;
-char **main_argv;
-
 static void install_trace_analyses(ModelExecution *execution)
 {
        ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
 static void install_trace_analyses(ModelExecution *execution)
 {
        ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
@@ -174,9 +181,6 @@ static void install_trace_analyses(ModelExecution *execution)
  */
 int main(int argc, char **argv)
 {
  */
 int main(int argc, char **argv)
 {
-       main_argc = argc;
-       main_argv = argv;
-
        /*
         * If this printf statement is removed, C11Tester will fail on an
         * assert on some versions of glibc.  The first time printf is
        /*
         * If this printf statement is removed, C11Tester will fail on an
         * assert on some versions of glibc.  The first time printf is
@@ -199,13 +203,12 @@ int main(int argc, char **argv)
 
        /* Configure output redirection for the model-checker */
        redirect_output();
 
        /* Configure output redirection for the model-checker */
        redirect_output();
-
        register_plugins();
 
        register_plugins();
 
-       //Parse command line options
+       //Stash command line options
        model_params *params = model->getParams();
        model_params *params = model->getParams();
-       parse_options(params, main_argc, main_argv);
-
+       params->argc = argc;
+       params->argv = argv;
 
        install_trace_analyses(model->get_execution());
 
 
        install_trace_analyses(model->get_execution());
 
index 88b3302acd5804a2a0756e818e5e9fc98092e0de..b5e55867e1e6485659677cfce6a8f51432509d73 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -48,6 +48,7 @@ ModelChecker::ModelChecker() :
        scheduler->set_current_thread(init_thread);
        execution->setParams(&params);
        param_defaults(&params);
        scheduler->set_current_thread(init_thread);
        execution->setParams(&params);
        param_defaults(&params);
+       parse_options(&params);
        initRaceDetector();
 }
 
        initRaceDetector();
 }
 
diff --git a/model.h b/model.h
index 3e0651864d80f97d5ff01a11b758ec77871867b4..354ed791dc103e01cf544e9e9bc7cf5a19fb2945 100644 (file)
--- a/model.h
+++ b/model.h
@@ -108,4 +108,5 @@ private:
 };
 
 extern ModelChecker *model;
 };
 
 extern ModelChecker *model;
+void parse_options(struct model_params *params);
 #endif /* __MODEL_H__ */
 #endif /* __MODEL_H__ */