Enable more Travis configurations.

pull/13171/head
Josh Haberman 11 years ago
parent 6ed916653f
commit 3461a5113e
  1. 10
      .travis.yml
  2. 96
      Makefile
  3. 159
      tests/bindings/googlepb/test_vs_proto2.cc
  4. 32
      travis.sh
  5. 2
      upb/pb/compile_decoder_x64.c
  6. 1804
      upb/pb/compile_decoder_x64.h

@ -1,4 +1,6 @@
install:
- sudo apt-get update -qq
- sudo apt-get install protobuf-compiler libprotobuf-dev
script: make test
install: ./travis.sh install
script: ./travis.sh script
env:
- UPB_TRAVIS_BUILD=bare
- UPB_TRAVIS_BUILD=barejit
- UPB_TRAVIS_BUILD=withprotobuf

@ -84,20 +84,20 @@ dep:
clean_leave_profile:
rm -rf obj lib
rm -f benchmark/google_messages.proto.pb benchmark/google_messages.pb.* benchmarks/b.* benchmarks/*.pb*
rm -f $(TESTS) tests/testmain.o tests/t.*
rm -f tests/test.proto.pb
rm -f upb/descriptor.pb
rm -rf tools/upbc deps
rm -rf upb/bindings/python/build
rm -f upb/bindings/ruby/Makefile
rm -f upb/bindings/ruby/upb.so
rm -f upb/bindings/ruby/mkmf.log
find . | grep dSYM | xargs rm -rf
@rm -rf obj lib
@rm -f benchmark/google_messages.proto.pb benchmark/google_messages.pb.* benchmarks/b.* benchmarks/*.pb*
@rm -f $(TESTS) tests/testmain.o tests/t.*
@rm -f tests/test.proto.pb
@rm -f upb/descriptor.pb
@rm -rf tools/upbc deps
@rm -rf upb/bindings/python/build
@rm -f upb/bindings/ruby/Makefile
@rm -f upb/bindings/ruby/upb.so
@rm -f upb/bindings/ruby/mkmf.log
@find . | grep dSYM | xargs rm -rf
clean: clean_leave_profile
rm -rf $(call rwildcard,,*.gcno) $(call rwildcard,,*.gcda)
@rm -rf $(call rwildcard,,*.gcno) $(call rwildcard,,*.gcda)
# A little bit of Make voodoo: you can call this from the deps of a patterned
# rule like so:
@ -146,6 +146,8 @@ upb_pb_SRCS = \
ifdef USE_JIT
upb_pb_SRCS += upb/pb/compile_decoder_x64.c
obj/pb/compile_decoder_x64.o obj/pb/compile_decoder_x64.lo: upb/pb/compile_decoder_x64.h
obj/pb/compile_decoder_x64.o: CFLAGS=-std=gnu99
obj/pb/compile_decoder_x64.o: OPT=-Os
upb/pb/compile_decoder_x64.h: upb/pb/compile_decoder_x64.dasc
$(E) DYNASM $<
@ -161,6 +163,8 @@ ifeq (, $(findstring -O, $(USER_CFLAGS)))
OPT = -O3
lib/libupb.a : OPT = -Os
lib/libupb.descriptor.a : OPT = -Os
obj/pb/compile_decoder.o : OPT = -Os
obj/pb/compile_decoder_64.o : OPT = -Os
endif
$(UPB_PICLIBS): lib/lib%_pic.a: $(call make_objs,lo)
@ -265,7 +269,7 @@ ifeq ($(RUN_UNDER), valgrind)
RUN_UNDER=valgrind --leak-check=full --error-exitcode=1 --track-origins=yes
endif
test: tests
test:
@set -e # Abort on error.
@find tests -perm -u+x -type f | while read test; do \
if [ -x ./$$test ] ; then \
@ -289,50 +293,65 @@ GOOGLEPB_TESTS = \
GOOGLEPB_LIB=lib/libupb.bindings.googlepb.a
.PHONY: googlepb clean_googlepb googlepbtest
clean: clean_googlepb
clean_googlepb:
rm -f tests/bindings/googlepb/test_vs_proto2.googlemessage*
rm -f $(GOOGLEPB_LIB)
@rm -f tests/bindings/googlepb/test_vs_proto2.googlemessage*
@rm -f benchmarks/googlemessage?.h
@rm -f $(GOOGLEPB_LIB)
googlepb: default $(GOOGLEPB_LIB)
googlepbtest: $(GOOGLEPB_TESTS)
googlepbtests: googlepb $(GOOGLEPB_TESTS)
lib/libupb.bindings.googlepb.a: $(upb_bindings_googlepb_SRCS:upb/%.cc=obj/%.o)
$(E) AR $@
$(Q) mkdir -p lib && ar rcs $@ $^
# These generated files live in benchmarks/ but are used by both tests and
# benchmarks.
# Generate C++ with Google's protobuf compiler, to test and benchmark against.
benchmarks/google_messages.proto.pb: benchmarks/google_messages.proto
@# TODO: replace with upbc.
protoc benchmarks/google_messages.proto -obenchmarks/google_messages.proto.pb
benchmarks/google_messages.pb.cc: benchmarks/google_messages.proto
protoc benchmarks/google_messages.proto --cpp_out=.
tests/bindings/googlepb/test_vs_proto2.googlemessage1: \
tests/bindings/googlepb/test_vs_proto2.cc $(LIBUPB) benchmarks/google_messages.proto.pb \
benchmarks/google_messages.pb.cc
benchmarks/googlemessage1.h:
$(E) XXD benchmarks/google_message1.dat
$(Q) xxd -i < benchmarks/google_message1.dat > benchmarks/googlemessage1.h
benchmarks/googlemessage2.h:
$(E) XXD benchmarks/google_message2.dat
$(Q) xxd -i < benchmarks/google_message2.dat > benchmarks/googlemessage2.h
GOOGLEPB_TEST_LIBS = \
lib/libupb.bindings.googlepb.a \
lib/libupb.pb.a \
lib/libupb.descriptor.a \
lib/libupb.a
GOOGLEPB_TEST_DEPS = \
tests/bindings/googlepb/test_vs_proto2.cc \
benchmarks/google_messages.proto.pb \
benchmarks/google_messages.pb.cc \
tests/testmain.o \
$(GOOGLEPB_TEST_LIBS)
tests/bindings/googlepb/test_vs_proto2.googlemessage1: $(GOOGLEPB_TEST_DEPS) \
benchmarks/googlemessage1.h
$(E) CXX $< '(benchmarks::SpeedMessage1)'
$(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $< \
-DMESSAGE_NAME=\"benchmarks.SpeedMessage1\" \
-DMESSAGE_DESCRIPTOR_FILE=\"../benchmarks/google_messages.proto.pb\" \
-DMESSAGE_FILE=\"../benchmarks/google_message1.dat\" \
-DMESSAGE_CIDENT="benchmarks::SpeedMessage1" \
-DMESSAGE_HFILE=\"../benchmarks/google_messages.pb.h\" \
-DMESSAGE_DATA_HFILE=\"benchmarks/googlemessage1.h\" \
benchmarks/google_messages.pb.cc tests/testmain.o -lprotobuf -lpthread \
lib/libupb.bindings.googlepb.a lib/libupb.pb.a lib/libupb.descriptor.a lib/libupb.a
$(GOOGLEPB_TEST_LIBS)
tests/bindings/googlepb/test_vs_proto2.googlemessage2: \
tests/bindings/googlepb/test_vs_proto2.cc $(LIBUPB) benchmarks/google_messages.proto.pb \
benchmarks/google_messages.pb.cc
tests/bindings/googlepb/test_vs_proto2.googlemessage2: $(GOOGLEPB_TEST_DEPS) \
benchmarks/googlemessage2.h
$(E) CXX $< '(benchmarks::SpeedMessage2)'
$(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $< \
-DMESSAGE_NAME=\"benchmarks.SpeedMessage2\" \
-DMESSAGE_DESCRIPTOR_FILE=\"../benchmarks/google_messages.proto.pb\" \
-DMESSAGE_FILE=\"../benchmarks/google_message2.dat\" \
-DMESSAGE_CIDENT="benchmarks::SpeedMessage2" \
-DMESSAGE_HFILE=\"../benchmarks/google_messages.pb.h\" \
-DMESSAGE_DATA_HFILE=\"benchmarks/googlemessage2.h\" \
benchmarks/google_messages.pb.cc tests/testmain.o -lprotobuf -lpthread \
lib/libupb.bindings.googlepb.a lib/libupb.pb.a lib/libupb.descriptor.a lib/libupb.a
$(GOOGLEPB_TEST_LIBS)
# Lua extension ##################################################################
@ -348,14 +367,15 @@ LUAEXTS = \
upb/bindings/lua/upb.pb.so \
.PHONY: clean_lua testlua lua
clean: clean_lua
testlua:
LUA_PATH=tests/bindings/lua/?.lua LUA_CPATH=upb/bindings/lua/?.so lua tests/bindings/lua/upb.lua
clean: clean_lua
clean_lua:
rm -f upb/bindings/lua/upb.lua.h
rm -f upb/bindings/lua/upb.so
rm -f upb/bindings/lua/upb.pb.so
@rm -f upb/bindings/lua/upb.lua.h
@rm -f upb/bindings/lua/upb.so
@rm -f upb/bindings/lua/upb.pb.so
lua: $(LUAEXTS)

@ -0,0 +1,159 @@
/*
* upb - a minimalist implementation of protocol buffers.
*
* Copyright (c) 2011-2012 Google Inc. See LICENSE for details.
*
* A test that verifies that our results are identical to proto2 for a
* given proto type and input protobuf.
*/
#define __STDC_LIMIT_MACROS // So we get UINT32_MAX
#include <assert.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>
#include <google/protobuf/wire_format_lite.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "benchmarks/google_messages.pb.h"
#include "tests/upb_test.h"
#include "upb/bindings/googlepb/bridge.h"
#include "upb/def.h"
#include "upb/handlers.h"
#include "upb/pb/decoder.h"
#include "upb/pb/glue.h"
#include "upb/pb/varint.int.h"
static const char message_data[] = {
#include MESSAGE_DATA_HFILE
};
void compare_metadata(const google::protobuf::Descriptor* d,
const upb::MessageDef *upb_md) {
ASSERT(d->field_count() == upb_md->field_count());
for (upb::MessageDef::const_iterator i = upb_md->begin(); i != upb_md->end();
++i) {
const upb::FieldDef* upb_f = *i;
const google::protobuf::FieldDescriptor *proto2_f =
d->FindFieldByNumber(upb_f->number());
ASSERT(upb_f);
ASSERT(proto2_f);
ASSERT(upb_f->number() == proto2_f->number());
ASSERT(std::string(upb_f->name()) == proto2_f->name());
ASSERT(upb_f->descriptor_type() ==
static_cast<upb::FieldDef::DescriptorType>(proto2_f->type()));
ASSERT(upb_f->IsSequence() == proto2_f->is_repeated());
}
}
void print_diff(const google::protobuf::Message& msg1,
const google::protobuf::Message& msg2) {
std::string text_str1;
std::string text_str2;
google::protobuf::TextFormat::PrintToString(msg1, &text_str1);
google::protobuf::TextFormat::PrintToString(msg2, &text_str2);
fprintf(stderr, "str1: %s, str2: %s\n", text_str1.c_str(), text_str2.c_str());
}
void parse_and_compare(google::protobuf::Message *msg1,
google::protobuf::Message *msg2,
const upb::Handlers *protomsg_handlers,
const char *str, size_t len, bool allow_jit) {
// Parse to both proto2 and upb.
ASSERT(msg1->ParseFromArray(str, len));
upb::pb::CodeCache cache;
ASSERT(cache.set_allow_jit(allow_jit));
upb::reffed_ptr<const upb::pb::DecoderMethod> decoder_method(
cache.GetDecoderMethod(upb::pb::DecoderMethodOptions(protomsg_handlers)));
upb::Status status;
upb::pb::Decoder decoder(decoder_method.get(), &status);
upb::Sink protomsg_sink(protomsg_handlers, msg2);
decoder.ResetOutput(&protomsg_sink);
msg2->Clear();
bool ok = upb::BufferSource::PutBuffer(str, len, decoder.input());
if (!ok) {
fprintf(stderr, "error parsing: %s\n", status.error_message());
print_diff(*msg1, *msg2);
}
ASSERT(ok);
ASSERT(status.ok());
// Would like to just compare the message objects themselves, but
// unfortunately MessageDifferencer is not part of the open-source release of
// proto2, so we compare their serialized strings, which we expect will be
// equivalent.
std::string str1;
std::string str2;
msg1->SerializeToString(&str1);
msg2->SerializeToString(&str2);
if (str1 != str2) {
print_diff(*msg1, *msg2);
}
ASSERT(str1 == str2);
ASSERT(std::string(str, len) == str2);
}
void test_zig_zag() {
for (uint64_t num = 5; num * 1.5 < UINT64_MAX; num *= 1.5) {
ASSERT(upb_zzenc_64(num) ==
google::protobuf::internal::WireFormatLite::ZigZagEncode64(num));
if (num < UINT32_MAX) {
ASSERT(upb_zzenc_32(num) ==
google::protobuf::internal::WireFormatLite::ZigZagEncode32(num));
}
}
}
extern "C" {
int run_tests(int argc, char *argv[]) {
UPB_UNUSED(argc);
UPB_UNUSED(argv);
size_t len = sizeof(message_data);
const char *str = message_data;
MESSAGE_CIDENT msg1;
MESSAGE_CIDENT msg2;
upb::reffed_ptr<const upb::Handlers> h(
upb::googlepb::WriteHandlers::New(msg1));
compare_metadata(msg1.GetDescriptor(), h->message_def());
// Run twice to test proper object reuse.
parse_and_compare(&msg1, &msg2, h.get(), str, len, false);
parse_and_compare(&msg1, &msg2, h.get(), str, len, true);
parse_and_compare(&msg1, &msg2, h.get(), str, len, false);
parse_and_compare(&msg1, &msg2, h.get(), str, len, true);
// Test with DynamicMessage.
google::protobuf::DynamicMessageFactory* factory =
new google::protobuf::DynamicMessageFactory;
const google::protobuf::Message* prototype =
factory->GetPrototype(msg1.descriptor());
google::protobuf::Message* dyn_msg1 = prototype->New();
google::protobuf::Message* dyn_msg2 = prototype->New();
h = upb::googlepb::WriteHandlers::New(*dyn_msg1);
parse_and_compare(dyn_msg1, dyn_msg2, h.get(), str, len, false);
parse_and_compare(dyn_msg1, dyn_msg2, h.get(), str, len, true);
delete dyn_msg1;
delete dyn_msg2;
delete factory;
test_zig_zag();
printf("All tests passed, %d assertions.\n", num_assertions);
google::protobuf::ShutdownProtobufLibrary();
return 0;
}
}

