Changeset 2d11a7d8 in mainline


Ignore:
Timestamp:
2009-06-30T15:54:14Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9c40f88
Parents:
db24058
Message:

tester framework rewrite (go from a menu-driven interface to command-line interface)

Location:
uspace/app/tester
Files:
3 added
9 deleted
17 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/tester/Makefile

    rdb24058 r2d11a7d8  
    4646        thread/thread1.c \
    4747        print/print1.c \
     48        print/print2.c \
     49        print/print3.c \
    4850        print/print4.c \
    49         fault/fault1.c \
    50         fault/fault2.c \
    51         ipc/register.c \
    52         ipc/connect.c \
    53         ipc/send_async.c \
    54         ipc/send_sync.c \
    55         ipc/answer.c \
    56         ipc/hangup.c \
    57         ipc/ping_pong.c \
    58         loop/loop1.c \
    59         devmap/devmap1.c \
    6051        console/console1.c \
    6152        stdio/stdio1.c \
    6253        stdio/stdio2.c \
    63         vfs/vfs1.c
     54        fault/fault1.c \
     55        fault/fault2.c \
     56        vfs/vfs1.c \
     57        ipc/ping_pong.c \
     58        ipc/register.c \
     59        ipc/connect.c \
     60        loop/loop1.c \
     61        mm/malloc1.c
    6462
    6563OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
  • uspace/app/tester/console/console1.c

    rdb24058 r2d11a7d8  
    4747};
    4848
    49 char * test_console1(bool quiet)
     49char *test_console1(void)
    5050{
    51         int i, j;
    52 
    53         printf("Style test: ");
    54         fflush(stdout);
    55         console_set_style(fphone(stdout), STYLE_NORMAL);
    56         printf("normal ");
    57         fflush(stdout);
    58         console_set_style(fphone(stdout), STYLE_EMPHASIS);
    59         printf("emphasized");
    60         fflush(stdout);
    61         console_set_style(fphone(stdout), STYLE_NORMAL);
    62         printf(".\n");
    63 
    64         printf("Foreground color test:\n");
    65         for (j = 0; j < 2; j++) {
    66                 for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) {
     51        if (!test_quiet) {
     52                printf("Style test: ");
     53                fflush(stdout);
     54                console_set_style(fphone(stdout), STYLE_NORMAL);
     55                printf("normal ");
     56                fflush(stdout);
     57                console_set_style(fphone(stdout), STYLE_EMPHASIS);
     58                printf("emphasized");
     59                fflush(stdout);
     60                console_set_style(fphone(stdout), STYLE_NORMAL);
     61                printf(".\n");
     62               
     63                unsigned int i;
     64                unsigned int j;
     65               
     66                printf("\nForeground color test:\n");
     67                for (j = 0; j < 2; j++) {
     68                        for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) {
     69                                fflush(stdout);
     70                                console_set_color(fphone(stdout), i, COLOR_WHITE,
     71                                    j ? CATTR_BRIGHT : 0);
     72                                printf(" %s ", color_name[i]);
     73                        }
    6774                        fflush(stdout);
    68                         console_set_color(fphone(stdout), i, COLOR_WHITE,
    69                             j ? CATTR_BRIGHT : 0);
    70                         printf(" %s ", color_name[i]);
     75                        console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     76                        putchar('\n');
     77                }
     78               
     79                printf("\nBackground color test:\n");
     80                for (j = 0; j < 2; j++) {
     81                        for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) {
     82                                fflush(stdout);
     83                                console_set_color(fphone(stdout), COLOR_WHITE, i,
     84                                    j ? CATTR_BRIGHT : 0);
     85                                printf(" %s ", color_name[i]);
     86                        }
     87                        fflush(stdout);
     88                        console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     89                        putchar('\n');
     90                }
     91               
     92                printf("\nRGB colors test:\n");
     93               
     94                for (i = 0; i < 255; i += 16) {
     95                        fflush(stdout);
     96                        console_set_rgb_color(fphone(stdout), 0xffffff, i << 16);
     97                        putchar('X');
     98                }
     99                fflush(stdout);
     100                console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     101                putchar('\n');
     102               
     103                for (i = 0; i < 255; i += 16) {
     104                        fflush(stdout);
     105                        console_set_rgb_color(fphone(stdout), 0xffffff, i << 8);
     106                        putchar('X');
     107                }
     108                fflush(stdout);
     109                console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     110                putchar('\n');
     111               
     112                for (i = 0; i < 255; i += 16) {
     113                        fflush(stdout);
     114                        console_set_rgb_color(fphone(stdout), 0xffffff, i);
     115                        putchar('X');
    71116                }
    72117                fflush(stdout);
     
    74119                putchar('\n');
    75120        }
    76 
    77         printf("Background color test:\n");
    78         for (j = 0; j < 2; j++) {
    79                 for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) {
    80                         fflush(stdout);
    81                         console_set_color(fphone(stdout), COLOR_WHITE, i,
    82                             j ? CATTR_BRIGHT : 0);
    83                         printf(" %s ", color_name[i]);
    84                 }
    85                 fflush(stdout);
    86                 console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
    87                 putchar('\n');
    88         }
    89 
    90         printf("Now let's test RGB colors:\n");
    91 
    92         for (i = 0; i < 255; i += 16) {
    93                 fflush(stdout);
    94                 console_set_rgb_color(fphone(stdout), 0xffffff, i << 16);
    95                 putchar('X');
    96         }
    97         fflush(stdout);
    98         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
    99         putchar('\n');
    100 
    101         for (i = 0; i < 255; i += 16) {
    102                 fflush(stdout);
    103                 console_set_rgb_color(fphone(stdout), 0xffffff, i << 8);
    104                 putchar('X');
    105         }
    106         fflush(stdout);
    107         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
    108         putchar('\n');
    109 
    110         for (i = 0; i < 255; i += 16) {
    111                 fflush(stdout);
    112                 console_set_rgb_color(fphone(stdout), 0xffffff, i);
    113                 putchar('X');
    114         }
    115         fflush(stdout);
    116         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
    117         putchar('\n');
    118 
    119         printf("[press a key]\n");
    120         getchar();
    121 
     121       
    122122        return NULL;
    123123}
  • uspace/app/tester/fault/fault1.c

    rdb24058 r2d11a7d8  
    3030#include "../tester.h"
    3131
    32 char * test_fault1(bool quiet)
     32char *test_fault1(void)
    3333{
    3434        ((int *)(0))[1] = 0;
  • uspace/app/tester/fault/fault2.c

    rdb24058 r2d11a7d8  
    3030#include "../tester.h"
    3131
    32 char * test_fault2(bool quiet)
     32char *test_fault2(void)
    3333{
    3434        volatile long long var;
  • uspace/app/tester/ipc/connect.c

    rdb24058 r2d11a7d8  
    2929#include <stdio.h>
    3030#include <unistd.h>
     31#include <atomic.h>
    3132#include "../tester.h"
    3233
    33 char * test_connect(bool quiet)
     34static atomic_t finish;
     35
     36static void callback(void *priv, int retval, ipc_call_t *data)
    3437{
    35         char c;
    36         int svc;
    37         int phid;
     38        atomic_set(&finish, 1);
     39}
    3840
    39         printf("Choose one service: 0:10000....9:10009 (q to skip)\n");
    40         do {
    41                 c = getchar();
    42                 if ((c == 'Q') || (c == 'q'))
    43                         return TEST_SKIPPED;
    44         } while (c < '0' || c > '9');
     41char *test_connect(void)
     42{
     43        TPRINTF("Connecting to %u...", IPC_TEST_SERVICE);
     44        int phone = ipc_connect_me_to(PHONE_NS, IPC_TEST_SERVICE, 0, 0);
     45        if (phone > 0) {
     46                TPRINTF("phoneid %d\n", phone);
     47        } else {
     48                TPRINTF("\n");
     49                return "ipc_connect_me_to() failed";
     50        }
    4551       
    46         svc = IPC_TEST_START + c - '0';
    47         if (svc == myservice)
    48                 return "Currently cannot connect to myself, update test";
     52        printf("Sending synchronous message...\n");
     53        int retval = ipc_call_sync_0_0(phone, IPC_TEST_METHOD);
     54        TPRINTF("Received response to synchronous message\n");
    4955       
    50         printf("Connecting to %d..", svc);
    51         phid = ipc_connect_me_to(PHONE_NS, svc, 0, 0);
    52         if (phid > 0) {
    53                 printf("phoneid: %d\n", phid);
    54                 phones[phid] = 1;
    55         } else
    56                 return "Error";
     56        TPRINTF("Sending asynchronous message...\n");
     57        atomic_set(&finish, 0);
     58        ipc_call_async_0(phone, IPC_TEST_METHOD, NULL, callback, 1);
     59        while (atomic_get(&finish) != 1)
     60                TPRINTF(".");
     61        TPRINTF("Received response to asynchronous message\n");
     62       
     63        TPRINTF("Hanging up...");
     64        retval = ipc_hangup(phone);
     65        if (retval == 0) {
     66                TPRINTF("OK\n");
     67        } else {
     68                TPRINTF("\n");
     69                return "ipc_hangup() failed";
     70        }
    5771       
    5872        return NULL;
  • uspace/app/tester/ipc/ping_pong.c

    rdb24058 r2d11a7d8  
    3838#define COUNT_GRANULARITY  100
    3939
    40 char *test_ping_pong(bool quiet)
     40char *test_ping_pong(void)
    4141{
    42         printf("Pinging ns server for %d seconds...\n", DURATION_SECS);
     42        TPRINTF("Pinging ns server for %d seconds...", DURATION_SECS);
    4343       
    4444        struct timeval start;
    45         if (gettimeofday(&start, NULL) != 0)
    46                 return "Failed getting the time.";
     45        if (gettimeofday(&start, NULL) != 0) {
     46                TPRINTF("\n");
     47                return "Failed getting the time";
     48        }
    4749       
    4850        uint64_t count = 0;
    49        
    5051        while (true) {
    5152                struct timeval now;
    52                 if (gettimeofday(&now, NULL) != 0)
    53                         return "Failed getting the time.";
     53                if (gettimeofday(&now, NULL) != 0) {
     54                        TPRINTF("\n");
     55                        return "Failed getting the time";
     56                }
    5457               
    5558                if (tv_sub(&now, &start) >= DURATION_SECS * 1000000L)
     
    6063                        int retval = async_req_0_0(PHONE_NS, NS_PING);
    6164                       
    62                         if (retval != EOK)
    63                                 return "Failed to send ping message.";
     65                        if (retval != EOK) {
     66                                TPRINTF("\n");
     67                                return "Failed to send ping message";
     68                        }
    6469                }
    6570               
     
    6772        }
    6873       
    69         printf("Completed %lu round trips in %u seconds, %lu RT/s.\n",
     74        TPRINTF("OK\nCompleted %llu round trips in %u seconds, %llu rt/s.\n",
    7075            count, DURATION_SECS, count / DURATION_SECS);
    7176       
  • uspace/app/tester/ipc/register.c

    rdb24058 r2d11a7d8  
    3333#include "../tester.h"
    3434
     35#define MAX_CONNECTIONS  50
     36
     37static int connections[MAX_CONNECTIONS];
     38
    3539static void client_connection(ipc_callid_t iid, ipc_call_t *icall)
    3640{
    37         ipc_callid_t callid;
    38         ipc_call_t call;
    39         ipcarg_t phonehash = icall->in_phone_hash;
    40         int retval;
    41         int i;
    42 
    43         printf("Connected phone: %P, accepting\n", icall->in_phone_hash);
     41        unsigned int i;
     42       
     43        TPRINTF("Connected phone %#x accepting\n", icall->in_phone_hash);
    4444        ipc_answer_0(iid, EOK);
    45         for (i = 0; i < 1024; i++)
     45        for (i = 0; i < MAX_CONNECTIONS; i++) {
    4646                if (!connections[i]) {
    47                         connections[i] = phonehash;
     47                        connections[i] = icall->in_phone_hash;
    4848                        break;
    4949                }
     50        }
    5051       
    51         while (1) {
    52                 callid = async_get_call(&call);
     52        while (true) {
     53                ipc_call_t call;
     54                ipc_callid_t callid = async_get_call(&call);
     55                int retval;
     56               
    5357                switch (IPC_GET_METHOD(call)) {
    5458                case IPC_M_PHONE_HUNGUP:
    55                         printf("Phone (%P) hung up.\n", phonehash);
     59                        TPRINTF("Phone %#x hung up\n", icall->in_phone_hash);
    5660                        retval = 0;
    5761                        break;
     62                case IPC_TEST_METHOD:
     63                        TPRINTF("Received well known message from %#x: %#x\n",
     64                            icall->in_phone_hash, callid);
     65                        ipc_answer_0(callid, EOK);
     66                        break;
    5867                default:
    59                         printf("Received message from %P: %X\n", phonehash,
    60                             callid);
    61                         for (i = 0; i < 1024; i++)
    62                                 if (!callids[i]) {
    63                                         callids[i] = callid;
    64                                         break;
    65                                 }
    66                         continue;
     68                        TPRINTF("Received unknown message from %#x: %#x\n",
     69                            icall->in_phone_hash, callid);
     70                        ipc_answer_0(callid, ENOENT);
     71                        break;
    6772                }
    68                 ipc_answer_0(callid, retval);
    6973        }
    7074}
    7175
    72 char * test_register(bool quiet)
     76char *test_register(void)
    7377{
    74         int i;
     78        async_set_client_connection(client_connection);
    7579       
    76         async_set_client_connection(client_connection);
    77 
    78         for (i = IPC_TEST_START; i < IPC_TEST_START + 10; i++) {
    79                 ipcarg_t phonead;
    80                 int res = ipc_connect_to_me(PHONE_NS, i, 0, 0, &phonead);
    81                 if (!res)
    82                         break;
    83                 printf("Failed registering as %d..:%d\n", i, res);
    84         }
    85         printf("Registered as service: %d\n", i);
    86         myservice = i;
     80        ipcarg_t phonead;
     81        int res = ipc_connect_to_me(PHONE_NS, IPC_TEST_SERVICE, 0, 0, &phonead);
     82        if (res != 0)
     83                return "Failed registering IPC service";
     84       
     85        TPRINTF("Registered as service %u, accepting connections\n", IPC_TEST_SERVICE);
     86        async_manager();
    8787       
    8888        return NULL;
  • uspace/app/tester/loop/loop1.c

    rdb24058 r2d11a7d8  
    3131#include "../tester.h"
    3232
    33 char *test_loop1(bool quiet)
     33char *test_loop1(void)
    3434{
    35         printf("Looping...\n");
    36         while (1);
    37         printf("Survived endless loop?!!\n");
    38 
    39         return NULL;
     35        TPRINTF("Looping...");
     36        while (true);
     37        TPRINTF("\n");
     38       
     39        return "Survived endless loop";
    4040}
    41 
  • uspace/app/tester/print/print1.c

    rdb24058 r2d11a7d8  
    3131#include "../tester.h"
    3232
    33 #define BUFFER_SIZE 32
    34 
    35 char * test_print1(bool quiet)
     33char *test_print1(void)
    3634{
    37         if (!quiet) {
    38                 int retval;
    39                 unsigned int nat = 0x12345678u;
    40                
    41                 char buffer[BUFFER_SIZE];
    42                
    43                 printf(" text 10.8s %*.*s \n", 5, 3, "text");
    44                 printf(" very long text 10.8s %10.8s \n", "very long text");
    45                 printf(" text 8.10s %8.10s \n", "text");
    46                 printf(" very long text 8.10s %8.10s \n", "very long text");
    47                
    48                 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' );
    49                 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 );
    50                 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 );
    51                 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 );
    52                
    53                 printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#zx'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" );
    54                
    55                 printf(" Print to NULL '%s'\n", NULL);
    56                
    57                 retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters.");
    58                 printf("Result is: '%s', retval = %d\n", buffer, retval);
    59                
    60                 retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters.");
    61                 printf("Result is: '%s', retval = %d\n", buffer, retval);
    62                
    63                 printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE);
    64                 retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text");
    65                 printf("Result is: '%s', retval = %d\n", buffer, retval);
    66                
    67                 printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE);
    68                 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);
    69                 printf("Result is: '%s', retval = %d\n", buffer, retval);
    70         }
     35        TPRINTF("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n");
     36        TPRINTF("Expected output: \"  tex\"\n");
     37        TPRINTF("Real output:     \"%*.*s\"\n\n", 5, 3, "text");
     38       
     39        TPRINTF("Testing printf(\"%%10.8s\", \"very long text\"):\n");
     40        TPRINTF("Expected output: \"  very lon\"\n");
     41        TPRINTF("Real output:     \"%10.8s\"\n\n", "very long text");
     42       
     43        TPRINTF("Testing printf(\"%%8.10s\", \"text\"):\n");
     44        TPRINTF("Expected output: \"text\"\n");
     45        TPRINTF("Real output:     \"%8.10s\"\n\n", "text");
     46       
     47        TPRINTF("Testing printf(\"%%8.10s\", \"very long text\"):\n");
     48        TPRINTF("Expected output: \"very long \"\n");
     49        TPRINTF("Real output:     \"%8.10s\"\n\n", "very long text");
     50       
     51        TPRINTF("Testing printf(\"%%s\", NULL):\n");
     52        TPRINTF("Expected output: \"(NULL)\"\n");
     53        TPRINTF("Real output:     \"%s\"\n\n", NULL);
    7154       
    7255        return NULL;
  • uspace/app/tester/print/print1.def

    rdb24058 r2d11a7d8  
    11{
    22        "print1",
    3         "Printf test",
     3        "String printf test",
    44        &test_print1,
    55        true
  • uspace/app/tester/print/print2.c

    rdb24058 r2d11a7d8  
    11/*
    2  * Copyright (c) 2006 Ondrej Palkovsky
     2 * Copyright (c) 2005 Josef Cejka
    33 * All rights reserved.
    44 *
     
    2929#include <stdio.h>
    3030#include <unistd.h>
    31 #include <errno.h>
    3231#include "../tester.h"
    3332
    34 char * test_hangup(bool quiet)
     33char *test_print2(void)
    3534{
    36         char c;
    37         int res;
    38         int phoneid;
    39 
    40         printf("Select phoneid to hangup: 2-9 (q to skip)\n");
    41         do {
    42                 c = getchar();
    43                 if ((c == 'Q') || (c == 'q'))
    44                         return TEST_SKIPPED;
    45         } while (c < '2' || c > '9');
    46         phoneid = c - '0';
     35        TPRINTF("Testing printf(\"%%c %%3.2c %%-3.2c %%2.3c %%-2.3c\", 'a', 'b', 'c', 'd', 'e'):\n");
     36        TPRINTF("Expected output: [a] [  b] [c  ] [ d] [e ]\n");
     37        TPRINTF("Real output:     [%c] [%3.2c] [%-3.2c] [%2.3c] [%-2.3c]\n\n", 'a', 'b', 'c', 'd', 'e');
    4738       
    48         printf("Hanging up...");
    49         res = ipc_hangup(phoneid);
    50         printf("done: %d\n", phoneid); 
     39        TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", 1, 2, 3, 4, 5):\n");
     40        TPRINTF("Expected output: [1] [ 02] [03 ] [004] [005]\n");
     41        TPRINTF("Real output:     [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", 1, 2, 3, 4, 5);
     42       
     43        TPRINTF("Testing printf(\"%%d %%3.2d %%-3.2d %%2.3d %%-2.3d\", -1, -2, -3, -4, -5):\n");
     44        TPRINTF("Expected output: [-1] [-02] [-03] [-004] [-005]\n");
     45        TPRINTF("Real output:     [%d] [%3.2d] [%-3.2d] [%2.3d] [%-2.3d]\n\n", -1, -2, -3, -4, -5);
     46       
     47        TPRINTF("Testing printf(\"%%#x %%5.3#x %%-5.3#x %%3.5#x %%-3.5#x\", 17, 18, 19, 20, 21):\n");
     48        TPRINTF("Expected output: [0x11] [0x012] [0x013] [0x00014] [0x00015]\n");
     49        TPRINTF("Real output:     [%#x] [%#5.3x] [%#-5.3x] [%#3.5x] [%#-3.5x]\n\n", 17, 18, 19, 20, 21);
    5150       
    5251        return NULL;
  • uspace/app/tester/print/print4.c

    rdb24058 r2d11a7d8  
    3131#include "../tester.h"
    3232
    33 #define PRIx8 "x"
    34 
    35 char *test_print4(bool quiet)
     33char *test_print4(void)
    3634{
    37         if (!quiet) {
    38                 printf("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n");
     35        TPRINTF("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n");
     36       
     37        uint8_t group;
     38        for (group = 1; group < 4; group++) {
     39                TPRINTF("%#x: ", group << 5);
    3940               
    40                 uint8_t group;
    41                 for (group = 1; group < 4; group++) {
    42                         printf("%#" PRIx8 ": ", group << 5);
    43                        
    44                         uint8_t index;
    45                         for (index = 0; index < 32; index++)
    46                                 printf("%c", (char) ((group << 5) + index));
    47                        
    48                         printf("  ");
    49                         for (index = 0; index < 32; index++)
    50                                 printf("%lc", (wchar_t) ((group << 5) + index));
    51                        
    52                         printf("\n");
    53                 }
     41                uint8_t index;
     42                for (index = 0; index < 32; index++)
     43                        TPRINTF("%c", (char) ((group << 5) + index));
    5444               
    55                 printf("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n");
     45                TPRINTF("  ");
     46                for (index = 0; index < 32; index++)
     47                        TPRINTF("%lc", (wchar_t) ((group << 5) + index));
    5648               
    57                 for (group = 4; group < 8; group++) {
    58                         printf("%#" PRIx8 ": ", group << 5);
    59                        
    60                         uint8_t index;
    61                         for (index = 0; index < 32; index++)
    62                                 printf("%lc", (wchar_t) ((group << 5) + index));
    63                        
    64                         printf("\n");
    65                 }
     49                TPRINTF("\n");
     50        }
     51       
     52        TPRINTF("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n");
     53       
     54        for (group = 4; group < 8; group++) {
     55                TPRINTF("%#x: ", group << 5);
    6656               
    67                 printf("\nUTF-8 strings using printf(\"%%s\"):\n");
    68                 printf("English:  %s\n", "Quick brown fox jumps over the lazy dog");
    69                 printf("Czech:    %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy");
    70                 printf("Greek:    %s\n", "Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε");
    71                 printf("Hebrew:   %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה");
    72                 printf("Arabic:   %s\n", "التوزيع الجغرافي للحمل العنقودي");
    73                 printf("Russian:  %s\n", "Леннон познакомился с художницей-авангардисткой");
    74                 printf("Armenian: %s\n", "Սկսեց հրատարակվել Երուսաղեմի հայկական");
     57                uint8_t index;
     58                for (index = 0; index < 32; index++)
     59                        TPRINTF("%lc", (wchar_t) ((group << 5) + index));
    7560               
    76                 printf("\nUTF-32 strings using printf(\"%%ls\"):\n");
    77                 printf("English:  %ls\n", L"Quick brown fox jumps over the lazy dog");
    78                 printf("Czech:    %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy");
    79                 printf("Greek:    %ls\n", L"Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε");
    80                 printf("Hebrew:   %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה");
    81                 printf("Arabic:   %ls\n", L"التوزيع الجغرافي للحمل العنقودي");
    82                 printf("Russian:  %ls\n", L"Леннон познакомился с художницей-авангардисткой");
    83                 printf("Armenian: %ls\n", L"Սկսեց հրատարակվել Երուսաղեմի հայկական");
    84 
    85                 printf("Test: [%d] '%lc'\n", L'\x0161', L'\x0161');
     61                TPRINTF("\n");
    8662        }
    87 
    88         printf("[Press a key]\n");
    89         getchar();
     63       
     64        TPRINTF("\nUTF-8 strings using printf(\"%%s\"):\n");
     65        TPRINTF("English:  %s\n", "Quick brown fox jumps over the lazy dog");
     66        TPRINTF("Czech:    %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy");
     67        TPRINTF("Greek:    %s\n", "Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε");
     68        TPRINTF("Hebrew:   %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה");
     69        TPRINTF("Arabic:   %s\n", "التوزيع الجغرافي للحمل العنقودي");
     70        TPRINTF("Russian:  %s\n", "Леннон познакомился с художницей-авангардисткой");
     71        TPRINTF("Armenian: %s\n", "Սկսեց հրատարակվել Երուսաղեմի հայկական");
     72       
     73        TPRINTF("\nUTF-32 strings using printf(\"%%ls\"):\n");
     74        TPRINTF("English:  %ls\n", L"Quick brown fox jumps over the lazy dog");
     75        TPRINTF("Czech:    %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy");
     76        TPRINTF("Greek:    %ls\n", L"Ὦ ξεῖν’, ἀγγέλλειν Λακεδαιμονίοις ὅτι τῇδε");
     77        TPRINTF("Hebrew:   %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה");
     78        TPRINTF("Arabic:   %ls\n", L"التوزيع الجغرافي للحمل العنقودي");
     79        TPRINTF("Russian:  %ls\n", L"Леннон познакомился с художницей-авангардисткой");
     80        TPRINTF("Armenian: %ls\n", L"Սկսեց հրատարակվել Երուսաղեմի հայկական");
    9081       
    9182        return NULL;
  • uspace/app/tester/stdio/stdio1.c

    rdb24058 r2d11a7d8  
    3232#include "../tester.h"
    3333
    34 #define BUF_SIZE 32
     34#define BUF_SIZE  32
     35
    3536static char buf[BUF_SIZE + 1];
    3637
    37 char * test_stdio1(bool quiet)
     38char *test_stdio1(void)
    3839{
    39         FILE *f;
     40        FILE *file;
    4041        char *file_name = "/readme";
    41         size_t n;
    42         int c;
    43 
    44         printf("Open file '%s'\n", file_name);
     42       
     43        TPRINTF("Open file \"%s\"...", file_name);
    4544        errno = 0;
    46         f = fopen(file_name, "rt");
    47 
    48         if (f == NULL) printf("errno = %d\n", errno);
    49 
    50         if (f == NULL)
    51                 return "Failed opening file.";
    52 
    53         n = fread(buf, 1, BUF_SIZE, f);
    54         if (ferror(f)) {
    55                 fclose(f);
    56                 return "Failed reading file.";
     45        file = fopen(file_name, "rt");
     46        if (file == NULL) {
     47                TPRINTF("errno = %d\n", errno);
     48                return "Failed opening file";
     49        } else
     50                TPRINTF("OK\n");
     51       
     52        TPRINTF("Read file...");
     53        size_t cnt = fread(buf, 1, BUF_SIZE, file);
     54        if (ferror(file)) {
     55                TPRINTF("errno = %d\n", errno);
     56                fclose(file);
     57                return "Failed reading file";
     58        } else
     59                TPRINTF("OK\n");
     60       
     61        buf[cnt] = '\0';
     62        TPRINTF("Read %u bytes, string \"%s\"\n", cnt, buf);
     63       
     64        TPRINTF("Seek to beginning...");
     65        if (fseek(file, 0, SEEK_SET) != 0) {
     66                TPRINTF("errno = %d\n", errno);
     67                fclose(file);
     68                return "Failed seeking in file";
     69        } else
     70                TPRINTF("OK\n");
     71       
     72        TPRINTF("Read using fgetc()...");
     73        while (true) {
     74                int c = fgetc(file);
     75                if (c == EOF)
     76                        break;
     77               
     78                TPRINTF(".");
    5779        }
    58 
    59         printf("Read %d bytes.\n", n);
    60 
    61         buf[n] = '\0';
    62         printf("Read string '%s'.\n", buf);
    63 
    64         printf("Seek to beginning.\n");
    65         if (fseek(f, 0, SEEK_SET) != 0) {
    66                 fclose(f);
    67                 return "Failed seeking.";
    68         }
    69 
    70         printf("Read using fgetc().\n");
    71         while (true) {
    72                 c = fgetc(f);
    73                 if (c == EOF) break;
    74 
    75                 printf("'%c'", c);
    76         }
    77 
    78         printf("[EOF]\n");
    79         printf("Closing.\n");
    80 
    81         if (fclose(f) != 0)
    82                 return "Failed closing.";
    83 
     80        TPRINTF("[EOF]\n");
     81       
     82        TPRINTF("Close...");
     83        if (fclose(file) != 0) {
     84                TPRINTF("errno = %d\n", errno);
     85                return "Failed closing file";
     86        } else
     87                TPRINTF("OK\n");
     88       
    8489        return NULL;
    8590}
  • uspace/app/tester/stdio/stdio2.c

    rdb24058 r2d11a7d8  
    3232#include "../tester.h"
    3333
    34 char * test_stdio2(bool quiet)
     34char *test_stdio2(void)
    3535{
    36         FILE *f;
     36        FILE *file;
    3737        char *file_name = "/test";
    38         int c;
    39 
    40         printf("Open file '%s' for writing\n", file_name);
     38       
     39        TPRINTF("Open file \"%s\" for writing...", file_name);
    4140        errno = 0;
    42         f = fopen(file_name, "wt");
    43 
    44         if (f == NULL)
    45                 return "Failed opening file.";
    46 
    47         fprintf(f, "Integer: %d, string: '%s'\n", 42, "Hello!");
    48         if (fclose(f) != 0)
    49                 return "Failed closing file.";
    50 
    51         printf("Open file '%s' for reading\n", file_name);
    52 
    53         f = fopen(file_name, "rt");
    54         if (f == NULL)
    55                 return "Failed opening file.";
    56 
    57         printf("File contains:\n");
     41        file = fopen(file_name, "wt");
     42        if (file == NULL) {
     43                TPRINTF("errno = %d\n", errno);
     44                return "Failed opening file";
     45        } else
     46                TPRINTF("OK\n");
     47       
     48        TPRINTF("Write to file...");
     49        fprintf(file, "integer: %u, string: \"%s\"", 42, "Hello!");
     50        TPRINTF("OK\n");
     51       
     52        TPRINTF("Close...");
     53        if (fclose(file) != 0) {
     54                TPRINTF("errno = %d\n", errno);
     55                return "Failed closing file";
     56        } else
     57                TPRINTF("OK\n");
     58       
     59        TPRINTF("Open file \"%s\" for reading...", file_name);
     60        file = fopen(file_name, "rt");
     61        if (file == NULL) {
     62                TPRINTF("errno = %d\n", errno);
     63                return "Failed opening file";
     64        } else
     65                TPRINTF("OK\n");
     66       
     67        TPRINTF("File contains:\n");
    5868        while (true) {
    59                 c = fgetc(f);
    60                 if (c == EOF) break;
    61                 putchar(c);
     69                int c = fgetc(file);
     70                if (c == EOF)
     71                        break;
     72                TPRINTF("%c", c);
    6273        }
    63 
    64         if (fclose(f) != 0)
    65                 return "Failed closing file.";
    66 
     74       
     75        TPRINTF("\nClose...");
     76        if (fclose(file) != 0) {
     77                TPRINTF("errno = %d\n", errno);
     78                return "Failed closing file";
     79        } else
     80                TPRINTF("OK\n");
     81       
    6782        return NULL;
    6883}
  • uspace/app/tester/tester.c

    rdb24058 r2d11a7d8  
    2828 */
    2929
    30 /** @addtogroup tester User space Tester
    31  * @brief       User space testing infrastructure.
     30/** @addtogroup tester User space tester
     31 * @brief User space testing infrastructure.
    3232 * @{
    33  */ 
     33 */
    3434/**
    3535 * @file
     
    3838#include <unistd.h>
    3939#include <stdio.h>
     40#include <string.h>
    4041#include "tester.h"
    4142
    42 int myservice = 0;
    43 int phones[MAX_PHONES];
    44 int connections[MAX_CONNECTIONS];
    45 ipc_callid_t callids[MAX_CONNECTIONS];
     43bool test_quiet;
     44int test_argc;
     45char **test_argv;
    4646
    4747test_t tests[] = {
    4848#include "thread/thread1.def"
    4949#include "print/print1.def"
     50#include "print/print2.def"
     51#include "print/print3.def"
    5052#include "print/print4.def"
    51 #include "fault/fault1.def"
    52 #include "fault/fault2.def"
    53 #include "ipc/register.def"
    54 #include "ipc/connect.def"
    55 #include "ipc/send_async.def"
    56 #include "ipc/send_sync.def"
    57 #include "ipc/answer.def"
    58 #include "ipc/hangup.def"
    59 #include "ipc/ping_pong.def"
    60 #include "devmap/devmap1.def"
    61 #include "loop/loop1.def"
    62 #include "vfs/vfs1.def"
    6353#include "console/console1.def"
    6454#include "stdio/stdio1.def"
    6555#include "stdio/stdio2.def"
    66         {NULL, NULL, NULL}
     56#include "fault/fault1.def"
     57#include "fault/fault2.def"
     58#include "vfs/vfs1.def"
     59#include "ipc/ping_pong.def"
     60#include "ipc/register.def"
     61#include "ipc/connect.def"
     62#include "loop/loop1.def"
     63#include "mm/malloc1.def"
     64        {NULL, NULL, NULL, false}
    6765};
    6866
    6967static bool run_test(test_t *test)
    7068{
    71         printf("%s\t\t%s\n", test->name, test->desc);
    72        
    7369        /* Execute the test */
    74         char * ret = test->entry(false);
     70        char *ret = test->entry();
    7571       
    7672        if (ret == NULL) {
    77                 printf("Test passed\n\n");
     73                printf("\nTest passed\n");
    7874                return true;
    7975        }
    80 
    81         printf("%s\n\n", ret);
     76       
     77        printf("\n%s\n", ret);
    8278        return false;
    8379}
     
    8884        unsigned int i = 0;
    8985        unsigned int n = 0;
    90 
     86       
    9187        printf("\n*** Running all safe tests ***\n\n");
    92 
     88       
    9389        for (test = tests; test->name != NULL; test++) {
    9490                if (test->safe) {
     91                        printf("%s (%s)\n", test->name, test->desc);
    9592                        if (run_test(test))
    9693                                i++;
     
    9996                }
    10097        }
    101 
    102         printf("\nSafe tests completed, %u tests run, %u passed.\n\n", i + n, i);
     98       
     99        printf("\nCompleted, %u tests run, %u passed.\n", i + n, i);
    103100}
    104101
    105102static void list_tests(void)
    106103{
     104        size_t len = 0;
    107105        test_t *test;
    108         char c = 'a';
     106        for (test = tests; test->name != NULL; test++) {
     107                if (str_length(test->name) > len)
     108                        len = str_length(test->name);
     109        }
    109110       
    110         for (test = tests; test->name != NULL; test++, c++)
    111                 printf("%c\t%s\t\t%s%s\n", c, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
     111        for (test = tests; test->name != NULL; test++)
     112                printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
    112113       
    113         printf("*\t\t\tRun all safe tests\n");
     114        printf("%-*s Run all safe tests\n", len, "*");
    114115}
    115116
    116 int main(int argc, char **argv)
     117int main(int argc, char *argv[])
    117118{
    118         printf("Number of arguments: %d\n", argc);
    119         if (argv) {
    120                 printf("Arguments:");
    121                 while (*argv) {
    122                         printf(" '%s'", *argv++);
     119        if (argc < 2) {
     120                printf("Usage:\n\n");
     121                printf("%s <test> [args ...]\n\n", argv[0]);
     122                list_tests();
     123                return 0;
     124        }
     125       
     126        test_quiet = false;
     127        test_argc = argc - 2;
     128        test_argv = argv + 2;
     129       
     130        if (str_cmp(argv[1], "*") == 0) {
     131                run_safe_tests();
     132                return 0;
     133        }
     134       
     135        test_t *test;
     136        for (test = tests; test->name != NULL; test++) {
     137                if (str_cmp(argv[1], test->name) == 0) {
     138                        return (run_test(test) ? 0 : -1);
    123139                }
    124                 printf("\n");
    125140        }
    126 
    127         while (1) {
    128                 char c;
    129                 test_t *test;
    130                
    131                 list_tests();
    132                 printf("> ");
    133                 fflush(stdout);
    134                
    135                 c = getchar();
    136                 printf("%c\n", c);
    137                
    138                 if ((c >= 'a') && (c <= 'z')) {
    139                         for (test = tests; test->name != NULL; test++, c--)
    140                                 if (c == 'a')
    141                                         break;
    142                        
    143                         if (test->name == NULL)
    144                                 printf("Unknown test\n\n");
    145                         else
    146                                 run_test(test);
    147                 } else if (c == '*') {
    148                         run_safe_tests();
    149                 } else if (c < 0) {
    150                         /* got EOF */
    151                         break;
    152                 } else {
    153                         printf("Invalid test\n\n");
    154                 }
    155                        
    156         }
    157 
    158         return 0;
     141       
     142        printf("Unknown test \"%s\"\n", argv[1]);
     143        return -2;
    159144}
    160145
  • uspace/app/tester/tester.h

    rdb24058 r2d11a7d8  
    4040#include <ipc/ipc.h>
    4141
    42 #define IPC_TEST_START  10000
    43 #define MAX_PHONES              20
    44 #define MAX_CONNECTIONS 50
    45 #define TEST_SKIPPED    "Test Skipped"
     42#define IPC_TEST_SERVICE  10240
     43#define IPC_TEST_METHOD   2000
    4644
    47 extern int myservice;
    48 extern int phones[MAX_PHONES];
    49 extern int connections[MAX_CONNECTIONS];
    50 extern ipc_callid_t callids[MAX_CONNECTIONS];
     45extern bool test_quiet;
     46extern int test_argc;
     47extern char **test_argv;
    5148
    52 typedef char * (* test_entry_t)(bool);
     49#define TPRINTF(format, ...) \
     50        { \
     51                if (!test_quiet) { \
     52                        fprintf(stderr, format, ##__VA_ARGS__); \
     53                } \
     54        }
     55
     56typedef char *(*test_entry_t)(void);
    5357
    5458typedef struct {
    55         char * name;
    56         char * desc;
     59        char *name;
     60        char *desc;
    5761        test_entry_t entry;
    5862        bool safe;
    5963} test_t;
    6064
    61 extern char * test_thread1(bool quiet);
    62 extern char * test_print1(bool quiet);
    63 extern char * test_print4(bool quiet);
    64 extern char * test_fault1(bool quiet);
    65 extern char * test_fault2(bool quiet);
    66 extern char * test_register(bool quiet);
    67 extern char * test_connect(bool quiet);
    68 extern char * test_send_async(bool quiet);
    69 extern char * test_send_sync(bool quiet);
    70 extern char * test_answer(bool quiet);
    71 extern char * test_hangup(bool quiet);
    72 extern char * test_ping_pong(bool quiet);
    73 extern char * test_devmap1(bool quiet);
    74 extern char * test_loop1(bool quiet);
    75 extern char * test_vfs1(bool quiet);
    76 extern char * test_console1(bool quiet);
    77 extern char * test_stdio1(bool quiet);
    78 extern char * test_stdio2(bool quiet);
     65extern char *test_thread1(void);
     66extern char *test_print1(void);
     67extern char *test_print2(void);
     68extern char *test_print3(void);
     69extern char *test_print4(void);
     70extern char *test_console1(void);
     71extern char *test_stdio1(void);
     72extern char *test_stdio2(void);
     73extern char *test_fault1(void);
     74extern char *test_fault2(void);
     75extern char *test_vfs1(void);
     76extern char *test_ping_pong(void);
     77extern char *test_register(void);
     78extern char *test_connect(void);
     79extern char *test_loop1(void);
     80extern char *test_malloc1(void);
    7981
    8082extern test_t tests[];
  • uspace/app/tester/thread/thread1.c

    rdb24058 r2d11a7d8  
    2828 */
    2929
    30 #define THREADS 5
     30#define THREADS  20
     31#define DELAY    10
    3132
    3233#include <atomic.h>
     
    4344{
    4445        thread_detach(thread_get_id());
    45 
    46         while (atomic_get(&finish)) {
    47                 if (!sh_quiet)
    48                         printf("%llu ", thread_get_id());
     46       
     47        while (atomic_get(&finish))
    4948                usleep(100000);
    50         }
     49       
    5150        atomic_inc(&threads_finished);
    5251}
    5352
    54 char * test_thread1(bool quiet)
     53char *test_thread1(void)
    5554{
    56         unsigned int i, total = 0;
    57         sh_quiet = quiet;
     55        unsigned int i;
     56        unsigned int total = 0;
    5857       
    5958        atomic_set(&finish, 1);
    6059        atomic_set(&threads_finished, 0);
    61 
    62         for (i = 0; i < THREADS; i++) { 
     60       
     61        TPRINTF("Creating threads");
     62        for (i = 0; i < THREADS; i++) {
    6363                if (thread_create(threadtest, NULL, "threadtest", NULL) < 0) {
    64                         if (!quiet)
    65                                 printf("Could not create thread %d\n", i);
     64                        TPRINTF("\nCould not create thread %u\n", i);
    6665                        break;
    6766                }
     67                TPRINTF(".");
    6868                total++;
    6969        }
    7070       
    71         if (!quiet)
    72                 printf("Running threads for 10 seconds...\n");
    73         sleep(10);
     71        TPRINTF("\nRunning threads for %u seconds...", DELAY);
     72        sleep(DELAY);
     73        TPRINTF("\n");
    7474       
    7575        atomic_set(&finish, 0);
    7676        while (atomic_get(&threads_finished) < total) {
    77                 if (!quiet)
    78                         printf("Threads left: %d\n", total - atomic_get(&threads_finished));
     77                TPRINTF("Threads left: %u\n", total - atomic_get(&threads_finished));
    7978                sleep(1);
    8079        }
  • uspace/app/tester/vfs/vfs1.c

    rdb24058 r2d11a7d8  
    3535#include <fcntl.h>
    3636#include <dirent.h>
     37#include <devmap.h>
    3738#include <sys/types.h>
    3839#include <sys/stat.h>
    3940#include "../tester.h"
    4041
    41 char text[] = "O xein', angellein Lakedaimoniois hoti teide "
    42         "keimetha tois keinon rhemasi peithomenoi.";
     42#define FS_TYPE      "tmpfs"
     43#define MOUNT_POINT  "/tmp"
     44#define OPTIONS      ""
     45#define FLAGS        0
    4346
    44 char *test_vfs1(bool quiet)
     47#define TEST_DIRECTORY  MOUNT_POINT "/testdir"
     48#define TEST_FILE       TEST_DIRECTORY "/testfile"
     49#define TEST_FILE2      TEST_DIRECTORY "/nextfile"
     50
     51#define MAX_DEVICE_NAME  32
     52#define BUF_SIZE         16
     53
     54static char text[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit";
     55
     56static char *read_root(void)
    4557{
    46         int rc;
    47 
    48         rc = mount("tmpfs", "/", "nulldev0", "", 0);
    49         switch (rc) {
    50         case EOK:
    51                 if (!quiet)
    52                         printf("mounted tmpfs on /\n");
    53                 break;
    54         case EBUSY:
    55                 if (!quiet)
    56                         printf("(INFO) something is already mounted on /\n");
    57                 break;
    58         default:
    59                 if (!quiet)
    60                         printf("(INFO) IPC returned errno %d\n", rc);
    61                 return "mount() failed.";
    62         }
    63 
    64         if (mkdir("/mydir", 0) != 0)
    65                 return "mkdir() failed.\n";
    66         if (!quiet)
    67                 printf("created directory /mydir\n");
     58        TPRINTF("Opening the root directory...");
    6859       
    69         int fd0 = open("/mydir/myfile", O_CREAT);
    70         if (fd0 < 0)
    71                 return "open() failed.\n";
    72         if (!quiet)
    73                 printf("created file /mydir/myfile, fd=%d\n", fd0);
    74 
    75         ssize_t cnt;
    76         size_t size = sizeof(text);
    77         cnt = write(fd0, text, size);
    78         if (cnt < 0)
    79                 return "write() failed.\n";
    80         if (!quiet)
    81                 printf("written %d bytes, fd=%d\n", cnt, fd0);
    82         if (lseek(fd0, 0, SEEK_SET) != 0)
    83                 return "lseek() failed.\n";
    84         if (!quiet)
    85                 printf("sought to position 0, fd=%d\n", fd0);
    86 
    87         char buf[10];
    88 
    89         while ((cnt = read(fd0, buf, sizeof(buf)))) {
    90                 if (cnt < 0)
    91                         return "read() failed.\n";
    92                 if (!quiet)
    93                         printf("read %d bytes: \"%.*s\", fd=%d\n", cnt, cnt,
    94                             buf, fd0);
    95         }
    96 
    97         close(fd0);
    98 
    99         DIR *dirp;
     60        DIR *dirp = opendir("/");
     61        if (!dirp) {
     62                TPRINTF("\n");
     63                return "opendir() failed";
     64        } else
     65                TPRINTF("OK\n");
     66       
    10067        struct dirent *dp;
    101 
    102         if (!quiet)
    103                 printf("scanning the root directory...\n");
    104 
    105         dirp = opendir("/");
    106         if (!dirp)
    107                 return "opendir() failed\n";
    10868        while ((dp = readdir(dirp)))
    109                 printf("discovered node %s in /\n", dp->d_name);
     69                TPRINTF(" node \"%s\"\n", dp->d_name);
    11070        closedir(dirp);
    111 
    112         if (rename("/mydir/myfile", "/mydir/yourfile"))
    113                 return "rename() failed.\n";
    114 
    115         if (!quiet)
    116                 printf("renamed /mydir/myfile to /mydir/yourfile\n");
    117 
    118         if (unlink("/mydir/yourfile"))
    119                 return "unlink() failed.\n";
    12071       
    121         if (!quiet)
    122                 printf("unlinked file /mydir/yourfile\n");
    123 
    124         if (rmdir("/mydir"))
    125                 return "rmdir() failed.\n";
    126 
    127         if (!quiet)
    128                 printf("removed directory /mydir\n");
    129        
    130         if (!quiet)
    131                 printf("scanning the root directory...\n");
    132 
    133         dirp = opendir("/");
    134         if (!dirp)
    135                 return "opendir() failed\n";
    136         while ((dp = readdir(dirp)))
    137                 printf("discovered node %s in /\n", dp->d_name);
    138         closedir(dirp);
    139 
    14072        return NULL;
    14173}
    14274
     75char *test_vfs1(void)
     76{
     77        if (mkdir(MOUNT_POINT, 0) != 0)
     78                return "mkdir() failed";
     79        TPRINTF("Created directory %s\n", MOUNT_POINT);
     80       
     81        char null[MAX_DEVICE_NAME];
     82        int null_id = devmap_null_create();
     83       
     84        if (null_id == -1)
     85                return "Unable to create null device";
     86       
     87        snprintf(null, MAX_DEVICE_NAME, "null%d", null_id);
     88        int rc = mount(FS_TYPE, MOUNT_POINT, null, OPTIONS, FLAGS);
     89        switch (rc) {
     90        case EOK:
     91                TPRINTF("Mounted /dev/%s as %s on %s\n", null, FS_TYPE, MOUNT_POINT);
     92                break;
     93        case EBUSY:
     94                TPRINTF("(INFO) Filesystem already mounted on %s\n", MOUNT_POINT);
     95                break;
     96        default:
     97                TPRINTF("(ERR) IPC returned errno %d (is tmpfs loaded?)\n", rc);
     98                return "mount() failed";
     99        }
     100       
     101        if (mkdir(TEST_DIRECTORY, 0) != 0)
     102                return "mkdir() failed";
     103        TPRINTF("Created directory %s\n", TEST_DIRECTORY);
     104       
     105        int fd0 = open(TEST_FILE, O_CREAT);
     106        if (fd0 < 0)
     107                return "open() failed";
     108        TPRINTF("Created file %s (fd=%d)\n", TEST_FILE, fd0);
     109       
     110        size_t size = sizeof(text);
     111        ssize_t cnt = write(fd0, text, size);
     112        if (cnt < 0)
     113                return "write() failed";
     114        TPRINTF("Written %d bytes\n", cnt);
     115       
     116        if (lseek(fd0, 0, SEEK_SET) != 0)
     117                return "lseek() failed";
     118        TPRINTF("Sought to position 0\n");
     119       
     120        char buf[BUF_SIZE];
     121        while ((cnt = read(fd0, buf, BUF_SIZE))) {
     122                if (cnt < 0)
     123                        return "read() failed";
     124               
     125                TPRINTF("Read %d bytes: \".*s\"\n", cnt, cnt, buf);
     126        }
     127       
     128        close(fd0);
     129       
     130        char *rv = read_root();
     131        if (rv != NULL)
     132                return rv;
     133       
     134        if (rename(TEST_FILE, TEST_FILE2))
     135                return "rename() failed";
     136        TPRINTF("Renamed %s to %s\n", TEST_FILE, TEST_FILE2);
     137       
     138        if (unlink(TEST_FILE2))
     139                return "unlink() failed";
     140        TPRINTF("Unlinked %s\n", TEST_FILE2);
     141       
     142        if (rmdir(TEST_DIRECTORY))
     143                return "rmdir() failed";
     144        TPRINTF("Removed directory %s\n", TEST_DIRECTORY);
     145       
     146        rv = read_root();
     147        if (rv != NULL)
     148                return rv;
     149       
     150        return NULL;
     151}
Note: See TracChangeset for help on using the changeset viewer.