Changeset 2d11a7d8 in mainline for uspace/app/tester/tester.c


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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.