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
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ test:bl_common --build_tests_only
test:bl_common --test_tag_filters=-manual
test:bl_common --test_output=errors

# Component Integration Test configuration
build:cit --//score/json:base_library=nlohmann

# Common BaseLibs Toolchain flags for build (do not use it in case of system toolchains!)
build:bl_toolchain_common --incompatible_strict_action_env
build:bl_toolchain_common --host_platform=@score_bazel_platforms//:x86_64-linux
Expand Down
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ compile_commands.json
# docs build artifacts
_build
docs/ubproject.toml

# Python
.venv
__pycache__/
/.coverage
**/*.egg-info/*

# Vscode
.vscode*
*.orig
.venv_docs
5 changes: 5 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ docs(
],
source_dir = "docs",
)

test_suite(
name = "cit_tests",
tests = ["//tests/python_test_cases:cit_cpp"]
)
23 changes: 23 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ python.toolchain(
bazel_dep(name = "aspect_rules_py", version = "1.4.0")
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2")

## Component Integration Testing
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_dependency = True)
pip.parse(
hub_name = "pip_score_venv_test",
python_version = PYTHON_VERSION,
requirements_lock = "//tests/python_test_cases:requirements.txt.lock",
)
use_repo(pip, "pip_score_venv_test")

bazel_dep(name = "score_test_scenarios", version = "0.3.1", dev_dependency = True)

# Override until 0.3.1 is released
git_override(
module_name = "score_test_scenarios",
commit = "0452d65bb5366115041e10e30d05db585e718a21",
remote = "https://github.com/qorix-group/testing_tools.git",
)


# bazel cc rules
bazel_dep(name = "rules_cc", version = "0.1.2", dev_dependency = True)


deb = use_repo_rule("@download_utils//download/deb:defs.bzl", "download_deb")

deb(
Expand Down
3,082 changes: 2,249 additions & 833 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Component Integration Tests

For general information check [main README.md file](../README.md).

## Setup

Create `venv`, activate and install dependencies:

```bash
python -m venv <REPO_ROOT>/.venv
source <REPO_ROOT>/.venv/bin/activate
pip install -r <REPO_ROOT>/tests/python_test_cases/requirements.txt
```

## Usage

Set current working directory to the following:

```bash
cd <REPO_ROOT>/tests/python_test_cases
```

### Run tests

Basic run:

```bash
pytest .
```

Run with additional flags:

```bash
pytest -vsx . -k <PATTERN> --build-scenarios
```

- `-v` - increase verbosity.
- `-s` - show logs (disable capture).
- `-k <PATTERN>` - run tests matching the pattern.
- `--build-scenarios` - build Rust test scenarios before execution.

Run tests repeatedly:

```bash
pytest . --count <VALUE> --repeat-scope session -x
```

- `--count <VALUE>` - number of repeats.
- `--repeat-scope session` - scope of repeat.
- `-x` - exit on first error.

Refer to `pytest` manual for `pytest` specific options.
Refer to `conftest.py` for test suite specific options.

### Create HTML report

To generate HTML report use:

```bash
pytest -v . --build-scenarios --self-contained-html --html report.html --traces <VALUE>
```

- `--self-contained-html` - generate self contained HTML file.
- `--html report.html` - HTML report output path.
- `--traces <VALUE>` - verbosity of traces in output and HTML report - "none", "target" or "all".

> Traces are collected using `stdout`.
> Setting `--capture` flag (including `-s`) might cause traces to be missing from HTML report.

### Bazel execution

Run all Component Integration Tests:

```bash
bazel test //:cit_tests --config=cit
```

When the dependencies in [requirements.txt](python_test_cases/requirements.txt) file are manually modified, the user should invoke command and commit changes:

```bash
bazel run //tests/python_test_cases:requirements.update
```

In order to update all dependencies use:

```bash
bazel run //tests/python_test_cases:requirements.update -- --upgrade
```

## Standalone execution of test scenarios

Test scenarios can be run independently from `pytest`.

### C++ Scenarios

Set current working directory to the following:

```bash
cd <REPO_ROOT>/tests/cpp_test_scenarios
```

List all available scenarios:

```bash
bazel run //tests/cpp_test_scenarios:cpp_test_scenarios --config=cit -- --list-scenarios
```

Run specific test scenario:

```bash
bazel run //tests/cpp_test_scenarios:cpp_test_scenarios --config=cit -- --name <TEST_GROUP>.<TEST_SCENARIO> --input <TEST_INPUT>
```

Example:

```bash
bazel run //tests/cpp_test_scenarios:cpp_test_scenarios --config=cit -- --name basic.basic --input '{"test_logic":{"json_path":"data.json"}}'
```

Run test scenario executable directly:

```bash
<REPO_ROOT>/bazel-bin/tests/cpp_test_scenarios/cpp_test_scenarios --name basic.basic --input '{"kvs_parameters":{"instance_id":0}}'
```

Run with GDB:

```bash
bazel build //tests/cpp_test_scenarios:cpp_test_scenarios --config=cit -c dbg --strip never
gdb --args <REPO_ROOT>/bazel-bin/tests/cpp_test_scenarios/cpp_test_scenarios --name <TEST_GROUP>.<TEST_SCENARIO> --input '{"test_logic":{"json_path":"data.json"}}'
```
31 changes: 31 additions & 0 deletions tests/cpp_test_scenarios/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")


cc_binary(
name = "cpp_test_scenarios",
srcs = [
"src/main.cpp",
"src/test_basic.cpp",
"src/test_basic.hpp",
],
copts = [
"-g",
],
visibility = ["//visibility:public"],
deps = [
"//score/json:json",
"@score_test_scenarios//test_scenarios_cpp",
],
)
45 changes: 45 additions & 0 deletions tests/cpp_test_scenarios/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include <iostream>
#include <memory>
#include <string>
#include <vector>

#include "cli.hpp"
#include "scenario.hpp"
#include "test_basic.hpp"
#include "test_context.hpp"

int main(int argc, char **argv)
{
try
{
std::vector<std::string> raw_arguments{argv, argv + argc};

// Basic group.
Scenario::Ptr basic_scenario{new BasicScenario{}};
ScenarioGroup::Ptr basic_group{new ScenarioGroupImpl{"basic", {basic_scenario}, {}}};

// Root group.
ScenarioGroup::Ptr root_group{new ScenarioGroupImpl{"root", {}, {basic_group}}};

// Run.
TestContext test_context{root_group};
run_cli_app(raw_arguments, test_context);
}
catch (const std::exception &ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
}
78 changes: 78 additions & 0 deletions tests/cpp_test_scenarios/src/test_basic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include "test_basic.hpp"

#include <cassert>
#include <iostream>
#include <unordered_map>

#include "../../../score/json/json_parser.h"
#include "tracing.hpp"

namespace
{

struct TestLogic
{
std::string json_path;
};

TestLogic map_to_params(const std::string &data)
{
using namespace score::json;

JsonParser parser;
auto any_res{parser.FromBuffer(data)};
if (!any_res)
{
throw std::runtime_error{"Failed to parse JSON data"};
}
const auto &map_root{any_res.value().As<Object>().value().get().at("test_logic")};
const auto &obj_root{map_root.As<Object>().value().get()};

TestLogic params;

params.json_path = obj_root.at("json_path").As<std::string>().value();

return params;
}

const std::string kTargetName{"cpp_test_scenarios::basic::basic"};

} // namespace

std::string BasicScenario::name() const { return "basic"; }

void BasicScenario::run(const std::string &input) const
{

// Print and parse parameters.
std::cerr << input << std::endl;

auto params{map_to_params(input)};

using namespace score::json;

JsonParser parser;
auto data{parser.FromFile(params.json_path)};

// String value extraction and tracing.
std::string string_key = "string_key";
std::string value = data.value().As<Object>().value().get().at(string_key).As<std::string>().value();
TRACING_INFO(kTargetName, std::pair{string_key, value});

// Number value extraction and tracing.
std::string number_key = "number";
int number_value = data.value().As<Object>().value().get().at(number_key).As<int>().value();
TRACING_INFO(kTargetName, std::pair{number_key, number_value});
}
28 changes: 28 additions & 0 deletions tests/cpp_test_scenarios/src/test_basic.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#pragma once

#include <optional>
#include <string>

#include "scenario.hpp"

class BasicScenario final : public Scenario
{
public:
~BasicScenario() final = default;

std::string name() const final;

void run(const std::string &input) const final;
};
Loading