aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2015-05-04 06:12:55 -0400
committerMike Frysinger <vapier@gentoo.org>2015-05-04 06:12:55 -0400
commit7eb77555f12823a7b5763122b6817fb66eb2a89f (patch)
tree52541c02a11cb4602ab98d7a6d3b0d4bedb4aa91
parenttests: qmerge: fix running in nocolor mode (diff)
downloadportage-utils-7eb77555f12823a7b5763122b6817fb66eb2a89f.tar.gz
portage-utils-7eb77555f12823a7b5763122b6817fb66eb2a89f.tar.bz2
portage-utils-7eb77555f12823a7b5763122b6817fb66eb2a89f.zip
qcheck/qlop/qmerge/qxpak: fix spurious trailing u
The PRIu64 constant doesn't need its own "u" format as it's built in. For qcheck, this meant we generated invalid CONTENTS when updating. For the rest, it meant we had weird user facing output. Take this opportunity to add a qcheck testsuite. URL: https://bugs.gentoo.org/548262 Reported-by: Johnny Wezel <dev-jay@wezel.name>
-rw-r--r--qcheck.c10
-rw-r--r--qlop.c2
-rw-r--r--qmerge.c4
-rw-r--r--qxpak.c2
-rw-r--r--tests/Makefile2
-rw-r--r--tests/qcheck/Makefile11
-rwxr-xr-xtests/qcheck/dotest64
-rw-r--r--tests/qcheck/list01.good11
-rw-r--r--tests/qcheck/list02.good9
-rw-r--r--tests/qcheck/list03.good1
-rw-r--r--tests/qcheck/list04.good11
-rw-r--r--tests/qcheck/list05.good11
-rw-r--r--tests/qcheck/list06.good8
-rw-r--r--tests/qcheck/list07.good4
-rw-r--r--tests/qcheck/list08.good11
-rw-r--r--tests/qcheck/list09.good12
-rw-r--r--tests/qcheck/root/a-b/pkg-1.0/CONTENTS13
-rw-r--r--tests/qcheck/root/a-b/pkg-1.0/SLOT1
-rw-r--r--tests/qcheck/root/a-b/pkg-1.0/repository1
-rw-r--r--tests/qcheck/root/bin/bad-md51
-rw-r--r--tests/qcheck/root/bin/bad-mtime1
-rw-r--r--tests/qcheck/root/bin/bad-mtime-obj1
l---------tests/qcheck/root/bin/bad-mtime-sym1
-rw-r--r--tests/qcheck/root/bin/bad-sha11
-rw-r--r--tests/qcheck/root/bin/good-md51
-rw-r--r--tests/qcheck/root/bin/good-sha11
l---------tests/qcheck/root/bin/good-sym1
-rw-r--r--tests/qcheck/root/cat/pkg-1/CONTENTS0
-rw-r--r--tests/qcheck/root/cat/pkg-1/SLOT1
-rw-r--r--tests/qcheck/root/cat/pkg-1/repository1
30 files changed, 188 insertions, 10 deletions
diff --git a/qcheck.c b/qcheck.c
index 86d7aa6c..75dbf6d3 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -186,7 +186,7 @@ static int qcheck_process_contents(q_vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_sta
if (state->chk_hash) {
const char *digest_disp;
if (state->qc_update)
- fprintf(fpx, "obj %s %s %"PRIu64"u\n", e->name, hashed_file, (uint64_t)st.st_mtime);
+ fprintf(fpx, "obj %s %s %"PRIu64"\n", e->name, hashed_file, (uint64_t)st.st_mtime);
switch (hash_algo) {
case HASH_MD5: digest_disp = "MD5"; break;
case HASH_SHA1: digest_disp = "SHA1"; break;
@@ -208,12 +208,12 @@ static int qcheck_process_contents(q_vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_sta
if (state->chk_mtime) {
qcprintf(" %sMTIME%s: %s", RED, NORM, e->name);
if (verbose)
- qcprintf(" (recorded '%"PRIu64"u' != actual '%"PRIu64"u')", (uint64_t)e->mtime, (uint64_t)st.st_mtime);
+ qcprintf(" (recorded '%"PRIu64"' != actual '%"PRIu64"')", (uint64_t)e->mtime, (uint64_t)st.st_mtime);
qcprintf("\n");
/* This can only be an obj, dir and sym have no digest */
if (state->qc_update)
- fprintf(fpx, "obj %s %s %"PRIu64"u\n", e->name, e->digest, (uint64_t)st.st_mtime);
+ fprintf(fpx, "obj %s %s %"PRIu64"\n", e->name, e->digest, (uint64_t)st.st_mtime);
} else {
--num_files;
++num_files_ignored;
@@ -231,13 +231,13 @@ static int qcheck_process_contents(q_vdb_pkg_ctx *pkg_ctx, struct qcheck_opt_sta
if (state->chk_mtime) {
qcprintf(" %sMTIME%s: %s", RED, NORM, e->name);
if (verbose)
- qcprintf(" (recorded '%"PRIu64"u' != actual '%"PRIu64"u')",
+ qcprintf(" (recorded '%"PRIu64"' != actual '%"PRIu64"')",
(uint64_t)e->mtime, (uint64_t)st.st_mtime);
qcprintf("\n");
/* This can only be a sym */
if (state->qc_update)
- fprintf(fpx, "sym %s -> %s %"PRIu64"u\n", e->name, e->sym_target, (uint64_t)st.st_mtime);
+ fprintf(fpx, "sym %s -> %s %"PRIu64"\n", e->name, e->sym_target, (uint64_t)st.st_mtime);
} else {
--num_files;
++num_files_ignored;
diff --git a/qlop.c b/qlop.c
index d5e2226d..a2541e2a 100644
--- a/qlop.c
+++ b/qlop.c
@@ -208,7 +208,7 @@ show_merge_times(char *package, const char *logfile, int average, char human_rea
if (human_readable)
print_seconds_for_earthlings(t[1] - t[0]);
else
- printf("%s%"PRIu64"u%s seconds", GREEN, (uint64_t)(t[1] - t[0]), NORM);
+ printf("%s%"PRIu64"%s seconds", GREEN, (uint64_t)(t[1] - t[0]), NORM);
puts("");
}
merge_time += (t[1] - t[0]);
diff --git a/qmerge.c b/qmerge.c
index 9df93840..a3e2fd23 100644
--- a/qmerge.c
+++ b/qmerge.c
@@ -587,7 +587,7 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
/* syntax: obj filename hash mtime */
hash = hash_file_at(subfd_src, name, HASH_MD5);
- fprintf(contents, "obj %s %s %"PRIu64"u\n", cpath, hash, (uint64_t)st.st_mtime);
+ fprintf(contents, "obj %s %s %"PRIu64"\n", cpath, hash, (uint64_t)st.st_mtime);
/* Check CONFIG_PROTECT */
if (config_protected(cpath, cp_argc, cp_argv, cpm_argc, cpm_argv)) {
@@ -685,7 +685,7 @@ merge_tree_at(int fd_src, const char *src, int fd_dst, const char *dst,
sym[len] = '\0';
/* syntax: sym src -> dst mtime */
- fprintf(contents, "sym %s -> %s %"PRIu64"u\n", cpath, sym, (uint64_t)st.st_mtime);
+ fprintf(contents, "sym %s -> %s %"PRIu64"\n", cpath, sym, (uint64_t)st.st_mtime);
qprintf("%s>>>%s %s%s -> %s%s\n", GREEN, NORM, CYAN, cpath, sym, NORM);
*objs = add_set(cpath, *objs);
diff --git a/qxpak.c b/qxpak.c
index 9a2e11b9..d7cec6f6 100644
--- a/qxpak.c
+++ b/qxpak.c
@@ -283,7 +283,7 @@ _xpak_add_file(int dir_fd, const char *filename, struct stat *st, FILE *findex,
/* the xpak format can only store files whose size is a 32bit int
* so we have to make sure we don't store a big file */
if (in_len != st->st_size) {
- warnf("File is too big: %"PRIu64"u", (uint64_t)st->st_size);
+ warnf("File is too big: %"PRIu64, (uint64_t)st->st_size);
fclose(fin);
goto fake_data_len;
}
diff --git a/tests/Makefile b/tests/Makefile
index 0fc448ae..c0aedb47 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,6 +1,6 @@
TESTS = \
reinitialize atom_compare atom_explode mkdir \
- qdepends qfile qlist qmerge qtbz2 quse qxpak \
+ qcheck qdepends qfile qlist qmerge qtbz2 quse qxpak \
install profile source
all: check
diff --git a/tests/qcheck/Makefile b/tests/qcheck/Makefile
new file mode 100644
index 00000000..a7bd973e
--- /dev/null
+++ b/tests/qcheck/Makefile
@@ -0,0 +1,11 @@
+thisdir = qcheck
+include ../subdir.mk
+
+all: check
+
+test check:
+ $(Q)$(s)/dotest
+
+clean:
+
+.PHONY: all check clean test
diff --git a/tests/qcheck/dotest b/tests/qcheck/dotest
new file mode 100755
index 00000000..965a5b55
--- /dev/null
+++ b/tests/qcheck/dotest
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+. ../init.sh
+
+set -e
+
+export ROOT=${as}/root
+export Q_VDB=/
+
+# This is the "valid" mtime the test packages have hardcoded in the CONTENTS
+# files. The stamp is the CONTENTS while the touch date is the corresponding
+# unpacked date.
+STAMP=1398954900 DATE=201405011035
+find "${ROOT}" -exec touch -h -t "${DATE}" {} +
+
+mktmpdir
+
+test() {
+ local num=$1 exp=$2 ret=0
+ shift 2
+ eval "$@" > list || ret=$?
+ if ! diff -u list ${as}/list${num}.good ; then
+ tfail "output does not match"
+ fi
+ if [[ ${exp} -ne ${ret} ]] ; then
+ tfail "exit code (${ret}) does not match expected (${exp})"
+ fi
+ tend $? "$*"
+}
+
+# simple check
+test 01 1 "qcheck a-b/pkg"
+
+# exclude check
+test 02 1 "qcheck a-b/pkg -s ^/missing-dir/.*"
+
+# bad-only check
+test 03 1 "qcheck -Ba"
+
+# hash mismatch ignore check
+test 04 1 "qcheck -Ha"
+
+# mtime mismatch ignore check
+test 05 1 "qcheck -Ta"
+
+# missing ignore check
+test 06 1 "qcheck -Aa"
+
+# hash+mtime+missing mismatch ignore check
+test 07 0 "qcheck -AHTa"
+
+# verbose check
+test 08 1 "qcheck -v a-b/pkg"
+
+# update check
+(
+cp -a "${ROOT}" mod
+ROOT=${PWD}/mod
+test 09 0 "qcheck -u a-b/pkg && qcheck a-b/pkg"
+)
+
+cleantmpdir
+
+end
diff --git a/tests/qcheck/list01.good b/tests/qcheck/list01.good
new file mode 100644
index 00000000..71e9db3b
--- /dev/null
+++ b/tests/qcheck/list01.good
@@ -0,0 +1,11 @@
+Checking a-b/pkg-1.0 ...
+ MD5-DIGEST: /bin/bad-md5
+ MTIME: /bin/bad-mtime-obj
+ SHA1-DIGEST: /bin/bad-sha1
+ MTIME: /bin/bad-mtime-sym
+ AFK: /bin/broken-sym
+ AFK: /bin/missing-sym
+ AFK: /missing-dir
+ AFK: /missing-dir/missing-file
+ AFK: /missing-dir/missing-sym
+ * 4 out of 13 files are good
diff --git a/tests/qcheck/list02.good b/tests/qcheck/list02.good
new file mode 100644
index 00000000..8689d41b
--- /dev/null
+++ b/tests/qcheck/list02.good
@@ -0,0 +1,9 @@
+Checking a-b/pkg-1.0 ...
+ MD5-DIGEST: /bin/bad-md5
+ MTIME: /bin/bad-mtime-obj
+ SHA1-DIGEST: /bin/bad-sha1
+ MTIME: /bin/bad-mtime-sym
+ AFK: /bin/broken-sym
+ AFK: /bin/missing-sym
+ AFK: /missing-dir
+ * 4 out of 11 files are good (2 files were ignored)
diff --git a/tests/qcheck/list03.good b/tests/qcheck/list03.good
new file mode 100644
index 00000000..a70d3b48
--- /dev/null
+++ b/tests/qcheck/list03.good
@@ -0,0 +1 @@
+a-b/pkg
diff --git a/tests/qcheck/list04.good b/tests/qcheck/list04.good
new file mode 100644
index 00000000..930f896c
--- /dev/null
+++ b/tests/qcheck/list04.good
@@ -0,0 +1,11 @@
+Checking a-b/pkg-1.0 ...
+ MTIME: /bin/bad-mtime-obj
+ MTIME: /bin/bad-mtime-sym
+ AFK: /bin/broken-sym
+ AFK: /bin/missing-sym
+ AFK: /missing-dir
+ AFK: /missing-dir/missing-file
+ AFK: /missing-dir/missing-sym
+ * 4 out of 11 files are good (2 files were ignored)
+Checking cat/pkg-1 ...
+ * 0 out of 0 file are good
diff --git a/tests/qcheck/list05.good b/tests/qcheck/list05.good
new file mode 100644
index 00000000..d4c4243f
--- /dev/null
+++ b/tests/qcheck/list05.good
@@ -0,0 +1,11 @@
+Checking a-b/pkg-1.0 ...
+ MD5-DIGEST: /bin/bad-md5
+ SHA1-DIGEST: /bin/bad-sha1
+ AFK: /bin/broken-sym
+ AFK: /bin/missing-sym
+ AFK: /missing-dir
+ AFK: /missing-dir/missing-file
+ AFK: /missing-dir/missing-sym
+ * 4 out of 11 files are good (2 files were ignored)
+Checking cat/pkg-1 ...
+ * 0 out of 0 file are good
diff --git a/tests/qcheck/list06.good b/tests/qcheck/list06.good
new file mode 100644
index 00000000..3cd48f77
--- /dev/null
+++ b/tests/qcheck/list06.good
@@ -0,0 +1,8 @@
+Checking a-b/pkg-1.0 ...
+ MD5-DIGEST: /bin/bad-md5
+ MTIME: /bin/bad-mtime-obj
+ SHA1-DIGEST: /bin/bad-sha1
+ MTIME: /bin/bad-mtime-sym
+ * 4 out of 8 files are good (5 files were ignored)
+Checking cat/pkg-1 ...
+ * 0 out of 0 file are good
diff --git a/tests/qcheck/list07.good b/tests/qcheck/list07.good
new file mode 100644
index 00000000..fb596893
--- /dev/null
+++ b/tests/qcheck/list07.good
@@ -0,0 +1,4 @@
+Checking a-b/pkg-1.0 ...
+ * 4 out of 4 files are good (9 files were ignored)
+Checking cat/pkg-1 ...
+ * 0 out of 0 file are good
diff --git a/tests/qcheck/list08.good b/tests/qcheck/list08.good
new file mode 100644
index 00000000..16ba9da5
--- /dev/null
+++ b/tests/qcheck/list08.good
@@ -0,0 +1,11 @@
+Checking a-b/pkg-1.0 ...
+ MD5-DIGEST: /bin/bad-md5 (recorded '2b00042f7481c7b056c4b410d28f33cf' != actual 'f873a43958ea3a2c7a21fb0beb91001a')
+ MTIME: /bin/bad-mtime-obj (recorded '1' != actual '1398954900')
+ SHA1-DIGEST: /bin/bad-sha1 (recorded '7d97e98f8af710c7e7fe703abc8f639e0ee507c4' != actual '93e53f957b54a6a5bb2891d998fda65719887f84')
+ MTIME: /bin/bad-mtime-sym (recorded '1' != actual '1398954900')
+ AFK: /bin/broken-sym
+ AFK: /bin/missing-sym
+ AFK: /missing-dir
+ AFK: /missing-dir/missing-file
+ AFK: /missing-dir/missing-sym
+ * 4 out of 13 files are good
diff --git a/tests/qcheck/list09.good b/tests/qcheck/list09.good
new file mode 100644
index 00000000..cd6195e0
--- /dev/null
+++ b/tests/qcheck/list09.good
@@ -0,0 +1,12 @@
+Updating a-b/pkg-1.0 ...
+ MD5-DIGEST: /bin/bad-md5
+ MTIME: /bin/bad-mtime-obj
+ SHA1-DIGEST: /bin/bad-sha1
+ MTIME: /bin/bad-mtime-sym
+ AFK: /bin/broken-sym
+ AFK: /bin/missing-sym
+ AFK: /missing-dir
+ AFK: /missing-dir/missing-file
+ AFK: /missing-dir/missing-sym
+Checking a-b/pkg-1.0 ...
+ * 8 out of 8 files are good
diff --git a/tests/qcheck/root/a-b/pkg-1.0/CONTENTS b/tests/qcheck/root/a-b/pkg-1.0/CONTENTS
new file mode 100644
index 00000000..b8f5697b
--- /dev/null
+++ b/tests/qcheck/root/a-b/pkg-1.0/CONTENTS
@@ -0,0 +1,13 @@
+dir /bin
+obj /bin/good-md5 2b00042f7481c7b056c4b410d28f33cf 1398954900
+obj /bin/bad-md5 2b00042f7481c7b056c4b410d28f33cf 1398954900
+obj /bin/bad-mtime-obj 2b00042f7481c7b056c4b410d28f33cf 1
+obj /bin/good-sha1 7d97e98f8af710c7e7fe703abc8f639e0ee507c4 1398954900
+obj /bin/bad-sha1 7d97e98f8af710c7e7fe703abc8f639e0ee507c4 1398954900
+sym /bin/good-sym -> good-md5 1398954900
+sym /bin/bad-mtime-sym -> good-md5 1
+sym /bin/broken-sym -> broken 1398954900
+sym /bin/missing-sym -> noooooope 1398954900
+dir /missing-dir
+obj /missing-dir/missing-file 2b00042f7481c7b056c4b410d28f33cf 1398954900
+sym /missing-dir/missing-sym -> nowhere 1398954900
diff --git a/tests/qcheck/root/a-b/pkg-1.0/SLOT b/tests/qcheck/root/a-b/pkg-1.0/SLOT
new file mode 100644
index 00000000..573541ac
--- /dev/null
+++ b/tests/qcheck/root/a-b/pkg-1.0/SLOT
@@ -0,0 +1 @@
+0
diff --git a/tests/qcheck/root/a-b/pkg-1.0/repository b/tests/qcheck/root/a-b/pkg-1.0/repository
new file mode 100644
index 00000000..23574f35
--- /dev/null
+++ b/tests/qcheck/root/a-b/pkg-1.0/repository
@@ -0,0 +1 @@
+gentoo
diff --git a/tests/qcheck/root/bin/bad-md5 b/tests/qcheck/root/bin/bad-md5
new file mode 100644
index 00000000..485aba4f
--- /dev/null
+++ b/tests/qcheck/root/bin/bad-md5
@@ -0,0 +1 @@
+baaad
diff --git a/tests/qcheck/root/bin/bad-mtime b/tests/qcheck/root/bin/bad-mtime
new file mode 100644
index 00000000..8bd6648e
--- /dev/null
+++ b/tests/qcheck/root/bin/bad-mtime
@@ -0,0 +1 @@
+asdf
diff --git a/tests/qcheck/root/bin/bad-mtime-obj b/tests/qcheck/root/bin/bad-mtime-obj
new file mode 100644
index 00000000..8bd6648e
--- /dev/null
+++ b/tests/qcheck/root/bin/bad-mtime-obj
@@ -0,0 +1 @@
+asdf
diff --git a/tests/qcheck/root/bin/bad-mtime-sym b/tests/qcheck/root/bin/bad-mtime-sym
new file mode 120000
index 00000000..e6018f6a
--- /dev/null
+++ b/tests/qcheck/root/bin/bad-mtime-sym
@@ -0,0 +1 @@
+good-md5 \ No newline at end of file
diff --git a/tests/qcheck/root/bin/bad-sha1 b/tests/qcheck/root/bin/bad-sha1
new file mode 100644
index 00000000..485aba4f
--- /dev/null
+++ b/tests/qcheck/root/bin/bad-sha1
@@ -0,0 +1 @@
+baaad
diff --git a/tests/qcheck/root/bin/good-md5 b/tests/qcheck/root/bin/good-md5
new file mode 100644
index 00000000..8bd6648e
--- /dev/null
+++ b/tests/qcheck/root/bin/good-md5
@@ -0,0 +1 @@
+asdf
diff --git a/tests/qcheck/root/bin/good-sha1 b/tests/qcheck/root/bin/good-sha1
new file mode 100644
index 00000000..8bd6648e
--- /dev/null
+++ b/tests/qcheck/root/bin/good-sha1
@@ -0,0 +1 @@
+asdf
diff --git a/tests/qcheck/root/bin/good-sym b/tests/qcheck/root/bin/good-sym
new file mode 120000
index 00000000..e6018f6a
--- /dev/null
+++ b/tests/qcheck/root/bin/good-sym
@@ -0,0 +1 @@
+good-md5 \ No newline at end of file
diff --git a/tests/qcheck/root/cat/pkg-1/CONTENTS b/tests/qcheck/root/cat/pkg-1/CONTENTS
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/qcheck/root/cat/pkg-1/CONTENTS
diff --git a/tests/qcheck/root/cat/pkg-1/SLOT b/tests/qcheck/root/cat/pkg-1/SLOT
new file mode 100644
index 00000000..d00491fd
--- /dev/null
+++ b/tests/qcheck/root/cat/pkg-1/SLOT
@@ -0,0 +1 @@
+1
diff --git a/tests/qcheck/root/cat/pkg-1/repository b/tests/qcheck/root/cat/pkg-1/repository
new file mode 100644
index 00000000..f606d5e0
--- /dev/null
+++ b/tests/qcheck/root/cat/pkg-1/repository
@@ -0,0 +1 @@
+repo