Fix tests and the build (though a few tests are failing).

pull/13171/head
Joshua Haberman 16 years ago
parent 40e8127a24
commit a1a9596d02
  1. 15
      Makefile
  2. 45
      tests/tests.c

@ -3,14 +3,15 @@
CC=gcc CC=gcc
CXX=g++ CXX=g++
CFLAGS=-std=c99 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 \ 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/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 tools/*.h 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=$(OBJ) src/libupb.a tests/test_table tests/tests tools/upbc benchmark/benchmark
all: $(ALL) all: $(ALL)
clean: 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) src/libupb.a: $(OBJ)
ar rcs 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 tools/upbc: src/libupb.a
benchmark/benchmark: src/libupb.a benchmark/google_messages.pb.h benchmark/google_messages.pb.o benchmark/benchmark.o 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 $(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 protoc benchmark/google_messages.proto --cpp_out=. -obenchmark/google_messages.proto.pb
-include deps
deps: $(SRC)
gcc -MM $(SRC) > deps

@ -21,9 +21,9 @@ static void test_get_v_uint64_t()
#define TEST(name, bytes, val) {\ #define TEST(name, bytes, val) {\
upb_status_t status; \ upb_status_t status; \
uint8_t name[] = bytes; \ uint8_t name[] = bytes; \
void *name ## _buf = name; \ uint8_t *name ## _buf = name; \
uint64_t name ## _val = 0; \ 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(status == UPB_STATUS_OK); \
ASSERT(name ## _val == val); \ ASSERT(name ## _val == val); \
ASSERT(name ## _buf == name + sizeof(name) - 1); /* - 1 for NULL */ \ 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); 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}; 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; 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); 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. */ /* Byte 10 is 0x80, so we know it's unterminated. */
ASSERT(status == UPB_ERROR_UNTERMINATED_VARINT); 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); ASSERT(status == UPB_STATUS_NEED_MORE_DATA);
#undef TEST #undef TEST
} }
@ -59,9 +59,9 @@ static void test_get_v_uint32_t()
#define TEST(name, bytes, val) {\ #define TEST(name, bytes, val) {\
upb_status_t status; \ upb_status_t status; \
uint8_t name[] = bytes; \ uint8_t name[] = bytes; \
void *name ## _buf = name; \ uint8_t *name ## _buf = name; \
uint32_t name ## _val = 0; \ 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(status == UPB_STATUS_OK); \
ASSERT(name ## _val == val); \ ASSERT(name ## _val == val); \
ASSERT(name ## _buf == name + sizeof(name) - 1); /* - 1 for NULL */ \ 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); 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}; 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; 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); 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. */ /* Byte 10 is 0x80, so we know it's unterminated. */
ASSERT(status == UPB_ERROR_UNTERMINATED_VARINT); 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); ASSERT(status == UPB_STATUS_NEED_MORE_DATA);
#undef TEST #undef TEST
} }
@ -98,8 +98,8 @@ static void test_skip_v_uint64_t()
#define TEST(name, bytes) {\ #define TEST(name, bytes) {\
upb_status_t status; \ upb_status_t status; \
uint8_t name[] = bytes; \ uint8_t name[] = bytes; \
void *name ## _buf = name; \ uint8_t *name ## _buf = name; \
status = skip_v_uint64_t(&name ## _buf, name + sizeof(name)); \ status = skip_v_uint64_t(name ## _buf, name + sizeof(name), &name ## _buf); \
ASSERT(status == UPB_STATUS_OK); \ ASSERT(status == UPB_STATUS_OK); \
ASSERT(name ## _buf == name + sizeof(name) - 1); /* - 1 for NULL */ \ 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"); 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}; uint8_t elevenbyte[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01};
void *elevenbyte_buf = elevenbyte; uint8_t *elevenbyte_buf = elevenbyte;
upb_status_t status = skip_v_uint64_t(&elevenbyte_buf, elevenbyte + sizeof(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); 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. */ /* Byte 10 is 0x80, so we know it's unterminated. */
ASSERT(status == UPB_ERROR_UNTERMINATED_VARINT); 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); ASSERT(status == UPB_STATUS_NEED_MORE_DATA);
#undef TEST #undef TEST
} }
@ -133,9 +134,9 @@ static void test_get_f_uint32_t()
#define TEST(name, bytes, val) {\ #define TEST(name, bytes, val) {\
upb_status_t status; \ upb_status_t status; \
uint8_t name[] = bytes; \ uint8_t name[] = bytes; \
void *name ## _buf = name; \ uint8_t *name ## _buf = name; \
uint32_t name ## _val = 0; \ 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(status == UPB_STATUS_OK); \
ASSERT(name ## _val == val); \ ASSERT(name ## _val == val); \
ASSERT(name ## _buf == name + sizeof(name) - 1); /* - 1 for NULL */ \ 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); TEST(one, "\x01\x00\x00\x00", 0x1UL);
uint8_t threeb[] = {0x00, 0x00, 0x00}; uint8_t threeb[] = {0x00, 0x00, 0x00};
void *threeb_buf = threeb; uint8_t *threeb_buf = threeb;
uint32_t threeb_val; 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); ASSERT(status == UPB_STATUS_NEED_MORE_DATA);
#undef TEST #undef TEST

Loading…
Cancel
Save