{"thread":{"id":"35257","subject":"[PATCH] Test code for htonll, ntohll","startedAt":"2013-10-31T13:26:12Z","lastAt":"2013-10-31T13:26:12Z","messageCount":1,"participants":["Torsten Bögershausen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"229918","messageId":"201310311426.13657.tboegi@web.de","threadId":"35257","inReplyTo":null,"subject":"[PATCH] Test code for htonll, ntohll","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2013-10-31T13:26:12Z","receivedAt":"2013-10-31T13:26:12Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"\ntest-endianess.c adds test code for htonl(), ntohll()\nand the recently introduced ntohll() and htonll()\n\nThe test is called in t0070\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n .gitignore             |    1 +\n Makefile               |    3 +++\n t/t0070-fundamental.sh |    3 +++\n test-endianess.c       |   58 ++++++++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 65 insertions(+)\n create mode 100644 test-endianess.c\n\ndiff --git a/.gitignore b/.gitignore\nindex 66199ed..750e7d8 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -183,6 +183,7 @@\n /test-date\n /test-delta\n /test-dump-cache-tree\n+/test-endianess\n /test-scrap-cache-tree\n /test-genrandom\n /test-index-version\ndiff --git a/Makefile b/Makefile\nindex 07b0626..50957c7 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -555,6 +555,7 @@ TEST_PROGRAMS_NEED_X += test-ctype\n TEST_PROGRAMS_NEED_X += test-date\n TEST_PROGRAMS_NEED_X += test-delta\n TEST_PROGRAMS_NEED_X += test-dump-cache-tree\n+TEST_PROGRAMS_NEED_X += test-endianess\n TEST_PROGRAMS_NEED_X += test-genrandom\n TEST_PROGRAMS_NEED_X += test-hashmap\n TEST_PROGRAMS_NEED_X += test-index-version\n@@ -2275,6 +2276,8 @@ test-date$X: date.o ctype.o\n \n test-delta$X: diff-delta.o patch-delta.o\n \n+test-endianess$X: test-endianess.c\n+\n test-line-buffer$X: vcs-svn/lib.a\n \n test-parse-options$X: parse-options.o parse-options-cb.o\ndiff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh\nindex 5ed69a6..dc687da 100755\n--- a/t/t0070-fundamental.sh\n+++ b/t/t0070-fundamental.sh\n@@ -33,5 +33,8 @@ test_expect_success 'check for a bug in the regex routines' '\n \t# if this test fails, re-build git with NO_REGEX=1\n \ttest-regex\n '\n+test_expect_success 'test endianess, htonll(), ntohll()' '\n+\ttest-endianess\n+'\n \n test_done\ndiff --git a/test-endianess.c b/test-endianess.c\nnew file mode 100644\nindex 0000000..5b49175\n--- /dev/null\n+++ b/test-endianess.c\n@@ -0,0 +1,58 @@\n+#include \"cache.h\"\n+\n+int main(int argc, char **argv)\n+{\n+\tunion {\n+\t\tuint8_t  bytes[8];\n+\t\tuint32_t word32;\n+\t\tuint64_t word64;\n+\t} wordll;\n+\tvolatile uint64_t word64;\n+\tvolatile uint32_t word32;\n+\n+\twordll.bytes[0] = 0x80;\n+\twordll.bytes[1] = 0x81;\n+\twordll.bytes[2] = 0x82;\n+\twordll.bytes[3] = 0x83;\n+\twordll.bytes[4] = 0x00;\n+\twordll.bytes[5] = 0x01;\n+\twordll.bytes[6] = 0x02;\n+\twordll.bytes[7] = 0x03;\n+\n+\tword32 = htonl(wordll.word32);\n+\tif (word32 != 0x80818283)\n+\t\tdie(\"htonl word32 != 0x80818283\");\n+\n+\tword64 = htonll(wordll.word64);\n+\tif (word64 != 0x8081828300010203ULL)\n+\t\tdie(\"htonll word64 != 0x8081828300010203\");\n+\n+\tword32 = ntohl(wordll.word32);\n+\tif (word32 != 0x80818283)\n+\t\tdie(\"ntohl word32 != 0x80818283\");\n+\n+\tword64 = ntohll(wordll.word64);\n+\tif (word64 != 0x8081828300010203ULL)\n+\t\tdie(\"ntohll word64 != 0x8081828300010203\");\n+\n+\twordll.bytes[0] = 0x04;\n+\twordll.bytes[4] = 0x84;\n+\n+\tword32 = htonl(wordll.word32);\n+\tif (word32 != 0x04818283)\n+\t\tdie(\"htonl word32 != 0x04818283\");\n+\n+\tword64 = htonll(wordll.word64);\n+\tif (word64 != 0x0481828384010203ULL)\n+\t\tdie(\"htonll word64 != 0x0481828384010203\");\n+\n+\tword32 = ntohl(wordll.word32);\n+\tif (word32 != 0x04818283)\n+\t\tdie(\"ntohl word32 != 0x04818283\");\n+\n+\tword64 = ntohll(wordll.word64);\n+\tif (word64 != 0x0481828384010203ULL)\n+\t\tdie(\"ntohll word64 != 0x0481828384010203\");\n+\n+\treturn 0;\n+}\n-- \n1.7.10.4\n"}]}