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:
ENTITY_NAME <NAME>Test name In combination with the ENTITY_PREFIX parameter, it forms the name of the test process class in the format <ENTITY_PREFIX>.<ENTITY_NAME>. Required parameter.
TARGET_NAME <NAME>Name of the CMake target for building the test executable file. The default value is equal to the value of the ENTITY_NAME parameter. If the process class name passed to the generate_edl_file() function differs from the CMake target name passed to the add_executable() Cmake command, the CMake target name must be passed to the generate_kos_test() function in the TARGET_NAME parameter. For more details, please refer to the example of using the generate_kos_test() function below.
ENTITY_PREFIX <PREFIX>A path to the EDL file (without the extension and dot before it) relative to the directory that is included in the set of directories where the source code generators search for IDL-, CDL- and EDL files. A dot is used as a separator in a path description. Default value: kl. In combination with the ENTITY_NAME parameter, it forms the name of the test process class in the format <ENTITY_PREFIX>.<ENTITY_NAME>.
ENTITY_HAS_VFSUnlinks the standard client transport library vfs::client from the test executable file.
CUSTOM_TARGET_PATH <PATH>Full path to the pre-built test executable file. This parameter is used together with the USE_EXTERNAL_BIN parameter.
VARIABLES <VAR1> [<VAR2>…]Environment variables passed to the test executable file at startup.
ARGUMENTS <ARG1> [<ARG2>…]Startup parameters that are passed to the test executable at startup.
WITH_NETWORKEnables configuration of the network infrastructure for the test to work.
EXTRA_QEMU_FLAGS <FLAG1> [<FLAG2>…]List of additional flags for running QEMU.
TIMEOUT <SEC>Time (in seconds) allotted for starting and completing one test case. Default value: 60.
TEST_TYPE <TYPE>Test type. Permissible value: gtest. Required parameter.
USE_EXTERNAL_BIN <ON|OFF>Use a pre-built test executable file. When this parameter is set to ON, a test executable file that is built in a build system other than CMake is used. In this case, the generate_kos_test() function generates artifacts for this executable file. The path to the pre-built test executable file is specified in the CUSTOM_TARGET_PATH parameter.
FILES_TO_COPY <FROM1>:<WHERE1>[;<FROM2>:<WHERE2>;...]List of directories and files copied to the generated disk image system_hdd.img. For more details about the system_hdd.img disk image, see the description of generated artifacts of the generate_kos_test() function. Generating a system_hdd.img image overwrites the previous image version.
WHERE<N> destination paths are generated relative to the mount point specified in the TEST_HDD_MOUNTPOINT parameter.
If the GTEST_FLAGFILE_PATH environment variable is defined, the file containing command line parameters for Google Test specified in this variable is also copied to the system_hdd.img disk image.
TEST_FS_SIZE <SIZE>Size of the file system of the generated system_hdd.img disk image. The default value is 32M.
PREBUILT_HDD_IMAGE_PATH <PATH>Path to the pre-built test disk image to be used instead of generating a new image. When this parameter is specified, the build system copies the provided image to the directory of generated artifacts: <solution build directory>/bin/tests/gtest_<target name>_images/hdd.img, where target name is the name specified in the TARGET_NAME parameter, and uses that when running the test.
EINIT_GEN_DIR <PATH>Directory containing the Einit initializing program that is generated for the test. Default value: <build directory>/generated/einit_<test name>, where test name is the CMake target specified in the ENTITY_NAME parameter.
EXTRA_XDL_DIR <DIR1>[;<DIR2>;...]Additional directories for searching EDL, CDL, and IDL files when building the Einit initializing program.
PLATFORMS <PLAT>Target platform. Permissible value: qemu. The default value is qemu.
EXTRA_TEST_ENTITIES <ENT1> [<ENT2>…]List of additional programs linked to the test.
ENABLE_EXTRA_ENT_DEPS <ON|OFF>Enables (ON) or disables (OFF) linking of additional programs to the test. This parameter is used together with the EXTRA_TEST_ENTITIES parameter.
FILES <FILE1> [<FILE2>…]Full paths to files or directories to be added to the ROMFS image. This parameter can be used together with the FSTAB_FILE parameter in which you can specify where the ROMFS image should be mounted.
FSTAB_FILE <FILE>Full path to the custom fstab file.
KOS_IMAGE_PATH <PATH>Full name of the pre-built solution image that is used instead of building a new image. If this parameter is specified, the generate_kos_test() command generates the missing artifacts without generating the solution image kos-<platform>-image-<test name>, where platform is the value of the PLATFORMS parameter, and test name is the value of the ENTITY_NAME parameter.
BINARY_PATH <PATH>Full path to the completed solution image executable file that is used together with the KOS_IMAGE_PATH parameter for tests with pre-built images.
PRESCRIPT <PATH>Path to the script that is run before starting the test.
POSTSCRIPT <PATH>Path to the script that is run after the test is complete.
WITHOUT_DETECTING <ON|OFF>Disables (ON) or enables (OFF) using a regular expression to detect test completion errors. The default value is ON.
TAGS <TAG1> [<TAG2>…]List of test tags. Tags can be used to group and filter tests.
NO_STRIP <ON|OFF>Prohibits (ON) or allows (OFF) deletion of symbol tables from the test executable file during the build process. The default value is ON.
INIT_YAML_TEMPLATE_PATH <PATH>Path to the custom init.yaml.in template used to generate the final test image init.yaml file.
SECURITY_PSL_PATH <PATH>Path to the user file of the solution security policy description (*.psl).
PSL_BUILD_TYPE <TYPE>Build type of security policies. Permissible values: stub, debug, release. The default value is debug.
EXTRA_FILES <FILE1> [<FILE2>…]List of additional files included in the test YAML configuration and copied to the test environment.
TEST_HDD_MOUNTPOINT <PATH>Mount point for the main test disk in the test image file system. The default value is /kl_test_results.
EXTRA_TEST_CONF_YAMLS <PATH1> [<PATH2>…]List of paths to additional test configuration YAML files combined with the main configuration.
FS_TYPE <TYPE>Type of file system used when creating disk images such as system_hdd.img. The default value is ext2.
FSTAB_COPY_DIR <PATH>Target directory to copy the generated fstab file into. This parameter is used together with the FSTAB_COPY_TARGET parameter.
FSTAB_COPY_TARGET <TARGET_NAME>Name of the CMake target that copies the fstab file to the directory specified in the FSTAB_COPY_DIR parameter. This target is created by the build system to perform the copy operation.
GINGER_ENABLE <ON|OFF>Enables (ON) or disables (OFF) the Ginger template engine.
GINGER_DEFINITIONS <DEF1> [<DEF2>…]The set of variables used when expanding Ginger PSL templates.
GINGER_DUMP_DIR <DIR>Path to the directory where intermediate PSL files received from Ginger PSL templates will be stored. If this parameter is not specified, the intermediate files are not saved.
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).
./bin/tests/gtest_<test target>_images/kos-qemu-image<test target>, where test target is the value of the TARGET_NAME parameter../bin/tests/gtest_<test target>.qemu.sh, where test target is the value of the TARGET_NAME parameter../bin/tests/qemu-<test target>-test-conf.yaml, where test target is the value of the TARGET_NAME parameter../bin/tests/gtest_<test name>_images/system_hdd.img, which contains the files defined in the FILES_TO_COPY parameter. After starting the test, the following will be written to the disk:output_junit.xml in the root directorygcda_tree directoryEinit initializing program for the test in the directory ./generated/einit_<test name>, where test name is the value of the ENTITY_NAME parameter./generated/fstab_<test name>/fstab, where test name is the value of the ENTITY_NAME parameter.Building and running the test
To prepare a test using the CMake library test_generator, do the following:
CMake command cmake_minimum_required() to specify the minimum required version of the CMake build system for the project containing the test source files.CMake command include() to include the following CMake libraries in the CMake project: platform, image, test_generator.generate_edl_file() command.*.edl.h by using the command nk_build_edl_files().*.edl.h file to the project by using the CMake command add_executable().CMake target of *.edl.h file generation to the original CMake target by using the command add_dependencies().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