]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
dummy: Enable use of multiple dummy resources
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 22 Jun 2010 14:50:37 +0000 (16:50 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 22 Jun 2010 14:50:37 +0000 (16:50 +0200)
This is intended for the use in automatic tests which need to work
with multiple resources. The test can initialize several dummy
resources, not just the default one with id 255.

resources/dummy/fra_dummy.c
resources/dummy/frm_dummy.c
resources/dummy/res_dummy.h

index bd052c59b2517de1b1ff911219a5e1c6b23d1028..3536410e4aa3415d7bf04dc76d2334dab34e2011 100644 (file)
@@ -167,3 +167,34 @@ int fra_dummy_init(void)
        fres_block_register_dummy();
        return fra_register(&dummy_allocator);
 }
+
+/** 
+ * Initializes addition dummy resource allocator.
+ *
+ * This is intended for the use in automatic tests which need to work
+ * with multiple resources. The test can initialize several dummy
+ * resources, not just the default one with id 255.
+ * 
+ * @param id 
+ * 
+ * @return Zero on success, non-zero error code on error.
+ */
+int fra_dummy_init_and_activate_id(frsh_resource_id_t res_id)
+{
+       struct fres_allocator *fra;
+       int ret;
+       fres_block_register_dummy();
+       fra = malloc(sizeof(*fra));
+       if (!fra)
+               goto err;
+       *fra = dummy_allocator;
+       fra->res_id = res_id;
+       fra->priv = malloc(sizeof(int));
+       ret = fra_register(fra);
+       if (ret)
+               goto err;
+       ret = fra_activate(fra->res_type, fra->res_id);
+       return ret;
+err:
+       return -1;
+}
index bd7717531764d282754b08375b54f2955870ca4a..f9ff1702c0c075c8b16355f2680d7127259efebd 100644 (file)
@@ -71,6 +71,7 @@
 bool opt_accept_all = false;
 bool opt_daemon = false;
 char *opt_pidfile = NULL;
+int opt_res_id = DUMMY_RESOURCE_ID;
 
 struct dummy_data {
        int some_data;
@@ -152,7 +153,7 @@ int admission_test(struct fres_sa_scenario *scenario, void *priv, bool *schedula
 
 struct dummy_data dummy_data;
 
-static const struct fres_res_manager frm = {
+static struct fres_res_manager frm = {
        .res_type = DUMMY_RESOURCE_TYPE,
        .res_id = DUMMY_RESOURCE_ID,
        .admission_test = admission_test,
@@ -163,6 +164,7 @@ static const struct fres_res_manager frm = {
 static struct option long_opts[] = {
     { "daemon",   optional_argument, NULL, 'd' },
     { "loglevel", 1, 0, 'l' },
+    { "id",      required_argument, 0, 'i' },
     { "accept-all", 0, 0, 'a' },
     { "help", 0, 0, 'h' },
     { 0, 0, 0, 0}
@@ -174,6 +176,7 @@ usage(void)
        printf("usage: frm_dummy [ options ]\n");
        printf("  -a, --accept-all   Accepts all contracts\n");
        printf("  -d, --daemon [pid-file]   go to background after FORB initialization\n");
+       printf("  -i, --id <resource id>    Use a different id that the default (%d)\n", DUMMY_RESOURCE_ID);
        printf("  -h, --help         Display this help\n");
        printf("  -l, --loglevel <number>|<domain>=<number>,...\n");
 }
@@ -185,7 +188,7 @@ int main(int argc, char *argv[])
        forb_init_attr_t attr = { .orb_id = "org.frescor.frm.dummy" };
        int  opt;
 
-       while ((opt = getopt_long(argc, argv, "ad::l:h", &long_opts[0], NULL)) != EOF) {
+       while ((opt = getopt_long(argc, argv, "ad::i:l:h", &long_opts[0], NULL)) != EOF) {
                switch (opt) {
                        case 'a':
                                opt_accept_all = true;
@@ -193,6 +196,9 @@ int main(int argc, char *argv[])
                                opt_daemon = true;
                                opt_pidfile = optarg;
                                break;
+                       case 'i':
+                               opt_res_id = atoi(optarg);
+                               break;
                        case 'l':
                                ul_log_domain_arg2levels(optarg);
                                break;
@@ -217,6 +223,7 @@ int main(int argc, char *argv[])
        ulogd_frm_generic.level = UL_LOGL_ERR;
 #endif
 
+       frm.res_id = opt_res_id;
        ret = frm_register_and_run(orb, &frm);
 
        if (ret != 0) {
index d04a66d1e67d39886776f5de944ab72f4b5fd5f4..d0108fc92896542b43bb95ea659564c8fb843242 100644 (file)
@@ -67,6 +67,7 @@
 #define DUMMY_RESOURCE_ID   (frsh_resource_id_t)255
 
 int fra_dummy_init(void);
+int fra_dummy_init_and_activate_id(frsh_resource_id_t res_id);
 int fres_block_register_dummy(void);
 
 /* Define fres_container_(add|get|del)_dummy_sched. */