From 369c919f2be8d2c93b990a97436b41ba4ae1ff29 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 17 Aug 2011 12:06:37 +0200 Subject: move the interactive helper to a subdirectory of test --- test/interactive-helper/extract-control.cc | 42 +++++++++++ test/interactive-helper/makefile | 43 +++++++++++ test/interactive-helper/mthdcat.cc | 20 +++++ test/interactive-helper/rpmver.cc | 117 +++++++++++++++++++++++++++++ test/interactive-helper/test_udevcdrom.cc | 19 +++++ test/interactive-helper/testdeb.cc | 39 ++++++++++ test/interactive-helper/testextract.cc | 101 +++++++++++++++++++++++++ 7 files changed, 381 insertions(+) create mode 100644 test/interactive-helper/extract-control.cc create mode 100644 test/interactive-helper/makefile create mode 100644 test/interactive-helper/mthdcat.cc create mode 100644 test/interactive-helper/rpmver.cc create mode 100644 test/interactive-helper/test_udevcdrom.cc create mode 100644 test/interactive-helper/testdeb.cc create mode 100644 test/interactive-helper/testextract.cc (limited to 'test/interactive-helper') diff --git a/test/interactive-helper/extract-control.cc b/test/interactive-helper/extract-control.cc new file mode 100644 index 000000000..29dcbf371 --- /dev/null +++ b/test/interactive-helper/extract-control.cc @@ -0,0 +1,42 @@ +#include +#include + +#include +#include + +using namespace std; + +bool ExtractMember(const char *File,const char *Member) +{ + FileFd Fd(File,FileFd::ReadOnly); + debDebFile Deb(Fd); + if(_error->PendingError() == true) + return false; + + debDebFile::MemControlExtract Extract(Member); + if (Extract.Read(Deb) == false) + return false; + + if (Extract.Control == 0) + return true; + + write(STDOUT_FILENO,Extract.Control,Extract.Length); + return true; +} + +int main(int argc, const char *argv[]) +{ + if (argc < 2) + { + cerr << "Need two arguments, a .deb and the control member" << endl; + return 100; + } + + if (ExtractMember(argv[1],argv[2]) == false) + { + _error->DumpErrors(); + return 100; + } + + return 0; +} diff --git a/test/interactive-helper/makefile b/test/interactive-helper/makefile new file mode 100644 index 000000000..b96139fda --- /dev/null +++ b/test/interactive-helper/makefile @@ -0,0 +1,43 @@ +# -*- make -*- +BASE=../.. +SUBDIR=test/interactive-helper + +# Bring in the default rules +include ../../buildlib/defaults.mak + +# Program for testing methods +PROGRAM=mthdcat +SLIBS = +SOURCE = mthdcat.cc +include $(PROGRAM_H) + +# Version compare tester +PROGRAM=testextract +SLIBS = -lapt-pkg -lapt-inst +LIB_MAKES = apt-pkg/makefile apt-inst/makefile +SOURCE = testextract.cc +include $(PROGRAM_H) + +# Program for testing the tar/deb extractor +PROGRAM=testdeb +SLIBS = -lapt-pkg -lapt-inst +SOURCE = testdeb.cc +include $(PROGRAM_H) + +# Program for testing tar extraction +PROGRAM=extract-control +SLIBS = -lapt-pkg -lapt-inst +SOURCE = extract-control.cc +include $(PROGRAM_H) + +# Program for testing udevcdrom +PROGRAM=test_udevcdrom +SLIBS = -lapt-pkg +SOURCE = test_udevcdrom.cc +include $(PROGRAM_H) + +# Program for checking rpm versions +#PROGRAM=rpmver +#SLIBS = -lapt-pkg -lrpm +#SOURCE = rpmver.cc +#include $(PROGRAM_H) diff --git a/test/interactive-helper/mthdcat.cc b/test/interactive-helper/mthdcat.cc new file mode 100644 index 000000000..25d09a3f5 --- /dev/null +++ b/test/interactive-helper/mthdcat.cc @@ -0,0 +1,20 @@ +/* Usage, mthdcat < cmds | methods/mthd + All this does is cat a file into the method without closing the FD when + the file ends */ + +#include + +int main() +{ + char Buffer[4096]; + + while (1) + { + int Res = read(STDIN_FILENO,Buffer,sizeof(Buffer)); + if (Res <= 0) + while (1) sleep(100); + if (write(STDOUT_FILENO,Buffer,Res) != Res) + break; + } + return 0; +} diff --git a/test/interactive-helper/rpmver.cc b/test/interactive-helper/rpmver.cc new file mode 100644 index 000000000..9fc807de8 --- /dev/null +++ b/test/interactive-helper/rpmver.cc @@ -0,0 +1,117 @@ +#include +#include +#include +#include +#include + +#define xisdigit(x) isdigit(x) +#define xisalpha(x) isalpha(x) +#define xisalnum(x) (isdigit(x) || isalpha(x)) + +using namespace std; + +int rpmvercmp(const char * a, const char * b) +{ + char oldch1, oldch2; + char * str1, * str2; + char * one, * two; + int rc; + int isnum; + + /* easy comparison to see if versions are identical */ + if (!strcmp(a, b)) return 0; + + str1 = (char *)alloca(strlen(a) + 1); + str2 = (char *)alloca(strlen(b) + 1); + + strcpy(str1, a); + strcpy(str2, b); + + one = str1; + two = str2; + + /* loop through each version segment of str1 and str2 and compare them */ + while (*one && *two) { + while (*one && !xisalnum(*one)) one++; + while (*two && !xisalnum(*two)) two++; + + str1 = one; + str2 = two; + + /* grab first completely alpha or completely numeric segment */ + /* leave one and two pointing to the start of the alpha or numeric */ + /* segment and walk str1 and str2 to end of segment */ + if (xisdigit(*str1)) { + while (*str1 && xisdigit(*str1)) str1++; + while (*str2 && xisdigit(*str2)) str2++; + isnum = 1; + } else { + while (*str1 && xisalpha(*str1)) str1++; + while (*str2 && xisalpha(*str2)) str2++; + isnum = 0; + } + + /* save character at the end of the alpha or numeric segment */ + /* so that they can be restored after the comparison */ + oldch1 = *str1; + *str1 = '\0'; + oldch2 = *str2; + *str2 = '\0'; + + /* take care of the case where the two version segments are */ + /* different types: one numeric, the other alpha (i.e. empty) */ + if (one == str1) return -1; /* arbitrary */ + if (two == str2) return 1; + + if (isnum) { + /* this used to be done by converting the digit segments */ + /* to ints using atoi() - it's changed because long */ + /* digit segments can overflow an int - this should fix that. */ + + /* throw away any leading zeros - it's a number, right? */ + while (*one == '0') one++; + while (*two == '0') two++; + + /* whichever number has more digits wins */ + if (strlen(one) > strlen(two)) return 1; + if (strlen(two) > strlen(one)) return -1; + } + + /* strcmp will return which one is greater - even if the two */ + /* segments are alpha or if they are numeric. don't return */ + /* if they are equal because there might be more segments to */ + /* compare */ + rc = strcmp(one, two); + if (rc) return rc; + + /* restore character that was replaced by null above */ + *str1 = oldch1; + one = str1; + *str2 = oldch2; + two = str2; + } + + /* this catches the case where all numeric and alpha segments have */ + /* compared identically but the segment sepparating characters were */ + /* different */ + if ((!*one) && (!*two)) return 0; + + /* whichever version still has characters left over wins */ + if (!*one) return -1; else return 1; +} + +int main(int argc,const char *argv[]) +{ + printf("%i\n",strcmp(argv[1],argv[2])); + + printf("'%s' <> '%s': ",argv[1],argv[2]); + printf("rpm: %i deb: %i\n",rpmvercmp(argv[1],argv[2]), + debVS.CmpFragment(argv[1],argv[1]+strlen(argv[1]), + argv[2],argv[2]+strlen(argv[2]))); + + printf("'%s' <> '%s': ",argv[2],argv[1]); + printf("rpm: %i deb: %i\n",rpmvercmp(argv[2],argv[1]), + debVS.CmpFragment(argv[2],argv[2]+strlen(argv[2]), + argv[1],argv[1]+strlen(argv[1]))); + return 0; +} diff --git a/test/interactive-helper/test_udevcdrom.cc b/test/interactive-helper/test_udevcdrom.cc new file mode 100644 index 000000000..577e2d013 --- /dev/null +++ b/test/interactive-helper/test_udevcdrom.cc @@ -0,0 +1,19 @@ +#include +#include +#include + +int main() +{ + int i; + pkgUdevCdromDevices c; + assert(c.Dlopen()); + + vector l; + l = c.Scan(); + assert(l.empty() == false); + for (i=0;i +#include +#include +#include + +class NullStream : public pkgDirStream +{ + public: + virtual bool DoItem(Item &Itm,int &Fd) {return true;}; +}; + +bool Test(const char *File) +{ + FileFd Fd(File,FileFd::ReadOnly); + debDebFile Deb(Fd); + + if (_error->PendingError() == true) + return false; + + // Get the archive member and positition the file + const ARArchive::Member *Member = Deb.GotoMember("data.tar.gz"); + if (Member == 0) + return false; + + // Extract it. + ExtractTar Tar(Deb.GetFile(),Member->Size, "gzip"); + NullStream Dir; + if (Tar.Go(Dir) == false) + return false; + + return true; +} + +int main(int argc, const char *argv[]) +{ + Test(argv[1]); + _error->DumpErrors(); + return 0; +} diff --git a/test/interactive-helper/testextract.cc b/test/interactive-helper/testextract.cc new file mode 100644 index 000000000..b790df618 --- /dev/null +++ b/test/interactive-helper/testextract.cc @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace std; + +bool Go(int argc,char *argv[]) +{ + // Init the database + debDpkgDB Db; + { + OpTextProgress Prog; + + if (Db.ReadyPkgCache(Prog) == false) + return false; + Prog.Done(); + + if (Db.ReadyFileList(Prog) == false) + return false; + } + + for (int I = 1; I < argc; I++) + { + const char *Fake = 0; + for (unsigned J = 0; argv[I][J] != 0; J++) + { + if (argv[I][J] != ',') + continue; + Fake = argv[I] + J + 1; + argv[I][J] = 0; + } + + FileFd F(argv[I],FileFd::ReadOnly); + debDebFile Deb(F); + + if (_error->PendingError() == true) + return false; + + if (Deb.ExtractControl(Db) == false) + return false; + cout << argv[I] << endl; + + pkgCache::VerIterator Ver = Deb.MergeControl(Db); + if (Ver.end() == true) + return false; + + cout << Ver.ParentPkg().Name() << ' ' << Ver.VerStr() << endl; + + pkgExtract Extract(Db.GetFLCache(),Ver); + + if (Fake != 0) + { + pkgExtract::Item Itm; + memset(&Itm,0,sizeof(Itm)); + FILE *F = fopen(Fake,"r"); + while (feof(F) == 0) + { + char Line[300]; + fgets(Line,sizeof(Line),F); + Itm.Name = _strstrip(Line); + Itm.Type = pkgDirStream::Item::File; + if (Line[strlen(Line)-1] == '/') + Itm.Type = pkgDirStream::Item::Directory; + + int Fd; + if (Extract.DoItem(Itm,Fd) == false) { + fclose(F); + return false; + } + } + fclose(F); + } + else + if (Deb.ExtractArchive(Extract) == false) + return false; + } + return true; +} + +int main(int argc,char *argv[]) +{ + pkgInitConfig(*_config); + pkgInitSystem(*_config,_system); + _config->Set("Dir::State::status","/tmp/testing/status"); + + Go(argc,argv); + + if (_error->PendingError() == true) + { + _error->DumpErrors(); + return 0; + } +} -- cgit v1.2.3 From 92aacd885093389b5e9f7685ffe08219674ed6ff Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 17 Aug 2011 12:13:38 +0200 Subject: move the networkless test to the interactive helpers as it needs root rights for operation (ifup/down, iptables) so it is better run under supervision --- .../networkless-install-fixes/README | 5 +++++ .../networkless-install-fixes/sources.test.list | 25 ++++++++++++++++++++++ .../networkless-install-fixes/test.sh | 25 ++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 test/interactive-helper/networkless-install-fixes/README create mode 100644 test/interactive-helper/networkless-install-fixes/sources.test.list create mode 100755 test/interactive-helper/networkless-install-fixes/test.sh (limited to 'test/interactive-helper') diff --git a/test/interactive-helper/networkless-install-fixes/README b/test/interactive-helper/networkless-install-fixes/README new file mode 100644 index 000000000..e7ee2b03d --- /dev/null +++ b/test/interactive-helper/networkless-install-fixes/README @@ -0,0 +1,5 @@ + +Those tests aim at making the networkless install timeout +quicker, see +https://wiki.ubuntu.com/NetworklessInstallationFixes +for details diff --git a/test/interactive-helper/networkless-install-fixes/sources.test.list b/test/interactive-helper/networkless-install-fixes/sources.test.list new file mode 100644 index 000000000..380e1804d --- /dev/null +++ b/test/interactive-helper/networkless-install-fixes/sources.test.list @@ -0,0 +1,25 @@ + +# archive.ubuntu.com +deb http://archive.ubuntu.com/ubuntu/ hardy main restricted +deb-src http://archive.ubuntu.com/ubuntu/ hardy main restricted + +deb http://archive.ubuntu.com/ubuntu/ hardy-updates main restricted +deb-src http://archive.ubuntu.com/ubuntu/ hardy-updates main restricted + +deb http://archive.ubuntu.com/ubuntu/ hardy universe +deb-src http://archive.ubuntu.com/ubuntu/ hardy universe + +deb http://archive.ubuntu.com/ubuntu/ hardy-updates universe +deb-src http://archive.ubuntu.com/ubuntu/ hardy-updates universe + +# security.ubuntu.com +deb http://security.ubuntu.com/ubuntu/ hardy-security main restricted +deb-src http://security.ubuntu.com/ubuntu/ hardy-security main restricted + +deb http://security.ubuntu.com/ubuntu/ hardy-security universe +deb-src http://security.ubuntu.com/ubuntu/ hardy-security universe + + +# archive.canonical.com +deb http://archive.canonical.com/ubuntu/ hardy-partner universe +deb-src http://archive.canonical.com/ubuntu/ hardy-partner universe diff --git a/test/interactive-helper/networkless-install-fixes/test.sh b/test/interactive-helper/networkless-install-fixes/test.sh new file mode 100755 index 000000000..809d467ba --- /dev/null +++ b/test/interactive-helper/networkless-install-fixes/test.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +OPTS="-o Dir::Etc::sourcelist=./sources.test.list -o Acquire::http::timeout=20" + +# setup +unset http_proxy +iptables --flush + +echo "No network at all" +ifdown eth0 +time apt-get update $OPTS 2>&1 |grep system +ifup eth0 +echo "" + +echo "no working DNS (port 53 DROP)" +iptables -A OUTPUT -p udp --dport 53 -j DROP +time apt-get update $OPTS 2>&1 |grep system +iptables --flush +echo "" + +echo "DNS but no access to archive.ubuntu.com (port 80 DROP)" +iptables -A OUTPUT -p tcp --dport 80 -j DROP +time apt-get update $OPTS 2>&1 |grep system +iptables --flush +echo "" -- cgit v1.2.3 From 59f9dcbdf23ae430c2f5fa4bc85596347e73526f Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 17 Aug 2011 14:41:02 +0200 Subject: fix 'comparison between signed and unsigned integer expressions' warning in the udevcdrom testcase --- test/interactive-helper/test_udevcdrom.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/interactive-helper') diff --git a/test/interactive-helper/test_udevcdrom.cc b/test/interactive-helper/test_udevcdrom.cc index 577e2d013..dc25ab357 100644 --- a/test/interactive-helper/test_udevcdrom.cc +++ b/test/interactive-helper/test_udevcdrom.cc @@ -4,14 +4,13 @@ int main() { - int i; pkgUdevCdromDevices c; assert(c.Dlopen()); vector l; l = c.Scan(); assert(l.empty() == false); - for (i=0;i