@@ -30,6 +30,9 @@ else
obj-y += entry-armv.o
endif
+obj-m += test-get_user.o
+test-get_user-objs += get_user_test1.o get_user_test2.o
+
obj-$(CONFIG_OC_ETM) += etm.o
obj-$(CONFIG_CPU_IDLE) += cpuidle.o
obj-$(CONFIG_ISA_DMA_API) += dma.o
new file mode 100644
@@ -0,0 +1,54 @@
+typedef char tint8_t;
+typedef short tint16_t;
+typedef int tint32_t;
+typedef long long tint64_t;
+
+#define GUT_LOWER_TEST_DECLARE(vs, ps) \
+ tint8_t gut_lower_v ## vs ## _p ## ps \
+ (tint ## ps ## _t *ptr);
+
+GUT_LOWER_TEST_DECLARE(64, 8)
+GUT_LOWER_TEST_DECLARE(64, 16)
+GUT_LOWER_TEST_DECLARE(64, 32)
+GUT_LOWER_TEST_DECLARE(64, 64)
+
+GUT_LOWER_TEST_DECLARE(32, 8)
+GUT_LOWER_TEST_DECLARE(32, 16)
+GUT_LOWER_TEST_DECLARE(32, 32)
+GUT_LOWER_TEST_DECLARE(32, 64)
+
+GUT_LOWER_TEST_DECLARE(16, 8)
+GUT_LOWER_TEST_DECLARE(16, 16)
+GUT_LOWER_TEST_DECLARE(16, 32)
+GUT_LOWER_TEST_DECLARE(16, 64)
+
+GUT_LOWER_TEST_DECLARE(8, 8)
+GUT_LOWER_TEST_DECLARE(8, 16)
+GUT_LOWER_TEST_DECLARE(8, 32)
+GUT_LOWER_TEST_DECLARE(8, 64)
+
+
+#define GUT_UPPER_TEST_DECLARE(vs, ps) \
+ tint8_t gut_upper_v ## vs ## _p ## ps \
+ (tint ## ps ## _t *ptr);
+
+GUT_UPPER_TEST_DECLARE(64, 8)
+GUT_UPPER_TEST_DECLARE(64, 16)
+GUT_UPPER_TEST_DECLARE(64, 32)
+GUT_UPPER_TEST_DECLARE(64, 64)
+
+GUT_UPPER_TEST_DECLARE(32, 8)
+GUT_UPPER_TEST_DECLARE(32, 16)
+GUT_UPPER_TEST_DECLARE(32, 32)
+GUT_UPPER_TEST_DECLARE(32, 64)
+
+GUT_UPPER_TEST_DECLARE(16, 8)
+GUT_UPPER_TEST_DECLARE(16, 16)
+GUT_UPPER_TEST_DECLARE(16, 32)
+GUT_UPPER_TEST_DECLARE(16, 64)
+
+GUT_UPPER_TEST_DECLARE(8, 8)
+GUT_UPPER_TEST_DECLARE(8, 16)
+GUT_UPPER_TEST_DECLARE(8, 32)
+GUT_UPPER_TEST_DECLARE(8, 64)
+
new file mode 100644
@@ -0,0 +1,77 @@
+#include <asm/uaccess.h>
+
+#include "get_user_test.h"
+
+#define GUT_LOWER_TEST(vs, ps) \
+ tint8_t gut_lower_v ## vs ## _p ## ps \
+ (tint ## ps ## _t *ptr) \
+{ \
+ tint ## vs ## _t value = 0; \
+ \
+ mm_segment_t fs; \
+ fs = get_fs(); \
+ set_fs(KERNEL_DS); \
+ \
+ get_user(value, ptr); \
+ \
+ set_fs(fs); \
+ return 0xff & value; \
+} \
+
+GUT_LOWER_TEST(64, 8)
+GUT_LOWER_TEST(64, 16)
+GUT_LOWER_TEST(64, 32)
+GUT_LOWER_TEST(64, 64)
+
+GUT_LOWER_TEST(32, 8)
+GUT_LOWER_TEST(32, 16)
+GUT_LOWER_TEST(32, 32)
+GUT_LOWER_TEST(32, 64)
+
+GUT_LOWER_TEST(16, 8)
+GUT_LOWER_TEST(16, 16)
+GUT_LOWER_TEST(16, 32)
+GUT_LOWER_TEST(16, 64)
+
+GUT_LOWER_TEST(8, 8)
+GUT_LOWER_TEST(8, 16)
+GUT_LOWER_TEST(8, 32)
+GUT_LOWER_TEST(8, 64)
+
+
+#define GUT_UPPER_TEST(vs, ps) \
+ tint8_t gut_upper_v ## vs ## _p ## ps \
+ (tint ## ps ## _t *ptr) \
+{ \
+ tint ## vs ## _t value = 0; \
+ \
+ mm_segment_t fs; \
+ fs = get_fs(); \
+ set_fs(KERNEL_DS); \
+ \
+ get_user(value, ptr); \
+ \
+ set_fs(fs); \
+ return 0xff & (value >> ((vs > ps) ? (ps - 8) : (vs - 8))); \
+} \
+
+
+GUT_UPPER_TEST(64, 8)
+GUT_UPPER_TEST(64, 16)
+GUT_UPPER_TEST(64, 32)
+GUT_UPPER_TEST(64, 64)
+
+GUT_UPPER_TEST(32, 8)
+GUT_UPPER_TEST(32, 16)
+GUT_UPPER_TEST(32, 32)
+GUT_UPPER_TEST(32, 64)
+
+GUT_UPPER_TEST(16, 8)
+GUT_UPPER_TEST(16, 16)
+GUT_UPPER_TEST(16, 32)
+GUT_UPPER_TEST(16, 64)
+
+GUT_UPPER_TEST(8, 8)
+GUT_UPPER_TEST(8, 16)
+GUT_UPPER_TEST(8, 32)
+GUT_UPPER_TEST(8, 64)
new file mode 100644
@@ -0,0 +1,151 @@
+#include <linux/module.h>
+#include "get_user_test.h"
+
+tint8_t gut_data8 = 0x12;
+tint16_t gut_data16 = 0x1234;
+tint32_t gut_data32 = 0x12345678;
+tint64_t gut_data64 = 0x1234567890abcdef;
+
+#define GUT_RUN_LOWER_TEST(vs, ps, expect) \
+ void gut_run_lower_v ## vs ## _p ## ps \
+ (void) \
+{ \
+ tint8_t ret = gut_lower_v ## vs ## _p ## ps (&gut_data ## ps); \
+ if (ret == expect) { \
+ printk("GUT_TEST: lower v" #vs "_" #ps ": PASS\n"); \
+ } else { \
+ printk("GUT_TEST: lower v" #vs "_" #ps \
+ ": FAILED: expected 0x%x got 0x%x\n", \
+ expect, ret); \
+ } \
+}
+
+
+GUT_RUN_LOWER_TEST(64, 8, 0x12)
+GUT_RUN_LOWER_TEST(64, 16, 0x34)
+GUT_RUN_LOWER_TEST(64, 32, 0x78)
+GUT_RUN_LOWER_TEST(64, 64, 0xef)
+
+GUT_RUN_LOWER_TEST(32, 8, 0x12)
+GUT_RUN_LOWER_TEST(32, 16, 0x34)
+GUT_RUN_LOWER_TEST(32, 32, 0x78)
+GUT_RUN_LOWER_TEST(32, 64, 0xef)
+
+GUT_RUN_LOWER_TEST(16, 8, 0x12)
+GUT_RUN_LOWER_TEST(16, 16, 0x34)
+GUT_RUN_LOWER_TEST(16, 32, 0x78)
+GUT_RUN_LOWER_TEST(16, 64, 0xef)
+
+GUT_RUN_LOWER_TEST(8, 8, 0x12)
+GUT_RUN_LOWER_TEST(8, 16, 0x34)
+GUT_RUN_LOWER_TEST(8, 32, 0x78)
+GUT_RUN_LOWER_TEST(8, 64, 0xef)
+
+#define GUT_RUN_UPPER_TEST(vs, ps, expect) \
+ void gut_run_upper_v ## vs ## _p ## ps \
+ (void) \
+{ \
+ tint8_t ret = gut_upper_v ## vs ## _p ## ps (&gut_data ## ps); \
+ if (ret == expect) { \
+ printk("GUT_TEST: upper v" #vs "_" #ps ": PASS\n"); \
+ } else { \
+ printk("GUT_TEST: upper v" #vs "_" #ps \
+ ": FAILED: expected 0x%x got 0x%x\n", \
+ expect, ret); \
+ } \
+}
+
+GUT_RUN_UPPER_TEST(64, 8, 0x12)
+GUT_RUN_UPPER_TEST(64, 16, 0x12)
+GUT_RUN_UPPER_TEST(64, 32, 0x12)
+GUT_RUN_UPPER_TEST(64, 64, 0x12)
+
+GUT_RUN_UPPER_TEST(32, 8, 0x12)
+GUT_RUN_UPPER_TEST(32, 16, 0x12)
+GUT_RUN_UPPER_TEST(32, 32, 0x12)
+GUT_RUN_UPPER_TEST(32, 64, 0x90)
+
+GUT_RUN_UPPER_TEST(16, 8, 0x12)
+GUT_RUN_UPPER_TEST(16, 16, 0x12)
+GUT_RUN_UPPER_TEST(16, 32, 0x56)
+GUT_RUN_UPPER_TEST(16, 64, 0xcd)
+
+GUT_RUN_UPPER_TEST(8, 8, 0x12)
+GUT_RUN_UPPER_TEST(8, 16, 0x34)
+GUT_RUN_UPPER_TEST(8, 32, 0x78)
+GUT_RUN_UPPER_TEST(8, 64, 0xef)
+
+
+#define GUT_RUN_LOWER_TEST_CALL(vs, ps) gut_run_lower_v ## vs ## _p ## ps ()
+#define GUT_RUN_UPPER_TEST_CALL(vs, ps) gut_run_upper_v ## vs ## _p ## ps ()
+
+static int
+run_all_tests (void)
+{
+ printk("GUT_TEST: start\n");
+
+ GUT_RUN_LOWER_TEST_CALL(64, 8);
+ GUT_RUN_LOWER_TEST_CALL(64, 16);
+ GUT_RUN_LOWER_TEST_CALL(64, 32);
+ GUT_RUN_LOWER_TEST_CALL(64, 64);
+
+ GUT_RUN_LOWER_TEST_CALL(32, 8);
+ GUT_RUN_LOWER_TEST_CALL(32, 16);
+ GUT_RUN_LOWER_TEST_CALL(32, 32);
+ GUT_RUN_LOWER_TEST_CALL(32, 64);
+
+ GUT_RUN_LOWER_TEST_CALL(16, 8);
+ GUT_RUN_LOWER_TEST_CALL(16, 16);
+ GUT_RUN_LOWER_TEST_CALL(16, 32);
+ GUT_RUN_LOWER_TEST_CALL(16, 64);
+
+ GUT_RUN_LOWER_TEST_CALL(8, 8);
+ GUT_RUN_LOWER_TEST_CALL(8, 16);
+ GUT_RUN_LOWER_TEST_CALL(8, 32);
+ GUT_RUN_LOWER_TEST_CALL(8, 64);
+
+
+ GUT_RUN_UPPER_TEST_CALL(64, 8);
+ GUT_RUN_UPPER_TEST_CALL(64, 16);
+ GUT_RUN_UPPER_TEST_CALL(64, 32);
+ GUT_RUN_UPPER_TEST_CALL(64, 64);
+
+ GUT_RUN_UPPER_TEST_CALL(32, 8);
+ GUT_RUN_UPPER_TEST_CALL(32, 16);
+ GUT_RUN_UPPER_TEST_CALL(32, 32);
+ GUT_RUN_UPPER_TEST_CALL(32, 64);
+
+ GUT_RUN_UPPER_TEST_CALL(16, 8);
+ GUT_RUN_UPPER_TEST_CALL(16, 16);
+ GUT_RUN_UPPER_TEST_CALL(16, 32);
+ GUT_RUN_UPPER_TEST_CALL(16, 64);
+
+ GUT_RUN_UPPER_TEST_CALL(8, 8);
+ GUT_RUN_UPPER_TEST_CALL(8, 16);
+ GUT_RUN_UPPER_TEST_CALL(8, 32);
+ GUT_RUN_UPPER_TEST_CALL(8, 64);
+
+ printk("GUT_TEST: finished\n");
+ return 0;
+}
+
+/*
+ * Module setup
+ */
+
+#ifdef MODULE
+
+static void
+test_exit(void)
+{
+}
+
+module_init(run_all_tests)
+module_exit(test_exit)
+MODULE_LICENSE("GPL");
+
+#else /* !MODULE */
+
+late_initcall(run_all_tests);
+
+#endif