/trunk/kernel/test/test.c |
---|
56,11 → 56,14 |
#include <synch/semaphore1.def> |
#include <synch/semaphore2.def> |
#include <print/print1.def> |
#include <print/print2.def> |
#include <print/print3.def> |
#include <print/print4.def> |
#include <thread/thread1.def> |
#include <sysinfo/sysinfo1.def> |
{ |
.name = NULL, |
.desc = NULL, |
.desc = NULL, |
.entry = NULL |
} |
}; |
/trunk/kernel/test/test.h |
---|
47,30 → 47,33 |
bool safe; |
} test_t; |
extern char * test_atomic1(bool quiet); |
extern char * test_avltree1(bool quiet); |
extern char * test_btree1(bool quiet); |
extern char * test_mips1(bool quiet); |
extern char * test_fault1(bool quiet); |
extern char * test_fpu1(bool quiet); |
extern char * test_sse1(bool quiet); |
extern char * test_mips2(bool quiet); |
extern char * test_falloc1(bool quiet); |
extern char * test_falloc2(bool quiet); |
extern char * test_mapping1(bool quiet); |
extern char * test_purge1(bool quiet); |
extern char * test_slab1(bool quiet); |
extern char * test_slab2(bool quiet); |
extern char * test_rwlock1(bool quiet); |
extern char * test_rwlock2(bool quiet); |
extern char * test_rwlock3(bool quiet); |
extern char * test_rwlock4(bool quiet); |
extern char * test_rwlock5(bool quiet); |
extern char * test_semaphore1(bool quiet); |
extern char * test_semaphore2(bool quiet); |
extern char * test_print1(bool quiet); |
extern char * test_thread1(bool quiet); |
extern char * test_sysinfo1(bool quiet); |
extern char *test_atomic1(bool quiet); |
extern char *test_avltree1(bool quiet); |
extern char *test_btree1(bool quiet); |
extern char *test_mips1(bool quiet); |
extern char *test_fault1(bool quiet); |
extern char *test_fpu1(bool quiet); |
extern char *test_sse1(bool quiet); |
extern char *test_mips2(bool quiet); |
extern char *test_falloc1(bool quiet); |
extern char *test_falloc2(bool quiet); |
extern char *test_mapping1(bool quiet); |
extern char *test_purge1(bool quiet); |
extern char *test_slab1(bool quiet); |
extern char *test_slab2(bool quiet); |
extern char *test_rwlock1(bool quiet); |
extern char *test_rwlock2(bool quiet); |
extern char *test_rwlock3(bool quiet); |
extern char *test_rwlock4(bool quiet); |
extern char *test_rwlock5(bool quiet); |
extern char *test_semaphore1(bool quiet); |
extern char *test_semaphore2(bool quiet); |
extern char *test_print1(bool quiet); |
extern char *test_print2(bool quiet); |
extern char *test_print3(bool quiet); |
extern char *test_print4(bool quiet); |
extern char *test_thread1(bool quiet); |
extern char *test_sysinfo1(bool quiet); |
extern test_t tests[]; |
/trunk/kernel/test/print/print2.c |
---|
0,0 → 1,59 |
/* |
* Copyright (c) 2005 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <print.h> |
#include <test.h> |
char *test_print2(bool quiet) |
{ |
if (!quiet) { |
printf("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n"); |
printf("Expected output: [a] [ b] [c ] [ d] [e ]\n"); |
printf("Real output: [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e'); |
printf("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n"); |
printf("Expected output: [1] [ 02] [03 ] [004] [005]\n"); |
printf("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", 1, 2, 3, 4, 5); |
printf("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", -1, -2, -3, -4, -5):\n"); |
printf("Expected output: [-1] [-02] [-03] [-004] [-005]\n"); |
printf("Real output: [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5); |
printf("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n"); |
printf("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n"); |
printf("Real output: [%#x] [%#5.3x] [%#-5.3x] [%#3.5x] [%#-3.5x]\n\n", 17, 18, 19, 20, 21); |
unative_t nat = 0x12345678u; |
printf("Testing printf(\"%%#" PRIx64 " %%#" PRIx32 " %%#" PRIx16 " %%#" PRIx8 " %%#" PRIxn " %%#" PRIx64 " %%s\", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, \"Lovely string\"):\n"); |
printf("Expected output: [0x1234567887654321] [0x12345678] [0x1234] [0x12] [0x12345678] [0x1234567887654321] \"Lovely string\"\n"); |
printf("Real output: [%#" PRIx64 "] [%#" PRIx32 "] [%#" PRIx16 "] [%#" PRIx8 "] [%#" PRIxn "] [%#" PRIx64 "] \"%s\"\n\n", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, "Lovely string"); |
} |
return NULL; |
} |
/trunk/kernel/test/print/print3.c |
---|
0,0 → 1,63 |
/* |
* Copyright (c) 2005 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <print.h> |
#include <macros.h> |
#include <test.h> |
#define BUFFER_SIZE 32 |
char *test_print3(bool quiet) |
{ |
if (!quiet) { |
char buffer[BUFFER_SIZE]; |
int retval; |
printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short text without parameters.\"):\n"); |
printf("Expected result: retval=30 buffer=\"Short text without parameters.\"\n"); |
retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); |
printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); |
printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very very very long text without parameters.\"):\n"); |
printf("Expected result: retval=44 buffer=\"Very very very long text withou\"\n"); |
retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); |
printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); |
printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short %%s.\", \"text\"):\n"); |
printf("Expected result: retval=11 buffer=\"Short text.\"\n"); |
retval = snprintf(buffer, BUFFER_SIZE, "Short %s.", "text"); |
printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); |
printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very long %%s. This text's length is more than %%d. We are interested in the result.\", \"text\", " STRING(BUFFER_SIZE) "):\n"); |
printf("Expected result: retval=84 buffer=\"Very long text. This text's len\"\n"); |
retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text's length is more than %d. We are interested in the result.", "text", BUFFER_SIZE); |
printf("Real result: retval=%d buffer=\"%s\"\n\n", retval, buffer); |
} |
return NULL; |
} |
/trunk/kernel/test/print/print4.c |
---|
0,0 → 1,63 |
/* |
* Copyright (c) 2009 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - 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. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <print.h> |
#include <test.h> |
char *test_print4(bool quiet) |
{ |
if (!quiet) { |
printf("ASCII printable characters (32 - 127) using printf(%%c):\n"); |
uint8_t hextet; |
for (hextet = 2; hextet < 8; hextet++) { |
printf("%#" PRIx8 ": ", hextet << 4); |
uint8_t index; |
for (index = 0; index < 16; index++) |
printf("%c", (char) ((hextet << 4) + index)); |
printf("\n"); |
} |
printf("\nExtended ASCII characters (128 - 255) using printf(%%c):\n"); |
for (hextet = 8; hextet < 16; hextet++) { |
printf("%#" PRIx8 ": ", hextet << 4); |
uint8_t index; |
for (index = 0; index < 16; index++) |
printf("%c", (char) ((hextet << 4) + index)); |
printf("\n"); |
} |
} |
return NULL; |
} |
/trunk/kernel/test/print/print1.def |
---|
1,6 → 1,6 |
{ |
"print1", |
"Printf test", |
"String printf test", |
&test_print1, |
true |
}, |
/trunk/kernel/test/print/print2.def |
---|
0,0 → 1,6 |
{ |
"print2", |
"Numeric printf test", |
&test_print2, |
true |
}, |
/trunk/kernel/test/print/print3.def |
---|
0,0 → 1,6 |
{ |
"print3", |
"Buffered printf test", |
&test_print3, |
true |
}, |
/trunk/kernel/test/print/print4.def |
---|
0,0 → 1,6 |
{ |
"print4", |
"Unicode test", |
&test_print4, |
true |
}, |
/trunk/kernel/test/print/print1.c |
---|
29,43 → 29,28 |
#include <print.h> |
#include <test.h> |
#define BUFFER_SIZE 32 |
char * test_print1(bool quiet) |
char *test_print1(bool quiet) |
{ |
if (!quiet) { |
int retval; |
unative_t nat = 0x12345678u; |
printf("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n"); |
printf("Expected output: \" tex\"\n"); |
printf("Real output: \"%*.*s\"\n\n", 5, 3, "text"); |
char buffer[BUFFER_SIZE]; |
printf("Testing printf(\"%%10.8s\", \"very long text\"):\n"); |
printf("Expected output: \" very lon\"\n"); |
printf("Real output: \"%10.8s\"\n\n", "very long text"); |
printf(" text 10.8s %*.*s \n", 5, 3, "text"); |
printf(" very long text 10.8s %10.8s \n", "very long text"); |
printf(" text 8.10s %8.10s \n", "text"); |
printf(" very long text 8.10s %8.10s \n", "very long text"); |
printf("Testing printf(\"%%8.10s\", \"text\"):\n"); |
printf("Expected output: \"text\"\n"); |
printf("Real output: \"%8.10s\"\n\n", "text"); |
printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n", 'a', 'b', 'c', 'd', 'e'); |
printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n", 1, 1, 1, 1, 1); |
printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n", -1, -1, -1, -1, -1); |
printf(" 0xint: x '%#x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n", 17, 17, 17, 17, 17); |
printf("Testing printf(\"%%8.10s\", \"very long text\"):\n"); |
printf("Expected output: \"very long \"\n"); |
printf("Real output: \"%8.10s\"\n\n", "very long text"); |
printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#" PRIxn "'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" ); |
printf(" Print to NULL '%s'\n", NULL); |
retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text"); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
printf("Testing printf(\"%%s\", NULL):\n"); |
printf("Expected output: \"(NULL)\"\n"); |
printf("Real output: \"%s\"\n\n", NULL); |
} |
return NULL; |
/trunk/kernel/Makefile |
---|
261,6 → 261,9 |
test/synch/semaphore1.c \ |
test/synch/semaphore2.c \ |
test/print/print1.c \ |
test/print/print2.c \ |
test/print/print3.c \ |
test/print/print4.c \ |
test/thread/thread1.c \ |
test/sysinfo/sysinfo1.c |