[pacman-dev] [PATCH] Add test directory for testing private libalpm functions.
I found this useful when testing the shortest_delta_path code. Recently, I ran valgrind on the test which helped to discover the memory leak. Not sure if you guys will want to apply this, but here it is. Signed-off-by: Nathan Jones <nathanj@insightbb.com> --- Makefile.am | 2 +- configure.ac | 1 + lib/libalpm/test/.gitignore | 3 + lib/libalpm/test/Makefile.am | 47 +++++++++++++++++ lib/libalpm/test/deltatest.c | 112 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 164 insertions(+), 1 deletions(-) create mode 100644 lib/libalpm/test/.gitignore create mode 100644 lib/libalpm/test/Makefile.am create mode 100644 lib/libalpm/test/deltatest.c diff --git a/Makefile.am b/Makefile.am index e07321b..c68786a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = lib/libalpm src/util src/pacman scripts doc etc po pactest contrib +SUBDIRS = lib/libalpm lib/libalpm/test src/util src/pacman scripts doc etc po pactest contrib # Some files automatically included, so they aren't specified below: # AUTHORS, COPYING, NEWS, README diff --git a/configure.ac b/configure.ac index 9a5f3b3..f9f27a7 100644 --- a/configure.ac +++ b/configure.ac @@ -309,6 +309,7 @@ AC_DEFINE_UNQUOTED([DBEXT], "$DBEXT", [The file extension used by pacman databas AC_CONFIG_FILES([ lib/libalpm/Makefile lib/libalpm/po/Makefile.in +lib/libalpm/test/Makefile src/pacman/Makefile src/util/Makefile scripts/Makefile diff --git a/lib/libalpm/test/.gitignore b/lib/libalpm/test/.gitignore new file mode 100644 index 0000000..64ebea7 --- /dev/null +++ b/lib/libalpm/test/.gitignore @@ -0,0 +1,3 @@ +deltatest +.deps +.libs diff --git a/lib/libalpm/test/Makefile.am b/lib/libalpm/test/Makefile.am new file mode 100644 index 0000000..b033018 --- /dev/null +++ b/lib/libalpm/test/Makefile.am @@ -0,0 +1,47 @@ +AUTOMAKE_OPTIONS = gnu + +bin_PROGRAMS = deltatest + +DEFS = -DLOCALEDIR=\"@localedir@\" @DEFS@ + +AM_CFLAGS = -pedantic -D_GNU_SOURCE -I.. -I../../.. + +if ENABLE_VISIBILITY_CC +AM_CFLAGS += -fvisibility=internal +endif +if ENABLE_GNU89_INLINE_CC +AM_CFLAGS += -fgnu89-inline +endif + +deltatest_SOURCES = deltatest.c +deltatest_LDADD = ../.libs/libalpm.a + +libalpm_sources = \ + ../add.h ../add.c \ + ../alpm.h ../alpm.c \ + ../alpm_list.h ../alpm_list.c \ + ../backup.h ../backup.c \ + ../be_files.c ../\ + ../cache.h ../cache.c \ + ../conflict.h ../conflict.c \ + ../db.h ../db.c \ + ../delta.h ../delta.c \ + ../deps.h ../deps.c \ + ../error.h ../error.c \ + ../group.h ../group.c \ + ../handle.h ../handle.c \ + ../log.h ../log.c \ + ../md5.h ../md5.c \ + ../package.h ../package.c \ + ../remove.h ../remove.c \ + ../server.h ../server.c \ + ../sync.h ../sync.c \ + ../trans.h ../trans.c \ + ../util.h ../util.c + +all: ../.libs/libalpm.a + +../.libs/libalpm.a: $(libalpm_sources) + cd .. && make + +# vim:set ts=2 sw=2 noet: diff --git a/lib/libalpm/test/deltatest.c b/lib/libalpm/test/deltatest.c new file mode 100644 index 0000000..e2c3c2e --- /dev/null +++ b/lib/libalpm/test/deltatest.c @@ -0,0 +1,112 @@ +/* + * deltatest.c + * + * Copyright (c) 2007 by Judd Vinet <jvinet@zeroflux.org> + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ +#include "string.h" +#include "assert.h" + +#include "alpm.h" +#include "alpm_list.h" +#include "delta.h" + +int main() +{ + alpm_list_t *deltas = NULL, *path = NULL; + pmdelta_t d1, d2, d3, d4, d5; + + strcpy(d1.from, "1.0-1"); + strcpy(d1.to, "1.1-1"); + d1.size = 10000; + + strcpy(d2.from, "1.1-1"); + strcpy(d2.to, "1.2-1"); + d2.size = 12000; + + strcpy(d3.from, "1.2-1"); + strcpy(d3.to, "1.2-2"); + d3.size = 8000; + + strcpy(d4.from, "1.2-2"); + strcpy(d4.to, "1.3-1"); + d4.size = 15000; + + strcpy(d5.from, "1.0-1"); + strcpy(d5.to, "1.3-1"); + d5.size = 20000; + + deltas = alpm_list_add(deltas, &d1); + deltas = alpm_list_add(deltas, &d2); + deltas = alpm_list_add(deltas, &d3); + deltas = alpm_list_add(deltas, &d4); + deltas = alpm_list_add(deltas, &d5); + + /* test standard path */ + path = _alpm_shortest_delta_path(deltas, "1.0-1", "1.1-1"); + assert(alpm_list_count(path) == 1); + assert(_alpm_delta_path_size(path) == 10000); + alpm_list_free(path); + + path = _alpm_shortest_delta_path(deltas, "1.0-1", "1.2-1"); + assert(alpm_list_count(path) == 2); + assert(_alpm_delta_path_size(path) == 22000); + alpm_list_free(path); + + path = _alpm_shortest_delta_path(deltas, "1.0-1", "1.2-2"); + assert(alpm_list_count(path) == 3); + assert(_alpm_delta_path_size(path) == 30000); + alpm_list_free(path); + + path = _alpm_shortest_delta_path(deltas, "1.0-1", "1.3-1"); + assert(alpm_list_count(path) == 1); + assert(_alpm_delta_path_size(path) == 20000); + alpm_list_free(path); + + path = _alpm_shortest_delta_path(deltas, "1.2-2", "1.3-1"); + assert(alpm_list_count(path) == 1); + assert(_alpm_delta_path_size(path) == 15000); + alpm_list_free(path); + + path = _alpm_shortest_delta_path(deltas, "1.2-1", "1.3-1"); + assert(alpm_list_count(path) == 2); + assert(_alpm_delta_path_size(path) == 23000); + alpm_list_free(path); + + /* test no path */ + path = _alpm_shortest_delta_path(deltas, "0.9-1", "1.3-1"); + assert(alpm_list_count(path) == 0); + alpm_list_free(path); + + path = _alpm_shortest_delta_path(deltas, "1.0-1", "1.4-1"); + assert(alpm_list_count(path) == 0); + alpm_list_free(path); + + path = _alpm_shortest_delta_path(deltas, "0.9-1", "1.4-1"); + assert(alpm_list_count(path) == 0); + alpm_list_free(path); + + /* test reverse direction */ + path = _alpm_shortest_delta_path(deltas, "1.1-1", "1.0-1"); + assert(alpm_list_count(path) == 0); + alpm_list_free(path); + + alpm_list_free(deltas); + + return 0; +} + -- 1.5.3.7
On Dec 7, 2007 3:56 PM, Nathan Jones <nathanj@insightbb.com> wrote:
I found this useful when testing the shortest_delta_path code. Recently, I ran valgrind on the test which helped to discover the memory leak.
Not sure if you guys will want to apply this, but here it is.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
I really think we do need some test programs directly on libalpm- things that pactest can't fully set on fire. I'd definitely like to write a unit test harness for alpm_list_t, so this may provide some inspiration for that. -Dan
On Dec 7, 2007 5:13 PM, Dan McGee <dpmcgee@gmail.com> wrote:
On Dec 7, 2007 3:56 PM, Nathan Jones <nathanj@insightbb.com> wrote:
I found this useful when testing the shortest_delta_path code. Recently, I ran valgrind on the test which helped to discover the memory leak.
Not sure if you guys will want to apply this, but here it is.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
I really think we do need some test programs directly on libalpm- things that pactest can't fully set on fire.
I'd definitely like to write a unit test harness for alpm_list_t, so this may provide some inspiration for that.
I agree. Nathan, this is great. I started a makepkg unit test setup somewhere, but that went by the wayside. A pacman test setup is also great. If we're testing JUST the libalpm functions we may not need all the complexity pactest has with creating DBs and the like, so we could go with the precedent here
participants (3)
-
Aaron Griffin
-
Dan McGee
-
Nathan Jones