This repository includes kernel code as a submodule, and it contains code to run integration tests.
Each integration test is organized as a setup function, and a set of tasks that interact between each other and that communicate the result of the test once it is completed.
A test_runner task is responsible for executing tests. Before running a test it calls its setup function, which instantiates the data necessary for the test, creates the tasks and yields control of the CPU, until the test is finished. The general scheme for a setup function is the following:
typedef struct SharedData {...} SharedData;
void producer_task(SharedData* data);
void consumer_task(SharedData* data);
void test_producer_consumer() {
// INSTANTIATION OF DATA NECESSARY FOR THE TEST
SharedData data = {0, true};
// INITIALIZATION OF THE TEST TASKS
create_task((void(*)(void*)) producer_task, (void*)&data, 0);
create_task((void(*)(void*)) consumer_task, (void*)&data, 0);
}
The result of a test is communicated to the test runner by signaling through a dedicated event, test_completed_event. One of the tasks running the test should post to that event and communicate the result of the test in the event message payload.
The tasks are responsible for deallocating the memory used for the test once the test is completed. The test tasks should terminate by calling the exit() syscall. Refer to this test to check out the correct behavior of test tasks.
make testto run the integration tests. When issuing this command the executable will be recompiled from scratch.- If you need to debug the code using GDB, issue
make gdb. Also this command recompiles all the suorce files. - When running the tests with GDB, in another terminal window type the following command
gdb-multiarch -q executable_file.elfto open the gdb console.
Then on gdb console typetarget remote :3333to connect to qemu via tcp.
To add a breakpoint, use the commandbreak _symbolwhere_symbolrepresents a valid memory symbol.
To let the execution begin, typecontinue; this will execute the program until the following breakpoint. Otherwise, use the commandnextto proceed to the following code line. - when the program terminates:
- in qemu terminal press
control+aand thenx - close gdb typing
quit
If you want to just run qemu (without enabling debug session), type make run
In ordet to debug using VSCode GUI, you need to install Native Debug extension (https://marketplace.visualstudio.com/items?itemName=webfreak.debug). Make sure the .vscode/launch.json file is properly configured.
"configurations": [
{
"name": "GDB",
"type": "gdb",
"request": "attach",
"cwd": "${workspaceRoot}",
"executable": "./debug/final.elf",
"target": ":3333",
"remote": true,
"gdbpath" : "/usr/bin/gdb-multiarch",
"stopAtConnect": true
}
]
- set breakpoints throughout your code
- launch simulation with qemu typing
make gdb - start a debug session using VSCode GUI (left panel -> Run and Debug). The default breakpoint is set to
ResetHandlerentry. - use VSCode GUI to debug your code
- when the program terminates, disconnect the gdb debug session (red icon of VSCode debugger GUI) and in qemu terminal press
control+aand thenx