1load( 2 "//bazel:build_defs.bzl", 3 "UPB_DEFAULT_COPTS", 4 "UPB_DEFAULT_CPPOPTS", 5 "make_shell_script", 6) 7load( 8 "//bazel:upb_proto_library.bzl", 9 "upb_proto_library", 10 "upb_proto_reflection_library", 11) 12 13licenses(["notice"]) 14 15config_setting( 16 name = "fuzz", 17 values = {"define": "fuzz=true"}, 18) 19 20cc_library( 21 name = "upb_test", 22 testonly = 1, 23 srcs = [ 24 "testmain.cc", 25 ], 26 hdrs = [ 27 "test_util.h", 28 "upb_test.h", 29 ], 30 copts = UPB_DEFAULT_CPPOPTS, 31 deps = [ 32 "//:handlers", 33 "//:port", 34 "//:upb", 35 ], 36) 37 38proto_library( 39 name = "test_proto", 40 testonly = 1, 41 srcs = ["test.proto"], 42) 43 44upb_proto_library( 45 name = "test_upb_proto", 46 testonly = 1, 47 deps = [":test_proto"], 48) 49 50cc_test( 51 name = "test_generated_code", 52 srcs = ["test_generated_code.c"], 53 copts = UPB_DEFAULT_COPTS, 54 deps = [ 55 ":empty_upbdefs_proto", 56 ":test_messages_proto3_proto_upb", 57 ":test_upb_proto", 58 ":upb_test", 59 ], 60) 61 62proto_library( 63 name = "empty_proto", 64 srcs = ["empty.proto"], 65) 66 67upb_proto_reflection_library( 68 name = "empty_upbdefs_proto", 69 testonly = 1, 70 deps = [":empty_proto"], 71) 72 73upb_proto_library( 74 name = "test_messages_proto3_proto_upb", 75 testonly = 1, 76 deps = ["@com_google_protobuf//:test_messages_proto3_proto"], 77) 78 79proto_library( 80 name = "test_decoder_proto", 81 srcs = [ 82 "pb/test_decoder.proto", 83 ], 84) 85 86upb_proto_reflection_library( 87 name = "test_decoder_upb_proto", 88 deps = [":test_decoder_proto"], 89) 90 91cc_test( 92 name = "test_decoder", 93 srcs = ["pb/test_decoder.cc"], 94 copts = UPB_DEFAULT_CPPOPTS, 95 deps = [ 96 ":test_decoder_upb_proto", 97 ":upb_test", 98 "//:handlers", 99 "//:port", 100 "//:upb", 101 "//:upb_pb", 102 ], 103) 104 105proto_library( 106 name = "test_cpp_proto", 107 srcs = [ 108 "test_cpp.proto", 109 ], 110) 111 112upb_proto_reflection_library( 113 name = "test_cpp_upb_proto", 114 deps = ["test_cpp_proto"], 115) 116 117cc_test( 118 name = "test_cpp", 119 srcs = ["test_cpp.cc"], 120 copts = UPB_DEFAULT_CPPOPTS, 121 deps = [ 122 ":test_cpp_upb_proto", 123 ":upb_test", 124 "//:handlers", 125 "//:port", 126 "//:reflection", 127 "//:upb", 128 "//:upb_pb", 129 ], 130) 131 132cc_test( 133 name = "test_table", 134 srcs = ["test_table.cc"], 135 copts = UPB_DEFAULT_CPPOPTS, 136 deps = [ 137 ":upb_test", 138 "//:port", 139 "//:table", 140 "//:upb", 141 ], 142) 143 144# OSS-Fuzz test 145cc_binary( 146 name = "file_descriptor_parsenew_fuzzer", 147 testonly = 1, 148 srcs = ["file_descriptor_parsenew_fuzzer.cc"], 149 copts = UPB_DEFAULT_CPPOPTS + select({ 150 "//conditions:default": [], 151 ":fuzz": ["-fsanitize=fuzzer,address"], 152 }), 153 defines = select({ 154 "//conditions:default": [], 155 ":fuzz": ["HAVE_FUZZER"], 156 }), 157 deps = [ 158 "//:descriptor_upb_proto", 159 "//:upb", 160 ], 161) 162 163# copybara:strip_for_google3_begin 164cc_test( 165 name = "test_encoder", 166 srcs = ["pb/test_encoder.cc"], 167 copts = UPB_DEFAULT_CPPOPTS, 168 deps = [ 169 ":upb_test", 170 "//:descriptor_upb_proto", 171 "//:descriptor_upb_proto_reflection", 172 "//:upb", 173 "//:upb_pb", 174 ], 175) 176 177proto_library( 178 name = "test_json_enum_from_separate", 179 srcs = ["json/enum_from_separate_file.proto"], 180 deps = [":test_json_proto"], 181) 182 183proto_library( 184 name = "test_json_proto", 185 srcs = ["json/test.proto"], 186) 187 188upb_proto_reflection_library( 189 name = "test_json_upb_proto_reflection", 190 deps = ["test_json_proto"], 191) 192 193upb_proto_library( 194 name = "test_json_enum_from_separate_upb_proto", 195 deps = [":test_json_enum_from_separate"], 196) 197 198upb_proto_library( 199 name = "test_json_upb_proto", 200 deps = [":test_json_proto"], 201) 202 203cc_test( 204 name = "test_json", 205 srcs = [ 206 "json/test_json.cc", 207 ], 208 copts = UPB_DEFAULT_CPPOPTS, 209 deps = [ 210 ":test_json_upb_proto", 211 ":test_json_upb_proto_reflection", 212 ":upb_test", 213 "//:upb_json", 214 ], 215) 216# copybara:strip_end 217 218upb_proto_library( 219 name = "conformance_proto_upb", 220 testonly = 1, 221 deps = ["@com_google_protobuf//:conformance_proto"], 222) 223 224upb_proto_reflection_library( 225 name = "conformance_proto_upbdefs", 226 testonly = 1, 227 deps = ["@com_google_protobuf//:conformance_proto"], 228) 229 230upb_proto_reflection_library( 231 name = "test_messages_proto2_upbdefs", 232 testonly = 1, 233 deps = ["@com_google_protobuf//:test_messages_proto2_proto"], 234) 235 236upb_proto_reflection_library( 237 name = "test_messages_proto3_upbdefs", 238 testonly = 1, 239 deps = ["@com_google_protobuf//:test_messages_proto3_proto"], 240) 241 242cc_binary( 243 name = "conformance_upb", 244 testonly = 1, 245 srcs = [ 246 "conformance_upb.c", 247 ], 248 copts = UPB_DEFAULT_COPTS, 249 data = [ 250 "conformance_upb_failures.txt", 251 ], 252 deps = [ 253 ":conformance_proto_upb", 254 ":conformance_proto_upbdefs", 255 ":test_messages_proto2_upbdefs", 256 ":test_messages_proto3_upbdefs", 257 "//:json", 258 "//:port", 259 "//:reflection", 260 "//:textformat", 261 "//:upb", 262 ], 263) 264 265make_shell_script( 266 name = "gen_test_conformance_upb", 267 out = "test_conformance_upb.sh", 268 contents = "external/com_google_protobuf/conformance_test_runner " + 269 " --enforce_recommended " + 270 " --failure_list ./tests/conformance_upb_failures.txt" + 271 " ./tests/conformance_upb", 272) 273 274sh_test( 275 name = "test_conformance_upb", 276 srcs = ["test_conformance_upb.sh"], 277 data = [ 278 "conformance_upb_failures.txt", 279 ":conformance_upb", 280 "@com_google_protobuf//:conformance_test_runner", 281 ], 282 deps = ["@bazel_tools//tools/bash/runfiles"], 283) 284