Changeset cb01e1e in mainline for kernel/test/print


Ignore:
Timestamp:
2009-04-04T00:26:27Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a85aebd
Parents:
171f9a1
Message:

use global variable and a macro for silencing tests

Location:
kernel/test/print
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/print/print1.c

    r171f9a1 rcb01e1e  
    3030#include <test.h>
    3131
    32 char *test_print1(bool quiet)
     32char *test_print1(void)
    3333{
    34         if (!quiet) {
    35                 printf("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n");
    36                 printf("Expected output: \"  tex\"\n");
    37                 printf("Real output:     \"%*.*s\"\n\n", 5, 3, "text");
    38                
    39                 printf("Testing printf(\"%%10.8s\", \"very long text\"):\n");
    40                 printf("Expected output: \"  very lon\"\n");
    41                 printf("Real output:     \"%10.8s\"\n\n", "very long text");
    42                
    43                 printf("Testing printf(\"%%8.10s\", \"text\"):\n");
    44                 printf("Expected output: \"text\"\n");
    45                 printf("Real output:     \"%8.10s\"\n\n", "text");
    46                
    47                 printf("Testing printf(\"%%8.10s\", \"very long text\"):\n");
    48                 printf("Expected output: \"very long \"\n");
    49                 printf("Real output:     \"%8.10s\"\n\n", "very long text");
    50                
    51                 printf("Testing printf(\"%%s\", NULL):\n");
    52                 printf("Expected output: \"(NULL)\"\n");
    53                 printf("Real output:     \"%s\"\n\n", NULL);
    54         }
     34        TPRINTF("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n");
     35        TPRINTF("Expected output: \"  tex\"\n");
     36        TPRINTF("Real output:     \"%*.*s\"\n\n", 5, 3, "text");
     37       
     38        TPRINTF("Testing printf(\"%%10.8s\", \"very long text\"):\n");
     39        TPRINTF("Expected output: \"  very lon\"\n");
     40        TPRINTF("Real output:     \"%10.8s\"\n\n", "very long text");
     41       
     42        TPRINTF("Testing printf(\"%%8.10s\", \"text\"):\n");
     43        TPRINTF("Expected output: \"text\"\n");
     44        TPRINTF("Real output:     \"%8.10s\"\n\n", "text");
     45       
     46        TPRINTF("Testing printf(\"%%8.10s\", \"very long text\"):\n");
     47        TPRINTF("Expected output: \"very long \"\n");
     48        TPRINTF("Real output:     \"%8.10s\"\n\n", "very long text");
     49       
     50        TPRINTF("Testing printf(\"%%s\", NULL):\n");
     51        TPRINTF("Expected output: \"(NULL)\"\n");
     52        TPRINTF("Real output:     \"%s\"\n\n", NULL);
    5553       
    5654        return NULL;
  • kernel/test/print/print2.c

    r171f9a1 rcb01e1e  
    3030#include <test.h>
    3131
    32 char *test_print2(bool quiet)
     32char *test_print2(void)
    3333{
    34         if (!quiet) {
    35                 printf("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n");
    36                 printf("Expected output: [a] [  b] [c  ] [ d] [e ]\n");
    37                 printf("Real output:     [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e');
    38                
    39                 printf("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n");
    40                 printf("Expected output: [1] [ 02] [03 ] [004] [005]\n");
    41                 printf("Real output:     [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", 1, 2, 3, 4, 5);
    42                
    43                 printf("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", -1, -2, -3, -4, -5):\n");
    44                 printf("Expected output: [-1] [-02] [-03] [-004] [-005]\n");
    45                 printf("Real output:     [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5);
    46                
    47                 printf("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n");
    48                 printf("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n");
    49                 printf("Real output:     [%#x] [%#5.3x] [%#-5.3x] [%#3.5x] [%#-3.5x]\n\n", 17, 18, 19, 20, 21);
    50                
    51                 unative_t nat = 0x12345678u;
    52                
    53                 printf("Testing printf(\"%%#" PRIx64 " %%#" PRIx32 " %%#" PRIx16 " %%#" PRIx8 " %%#" PRIxn " %%#" PRIx64 " %%s\", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, \"Lovely string\"):\n");
    54                 printf("Expected output: [0x1234567887654321] [0x12345678] [0x1234] [0x12] [0x12345678] [0x1234567887654321] \"Lovely string\"\n");
    55                 printf("Real output:     [%#" PRIx64 "] [%#" PRIx32 "] [%#" PRIx16 "] [%#" PRIx8 "] [%#" PRIxn "] [%#" PRIx64 "] \"%s\"\n\n", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, "Lovely string");
    56         }
     34        TPRINTF("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n");
     35        TPRINTF("Expected output: [a] [  b] [c  ] [ d] [e ]\n");
     36        TPRINTF("Real output:     [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e');
     37       
     38        TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n");
     39        TPRINTF("Expected output: [1] [ 02] [03 ] [004] [005]\n");
     40        TPRINTF("Real output:     [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", 1, 2, 3, 4, 5);
     41       
     42        TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", -1, -2, -3, -4, -5):\n");
     43        TPRINTF("Expected output: [-1] [-02] [-03] [-004] [-005]\n");
     44        TPRINTF("Real output:     [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5);
     45       
     46        TPRINTF("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n");
     47        TPRINTF("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n");
     48        TPRINTF("Real output:     [%#x] [%#5.3x] [%#-5.3x] [%#3.5x] [%#-3.5x]\n\n", 17, 18, 19, 20, 21);
     49       
     50        unative_t nat = 0x12345678u;
     51       
     52        TPRINTF("Testing printf(\"%%#" PRIx64 " %%#" PRIx32 " %%#" PRIx16 " %%#" PRIx8 " %%#" PRIxn " %%#" PRIx64 " %%s\", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, \"Lovely string\"):\n");
     53        TPRINTF("Expected output: [0x1234567887654321] [0x12345678] [0x1234] [0x12] [0x12345678] [0x1234567887654321] \"Lovely string\"\n");
     54        TPRINTF("Real output:     [%#" PRIx64 "] [%#" PRIx32 "] [%#" PRIx16 "] [%#" PRIx8 "] [%#" PRIxn "] [%#" PRIx64 "] \"%s\"\n\n", 0x1234567887654321ll, 0x12345678, 0x1234, 0x12, nat, 0x1234567887654321ull, "Lovely string");
    5755       
    5856        return NULL;
  • kernel/test/print/print3.c

    r171f9a1 rcb01e1e  
    3333#define BUFFER_SIZE  32
    3434
    35 char *test_print3(bool quiet)
     35char *test_print3(void)
    3636{
    37         if (!quiet) {
    38                 char buffer[BUFFER_SIZE];
    39                 int retval;
    40                
    41                 printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short text without parameters.\"):\n");
    42                 printf("Expected result: retval=30 buffer=\"Short text without parameters.\"\n");
    43                 retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
    44                 printf("Real result:     retval=%d buffer=\"%s\"\n\n", retval, buffer);
    45                
    46                 printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very very very long text without parameters.\"):\n");
    47                 printf("Expected result: retval=44 buffer=\"Very very very long text withou\"\n");
    48                 retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters.");
    49                 printf("Real result:     retval=%d buffer=\"%s\"\n\n", retval, buffer);
    50                
    51                 printf("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short %%s.\", \"text\"):\n");
    52                 printf("Expected result: retval=11 buffer=\"Short text.\"\n");
    53                 retval = snprintf(buffer, BUFFER_SIZE, "Short %s.", "text");
    54                 printf("Real result:     retval=%d buffer=\"%s\"\n\n", retval, buffer);
    55                
    56                 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");
    57                 printf("Expected result: retval=84 buffer=\"Very long text. This text's len\"\n");
    58                 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);
    59                 printf("Real result:     retval=%d buffer=\"%s\"\n\n", retval, buffer);
    60         }
     37        char buffer[BUFFER_SIZE];
     38        int retval;
     39       
     40        TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short text without parameters.\"):\n");
     41        TPRINTF("Expected result: retval=30 buffer=\"Short text without parameters.\"\n");
     42        retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
     43        TPRINTF("Real result:     retval=%d buffer=\"%s\"\n\n", retval, buffer);
     44       
     45        TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Very very very long text without parameters.\"):\n");
     46        TPRINTF("Expected result: retval=44 buffer=\"Very very very long text withou\"\n");
     47        retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters.");
     48        TPRINTF("Real result:     retval=%d buffer=\"%s\"\n\n", retval, buffer);
     49       
     50        TPRINTF("Testing snprintf(buffer, " STRING(BUFFER_SIZE) ", \"Short %%s.\", \"text\"):\n");
     51        TPRINTF("Expected result: retval=11 buffer=\"Short text.\"\n");
     52        retval = snprintf(buffer, BUFFER_SIZE, "Short %s.", "text");
     53        TPRINTF("Real result:     retval=%d buffer=\"%s\"\n\n", retval, buffer);
     54       
     55        TPRINTF("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");
     56        TPRINTF("Expected result: retval=84 buffer=\"Very long text. This text's len\"\n");
     57        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);
     58        TPRINTF("Real result:     retval=%d buffer=\"%s\"\n\n", retval, buffer);
    6159       
    6260        return NULL;
  • kernel/test/print/print4.c

    r171f9a1 rcb01e1e  
    3030#include <test.h>
    3131
    32 char *test_print4(bool quiet)
     32char *test_print4(void)
    3333{
    34         if (!quiet) {
    35                 printf("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n");
     34        TPRINTF("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n");
     35       
     36        uint8_t group;
     37        for (group = 1; group < 4; group++) {
     38                TPRINTF("%#" PRIx8 ": ", group << 5);
    3639               
    37                 uint8_t group;
    38                 for (group = 1; group < 4; group++) {
    39                         printf("%#" PRIx8 ": ", group << 5);
    40                        
    41                         uint8_t index;
    42                         for (index = 0; index < 32; index++)
    43                                 printf("%c", (char) ((group << 5) + index));
    44                        
    45                         printf("  ");
    46                         for (index = 0; index < 32; index++)
    47                                 printf("%lc", (wchar_t) ((group << 5) + index));
    48                        
    49                         printf("\n");
    50                 }
     40                uint8_t index;
     41                for (index = 0; index < 32; index++)
     42                        TPRINTF("%c", (char) ((group << 5) + index));
    5143               
    52                 printf("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n");
     44                TPRINTF("  ");
     45                for (index = 0; index < 32; index++)
     46                        TPRINTF("%lc", (wchar_t) ((group << 5) + index));
    5347               
    54                 for (group = 4; group < 8; group++) {
    55                         printf("%#" PRIx8 ": ", group << 5);
    56                        
    57                         uint8_t index;
    58                         for (index = 0; index < 32; index++)
    59                                 printf("%lc", (wchar_t) ((group << 5) + index));
    60                        
    61                         printf("\n");
    62                 }
     48                TPRINTF("\n");
     49        }
     50       
     51        TPRINTF("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n");
     52       
     53        for (group = 4; group < 8; group++) {
     54                TPRINTF("%#" PRIx8 ": ", group << 5);
    6355               
    64                 printf("\nUTF-8 strings using printf(\"%%s\"):\n");
    65                 printf("English:  %s\n", "Quick brown fox jumps over the lazy dog");
    66                 printf("Czech:    %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy");
    67                 printf("Greek:    %s\n", "Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε");
    68                 printf("Hebrew:   %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה");
    69                 printf("Arabic:   %s\n", "التوزيع الجغرافي للحمل العنقودي");
    70                 printf("Russian:  %s\n", "Леннон познакомился с художницей-авангардисткой");
    71                 printf("Armenian: %s\n", "Սկսեց հրատարակվել Երուսաղեմի հայկական");
     56                uint8_t index;
     57                for (index = 0; index < 32; index++)
     58                        TPRINTF("%lc", (wchar_t) ((group << 5) + index));
    7259               
    73                 printf("\nUTF-32 strings using printf(\"%%ls\"):\n");
    74                 printf("English:  %ls\n", L"Quick brown fox jumps over the lazy dog");
    75                 printf("Czech:    %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy");
    76                 printf("Greek:    %ls\n", L"Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε");
    77                 printf("Hebrew:   %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה");
    78                 printf("Arabic:   %ls\n", L"التوزيع الجغرافي للحمل العنقودي");
    79                 printf("Russian:  %ls\n", L"Леннон познакомился с художницей-авангардисткой");
    80                 printf("Armenian: %ls\n", L"Սկսեց հրատարակվել Երուսաղեմի հայկական");
     60                TPRINTF("\n");
    8161        }
     62       
     63        TPRINTF("\nUTF-8 strings using printf(\"%%s\"):\n");
     64        TPRINTF("English:  %s\n", "Quick brown fox jumps over the lazy dog");
     65        TPRINTF("Czech:    %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy");
     66        TPRINTF("Greek:    %s\n", "Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε");
     67        TPRINTF("Hebrew:   %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה");
     68        TPRINTF("Arabic:   %s\n", "التوزيع الجغرافي للحمل العنقودي");
     69        TPRINTF("Russian:  %s\n", "Леннон познакомился с художницей-авангардисткой");
     70        TPRINTF("Armenian: %s\n", "Սկսեց հրատարակվել Երուսաղեմի հայկական");
     71       
     72        TPRINTF("\nUTF-32 strings using printf(\"%%ls\"):\n");
     73        TPRINTF("English:  %ls\n", L"Quick brown fox jumps over the lazy dog");
     74        TPRINTF("Czech:    %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy");
     75        TPRINTF("Greek:    %ls\n", L"Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε");
     76        TPRINTF("Hebrew:   %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה");
     77        TPRINTF("Arabic:   %ls\n", L"التوزيع الجغرافي للحمل العنقودي");
     78        TPRINTF("Russian:  %ls\n", L"Леннон познакомился с художницей-авангардисткой");
     79        TPRINTF("Armenian: %ls\n", L"Սկսեց հրատարակվել Երուսաղեմի հայկական");
    8280       
    8381        return NULL;
Note: See TracChangeset for help on using the changeset viewer.