generate_kos_test()

This section describes the generate_kos_test() function of the CMake library test_generator:

Function syntax

This function is declared in a file located in KasperskyOS Community Edition at the following path: toolchain/share/cmake/Modules/test-generator/generate_kos_test.cmake.

generate_kos_test(ENTITY_NAME <NAME> TEST_TYPE <TYPE> ...)

This command generates the initializing program Einit, and other artifacts necessary for building and running a test based on KasperskyOS.

Function parameters

The following parameters are available in KasperskyOS Community Edition:

The generate_kos_test() function additionally processes the GTEST_FLAGFILE_PATH environment variable that sets the path to the file containing command line parameters for Google Test.

Artifacts generated by the function

When the generate_kos_test() function is executed, the artifacts required for building and running a test in KasperskyOS are generated in the solution build directory (which is normally the directory named build).

Building and running the test

To prepare a test using the CMake library test_generator, do the following:

  1. Use the CMake command cmake_minimum_required() to specify the minimum required version of the CMake build system for the project containing the test source files.
  2. Use the CMake command include() to include the following CMake libraries in the CMake project: platform, image, test_generator.
  3. Generate an EDL description of the test either manually or by using the generate_edl_file() command.
  4. Generate an *.edl.h by using the command nk_build_edl_files().
  5. Add the generated *.edl.h file to the project by using the CMake command add_executable().
  6. Add a dependency on the CMake target of *.edl.h file generation to the original CMake target by using the command add_dependencies().
  7. Call the generate_kos_test() command with the required parameters.

The following commands are used to build and run a test:

cmake -B build -D CMAKE_TOOLCHAIN_FILE="$KOSCEDIR/toolchain/share/toolchain-aarch64-kos.cmake"

cmake -B ./build && cmake --build ./build -t kos-qemu-image-<test name>-sim

test name is the value of the ENTITY_NAME parameter.

The KasperskyOS SDK Extension for Visual Studio Code is also used for running a test. For more details, please refer to the Extension functions section that describes how to run tests.

Example

# Minimum required version of the CMake build system for the project.

cmake_minimum_required (VERSION 3.25)

# Name of the CMake project.

project (Test)

# Connect the CMake library named platform.

include (platform)

# Statically link executable files.

initialize_platform (FORCE_STATIC)

# Include the CMake library named image, which contains the solution image build scripts.

include (platform/image)

# Connect the CMake library test_generator to the project.

include (test-generator/test_generator)

# Generate an EDL file containing a description of the process class.

generate_edl_file(${PROJECT_NAME})

# Create a CMake target for generating an .edl.h file

# for the specified EDL file by using the NK compiler.

nk_build_edl_files(${PROJECT_NAME}_edl_files EDL ${EDL_FILE})

# Add the CMake target Test for generating an executable

# file containing the test by using the source code files

# of the test and the generated .edl.h file.

add_executable (${PROJECT_NAME}

<files containing source code>

$<TARGET_OBJECTS:${PROJECT_NAME}_edl_files>)

# Add a dependency:

# the edl.h file must be generated before the CMake target Test is built.

add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_edl_files)

# Call the command that generates artifacts for building the gtest test.

# 60 seconds are allotted for starting and completing one test case.

generate_kos_test(ENTITY_NAME ${PROJECT_NAME} TEST_TYPE gtest TIMEOUT 60)

Page top