From owner-svn-soc-all@FreeBSD.ORG Fri Sep 6 21:29:36 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 64169827 for ; Fri, 6 Sep 2013 21:29:36 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 42C4827B4 for ; Fri, 6 Sep 2013 21:29:36 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r86LTaot083398 for ; Fri, 6 Sep 2013 21:29:36 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r86LTaAc083393 for svn-soc-all@FreeBSD.org; Fri, 6 Sep 2013 21:29:36 GMT (envelope-from mattbw@FreeBSD.org) Date: Fri, 6 Sep 2013 21:29:36 GMT Message-Id: <201309062129.r86LTaAc083393@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r257040 - soc2013/mattbw/backend/jobs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Sep 2013 21:29:36 -0000 Author: mattbw Date: Fri Sep 6 21:29:35 2013 New Revision: 257040 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257040 Log: Add some tests for job/check.c. Trying to get as close to full coverage of the backend's non-database and non-backend code as possible in the time remaining. Added: soc2013/mattbw/backend/jobs/Atffile soc2013/mattbw/backend/jobs/check_test.c Modified: soc2013/mattbw/backend/jobs/check.c soc2013/mattbw/backend/jobs/check.h Added: soc2013/mattbw/backend/jobs/Atffile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/jobs/Atffile Fri Sep 6 21:29:35 2013 (r257040) @@ -0,0 +1,5 @@ +Content-Type: application/X-atf-atffile; version="1" + +prop: test-suite = "main" + +tp: check_test Modified: soc2013/mattbw/backend/jobs/check.c ============================================================================== --- soc2013/mattbw/backend/jobs/check.c Fri Sep 6 20:51:15 2013 (r257039) +++ soc2013/mattbw/backend/jobs/check.c Fri Sep 6 21:29:35 2013 (r257040) @@ -34,20 +34,20 @@ #include "check.h" /* jobs_check_... */ static bool check_package(struct pkg *pkg, struct query_id *query_ids, guint count, bool reject_non_updates); -static bool jobs_check_id_on_package(struct pkg *pkg, struct query_id *query_id, const char *namever); static struct pkg *jobs_check_query_ids(struct pkg_jobs *jobs, struct query_id *query_ids, guint count, bool reject_non_updates); -/* Checks a solved job against a string vector of PackageIDs to ensure any +/* + * Checks a solved job against a string vector of PackageIDs to ensure any * packages that match the PackageIDs match them fully. - * - * Returns NULL if the check succeeded, and a struct pkg if that package - * failed the check. + * + * Returns NULL if the check succeeded, and a struct pkg if that package failed + * the check. */ -struct pkg * +struct pkg * jobs_check_package_ids(struct pkg_jobs *jobs, gchar **package_ids, guint count, bool reject_non_updates) { - struct pkg *package; + struct pkg *package; struct query_id *query_ids; assert(jobs != NULL); @@ -63,11 +63,17 @@ package = jobs_check_query_ids(jobs, query_ids, count, reject_non_updates); } - return package; } -static bool +/* + * Checks a package and its pre-computed namever against a Query ID to ensure + * that if the ID refers to the same package name and version, the + * architecture and repository also match. + * + * Exposed publicly to allow for unit testing. + */ +bool jobs_check_id_on_package(struct pkg *pkg, struct query_id *query_id, const char *namever) { @@ -85,11 +91,9 @@ /* Does the rest of the PackageID match up? */ success = query_check_package(pkg, query_id); } - return success; } - static struct pkg * jobs_check_query_ids(struct pkg_jobs *jobs, struct query_id *query_ids, guint count, bool reject_non_updates) @@ -111,9 +115,9 @@ count, reject_non_updates); } else if (err == EPKG_END) { /* - * Only return a package if it failed to match. - * If we've reached this far all of them have - * matched, so don't return one! + * Only return a package if it failed to match. If + * we've reached this far all of them have matched, + * so don't return one! */ package = NULL; break; @@ -127,17 +131,17 @@ } /* - * Checks a single job target package against a set of candidate - * query IDs to make sure that the originally requested packages in - * the job have been resolved properly. - */ + * Checks a single job target package against a set of candidate query IDs to + * make sure that the originally requested packages in the job have been + * resolved properly. + */ static bool check_package(struct pkg *package, struct query_id *query_ids, guint count, bool reject_non_updates) { bool success; guint i; - char *namever; + char *namever; assert(package != NULL); @@ -147,12 +151,10 @@ if (namever == NULL) { success = false; } - for (i = 0; i < count; i++) { if (!success) { break; } - assert(success); success = jobs_check_id_on_package(package, query_ids + i, Modified: soc2013/mattbw/backend/jobs/check.h ============================================================================== --- soc2013/mattbw/backend/jobs/check.h Fri Sep 6 20:51:15 2013 (r257039) +++ soc2013/mattbw/backend/jobs/check.h Fri Sep 6 21:29:35 2013 (r257040) @@ -25,6 +25,9 @@ #include /* bool */ #include "../pkg.h" /* pkg_... */ +#include "../query/id.h" /* struct query_id */ + +bool jobs_check_id_on_package(struct pkg *pkg, struct query_id *query_id, const char *namever); struct pkg *jobs_check_package_ids(struct pkg_jobs *jobs, gchar **package_ids, guint count, bool reject_non_updates); #endif /* !_PKGNG_BACKEND_JOBS_CHECK_H_ */ Added: soc2013/mattbw/backend/jobs/check_test.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/mattbw/backend/jobs/check_test.c Fri Sep 6 21:29:35 2013 (r257040) @@ -0,0 +1,131 @@ +/*- + * Copyright (C) 2013 Matt Windsor + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include /* free */ +#include /* strcmp */ +#include "pkg.h" /* pkg... */ + +#include "check.h" /* job_check... */ +#include "../testutils.h" /* gen_pkg */ + +/* ATF/kyua tests for 'check.c'. */ + +ATF_TC(check_id_on_package_no_match); +ATF_TC_HEAD(check_id_on_package_no_match, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Ensure package/ID check succeeds if package and ID don't match."); +} +ATF_TC_BODY(check_id_on_package_no_match, tc) +{ + struct pkg *package; + struct query_id id; + + package = gen_pkg(PKG_REMOTE); + ATF_REQUIRE(package != NULL); + + id.namever = strdup("nonsuch-1.2.3"); + id.arch = strdup("freebsd:10:x86:32"); + id.repo = strdup("packagesite"); + + ATF_CHECK(jobs_check_id_on_package(package, &id, "pkg-1.1.4")); + + pkg_free(package); + free(id.namever); + free(id.arch); + free(id.repo); +} + +ATF_TC(check_id_on_package_partial_match); +ATF_TC_HEAD(check_id_on_package_partial_match, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Ensure package/ID check fails if only the namever matches."); +} +ATF_TC_BODY(check_id_on_package_partial_match, tc) +{ + struct pkg *package; + struct query_id id; + + package = gen_pkg(PKG_REMOTE); + ATF_REQUIRE(package != NULL); + + id.namever = strdup("pkg-1.1.4"); + id.arch = strdup("freebsd:10:x86:32"); + id.repo = strdup("nope"); + + ATF_CHECK(!jobs_check_id_on_package(package, &id, "pkg-1.1.4")); + + free(id.arch); + free(id.repo); + + id.arch = strdup("nope"); + id.repo = strdup("packagesite"); + + ATF_CHECK(!jobs_check_id_on_package(package, &id, "pkg-1.1.4")); + + pkg_free(package); + free(id.namever); + free(id.arch); + free(id.repo); +} + +ATF_TC(check_id_on_package_full_match); +ATF_TC_HEAD(check_id_on_package_full_match, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Ensure package/ID check succeeds if everything matches."); +} +ATF_TC_BODY(check_id_on_package_full_match, tc) +{ + struct pkg *package; + struct query_id id; + + package = gen_pkg(PKG_REMOTE); + ATF_REQUIRE(package != NULL); + + id.namever = strdup("pkg-1.1.4"); + id.arch = strdup("freebsd:10:x86:32"); + id.repo = strdup("packagesite"); + + ATF_CHECK(jobs_check_id_on_package(package, &id, "pkg-1.1.4")); + + pkg_free(package); + free(id.namever); + free(id.arch); + free(id.repo); +} + +/* + * TEST PACK + */ + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, check_id_on_package_no_match); + ATF_TP_ADD_TC(tp, check_id_on_package_partial_match); + ATF_TP_ADD_TC(tp, check_id_on_package_full_match); + + return atf_no_error(); +}