Enable upb editions conformance testing.

This also cleans up some pre-existing bugs and adds a Fasttable/ASAN build.

PiperOrigin-RevId: 581408568
pull/14725/head
Mike Kruskal 1 year ago committed by Copybara-Service
parent c6b149cbf9
commit 8699fde0a9
  1. 1
      .github/workflows/test_upb.yml
  2. 27
      src/google/protobuf/editions/BUILD
  3. 8
      upb/conformance/BUILD
  4. 12
      upb/conformance/conformance_upb.c
  5. 2
      upb/conformance/conformance_upb_failures.txt
  6. 20
      upb/wire/decode_fast.c

@ -20,6 +20,7 @@ jobs:
- { name: "Fastbuild" } - { name: "Fastbuild" }
- { name: "Optimized", flags: "-c opt" } - { name: "Optimized", flags: "-c opt" }
- { name: "FastTable", flags: "--//upb:fasttable_enabled=true" } - { name: "FastTable", flags: "--//upb:fasttable_enabled=true" }
- { name: "FastTable ASAN", flags: "--//upb:fasttable_enabled=true --config=asan", exclude-targets: "-//benchmarks:benchmark -//python/..." }
- { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/..." } - { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/..." }
- { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/... -//lua/..." } - { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/... -//lua/..." }
- { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-//benchmarks:benchmark -//python/..." } - { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-//benchmarks:benchmark -//python/..." }

@ -1,4 +1,5 @@
load("@rules_python//python:proto.bzl", "py_proto_library") load("@rules_python//python:proto.bzl", "py_proto_library")
load("//bazel:upb_proto_library.bzl", "upb_c_proto_library", "upb_proto_reflection_library")
load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":defaults.bzl", "compile_edition_defaults", "embed_edition_defaults") load(":defaults.bzl", "compile_edition_defaults", "embed_edition_defaults")
@ -106,6 +107,19 @@ py_proto_library(
deps = [":test_messages_proto2_editions_proto"], deps = [":test_messages_proto2_editions_proto"],
) )
upb_c_proto_library(
name = "test_messages_proto2_editions_upb_proto",
testonly = 1,
deps = [":test_messages_proto2_editions_proto"],
)
upb_proto_reflection_library(
name = "test_messages_proto2_editions_upbdefs",
testonly = 1,
visibility = ["//upb/conformance:__pkg__"],
deps = [":test_messages_proto2_editions_proto"],
)
proto_library( proto_library(
name = "test_messages_proto3_editions_proto", name = "test_messages_proto3_editions_proto",
testonly = True, testonly = True,
@ -135,6 +149,19 @@ py_proto_library(
deps = [":test_messages_proto3_editions_proto"], deps = [":test_messages_proto3_editions_proto"],
) )
upb_c_proto_library(
name = "test_messages_proto3_editions_upb_proto",
testonly = 1,
deps = [":test_messages_proto3_editions_proto"],
)
upb_proto_reflection_library(
name = "test_messages_proto3_editions_upbdefs",
testonly = 1,
visibility = ["//upb/conformance:__pkg__"],
deps = ["test_messages_proto3_editions_proto"],
)
# Export these for conformance tests until we support py_proto_library. # Export these for conformance tests until we support py_proto_library.
exports_files( exports_files(
[ [

@ -73,6 +73,8 @@ cc_binary(
":conformance_upb_proto_reflection", ":conformance_upb_proto_reflection",
":test_messages_proto2_upbdefs", ":test_messages_proto2_upbdefs",
":test_messages_proto3_upbdefs", ":test_messages_proto3_upbdefs",
"//src/google/protobuf/editions:test_messages_proto2_editions_upbdefs",
"//src/google/protobuf/editions:test_messages_proto3_editions_upbdefs",
"//upb:json", "//upb:json",
"//upb:port", "//upb:port",
"//upb:reflection", "//upb:reflection",
@ -84,7 +86,7 @@ cc_binary(
make_shell_script( make_shell_script(
name = "gen_test_conformance_upb", name = "gen_test_conformance_upb",
out = "test_conformance_upb.sh", out = "test_conformance_upb.sh",
contents = "$1 --enforce_recommended --failure_list $2 $3", contents = "$1 --maximum_edition 2023 --enforce_recommended --failure_list $2 $3",
) )
sh_test( sh_test(
@ -124,6 +126,8 @@ cc_binary(
":conformance_upb_proto_reflection", ":conformance_upb_proto_reflection",
":test_messages_proto2_upbdefs", ":test_messages_proto2_upbdefs",
":test_messages_proto3_upbdefs", ":test_messages_proto3_upbdefs",
"//src/google/protobuf/editions:test_messages_proto2_editions_upbdefs",
"//src/google/protobuf/editions:test_messages_proto3_editions_upbdefs",
"//upb:json", "//upb:json",
"//upb:port", "//upb:port",
"//upb:reflection", "//upb:reflection",
@ -135,7 +139,7 @@ cc_binary(
make_shell_script( make_shell_script(
name = "gen_test_conformance_upb_dynamic_minitable", name = "gen_test_conformance_upb_dynamic_minitable",
out = "test_conformance_upb_dynamic_minitable.sh", out = "test_conformance_upb_dynamic_minitable.sh",
contents = "$1 --enforce_recommended --failure_list $2 $3", contents = "$1 --maximum_edition 2023 --enforce_recommended --failure_list $2 $3",
) )
sh_test( sh_test(

@ -16,6 +16,8 @@
#include "conformance/conformance.upb.h" #include "conformance/conformance.upb.h"
#include "conformance/conformance.upbdefs.h" #include "conformance/conformance.upbdefs.h"
#include "google/protobuf/editions/golden/test_messages_proto2_editions.upbdefs.h"
#include "google/protobuf/editions/golden/test_messages_proto3_editions.upbdefs.h"
#include "google/protobuf/test_messages_proto2.upbdefs.h" #include "google/protobuf/test_messages_proto2.upbdefs.h"
#include "google/protobuf/test_messages_proto3.upbdefs.h" #include "google/protobuf/test_messages_proto3.upbdefs.h"
#include "upb/json/decode.h" #include "upb/json/decode.h"
@ -309,9 +311,19 @@ int main(void) {
symtab, &google_protobuf_test_messages_proto2_proto_upbdefinit, true); symtab, &google_protobuf_test_messages_proto2_proto_upbdefinit, true);
_upb_DefPool_LoadDefInitEx( _upb_DefPool_LoadDefInitEx(
symtab, &google_protobuf_test_messages_proto3_proto_upbdefinit, true); symtab, &google_protobuf_test_messages_proto3_proto_upbdefinit, true);
_upb_DefPool_LoadDefInitEx(
symtab,
&google_protobuf_editions_golden_test_messages_proto2_editions_proto_upbdefinit,
true);
_upb_DefPool_LoadDefInitEx(
symtab,
&google_protobuf_editions_golden_test_messages_proto3_editions_proto_upbdefinit,
true);
#else #else
protobuf_test_messages_proto2_TestAllTypesProto2_getmsgdef(symtab); protobuf_test_messages_proto2_TestAllTypesProto2_getmsgdef(symtab);
protobuf_test_messages_editions_proto2_TestAllTypesProto2_getmsgdef(symtab);
protobuf_test_messages_proto3_TestAllTypesProto3_getmsgdef(symtab); protobuf_test_messages_proto3_TestAllTypesProto3_getmsgdef(symtab);
protobuf_test_messages_editions_proto3_TestAllTypesProto3_getmsgdef(symtab);
#endif #endif
while (1) { while (1) {

@ -1,2 +1,4 @@
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput
Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput
Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput

@ -658,12 +658,14 @@ static const char* fastdecode_longstring_noutf8(
UPB_FORCEINLINE UPB_FORCEINLINE
static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size,
int copy, char* data, upb_StringView* dst) { int copy, char* data, size_t data_offset,
upb_StringView* dst) {
d->arena.head.ptr += copy; d->arena.head.ptr += copy;
dst->data = data; dst->data = data + data_offset;
UPB_UNPOISON_MEMORY_REGION(data, copy); UPB_UNPOISON_MEMORY_REGION(data, copy);
memcpy(data, ptr, copy); memcpy(data, ptr, copy);
UPB_POISON_MEMORY_REGION(data + size, copy - size); UPB_POISON_MEMORY_REGION(data + data_offset + size,
copy - data_offset - size);
} }
#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ #define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \
@ -697,18 +699,17 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size,
\ \
if (UPB_LIKELY(size <= 15 - tagbytes)) { \ if (UPB_LIKELY(size <= 15 - tagbytes)) { \
if (arena_has < 16) goto longstr; \ if (arena_has < 16) goto longstr; \
d->arena.head.ptr += 16; \ fastdecode_docopy(d, ptr - tagbytes - 1, size, 16, buf, tagbytes + 1, \
memcpy(buf, ptr - tagbytes - 1, 16); \ dst); \
dst->data = buf + tagbytes + 1; \
} else if (UPB_LIKELY(size <= 32)) { \ } else if (UPB_LIKELY(size <= 32)) { \
if (UPB_UNLIKELY(common_has < 32)) goto longstr; \ if (UPB_UNLIKELY(common_has < 32)) goto longstr; \
fastdecode_docopy(d, ptr, size, 32, buf, dst); \ fastdecode_docopy(d, ptr, size, 32, buf, 0, dst); \
} else if (UPB_LIKELY(size <= 64)) { \ } else if (UPB_LIKELY(size <= 64)) { \
if (UPB_UNLIKELY(common_has < 64)) goto longstr; \ if (UPB_UNLIKELY(common_has < 64)) goto longstr; \
fastdecode_docopy(d, ptr, size, 64, buf, dst); \ fastdecode_docopy(d, ptr, size, 64, buf, 0, dst); \
} else if (UPB_LIKELY(size < 128)) { \ } else if (UPB_LIKELY(size < 128)) { \
if (UPB_UNLIKELY(common_has < 128)) goto longstr; \ if (UPB_UNLIKELY(common_has < 128)) goto longstr; \
fastdecode_docopy(d, ptr, size, 128, buf, dst); \ fastdecode_docopy(d, ptr, size, 128, buf, 0, dst); \
} else { \ } else { \
goto longstr; \ goto longstr; \
} \ } \
@ -917,6 +918,7 @@ static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e,
fastdecode_arr farr; \ fastdecode_arr farr; \
\ \
if (subtablep->table_mask == (uint8_t)-1) { \ if (subtablep->table_mask == (uint8_t)-1) { \
d->depth++; \
RETURN_GENERIC("submessage doesn't have fast tables."); \ RETURN_GENERIC("submessage doesn't have fast tables."); \
} \ } \
\ \

Loading…
Cancel
Save