Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/test_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,15 @@ jobs:
- name: Windows Bazel
os: windows-2022
cache_key: windows-2022-msvc-cl
bazel: test //src/... --config=msvc-cl --test_tag_filters=-conformance --build_tag_filters=-conformance
bazel: test //src/... //third_party/utf8_range/... //conformance:conformance_framework_tests --config=msvc-cl
- name: Windows Bazel C++20
os: windows-2022
cache_key: windows-2022-msvc-cl
bazel: test //src/... --config=msvc-cl --cxxopt="-std:c++20" --test_tag_filters=-conformance --build_tag_filters=-conformance
bazel: test //src/... //third_party/utf8_range/... //conformance:conformance_framework_tests --config=msvc-cl --cxxopt="-std:c++20"
- name: Windows Bazel clang-cl
os: windows-2022
cache_key: windows-2022-clang-cl
bazel: test //src/... --test_tag_filters=-conformance --build_tag_filters=-conformance
bazel: test //src/... //third_party/utf8_range/... //conformance:conformance_framework_tests
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} ${{ matrix.name }}
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -468,32 +468,32 @@ jobs:
- name: Windows CMake
os: windows-2022
flags: >-
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
-G Ninja -Dprotobuf_WITH_ZLIB=OFF
-Dprotobuf_BUILD_SHARED_LIBS=OFF
-Dprotobuf_BUILD_EXAMPLES=ON
vsversion: '2022'
cache-prefix: windows-2022-cmake
- name: Windows CMake 32-bit
os: windows-2022
flags: >-
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
-G Ninja -Dprotobuf_WITH_ZLIB=OFF
vsversion: '2022'
windows-arch: 'win32'
cache-prefix: windows-2022-win32-cmake
continuous-only: true
- name: Windows CMake Shared
os: windows-2022
flags: >-
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
-G Ninja -Dprotobuf_WITH_ZLIB=OFF
-Dprotobuf_BUILD_SHARED_LIBS=ON
vsversion: '2022'
cache-prefix: windows-2022-cmake
- name: Windows CMake Install
os: windows-2022
install-flags: >-
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
-G Ninja -Dprotobuf_WITH_ZLIB=OFF
flags: >-
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
-G Ninja -Dprotobuf_WITH_ZLIB=OFF
-Dprotobuf_REMOVE_INSTALLED_HEADERS=ON
-Dprotobuf_BUILD_PROTOBUF_BINARIES=OFF
vsversion: '2022'
Expand Down
2 changes: 2 additions & 0 deletions cmake/conformance.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ add_executable(conformance_test_runner
${conformance_runner_srcs}
${conformance_runner_hdrs}
)
protobuf_configure_target(conformance_test_runner)

add_executable(conformance_cpp
${conformance_testee_srcs}
${conformance_testee_hdrs}
)
protobuf_configure_target(conformance_cpp)

target_include_directories(
conformance_test_runner
Expand Down
6 changes: 5 additions & 1 deletion conformance/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ cc_library(

cc_library(
name = "fork_pipe_runner",
srcs = ["fork_pipe_runner.cc"],
srcs = [
"fork_pipe_runner.cc",
"fork_pipe_runner_posix.cc",
"fork_pipe_runner_win32.cc",
],
hdrs = ["fork_pipe_runner.h"],
deps = [
":conformance_cc_proto",
Expand Down
40 changes: 25 additions & 15 deletions conformance/conformance_cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
#include <errno.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>

#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <memory>
#include <string>

#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
#endif

#include "google/protobuf/any.pb.h"
#include "google/protobuf/api.pb.h"
#include "google/protobuf/duration.pb.h"
Expand Down Expand Up @@ -68,15 +72,14 @@ using TestAllTypesProto2Editions =
using TestAllTypesProto3Editions =
::protobuf_test_messages::editions::proto3::TestAllTypesProto3;

absl::Status ReadFd(int fd, char* buf, size_t len) {
absl::Status ReadFile(FILE* file, char* buf, size_t len) {
while (len > 0) {
ssize_t bytes_read = read(fd, buf, len);
size_t bytes_read = fread(buf, 1, len, file);

if (bytes_read == 0) {
return absl::DataLossError("unexpected EOF");
}

if (bytes_read < 0) {
if (feof(file)) {
return absl::DataLossError("unexpected EOF");
}
return absl::ErrnoToStatus(errno, "error reading from test runner");
}

Expand All @@ -86,9 +89,9 @@ absl::Status ReadFd(int fd, char* buf, size_t len) {
return absl::OkStatus();
}

absl::Status WriteFd(int fd, const void* buf, size_t len) {
if (static_cast<size_t>(write(fd, buf, len)) != len) {
return absl::ErrnoToStatus(errno, "error reading to test runner");
absl::Status WriteFile(FILE* file, const void* buf, size_t len) {
if (fwrite(buf, 1, len, file) != len) {
return absl::ErrnoToStatus(errno, "error writing to test runner");
}
return absl::OkStatus();
}
Expand Down Expand Up @@ -224,7 +227,7 @@ absl::StatusOr<ConformanceResponse> Harness::RunTest(

absl::StatusOr<bool> Harness::ServeConformanceRequest() {
uint32_t in_len;
if (!ReadFd(STDIN_FILENO, reinterpret_cast<char*>(&in_len), sizeof(in_len))
if (!ReadFile(stdin, reinterpret_cast<char*>(&in_len), sizeof(in_len))
.ok()) {
// EOF means we're done.
return true;
Expand All @@ -233,7 +236,7 @@ absl::StatusOr<bool> Harness::ServeConformanceRequest() {

std::string serialized_input;
serialized_input.resize(in_len);
RETURN_IF_ERROR(ReadFd(STDIN_FILENO, &serialized_input[0], in_len));
RETURN_IF_ERROR(ReadFile(stdin, &serialized_input[0], in_len));

ConformanceRequest request;
ABSL_CHECK(request.ParseFromString(serialized_input));
Expand All @@ -248,9 +251,12 @@ absl::StatusOr<bool> Harness::ServeConformanceRequest() {
uint32_t out_len = internal::little_endian::FromHost(
static_cast<uint32_t>(serialized_output.size()));

RETURN_IF_ERROR(WriteFd(STDOUT_FILENO, &out_len, sizeof(out_len)));
RETURN_IF_ERROR(WriteFd(STDOUT_FILENO, serialized_output.data(),
serialized_output.size()));
RETURN_IF_ERROR(WriteFile(stdout, &out_len, sizeof(out_len)));
RETURN_IF_ERROR(WriteFile(stdout, serialized_output.data(),
serialized_output.size()));
if (fflush(stdout) != 0) {
return absl::ErrnoToStatus(errno, "error flushing to test runner");
}

if (verbose_) {
ABSL_LOG(INFO) << "conformance-cpp: request="
Expand All @@ -264,6 +270,10 @@ absl::StatusOr<bool> Harness::ServeConformanceRequest() {
} // namespace google

int main() {
#ifdef _WIN32
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
#endif
google::protobuf::Harness harness;
int total_runs = 0;
while (true) {
Expand Down
4 changes: 3 additions & 1 deletion conformance/conformance_test_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
// 3. testee sends 4-byte length M (little endian)
// 4. testee sends M bytes representing a ConformanceResponse proto

#include <signal.h>
#include <stdio.h>
#ifndef _WIN32
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#endif

#include <algorithm>
#include <cctype>
Expand Down
Loading
Loading