Merge branch 'main' into def-benchmark

pull/13171/head
Joshua Haberman 3 years ago
commit 6616ed639b
  1. 3
      .clang-format
  2. 30
      .github/workflows/bazel_tests.yml
  3. 22
      tests/test_cpp.cc
  4. 6
      tests/test_generated_code.cc
  5. 2
      tests/test_table.cc
  6. 1
      upb/upb.c
  7. 4
      upb/upb_internal.h

@ -0,0 +1,3 @@
BasedOnStyle: Google
DerivePointerAlignment: false
PointerAlignment: Left

@ -1,4 +1,4 @@
name: Bazel Tests
name: Check ClangFormat
on:
push:
@ -10,27 +10,11 @@ on:
workflow_dispatch:
jobs:
ubuntu:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # Don't cancel all jobs if one fails.
matrix:
include:
- { CC: clang, os: ubuntu-20.04, flags: "" }
- { CC: clang, os: ubuntu-20.04, flags: "-c opt" } # Some warnings only fire with -c opt
- { CC: gcc, os: ubuntu-20.04, flags: "-c opt" }
- { CC: clang, os: ubuntu-20.04, flags: "--//:fasttable_enabled=true -- -cmake:test_generated_files" }
- { CC: clang, os: ubuntu-20.04, flags: "--config=asan -- -benchmarks:benchmark -python/..." }
- { CC: clang, os: macos-11, flags: "" }
check_clang_format:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Setup Python venv
run: rm -rf /tmp/venv && python3 -m venv /tmp/venv
- name: Install dependencies
run: sudo apt install -y ${{ matrix.install }}
if: matrix.install != ''
- name: Run tests
run: cd ${{ github.workspace }} && PATH=/tmp/venv/bin:$PATH CC=${{ matrix.CC }} bazel test --test_output=errors ... ${{ matrix.flags }}
- name: Run ClangFormat
run: find . | grep -E '\.(c|h|cc)$' | grep -E -v '^./(third_party|cmake)' | xargs clang-format -i
- name: Check for differences
run: git diff --exit-code

@ -35,11 +35,11 @@
#include <set>
#include <sstream>
#include "google/protobuf/timestamp.upb.h"
#include "google/protobuf/timestamp.upbdefs.h"
#include "gtest/gtest.h"
#include "tests/test_cpp.upb.h"
#include "tests/test_cpp.upbdefs.h"
#include "google/protobuf/timestamp.upb.h"
#include "google/protobuf/timestamp.upbdefs.h"
#include "upb/def.h"
#include "upb/def.hpp"
#include "upb/json_decode.h"
@ -155,9 +155,10 @@ TEST(Cpp, TimestampEncoder) {
upb::SymbolTable symtab;
upb::Arena arena;
upb::MessageDefPtr md(google_protobuf_Timestamp_getmsgdef(symtab.ptr()));
google_protobuf_Timestamp* timestamp_upb = google_protobuf_Timestamp_new(arena.ptr());
google_protobuf_Timestamp* timestamp_upb_decoded = google_protobuf_Timestamp_new(arena.ptr());
google_protobuf_Timestamp* timestamp_upb =
google_protobuf_Timestamp_new(arena.ptr());
google_protobuf_Timestamp* timestamp_upb_decoded =
google_protobuf_Timestamp_new(arena.ptr());
long timestamps[] = {
253402300799, // 9999-12-31T23:59:59Z
@ -168,13 +169,16 @@ TEST(Cpp, TimestampEncoder) {
-62135596800, // 0000-01-01T00:00:00Z
};
for(long timestamp: timestamps) {
for (long timestamp : timestamps) {
google_protobuf_Timestamp_set_seconds(timestamp_upb, timestamp);
char json[128];
size_t size = upb_JsonEncode(timestamp_upb, md.ptr(), NULL, 0, json, sizeof(json), NULL);
bool result = upb_JsonDecode(json, size, timestamp_upb_decoded, md.ptr(), NULL, 0, arena.ptr(), NULL);
const long timestamp_decoded = google_protobuf_Timestamp_seconds(timestamp_upb_decoded);
size_t size = upb_JsonEncode(timestamp_upb, md.ptr(), NULL, 0, json,
sizeof(json), NULL);
bool result = upb_JsonDecode(json, size, timestamp_upb_decoded, md.ptr(),
NULL, 0, arena.ptr(), NULL);
const long timestamp_decoded =
google_protobuf_Timestamp_seconds(timestamp_upb_decoded);
ASSERT_TRUE(result);
EXPECT_EQ(timestamp, timestamp_decoded);

@ -296,11 +296,13 @@ static void check_int32_map_one_entry(
EXPECT_EQ(
1, protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_size(
msg));
EXPECT_TRUE(protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_get(
EXPECT_TRUE(
protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_get(
msg, test_int32, &val));
EXPECT_EQ(val, test_int32_2);
EXPECT_FALSE(protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_get(
EXPECT_FALSE(
protobuf_test_messages_proto3_TestAllTypesProto3_map_int32_int32_get(
msg, test_int32_3, &val));
/* Test that iteration reveals a single k/v pair in the map. */

@ -460,7 +460,7 @@ TEST_P(IntTableTest, TestIntTable) {
uint32_t largest_key = 0;
std::map<uint32_t, uint32_t> m;
std::unordered_map<uint32_t, uint32_t> hm;
for (const auto& key: keys_) {
for (const auto& key : keys_) {
largest_key = UPB_MAX((int32_t)largest_key, key);
table.Insert(key, key * 2);
m[key] = key * 2;

@ -341,7 +341,6 @@ static void upb_FixLocale(char* p) {
}
}
void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) {
assert(size >= kUpb_RoundTripBufferSize);
snprintf(buf, size, "%.*g", DBL_DIG, val);

@ -61,9 +61,7 @@ struct upb_Arena {
// the beginning.
//
// The given buffer size must be at least kUpb_RoundTripBufferSize.
enum {
kUpb_RoundTripBufferSize = 32
};
enum { kUpb_RoundTripBufferSize = 32 };
void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size);
void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size);

Loading…
Cancel
Save