@ -0,0 +1,32 @@
#!/bin/bash
# Bare build: no dependencies installed, no JIT enabled.
bare_install() {
:
}
bare_script() {
make -j12 tests && make test
}
# Bare JIT build: no dependencies installed, but JIT enabled.
barejit_install() {
:
}
barejit_script() {
make -j12 tests WITH_JIT=yes && make test
}
# Build with Google protobuf support and tests (with JIT).
withprotobuf_install() {
sudo apt-get update -qq
sudo apt-get install protobuf-compiler libprotobuf-dev
}
withprotobuf_script() {
make -j12 tests googlepbtests WITH_JIT=yes
make test
}
set -e
set -x
eval ${UPB_TRAVIS_BUILD}_${1}

@ -220,7 +220,7 @@ static bool try_getjmptarget(jitcompiler *jc, const void *key, int *pclabel) {
// Gets the pclabel for this bytecode location's jmptarget. Requires that the
// jmptarget() has been previously defined.
static int getjmptarget(jitcompiler *jc, const void *key) {
int pclabel;
int pclabel = 0;
assert(upb_inttable_lookupptr(&jc->jmpdefined, key, NULL));
bool ok = try_getjmptarget(jc, key, &pclabel);
UPB_ASSERT_VAR(ok, ok);

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save