From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>,
"Eric Sunshine" <sunshine@sunshineco.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Torsten Bögershausen" <tboegi@web.de>
Subject: [PATCH v3 01/11] t: add tool to translate hash-related values
Date: Wed, 29 Aug 2018 00:56:32 +0000 [thread overview]
Message-ID: <20180829005642.980617-2-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20180829005642.980617-1-sandals@crustytoothpaste.net>
Add a test function helper, test_oid, that produces output that varies
depending on the hash in use. Add two additional helpers,
test_oid_cache, which can be used to load data for test_oid from
standard input, and test_oid_init, which can be used to load certain
fixed values from lookup charts. Check that these functions work in
t0000, as the rest of the testsuite will soon come to depend on them.
Implement two basic lookup charts, one for common invalid or synthesized
object IDs, and one for various facts about the hash function in use.
Provide versions for both SHA-1 and SHA-256.
Note that due to the implementation used, names used for lookup can
currently consist only of shell identifier characters. If this is a
problem in the future, we can hash the names before use.
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
t/oid-info/hash-info | 8 ++++++++
t/oid-info/oid | 29 +++++++++++++++++++++++++++
t/t0000-basic.sh | 35 ++++++++++++++++++++++++++++++++
t/test-lib-functions.sh | 44 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 116 insertions(+)
create mode 100644 t/oid-info/hash-info
create mode 100644 t/oid-info/oid
diff --git a/t/oid-info/hash-info b/t/oid-info/hash-info
new file mode 100644
index 0000000000..ccdbfdf974
--- /dev/null
+++ b/t/oid-info/hash-info
@@ -0,0 +1,8 @@
+rawsz sha1:20
+rawsz sha256:32
+
+hexsz sha1:40
+hexsz sha256:64
+
+zero sha1:0000000000000000000000000000000000000000
+zero sha256:0000000000000000000000000000000000000000000000000000000000000000
diff --git a/t/oid-info/oid b/t/oid-info/oid
new file mode 100644
index 0000000000..a754970523
--- /dev/null
+++ b/t/oid-info/oid
@@ -0,0 +1,29 @@
+# These are some common invalid and partial object IDs used in tests.
+001 sha1:0000000000000000000000000000000000000001
+001 sha256:0000000000000000000000000000000000000000000000000000000000000001
+002 sha1:0000000000000000000000000000000000000002
+002 sha256:0000000000000000000000000000000000000000000000000000000000000002
+003 sha1:0000000000000000000000000000000000000003
+003 sha256:0000000000000000000000000000000000000000000000000000000000000003
+004 sha1:0000000000000000000000000000000000000004
+004 sha256:0000000000000000000000000000000000000000000000000000000000000004
+005 sha1:0000000000000000000000000000000000000005
+005 sha256:0000000000000000000000000000000000000000000000000000000000000005
+006 sha1:0000000000000000000000000000000000000006
+006 sha256:0000000000000000000000000000000000000000000000000000000000000006
+007 sha1:0000000000000000000000000000000000000007
+007 sha256:0000000000000000000000000000000000000000000000000000000000000007
+# All zeros or Fs missing one or two hex segments.
+zero_1 sha1:000000000000000000000000000000000000000
+zero_1 sha256:000000000000000000000000000000000000000000000000000000000000000
+zero_2 sha1:00000000000000000000000000000000000000
+zero_2 sha256:00000000000000000000000000000000000000000000000000000000000000
+ff_1 sha1:fffffffffffffffffffffffffffffffffffffff
+ff_1 sha256:fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
+ff_2 sha1:ffffffffffffffffffffffffffffffffffffff
+ff_2 sha256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
+# More various invalid OIDs.
+numeric sha1:0123456789012345678901234567890123456789
+numeric sha256:0123456789012345678901234567890123456789012345678901234567890123
+deadbeef sha1:deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
+deadbeef sha256:deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 850f651e4e..e3cace299e 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -821,6 +821,41 @@ test_expect_success 'tests clean up even on failures' "
EOF
"
+test_oid_init
+
+test_expect_success 'test_oid provides sane info by default' '
+ test_oid zero >actual &&
+ grep "^00*$" actual &&
+ rawsz="$(test_oid rawsz)" &&
+ hexsz="$(test_oid hexsz)" &&
+ test "$hexsz" -eq $(wc -c <actual) &&
+ test $(( $rawsz * 2)) -eq "$hexsz"
+'
+
+test_expect_success 'test_oid can look up data for SHA-1' '
+ test_when_finished "test_detect_hash" &&
+ test_set_hash sha1 &&
+ test_oid zero >actual &&
+ grep "^00*$" actual &&
+ rawsz="$(test_oid rawsz)" &&
+ hexsz="$(test_oid hexsz)" &&
+ test $(wc -c <actual) -eq 40 &&
+ test "$rawsz" -eq 20 &&
+ test "$hexsz" -eq 40
+'
+
+test_expect_success 'test_oid can look up data for SHA-256' '
+ test_when_finished "test_detect_hash" &&
+ test_set_hash sha256 &&
+ test_oid zero >actual &&
+ grep "^00*$" actual &&
+ rawsz="$(test_oid rawsz)" &&
+ hexsz="$(test_oid hexsz)" &&
+ test $(wc -c <actual) -eq 64 &&
+ test "$rawsz" -eq 32 &&
+ test "$hexsz" -eq 64
+'
+
################################################################
# Basics of the basics
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 4207af4077..2300ec49dd 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1155,3 +1155,47 @@ depacketize () {
}
'
}
+
+test_set_hash () {
+ test_hash_algo="$1"
+}
+
+test_detect_hash () {
+ test_hash_algo='sha1'
+}
+
+test_oid_init () {
+ test_oid_cache <"$TEST_DIRECTORY/oid-info/hash-info" &&
+ test_oid_cache <"$TEST_DIRECTORY/oid-info/oid"
+}
+
+test_oid_cache () {
+ test -n "$test_hash_algo" || test_detect_hash
+ while read _tag _rest
+ do
+ case $_tag in
+ \#*)
+ continue;;
+ ?*)
+ # non-empty
+ ;;
+ *)
+ # blank line
+ continue;;
+
+ esac &&
+
+ _k="${_rest%:*}" &&
+ _v="${_rest#*:}" &&
+ { echo "$_k" | egrep '^[a-z0-9]+$' >/dev/null ||
+ error 'bug in the test script: bad hash algorithm'; } &&
+ eval "test_oid_${_k}_$_tag=\"\$_v\"" || return 1
+ done
+}
+
+test_oid () {
+ eval "
+ test -n \"\${test_oid_${test_hash_algo}_$1+set}\" &&
+ printf '%s' \"\${test_oid_${test_hash_algo}_$1}\"
+ "
+}
next prev parent reply other threads:[~2018-08-29 0:57 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-29 0:56 [PATCH v3 00/11] Hash-independent tests (part 3) brian m. carlson
2018-08-29 0:56 ` brian m. carlson [this message]
2018-08-29 4:05 ` [PATCH v3 01/11] t: add tool to translate hash-related values Jonathan Nieder
2018-08-29 23:22 ` brian m. carlson
2018-08-29 12:37 ` Derrick Stolee
2018-08-29 22:52 ` brian m. carlson
2018-08-29 0:56 ` [PATCH v3 02/11] t0000: use hash translation table brian m. carlson
2018-08-29 0:56 ` [PATCH v3 03/11] t0000: update tests for SHA-256 brian m. carlson
2018-08-29 0:56 ` [PATCH v3 04/11] t0002: abstract away SHA-1 specific constants brian m. carlson
2018-08-29 0:56 ` [PATCH v3 05/11] t0027: make hash size independent brian m. carlson
2018-08-31 18:21 ` Torsten Bögershausen
2018-08-31 18:40 ` Eric Sunshine
2018-09-01 15:33 ` brian m. carlson
2018-08-29 0:56 ` [PATCH v3 06/11] t0064: " brian m. carlson
2018-08-29 0:56 ` [PATCH v3 07/11] t1006: " brian m. carlson
2018-08-29 0:56 ` [PATCH v3 08/11] t1400: switch hard-coded object ID to variable brian m. carlson
2018-08-29 0:56 ` [PATCH v3 09/11] t1405: make hash size independent brian m. carlson
2018-08-29 0:56 ` [PATCH v3 10/11] t1406: make hash-size independent brian m. carlson
2018-08-29 0:56 ` [PATCH v3 11/11] t1407: make hash size independent brian m. carlson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180829005642.980617-2-sandals@crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=sunshine@sunshineco.com \
--cc=tboegi@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).