[SCM] Samba Shared Repository - branch master updated
Andrew Bartlett
abartlet at samba.org
Fri May 17 20:45:01 UTC 2019
The branch, master has been updated
via 0b8b04dbd3f lib:util: Add a test for byteorder.h
via ad04e5f5f91 lib:util: Move VWV macro to smb_constants.h
via 3f16e97fe38 lib:util: Remove PPC big endian asm optimized code in byteorder.h
via be589a1fd4d lib:util: Remove unused ALIGN marcos from byteorder.h
from 75cad1d79f6 tdb: Release tdb 1.4.1
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 0b8b04dbd3f053f11da15a8f28bbd5cbd9f4d48b
Author: Andreas Schneider <asn at samba.org>
Date: Thu May 16 08:31:40 2019 +0200
lib:util: Add a test for byteorder.h
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
Autobuild-Date(master): Fri May 17 20:44:36 UTC 2019 on sn-devel-184
commit ad04e5f5f9181516b7aee209237f20b9ca90da97
Author: Andreas Schneider <asn at samba.org>
Date: Thu Jan 17 11:03:14 2019 +0100
lib:util: Move VWV macro to smb_constants.h
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit 3f16e97fe38df7e46ec16d131da8a45577863bfa
Author: Andreas Schneider <asn at samba.org>
Date: Fri Dec 21 09:43:01 2018 +0100
lib:util: Remove PPC big endian asm optimized code in byteorder.h
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
commit be589a1fd4d8dfba2d16f8e62bb7e63e114ec16f
Author: Andreas Schneider <asn at samba.org>
Date: Thu Dec 20 10:01:03 2018 +0100
lib:util: Remove unused ALIGN marcos from byteorder.h
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Andrew Bartlett <abartlet at samba.org>
-----------------------------------------------------------------------
Summary of changes:
lib/util/byteorder.h | 59 ------
lib/util/tests/test_byteorder.c | 435 ++++++++++++++++++++++++++++++++++++++++
lib/util/wscript_build | 6 +
libcli/smb/smb_constants.h | 3 +
selftest/tests.py | 2 +
5 files changed, 446 insertions(+), 59 deletions(-)
create mode 100644 lib/util/tests/test_byteorder.c
Changeset truncated at 500 lines:
diff --git a/lib/util/byteorder.h b/lib/util/byteorder.h
index 8656035693d..d58e6d0b7d7 100644
--- a/lib/util/byteorder.h
+++ b/lib/util/byteorder.h
@@ -88,60 +88,11 @@ it also defines lots of intermediate macros, just ignore those :-)
*/
-/*
- * On powerpc we can use the magic instructions to load/store in little endian.
- * The instructions are reverse-indexing, so assume a big endian Power
- * processor. Power8 can be big or little endian, so we need to explicitly
- * check.
- */
-#if (defined(__powerpc__) && defined(__GNUC__) && HAVE_BIG_ENDIAN)
-static __inline__ uint16_t ld_le16(const uint16_t *addr)
-{
- uint16_t val;
- __asm__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
- return val;
-}
-
-static __inline__ void st_le16(uint16_t *addr, const uint16_t val)
-{
- __asm__ ("sthbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
-}
-
-static __inline__ uint32_t ld_le32(const uint32_t *addr)
-{
- uint32_t val;
- __asm__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
- return val;
-}
-
-static __inline__ void st_le32(uint32_t *addr, const uint32_t val)
-{
- __asm__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
-}
-#define USE_ASM_BYTEORDER 1
-#else
-#define USE_ASM_BYTEORDER 0
-#endif
-
#define CVAL(buf,pos) ((unsigned int)(((const uint8_t *)(buf))[pos]))
#define CVAL_NC(buf,pos) (((uint8_t *)(buf))[pos]) /* Non-const version of CVAL */
#define PVAL(buf,pos) (CVAL(buf,pos))
#define SCVAL(buf,pos,val) (CVAL_NC(buf,pos) = (val))
-#if USE_ASM_BYTEORDER
-
-#define _PTRPOS(buf,pos) (((const uint8_t *)(buf))+(pos))
-#define SVAL(buf,pos) ld_le16((const uint16_t *)_PTRPOS(buf,pos))
-#define IVAL(buf,pos) ld_le32((const uint32_t *)_PTRPOS(buf,pos))
-#define SSVAL(buf,pos,val) st_le16((uint16_t *)_PTRPOS(buf,pos), val)
-#define SIVAL(buf,pos,val) st_le32((uint32_t *)_PTRPOS(buf,pos), val)
-#define SVALS(buf,pos) ((int16_t)SVAL(buf,pos))
-#define IVALS(buf,pos) ((int32_t)IVAL(buf,pos))
-#define SSVALS(buf,pos,val) SSVAL((buf),(pos),((int16_t)(val)))
-#define SIVALS(buf,pos,val) SIVAL((buf),(pos),((int32_t)(val)))
-
-#else /* not USE_ASM_BYTEORDER */
-
#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
#define SSVALX(buf,pos,val) (CVAL_NC(buf,pos)=(uint8_t)((val)&0xFF),CVAL_NC(buf,pos+1)=(uint8_t)((val)>>8))
@@ -153,8 +104,6 @@ static __inline__ void st_le32(uint32_t *addr, const uint32_t val)
#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16_t)(val)))
#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32_t)(val)))
-#endif /* not USE_ASM_BYTEORDER */
-
/* 64 bit macros */
#define BVAL(p, ofs) (IVAL(p,ofs) | (((uint64_t)IVAL(p,(ofs)+4)) << 32))
#define BVALS(p, ofs) ((int64_t)BVAL(p,ofs))
@@ -179,12 +128,4 @@ static __inline__ void st_le32(uint32_t *addr, const uint32_t val)
#define RSBVAL(buf,pos,val) SBVAL(buf,pos,BREV(val))
#define RSBVALS(buf,pos,val) SBVALS(buf,pos,BREV(val))
-/* Alignment macros. */
-#define ALIGN4(p,base) ((p) + ((4 - (PTR_DIFF((p), (base)) & 3)) & 3))
-#define ALIGN2(p,base) ((p) + ((2 - (PTR_DIFF((p), (base)) & 1)) & 1))
-
-
-/* macros for accessing SMB protocol elements */
-#define VWV(vwv) ((vwv)*2)
-
#endif /* _BYTEORDER_H */
diff --git a/lib/util/tests/test_byteorder.c b/lib/util/tests/test_byteorder.c
new file mode 100644
index 00000000000..9faa0380826
--- /dev/null
+++ b/lib/util/tests/test_byteorder.c
@@ -0,0 +1,435 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * Copyright (C) 2018-2019 Andreas Schneider <asn at samba.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include "lib/replace/replace.h"
+#include "lib/util/byteorder.h"
+
+static void torture_pull_le_u8(void **state)
+{
+ uint8_t data[2] = {0};
+ uint8_t result;
+
+ (void)state;
+
+ result = CVAL(data, 0);
+ assert_int_equal(result, 0);
+
+ data[0] = 0x2a;
+ result = CVAL(data, 0);
+ assert_int_equal(result, 42);
+
+
+ data[0] = 0xf;
+ result = CVAL(data, 0);
+ assert_int_equal(result, 0xf);
+
+ data[0] = 0xff;
+ result = CVAL(data, 0);
+ assert_int_equal(result, 0xff);
+
+ data[1] = 0x2a;
+ result = CVAL(data, 1);
+ assert_int_equal(result, 42);
+}
+
+static void torture_pull_le_u16(void **state)
+{
+ uint8_t data[2] = {0, 0};
+ uint16_t result;
+
+ (void)state;
+
+ result = SVAL(data, 0);
+ assert_int_equal(result, 0);
+
+ data[0] = 0x2a;
+ data[1] = 0x00;
+ result = SVAL(data, 0);
+ assert_int_equal(result, 42);
+
+ data[0] = 0xff;
+ data[1] = 0x00;
+ result = SVAL(data, 0);
+ assert_int_equal(result, 0x00ff);
+
+ data[0] = 0x00;
+ data[1] = 0xff;
+ result = SVAL(data, 0);
+ assert_int_equal(result, 0xff00);
+
+ data[0] = 0xff;
+ data[1] = 0xff;
+ result = SVAL(data, 0);
+ assert_int_equal(result, 0xffff);
+}
+
+static void torture_pull_le_u32(void **state)
+{
+ uint8_t data[4] = {0, 0, 0, 0};
+ uint32_t result;
+
+ (void)state;
+
+ result = IVAL(data, 0);
+ assert_int_equal(result, 0);
+
+ data[0] = 0x2a;
+ data[1] = 0x00;
+ data[2] = 0x00;
+ data[3] = 0x00;
+ result = IVAL(data, 0);
+ assert_int_equal(result, 42);
+
+ data[0] = 0xff;
+ data[1] = 0x00;
+ data[2] = 0x00;
+ data[3] = 0x00;
+ result = IVAL(data, 0);
+ assert_int_equal(result, 0x00ff);
+
+ data[0] = 0x00;
+ data[1] = 0xff;
+ data[2] = 0x00;
+ data[3] = 0x00;
+ result = IVAL(data, 0);
+ assert_int_equal(result, 0xff00);
+
+ data[0] = 0x00;
+ data[1] = 0x00;
+ data[2] = 0xff;
+ data[3] = 0x00;
+ result = IVAL(data, 0);
+ assert_int_equal(result, 0xff0000);
+
+ data[0] = 0x00;
+ data[1] = 0x00;
+ data[2] = 0x00;
+ data[3] = 0xff;
+ result = IVAL(data, 0);
+ assert_int_equal(result, 0xff000000);
+
+ data[0] = 0xff;
+ data[1] = 0xff;
+ data[2] = 0xff;
+ data[3] = 0xff;
+ result = IVAL(data, 0);
+ assert_int_equal(result, 0xffffffff);
+}
+
+static void torture_push_le_u8(void **state)
+{
+ uint8_t data[4] = {0, 0, 0, 0};
+ uint8_t data2[4] = {42, 42, 42, 42};
+
+ (void)state;
+
+ SCVAL(data, 0, 42);
+ SCVAL(data, 1, 42);
+ SCVAL(data, 2, 42);
+ SCVAL(data, 3, 42);
+ assert_memory_equal(data, data2, sizeof(data));
+}
+
+static void torture_push_le_u16(void **state)
+{
+ uint8_t data[4] = {0, 0, 0, 0};
+ uint8_t data2[4] = {0xa6, 0x7f, 0x2a, 0x00};
+ uint16_t result;
+
+ (void)state;
+
+ SSVALX(data, 0, 32678);
+ SSVALX(data, 2, 42);
+ assert_memory_equal(data, data2, sizeof(data));
+
+ result = SVAL(data, 2);
+ assert_int_equal(result, 42);
+
+ result = SVAL(data, 0);
+ assert_int_equal(result, 32678);
+}
+
+static void torture_push_le_u32(void **state)
+{
+ uint8_t data[8] = {0};
+ uint8_t data2[8] = {0xa6, 0x7f, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00};
+ uint32_t result;
+
+ (void)state;
+
+ SIVALX(data, 0, 32678);
+ SIVALX(data, 4, 42);
+ assert_memory_equal(data, data2, sizeof(data));
+
+ result = IVAL(data, 4);
+ assert_int_equal(result, 42);
+
+ result = IVAL(data, 0);
+ assert_int_equal(result, 32678);
+
+ SIVALX(data, 0, 0xfffefffe);
+ result = IVAL(data, 0);
+ assert_int_equal(result, 0xfffefffe);
+}
+
+static void torture_push_le_u64(void **state)
+{
+ uint8_t data[16] = {0};
+ uint64_t result;
+
+ (void)state;
+
+ SBVAL(data, 0, 32678);
+
+ result = BVAL(data, 0);
+ assert_int_equal(result, 32678);
+
+ SBVAL(data, 0, 0xfffefffefffefffeUL);
+
+ result = BVAL(data, 0);
+ assert_int_equal(result, 0xfffefffefffefffeUL);
+}
+
+/****************** BIG ENDIAN ********************/
+
+static void torture_pull_be_u8(void **state)
+{
+ uint8_t data[2] = {0};
+ uint8_t result;
+
+ (void)state;
+
+ result = CVAL(data, 0);
+ assert_int_equal(result, 0);
+
+ data[0] = 0x2a;
+ result = CVAL(data, 0);
+ assert_int_equal(result, 42);
+
+
+ data[0] = 0xf;
+ result = CVAL(data, 0);
+ assert_int_equal(result, 0xf);
+
+ data[0] = 0xff;
+ result = CVAL(data, 0);
+ assert_int_equal(result, 0xff);
+
+ data[1] = 0x2a;
+ result = CVAL(data, 1);
+ assert_int_equal(result, 42);
+}
+
+static void torture_pull_be_u16(void **state)
+{
+ uint8_t data[2] = {0, 0};
+ uint16_t result;
+
+ (void)state;
+
+ result = RSVAL(data, 0);
+ assert_int_equal(result, 0);
+
+ data[0] = 0x00;
+ data[1] = 0x2a;
+ result = RSVAL(data, 0);
+ assert_int_equal(result, 42);
+
+ data[0] = 0x00;
+ data[1] = 0xff;
+ result = RSVAL(data, 0);
+ assert_int_equal(result, 0x00ff);
+
+ data[0] = 0xff;
+ data[1] = 0x00;
+ result = RSVAL(data, 0);
+ assert_int_equal(result, 0xff00);
+
+ data[0] = 0xff;
+ data[1] = 0xff;
+ result = RSVAL(data, 0);
+ assert_int_equal(result, 0xffff);
+}
+
+static void torture_pull_be_u32(void **state)
+{
+ uint8_t data[4] = {0, 0, 0, 0};
+ uint32_t result;
+
+ (void)state;
+
+ result = RIVAL(data, 0);
+ assert_int_equal(result, 0);
+
+ data[0] = 0x00;
+ data[1] = 0x00;
+ data[2] = 0x00;
+ data[3] = 0x2a;
+ result = RIVAL(data, 0);
+ assert_int_equal(result, 42);
+
+ data[0] = 0x00;
+ data[1] = 0x00;
+ data[2] = 0x00;
+ data[3] = 0xff;
+ result = RIVAL(data, 0);
+ assert_int_equal(result, 0x00ff);
+
+ data[0] = 0x00;
+ data[1] = 0x00;
+ data[2] = 0xff;
+ data[3] = 0x00;
+ result = RIVAL(data, 0);
+ assert_int_equal(result, 0xff00);
+
+ data[0] = 0x00;
+ data[1] = 0xff;
+ data[2] = 0x00;
+ data[3] = 0x00;
+ result = RIVAL(data, 0);
+ assert_int_equal(result, 0xff0000);
+
+ data[0] = 0xff;
+ data[1] = 0x00;
+ data[2] = 0x00;
+ data[3] = 0x00;
+ result = RIVAL(data, 0);
+ assert_int_equal(result, 0xff000000);
+
+ data[0] = 0xff;
+ data[1] = 0xff;
+ data[2] = 0xff;
+ data[3] = 0xff;
+ result = RIVAL(data, 0);
+ assert_int_equal(result, 0xffffffff);
+}
+
+static void torture_push_be_u8(void **state)
+{
+ uint8_t data[4] = {0, 0, 0, 0};
+ uint8_t data2[4] = {42, 42, 42, 42};
+
+ (void)state;
+
+ SCVAL(data, 0, 42);
+ SCVAL(data, 1, 42);
+ SCVAL(data, 2, 42);
+ SCVAL(data, 3, 42);
+ assert_memory_equal(data, data2, sizeof(data));
+}
+
+static void torture_push_be_u16(void **state)
+{
+ uint8_t data[4] = {0, 0, 0, 0};
+ uint8_t data2[4] = {0x7f, 0xa6, 0x00, 0x2a};
+ uint16_t result;
+
+ (void)state;
+
+ RSSVALS(data, 0, 32678);
+ RSSVALS(data, 2, 42);
+ assert_memory_equal(data, data2, sizeof(data));
+
+ result = RSVAL(data, 2);
+ assert_int_equal(result, 42);
+
+ result = RSVAL(data, 0);
+ assert_int_equal(result, 32678);
+}
+
+static void torture_push_be_u32(void **state)
+{
+ uint8_t data[8] = {0};
+ uint8_t data2[8] = {0x00, 0x00, 0x7f, 0xa6, 0x00, 0x00, 0x00, 0x2a};
+ uint32_t result;
+
+ (void)state;
+
+ RSIVALS(data, 0, 32678);
+ RSIVALS(data, 4, 42);
+ assert_memory_equal(data, data2, sizeof(data));
+
+ result = RIVAL(data, 4);
+ assert_int_equal(result, 42);
+
+ result = RIVAL(data, 0);
+ assert_int_equal(result, 32678);
+
+ RSIVALS(data, 0, 0xfffefffe);
+ result = RIVAL(data, 0);
+ assert_int_equal(result, 0xfffefffe);
+}
+
+static void torture_push_be_u64(void **state)
+{
+ uint8_t data[16] = {0};
+ uint64_t result;
+
+ (void)state;
+
+ RSBVALS(data, 0, 32678);
+
+ result = RBVAL(data, 0);
+ assert_int_equal(result, 32678);
+
+ SBVAL(data, 8, 0xfffefffe);
+
+ result = BVAL(data, 8);
+ assert_int_equal(result, 0xfffefffe);
+}
+
+int main(int argc, char *argv[])
+{
+ int rc;
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(torture_pull_le_u8),
--
Samba Shared Repository
More information about the samba-cvs
mailing list