From a1a9596d02f5297d60448edac994c2bcb56edc4a Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 21 Jul 2009 17:36:02 -0700 Subject: Fix tests and the build (though a few tests are failing). --- Makefile | 15 ++++++--------- tests/tests.c | 45 +++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 3d4642d..2ee0ff6 100644 --- a/Makefile +++ b/Makefile @@ -3,14 +3,15 @@ CC=gcc CXX=g++ CFLAGS=-std=c99 -CPPFLAGS=-O0 -Wall -Wextra -pedantic -g -DUPB_UNALIGNED_READS_OK -DNDEBUG -Idescriptor -Isrc -Itests -I. +INCLUDE=-Idescriptor -Isrc -Itests -I. +CPPFLAGS=-O3 -fomit-frame-pointer -Wall -Wextra -g -DUPB_UNALIGNED_READS_OK -DNDEBUG $(INCLUDE) OBJ=src/upb_parse.o src/upb_table.o src/upb_msg.o src/upb_enum.o src/upb_context.o \ - src/upb_string.o descriptor/descriptor.o -SRC=src/*.c src/*.h descriptor/*.c descriptor/*.h tests/*.c tests/*.h tools/*.c tools/*.h + src/upb_string.o src/upb_text.o descriptor/descriptor.o +SRC=src/*.c src/*.h descriptor/*.c descriptor/*.h tests/*.c tests/*.h tools/*.c ALL=$(OBJ) src/libupb.a tests/test_table tests/tests tools/upbc benchmark/benchmark all: $(ALL) clean: - rm -f $(ALL) deps benchmark/google_messages.proto.pb benchmark/google_messages.pb.* + rm -f $(ALL) benchmark/google_messages.proto.pb benchmark/google_messages.pb.* src/libupb.a: $(OBJ) ar rcs src/libupb.a $(OBJ) @@ -18,9 +19,5 @@ tests/test_table: src/libupb.a tools/upbc: src/libupb.a benchmark/benchmark: src/libupb.a benchmark/google_messages.pb.h benchmark/google_messages.pb.o benchmark/benchmark.o $(CXX) $(CPPFLAGS) -o benchmark/benchmark benchmark/google_messages.pb.o benchmark/benchmark.cc src/libupb.a -lm -lprotobuf -lpthread -benchmark/google_messages.pb.h benchmark/google_messages.pb: benchmark/google_messages.proto +benchmark/google_messages.pb.cc benchmark/google_messages.pb.h benchmark/google_messages.pb: benchmark/google_messages.proto protoc benchmark/google_messages.proto --cpp_out=. -obenchmark/google_messages.proto.pb - --include deps -deps: $(SRC) - gcc -MM $(SRC) > deps diff --git a/tests/tests.c b/tests/tests.c index 81f09f0..79d891a 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -21,9 +21,9 @@ static void test_get_v_uint64_t() #define TEST(name, bytes, val) {\ upb_status_t status; \ uint8_t name[] = bytes; \ - void *name ## _buf = name; \ + uint8_t *name ## _buf = name; \ uint64_t name ## _val = 0; \ - status = get_v_uint64_t(&name ## _buf, name + sizeof(name), &name ## _val); \ + status = get_v_uint64_t(name ## _buf, name + sizeof(name), &name ## _val, &name ## _buf); \ ASSERT(status == UPB_STATUS_OK); \ ASSERT(name ## _val == val); \ ASSERT(name ## _buf == name + sizeof(name) - 1); /* - 1 for NULL */ \ @@ -42,14 +42,14 @@ static void test_get_v_uint64_t() TEST(tenb, "\x81\x83\x87\x8f\x9f\xbf\xff\x81\x83\x07", 0x8303fdf9f1e1c181ULL); uint8_t elevenbyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01}; - void *elevenbyte_buf = elevenbyte; + uint8_t *elevenbyte_buf = elevenbyte; uint64_t elevenbyte_val = 0; - upb_status_t status = get_v_uint64_t(&elevenbyte_buf, elevenbyte + sizeof(elevenbyte), &elevenbyte_val); + upb_status_t status = get_v_uint64_t(elevenbyte_buf, elevenbyte + sizeof(elevenbyte), &elevenbyte_val, &elevenbyte_buf); ASSERT(status == UPB_ERROR_UNTERMINATED_VARINT); - status = get_v_uint64_t(&elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-1, &elevenbyte_val); + status = get_v_uint64_t(elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-1, &elevenbyte_val, &elevenbyte_buf); /* Byte 10 is 0x80, so we know it's unterminated. */ ASSERT(status == UPB_ERROR_UNTERMINATED_VARINT); - status = get_v_uint64_t(&elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-2, &elevenbyte_val); + status = get_v_uint64_t(elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-2, &elevenbyte_val, &elevenbyte_buf); ASSERT(status == UPB_STATUS_NEED_MORE_DATA); #undef TEST } @@ -59,9 +59,9 @@ static void test_get_v_uint32_t() #define TEST(name, bytes, val) {\ upb_status_t status; \ uint8_t name[] = bytes; \ - void *name ## _buf = name; \ + uint8_t *name ## _buf = name; \ uint32_t name ## _val = 0; \ - status = get_v_uint32_t(&name ## _buf, name + sizeof(name), &name ## _val); \ + status = get_v_uint32_t(name ## _buf, name + sizeof(name), &name ## _val, &name ## _buf); \ ASSERT(status == UPB_STATUS_OK); \ ASSERT(name ## _val == val); \ ASSERT(name ## _buf == name + sizeof(name) - 1); /* - 1 for NULL */ \ @@ -81,14 +81,14 @@ static void test_get_v_uint32_t() TEST(tenb, "\x81\x83\x87\x8f\x9f\xbf\xff\x81\x83\x07", 0xf1e1c181UL); uint8_t elevenbyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01}; - void *elevenbyte_buf = elevenbyte; + uint8_t *elevenbyte_buf = elevenbyte; uint64_t elevenbyte_val = 0; - upb_status_t status = get_v_uint64_t(&elevenbyte_buf, elevenbyte + sizeof(elevenbyte), &elevenbyte_val); + upb_status_t status = get_v_uint64_t(elevenbyte_buf, elevenbyte + sizeof(elevenbyte), &elevenbyte_val, &elevenbyte_buf); ASSERT(status == UPB_ERROR_UNTERMINATED_VARINT); - status = get_v_uint64_t(&elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-1, &elevenbyte_val); + status = get_v_uint64_t(elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-1, &elevenbyte_val, &elevenbyte_buf); /* Byte 10 is 0x80, so we know it's unterminated. */ ASSERT(status == UPB_ERROR_UNTERMINATED_VARINT); - status = get_v_uint64_t(&elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-2, &elevenbyte_val); + status = get_v_uint64_t(elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-2, &elevenbyte_val, &elevenbyte_buf); ASSERT(status == UPB_STATUS_NEED_MORE_DATA); #undef TEST } @@ -98,8 +98,8 @@ static void test_skip_v_uint64_t() #define TEST(name, bytes) {\ upb_status_t status; \ uint8_t name[] = bytes; \ - void *name ## _buf = name; \ - status = skip_v_uint64_t(&name ## _buf, name + sizeof(name)); \ + uint8_t *name ## _buf = name; \ + status = skip_v_uint64_t(name ## _buf, name + sizeof(name), &name ## _buf); \ ASSERT(status == UPB_STATUS_OK); \ ASSERT(name ## _buf == name + sizeof(name) - 1); /* - 1 for NULL */ \ } @@ -117,13 +117,14 @@ static void test_skip_v_uint64_t() TEST(tenb, "\x81\x83\x87\x8f\x9f\xbf\xff\x81\x83\x07"); uint8_t elevenbyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01}; - void *elevenbyte_buf = elevenbyte; - upb_status_t status = skip_v_uint64_t(&elevenbyte_buf, elevenbyte + sizeof(elevenbyte)); + uint8_t *elevenbyte_buf = elevenbyte; + upb_status_t status = skip_v_uint64_t(elevenbyte_buf, elevenbyte + sizeof(elevenbyte), &elevenbyte_buf); + printf("%d\n", status); ASSERT(status == UPB_ERROR_UNTERMINATED_VARINT); - status = skip_v_uint64_t(&elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-1); + status = skip_v_uint64_t(elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-1, &elevenbyte_buf); /* Byte 10 is 0x80, so we know it's unterminated. */ ASSERT(status == UPB_ERROR_UNTERMINATED_VARINT); - status = skip_v_uint64_t(&elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-2); + status = skip_v_uint64_t(elevenbyte_buf, elevenbyte + sizeof(elevenbyte)-2, &elevenbyte_buf); ASSERT(status == UPB_STATUS_NEED_MORE_DATA); #undef TEST } @@ -133,9 +134,9 @@ static void test_get_f_uint32_t() #define TEST(name, bytes, val) {\ upb_status_t status; \ uint8_t name[] = bytes; \ - void *name ## _buf = name; \ + uint8_t *name ## _buf = name; \ uint32_t name ## _val = 0; \ - status = get_f_uint32_t(&name ## _buf, name + sizeof(name), &name ## _val); \ + status = get_f_uint32_t(name ## _buf, name + sizeof(name), &name ## _val, &name ## _buf); \ ASSERT(status == UPB_STATUS_OK); \ ASSERT(name ## _val == val); \ ASSERT(name ## _buf == name + sizeof(name) - 1); /* - 1 for NULL */ \ @@ -145,9 +146,9 @@ static void test_get_f_uint32_t() TEST(one, "\x01\x00\x00\x00", 0x1UL); uint8_t threeb[] = {0x00, 0x00, 0x00}; - void *threeb_buf = threeb; + uint8_t *threeb_buf = threeb; uint32_t threeb_val; - upb_status_t status = get_f_uint32_t(&threeb_buf, threeb + sizeof(threeb), &threeb_val); + upb_status_t status = get_f_uint32_t(threeb_buf, threeb + sizeof(threeb), &threeb_val, &threeb_buf); ASSERT(status == UPB_STATUS_NEED_MORE_DATA); #undef TEST -- cgit v1.2.3