Skip to content

Commit 0d9baf3

Browse files
mkruskal-googlecopybara-github
authored andcommitted
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
1 parent beb4bdb commit 0d9baf3

17 files changed

+72
-264
lines changed

java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.google.protobuf.CodedOutputStream.OutOfSpaceException;
1414
import protobuf_unittest.UnittestProto.SparseEnumMessage;
1515
import protobuf_unittest.UnittestProto.TestAllTypes;
16-
import protobuf_unittest.UnittestProto.TestPackedTypes;
1716
import protobuf_unittest.UnittestProto.TestSparseEnum;
1817
import java.io.ByteArrayInputStream;
1918
import java.io.ByteArrayOutputStream;
@@ -402,47 +401,6 @@ public void computeTagSize() {
402401
assertThat(CodedOutputStream.computeTagSize((1 << 30) + 1)).isEqualTo(1);
403402
}
404403

405-
/** Tests writing a whole message with every field type. */
406-
@Test
407-
public void testWriteWholeMessage() throws Exception {
408-
final byte[] expectedBytes = TestUtil.getGoldenMessage().toByteArray();
409-
TestAllTypes message = TestUtil.getAllSet();
410-
411-
for (OutputType outputType : OutputType.values()) {
412-
Coder coder = outputType.newCoder(message.getSerializedSize());
413-
message.writeTo(coder.stream());
414-
coder.stream().flush();
415-
byte[] rawBytes = coder.toByteArray();
416-
assertEqualBytes(outputType, expectedBytes, rawBytes);
417-
}
418-
419-
// Try different block sizes.
420-
for (int blockSize = 1; blockSize < 256; blockSize *= 2) {
421-
Coder coder = OutputType.STREAM.newCoder(blockSize);
422-
message.writeTo(coder.stream());
423-
coder.stream().flush();
424-
assertEqualBytes(OutputType.STREAM, expectedBytes, coder.toByteArray());
425-
}
426-
}
427-
428-
/**
429-
* Tests writing a whole message with every packed field type. Ensures the wire format of packed
430-
* fields is compatible with C++.
431-
*/
432-
@Test
433-
public void testWriteWholePackedFieldsMessage() throws Exception {
434-
byte[] expectedBytes = TestUtil.getGoldenPackedFieldsMessage().toByteArray();
435-
TestPackedTypes message = TestUtil.getPackedSet();
436-
437-
for (OutputType outputType : OutputType.values()) {
438-
Coder coder = outputType.newCoder(message.getSerializedSize());
439-
message.writeTo(coder.stream());
440-
coder.stream().flush();
441-
byte[] rawBytes = coder.toByteArray();
442-
assertEqualBytes(outputType, expectedBytes, rawBytes);
443-
}
444-
}
445-
446404
/**
447405
* Test writing a message containing a negative enum value. This used to fail because the size was
448406
* not properly computed as a sign-extended varint.

java/core/src/test/java/com/google/protobuf/TestUtil.java

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@
212212
import protobuf_unittest.UnittestProto.TestUnpackedTypes;
213213
import java.io.File;
214214
import java.io.IOException;
215-
import java.io.InputStream;
216215
import java.io.RandomAccessFile;
217216
import java.util.ArrayList;
218217
import java.util.Collections;
@@ -3819,53 +3818,7 @@ public static ByteString readBytesFromFile(String filename) {
38193818
throw new IllegalArgumentException("Couldn't read file: " + fullPath.getPath(), e);
38203819
}
38213820
}
3822-
// END FULL-RUNTIME
3823-
3824-
private static ByteString readBytesFromResource(String name) {
3825-
try {
3826-
InputStream in = TestUtil.class.getResourceAsStream(name);
3827-
if (in == null) { //
3828-
throw new RuntimeException("Tests data file " + name + " is missing.");
3829-
}
3830-
return ByteString.readFrom(in);
3831-
} catch (IOException e) {
3832-
throw new RuntimeException(e);
3833-
}
3834-
}
3835-
3836-
/**
3837-
* Get the bytes of the "golden message". This is a serialized TestAllTypes with all fields set as
3838-
* they would be by {@link #setAllFields(TestAllTypes.Builder)}, but it is loaded from a file on
3839-
* disk rather than generated dynamically. The file is actually generated by C++ code, so testing
3840-
* against it verifies compatibility with C++.
3841-
*/
3842-
public static ByteString getGoldenMessage() {
3843-
if (goldenMessage == null) {
3844-
goldenMessage =
3845-
readBytesFromResource("/google/protobuf/testdata/golden_message_oneof_implemented");
3846-
}
3847-
return goldenMessage;
3848-
}
3849-
3850-
private static ByteString goldenMessage = null;
3851-
3852-
/**
3853-
* Get the bytes of the "golden packed fields message". This is a serialized TestPackedTypes with
3854-
* all fields set as they would be by {@link #setPackedFields(TestPackedTypes.Builder)}, but it is
3855-
* loaded from a file on disk rather than generated dynamically. The file is actually generated by
3856-
* C++ code, so testing against it verifies compatibility with C++.
3857-
*/
3858-
public static ByteString getGoldenPackedFieldsMessage() {
3859-
if (goldenPackedFieldsMessage == null) {
3860-
goldenPackedFieldsMessage =
3861-
readBytesFromResource("/google/protobuf/testdata/golden_packed_fields_message");
3862-
}
3863-
return goldenPackedFieldsMessage;
3864-
}
38653821

