Vertexwahn
Vertexwahn

Reputation: 8170

SEH exception on GitHub Workflow with Glog and Gtest

My project looks like this:

.bazelrc:

build:vs2022 --copt=-DWIN32_LEAN_AND_MEAN
build:vs2022 --cxxopt=/std:c++20
build:vs2022 --cxxopt=/utf-8
build:vs2022 --cxxopt=/Zc:__cplusplus
build:vs2022 --define compiler=vs2022
build:vs2022 --enable_runfiles # https://github.com/bazelbuild/bazel/issues/8843
build:vs2022 --host_copt=-DWIN32_LEAN_AND_MEAN

.bazelversion:

7.1.2

MODULE.bazel:

bazel_dep(name = "glog", version = "0.7.1")
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")

BUILD.bazel:

cc_test(
    name = "glog_test",
    size = "small",
    srcs = [
        "glog_test.cpp",
    ],
    deps = [
        "@glog",
        "@googletest//:gtest_main",
    ],
)

glog_test.cpp:

// copied from: https://github.com/google/glog/blob/master/bazel/example/main.cc

#include "gflags/gflags.h"
#include "glog/logging.h"
#include "glog/stl_logging.h"

#include <string>
#include <fstream>

#include "gmock/gmock.h"

TEST(glog, log_message) {
    FLAGS_logtostderr = true;
    google::SetLogDestination(google::GLOG_INFO, "log.txt");

    const char *argv[] = {"some_program", nullptr};
    google::InitGoogleLogging(argv[0]);

    LOG(INFO) << "Hello, world!";

    std::vector<int> x;
    x.push_back(1);
    x.push_back(2);
    x.push_back(3);
    LOG(INFO) << "ABC, it's easy as " << x;

    // Assert
    // Try to read log
    std::ifstream file("log.txt");
    //std::string str((std::istreambuf_iterator<char>(file)),
    //                std::istreambuf_iterator<char>());
    const char* test_tmpdir = std::getenv("TEST_TMPDIR");

    ASSERT_STRNE(nullptr, test_tmpdir);

    // Does not work - I guess log.txt is stored somewhere - todo: find out how to read it - or switch to parsing standard output
    //EXPECT_THAT(str, testing::HasSubstr("ABC, it's easy as"));
}

.github\workflows\bazel_windows-2022-vs2022-opt.yaml:

Bazel Windows 2022

on:
  push: {}

jobs:
  build_and_test_windows:
    name: VS2022 opt on Windows Server 2022
    runs-on: windows-2022
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Bazel test
        run: |
          bazel --output_base=C:/bazel_output_base test --test_output=errors --config=vs2022 -- //...

When I do a Bazel test within a GitHub workflow on a Windows 2022 runner I get an SHE exception:

unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.

The project can also be found on GitHub.

If I do a bazel --output_base=C:/bazel_output_base test --test_output=errors --config=vs2022 -- //... on my local Windows developer machine I do not see this error - the test does not fail on my local machine. I wonder what I am doing wrong here. I also executed this test on Ubuntu 20.04, 22.04, and macOS 12/13/14 without any problems (of course a slightly Bazel config is used in those cases).

In the past, the test was also successfully executed when Visual Studio 2022 17.9.2 (1939) was used in the CI. Since the recent switch to Visual Studio 2022 17.10.1 (1940) the test is failing in the CI.

Maybe there is some undefined behavior and VS 2022 is correct here. Any hints that make the "smoke" test green or can explain why it is failing are welcome!

UPDATE

Seems that I am not the only one that faces such issues:

More details

It seems that the new images on GitHub and Azure CI face issues with an incorrect placement of VC runtime DLLs. This pull request shows a fix can be as simple as:

 - name: Copy in the correct VC runtime DLLs (workaround for actions/runner-images#10004)
    if: runner.os == 'windows'
    run: |
      Copy-Item (Join-Path `
        ((Get-ChildItem -Directory `
            -Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Redist\MSVC\14.*" |
          Sort -Descending | Select-Object -First 1).FullName
        ) 'x64\Microsoft.VC143.CRT\*.dll') "build\bin\Release"

Nevertheless, what still remains is the question what would be a prober workaround for Bazel here?

Upvotes: 0

Views: 62

Answers (0)

Related Questions