|
From: Kenn H. <ke...@us...> - 2005-02-27 21:31:32
|
Update of /cvsroot/linux-vax/kernel-2.5/init In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv477/init Modified Files: Kconfig Makefile Added Files: apitest.c Log Message: This is the beginning of a test suite for the functions exported by the arch-dependent code to the arch-independent code. I plan to submit this to LKML once we've fleshed it out a bit more. Index: Makefile =================================================================== RCS file: /cvsroot/linux-vax/kernel-2.5/init/Makefile,v retrieving revision 1.1.1.18 retrieving revision 1.2 diff -u -d -r1.1.1.18 -r1.2 --- Makefile 24 Mar 2004 22:45:49 -0000 1.1.1.18 +++ Makefile 27 Feb 2005 21:31:22 -0000 1.2 @@ -9,6 +9,8 @@ mounts-$(CONFIG_BLK_DEV_INITRD) += do_mounts_initrd.o mounts-$(CONFIG_BLK_DEV_MD) += do_mounts_md.o +obj-$(CONFIG_ARCH_API_TEST) += apitest.o + # files to be removed upon make clean clean-files := ../include/linux/compile.h --- NEW FILE: apitest.c --- #include <linux/module.h> #include <linux/bitops.h> #include <asm/atomic.h> #include <asm/byteorder.h> #define TEST(expr) do { \ if (!(expr)) { \ test_failed = 1; \ printk("apitest: FAIL line %d: %s\n", __LINE__, #expr); \ } else if (verbose) { \ printk("apitest: PASS line %d: %s\n", __LINE__, #expr); \ } \ } while (0) static int test_failed; /* Fixme: make this a module parameter */ static int verbose = 0; static void test_div64(void) { uint64_t n; n = 20; TEST(do_div(n,6) == 2); TEST(n == 3); n = 20; TEST(do_div(n,4) == 0); TEST(n == 5); n = 1234567890123ULL; TEST(do_div(n,1000) == 123); TEST(n == 1234567890); } static void test_swab(void) { TEST(swab16(0x1234) == 0x3412); TEST(swab32(0x12345678) == 0x78563412); } static void test_atomic_t(void) { atomic_t a = ATOMIC_INIT(5); TEST(atomic_read(&a) == 5); atomic_set(&a, 10); TEST(atomic_read(&a) == 10); atomic_add(3, &a); TEST(atomic_read(&a) == 13); atomic_sub(5, &a); TEST(atomic_read(&a) == 8); TEST(!atomic_sub_and_test(5, &a)); TEST(atomic_sub_and_test(3, &a)); atomic_set(&a, 2); atomic_inc(&a); TEST(atomic_read(&a) == 3); atomic_dec(&a); TEST(atomic_read(&a) == 2); TEST(!atomic_dec_and_test(&a)); TEST(atomic_dec_and_test(&a)); TEST(!atomic_dec_and_test(&a)); TEST(!atomic_dec_and_test(&a)); /* a is now -2 */ TEST(!atomic_inc_and_test(&a)); TEST(atomic_inc_and_test(&a)); TEST(!atomic_inc_and_test(&a)); atomic_set(&a, -5); TEST(atomic_add_negative(4, &a)); atomic_set(&a, -5); TEST(!atomic_add_negative(5, &a)); atomic_set(&a, -5); TEST(!atomic_add_negative(6, &a)); atomic_set(&a, 0); atomic_clear_mask(0x123456, &a); TEST(atomic_read(&a) == 0); atomic_set(&a, 0x123456); atomic_clear_mask(0x123456, &a); TEST(atomic_read(&a) == 0); atomic_set(&a, 0xffffff); atomic_clear_mask(0x123456, &a); TEST(atomic_read(&a) == 0xedcba9); atomic_set(&a, 0); atomic_set_mask(0x123456, &a); TEST(atomic_read(&a) == 0x123456); atomic_set(&a, 0x123456); atomic_set_mask(0x123456, &a); TEST(atomic_read(&a) == 0x123456); atomic_set(&a, 0xffffff); atomic_set_mask(0x123456, &a); TEST(atomic_read(&a) == 0xffffff); } static void test_find_next_bit(void) { long mask[] = { 0, 0, 0, 0 }; int size = sizeof(mask) * 8; TEST(find_next_bit(mask, size, 0) == size); TEST(find_next_bit(mask, size, 1) == size); TEST(find_next_bit(mask, size, 2) == size); TEST(find_next_bit(mask, size, 7) == size); TEST(find_next_bit(mask, size, 8) == size); mask[0] = 0x7e; TEST(find_next_bit(mask, size, 0) == 1); TEST(find_next_bit(mask, size, 1) == 1); TEST(find_next_bit(mask, size, 2) == 2); TEST(find_next_bit(mask, size, 6) == 6); TEST(find_next_bit(mask, size, 7) == size); TEST(find_next_bit(mask, size, 8) == size); mask[0] = 0xff; TEST(find_next_bit(mask, size, 0) == 0); TEST(find_next_bit(mask, size, 1) == 1); TEST(find_next_bit(mask, size, 2) == 2); TEST(find_next_bit(mask, size, 7) == 7); TEST(find_next_bit(mask, size, 8) == size); mask[0] = 0xfe00; TEST(find_next_bit(mask, size, 0) == 9); TEST(find_next_bit(mask, size, 7) == 9); TEST(find_next_bit(mask, size, 8) == 9); TEST(find_next_bit(mask, size, 9) == 9); TEST(find_next_bit(mask, size, 10) == 10); TEST(find_next_bit(mask, size, 11) == 11); TEST(find_next_bit(mask, size, 15) == 15); TEST(find_next_bit(mask, size, 16) == size); mask[0] = 0; mask[1] = 0xfe; TEST(find_next_bit(mask, size, 0) == 33); TEST(find_next_bit(mask, size, 1) == 33); TEST(find_next_bit(mask, size, 31) == 33); TEST(find_next_bit(mask, size, 32) == 33); TEST(find_next_bit(mask, size, 33) == 33); TEST(find_next_bit(mask, size, 34) == 34); TEST(find_next_bit(mask, size, 39) == 39); TEST(find_next_bit(mask, size, 40) == size); TEST(find_next_bit(mask, size, size-1) == size); } static void test_ffs(void) { /* ffs() counts LSB as bit 1 */ TEST(ffs(0) == 0); TEST(ffs(1) == 1); TEST(ffs(2) == 2); TEST(ffs(3) == 1); TEST(ffs(0x80000000) == 32); /* __ffs() counts LSB as bit 0 */ /* __ffs(0) is undefined */ TEST(__ffs(1) == 0); TEST(__ffs(2) == 1); TEST(__ffs(3) == 0); TEST(__ffs(0x80000000) == 31); } void do_tests(void) { test_div64(); test_swab(); test_atomic_t(); test_find_next_bit(); test_ffs(); } static int __init apitest_init(void) { do_tests(); if (test_failed) { printk("apitest: at least one test failed\n"); } else { printk("apitest: all tests passed\n"); } return 0; } static void __exit apitest_exit(void) { } core_initcall(apitest_init); module_exit(apitest_exit); MODULE_LICENSE("GPL"); Index: Kconfig =================================================================== RCS file: /cvsroot/linux-vax/kernel-2.5/init/Kconfig,v retrieving revision 1.1.1.22 retrieving revision 1.2 diff -u -d -r1.1.1.22 -r1.2 --- Kconfig 16 Nov 2004 22:20:13 -0000 1.1.1.22 +++ Kconfig 27 Feb 2005 21:31:21 -0000 1.2 @@ -50,6 +50,17 @@ depends on BROKEN || !SMP default y +config ARCH_API_TEST + tristate "Compile tests for core<->arch API" + default n + help + Select this option if you want to compile a test suite + for the API exposed by the arch-dependent code to the + arch-independent portions of the kernel. If compiled + into the kernel, this test suite will be run early in + the boot sequence. If compiled as a module, the test + suite will be run when the module is loaded. + endmenu menu "General setup" |