3866-
private static ByteString goldenPackedFieldsMessage = null;
3867-
3868-
// BEGIN FULL-RUNTIME
38693822
/**
38703823
* Mock implementation of {@link GeneratedMessage.BuilderParent} for testing.
38713824
*

python/google/protobuf/internal/message_test.py

Lines changed: 3 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -65,48 +65,6 @@ def testBadUtf8String(self, message_module):
6565
message_module.TestAllTypes.FromString(bad_utf8_data)
6666
self.assertIn('TestAllTypes.optional_string', str(context.exception))
6767

68-
def testGoldenMessage(self, message_module):
69-
# Proto3 doesn't have the "default_foo" members or foreign enums,
70-
# and doesn't preserve unknown fields, so for proto3 we use a golden
71-
# message that doesn't have these fields set.
72-
if message_module is unittest_pb2:
73-
golden_data = test_util.GoldenFileData('golden_message_oneof_implemented')
74-
else:
75-
golden_data = test_util.GoldenFileData('golden_message_proto3')
76-
77-
golden_message = message_module.TestAllTypes()
78-
golden_message.ParseFromString(golden_data)
79-
if message_module is unittest_pb2:
80-
test_util.ExpectAllFieldsSet(self, golden_message)
81-
self.assertEqual(golden_data, golden_message.SerializeToString())
82-
golden_copy = copy.deepcopy(golden_message)
83-
self.assertEqual(golden_data, golden_copy.SerializeToString())
84-
85-
def testGoldenMessageBytearray(self, message_module):
86-
# bytearray was broken, test that it works again
87-
if message_module is unittest_pb2:
88-
golden_data = test_util.GoldenFileData('golden_message_oneof_implemented')
89-
else:
90-
golden_data = test_util.GoldenFileData('golden_message_proto3')
91-
92-
golden_message = message_module.TestAllTypes()
93-
golden_message.ParseFromString(bytearray(golden_data))
94-
if message_module is unittest_pb2:
95-
test_util.ExpectAllFieldsSet(self, golden_message)
96-
self.assertEqual(golden_data, golden_message.SerializeToString())
97-
98-
def testGoldenPackedMessage(self, message_module):
99-
golden_data = test_util.GoldenFileData('golden_packed_fields_message')
100-
golden_message = message_module.TestPackedTypes()
101-
parsed_bytes = golden_message.ParseFromString(golden_data)
102-
all_set = message_module.TestPackedTypes()
103-
test_util.SetAllPackedFields(all_set)
104-
self.assertEqual(parsed_bytes, len(golden_data))
105-
self.assertEqual(all_set, golden_message)
106-
self.assertEqual(golden_data, all_set.SerializeToString())
107-
golden_copy = copy.deepcopy(golden_message)
108-
self.assertEqual(golden_data, golden_copy.SerializeToString())
109-
11068
def testParseErrors(self, message_module):
11169
msg = message_module.TestAllTypes()
11270
self.assertRaises(TypeError, msg.FromString, 0)
@@ -162,7 +120,9 @@ def __bool__(self):
162120
golden_message.SerializeToString(deterministic=BadArg())
163121

164122
def testPickleSupport(self, message_module):
165-
golden_data = test_util.GoldenFileData('golden_message')
123+
golden_message = message_module.TestAllTypes()
124+
test_util.SetAllFields(golden_message)
125+
golden_data = golden_message.SerializeToString()
166126
golden_message = message_module.TestAllTypes()
167127
golden_message.ParseFromString(golden_data)
168128
pickled_message = pickle.dumps(golden_message)
@@ -1537,36 +1497,6 @@ def testCopyFromAllPackedExtensions(self):
15371497
all_set.Extensions[unittest_pb2.packed_float_extension].extend([61.0, 71.0])
15381498
self.assertNotEqual(all_set, copy)
15391499

1540-
def testGoldenExtensions(self):
1541-
golden_data = test_util.GoldenFileData('golden_message')
1542-
golden_message = unittest_pb2.TestAllExtensions()
1543-
golden_message.ParseFromString(golden_data)
1544-
all_set = unittest_pb2.TestAllExtensions()
1545-
test_util.SetAllExtensions(all_set)
1546-
self.assertEqual(all_set, golden_message)
1547-
self.assertEqual(golden_data, golden_message.SerializeToString())
1548-
golden_copy = copy.deepcopy(golden_message)
1549-
self.assertEqual(golden_message, golden_copy)
1550-
# Depend on a specific serialization order for extensions is not
1551-
# reasonable to guarantee.
1552-
if api_implementation.Type() != 'upb':
1553-
self.assertEqual(golden_data, golden_copy.SerializeToString())
1554-
1555-
def testGoldenPackedExtensions(self):
1556-
golden_data = test_util.GoldenFileData('golden_packed_fields_message')
1557-
golden_message = unittest_pb2.TestPackedExtensions()
1558-
golden_message.ParseFromString(golden_data)
1559-
all_set = unittest_pb2.TestPackedExtensions()
1560-
test_util.SetAllPackedExtensions(all_set)
1561-
self.assertEqual(all_set, golden_message)
1562-
self.assertEqual(golden_data, all_set.SerializeToString())
1563-
golden_copy = copy.deepcopy(golden_message)
1564-
self.assertEqual(golden_message, golden_copy)
1565-
# Depend on a specific serialization order for extensions is not
1566-
# reasonable to guarantee.
1567-
if api_implementation.Type() != 'upb':
1568-
self.assertEqual(golden_data, golden_copy.SerializeToString())
1569-
15701500
def testPickleIncompleteProto(self):
15711501
golden_message = unittest_pb2.TestRequired(a=1)
15721502
pickled_message = pickle.dumps(golden_message)

src/google/protobuf/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,6 @@ cc_test(
16151615
"message_unittest.inc",
16161616
"message_unittest_legacy_apis.inc",
16171617
],
1618-
data = [":testdata"],
16191618
deps = [
16201619
":arena",
16211620
":cc_lite_test_protos",
@@ -1648,7 +1647,6 @@ cc_test(
16481647
"edition_message_unittest.cc",
16491648
"message_unittest.inc",
16501649
],
1651-
data = [":testdata"],
16521650
deps = [
16531651
":arena",
16541652
":cc_test_protos",

src/google/protobuf/arena_test_util.h

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,6 @@
2121

2222
namespace google {
2323
namespace protobuf {
24-
25-
template <typename T, bool use_arena>
26-
void TestParseCorruptedString(const T& message) {
27-
int success_count = 0;
28-
std::string s;
29-
{
30-
// Map order is not deterministic. To make the test deterministic we want
31-
// to serialize the proto deterministically.
32-
io::StringOutputStream output(&s);
33-
io::CodedOutputStream out(&output);
34-
out.SetSerializationDeterministic(true);
35-
message.SerializePartialToCodedStream(&out);
36-
}
37-
#if defined(PROTOBUF_ASAN) || defined(PROTOBUF_TSAN) || defined(PROTOBUF_MSAN)
38-
// Make the test smaller in sanitizer mode.
39-
const int kMaxIters = 200;
40-
#else
41-
const int kMaxIters = 900;
42-
#endif
43-
const int stride = s.size() <= kMaxIters ? 1 : s.size() / kMaxIters;
44-
const int start = stride == 1 || use_arena ? 0 : (stride + 1) / 2;
45-
for (int i = start; i < s.size(); i += stride) {
46-
for (int c = 1 + (i % 17); c < 256; c += 2 * c + (i & 3)) {
47-
s[i] ^= c;
48-
Arena arena;
49-
T* message = Arena::Create<T>(use_arena ? &arena : nullptr);
50-
if (message->ParseFromString(s)) {
51-
++success_count;
52-
}
53-
if (!use_arena) {
54-
delete message;
55-
}
56-
s[i] ^= c; // Restore s to its original state.
57-
}
58-
}
59-
// This next line is a low bar. But getting through the test without crashing
60-
// due to use-after-free or other bugs is a big part of what we're checking.
61-
ABSL_CHECK_GT(success_count, 0);
62-
}
63-
6424
namespace internal {
6525

6626
struct ArenaTestPeer {

src/google/protobuf/arena_unittest.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,13 +1607,6 @@ TEST(ArenaTest, NoHeapAllocationsTest) {
16071607
arena.Reset();
16081608
}
16091609

1610-
TEST(ArenaTest, ParseCorruptedString) {
1611-
TestAllTypes message;
1612-
TestUtil::SetAllFields(&message);
1613-
TestParseCorruptedString<TestAllTypes, true>(message);
1614-
TestParseCorruptedString<TestAllTypes, false>(message);
1615-
}
1616-
16171610
#if PROTOBUF_RTTI
16181611
// Test construction on an arena via generic MessageLite interface. We should be
16191612
// able to successfully deserialize on the arena without incurring heap

src/google/protobuf/compiler/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ cc_test(
432432
"//src/google/protobuf:cc_test_protos",
433433
"//src/google/protobuf:port",
434434
"//src/google/protobuf:test_textproto",
435+
"//src/google/protobuf:test_util",
435436
"//src/google/protobuf:test_util2",
436437
"//src/google/protobuf/compiler/cpp:names",
437438
"//src/google/protobuf/io",

src/google/protobuf/compiler/command_line_interface_unittest.cc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "google/protobuf/compiler/mock_code_generator.h"
4949
#include "google/protobuf/compiler/plugin.pb.h"
5050
#include "google/protobuf/test_textproto.h"
51+
#include "google/protobuf/test_util.h"
5152
#include "google/protobuf/test_util2.h"
5253
#include "google/protobuf/unittest.pb.h"
5354
#include "google/protobuf/unittest_custom_options.pb.h"
@@ -4202,7 +4203,16 @@ class EncodeDecodeTest : public testing::TestWithParam<EncodeDecodeTestMode> {
42024203
std::string unittest_proto_descriptor_set_filename_;
42034204
};
42044205

4206+
static void WriteGoldenMessage(const std::string& filename) {
4207+
protobuf_unittest::TestAllTypes message;
4208+
TestUtil::SetAllFields(&message);
4209+
std::string golden = message.SerializeAsString();
4210+
ABSL_CHECK_OK(File::SetContents(filename, golden, true));
4211+
}
4212+
42054213
TEST_P(EncodeDecodeTest, Encode) {
4214+
std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message");
4215+
WriteGoldenMessage(golden_path);
42064216
RedirectStdinFromFile(TestUtil::GetTestDataPath(
42074217
"google/protobuf/"
42084218
"testdata/text_format_unittest_data_oneof_implemented.txt"));
@@ -4212,14 +4222,14 @@ TEST_P(EncodeDecodeTest, Encode) {
42124222
}
42134223
EXPECT_TRUE(
42144224
Run(absl::StrCat(args, " --encode=protobuf_unittest.TestAllTypes")));
4215-
ExpectStdoutMatchesBinaryFile(TestUtil::GetTestDataPath(
4216-
"google/protobuf/testdata/golden_message_oneof_implemented"));
4225+
ExpectStdoutMatchesBinaryFile(golden_path);
42174226
ExpectStderrMatchesText("");
42184227
}
42194228

42204229
TEST_P(EncodeDecodeTest, Decode) {
4221-
RedirectStdinFromFile(TestUtil::GetTestDataPath(
4222-
"google/protobuf/testdata/golden_message_oneof_implemented"));
4230+
std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message");
4231+
WriteGoldenMessage(golden_path);
4232+
RedirectStdinFromFile(golden_path);
42234233
EXPECT_TRUE(
42244234
Run("google/protobuf/unittest.proto"
42254235
" --decode=protobuf_unittest.TestAllTypes"));
@@ -4272,6 +4282,8 @@ TEST_P(EncodeDecodeTest, ProtoParseError) {
42724282
}
42734283

42744284
TEST_P(EncodeDecodeTest, EncodeDeterministicOutput) {
4285+
std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message");
4286+
WriteGoldenMessage(golden_path);
42754287
RedirectStdinFromFile(TestUtil::GetTestDataPath(
42764288
"google/protobuf/"
42774289
"testdata/text_format_unittest_data_oneof_implemented.txt"));
@@ -4281,14 +4293,14 @@ TEST_P(EncodeDecodeTest, EncodeDeterministicOutput) {
42814293
}
42824294
EXPECT_TRUE(Run(absl::StrCat(
42834295
args, " --encode=protobuf_unittest.TestAllTypes --deterministic_output")));
4284-
ExpectStdoutMatchesBinaryFile(TestUtil::GetTestDataPath(
4285-
"google/protobuf/testdata/golden_message_oneof_implemented"));
4296+
ExpectStdoutMatchesBinaryFile(golden_path);
42864297
ExpectStderrMatchesText("");
42874298
}
42884299

42894300
TEST_P(EncodeDecodeTest, DecodeDeterministicOutput) {
4290-
RedirectStdinFromFile(TestUtil::GetTestDataPath(
4291-
"google/protobuf/testdata/golden_message_oneof_implemented"));
4301+
std::string golden_path = absl::StrCat(TestTempDir(), "/golden_message");
4302+
WriteGoldenMessage(golden_path);
4303+
RedirectStdinFromFile(golden_path);
42924304
EXPECT_FALSE(
42934305
Run("google/protobuf/unittest.proto"
42944306
" --decode=protobuf_unittest.TestAllTypes --deterministic_output"));

src/google/protobuf/io/BUILD.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,6 @@ cc_test(
192192
"zero_copy_stream_unittest.cc",
193193
],
194194
copts = COPTS,
195-
data = [
196-
"//src/google/protobuf:testdata",
197-
],
198195
deps = [
199196
":gzip_stream",
200197
":io",
@@ -204,6 +201,7 @@ cc_test(
204201
"//:protobuf",
205202
"//src/google/protobuf",
206203
"//src/google/protobuf:port",
204+
"//src/google/protobuf:test_util",
207205
"//src/google/protobuf:test_util2",
208206
"//src/google/protobuf/stubs",
209207
"//src/google/protobuf/testing",

0 commit comments

Comments
 (0)