Tests use valgrind, chdir in test.

pull/13171/head
Joshua Haberman 16 years ago
parent d05eac2890
commit 46fac0f58d
  1. 21
      Makefile
  2. 16
      tests/test_vs_proto2.cc

@ -73,31 +73,42 @@ python: $(LIBUPB_PIC)
# Tests
tests: tests/tests \
tests/test_table \
tests/t.test_vs_proto2.googlemessage1 \
tests/t.test_vs_proto2.googlemessage2
test: tests/tests
./tests/tests
test: tests
@echo Running all tests under valgrind.
valgrind --leak-check=full --error-exitcode=1 ./tests/tests
# Needs to be rewritten to separate the benchmark.
# valgrind --error-exitcode=1 ./tests/test_table
@for test in tests/t.* ; do \
echo valgrind --leak-check=full --error-exitcode=1 ./$$test; \
valgrind --leak-check=full --error-exitcode=1 ./$$test; \
done;
tests/t.test_vs_proto2.googlemessage1 \
tests/t.test_vs_proto2.googlemessage2: \
tests/test_vs_proto2.cc $(LIBUPB) benchmarks/google_messages.proto.pb \
benchmarks/google_messages.pb.cc
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o tests/test_vs_proto2.googlemessage1 $< \
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o tests/t.test_vs_proto2.googlemessage1 $< \
-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\" \
benchmarks/google_messages.pb.cc -lprotobuf -lpthread $(LIBUPB)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o tests/test_vs_proto2.googlemessage2 $< \
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o tests/t.test_vs_proto2.googlemessage2 $< \
-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\" \
benchmarks/google_messages.pb.cc -lprotobuf -lpthread $(LIBUPB)
tests/test_table: src/libupb.a
tests/test_table: tests/test_table.cc
# Includes <hash_set> which is a deprecated header.
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -Wno-deprecated -o $@ $< $(LIBUPB)
tests/tests: src/libupb.a
# Tools

@ -172,8 +172,22 @@ void parse_and_compare(MESSAGE_CIDENT *proto2_msg, struct upb_msg *upb_msg,
compare(*proto2_msg, upb_msg);
}
int main()
int main(int argc, char *argv[])
{
// Change cwd to where the binary is.
(void)argc;
char *lastslash = strrchr(argv[0], '/');
char *progname = argv[0];
if(lastslash) {
*lastslash = '\0';
if(chdir(argv[0]) < 0) {
fprintf(stderr, "Error changing directory to %s.\n", argv[0]);
return 1;
}
*lastslash = '/';
progname = lastslash + 3; /* "/b_" */
}
// Initialize upb state, parse descriptor.
struct upb_context *c = upb_context_new();
struct upb_string *fds = upb_strreadfile(MESSAGE_DESCRIPTOR_FILE);

Loading…
Cancel
Save