TROPIC01 Model¶
Code in the tropic01_model/
directory is meant to be compiled under Unix-like OS. This directory offers running libtropic's functional tests and examples against the TROPIC01's Python model, so no chip or external hardware is needed.
- Functional testing is managed by CTest - it executes both the test and the model automatically, along with the creation of model configuration.
- When running examples, you need to start the model manually and then execute the example binary in a separate terminal. This applies also for the tests, if they are not run using CTest.
- Both of these points are discussed further in this text.
Warning
There are some examples which are not compatible with model, as the model does not implement all the chip's functionality. As such, those will always fail against the model. Namely:
lt_ex_fw_update
,lt_ex_show_chip_id_and_fwver
(model does not implement Bootloader mode, so you can usetests/functional/lt_test_rev_get_info_req_app.c
to get this info from the Application mode atleast).
How it Works?¶
Both processes (tests/examples and model) will talk to each other through TCP socket at 127.0.0.1:28992. The SPI layer between libtropic and model is emulated through this TCP connection. The model responses are exactly the same as from physical TROPIC01 chip.
Note
This functionality is implemented with the help of the Unix TCP HAL implemented in hal/port/unix/libtropic_port_unix_tcp.c
.
Model Setup¶
First, the model has to be installed. For that, follow the readme in the ts-tvl repository.
Next, it is possible to initialize the model with some data, so it can behave like the real provisioned chip. To do that, it is neccesary to pass a YAML configuration file to the model - see sections Model Server and Model Configuration in the ts-tvl repository. To create such a YAML configuration, the script tropic01_model/create_model_cfg.py
in libtropic repository is used (example usage follows).
Important
In the case of running tests using CTest, no manual steps for creating the model configuration or initializing the model are necessary - CTest handles this by itself. In the case of running examples (or tests without CTest), the model has to be started manually by the user and some configuration has to be applied to the model, so atleast the pairing key slot 0 is written to be able to establish a secure session.
Data, from which the tropic01_model/create_model_cfg.py
script creates the YAML configuration file for the model, can be found in provisioning_data/
directory - see Provisioning Data section for more information about the directory structure.
To create a model configuration that will initialize the model to the state which is almost identical to the provisioned chip, the tropic01_model/create_model_cfg.py
script is run as:
cd tropic01_model/
python3 create_model_cfg.py --pkg-dir <path_to_the_lab_batch_package_directory>
<path_to_the_lab_batch_package_directory>
is the path to one of the lab batch packages inside the provisioning_data/
. As a result of running the script, a file model_cfg.yml
is created, which can be passed directly to the model using the -c
flag. Running the Examples¶
- Switch to the
tropic01_model/
directory:cd tropic01_model/
-
Compile the examples:
As a result, executables for each example are built in themkdir build cd build cmake -DLT_BUILD_EXAMPLES=1 .. make
tropic01_model/build/
directory.Tip
To enable debugging symbols (e.g. to use GDB), add switch
-DCMAKE_BUILD_TYPE=Debug
when executingcmake
.To use AddressSanitizer (ASan), add switches
-DCMAKE_BUILD_TYPE=Debug
and-DLT_ASAN=1
when executingcmake
. -
Create a YAML configuration for the model from one of the lab batch packages:
As a result,python3 ../create_model_cfg.py --pkg-dir ../../provisioning_data/2025-06-27T07-51-29Z__prod_C2S_T200__provisioning__lab_batch_package/
model_cfg.yml
is created. -
In a separate terminal, start the model server (which was previously installed in a Python virtual environment) and configure it:
As a result, the model now listens on TCP port 127.0.0.1:28992.model_server tcp -c model_cfg.yml
-
In the original terminal, execute one of the built examples:
As a result, you should see an output from the example in the original terminal and a log from the model in the separate terminal../lt_ex_hello_world
Running the Tests¶
Note
It is recommended to run the tests using CTest, but if it's needed to run the tests under GDB, they can be run exactly the same way as the examples.
- Switch to the
tropic01_model/
directory:cd tropic01_model/
-
Compile the tests in this directory:
As a result, executables for each test are built in themkdir build cd build cmake -DLT_BUILD_TESTS=1 .. make
tropic01_model/build/
directory.Tip
To enable debugging symbols (e.g. to use GDB), add switch
-DCMAKE_BUILD_TYPE=Debug
when executingcmake
.To use AddressSanitizer (ASan), add switches
-DCMAKE_BUILD_TYPE=Debug
and-DLT_ASAN=1
when executingcmake
.To execute the tests with Valgrind, add switches
-DCMAKE_BUILD_TYPE=Debug
and-DLT_VALGRIND=1
when executingcmake
. Note that Valgrind will be executed automatically only when using CTest! -
Now, the tests can be run using CTest. To see available tests, run:
To select specific test(s) using regular expression, run:ctest -N
wherectest -R <test_regex>
<test_regex>
is a regular expression for the test names from the list.
To run all tests, simply run:
ctest
Tip
To enable verbose output from CTest, run ctest -V
or ctest -W
switch for even more verbose output.
To exclude some tests, run:
ctest -E <test_regex>
<test_regex>
is a regular expression for the test names from the list. After CTest finishes, it informs about the results and saves all output to the tropic01_model/build/run_logs/
directory. Output from the tests and responses from the model are saved.
Note
The model is automatically started for each test separately, so it behaves like a fresh TROPIC01 straight out of factory. All this and other handling is done by the script scripts/model_test_runner.py
, which is called by CTest.
Important
When -DLT_BUILD_EXAMPLES=1
or -DLT_BUILD_TESTS=1
are passed to CMake, there has to be a way to define the SH0 private key for the TROPIC01's pairing key slot 0, because both the examples and the tests depend on it. For this purpose, the CMake variable LT_SH0_PRIV_PATH
is used, which should hold the path to the file with the SH0 private key in PEM or DER format. By default, the path is set to the currently used lab batch package, found in ../provisioning_data/<lab_batch_package_directory>/sh0_key_pair/
. But it can be overriden by the user either from the command line when executing CMake (switch -DLT_SH0_PRIV_PATH=<path>
), or from a child CMakeLists.txt
.