Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/tls-maxphys]: src/sys/external/bsd/sljit/dist/test_src Compile with WARN...



details:   https://anonhg.NetBSD.org/src/rev/97fe8f7a046b
branches:  tls-maxphys
changeset: 852945:97fe8f7a046b
user:      alnsn <alnsn%NetBSD.org@localhost>
date:      Mon Nov 05 00:29:58 2012 +0000

description:
Compile with WARNS=3.

diffstat:

 sys/external/bsd/sljit/dist/test_src/sljitTest.c |  3784 ++++++++++++++++++++++
 1 files changed, 3784 insertions(+), 0 deletions(-)

diffs (truncated from 3788 to 300 lines):

diff -r 6dee9b6c6190 -r 97fe8f7a046b sys/external/bsd/sljit/dist/test_src/sljitTest.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/sljit/dist/test_src/sljitTest.c  Mon Nov 05 00:29:58 2012 +0000
@@ -0,0 +1,3784 @@
+/*
+ *    Stack-less Just-In-Time compiler
+ *
+ *    Copyright 2009-2010 Zoltan Herczeg (hzmester%freemail.hu@localhost). All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright notice, this list of
+ *      conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *      of conditions and the following disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+ * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "sljitLir.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+union executable_code {
+       void* code;
+       sljit_w (SLJIT_CALL *func0)(void);
+       sljit_w (SLJIT_CALL *func1)(sljit_w a);
+       sljit_w (SLJIT_CALL *func2)(sljit_w a, sljit_w b);
+       sljit_w (SLJIT_CALL *func3)(sljit_w a, sljit_w b, sljit_w c);
+};
+typedef union executable_code executable_code;
+
+static int successful_tests = 0;
+
+#define FAILED(cond, text) \
+       if (SLJIT_UNLIKELY(cond)) { \
+               printf(text); \
+               return; \
+       }
+
+#define CHECK(compiler) \
+       if (sljit_get_compiler_error(compiler) != SLJIT_ERR_COMPILED) { \
+               printf("Compiler error: %d\n", sljit_get_compiler_error(compiler)); \
+               sljit_free_compiler(compiler); \
+               return; \
+       }
+
+static void cond_set(struct sljit_compiler *compiler, int dst, sljit_w dstw, int type)
+{
+       /* Testing both sljit_emit_cond_value and sljit_emit_jump. */
+       struct sljit_jump* jump;
+       struct sljit_label* label;
+
+       sljit_emit_cond_value(compiler, SLJIT_MOV, dst, dstw, type);
+       jump = sljit_emit_jump(compiler, type);
+       sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_KEEP_FLAGS, dst, dstw, dst, dstw, SLJIT_IMM, 2);
+       label = sljit_emit_label(compiler);
+       sljit_set_label(jump, label);
+}
+
+#if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
+
+#define MALLOC_EXEC(result, size) \
+       result = SLJIT_MALLOC_EXEC(size); \
+       if (!result) { \
+               printf("Cannot allocate executable memory\n"); \
+               return; \
+       } \
+       memset(result, 255, size);
+
+static void test_exec_allocator(void)
+{
+       /* This is not an sljit test. */
+       void *ptr1;
+       void *ptr2;
+       void *ptr3;
+
+       MALLOC_EXEC(ptr1, 32);
+       MALLOC_EXEC(ptr2, 512);
+       MALLOC_EXEC(ptr3, 512);
+       SLJIT_FREE_EXEC(ptr2);
+       SLJIT_FREE_EXEC(ptr3);
+       SLJIT_FREE_EXEC(ptr1);
+       MALLOC_EXEC(ptr1, 262104);
+       MALLOC_EXEC(ptr2, 32000);
+       SLJIT_FREE_EXEC(ptr1);
+       MALLOC_EXEC(ptr1, 262104);
+       SLJIT_FREE_EXEC(ptr1);
+       SLJIT_FREE_EXEC(ptr2);
+       MALLOC_EXEC(ptr1, 512);
+       MALLOC_EXEC(ptr2, 512);
+       MALLOC_EXEC(ptr3, 512);
+       SLJIT_FREE_EXEC(ptr2);
+       MALLOC_EXEC(ptr2, 512);
+       SLJIT_FREE_EXEC(ptr3);
+       SLJIT_FREE_EXEC(ptr1);
+       SLJIT_FREE_EXEC(ptr2);
+#if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
+       /* Just call the global locks. */
+       sljit_grab_lock();
+       sljit_release_lock();
+#endif
+       printf("Executable allocator: ok\n");
+}
+
+#undef MALLOC_EXEC
+
+#endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
+
+static void test1(void)
+{
+       /* Enter and return from an sljit function. */
+       executable_code code;
+       struct sljit_compiler* compiler = sljit_create_compiler();
+
+       FAILED(!compiler, "cannot create compiler\n");
+
+       /* 3 arguments passed, 3 arguments used. */
+       sljit_emit_enter(compiler, 3, 3, 3, 0);
+       sljit_emit_return(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0);
+
+       SLJIT_ASSERT(sljit_get_generated_code_size(compiler) == 0);
+       code.code = sljit_generate_code(compiler);
+       CHECK(compiler);
+       SLJIT_ASSERT(compiler->error == SLJIT_ERR_COMPILED);
+       SLJIT_ASSERT(sljit_get_generated_code_size(compiler) > 0);
+       sljit_free_compiler(compiler);
+
+       FAILED(code.func3(3, -21, 86) != -21, "test1 case 1 failed\n");
+       FAILED(code.func3(4789, 47890, 997) != 47890, "test1 case 2 failed\n");
+       sljit_free_code(code.code);
+       printf("test1 ok\n");
+       successful_tests++;
+}
+
+static void test2(void)
+{
+       /* Test mov. */
+       executable_code code;
+       struct sljit_compiler* compiler = sljit_create_compiler();
+       sljit_w buf[6];
+       static sljit_w data[2] = { 0, -9876 };
+
+       FAILED(!compiler, "cannot create compiler\n");
+
+       buf[0] = 5678;
+       buf[1] = 0;
+       buf[2] = 0;
+       buf[3] = 0;
+       buf[4] = 0;
+       buf[5] = 0;
+       sljit_emit_enter(compiler, 1, 3, 2, 0);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_UNUSED, 0, SLJIT_MEM0(), (sljit_w)&buf);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, 9999);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG2, 0, SLJIT_SAVED_REG1, 0);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, sizeof(sljit_w));
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG2), 0);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 2);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SAVED_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_TEMPORARY_REG2), 0);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_SAVED_REG1, 0, SLJIT_IMM, 3);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_SAVED_REG2, SLJIT_SAVED_REG1), SLJIT_WORD_SHIFT, SLJIT_MEM0(), (sljit_w)&buf);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, sizeof(sljit_w));
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), (sljit_w)&data);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 4 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, (sljit_w)&buf - 0x12345678);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_TEMPORARY_REG1), 0x12345678);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG2), 5 * sizeof(sljit_w), SLJIT_TEMPORARY_REG1, 0);
+       sljit_emit_return(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0);
+
+       code.code = sljit_generate_code(compiler);
+       CHECK(compiler);
+       sljit_free_compiler(compiler);
+
+       FAILED(code.func1((sljit_w)&buf) != 9999, "test2 case 1 failed\n");
+       FAILED(buf[1] != 9999, "test2 case 2 failed\n");
+       FAILED(buf[2] != 9999, "test2 case 3 failed\n");
+       FAILED(buf[3] != 5678, "test2 case 4 failed\n");
+       FAILED(buf[4] != -9876, "test2 case 5 failed\n");
+       FAILED(buf[5] != 5678, "test2 case 6 failed\n");
+       sljit_free_code(code.code);
+       printf("test2 ok\n");
+       successful_tests++;
+}
+
+static void test3(void)
+{
+       /* Test not. */
+       executable_code code;
+       struct sljit_compiler* compiler = sljit_create_compiler();
+       sljit_w buf[5];
+
+       FAILED(!compiler, "cannot create compiler\n");
+       buf[0] = 1234;
+       buf[1] = 0;
+       buf[2] = 9876;
+       buf[3] = 0;
+       buf[4] = 0x12345678;
+
+       sljit_emit_enter(compiler, 1, 3, 1, 0);
+       sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_UNUSED, 0, SLJIT_MEM0(), (sljit_w)&buf);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w), SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
+       sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM0(), (sljit_w)&buf[1], SLJIT_MEM0(), (sljit_w)&buf[1]);
+       sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_RETURN_REG, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
+       sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, (sljit_w)&buf[4] - 0xff0000 - 0x20);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG3, 0, SLJIT_IMM, (sljit_w)&buf[4] - 0xff0000);
+       sljit_emit_op1(compiler, SLJIT_NOT, SLJIT_MEM1(SLJIT_TEMPORARY_REG2), 0xff0000 + 0x20, SLJIT_MEM1(SLJIT_TEMPORARY_REG3), 0xff0000);
+       sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
+
+       code.code = sljit_generate_code(compiler);
+       CHECK(compiler);
+       sljit_free_compiler(compiler);
+
+       FAILED(code.func1((sljit_w)&buf) != ~1234, "test3 case 1 failed\n");
+       FAILED(buf[1] != ~1234, "test3 case 2 failed\n");
+       FAILED(buf[3] != ~9876, "test3 case 3 failed\n");
+       FAILED(buf[4] != ~0x12345678, "test3 case 4 failed\n");
+
+       sljit_free_code(code.code);
+       printf("test3 ok\n");
+       successful_tests++;
+}
+
+static void test4(void)
+{
+       /* Test neg. */
+       executable_code code;
+       struct sljit_compiler* compiler = sljit_create_compiler();
+       sljit_w buf[4];
+
+       FAILED(!compiler, "cannot create compiler\n");
+       buf[0] = 0;
+       buf[1] = 1234;
+       buf[2] = 0;
+       buf[3] = 0;
+
+       sljit_emit_enter(compiler, 2, 3, 2, 0);
+       sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_UNUSED, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);
+       sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 2, SLJIT_SAVED_REG2, 0);
+       sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM0(), (sljit_w)&buf[0], SLJIT_MEM0(), (sljit_w)&buf[1]);
+       sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_RETURN_REG, 0, SLJIT_SAVED_REG2, 0);
+       sljit_emit_op1(compiler, SLJIT_NEG, SLJIT_MEM1(SLJIT_SAVED_REG1), sizeof(sljit_w) * 3, SLJIT_IMM, 299);
+       sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0);
+
+       code.code = sljit_generate_code(compiler);
+       CHECK(compiler);
+       sljit_free_compiler(compiler);
+
+       FAILED(code.func2((sljit_w)&buf, 4567) != -4567, "test4 case 1 failed\n");
+       FAILED(buf[0] != -1234, "test4 case 2 failed\n");
+       FAILED(buf[2] != -4567, "test4 case 3 failed\n");
+       FAILED(buf[3] != -299, "test4 case 4 failed\n");
+
+       sljit_free_code(code.code);
+       printf("test4 ok\n");
+       successful_tests++;
+}
+
+static void test5(void)
+{
+       /* Test add. */
+       executable_code code;
+       struct sljit_compiler* compiler = sljit_create_compiler();
+       sljit_w buf[9];
+
+       FAILED(!compiler, "cannot create compiler\n");
+       buf[0] = 100;
+       buf[1] = 200;
+       buf[2] = 300;
+       buf[3] = 0;
+       buf[4] = 0;
+       buf[5] = 0;
+       buf[6] = 0;
+       buf[7] = 0;
+       buf[8] = 313;
+
+       sljit_emit_enter(compiler, 1, 3, 2, 0);
+       sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_IMM, 16, SLJIT_IMM, 16);
+       sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_IMM, 255, SLJIT_IMM, 255);
+       sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_UNUSED, 0, SLJIT_SAVED_REG1, 0, SLJIT_SAVED_REG1, 0);
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, sizeof(sljit_w));
+       sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 50);
+       sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), 1, SLJIT_MEM2(SLJIT_SAVED_REG1, SLJIT_TEMPORARY_REG1), 1, SLJIT_MEM2(SLJIT_SAVED_REG1, 
SLJIT_TEMPORARY_REG1), 0);
+       sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_IMM, sizeof(sljit_w) + 2);
+       sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG2, 0, SLJIT_TEMPORARY_REG2, 0, SLJIT_IMM, 50);
+       sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_TEMPORARY_REG1, 0, SLJIT_TEMPORARY_REG1, 0, SLJIT_MEM1(SLJIT_SAVED_REG1), 0);



Home | Main Index | Thread Index | Old Index