svn rev #22762: trunk/src/util/support/

raeburn@MIT.EDU raeburn at MIT.EDU
Tue Sep 15 02:19:32 EDT 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=22762
Commit By: raeburn
Log Message:
Test byte ordering determination and unaligned access.


Changed Files:
U   trunk/src/util/support/Makefile.in
A   trunk/src/util/support/t_unal.c
Modified: trunk/src/util/support/Makefile.in
===================================================================
--- trunk/src/util/support/Makefile.in	2009-09-15 06:17:17 UTC (rev 22761)
+++ trunk/src/util/support/Makefile.in	2009-09-15 06:19:32 UTC (rev 22762)
@@ -153,13 +153,17 @@
 t_k5buf: $(T_K5BUF_OBJS)
 	$(CC_LINK) -o t_k5buf $(T_K5BUF_OBJS)
 
-TEST_PROGS= t_k5buf
+t_unal: t_unal.o
+	$(CC_LINK) -o t_unal t_unal.o
 
+TEST_PROGS= t_k5buf t_unal
+
 check-unix:: $(TEST_PROGS)
 	./t_k5buf
+	./t_unal
 
 clean::
-	$(RM) t_k5buf.o t_k5buf
+	$(RM) t_k5buf.o t_k5buf t_unal.o t_unal
 
 @lib_frag@
 @libobj_frag@

Added: trunk/src/util/support/t_unal.c
===================================================================
--- trunk/src/util/support/t_unal.c	2009-09-15 06:17:17 UTC (rev 22761)
+++ trunk/src/util/support/t_unal.c	2009-09-15 06:19:32 UTC (rev 22762)
@@ -0,0 +1,46 @@
+#undef NDEBUG
+#include <assert.h>
+#include "k5-platform.h"
+
+int main ()
+{
+     /* Test some low-level assumptions the Kerberos code depends
+        on.  */
+
+    union {
+        UINT64_TYPE n64;
+        uint32_t n32;
+        uint16_t n16;
+        unsigned char b[9];
+    } u;
+    static unsigned char buf[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
+
+    assert(load_64_be(buf+1) == 0x0102030405060708LL);
+    assert(load_64_le(buf+1) == 0x0807060504030201LL);
+    assert(load_32_le(buf+2) == 0x05040302);
+    assert(load_32_be(buf+2) == 0x02030405);
+    assert(load_16_be(buf+3) == 0x0304);
+    assert(load_16_le(buf+3) == 0x0403);
+    u.b[0] = 0;
+    assert((store_64_be(0x0102030405060708LL, u.b+1), !memcmp(buf, u.b, 9)));
+    u.b[1] = 9;
+    assert((store_64_le(0x0807060504030201LL, u.b+1), !memcmp(buf, u.b, 9)));
+    u.b[2] = 10;
+    assert((store_32_be(0x02030405, u.b+2), !memcmp(buf, u.b, 9)));
+    u.b[3] = 11;
+    assert((store_32_le(0x05040302, u.b+2), !memcmp(buf, u.b, 9)));
+    u.b[4] = 12;
+    assert((store_16_be(0x0304, u.b+3), !memcmp(buf, u.b, 9)));
+    u.b[4] = 13;
+    assert((store_16_le(0x0403, u.b+3), !memcmp(buf, u.b, 9)));
+    /* Verify that load_*_n properly does native format.  Assume
+       the unaligned thing is okay.  */
+    u.n64 = 0x090a0b0c0d0e0f00LL;
+    assert(load_64_n((unsigned char *) &u.n64) == 0x090a0b0c0d0e0f00LL);
+    u.n32 = 0x06070809;
+    assert(load_32_n((unsigned char *) &u.n32) == 0x06070809);
+    u.n16 = 0x0a0b;
+    assert(load_16_n((unsigned char *) &u.n16) == 0x0a0b);
+
+    return 0;
+}




More information about the cvs-krb5 mailing list