Skip to content

Commit

Permalink
Add CI testing (#2)
Browse files Browse the repository at this point in the history
Adds a test framework and CI pipeline for automated tests

The dummy test case can be deleted whenever the first real test case is
added.

All of this was taken from https://github.com/microsoft/msquic and
trimmed down.
  • Loading branch information
nigriMSFT authored Apr 22, 2024
1 parent 4142125 commit b3c37bd
Show file tree
Hide file tree
Showing 30 changed files with 3,585 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-reuse-winkernel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ jobs:
- name: Build
shell: pwsh
run: scripts/build.ps1 -Config ${{ inputs.config }} -Platform ${{ inputs.plat }} -Arch ${{ inputs.arch }}
- name: Sign Kernel
shell: pwsh
run: scripts/sign.ps1 -Config ${{ inputs.config }} -Arch ${{ inputs.arch }}
- name: Upload build artifacts
uses: actions/upload-artifact@1746f4ab65b179e0ea60a494b83293b640dd5bba
with:
Expand Down
165 changes: 165 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
name: BVT

on:
workflow_dispatch:
push:
branches:
- main
- release/*
pull_request:
branches:
- main
- release/*

concurrency:
# Cancel any workflow currently in progress for the same PR.
# Allow running concurrently with any other commits.
group: bvt-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

permissions: read-all

jobs:
build-windows-kernel:
name: Build WinKernel
strategy:
fail-fast: false
matrix:
vec: [
{ config: "Debug", plat: "winkernel", os: "windows-2022", arch: "x64" },
{ config: "Release", plat: "winkernel", os: "windows-2022", arch: "x64" }
]
uses: ./.github/workflows/build-reuse-winkernel.yml
with:
config: ${{ matrix.vec.config }}
plat: ${{ matrix.vec.plat }}
os: ${{ matrix.vec.os }}
arch: ${{ matrix.vec.arch }}

build-windows:
name: Build WinUser
strategy:
fail-fast: false
matrix:
vec: [
{ config: "Debug", plat: "windows", os: "windows-2022", arch: "x64" },
{ config: "Release", plat: "windows", os: "windows-2022", arch: "x64" }
]
uses: ./.github/workflows/build-reuse-win.yml
with:
config: ${{ matrix.vec.config }}
plat: ${{ matrix.vec.plat }}
os: ${{ matrix.vec.os }}
arch: ${{ matrix.vec.arch }}

build-unix:
name: Build Unix
strategy:
fail-fast: false
matrix:
vec: [
{ config: "Debug", plat: "linux", os: "ubuntu-20.04", arch: "x64" },
{ config: "Release", plat: "linux", os: "ubuntu-20.04", arch: "x64" },
{ config: "Debug", plat: "linux", os: "ubuntu-22.04", arch: "x64" },
{ config: "Release", plat: "linux", os: "ubuntu-22.04", arch: "x64" }
]
uses: ./.github/workflows/build-reuse-unix.yml
with:
config: ${{ matrix.vec.config }}
plat: ${{ matrix.vec.plat }}
os: ${{ matrix.vec.os }}
arch: ${{ matrix.vec.arch }}

bvt:
name: BVT
needs: [build-windows, build-unix]
strategy:
fail-fast: false
matrix:
vec: [
{ config: "Debug", plat: "linux", os: "ubuntu-20.04", arch: "x64" },
{ config: "Release", plat: "linux", os: "ubuntu-20.04", arch: "x64" },
{ config: "Debug", plat: "linux", os: "ubuntu-22.04", arch: "x64" },
{ config: "Release", plat: "linux", os: "ubuntu-22.04", arch: "x64" },
{ config: "Debug", plat: "windows", os: "windows-2019", arch: "x64" },
{ config: "Release", plat: "windows", os: "windows-2019", arch: "x64" },
{ config: "Debug", plat: "windows", os: "windows-2022", arch: "x64" },
{ config: "Release", plat: "windows", os: "windows-2022", arch: "x64" }
]
runs-on: ${{ matrix.vec.os }}
steps:
- name: Checkout repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- name: Download Build Artifacts
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427
if: matrix.vec.plat == 'windows'
with: # note we always use binaries built on windows-2022.
name: ${{ matrix.vec.config }}-${{ matrix.vec.plat }}-windows-2022-${{ matrix.vec.arch }}
path: artifacts
- name: Download Build Artifacts
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427
if: matrix.vec.plat == 'linux'
with:
name: ${{ matrix.vec.config }}-${{ matrix.vec.plat }}-${{ matrix.vec.os }}-${{ matrix.vec.arch }}-
path: artifacts
- name: Fix permissions for Unix
if: matrix.vec.plat == 'linux' || matrix.vec.plat == 'macos'
run: |
sudo chmod -R 777 artifacts
- name: Prepare Machine
run: scripts/prepare-machine.ps1 -ForTest
shell: pwsh
- name: Test
if: matrix.vec.os == 'WinServerPrerelease'
shell: pwsh
timeout-minutes: 5
run: scripts/test.ps1 -Config ${{ matrix.vec.config }} -Arch ${{ matrix.vec.arch }} -GHA -GenerateXmlResults
- name: Test
if: matrix.vec.os != 'WinServerPrerelease'
shell: pwsh
timeout-minutes: 5
run: scripts/test.ps1 -Config ${{ matrix.vec.config }} -Arch ${{ matrix.vec.arch }} -OsRunner ${{ matrix.vec.os }} -GHA -GenerateXmlResults
- name: Upload on Failure
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
if: failure()
with:
name: BVT-${{ matrix.vec.config }}-${{ matrix.vec.plat }}-${{ matrix.vec.os }}-${{ matrix.vec.arch }}
path: artifacts

bvt-kernel:
name: BVT Kernel
needs: [build-windows, build-windows-kernel]
strategy:
fail-fast: false
matrix:
vec: [
{ config: "Debug", plat: "winkernel", os: "windows-2022", arch: "x64" },
{ config: "Release", plat: "winkernel", os: "windows-2022", arch: "x64" }
]
runs-on: ${{ matrix.vec.os }}
steps:
- name: Checkout repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- name: Download Build Artifacts
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427
with: # note we always use binaries built on windows-2022.
name: ${{ matrix.vec.config }}-${{ matrix.vec.plat }}-windows-2022-${{ matrix.vec.arch }}
path: artifacts
- name: Download Build Artifacts for Testing From WinUser
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427
with: # note we always use binaries built on windows-2022.
name: ${{ matrix.vec.config }}-windows-windows-2022-${{ matrix.vec.arch }}
path: artifacts
- name: Prepare Machine
shell: pwsh
run: scripts/prepare-machine.ps1 -ForTest -ForKernel
- name: Test
shell: pwsh
timeout-minutes: 5
run: scripts/test.ps1 -Config ${{ matrix.vec.config }} -Arch ${{ matrix.vec.arch }} -GHA -GenerateXmlResults -Kernel
- name: Upload on Failure
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
if: failure()
with:
name: BVT-Kernel-${{ matrix.vec.config }}-${{ matrix.vec.plat }}-${{ matrix.vec.os }}-${{ matrix.vec.arch }}
path: artifacts
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
# "bin" is used by this project
#[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
[Bb]uild/

# Visual Studio 2015/2017 cache/options directory
.vs/
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/googletest"]
path = submodules/googletest
url = https://github.com/google/googletest
53 changes: 53 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ message(STATUS "Platform: ${CX_PLATFORM}")
set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)")
set(SELF_DIR "$\{SELF_DIR\}")

option(CXPLAT_BUILD_TEST "Builds the test code" OFF)
option(CXPLAT_UWP_BUILD "Build for UWP" OFF)
option(CXPLAT_GAMECORE_BUILD "Build for GameCore" OFF)
option(CXPLAT_EMBED_GIT_HASH "Embed git commit hash in the binary" ON)
Expand All @@ -87,6 +88,11 @@ if (CXPLAT_GAMECORE_BUILD)
endif()
endif()

if (CXPLAT_UWP_BUILD OR CXPLAT_GAMECORE_BUILD)
message(STATUS "UWP And GameCore builds disable all executables")
set(CXPLAT_BUILD_TEST OFF)
endif()

if (NOT CXPLAT_BUILD_SHARED)
cmake_minimum_required(VERSION 3.20)
endif()
Expand Down Expand Up @@ -292,6 +298,8 @@ if(WIN32)

endif()

list(APPEND CXPLAT_COMMON_DEFINES CX_PLATFORM_WINUSER)

set(CXPLAT_C_FLAGS ${CXPLAT_COMMON_FLAGS})
set(CXPLAT_CXX_FLAGS ${CXPLAT_COMMON_FLAGS} /EHsc /permissive-)

Expand All @@ -301,6 +309,9 @@ if(WIN32)
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG /IGNORE:4075 /DEBUG /OPT:REF /OPT:ICF")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG /IGNORE:4075 /DEBUG /OPT:REF /OPT:ICF")

message(STATUS "Configuring for statically-linked CRT")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

else() #!WIN32
# Custom build flags.

Expand Down Expand Up @@ -338,3 +349,45 @@ endif()

# Product code
add_subdirectory(src/lib/)

# Test code
if(CXPLAT_BUILD_TEST)
include(FetchContent)

enable_testing()

# Build the googletest framework.

# Enforce static builds for test artifacts
set(PREV_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} CACHE INTERNAL "")
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
set(BUILD_GMOCK OFF CACHE BOOL "Builds the googlemock subproject")
set(INSTALL_GTEST OFF CACHE BOOL "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)")
FetchContent_Declare(
googletest
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/submodules/googletest
)
FetchContent_MakeAvailable(googletest)
set(BUILD_SHARED_LIBS ${PREV_BUILD_SHARED_LIBS} CACHE INTERNAL "")

set_property(TARGET gtest PROPERTY CXX_STANDARD 17)
set_property(TARGET gtest PROPERTY FOLDER "${CXPLAT_FOLDER_PREFIX}tests")

set_property(TARGET gtest_main PROPERTY CXX_STANDARD 17)
set_property(TARGET gtest_main PROPERTY FOLDER "${CXPLAT_FOLDER_PREFIX}tests")
set_property(TARGET gtest_main PROPERTY EXCLUDE_FROM_ALL ON)
set_property(TARGET gtest_main PROPERTY EXCLUDE_FROM_DEFAULT_BUILD ON)

if (HAS_SPECTRE)
target_compile_options(gtest PRIVATE /Qspectre)
target_compile_options(gtest_main PRIVATE /Qspectre)
endif()

if (HAS_GUARDCF)
target_compile_options(gtest PRIVATE /guard:cf)
target_compile_options(gtest_main PRIVATE /guard:cf)
endif()

add_subdirectory(src/test/lib)
add_subdirectory(src/test/bin)
endif()
31 changes: 31 additions & 0 deletions cxplat.kernel.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ VisualStudioVersion = 16.0.29728.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{BC8DFCC2-43CB-481C-988F-C39903116328}") = "cxplat.kernel", "src\lib\cxplat.kernel.vcxproj", "{E680F075-FEE8-421B-A9F1-DAD0A1C537D3}"
EndProject
Project("{BC8DFCC2-43CB-481C-988F-C39903116328}") = "testlib.kernel", "src\test\lib\testlib.kernel.vcxproj", "{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}"
ProjectSection(ProjectDependencies) = postProject
{E680F075-FEE8-421B-A9F1-DAD0A1C537D3} = {E680F075-FEE8-421B-A9F1-DAD0A1C537D3}
EndProjectSection
EndProject
Project("{BC8DFCC2-43CB-481C-988F-C39903116328}") = "cxplattest.kernel", "src\test\bin\winkernel\cxplattest.kernel.vcxproj", "{1E494654-9BFD-492F-BC31-36E2C73A782E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Expand All @@ -25,6 +32,30 @@ Global
{E680F075-FEE8-421B-A9F1-DAD0A1C537D3}.Release|x64.ActiveCfg = Release|x64
{E680F075-FEE8-421B-A9F1-DAD0A1C537D3}.Release|x64.Build.0 = Release|x64
{E680F075-FEE8-421B-A9F1-DAD0A1C537D3}.Release|x64.Deploy.0 = Release|x64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Debug|ARM64.ActiveCfg = Debug|ARM64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Debug|ARM64.Build.0 = Debug|ARM64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Debug|ARM64.Deploy.0 = Debug|ARM64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Debug|x64.ActiveCfg = Debug|x64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Debug|x64.Build.0 = Debug|x64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Debug|x64.Deploy.0 = Debug|x64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Release|ARM64.ActiveCfg = Release|ARM64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Release|ARM64.Build.0 = Release|ARM64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Release|ARM64.Deploy.0 = Release|ARM64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Release|x64.ActiveCfg = Release|x64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Release|x64.Build.0 = Release|x64
{6DBEB7D2-4BCF-46B2-95CB-88DEF2F049D7}.Release|x64.Deploy.0 = Release|x64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Debug|ARM64.ActiveCfg = Debug|ARM64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Debug|ARM64.Build.0 = Debug|ARM64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Debug|ARM64.Deploy.0 = Debug|ARM64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Debug|x64.ActiveCfg = Debug|x64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Debug|x64.Build.0 = Debug|x64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Debug|x64.Deploy.0 = Debug|x64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Release|ARM64.ActiveCfg = Release|ARM64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Release|ARM64.Build.0 = Release|ARM64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Release|ARM64.Deploy.0 = Release|ARM64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Release|x64.ActiveCfg = Release|x64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Release|x64.Build.0 = Release|x64
{1E494654-9BFD-492F-BC31-36E2C73A782E}.Release|x64.Deploy.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions inc/cxplat_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifndef CXPLAT_POSIX_H
#define CXPLAT_POSIX_H

#include "cxplat_sal_stub.h"

#if defined(__cplusplus)
extern "C" {
#endif
Expand Down
Loading

0 comments on commit b3c37bd

Please sign in to comment.