Changeset a42d7d8 in mainline


Ignore:
Timestamp:
2012-08-19T05:28:24Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fae4d30
Parents:
1c79996
Message:

Bithenge: add fake system call errors to test error handling

Location:
uspace
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bithenge/Makefile.linux

    r1c79996 ra42d7d8  
    4141        test.c
    4242
     43ifdef COVERAGE
     44        CFLAGS += -fprofile-arcs -ftest-coverage
     45endif
     46
    4347OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
    4448
  • uspace/lib/bithenge/Makefile.linux

    r1c79996 ra42d7d8  
    4646        tree.c
    4747
     48ifdef COVERAGE
     49        CFLAGS += -fprofile-arcs -ftest-coverage
     50endif
     51
     52ifdef FAILURE
     53        CFLAGS += -DBITHENGE_FAILURE_ENABLE=1
     54        SOURCES += failure.c
     55endif
     56
    4857OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
    4958
  • uspace/lib/bithenge/blob.c

    r1c79996 ra42d7d8  
    461461/** Check whether the contents of two blobs are equal.
    462462 * @memberof bithenge_blob_t
     463 * @param[out] out Holds whether the blobs are equal.
    463464 * @param a, b Blobs to compare.
    464  * @return Whether the blobs are equal. If an error occurs, returns false.
    465  */
    466 bool bithenge_blob_equal(bithenge_blob_t *a, bithenge_blob_t *b)
     465 * @return EOK on success, or an error code from errno.h.
     466 */
     467int bithenge_blob_equal(bool *out, bithenge_blob_t *a, bithenge_blob_t *b)
    467468{
    468469        assert(a);
     
    476477                rc = bithenge_blob_read(a, offset, buffer_a, &size_a);
    477478                if (rc != EOK)
    478                         return false;
     479                        return rc;
    479480                rc = bithenge_blob_read(b, offset, buffer_b, &size_b);
    480481                if (rc != EOK)
    481                         return false;
    482                 if (size_a != size_b || bcmp(buffer_a, buffer_b, size_a))
    483                         return false;
     482                        return rc;
     483                if (size_a != size_b || bcmp(buffer_a, buffer_b, size_a)) {
     484                        *out = false;
     485                        return EOK;
     486                }
    484487                offset += size_a;
    485488        } while (size_a == sizeof(buffer_a));
    486         return true;
     489        *out = true;
     490        return EOK;
    487491}
    488492
  • uspace/lib/bithenge/blob.h

    r1c79996 ra42d7d8  
    243243int bithenge_new_subblob(bithenge_node_t **, bithenge_blob_t *, aoff64_t,
    244244    aoff64_t);
    245 bool bithenge_blob_equal(bithenge_blob_t *, bithenge_blob_t *);
     245int bithenge_blob_equal(bool *, bithenge_blob_t *, bithenge_blob_t *);
    246246
    247247#endif
  • uspace/lib/bithenge/expression.c

    r1c79996 ra42d7d8  
    104104        /* Check types and get values. */
    105105        bithenge_int_t a_int = 0, b_int = 0;
    106         bool a_bool = false, b_bool = false;
     106        bool a_bool = false, b_bool = false, out_bool = false;
    107107        switch (self->op) {
    108108        case BITHENGE_EXPRESSION_ADD: /* fallthrough */
     
    187187                break;
    188188        case BITHENGE_EXPRESSION_EQUALS:
    189                 rc = bithenge_new_boolean_node(out, bithenge_node_equal(a, b));
     189                rc = bithenge_node_equal(&out_bool, a, b);
     190                if (rc != EOK)
     191                        break;
     192                rc = bithenge_new_boolean_node(out, out_bool);
    190193                break;
    191194        case BITHENGE_EXPRESSION_NOT_EQUALS:
    192                 rc = bithenge_new_boolean_node(out,
    193                     !bithenge_node_equal(a, b));
     195                rc = bithenge_node_equal(&out_bool, a, b);
     196                if (rc != EOK)
     197                        break;
     198                rc = bithenge_new_boolean_node(out, !out_bool);
    194199                break;
    195200        case BITHENGE_EXPRESSION_AND:
  • uspace/lib/bithenge/file.c

    r1c79996 ra42d7d8  
    7979                return ELIMIT;
    8080        if (lseek(blob->fd, offset, SEEK_SET) < 0)
    81                 return errno;
     81                return errno == EINVAL ? EIO : EINVAL;
    8282
    8383        ssize_t amount_read;
  • uspace/lib/bithenge/os.h

    r1c79996 ra42d7d8  
    3232#include "linux/os.h"
    3333#endif
     34
     35#ifdef BITHENGE_FAILURE_ENABLE
     36#include "failure.h"
     37#endif
  • uspace/lib/bithenge/script.c

    r1c79996 ra42d7d8  
    731731                }
    732732                int rc = bithenge_binary_expression(&expr, op, expr, expr2);
    733                 if (rc != EOK)
    734                         error_errno(state, rc);
     733                if (rc != EOK) {
     734                        expr = NULL;
     735                        error_errno(state, rc);
     736                }
    735737        }
    736738        if (state->error != EOK) {
     
    940942                int rc = bithenge_if_transform(&switch_xform, exprs[num],
    941943                    xforms[num], switch_xform);
    942                 if (rc != EOK)
    943                         error_errno(state, rc);
     944                if (rc != EOK) {
     945                        switch_xform = NULL;
     946                        error_errno(state, rc);
     947                }
    944948        }
    945949
     
    11891193                if (state->error != EOK)
    11901194                        break;
    1191                 xforms[num] = parse_transform_no_compose(state);
    1192                 num++;
     1195                xforms[num++] = parse_transform_no_compose(state);
    11931196        }
    11941197        if (state->error != EOK) {
    1195                 while (xforms && num--)
    1196                         bithenge_transform_dec_ref(xforms[num]);
     1198                while (xforms && num > 1)
     1199                        bithenge_transform_dec_ref(xforms[--num]);
    11971200                free(xforms);
    11981201                bithenge_transform_dec_ref(result);
  • uspace/lib/bithenge/sequence.c

    r1c79996 ra42d7d8  
    488488                return rc;
    489489        }
     490
     491        rc = seq_node_init(struct_as_seq(node), &struct_node_seq_ops, inner,
     492            blob, self->num_subtransforms, false);
     493        if (rc != EOK) {
     494                bithenge_scope_dec_ref(inner);
     495                free(node);
     496                return rc;
     497        }
     498
     499        bithenge_transform_inc_ref(struct_as_transform(self));
     500        node->transform = self;
     501        node->prefix = prefix;
     502
    490503        /* We should inc_ref(node) here, but that would make a cycle. Instead,
    491504         * we leave it 1 too low, so that when the only remaining use of node
     
    493506         * struct_node_destroy. */
    494507        bithenge_scope_set_current_node(inner, struct_as_node(node));
    495 
    496         rc = seq_node_init(struct_as_seq(node), &struct_node_seq_ops, inner,
    497             blob, self->num_subtransforms, false);
    498508        bithenge_scope_dec_ref(inner);
    499         if (rc != EOK) {
    500                 free(node);
    501                 return rc;
    502         }
    503 
    504         bithenge_transform_inc_ref(struct_as_transform(self));
    505         node->transform = self;
    506         node->prefix = prefix;
     509
    507510        *out = struct_as_node(node);
    508511
     
    834837                                rc = seq_node_field_offset(
    835838                                    node_as_seq(*out_node), &size, count);
    836                                 if (rc != EOK)
     839                                if (rc == EINVAL || rc == ENOENT)
    837840                                        break;
     841                                if (rc != EOK) {
     842                                        bithenge_node_dec_ref(*out_node);
     843                                        return rc;
     844                                }
    838845                                *out_size = size;
    839846                        }
  • uspace/lib/bithenge/tree.c

    r1c79996 ra42d7d8  
    9090{
    9191        get_for_each_data_t *data = (get_for_each_data_t *)raw_data;
    92         bool equal = bithenge_node_equal(key, data->key);
     92        bool equal;
     93        int rc = bithenge_node_equal(&equal, key, data->key);
    9394        bithenge_node_dec_ref(key);
     95        if (rc != EOK)
     96                return rc;
    9497        if (equal) {
    9598                *data->out = value;
     
    348351 * internal nodes. Takes ownership of nothing.
    349352 * @memberof bithenge_node_t
     353 * @param[out] out Holds whether the nodes are equal.
    350354 * @param a, b Nodes to compare.
    351  * @return Whether the nodes are equal. If an error occurs, returns false.
     355 * @return EOK on success or an error code from errno.h.
    352356 * @todo Add support for internal nodes.
    353357 */
    354 bool bithenge_node_equal(bithenge_node_t *a, bithenge_node_t *b)
    355 {
    356         if (a->type != b->type)
    357                 return false;
     358int bithenge_node_equal(bool *out, bithenge_node_t *a, bithenge_node_t *b)
     359{
     360        if (a->type != b->type) {
     361                *out = false;
     362                return EOK;
     363        }
    358364        switch (a->type) {
    359365        case BITHENGE_NODE_INTERNAL:
    360                 return false;
     366                *out = false;
     367                return EOK;
    361368        case BITHENGE_NODE_BOOLEAN:
    362                 return a->boolean_value == b->boolean_value;
     369                *out = a->boolean_value == b->boolean_value;
     370                return EOK;
    363371        case BITHENGE_NODE_INTEGER:
    364                 return a->integer_value == b->integer_value;
     372                *out = a->integer_value == b->integer_value;
     373                return EOK;
    365374        case BITHENGE_NODE_STRING:
    366                 return !str_cmp(a->string_value.ptr, b->string_value.ptr);
     375                *out = !str_cmp(a->string_value.ptr, b->string_value.ptr);
     376                return EOK;
    367377        case BITHENGE_NODE_BLOB:
    368                 return bithenge_blob_equal(bithenge_node_as_blob(a),
     378                return bithenge_blob_equal(out, bithenge_node_as_blob(a),
    369379                    bithenge_node_as_blob(b));
    370380        }
    371         return false;
     381        return EINVAL;
    372382}
    373383
  • uspace/lib/bithenge/tree.h

    r1c79996 ra42d7d8  
    167167int bithenge_new_integer_node(bithenge_node_t **, bithenge_int_t);
    168168int bithenge_new_string_node(bithenge_node_t **, const char *, bool);
    169 bool bithenge_node_equal(bithenge_node_t *, bithenge_node_t *);
     169int bithenge_node_equal(bool *, bithenge_node_t *, bithenge_node_t *);
    170170
    171171#endif
Note: See TracChangeset for help on using the changeset viewer.