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
68 changes: 60 additions & 8 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ jobs:
if: success() || failure()
with:
ketryx-url: ${{ vars.KETRYX_URL }}
project: ${{ vars.KETRYX_PROJECT }}
api-key: ${{ secrets.KETRYX_API_KEY }}
project: ${{ vars.KETRYX_PROJECT_EK1 }}
api-key: ${{ secrets.KETRYX_API_KEY_EK }}
commit-sha: ${{ github.event.pull_request.head.sha || github.sha }}
build-name: ci-js
test-junit-path: js-src/test-results/jest-junit.xml
Expand Down Expand Up @@ -81,12 +81,64 @@ jobs:
if: success() || failure()
with:
ketryx-url: ${{ vars.KETRYX_URL }}
project: ${{ vars.KETRYX_PROJECT }}
api-key: ${{ secrets.KETRYX_API_KEY }}
project: ${{ vars.KETRYX_PROJECT_EK1 }}
api-key: ${{ secrets.KETRYX_API_KEY_EK }}
commit-sha: ${{ github.event.pull_request.head.sha || github.sha }}
build-name: ci-java
test-junit-path: java-src/build/test-results/test/*.xml

test-cpp:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache APT packages
id: cache-apt
uses: actions/cache@v3
with:
path: /var/cache/apt
key: ${{ runner.os }}-apt-cache
restore-keys: |
${{ runner.os }}-apt-cache
- name: Cache APT lists
id: cache-apt-lists
uses: actions/cache@v3
with:
path: /var/lib/apt/lists
key: ${{ runner.os }}-apt-lists
restore-keys: |
${{ runner.os }}-apt-lists
- name: Install cmake
run: sudo apt update && sudo apt install cmake -y
- name: Use cmake
run: cmake --version
- name: Run C++ unit tests
working-directory: cpp-src
run: |
mkdir build -p
cd build
cmake ..
cmake --build .
./cpp_sorter_test --gtest_output=xml
- name: Upload test results
uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test-results-cpp
path: cpp-src/build/*.xml
retention-days: 7
if-no-files-found: error
- name: Report C++ build to Ketryx
uses: Ketryx/ketryx-github-action@v1
if: success() || failure()
with:
ketryx-url: ${{ vars.KETRYX_URL }}
project: ${{ vars.KETRYX_PROJECT_EK1 }}
api-key: ${{ secrets.KETRYX_API_KEY_EK }}
commit-sha: ${{ github.event.pull_request.head.sha || github.sha }}
build-name: ci-cpp
test-junit-path: cpp-src/build/*.xml

create-sbom:
runs-on: ubuntu-latest
steps:
Expand All @@ -103,8 +155,8 @@ jobs:
if: success() || failure()
with:
ketryx-url: ${{ vars.KETRYX_URL }}
project: ${{ vars.KETRYX_PROJECT }}
api-key: ${{ secrets.KETRYX_API_KEY }}
project: ${{ vars.KETRYX_PROJECT_EK1 }}
api-key: ${{ secrets.KETRYX_API_KEY_EK }}
commit-sha: ${{ github.event.pull_request.head.sha || github.sha }}
build-name: ci-sbom
spdx-json-path: |
Expand All @@ -121,8 +173,8 @@ jobs:
if: success() || failure()
with:
ketryx-url: ${{ vars.KETRYX_URL }}
project: ${{ vars.KETRYX_PROJECT }}
api-key: ${{ secrets.KETRYX_API_KEY }}
project: ${{ vars.KETRYX_PROJECT_EK1 }}
api-key: ${{ secrets.KETRYX_API_KEY_EK }}
commit-sha: ${{ github.event.pull_request.head.sha || github.sha }}
build-name: check-pr
check-release-status: true
59 changes: 59 additions & 0 deletions cpp-src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
cmake_minimum_required(VERSION 2.8.8)
set(PROJECT_NAME_STR google-test-examples)
project(${PROJECT_NAME_STR} C CXX)

set(CMAKE_CXX_STANDARD 14)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
get_filename_component(DEPS_ROOT "${PROJECT_BINARY_DIR}/deps" ABSOLUTE)

include(ExtProjectUtils)

find_package(Threads REQUIRED)

if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ansi -Wno-deprecated")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -ansi -Wno-deprecated")
endif()

if(MSVC)
#vc 2012 fix for vararg templates
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_VARIADIC_MAX=10")
endif()

if(WIN32)
set(_OPT_CMAKE_ARGS "-Dgtest_force_shared_crt=ON;-DCMAKE_SH=CMAKE_SH-NOTFOUND")
else()
set(_OPT_CMAKE_ARGS "")
endif()

# Will download external CMakeable project from git repo, branch "master" and install it in $DEPS_ROOT
# This also will create "googletest.git" target, which we'll use as dependency for our test project
ExtProjectGit("https://github.com/google/googletest.git" "main" ${DEPS_ROOT} CMAKE_ARGS "${_OPT_CMAKE_ARGS}")

include_directories("${DEPS_ROOT}/include")
link_directories("${DEPS_ROOT}/lib")
link_directories("${DEPS_ROOT}/lib64")

#-------------------
# set common include folder for module
#-------------------
set(COMMON_INCLUDES ${PROJECT_SOURCE_DIR}/include)

#-------------------
# Test
#-------------------
enable_testing()
include_directories(${COMMON_INCLUDES})

file(GLOB TEST_SRC_FILES ${PROJECT_SOURCE_DIR}/test/*.cpp)

# from list of files we'll create tests test_name.cpp -> test_name
foreach(_test_file ${TEST_SRC_FILES})
get_filename_component(_test_name ${_test_file} NAME_WE)
add_executable(${_test_name} ${_test_file})
add_dependencies(${_test_name} "googletest.git")
target_link_libraries(${_test_name} gtest gtest_main ${CMAKE_THREAD_LIBS_INIT})
add_test(${_test_name} ${_test_name})
set_tests_properties(${_test_name} PROPERTIES TIMEOUT 5)
endforeach()
71 changes: 71 additions & 0 deletions cpp-src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Short sample how-to use Google C++ Test Framework in cmakeable projects

1. Google test will be downloaded from GitHub and built with your project

## How to use:

1. git clone https://github.com/snikulov/google-test-examples.git
2. cd google-test-examples
3. mkdir build
4. cd build
5. cmake ..
6. cmake --build .
7. ctest -VV

## CI status:

[![Build Status](https://travis-ci.org/snikulov/google-test-examples.svg?branch=master)](https://travis-ci.org/snikulov/google-test-examples) | [![Build status](https://ci.appveyor.com/api/projects/status/t30uakdk0awxy88p/branch/master?svg=true)](https://ci.appveyor.com/project/snikulov/google-test-examples/branch/master)

## Known issues:

- TBD
---

# How to use (alternativ with docker containers)

## Get repo
```bash
$ git clone https://github.com/snikulov/google-test-examples.git
$ cd google-test-examples
```

## CMake
We can use CMake to configure/build/running tests:

### Host side
```bash
$ cmake -P build.cmake
```

### Docker Containers side
```bash
cmake -P build_with_docker.cmake
```

## Makefile

### Targets
```bash
$ make [tab]
make all
all build/Makefile configure google-test-examples_test
build clean DOCKER_COMMAND run
build_directory clean_docker_image docker_image
build_docker_image CMAKE_COMMAND DOCKER_IMAGE
```

### Configure/Build/Running tests (with docker containers)
```bash
$ make all
docker build -t atty/google-test-examples:latest --file docker/Dockerfile .
Sending build context to Docker daemon 221.2kB
Step 1/1 : FROM rikorose/gcc-cmake:latest
...
1/1 Test #1: test1 ............................ Passed 0.00 sec
100% tests passed, 0 tests failed out of 1

Total Test time (real) = 0.00 sec
```

## Screencast recording
[![asciicast](https://asciinema.org/a/a03v5lmsoph7l0lhish1jkwqo.png)](https://asciinema.org/a/a03v5lmsoph7l0lhish1jkwqo)
28 changes: 28 additions & 0 deletions cpp-src/build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 2.8)

set(build_dir ${CMAKE_CURRENT_LIST_DIR}/build)

if(NOT EXISTS ${build_dir})
file(MAKE_DIRECTORY ${build_dir})
endif()

execute_process(
COMMAND ${CMAKE_COMMAND} ..
WORKING_DIRECTORY ${build_dir}
)

execute_process(
COMMAND ${CMAKE_COMMAND} --build .
WORKING_DIRECTORY ${build_dir}
)


execute_process(
COMMAND ctest -VV
WORKING_DIRECTORY ${build_dir}
RESULT_VARIABLE test_result
)

if(${test_result})
message(FATAL_ERROR "test failed")
endif()
50 changes: 50 additions & 0 deletions cpp-src/cmake/ExtProjectUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
include(ExternalProject)
include(CMakeParseArguments)

#
# Function to inject dependency (download from git repo)
#
# Use as ExternalProjectGit( "<url to git repository>" "<tag>" "<destination>" )
# where
# - url to repository for ex. https://github.com/log4cplus/log4cplus.git
# project name will be regexed from url as latest part in our case log4cplus.git
# - tag - tag you want to use
# - destination - where to install your binaries, for example ${CMAKE_BINARY_DIR}/3rdparty
#

function(ExtProjectGit repourl tag destination)

message(STATUS "Get external project from: ${repourl} : ${tag}")

string(REGEX MATCH "([^\\/]+)[.]git$" _name ${repourl})
message(STATUS "_name = ${_name}")

set(options)
set(oneValueArgs)
set(multiValueArgs CMAKE_ARGS)
cmake_parse_arguments(ExtProjectGit "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set(cmake_cli_args -DCMAKE_INSTALL_PREFIX=${destination}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
if(CMAKE_TOOLCHAIN_FILE)
get_filename_component(_ft_path ${CMAKE_TOOLCHAIN_FILE} ABSOLUTE)
get_filename_component(_cm_rt_opath ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ABSOLUTE)
set(cmake_cli_args ${cmake_cli_args}
-DCMAKE_TOOLCHAIN_FILE=${_ft_path}
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${_cm_rt_opath})
endif()

foreach(cmake_key ${ExtProjectGit_CMAKE_ARGS})
set(cmake_cli_args ${cmake_key} ${cmake_cli_args})
endforeach()

message(STATUS "ARGS for ExternalProject_Add(${name}): ${cmake_cli_args}")
message(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")

ExternalProject_Add(${_name}
GIT_REPOSITORY ${repourl}
GIT_TAG ${tag}
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} ${cmake_cli_args} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
PREFIX "${destination}"
INSTALL_DIR "${destination}")
endfunction()
12 changes: 12 additions & 0 deletions cpp-src/include/cpp_sorter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#if !defined(CPP_SORTER_H_)
#define CPP_SORTER_H_

// simple sorter for arrays
template <typename T>
void array_sort(T * arr, size_t len)
{
std::sort(arr, arr+len);
}

#endif

Empty file added cpp-src/src/cpp_sort_impl.cpp
Empty file.
42 changes: 42 additions & 0 deletions cpp-src/test/cpp_sorter_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <algorithm>

#include "cpp_sorter.h"
#include "gtest/gtest.h"

TEST(cpp_sorter_test, null_term_str_sort)
{
RecordProperty("tested-item-id", "KXITM4XS49623PY9F2BFRA2S67Y2JSJ");

char arr[] = "abcdefghab";
char eq[] = "aabbcdefgh";
int sz = sizeof(arr)/sizeof(arr[0]) - 1; // we need it, to avoid terminating \0 in "" definition case

array_sort(arr, sz);

for(int i=0; i<sz; i++)
EXPECT_EQ(arr[i], eq[i]);
}

TEST(cpp_sorter_test, char_arr_sort)
{
char arr[] = {'a','b','c','d','e','f','g','h','a','b'};
char eq[] = {'a','a','b','b','c','d','e','f','g','h'};
int sz = sizeof(arr)/sizeof(arr[0]);

array_sort(arr, sz);

for(int i=0; i<sz; i++)
EXPECT_EQ(arr[i], eq[i]);
}

TEST(cpp_sorter_test, int_arr_sort)
{
int arr[] = {9,8,7,6,5,4,3,2,1,0};
int eq[] = {0,1,2,3,4,5,6,7,8,9};
int sz = sizeof(arr)/sizeof(arr[0]);

array_sort(arr, sz);

for(int i=0; i<sz; i++)
EXPECT_EQ(arr[i], eq[i]);
}
6 changes: 3 additions & 3 deletions java-src/src/main/java/com/ketryx/sample/SensorReading.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.ketryx.sample;

/**
* Utility class to read sensor.
* A module that calculates and displays risk scores for coronary events based on model predictions.
*
* @itemId:SensorReading
* @itemTitle:"Sensor Reading (Java)"
* @itemTitle:"Risk Scoring Module (Java)"
* @itemHasParent:spec-sensor-module
* @itemFulfills:CS-1,KD-20
* @itemFulfills:KD-26, KD-20
*/
public class SensorReading {
public static int readSensor(int a, int b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public class SensorReadingTest {
/**
* Tests that sensor is read correctly.
* Validates that the Risk Scoring Module accurately calculates risk scores for coronary events based on patient data.
* @tests:SensorReading
* @itemTitle:"Test Sensor Reading (Java)"
* @itemTitle:"Risk Scoring Module Validation (Java)"
*/
@Test
public void sensorReadingTest() {
Expand Down
Loading
Loading