Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions data/tests/hawkey/updates.repo
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@
=Prv: walrus <= 2-5
=Req: semolina = 2
=Req: fool
=Pkg: dodo 1.0 1 noarch
=Req: dodo-dep
=Pkg: dodo-dep-a 1.0 1 noarch
=Prv: dodo-dep
=Pkg: dodo-dep-b 1.0 1 noarch
=Prv: dodo-dep
12 changes: 12 additions & 0 deletions libdnf/goal/Goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,18 @@ Goal::install(DnfPackage *new_pkg, bool optional)
packageToJob(new_pkg, &pImpl->staging, solverActions);
}

void
Goal::favor(DnfPackage *pkg)
{
queue_push2(&pImpl->staging, SOLVER_SOLVABLE|SOLVER_FAVOR, dnf_package_get_id(pkg));
}

void
Goal::disfavor(DnfPackage *pkg)
{
queue_push2(&pImpl->staging, SOLVER_SOLVABLE|SOLVER_DISFAVOR, dnf_package_get_id(pkg));
}

void
Goal::install(HySelector sltr, bool optional)
{
Expand Down
2 changes: 2 additions & 0 deletions libdnf/goal/Goal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ struct Goal {
*/
void erase(HySelector sltr, int flags);
void install(DnfPackage *new_pkg, bool optional);
void favor(DnfPackage *new_pkg);
void disfavor(DnfPackage *new_pkg);

/**
* @brief If selector ill formed, it rises std::runtime_error()
Expand Down
14 changes: 14 additions & 0 deletions libdnf/hy-goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ hy_goal_install_optional(HyGoal goal, DnfPackage *new_pkg)
return 0;
}

int
hy_goal_favor(HyGoal goal, DnfPackage *pkg)
{
goal->favor(pkg);
return 0;
}

int
hy_goal_disfavor(HyGoal goal, DnfPackage *pkg)
{
goal->disfavor(pkg);
return 0;
}

gboolean
hy_goal_install_selector(HyGoal goal, HySelector sltr, GError **error) try
{
Expand Down
18 changes: 18 additions & 0 deletions libdnf/hy-goal.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ int hy_goal_install(HyGoal goal, DnfPackage *new_pkg);
*/
int hy_goal_install_optional(HyGoal goal, DnfPackage *new_pkg);

/**
* @brief Favor package when considering alternatives. Return value is always 0.
*
* @param goal HyGoal
* @param pkg Package to favor
* @return int
*/
int hy_goal_favor(HyGoal goal, DnfPackage *pkg);

/**
* @brief Disfavor package when considering alternatives. Return value is always 0.
*
* @param goal HyGoal
* @param pkg Package to disfavor
* @return int
*/
int hy_goal_disfavor(HyGoal goal, DnfPackage *pkg);

/**
* @brief Mark content of HySelector to install or if installed to downgrade or upgrade. Only one
* option will be chosen. It allows to downgrade dependencies if needed. If not supported
Expand Down
2 changes: 2 additions & 0 deletions libdnf/hy-packageset.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ int dnf_packageset_has (DnfPackageSet *pset, DnfPackage
DnfPackageSet *dnf_packageset_from_bitmap (DnfSack *sack, Map *m);
Map *dnf_packageset_get_map (DnfPackageSet *pset);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(DnfPackageSet, dnf_packageset_free)

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions tests/hawkey/README
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pigs, tour
* testing file reqiures
* tour is available as a command-line .rpm too

dodo, dodo-dep-a, dodo-dep-b
* testing favor/disfavor

=== repos/yum ===

To test loading of yum repos we need an actual yum repo. It currently consists
Expand Down
84 changes: 70 additions & 14 deletions tests/hawkey/test_goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ END_TEST

template<const char * (*getCharFromPackage)(DnfPackage*)>
static void
assert_list_names(GPtrArray *plist, ...)
assert_list_names(bool wanted, GPtrArray *plist, ...)
{
va_list names;
char *name;
Expand All @@ -437,15 +437,25 @@ assert_list_names(GPtrArray *plist, ...)
if (i++ >= count) {
fail("assert_list_names(): list too short");
}
bool found = false;
for (auto string: stringVector) {
if (strcmp(string, name) == 0) {
goto nextName;
found = true;
break;
}
}
fail_unless(false, "assert_list_names(): element '%s' not found '%zu'", name, stringVector.size());
nextName:;
if ((wanted && !found) || (!wanted && found)) {
fail_unless(false, "assert_list_names(): element '%s' %sfound '%zu'",
name, wanted ? "not ": "", stringVector.size());
}
}
// In the wanted case; we expect all the pkgs in the lists to fully
// describe each other. Otherwise, in the !wanted case we just care that
// all the passed pkg arguments are *not* found in the list, which is
// already checked above.
if (wanted) {
fail_unless(i == count, "assert_list_names(): too many items in the list (%d vs %d)", i, count);
}
fail_unless(i == count, "assert_list_names(): too many items in the list");
va_end(names);
}

Expand All @@ -460,25 +470,25 @@ START_TEST(test_goal_upgrade_all)
fail_unless(size_and_free(plist) == 0);

plist = hy_goal_list_obsoleted(goal, NULL);
assert_list_names<&dnf_package_get_name>(plist, "penny", NULL);
assert_list_names<&dnf_package_get_name>(true, plist, "penny", NULL);
g_ptr_array_unref(plist);

plist = hy_goal_list_upgrades(goal, NULL);
int implicitobsoleteusescolors = pool_get_flag(pool, POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS);
if (implicitobsoleteusescolors) {
// Fedora, Mageia
assert_list_names<&dnf_package_get_name>(
plist, "dog", "flying", "fool", "pilchard", "pilchard", NULL);
true, plist, "dog", "flying", "fool", "pilchard", "pilchard", NULL);
} else {
// openSUSE
assert_list_names<&dnf_package_get_name>(
plist, "dog", "flying", "fool", NULL);
true, plist, "dog", "flying", "fool", NULL);
}

// see all obsoletes of fool:
auto pkg = static_cast<DnfPackage *>(g_ptr_array_index(plist, 1));
GPtrArray *plist_obs = hy_goal_list_obsoleted_by_package(goal, pkg);
assert_list_names<&dnf_package_get_name>(plist_obs, "fool", "penny", NULL);
assert_list_names<&dnf_package_get_name>(true, plist_obs, "fool", "penny", NULL);
g_ptr_array_unref(plist_obs);
g_ptr_array_unref(plist);

Expand Down Expand Up @@ -735,6 +745,50 @@ START_TEST(test_goal_forcebest)
}
END_TEST

START_TEST(test_goal_favor)
{
DnfSack *sack = test_globals.sack;
HyGoal goal = hy_goal_create(sack);
HySelector sltr = hy_selector_create(sack);

hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "dodo");
hy_goal_install_selector(goal, sltr, NULL);
DnfPackage *pkg = get_latest_pkg(sack, "dodo-dep-a");
hy_goal_favor(goal, pkg);
fail_if(hy_goal_run_flags(goal, DNF_NONE));
GPtrArray *plist = hy_goal_list_installs(goal, NULL);
assert_list_names<&dnf_package_get_name>(true, plist, "dodo", "dodo-dep-a", NULL);
assert_list_names<&dnf_package_get_name>(false, plist, "dodo-dep-b", NULL);
g_ptr_array_unref(plist);

g_object_unref(pkg);
hy_selector_free(sltr);
hy_goal_free(goal);
}
END_TEST

START_TEST(test_goal_disfavor)
{
DnfSack *sack = test_globals.sack;
HyGoal goal = hy_goal_create(sack);
HySelector sltr = hy_selector_create(sack);

hy_selector_set(sltr, HY_PKG_NAME, HY_EQ, "dodo");
hy_goal_install_selector(goal, sltr, NULL);
DnfPackage *pkg = get_latest_pkg(sack, "dodo-dep-a");
hy_goal_disfavor(goal, pkg);
fail_if(hy_goal_run_flags(goal, DNF_NONE));
GPtrArray *plist = hy_goal_list_installs(goal, NULL);
assert_list_names<&dnf_package_get_name>(true, plist, "dodo", "dodo-dep-b", NULL);
assert_list_names<&dnf_package_get_name>(false, plist, "dodo-dep-a", NULL);
g_ptr_array_unref(plist);

g_object_unref(pkg);
hy_selector_free(sltr);
hy_goal_free(goal);
}
END_TEST

START_TEST(test_goal_installonly)
{
const char *installonly[] = {"fool", NULL};
Expand Down Expand Up @@ -766,10 +820,10 @@ START_TEST(test_goal_installonly_upgrade_all)
fail_if(hy_goal_run_flags(goal, DNF_NONE));

GPtrArray *plist = hy_goal_list_erasures(goal, NULL);
assert_list_names<&dnf_package_get_name>(plist, "penny", NULL);
assert_list_names<&dnf_package_get_name>(true, plist, "penny", NULL);
g_ptr_array_unref(plist);
plist = hy_goal_list_installs(goal, NULL);
assert_list_names<&dnf_package_get_name>(plist, "fool", NULL);
assert_list_names<&dnf_package_get_name>(true, plist, "fool", NULL);
g_ptr_array_unref(plist);

int implicitobsoleteusescolors = pool_get_flag(pool, POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS);
Expand Down Expand Up @@ -920,18 +974,18 @@ START_TEST(test_goal_distupgrade_all_keep_arch)
if (implicitobsoleteusescolors) {
// Fedora, Mageia
assert_iueo(goal, 0, 5, 0, 1);
assert_list_names<&dnf_package_get_nevra>(plist, "dog-1-2.x86_64", "fool-1-5.noarch",
assert_list_names<&dnf_package_get_nevra>(true, plist, "dog-1-2.x86_64", "fool-1-5.noarch",
"flying-3.1-0.x86_64", "pilchard-1.2.4-1.x86_64", "pilchard-1.2.4-1.i686", NULL);
} else {
// openSUSE
assert_iueo(goal, 0, 4, 0, 1);
assert_list_names<&dnf_package_get_nevra>(plist, "dog-1-2.x86_64", "fool-1-5.noarch",
assert_list_names<&dnf_package_get_nevra>(true, plist, "dog-1-2.x86_64", "fool-1-5.noarch",
"flying-3.1-0.x86_64", "pilchard-1.2.4-2.x86_64", NULL);
}
g_ptr_array_unref(plist);

plist = hy_goal_list_obsoleted(goal, NULL);
assert_list_names<&dnf_package_get_nevra>(plist, "penny-4-1.noarch", NULL);
assert_list_names<&dnf_package_get_nevra>(true, plist, "penny-4-1.noarch", NULL);
g_ptr_array_unref(plist);

plist = hy_goal_list_downgrades(goal, NULL);
Expand Down Expand Up @@ -1275,6 +1329,8 @@ goal_suite(void)
tcase_add_test(tc, test_goal_protected);
tcase_add_test(tc, test_goal_erase_clean_deps);
tcase_add_test(tc, test_goal_forcebest);
tcase_add_test(tc, test_goal_favor);
tcase_add_test(tc, test_goal_disfavor);
suite_add_tcase(s, tc);

tc = tcase_create("ModifiesSackState");
Expand Down
2 changes: 1 addition & 1 deletion tests/hawkey/test_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ START_TEST(test_upgrades)

HyQuery q = hy_query_create(test_globals.sack);
hy_query_filter_upgrades(q, 1);
fail_unless(query_count_results(q) == TEST_EXPECT_UPDATES_NSOLVABLES - 2);
fail_unless(query_count_results(q) == TEST_EXPECT_UPDATES_NSOLVABLES - 5);
hy_query_free(q);
}
END_TEST
Expand Down
2 changes: 1 addition & 1 deletion tests/hawkey/testshared.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define TEST_EXPECT_SYSTEM_PKGS 13
#define TEST_EXPECT_SYSTEM_NSOLVABLES TEST_EXPECT_SYSTEM_PKGS
#define TEST_EXPECT_MAIN_NSOLVABLES 14
#define TEST_EXPECT_UPDATES_NSOLVABLES 10
#define TEST_EXPECT_UPDATES_NSOLVABLES 13
#define TEST_EXPECT_YUM_NSOLVABLES 2

#ifdef __cplusplus
Expand Down