summaryrefslogtreecommitdiff
path: root/include/mock-variables.h
AgeCommit message (Collapse)Author
2025-01-18test-mok-mirror: minor bug fixPeter Jones
In 70366a286552760863bacb521fb00c654586b494, I introduced a test case for test-mok-mirror to test the behavior when SetVariable() gives EFI_OUT_OF_RESOURCES. Unfortunately this includes a memory error in its cleanup functions: ==1972634== Invalid read of size 8 ==1972634== at 0x4032F3: mock_sv_adjust_usage_data (mock-variables.c:468) ==1972634== by 0x40387B: mock_delete_variable (mock-variables.c:541) ==1972634== by 0x4014E8: mock_reset_variables (mock-variables.c:1353) ==1972634== by 0x401348: mock_finalize_vars_and_configs (mock-variables.c:1405) ==1972634== by 0x401731: main (test-mok-mirror.c:688) ==1972634== Address 0x1ffeffc4f8 is on thread 1's stack ==1972634== 6784 bytes below stack pointer This is caused because the test data uses a linked-list data structure in an array in the test data, and we try to iterate the list to free the data, but of course the list pointers aren't initialized because it's an array. Whoops. This patch makes it so we don't try to clean up that list, because we don't need to. Signed-off-by: Peter Jones <pjones@redhat.com>
2025-01-17tests: make it possible to use different limits for variable spacePeter Jones
This splits up the API for setting default usage limits, adding a test API function to set alternate usage limits. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-09-07mok: Fix memory leak in mok mirroringPeter Jones
Currently valgrind shows a minor issue which is not introduced in this patch series: ==2595397== ==2595397== HEAP SUMMARY: ==2595397== in use at exit: 16,368 bytes in 48 blocks ==2595397== total heap usage: 6,953 allocs, 6,905 frees, 9,146,749 bytes allocated ==2595397== ==2595397== 16,368 bytes in 48 blocks are definitely lost in loss record 1 of 1 ==2595397== at 0x4845464: calloc (vg_replace_malloc.c:1117) ==2595397== by 0x4087F2: mock_efi_allocate_pool (test.c:72) ==2595397== by 0x4098DE: UnknownInlinedFun (misc.c:33) ==2595397== by 0x4098DE: AllocateZeroPool (misc.c:48) ==2595397== by 0x403D40: get_variable_attr (variables.c:301) ==2595397== by 0x4071C4: import_one_mok_state (mok.c:831) ==2595397== by 0x4072F4: import_mok_state (mok.c:908) ==2595397== by 0x407FA6: test_mok_mirror_0 (test-mok-mirror.c:205) ==2595397== by 0x4035B2: main (test-mok-mirror.c:378) ==2595397== ==2595397== LEAK SUMMARY: ==2595397== definitely lost: 16,368 bytes in 48 blocks ==2595397== indirectly lost: 0 bytes in 0 blocks ==2595397== possibly lost: 0 bytes in 0 blocks ==2595397== still reachable: 0 bytes in 0 blocks ==2595397== suppressed: 0 bytes in 0 blocks ==2595397== This is because we're doing get_variable_attr() on the same variable more than once and saving the value to our variables table. Each additional time we do so leaks the previous one. This patch solves the issue by not getting the variable again if it's already set in the table, and adds a test case to check if we're doing get_variable() of any variety on the same variable more than once. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-09-07tests: Add a unit test for mok mirroringPeter Jones
Test that our mok mirroring doesn't ever try to delete any variable that it has previously created, and that it properly mirrors at least MokList, MokListX, and SbatLevel, at least when variables actually work. These tests will fail (rather a lot) without 7f64fd6da9458b73c4. Currently valgrind shows a memory leak in this code which is not introduced in this patch series. Since all of our memory is freed on Exit() or when kernel does ExitBootServices(), this doesn't have any significant repercussions. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-09-07tests: Add config table supportPeter Jones
This adds a simple implementation of ST->ConfigurationTable, ST->NumberOfTableEntries, and BS->InstallConfigurationTable to our test harness. Currently it is limited at 1024 entries, but that should be well more than enough for any tests we've currently considered. Signed-off-by: Peter Jones <pjones@redhat.com>
2021-09-07tests: model different behaviors for deleting variablesPeter Jones
Signed-off-by: Peter Jones <pjones@redhat.com>
2021-09-07tests: add a mock implementation of {Get,Set}Variable and tests for itPeter Jones
Some tests will need variables, and so we need a mock implementation of the various calls relating to them. This patch adds implementations for the EFI Runtime Services calls GetVariable(), SetVariable(), GetNextVariableName(), and QueryVariableInfo(). Additionally, it enforces tunable limits on storage for variables, and (with only a little work) the limits can be different for SetVariable() vs what is returned by QueryVariableInfo(). That is, it can lie to you like real systems do. Signed-off-by: Peter Jones <pjones@redhat.com>