Remove outdated conformance/fuzz tests.

These are very old unit-tests that appear to have been written to provide some conformance and fuzzing capabilities before we had more comprehensive solutions.  Today, they should be already covered by our conformance tests and fuzz tests and create unnecessary noise.

The goal of this change is to remove the checked-in binary golden data that we no longer know how to regenerate.  There is a lot of nearby code that could likely also be cleaned up in a follow-up

PiperOrigin-RevId: 667604310
pull/17937/head
Mike Kruskal 6 months ago committed by Copybara-Service
parent beb4bdbed3
commit 0d9baf367f
  1. 42
      java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java
  2. 47
      java/core/src/test/java/com/google/protobuf/TestUtil.java
  3. 76
      python/google/protobuf/internal/message_test.py
  4. 2
      src/google/protobuf/BUILD.bazel
  5. 40
      src/google/protobuf/arena_test_util.h
  6. 7
      src/google/protobuf/arena_unittest.cc
  7. 1
      src/google/protobuf/compiler/BUILD.bazel
  8. 28
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  9. 4
      src/google/protobuf/io/BUILD.bazel
  10. 8
      src/google/protobuf/io/zero_copy_stream_unittest.cc
  11. 63
      src/google/protobuf/map_test.inc
  12. 18
      src/google/protobuf/message_unittest.inc
  13. BIN
      src/google/protobuf/testdata/golden_message
  14. BIN
      src/google/protobuf/testdata/golden_message_maps
  15. BIN
      src/google/protobuf/testdata/golden_message_oneof_implemented
  16. BIN
      src/google/protobuf/testdata/golden_message_proto3
  17. BIN
      src/google/protobuf/testdata/golden_packed_fields_message

