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

View File

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