Changeset 3fddb55 in mainline for uspace/drv/test1/test1.c


Ignore:
Timestamp:
2011-03-30T13:20:37Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fc8c2b6
Parents:
0876062
Message:

Testing driver improvement

The driver tries to register the same function twice and checks that
such operation fails with appropriate error code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/test1/test1.c

    r0876062 r3fddb55  
    5858 */
    5959static int register_fun_verbose(ddf_dev_t *parent, const char *message,
    60     const char *name, const char *match_id, int match_score)
     60    const char *name, const char *match_id, int match_score,
     61    int expected_rc)
    6162{
    62         ddf_fun_t *fun;
     63        ddf_fun_t *fun = NULL;
    6364        int rc;
    6465
     
    6869        if (fun == NULL) {
    6970                printf(NAME ": error creating function %s\n", name);
    70                 return ENOMEM;
     71                rc = ENOMEM;
     72                goto leave;
    7173        }
    7274
    73         rc = ddf_fun_add_match_id(fun, match_id, match_score);
     75        rc = ddf_fun_add_match_id(fun, str_dup(match_id), match_score);
    7476        if (rc != EOK) {
    7577                printf(NAME ": error adding match IDs to function %s\n", name);
    76                 ddf_fun_destroy(fun);
    77                 return rc;
     78                goto leave;
    7879        }
    7980
     
    8283                printf(NAME ": error binding function %s: %s\n", name,
    8384                    str_error(rc));
    84                 ddf_fun_destroy(fun);
    85                 return rc;
     85                goto leave;
    8686        }
    8787
    8888        printf(NAME ": registered child device `%s'\n", name);
    89         return EOK;
     89        rc = EOK;
     90
     91
     92leave:
     93        if (rc != expected_rc) {
     94                fprintf(stderr,
     95                    NAME ": Unexpected error registering function `%s'.\n" \
     96                    NAME ":     Expected \"%s\" but got \"%s\".\n",
     97                    name, str_error(expected_rc), str_error(rc));
     98        }
     99
     100        if ((rc != EOK) && (fun != NULL)) {
     101                ddf_fun_destroy(fun);
     102        }
     103
     104        return rc;
    90105}
    91106
     
    133148                ddf_fun_add_to_class(fun_a, "virt-null");
    134149        } else if (str_cmp(dev->name, "test1") == 0) {
    135                 (void) register_fun_verbose(dev, "cloning myself ;-)", "clone",
    136                     "virtual&test1", 10);
     150                (void) register_fun_verbose(dev,
     151                    "cloning myself ;-)", "clone",
     152                    "virtual&test1", 10, EOK);
     153                (void) register_fun_verbose(dev,
     154                    "cloning myself twice ;-)", "clone",
     155                    "virtual&test1", 10, EEXISTS);
    137156        } else if (str_cmp(dev->name, "clone") == 0) {
    138                 (void) register_fun_verbose(dev, "run by the same task", "child",
    139                     "virtual&test1&child", 10);
     157                (void) register_fun_verbose(dev,
     158                    "run by the same task", "child",
     159                    "virtual&test1&child", 10, EOK);
    140160        }
    141161
Note: See TracChangeset for help on using the changeset viewer.