tests: Port some bits of C to new style

Where we can; perhaps after updating libglnx we should use the
new test error macro?

Closes: #1169
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-09-13 12:09:51 -04:00 committed by Atomic Bot
parent 051cdf396c
commit 1c2d344074
2 changed files with 24 additions and 52 deletions

View File

@ -33,9 +33,7 @@
gboolean
ot_test_run_libtest (const char *cmd, GError **error)
{
gboolean ret = FALSE;
const char *srcdir = g_getenv ("G_TEST_SRCDIR");
int estatus;
g_autoptr(GPtrArray) argv = g_ptr_array_new ();
g_autoptr(GString) cmdstr = g_string_new ("");
@ -50,53 +48,39 @@ ot_test_run_libtest (const char *cmd, GError **error)
g_ptr_array_add (argv, cmdstr->str);
g_ptr_array_add (argv, NULL);
int estatus;
if (!g_spawn_sync (NULL, (char**)argv->pdata, NULL, G_SPAWN_SEARCH_PATH,
NULL, NULL, NULL, NULL, &estatus, error))
goto out;
return FALSE;
if (!g_spawn_check_exit_status (estatus, error))
goto out;
return FALSE;
ret = TRUE;
out:
return ret;
return TRUE;
}
OstreeRepo *
ot_test_setup_repo (GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
g_autoptr(GFile) repo_path = g_file_new_for_path ("repo");
glnx_unref_object OstreeRepo* ret_repo = NULL;
if (!ot_test_run_libtest ("setup_test_repository archive", error))
goto out;
ret_repo = ostree_repo_new (repo_path);
if (!ostree_repo_open (ret_repo, cancellable, error))
goto out;
ret = TRUE;
out:
if (ret)
return g_steal_pointer (&ret_repo);
return NULL;
g_autoptr(GFile) repo_path = g_file_new_for_path ("repo");
g_autoptr(OstreeRepo) ret_repo = ostree_repo_new (repo_path);
if (!ostree_repo_open (ret_repo, cancellable, error))
return NULL;
return g_steal_pointer (&ret_repo);
}
OstreeSysroot *
ot_test_setup_sysroot (GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
g_autoptr(GFile) sysroot_path = g_file_new_for_path ("sysroot");
glnx_unref_object OstreeSysroot *ret_sysroot = NULL;
struct statfs stbuf;
if (!ot_test_run_libtest ("setup_os_repository \"archive\" \"syslinux\"", error))
goto out;
return FALSE;
struct statfs stbuf;
{ g_autoptr(GString) buf = g_string_new ("mutable-deployments");
if (statfs ("/", &stbuf) < 0)
return glnx_null_throw_errno (error);
@ -113,11 +97,6 @@ ot_test_setup_sysroot (GCancellable *cancellable,
g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE);
}
ret_sysroot = ostree_sysroot_new (sysroot_path);
ret = TRUE;
out:
if (ret)
return g_steal_pointer (&ret_sysroot);
return NULL;
g_autoptr(GFile) sysroot_path = g_file_new_for_path ("sysroot");
return ostree_sysroot_new (sysroot_path);
}

View File

@ -260,34 +260,31 @@ import_write_and_ref (OstreeRepo *repo,
OstreeRepoCommitModifier *modifier,
GError **error)
{
gboolean ret = FALSE;
glnx_unref_object GFile *root = NULL;
g_autofree char *commit_checksum = NULL;
glnx_unref_object OstreeMutableTree *mtree = ostree_mutable_tree_new ();
g_autoptr(OstreeMutableTree) mtree = ostree_mutable_tree_new ();
if (!ostree_repo_prepare_transaction (repo, NULL, NULL, error))
goto out;
return FALSE;
if (!ostree_repo_import_archive_to_mtree (repo, opts, a, mtree, modifier,
NULL, error))
goto out;
return FALSE;
g_autoptr(GFile) root = NULL;
if (!ostree_repo_write_mtree (repo, mtree, &root, NULL, error))
goto out;
return FALSE;
g_autofree char *commit_checksum = NULL;
if (!ostree_repo_write_commit (repo, NULL, "", "", NULL,
OSTREE_REPO_FILE (root),
&commit_checksum, NULL, error))
goto out;
return FALSE;
ostree_repo_transaction_set_ref (repo, NULL, ref, commit_checksum);
if (!ostree_repo_commit_transaction (repo, NULL, NULL, error))
goto out;
return FALSE;
ret = TRUE;
out:
return ret;
return TRUE;
}
static void
@ -413,7 +410,7 @@ test_libarchive_xattr_callback (gconstpointer data)
GError *error = NULL;
g_autoptr(OtAutoArchiveRead) a = archive_read_new ();
OstreeRepoImportArchiveOptions opts = { 0 };
OstreeRepoCommitModifier *modifier = NULL;
g_autoptr(OstreeRepoCommitModifier) modifier = NULL;
char buf[7] = { 0 };
if (skip_if_no_xattr (td))
@ -452,8 +449,6 @@ test_libarchive_xattr_callback (gconstpointer data)
g_assert_cmpstr (buf, ==, "mydata");
out:
if (modifier)
ostree_repo_commit_modifier_unref (modifier);
g_assert_no_error (error);
}
@ -543,7 +538,7 @@ test_libarchive_selinux (gconstpointer data)
g_autoptr(OtAutoArchiveRead) a = archive_read_new ();
OstreeRepoImportArchiveOptions opts = { 0 };
glnx_unref_object OstreeSePolicy *sepol = NULL;
OstreeRepoCommitModifier *modifier = NULL;
g_autoptr(OstreeRepoCommitModifier) modifier = NULL;
char buf[64] = { 0 };
if (skip_if_no_xattr (td))
@ -591,8 +586,6 @@ test_libarchive_selinux (gconstpointer data)
g_assert_cmpstr (buf, ==, "system_u:object_r:etc_t:s0");
out:
if (modifier)
ostree_repo_commit_modifier_unref (modifier);
g_assert_no_error (error);
}