From: "Torsten Bögershausen" <tboegi@web.de>
To: git@vger.kernel.org
Cc: ramsay@ramsay1.demon.co.uk, tanoku@gmail.com
Subject: [PATCH] Test code for htonll, ntohll
Date: Thu, 31 Oct 2013 14:26:12 +0100 [thread overview]
Message-ID: <201310311426.13657.tboegi@web.de> (raw)
test-endianess.c adds test code for htonl(), ntohll()
and the recently introduced ntohll() and htonll()
The test is called in t0070
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
.gitignore | 1 +
Makefile | 3 +++
t/t0070-fundamental.sh | 3 +++
test-endianess.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 65 insertions(+)
create mode 100644 test-endianess.c
diff --git a/.gitignore b/.gitignore
index 66199ed..750e7d8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -183,6 +183,7 @@
/test-date
/test-delta
/test-dump-cache-tree
+/test-endianess
/test-scrap-cache-tree
/test-genrandom
/test-index-version
diff --git a/Makefile b/Makefile
index 07b0626..50957c7 100644
--- a/Makefile
+++ b/Makefile
@@ -555,6 +555,7 @@ TEST_PROGRAMS_NEED_X += test-ctype
TEST_PROGRAMS_NEED_X += test-date
TEST_PROGRAMS_NEED_X += test-delta
TEST_PROGRAMS_NEED_X += test-dump-cache-tree
+TEST_PROGRAMS_NEED_X += test-endianess
TEST_PROGRAMS_NEED_X += test-genrandom
TEST_PROGRAMS_NEED_X += test-hashmap
TEST_PROGRAMS_NEED_X += test-index-version
@@ -2275,6 +2276,8 @@ test-date$X: date.o ctype.o
test-delta$X: diff-delta.o patch-delta.o
+test-endianess$X: test-endianess.c
+
test-line-buffer$X: vcs-svn/lib.a
test-parse-options$X: parse-options.o parse-options-cb.o
diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh
index 5ed69a6..dc687da 100755
--- a/t/t0070-fundamental.sh
+++ b/t/t0070-fundamental.sh
@@ -33,5 +33,8 @@ test_expect_success 'check for a bug in the regex routines' '
# if this test fails, re-build git with NO_REGEX=1
test-regex
'
+test_expect_success 'test endianess, htonll(), ntohll()' '
+ test-endianess
+'
test_done
diff --git a/test-endianess.c b/test-endianess.c
new file mode 100644
index 0000000..5b49175
--- /dev/null
+++ b/test-endianess.c
@@ -0,0 +1,58 @@
+#include "cache.h"
+
+int main(int argc, char **argv)
+{
+ union {
+ uint8_t bytes[8];
+ uint32_t word32;
+ uint64_t word64;
+ } wordll;
+ volatile uint64_t word64;
+ volatile uint32_t word32;
+
+ wordll.bytes[0] = 0x80;
+ wordll.bytes[1] = 0x81;
+ wordll.bytes[2] = 0x82;
+ wordll.bytes[3] = 0x83;
+ wordll.bytes[4] = 0x00;
+ wordll.bytes[5] = 0x01;
+ wordll.bytes[6] = 0x02;
+ wordll.bytes[7] = 0x03;
+
+ word32 = htonl(wordll.word32);
+ if (word32 != 0x80818283)
+ die("htonl word32 != 0x80818283");
+
+ word64 = htonll(wordll.word64);
+ if (word64 != 0x8081828300010203ULL)
+ die("htonll word64 != 0x8081828300010203");
+
+ word32 = ntohl(wordll.word32);
+ if (word32 != 0x80818283)
+ die("ntohl word32 != 0x80818283");
+
+ word64 = ntohll(wordll.word64);
+ if (word64 != 0x8081828300010203ULL)
+ die("ntohll word64 != 0x8081828300010203");
+
+ wordll.bytes[0] = 0x04;
+ wordll.bytes[4] = 0x84;
+
+ word32 = htonl(wordll.word32);
+ if (word32 != 0x04818283)
+ die("htonl word32 != 0x04818283");
+
+ word64 = htonll(wordll.word64);
+ if (word64 != 0x0481828384010203ULL)
+ die("htonll word64 != 0x0481828384010203");
+
+ word32 = ntohl(wordll.word32);
+ if (word32 != 0x04818283)
+ die("ntohl word32 != 0x04818283");
+
+ word64 = ntohll(wordll.word64);
+ if (word64 != 0x0481828384010203ULL)
+ die("ntohll word64 != 0x0481828384010203");
+
+ return 0;
+}
--
1.7.10.4
reply other threads:[~2013-10-31 13:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201310311426.13657.tboegi@web.de \
--to=tboegi@web.de \
--cc=git@vger.kernel.org \
--cc=ramsay@ramsay1.demon.co.uk \
--cc=tanoku@gmail.com \
/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.
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 NNTP newsgroup(s).