Skip to content

Commit

Permalink
tests/qtest/tpm: Clean up remainders of swtpm
Browse files Browse the repository at this point in the history
After running "make check", there are remainders of the tpm
tests left in the /tmp directory, slowly filling it up.
Seems like "swtpm" leaves a ".lock" and a "tpm2-00.permall"
file behind, so that the g_rmdir() calls on the temporary
directories fail. Introduce a helper function to remove those
leftovers before doing the g_rmdir().

Message-Id: <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
  • Loading branch information
huth committed Oct 28, 2022
1 parent 9d711f1 commit daa8bb5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
5 changes: 2 additions & 3 deletions tests/qtest/tpm-crb-swtpm-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/

#include "qemu/osdep.h"
#include <glib/gstdio.h>

#include "libqtest.h"
#include "qemu/module.h"
Expand Down Expand Up @@ -62,9 +61,9 @@ int main(int argc, char **argv)
tpm_crb_swtpm_migration_test);
ret = g_test_run();

g_rmdir(ts.dst_tpm_path);
tpm_util_rmdir(ts.dst_tpm_path);
g_free(ts.dst_tpm_path);
g_rmdir(ts.src_tpm_path);
tpm_util_rmdir(ts.src_tpm_path);
g_free(ts.src_tpm_path);
g_free(ts.uri);

Expand Down
5 changes: 2 additions & 3 deletions tests/qtest/tpm-tis-device-swtpm-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

#include "qemu/osdep.h"
#include <glib/gstdio.h>

#include "libqtest.h"
#include "qemu/module.h"
Expand Down Expand Up @@ -66,9 +65,9 @@ int main(int argc, char **argv)
tpm_tis_swtpm_migration_test);
ret = g_test_run();

g_rmdir(ts.dst_tpm_path);
tpm_util_rmdir(ts.dst_tpm_path);
g_free(ts.dst_tpm_path);
g_rmdir(ts.src_tpm_path);
tpm_util_rmdir(ts.src_tpm_path);
g_free(ts.src_tpm_path);
g_free(ts.uri);

Expand Down
5 changes: 2 additions & 3 deletions tests/qtest/tpm-tis-swtpm-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/

#include "qemu/osdep.h"
#include <glib/gstdio.h>

#include "libqtest.h"
#include "qemu/module.h"
Expand Down Expand Up @@ -61,9 +60,9 @@ int main(int argc, char **argv)
tpm_tis_swtpm_migration_test);
ret = g_test_run();

g_rmdir(ts.dst_tpm_path);
tpm_util_rmdir(ts.dst_tpm_path);
g_free(ts.dst_tpm_path);
g_rmdir(ts.src_tpm_path);
tpm_util_rmdir(ts.src_tpm_path);
g_free(ts.src_tpm_path);
g_free(ts.uri);

Expand Down
19 changes: 19 additions & 0 deletions tests/qtest/tpm-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

#include "qemu/osdep.h"
#include <glib/gstdio.h>

#include "hw/acpi/tpm.h"
#include "libqtest.h"
Expand Down Expand Up @@ -292,3 +293,21 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu,
g_free(src_qemu_args);
g_free(dst_qemu_args);
}

/* Remove directory with remainders of swtpm */
void tpm_util_rmdir(const char *path)
{
char *filename;
int ret;

filename = g_strdup_printf("%s/tpm2-00.permall", path);
g_unlink(filename);
g_free(filename);

filename = g_strdup_printf("%s/.lock", path);
g_unlink(filename);
g_free(filename);

ret = g_rmdir(path);
g_assert(!ret);
}
1 change: 1 addition & 0 deletions tests/qtest/tpm-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu,
const char *machine_options);

void tpm_util_wait_for_migration_complete(QTestState *who);
void tpm_util_rmdir(const char *path);

#endif /* TESTS_TPM_UTIL_H */

0 comments on commit daa8bb5

Please sign in to comment.