@ -13,7 +13,6 @@ import static com.google.common.truth.Truth.assertWithMessage;
import com.google.protobuf.CodedOutputStream.OutOfSpaceException;
import protobuf_unittest.UnittestProto.SparseEnumMessage;
import protobuf_unittest.UnittestProto.TestAllTypes;
import protobuf_unittest.UnittestProto.TestPackedTypes;
import protobuf_unittest.UnittestProto.TestSparseEnum;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -402,47 +401,6 @@ public class CodedOutputStreamTest {
assertThat(CodedOutputStream.computeTagSize((1 << 30) + 1)).isEqualTo(1);
}
/** Tests writing a whole message with every field type. */
@Test
public void testWriteWholeMessage() throws Exception {
final byte[] expectedBytes = TestUtil.getGoldenMessage().toByteArray();
TestAllTypes message = TestUtil.getAllSet();
for (OutputType outputType : OutputType.values()) {
Coder coder = outputType.newCoder(message.getSerializedSize());
message.writeTo(coder.stream());
coder.stream().flush();
byte[] rawBytes = coder.toByteArray();
assertEqualBytes(outputType, expectedBytes, rawBytes);
}
// Try different block sizes.
for (int blockSize = 1; blockSize < 256; blockSize *= 2) {
Coder coder = OutputType.STREAM.newCoder(blockSize);
message.writeTo(coder.stream());
coder.stream().flush();
assertEqualBytes(OutputType.STREAM, expectedBytes, coder.toByteArray());
}
}
/**
* Tests writing a whole message with every packed field type. Ensures the wire format of packed
* fields is compatible with C++.
*/
@Test
public void testWriteWholePackedFieldsMessage() throws Exception {
byte[] expectedBytes = TestUtil.getGoldenPackedFieldsMessage().toByteArray();
TestPackedTypes message = TestUtil.getPackedSet();
for (OutputType outputType : OutputType.values()) {
Coder coder = outputType.newCoder(message.getSerializedSize());
message.writeTo(coder.stream());
coder.stream().flush();
byte[] rawBytes = coder.toByteArray();
assertEqualBytes(outputType, expectedBytes, rawBytes);
}
}
/**
* Test writing a message containing a negative enum value. This used to fail because the size was
* not properly computed as a sign-extended varint.

@ -212,7 +212,6 @@ import protobuf_unittest.UnittestProto.TestRequired;
import protobuf_unittest.UnittestProto.TestUnpackedTypes;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collections;
@ -3819,53 +3818,7 @@ public final class TestUtil {
throw new IllegalArgumentException("Couldn't read file: " + fullPath.getPath(), e);
}
}
// END FULL-RUNTIME
private static ByteString readBytesFromResource(String name) {
try {
InputStream in = TestUtil.class.getResourceAsStream(name);
if (in == null) { //
throw new RuntimeException("Tests data file " + name + " is missing.");
}
return ByteString.readFrom(in);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* Get the bytes of the "golden message". This is a serialized TestAllTypes with all fields set as
* they would be by {@link #setAllFields(TestAllTypes.Builder)}, but it is loaded from a file on
* disk rather than generated dynamically. The file is actually generated by C++ code, so testing
* against it verifies compatibility with C++.
*/
public static ByteString getGoldenMessage() {
if (goldenMessage == null) {
goldenMessage =
readBytesFromResource("/google/protobuf/testdata/golden_message_oneof_implemented");
}
return goldenMessage;
}
private static ByteString goldenMessage = null;
/**
* Get the bytes of the "golden packed fields message". This is a serialized TestPackedTypes with
* all fields set as they would be by {@link #setPackedFields(TestPackedTypes.Builder)}, but it is
* loaded from a file on disk rather than generated dynamically. The file is actually generated by
* C++ code, so testing against it verifies compatibility with C++.
*/
public static ByteString getGoldenPackedFieldsMessage() {
if (goldenPackedFieldsMessage == null) {
goldenPackedFieldsMessage =
readBytesFromResource("/google/protobuf/testdata/golden_packed_fields_message");
}
return goldenPackedFieldsMessage;
}
private static ByteString goldenPackedFieldsMessage = null;
// BEGIN FULL-RUNTIME
/**
* Mock implementation of {@link GeneratedMessage.BuilderParent} for testing.
*

@ -65,48 +65,6 @@ class MessageTest(unittest.TestCase):
message_module.TestAllTypes.FromString(bad_utf8_data)
self.assertIn('TestAllTypes.optional_string', str(context.exception))
def testGoldenMessage(self, message_module):
# Proto3 doesn't have the "default_foo" members or foreign enums,
# and doesn't preserve unknown fields, so for proto3 we use a golden
# message that doesn't have these fields set.
if message_module is unittest_pb2:
golden_data = test_util.GoldenFileData('golden_message_oneof_implemented')
else:
golden_data = test_util.GoldenFileData('golden_message_proto3')
golden_message = message_module.TestAllTypes()
golden_message.ParseFromString(golden_data)
if message_module is unittest_pb2:
test_util.ExpectAllFieldsSet(self, golden_message)
self.assertEqual(golden_data, golden_message.SerializeToString())
golden_copy = copy.deepcopy(golden_message)
self.assertEqual(golden_data, golden_copy.SerializeToString())
def testGoldenMessageBytearray(self, message_module):
# bytearray was broken, test that it works again
if message_module is unittest_pb2:
golden_data = test_util.GoldenFileData('golden_message_oneof_implemented')
else:
golden_data = test_util.GoldenFileData('golden_message_proto3')
golden_message = message_module.TestAllTypes()
golden_message.ParseFromString(bytearray(golden_data))
if message_module is unittest_pb2:
test_util.ExpectAllFieldsSet(self, golden_message)
self.assertEqual(golden_data, golden_message.SerializeToString())
def testGoldenPackedMessage(self, message_module):
golden_data = test_util.GoldenFileData('golden_packed_fields_message')
golden_message = message_module.TestPackedTypes()
parsed_bytes = golden_message.ParseFromString(golden_data)
all_set = message_module.TestPackedTypes()
test_util.SetAllPackedFields(all_set)
self.assertEqual(parsed_bytes, len(golden_data))
self.assertEqual(all_set, golden_message)
self.assertEqual(golden_data, all_set.SerializeToString())
golden_copy = copy.deepcopy(golden_message)
self.assertEqual(golden_data, golden_copy.SerializeToString())
def testParseErrors(self, message_module):
msg = message_module.TestAllTypes()
self.assertRaises(TypeError, msg.FromString, 0)
@ -162,7 +120,9 @@ class MessageTest(unittest.TestCase):
golden_message.SerializeToString(deterministic=BadArg())
def testPickleSupport(self, message_module):
golden_data = test_util.GoldenFileData('golden_message')
golden_message = message_module.TestAllTypes()
test_util.SetAllFields(golden_message)
golden_data = golden_message.SerializeToString()
golden_message = message_module.TestAllTypes()
golden_message.ParseFromString(golden_data)
pickled_message = pickle.dumps(golden_message)
@ -1537,36 +1497,6 @@ class Proto2Test(unittest.TestCase):
all_set.Extensions[unittest_pb2.packed_float_extension].extend([61.0, 71.0])
self.assertNotEqual(all_set, copy)
def testGoldenExtensions(self):
golden_data = test_util.GoldenFileData('golden_message')
golden_message = unittest_pb2.TestAllExtensions()
golden_message.ParseFromString(golden_data)
all_set = unittest_pb2.TestAllExtensions()
test_util.SetAllExtensions(all_set)
self.assertEqual(all_set, golden_message)
self.assertEqual(golden_data, golden_message.SerializeToString())
golden_copy = copy.deepcopy(golden_message)
self.assertEqual(golden_message, golden_copy)
# Depend on a specific serialization order for extensions is not
# reasonable to guarantee.
if api_implementation.Type() != 'upb':
self.assertEqual(golden_data, golden_copy.SerializeToString())
def testGoldenPackedExtensions(self):
golden_data = test_util.GoldenFileData('golden_packed_fields_message')
golden_message = unittest_pb2.TestPackedExtensions()
golden_message.ParseFromString(golden_data)
all_set = unittest_pb2.TestPackedExtensions()
test_util.SetAllPackedExtensions(all_set)
self.assertEqual(all_set, golden_message)
self.assertEqual(golden_data, all_set.SerializeToString())
golden_copy = copy.deepcopy(golden_message)
self.assertEqual(golden_message, golden_copy)
# Depend on a specific serialization order for extensions is not
# reasonable to guarantee.
if api_implementation.Type() != 'upb':
self.assertEqual(golden_data, golden_copy.SerializeToString())
def testPickleIncompleteProto(self):
golden_message = unittest_pb2.TestRequired(a=1)
pickled_message = pickle.dumps(golden_message)

@ -1615,7 +1615,6 @@ cc_test(
"message_unittest.inc",
"message_unittest_legacy_apis.inc",
],
data = [":testdata"],
deps = [
":arena",
":cc_lite_test_protos",
@ -1648,7 +1647,6 @@ cc_test(
"edition_message_unittest.cc",
"message_unittest.inc",
],
data = [":testdata"],
deps = [
":arena",
":cc_test_protos",

@ -21,46 +21,6 @@
namespace google {
namespace protobuf {
template <typename T, bool use_arena>
void TestParseCorruptedString(const T& message) {
int success_count = 0;
std::string s;
{
// Map order is not deterministic. To make the test deterministic we want
// to serialize the proto deterministically.
io::StringOutputStream output(&s);
io::CodedOutputStream out(&output);
out.SetSerializationDeterministic(true);
message.SerializePartialToCodedStream(&out);
}
#if defined(PROTOBUF_ASAN) || defined(PROTOBUF_TSAN) || defined(PROTOBUF_MSAN)
// Make the test smaller in sanitizer mode.
const int kMaxIters = 200;
#else
const int kMaxIters = 900;
#endif
const int stride = s.size() <= kMaxIters ? 1 : s.size() / kMaxIters;
const int start = stride == 1 || use_arena ? 0 : (stride + 1) / 2;
for (int i = start; i < s.size(); i += stride) {
for (int c = 1 + (i % 17); c < 256; c += 2 * c + (i & 3)) {
s[i] ^= c;
Arena arena;
T* message = Arena::Create<T>(use_arena ? &arena : nullptr);
if (message->ParseFromString(s)) {
++success_count;
}
if (!use_arena) {
delete message;
}
s[i] ^= c; // Restore s to its original state.
}
}
// This next line is a low bar. But getting through the test without crashing
// due to use-after-free or other bugs is a big part of what we're checking.
ABSL_CHECK_GT(success_count, 0);
}
namespace internal {
struct ArenaTestPeer {

@ -1607,13 +1607,6 @@ TEST(ArenaTest, NoHeapAllocationsTest) {
arena.Reset();
}
TEST(ArenaTest, ParseCorruptedString) {
TestAllTypes message;
TestUtil::SetAllFields(&message);
TestParseCorruptedString<TestAllTypes, true>(message);
TestParseCorruptedString<TestAllTypes, false>(message);
}
#if PROTOBUF_RTTI
// Test construction on an arena via generic MessageLite interface. We should be
// able to successfully deserialize on the arena without incurring heap

@ -432,6 +432,7 @@ cc_test(
"//src/google/protobuf:cc_test_protos",
"//src/google/protobuf:port",
"//src/google/protobuf:test_textproto",
"//src/google/protobuf:test_util",
"//src/google/protobuf:test_util2",
"//src/google/protobuf/compiler/cpp:names",
"//src/google/protobuf/io",

@ -48,6 +48,7 @@
#include "google/protobuf/compiler/mock_code_generator.h"
#include "google/protobuf/compiler/plugin.pb.h"
#include "google/protobuf/test_textproto.h"
#include "google/protobuf/test_util.h"
#include "google/protobuf/test_util2.h"
#include "google/protobuf/unittest.pb.h"
#include "google/protobuf/unittest_custom_options.pb.h"
@ -4202,7 +4203,16 @@ class EncodeDecodeTest : public testing::TestWithParam<EncodeDecodeTestMode> {
std::string unittest_proto_descriptor_set_filename_;
};
static void WriteGoldenMessage(const std::string& filename) {
protobuf_unittest::TestAllTypes message;
TestUtil::SetAllFields(&message);
std::string golden = message.SerializeAsString();
ABSL_CHECK_OK(File::SetContents(filename, golden, true));
}
TEST_P(EncodeDecodeTest, Encode) {
std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message");
WriteGoldenMessage(golden_path);
RedirectStdinFromFile(TestUtil::GetTestDataPath(
"google/protobuf/"
"testdata/text_format_unittest_data_oneof_implemented.txt"));
@ -4212,14 +4222,14 @@ TEST_P(EncodeDecodeTest, Encode) {
}
EXPECT_TRUE(
Run(absl::StrCat(args, " --encode=protobuf_unittest.TestAllTypes")));
ExpectStdoutMatchesBinaryFile(TestUtil::GetTestDataPath(
"google/protobuf/testdata/golden_message_oneof_implemented"));
ExpectStdoutMatchesBinaryFile(golden_path);
ExpectStderrMatchesText("");
}
TEST_P(EncodeDecodeTest, Decode) {
RedirectStdinFromFile(TestUtil::GetTestDataPath(
"google/protobuf/testdata/golden_message_oneof_implemented"));
std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message");
WriteGoldenMessage(golden_path);
RedirectStdinFromFile(golden_path);
EXPECT_TRUE(
Run("google/protobuf/unittest.proto"
" --decode=protobuf_unittest.TestAllTypes"));
@ -4272,6 +4282,8 @@ TEST_P(EncodeDecodeTest, ProtoParseError) {
}
TEST_P(EncodeDecodeTest, EncodeDeterministicOutput) {
std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message");
WriteGoldenMessage(golden_path);
RedirectStdinFromFile(TestUtil::GetTestDataPath(
"google/protobuf/"
"testdata/text_format_unittest_data_oneof_implemented.txt"));
@ -4281,14 +4293,14 @@ TEST_P(EncodeDecodeTest, EncodeDeterministicOutput) {
}
EXPECT_TRUE(Run(absl::StrCat(
args, " --encode=protobuf_unittest.TestAllTypes --deterministic_output")));
ExpectStdoutMatchesBinaryFile(TestUtil::GetTestDataPath(
"google/protobuf/testdata/golden_message_oneof_implemented"));
ExpectStdoutMatchesBinaryFile(golden_path);
ExpectStderrMatchesText("");
}
TEST_P(EncodeDecodeTest, DecodeDeterministicOutput) {
RedirectStdinFromFile(TestUtil::GetTestDataPath(
"google/protobuf/testdata/golden_message_oneof_implemented"));
std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message");
WriteGoldenMessage(golden_path);
RedirectStdinFromFile(golden_path);
EXPECT_FALSE(
Run("google/protobuf/unittest.proto"
" --decode=protobuf_unittest.TestAllTypes --deterministic_output"));

@ -192,9 +192,6 @@ cc_test(
"zero_copy_stream_unittest.cc",
],
copts = COPTS,
data = [
"//src/google/protobuf:testdata",
],
deps = [
":gzip_stream",
":io",
@ -204,6 +201,7 @@ cc_test(
"//:protobuf",
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf:test_util",
"//src/google/protobuf:test_util2",
"//src/google/protobuf/stubs",
"//src/google/protobuf/testing",

@ -62,6 +62,7 @@
#include "google/protobuf/io/gzip_stream.h"
#endif
#include "google/protobuf/test_util.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
@ -557,10 +558,9 @@ std::string IoTest::Uncompress(const std::string& data) {
TEST_F(IoTest, CompressionOptions) {
// Some ad-hoc testing of compression options.
std::string golden_filename =
TestUtil::GetTestDataPath("google/protobuf/testdata/golden_message");
std::string golden;
ABSL_CHECK_OK(File::GetContents(golden_filename, &golden, true));
protobuf_unittest::TestAllTypes message;
TestUtil::SetAllFields(&message);
std::string golden = message.SerializeAsString();
GzipOutputStream::Options options;
std::string gzip_compressed = Compress(golden, options);

@ -3938,16 +3938,35 @@ TEST(MapSerializationTest, Deterministic) {
EXPECT_TRUE(util::MessageDifferencer::Equals(u, t));
}
static std::string GetGoldenMessageTextProto() {
static std::string* golden_message_textproto = [] {
std::string* textproto = new std::string;
ABSL_CHECK_OK(File::GetContents(
TestUtil::GetTestDataPath("google/protobuf/"
"testdata/map_test_data.txt"),
textproto, true));
return textproto;
}();
return *golden_message_textproto;
}
static std::string GetGoldenMessageBinary() {
static std::string* golden_message_binary = [] {
UNITTEST::TestMaps t;
TextFormat::Parser parser;
parser.ParseFromString(GetGoldenMessageTextProto(), &t);
std::string* result = new std::string;
t.SerializeToString(result);
return result;
}();
return *golden_message_binary;
}
TEST(MapSerializationTest, DeterministicSubmessage) {
UNITTEST::TestSubmessageMaps p;
UNITTEST::TestMaps t;
const std::string filename = "golden_message_maps";
std::string golden;
ABSL_CHECK_OK(
File::GetContents(TestUtil::GetTestDataPath(absl::StrCat(
"google/protobuf/testdata/", filename)),
&golden, true));
t.ParseFromString(golden);
t.ParseFromString(GetGoldenMessageBinary());
*(p.mutable_m()) = t;
std::vector<std::string> v;
// Use multiple attempts to increase the chance of a failure if something is
@ -3985,15 +4004,9 @@ TEST(TextFormatMapTest, DynamicMessage) {
MapReflectionTester tester(message->GetDescriptor());
tester.SetMapFieldsViaReflection(message.get());
std::string expected_text;
ABSL_CHECK_OK(
File::GetContents(TestUtil::GetTestDataPath("google/protobuf/"
"testdata/map_test_data.txt"),
&expected_text, true));
std::string actual_text;
TextFormat::PrintToString(*message, &actual_text);
EXPECT_EQ(actual_text, expected_text);
EXPECT_EQ(actual_text, GetGoldenMessageTextProto());
}
TEST(TextFormatMapTest, Sorted) {
@ -4001,35 +4014,17 @@ TEST(TextFormatMapTest, Sorted) {
MapReflectionTester tester(message.GetDescriptor());
tester.SetMapFieldsViaReflection(&message);
std::string expected_text;
ABSL_CHECK_OK(
File::GetContents(TestUtil::GetTestDataPath("google/protobuf/"
"testdata/map_test_data.txt"),
&expected_text, true));
TextFormat::Printer printer;
std::string actual_text;
printer.PrintToString(message, &actual_text);
EXPECT_EQ(actual_text, expected_text);
EXPECT_EQ(actual_text, GetGoldenMessageTextProto());
// Test again on the reverse order.
UNITTEST::TestMap message2;
tester.SetMapFieldsViaReflection(&message2);
tester.SwapMapsViaReflection(&message2);
printer.PrintToString(message2, &actual_text);
EXPECT_EQ(actual_text, expected_text);
}
TEST(TextFormatMapTest, ParseCorruptedString) {
std::string serialized_message;
ABSL_CHECK_OK(File::GetContents(
TestUtil::GetTestDataPath(
"google/protobuf/testdata/golden_message_maps"),
&serialized_message, true));
UNITTEST::TestMaps message;
ABSL_CHECK(message.ParseFromString(serialized_message));
TestParseCorruptedString<UNITTEST::TestMaps, true>(message);
TestParseCorruptedString<UNITTEST::TestMaps, false>(message);
EXPECT_EQ(actual_text, GetGoldenMessageTextProto());
}
// Previously, serializing to text format will disable iterator from generated

@ -29,6 +29,8 @@
#include <fstream>
#include <sstream>
#include "google/protobuf/testing/file.h"
#include "google/protobuf/testing/file.h"
#include "google/protobuf/descriptor.pb.h"
#include <gmock/gmock.h>
#include "google/protobuf/testing/googletest.h"
@ -143,8 +145,12 @@ TEST(MESSAGE_TEST_NAME, SerializeToBrokenOstream) {
}
TEST(MESSAGE_TEST_NAME, ParseFromFileDescriptor) {
std::string filename =
TestUtil::GetTestDataPath("google/protobuf/testdata/golden_message");
std::string filename = absl::StrCat(TestTempDir(), "/golden_message");
UNITTEST::TestAllTypes expected_message;
TestUtil::SetAllFields(&expected_message);
ABSL_CHECK_OK(File::SetContents(
filename, expected_message.SerializeAsString(), true));
int file = open(filename.c_str(), O_RDONLY | O_BINARY);
ASSERT_GE(file, 0);
@ -156,8 +162,12 @@ TEST(MESSAGE_TEST_NAME, ParseFromFileDescriptor) {
}
TEST(MESSAGE_TEST_NAME, ParsePackedFromFileDescriptor) {
std::string filename = TestUtil::GetTestDataPath(
"google/protobuf/testdata/golden_packed_fields_message");
std::string filename = absl::StrCat(TestTempDir(), "/golden_message");
UNITTEST::TestPackedTypes expected_message;
TestUtil::SetPackedFields(&expected_message);
ABSL_CHECK_OK(File::SetContents(
filename, expected_message.SerializeAsString(), true));
int file = open(filename.c_str(), O_RDONLY | O_BINARY);
ASSERT_GE(file, 0);

Binary file not shown.
Loading…
Cancel
Save