Changeset 1c79996 in mainline


Ignore:
Timestamp:
2012-08-18T23:20:48Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a42d7d8
Parents:
1f9c9a4
Message:

Bithenge: fix issues and expand coverage for test.sh

Location:
uspace
Files:
8 added
6 edited
9 moved

Legend:

Unmodified
Added
Removed
  • uspace/dist/src/bithenge/fat.bh

    r1f9c9a4 r1c79996  
    7676        .size_shown <- if (.size > 32) { (32) } else { (.size) };
    7777
    78         if (.start != 0 && .start != self_start && .start != parent) {
     78        if (.start != 0 && .start != self_start && .start != parent && .filename[0] != 229) {
    7979                .data
    8080                    <- if (.attrs.subdirectory) {
  • uspace/dist/src/bithenge/repeat.bh

    r1f9c9a4 r1c79996  
    2424        .without_count <- without_count <- known_length(9);
    2525        .do_while <- do_while;
     26        .do_while_item <- (.do_while[1]);
    2627};
  • uspace/dist/src/bithenge/repeat.out

    r1f9c9a4 r1c79996  
    4141            "val": 9
    4242        }
     43    },
     44    "do_while_item": {
     45        "valid": True,
     46        "val": 4
    4347    }
    4448}
  • uspace/dist/src/bithenge/test.sh

    r1f9c9a4 r1c79996  
    1212fi
    1313
     14test_file() {
     15        echo "Testing $1 on $2..."
     16        ${BITHENGE} $1 $2 2>&1|diff $3 -
     17}
     18
    1419for BH in *.bh
    1520do
     
    1924                [ -e ${DAT} ] || continue
    2025                [ -e ${OUT} ] || continue
    21                 echo "Testing ${BH} on ${DAT}..."
    22                 ${BITHENGE} ${BH} ${DAT} 2>&1|diff ${OUT} -
     26                test_file ${BH} ${DAT} ${OUT}
    2327        done
    2428done
    2529
     30test_file trip.bh file:trip.dat trip.out
     31test_file repeat.bh hex:7f07020305070b0D11020004000800102040010101040009 repeat.out
     32
    2633echo "Done!"
  • uspace/lib/bithenge/expression.c

    r1f9c9a4 r1c79996  
    10661066                if (rc != EOK)
    10671067                        return rc;
    1068                 b_size = offset + *size - self->a_size;
     1068                b_size = *size - a_size;
     1069                assert(a_size % 8 == 0); /* TODO: don't require this */
    10691070                rc = bithenge_blob_read_bits(self->b,
    1070                     offset + a_size - self->a_size, buffer + a_size, &b_size,
    1071                     little_endian);
     1071                    offset + a_size - self->a_size, buffer + a_size / 8,
     1072                    &b_size, little_endian);
    10721073                if (rc != EOK)
    10731074                        return rc;
  • uspace/lib/bithenge/sequence.c

    r1f9c9a4 r1c79996  
    915915typedef struct {
    916916        seq_node_t base;
    917         bool prefix;
    918917        bithenge_expression_t *expr;
    919918        bithenge_transform_t *xform;
     
    995994        }
    996995
    997         if (!self->prefix) {
    998                 bool complete;
    999                 rc = seq_node_complete(do_while_as_seq(self), &complete);
    1000                 if (rc != EOK)
    1001                         return rc;
    1002                 if (!complete)
    1003                         return EINVAL;
    1004         }
    1005 
    1006996        return rc;
    1007997}
     
    10351025
    10361026static int do_while_transform_make_node(do_while_transform_t *self,
    1037     bithenge_node_t **out, bithenge_scope_t *scope, bithenge_blob_t *blob,
    1038     bool prefix)
     1027    bithenge_node_t **out, bithenge_scope_t *scope, bithenge_blob_t *blob)
    10391028{
    10401029        do_while_node_t *node = malloc(sizeof(*node));
     
    10601049        bithenge_expression_inc_ref(self->expr);
    10611050        node->expr = self->expr;
    1062         node->prefix = prefix;
    10631051        node->count = -1;
    10641052        *out = do_while_as_node(node);
    10651053        return EOK;
    1066 }
    1067 
    1068 static int do_while_transform_apply(bithenge_transform_t *base,
    1069     bithenge_scope_t *scope, bithenge_node_t *in, bithenge_node_t **out)
    1070 {
    1071         do_while_transform_t *self = transform_as_do_while(base);
    1072         if (bithenge_node_type(in) != BITHENGE_NODE_BLOB)
    1073                 return EINVAL;
    1074         return do_while_transform_make_node(self, out, scope,
    1075             bithenge_node_as_blob(in), false);
    10761054}
    10771055
     
    10891067{
    10901068        do_while_transform_t *self = transform_as_do_while(base);
    1091         int rc = do_while_transform_make_node(self, out_node, scope, blob,
    1092             true);
     1069        int rc = do_while_transform_make_node(self, out_node, scope, blob);
    10931070        if (rc != EOK)
    10941071                return rc;
     
    11211098
    11221099static const bithenge_transform_ops_t do_while_transform_ops = {
    1123         .apply = do_while_transform_apply,
    11241100        .prefix_apply = do_while_transform_prefix_apply,
    11251101        .destroy = do_while_transform_destroy,
  • uspace/lib/bithenge/transform.c

    r1f9c9a4 r1c79996  
    892892MAKE_UINT_TRANSFORM(uint32le, uint32_t, uint32_t_le2host, prefix_length_4);
    893893MAKE_UINT_TRANSFORM(uint32be, uint32_t, uint32_t_be2host, prefix_length_4);
    894 MAKE_UINT_TRANSFORM(uint64le, uint64_t, uint32_t_le2host, prefix_length_8);
    895 MAKE_UINT_TRANSFORM(uint64be, uint64_t, uint32_t_be2host, prefix_length_8);
     894MAKE_UINT_TRANSFORM(uint64le, uint64_t, uint64_t_le2host, prefix_length_8);
     895MAKE_UINT_TRANSFORM(uint64be, uint64_t, uint64_t_be2host, prefix_length_8);
    896896
    897897
  • uspace/lib/bithenge/tree.c

    r1f9c9a4 r1c79996  
    102102/** Get a child of a node. Takes ownership of the key. If the node does not
    103103 * provide this function, for_each will be used as an alternative, which may be
    104  * very slow.
    105  * @memberof bithenge_node_t
    106  * @param self The internal node to find a child of.
     104 * very slow. Also works for blob nodes to find the byte value at a given
     105 * index.
     106 * @memberof bithenge_node_t
     107 * @param self The internal/blob node to find a child of.
    107108 * @param key The key to search for.
    108109 * @param[out] out Holds the found node.
     
    112113    bithenge_node_t **out)
    113114{
     115        if (self->type == BITHENGE_NODE_BLOB) {
     116                if (bithenge_node_type(key) != BITHENGE_NODE_INTEGER) {
     117                        bithenge_node_dec_ref(key);
     118                        return ENOENT;
     119                }
     120                bithenge_int_t offset = bithenge_integer_node_value(key);
     121                bithenge_node_dec_ref(key);
     122                uint8_t byte;
     123                aoff64_t size = 1;
     124                int rc = bithenge_blob_read(bithenge_node_as_blob(self),
     125                    offset, (char *)&byte, &size);
     126                if (rc != EOK)
     127                        return rc;
     128                if (size != 1)
     129                        return ENOENT;
     130
     131                return bithenge_new_integer_node(out, byte);
     132        }
     133
    114134        assert(self->type == BITHENGE_NODE_INTERNAL);
    115135        if (self->internal_ops->get)
Note: See TracChangeset for help on using the changeset viewer.