added hashcalc
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Sun, 23 Oct 2005 22:50:59 +0000 (22:50 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Sun, 23 Oct 2005 22:50:59 +0000 (22:50 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2173 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/src/testsuite/.cvsignore
util-vserver/src/testsuite/Makefile-files
util-vserver/src/testsuite/hashcalc.c [new file with mode: 0644]

index ab49759..6fc8d33 100644 (file)
@@ -3,5 +3,6 @@
 .libs
 chbind-test
 chcontext-test
+hashcalc
 rpm-fake-test
 vunify-functest
index 9c66747..6575e8c 100644 (file)
 src_testsuite_check_active_PRGS =      src/testsuite/vunify-functest \
                                        src/testsuite/chcontext-test \
                                        src/testsuite/chbind-test
+
 src_testsuite_check_passive_PRGS =     src/testsuite/rpm-fake-test
 
+if ENSC_HAVE_C99_COMPILER
+if ENSC_HAVE_BEECRYPT
+src_testsuite_check_passive_PRGS +=    src/testsuite/hashcalc
+endif
+endif
 
 check_PROGRAMS +=                      $(src_testsuite_check_passive_PRGS) \
                                        $(src_testsuite_check_active_PRGS)
@@ -57,6 +63,14 @@ src_testsuite_chcontext_test_LDADD = lib/libvserver.la $(LIBINTERNAL)
 src_testsuite_chbind_test_SOURCES =    src/testsuite/chbind-test.c
 src_testsuite_chbind_test_LDADD =      lib/libvserver.la
 
+src_testsuite_hashcalc_SOURCES =       src/testsuite/hashcalc.c
+if ENSC_CAN_BEECRYPT_WITH_DIETLIBC
+src_testsuite_hashcalc_LDADD =         $(LIBINTERNAL) $(LIBENSCVECTOR) -lbeecrypt $(VSERVER_LDADDS)
+src_testsuite_hashcalc_LDFLAGS =       $(VSERVER_LDFLGS)
+else
+src_testsuite_hashcalc_LDADD =         $(LIBINTERNAL_GLIBC) $(LIBENSCVECTOR_GLIBC) $(LIBVSERVER_GLIBC) -lbeecrypt
+src_testsuite_hashcalc_LDFLAGS =
+endif
 
 src_testsuite_CPPFLAGS =               -I $(top_srcdir)/src -D ENSC_TESTSUITE
 
diff --git a/util-vserver/src/testsuite/hashcalc.c b/util-vserver/src/testsuite/hashcalc.c
new file mode 100644 (file)
index 0000000..6dbd4cd
--- /dev/null
@@ -0,0 +1,56 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//  
+// 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; version 2 of the License.
+//  
+// 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.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#define ENSC_TESTSUITE
+#define main   Xmain
+#  include "../vhashify.c"
+#undef main
+
+int main(int argc, char *argv[])
+{
+  int          fd = open(argv[1], O_NOFOLLOW|O_NONBLOCK|O_RDONLY|O_NOCTTY);
+  struct stat  st;
+  HashPath     d_path;
+  off_t                size;
+
+  global_info.hash_conf.method = hashFunctionFind(argv[2]);
+  
+  assert(hashFunctionContextInit(&global_info.hash_context,
+                                global_info.hash_conf.method)!=-1);
+
+  assert(fstat(fd, &st)!=-1);
+
+    // set members of st to defined values so that the hash (which is
+    // influenced by them) is predictable
+  size = st.st_size;
+  memset(&st, 0, sizeof st);
+  st.st_size = size;
+  
+  assert(calculateHashFromFD(fd, &d_path, &st));
+
+  write(1, d_path, strlen(d_path));
+  write(1, "\n", 1);
+  
+  hashFunctionContextFree(&global_info.hash_context);
+  
+  return 0;
+}