Add a test for circularly-linked descriptors.

The test currently triggers valgrind-detected memory errors.
pull/13171/head
Joshua Haberman 15 years ago
parent 651c92ab33
commit 08b4a91204
  1. 7
      Makefile
  2. 5
      src/upb_def.c
  3. 4
      tests/test_vs_proto2.cc
  4. 15
      tests/tests.c
  5. 2
      tools/upbc.c

@ -74,10 +74,15 @@ python: $(LIBUPB_PIC)
cd lang_ext/python && python setup.py build
# Tests
tests/test.proto.pb: tests/test.proto
# TODO: replace with upbc
protoc tests/test.proto -otests/test.proto.pb
tests: tests/tests \
tests/test_table \
tests/t.test_vs_proto2.googlemessage1 \
tests/t.test_vs_proto2.googlemessage2
tests/t.test_vs_proto2.googlemessage2 \
tests/test.proto.pb
#VALGRIND=valgrind --leak-check=full --error-exitcode=1
VALGRIND=

@ -27,8 +27,9 @@ static int div_round_up(int numerator, int denominator) {
//
// Our scheme is as follows. First we give each def a flag indicating whether
// it is part of a cycle or not. Because defs are immutable, this flag will
// never change. For acyclic defs, we can use a naive algorithm and avoid
// the overhead of dealing with cycles. Most defs will be acyclic.
// never change. For acyclic defs, we can use a naive algorithm and avoid the
// overhead of dealing with cycles. Most defs will be acyclic, and most cycles
// will be very short.
//
// For defs that participate in cycles we keep two reference counts. One
// tracks references that come from outside the cycle (we call these external

@ -131,8 +131,8 @@ void compare(const google::protobuf::Message& proto2_msg,
const google::protobuf::Descriptor *d = proto2_msg.GetDescriptor();
struct upb_msgdef *def = upb_msg->def;
ASSERT((uint32_t)d->field_count() == def->num_fields);
for(uint32_t i = 0; i < def->num_fields; i++) {
ASSERT((upb_field_count_t)d->field_count() == def->num_fields);
for(upb_field_count_t i = 0; i < def->num_fields; i++) {
struct upb_fielddef *upb_f = &def->fields[i];
const google::protobuf::FieldDescriptor *proto2_f =
d->FindFieldByNumber(upb_f->number);

@ -228,9 +228,18 @@ static void test_get_f_uint32_t()
}
static void test_upb_symtab() {
struct upb_symtab *c = upb_symtab_new();
ASSERT(c);
upb_symtab_unref(c);
struct upb_symtab *s = upb_symtab_new();
ASSERT(s);
struct upb_string *descriptor = upb_strreadfile("tests/test.proto.pb");
if(!descriptor) {
fprintf(stderr, "Couldn't read input file tests/test.proto.pb\n");
exit(1);
}
struct upb_status status = UPB_STATUS_INIT;
upb_symtab_add_desc(s, descriptor, &status);
ASSERT(upb_ok(&status));
upb_string_unref(descriptor);
upb_symtab_unref(s);
}

@ -708,6 +708,7 @@ int main(int argc, char *argv[])
int symcount;
struct upb_def **defs = upb_symtab_getandref_defs(s, &symcount);
upb_symtab_unref(s);
write_h(defs, symcount, h_filename, cident, h_file);
write_const_h(defs, symcount, h_filename, h_const_file);
for (int i = 0; i < symcount; i++) upb_def_unref(defs[i]);
@ -719,7 +720,6 @@ int main(int argc, char *argv[])
fclose(c_file);
}
upb_msg_unref(fds_msg);
upb_symtab_unref(s);
upb_string_unref(descriptor);
fclose(h_file);
fclose(h_const_file);

Loading…
Cancel
Save