xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86emul/test: add a private header
@ 2016-12-06 13:40 Jan Beulich
  2016-12-06 14:54 ` Andrew Cooper
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2016-12-06 13:40 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper

[-- Attachment #1: Type: text/plain, Size: 4084 bytes --]

This is to avoid having to duplicate auxiliary definitions in both
source files.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/tools/tests/x86_emulator/test_x86_emulator.c
+++ b/tools/tests/x86_emulator/test_x86_emulator.c
@@ -1,15 +1,9 @@
-#include <assert.h>
 #include <errno.h>
 #include <limits.h>
-#include <stdbool.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <xen/xen.h>
 #include <sys/mman.h>
 
-#include "x86_emulate/x86_emulate.h"
+#include "x86_emulate.h"
 #include "blowfish.h"
 
 #define verbose false /* Switch to true for far more logging. */
@@ -1373,7 +1367,7 @@ int main(int argc, char **argv)
     else
         printf("skipped\n");
 
-    for ( j = 0; j < sizeof(blobs) / sizeof(*blobs); j++ )
+    for ( j = 0; j < ARRAY_SIZE(blobs); j++ )
     {
         memcpy(res, blobs[j].code, blobs[j].size);
         ctxt.addr_size = ctxt.sp_size = blobs[j].bitness;
--- a/tools/tests/x86_emulator/x86_emulate.c
+++ b/tools/tests/x86_emulator/x86_emulate.c
@@ -1,34 +1,8 @@
-#include <assert.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <xen/xen.h>
-
-#include "x86_emulate/x86_emulate.h"
-
-#define is_canonical_address(x) (((int64_t)(x) >> 47) == ((int64_t)(x) >> 63))
+#include "x86_emulate.h"
 
 #define EFER_SCE       (1 << 0)
 #define EFER_LMA       (1 << 10)
 
-#define BUG() abort()
-#define ASSERT_UNREACHABLE() assert(!__LINE__)
-
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
-/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
-#define BUILD_BUG_ON_ZERO(cond) \
-    sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })
-#else
-#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); })
-#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond))
-#endif
-
-#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
-#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
-
 #define cpu_has_amd_erratum(nr) 0
 #define mark_regs_dirty(r) ((void)(r))
 
@@ -44,10 +18,4 @@
 #define get_stub(stb) ((void *)((stb).addr = (uintptr_t)(stb).buf))
 #define put_stub(stb)
 
-#define __init
-#define __maybe_unused __attribute__((__unused__))
-
-#define likely(x)     __builtin_expect(!!(x), true)
-#define unlikely(x)   __builtin_expect(!!(x), false)
-
 #include "x86_emulate/x86_emulate.c"
--- /dev/null
+++ b/tools/tests/x86_emulator/x86_emulate.h
@@ -0,0 +1,36 @@
+#include <assert.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <xen/xen.h>
+
+#define BUG() abort()
+#define ASSERT assert
+#define ASSERT_UNREACHABLE() assert(!__LINE__)
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+/* Force a compilation error if condition is true */
+#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
+#define BUILD_BUG_ON_ZERO(cond) \
+    sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })
+#else
+#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); })
+#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond))
+#endif
+
+#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
+#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
+
+#define __init
+#define __maybe_unused __attribute__((__unused__))
+
+#define likely(x)   __builtin_expect(!!(x), true)
+#define unlikely(x) __builtin_expect(!!(x), false)
+
+#define is_canonical_address(x) (((int64_t)(x) >> 47) == ((int64_t)(x) >> 63))
+
+#include "x86_emulate/x86_emulate.h"
--- a/xen/arch/x86/x86_emulate/x86_emulate.h
+++ b/xen/arch/x86/x86_emulate/x86_emulate.h
@@ -23,10 +23,6 @@
 #ifndef __X86_EMULATE_H__
 #define __X86_EMULATE_H__
 
-#if !defined(__XEN__) && !defined(ASSERT)
-#define ASSERT assert
-#endif
-
 #define MAX_INST_LEN 15
 
 struct x86_emulate_ctxt;




[-- Attachment #2: x86emul-test-header.patch --]
[-- Type: text/plain, Size: 4116 bytes --]

x86emul/test: add a private header

This is to avoid having to duplicate auxiliary definitions in both
source files.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/tools/tests/x86_emulator/test_x86_emulator.c
+++ b/tools/tests/x86_emulator/test_x86_emulator.c
@@ -1,15 +1,9 @@
-#include <assert.h>
 #include <errno.h>
 #include <limits.h>
-#include <stdbool.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <xen/xen.h>
 #include <sys/mman.h>
 
-#include "x86_emulate/x86_emulate.h"
+#include "x86_emulate.h"
 #include "blowfish.h"
 
 #define verbose false /* Switch to true for far more logging. */
@@ -1373,7 +1367,7 @@ int main(int argc, char **argv)
     else
         printf("skipped\n");
 
-    for ( j = 0; j < sizeof(blobs) / sizeof(*blobs); j++ )
+    for ( j = 0; j < ARRAY_SIZE(blobs); j++ )
     {
         memcpy(res, blobs[j].code, blobs[j].size);
         ctxt.addr_size = ctxt.sp_size = blobs[j].bitness;
--- a/tools/tests/x86_emulator/x86_emulate.c
+++ b/tools/tests/x86_emulator/x86_emulate.c
@@ -1,34 +1,8 @@
-#include <assert.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <xen/xen.h>
-
-#include "x86_emulate/x86_emulate.h"
-
-#define is_canonical_address(x) (((int64_t)(x) >> 47) == ((int64_t)(x) >> 63))
+#include "x86_emulate.h"
 
 #define EFER_SCE       (1 << 0)
 #define EFER_LMA       (1 << 10)
 
-#define BUG() abort()
-#define ASSERT_UNREACHABLE() assert(!__LINE__)
-
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
-/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
-#define BUILD_BUG_ON_ZERO(cond) \
-    sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })
-#else
-#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); })
-#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond))
-#endif
-
-#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
-#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
-
 #define cpu_has_amd_erratum(nr) 0
 #define mark_regs_dirty(r) ((void)(r))
 
@@ -44,10 +18,4 @@
 #define get_stub(stb) ((void *)((stb).addr = (uintptr_t)(stb).buf))
 #define put_stub(stb)
 
-#define __init
-#define __maybe_unused __attribute__((__unused__))
-
-#define likely(x)     __builtin_expect(!!(x), true)
-#define unlikely(x)   __builtin_expect(!!(x), false)
-
 #include "x86_emulate/x86_emulate.c"
--- /dev/null
+++ b/tools/tests/x86_emulator/x86_emulate.h
@@ -0,0 +1,36 @@
+#include <assert.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <xen/xen.h>
+
+#define BUG() abort()
+#define ASSERT assert
+#define ASSERT_UNREACHABLE() assert(!__LINE__)
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+/* Force a compilation error if condition is true */
+#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
+#define BUILD_BUG_ON_ZERO(cond) \
+    sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })
+#else
+#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); })
+#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond))
+#endif
+
+#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
+#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
+
+#define __init
+#define __maybe_unused __attribute__((__unused__))
+
+#define likely(x)   __builtin_expect(!!(x), true)
+#define unlikely(x) __builtin_expect(!!(x), false)
+
+#define is_canonical_address(x) (((int64_t)(x) >> 47) == ((int64_t)(x) >> 63))
+
+#include "x86_emulate/x86_emulate.h"
--- a/xen/arch/x86/x86_emulate/x86_emulate.h
+++ b/xen/arch/x86/x86_emulate/x86_emulate.h
@@ -23,10 +23,6 @@
 #ifndef __X86_EMULATE_H__
 #define __X86_EMULATE_H__
 
-#if !defined(__XEN__) && !defined(ASSERT)
-#define ASSERT assert
-#endif
-
 #define MAX_INST_LEN 15
 
 struct x86_emulate_ctxt;

[-- Attachment #3: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86emul/test: add a private header
  2016-12-06 13:40 [PATCH] x86emul/test: add a private header Jan Beulich
@ 2016-12-06 14:54 ` Andrew Cooper
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Cooper @ 2016-12-06 14:54 UTC (permalink / raw)
  To: Jan Beulich, xen-devel

On 06/12/16 13:40, Jan Beulich wrote:
> This is to avoid having to duplicate auxiliary definitions in both
> source files.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-12-06 14:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-06 13:40 [PATCH] x86emul/test: add a private header Jan Beulich
2016-12-06 14:54 ` Andrew Cooper

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).