Skip to content

Commit

Permalink
[azure-pipelines] build matrix (#111)
Browse files Browse the repository at this point in the history
* [auzre-pipelines] linux build matrix

* [azure-pipelines] matrix pipeline

* add tests and consideration toward 0.3

corrected typo in README.md

Update README.md
  • Loading branch information
Raffaello committed May 13, 2020
1 parent c78af53 commit 350683e
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 10 deletions.
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
|[![Build status](https://ci.appveyor.com/api/projects/status/67mildjynhnlekk5/branch/master?svg=true)](https://ci.appveyor.com/project/Raffaello/sdl2-vga-terminal/branch/master)| secondary check|
|[![Build Status](https://dev.azure.com/raffaellobertini/sdl2-vga-terminal/_apis/build/status/Raffaello.sdl2-vga-terminal?branchName=master)](https://dev.azure.com/raffaellobertini/sdl2-vga-terminal/_build/latest?definitionId=4&branchName=master)| disabled|

| Linux (x64) | Windows (x86, x64) | macOS (x64) | Analyzer (WIN) |
|:-----------:|:------------------:|:-----------:|:--------------:|
| Linux (x64) | Windows (x86, x64) | macOS (x64) | Analyzer |
|:-----------:|:------------------:|:-----------:|:---------:|
|[![Build Status](https://dev.azure.com/raffaellobertini/sdl2-vga-terminal/_apis/build/status/Raffaello.sdl2-vga-terminal.Linux?branchName=master)](https://dev.azure.com/raffaellobertini/sdl2-vga-terminal/_build/latest?definitionId=6&branchName=master)|[![Build Status](https://dev.azure.com/raffaellobertini/sdl2-vga-terminal/_apis/build/status/Raffaello.sdl2-vga-terminal.Windows?branchName=master)](https://dev.azure.com/raffaellobertini/sdl2-vga-terminal/_build/latest?definitionId=7&branchName=master)|[![Build Status](https://dev.azure.com/raffaellobertini/sdl2-vga-terminal/_apis/build/status/Raffaello.sdl2-vga-terminal.MacOS?branchName=master)](https://dev.azure.com/raffaellobertini/sdl2-vga-terminal/_build/latest?definitionId=8&branchName=master)|[![Build Status](https://dev.azure.com/raffaellobertini/sdl2-vga-terminal/_apis/build/status/Raffaello.sdl2-vga-terminal.Analyzer?branchName=master)](https://dev.azure.com/raffaellobertini/sdl2-vga-terminal/_build/latest?definitionId=9&branchName=master)|

## SonarCloud
Expand All @@ -29,6 +29,34 @@
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Raffaello_sdl2-vga-terminal&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=Raffaello_sdl2-vga-terminal)


## Azure Pipelines

there are 5 pipelines, 1 for each OS and one dedicated to "Analysis", plus 1 for matrix build.

- the CI pipelines related to each OS are building multiple times based on the below matrix.
The result of the tests are published in Azure Devops as well through `ctest -T Test` flag.

- the Analysis pipeline is analyzing the code, generating coverage and publish to codecov and SonarCloud
- the Matrix pipeline is an overkill so it is just triggered manually when required.

The Matrix build is reflecting this table:

| FLAGS\OS | Windows | Linux | macos |
|:--------------------:|:------------------:|:------------------:|:------------------:|
| Debug | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| Release | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| BUILD_SHARED_LIBS | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| WITH_SDL2_STATIC | :heavy_check_mark: | only | only |
| BUILD_TESTING | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| BUILD_EXAMPLES | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| BUILD_SNAPSHOT | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| TEST_DUMP_SNAPSHOT | :no_entry: | :no_entry: | :no_entry: |
| ENABLE_CODE_COVERAGE | :no_entry_sign: | :no_entry_sign: | :heavy_check_mark: |

- code coverage available only with LLVM and GCC in `cmake`, on CI working only on macos
- `TEST_DUMP_SNAPSHOT` is "forbidden" to test for the build as an helper flag only.


## Synopsis

It is just a VGA font terminal using SDL2.
Expand Down Expand Up @@ -88,5 +116,6 @@ Just as a convention.

## Projects Idea to be done in the future

- `VgaTerminal Snake` (retro-gaming style snake in an emulated DOS Text mode)
- `VgaTerminal Tetris` (retro-gaming style Tetris in an emulated DOS Text Mode)
- `VT Snake` (retro-gaming style snake in an emulated DOS Text Mode)
- `VT Tetris` (retro-gaming style Tetris in an emulated DOS Text Mode)
- `VT Pong` (retro-gaming style Pong in an emulated DOS Text Mode)
9 changes: 5 additions & 4 deletions azure-pipelines/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ variables:
- template: variables/global.yml
- template: variables/images.yml
- template: variables/build_switches.yml

stages:
- stage: Dep
jobs:
Expand All @@ -43,12 +43,13 @@ stages:

- stage: CI
jobs:
- job: Linux
- job: linux
displayName: Linux GCC
strategy:
matrix:
GCC Debug:
Debug:
CONFIGURATION: Debug
GCC Release:
Release:
CONFIGURATION: Release
pool:
vmImage: ${{ variables.linux_image }}
Expand Down
94 changes: 94 additions & 0 deletions azure-pipelines/matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
### Trigger only on tags or on github pre-release and make the other depending on this one?
### this is succeful by default if not running..

# trigger:
# branches:
# include:
# - master
# paths:
# exclude:
# #- .gitignore
# - .github/*
# - README.md
# - appveyor.yml
# tags:
# include:
# - '*'

# pr:
# branches:
# include:
# - master
# paths:
# exclude:
# #- .gitignore
# - .github/*
# - README.md
# - appveyor.yml
# - LICENSE

trigger: none
pr: none

variables:
- template: variables/global.yml
- template: variables/images.yml
- template: variables/build_switches.yml

stages:
- stage: Dep
jobs:
- job: vcpkg
strategy:
matrix:
linux:
vmImageName: ${{ variables.linux_image }}
triplet: x64-linux
windows:
vmImageName: ${{ variables.windows_image }}
triplet: x64-windows
macos:
vmImageName: ${{ variables.mac_image }}
triplet: x64-osx
pool:
vmImage: $(vmImageName)
steps:
- template: templates/dep-vcpkg-steps.yml
parameters:
vcpkg_key_cache: $(CACHE_VCPKG_KEY)
triplet: $(triplet)

### split in stages for each OS depending on stage dep
- stage: matrix_linux
displayName: Matrix Linux
dependsOn: Dep
jobs:
- template: 'templates/matrix-job.yml'
parameters:
jobName: "linux"
vmImageName: ${{ variables.linux_image }}
triplet: x64-linux
sdl2_static: ['ON']
enable_code_coverage: ['OFF']
- stage: matrix_windows
displayName: Matrix Windows
dependsOn: Dep
jobs:
- template: 'templates/matrix-job.yml'
parameters:
jobName: "windows"
vmImageName: ${{ variables.windows_image }}
triplet: x64-windows
arch: 64
enable_code_coverage: ['OFF']
cmake_ignore_path: $(CMAKE_IGNORE_PATH_WIN)
- stage: matrix_macos
displayName: Matrix MacOS
dependsOn: Dep
jobs:
- template: 'templates/matrix-job.yml'
parameters:
jobName: "macos"
vmImageName: ${{ variables.mac_image }}
triplet: x64-osx
sdl2_static: ['ON']
47 changes: 47 additions & 0 deletions azure-pipelines/templates/matrix-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
parameters:
configuration: ['Debug', 'Release']
sdl2_static: ['ON', 'OFF']
build_testing: ['ON', 'OFF']
build_shared_libs: ['ON', 'OFF']
build_examples: ['ON', 'OFF']
build_snapshot: ['ON', 'OFF']
enable_code_coverage: ['ON', 'OFF']
vmImageName: ''
triplet: ''
jobName: 'build_matrix'
arch: ''
cmake_ignore_path: ''

jobs:
- job: ${{ parameters.jobName }}
#displayName: ${{ parameters.jobDisplayName }}
strategy:
matrix:
${{ each configuration in parameters.configuration }}:
${{ each sdl2_static in parameters.sdl2_static}}:
${{ each build_testing in parameters.build_testing }}:
${{ each build_shared_libs in parameters.build_shared_libs }}:
${{ each build_examples in parameters.build_examples }}:
${{ each build_snapshot in parameters.build_snapshot}}:
${{ each enable_code_coverage in parameters.enable_code_coverage}}:
${{ format('{0}-{1}-{2}-{3}-{4}-{5}-{6}', configuration, sdl2_static, build_testing, build_shared_libs, build_examples, build_snapshot, enable_code_coverage) }}:
CONFIGURATION: ${{ configuration }}
SDL2_STATIC: ${{ sdl2_static }}
BUILD_TESTING: ${{ build_testing }}
BUILD_SHARED_LIBS: ${{ build_shared_libs }}
BUILD_EXAMPLES: ${{ build_examples }}
BUILD_SNAPSHOT: ${{ build_snapshot }}
ENABLE_CODE_COVERAGE: ${{ enable_code_coverage }}
pool:
vmImage: ${{ parameters.vmImageName }}
steps:
- template: 'ci-steps.yml'
parameters:
vcpkg_key_cache: $(CACHE_VCPKG_KEY)
triplet: ${{ parameters.triplet }}
build_type: $(CONFIGURATION)
arch: ${{ parameters.arch }}
cmake_ignore_path: ${{ parameters.cmake_ignore_path }}
test: false
install: false
package: false
2 changes: 1 addition & 1 deletion azure-pipelines/templates/sonarcloud-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parameters:

- name: triplet
displayName: triplet
type: string
type: string

- name: arch
displayName: arch
Expand Down
96 changes: 95 additions & 1 deletion sdl2-vga-terminal/test/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ void cmpViewportCheck(const SDL_Rect& vp, const SDL_Rect& exp)
EXPECT_EQ(vp.h, exp.h);
}

void cmpTerminalChar(const VgaTerminal::terminalChar_t& tc1, const VgaTerminal::terminalChar_t& tc2)
{
EXPECT_EQ(tc1.bgCol, tc2.bgCol);
EXPECT_EQ(tc1.c, tc2.c);
EXPECT_EQ(tc1.col, tc2.col);
}

// expect around ~1% tolerance on the given value to be matched
void cmpTicks(const uint32_t start, const uint32_t end, const uint16_t value)
{
Expand Down Expand Up @@ -85,12 +92,83 @@ TEST(VgaTerminal, ScrollDown) {
EXPECT_EQ(title[6], term.at(5, term.getMode().th - 1).c);
}

TEST(VgaTerminal, scrollDownReusingSameGridChar)
{
// TODO how to verify?
// BODY mocks and call some private method once?
std::string title = ::testing::UnitTest::GetInstance()->current_test_info()->name();
VgaTerminal term = VgaTerminal(title, SDL_WINDOW_HIDDEN, -1, 0);
term.writeXY(0, 24, "a", 7, 1);
term.writeXY(0, 23, "a", 7, 1);
VgaTerminal::terminalChar_t tc = term.at(0, 23);
term.newLine();
cmpTerminalChar(tc, term.at(0, 23));
cmpTerminalChar(VgaTerminal::terminalChar_t{ 0, 0, 0 }, term.at(0, 25));
}

TEST(VgaTerminal, doNotRenderTwiceIfAlreadyRendered)
{
// TODO: how to verify without mocking?
// BODY only with mocking at the moment i have a solution but require some restructure...
std::string title = ::testing::UnitTest::GetInstance()->current_test_info()->name();
VgaTerminal term = VgaTerminal(title, SDL_WINDOW_HIDDEN, -1, 0);
term.write("Hello", 7, 1);
term.render();
// here the expect internal method should not be used...
term.render();
}

TEST(VgaTerminal, notRenderingWhenWindowHidden)
{
// This test makes the reported code coverage not correct
// or is related to some other code, but not for this test suite,
// because render is never call.
// TODO: how to verify without mocking?
// BODY only with mocking at the moment i have a solution but require some restructure...
std::string title = ::testing::UnitTest::GetInstance()->current_test_info()->name();
VgaTerminal term = VgaTerminal(title, SDL_WINDOW_HIDDEN, -1, 0);
term.write("Hello", 7, 1);
term.render();
// expect term.renderPresent() to be called once
}

TEST(VgaTerminal, forceReRendering)
{
// TODO: how to verify without mocking?
// BODY only with mocking at the moment i have a solution but require some restructure...
std::string title = ::testing::UnitTest::GetInstance()->current_test_info()->name();
VgaTerminal term = VgaTerminal(title, 0, -1, 0);
term.write("Hello", 7, 1);
term.render();
term.render(true);
}

TEST(VgaTerminal, atOutOfViewport)
{
// TODO _defaultChar_t consideration
// BODY this test might bring the consideration to return/have something different
// rather that {0, 0, 0} when wrong input for .at
std::string title = ::testing::UnitTest::GetInstance()->current_test_info()->name();
VgaTerminal term = VgaTerminal(title, SDL_WINDOW_HIDDEN, -1, 0);
SDL_Rect vp = term.getViewport();
for (int i = 1; i < vp.w * vp.h; i++) {
term.write('X', 7, 1);
}

cmpTerminalChar(term.at(vp.w + 1, 0), VgaTerminal::terminalChar_t({ 0, 0, 0 }));

cmpTerminalChar(term.at(11, 6), VgaTerminal::terminalChar_t({ 'X', 7, 1 }));
term.setViewPort(VgaTerminal::position_t(0, 0), 10, 5);
cmpTerminalChar(term.at(11, 6), VgaTerminal::terminalChar_t({ 0, 0, 0 }));
}


TEST(VgaTerminal, moveCursorClockWise)
{
std::string title = ::testing::UnitTest::GetInstance()->current_test_info()->name();
VgaTerminal term = VgaTerminal(title, SDL_WINDOW_HIDDEN, -1, 0);

term.gotoXY(10, 10);
term.gotoXY(VgaTerminal::position_t(10, 10));
term.moveCursorLeft();
EXPECT_EQ(9, term.getX());
EXPECT_EQ(10, term.getY());
Expand Down Expand Up @@ -185,6 +263,22 @@ TEST(VgaTerminal, resetViewport)
cmpViewportCheck(vp, term.getViewport());
}

TEST(VgaTerminal, setViewportLargerThanTerminalMode)
{
using ::testing::HasSubstr;
using ::testing::EndsWith;

std::string title = ::testing::UnitTest::GetInstance()->current_test_info()->name();
VgaTerminal term = VgaTerminal(title, SDL_WINDOW_HIDDEN, -1, 0);
SDL_Rect vp = { 0, 0, term.getMode().tw + 1, term.getMode().th };

testing::internal::CaptureStderr();
EXPECT_FALSE(term.setViewPort(vp));
std::string output = testing::internal::GetCapturedStderr();
EXPECT_THAT(output, HasSubstr("WARN: ["));
EXPECT_THAT(output, EndsWith("VgaTerminal] setViewPort: viewport larger than terminal.\n"));
}

TEST(VgaTerminal, Idle)
{
std::string title = ::testing::UnitTest::GetInstance()->current_test_info()->name();
Expand Down

0 comments on commit 350683e

Please sign in to comment.