Subversion Repositories HelenOS

Rev

Rev 3117 | Rev 3415 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2006 Ondrej Palkovsky
  3.  * Copyright (c) 2007 Martin Decky
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  *
  10.  * - Redistributions of source code must retain the above copyright
  11.  *   notice, this list of conditions and the following disclaimer.
  12.  * - Redistributions in binary form must reproduce the above copyright
  13.  *   notice, this list of conditions and the following disclaimer in the
  14.  *   documentation and/or other materials provided with the distribution.
  15.  * - The name of the author may not be used to endorse or promote products
  16.  *   derived from this software without specific prior written permission.
  17.  *
  18.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28.  */
  29.  
  30. /** @addtogroup tester User space Tester
  31.  * @brief   User space testing infrastructure.
  32.  * @{
  33.  */
  34. /**
  35.  * @file
  36.  */
  37.  
  38. #include <unistd.h>
  39. #include <stdio.h>
  40. #include "tester.h"
  41.  
  42. int myservice = 0;
  43. int phones[MAX_PHONES];
  44. int connections[MAX_CONNECTIONS];
  45. ipc_callid_t callids[MAX_CONNECTIONS];
  46.  
  47. test_t tests[] = {
  48. #include "thread/thread1.def"
  49. #include "print/print1.def"
  50. #include "fault/fault1.def"
  51. #include "fault/fault2.def"
  52. #include "ipc/register.def"
  53. #include "ipc/connect.def"
  54. #include "ipc/send_async.def"
  55. #include "ipc/send_sync.def"
  56. #include "ipc/answer.def"
  57. #include "ipc/hangup.def"
  58. #include "devmap/devmap1.def"
  59. #include "vfs/vfs1.def"
  60.     {NULL, NULL, NULL}
  61. };
  62.  
  63. static bool run_test(test_t *test)
  64. {
  65.     printf("%s\t\t%s\n", test->name, test->desc);
  66.    
  67.     /* Execute the test */
  68.     char * ret = test->entry(false);
  69.    
  70.     if (ret == NULL) {
  71.         printf("Test passed\n\n");
  72.         return true;
  73.     }
  74.  
  75.     printf("%s\n\n", ret);
  76.     return false;
  77. }
  78.  
  79. static void run_safe_tests(void)
  80. {
  81.     test_t *test;
  82.     unsigned int i = 0;
  83.     unsigned int n = 0;
  84.  
  85.     printf("\n*** Running all safe tests ***\n\n");
  86.  
  87.     for (test = tests; test->name != NULL; test++) {
  88.         if (test->safe) {
  89.             if (run_test(test))
  90.                 i++;
  91.             else
  92.                 n++;
  93.         }
  94.     }
  95.  
  96.     printf("\nSafe tests completed, %u tests run, %u passed.\n\n", i + n, i);
  97. }
  98.  
  99. static void list_tests(void)
  100. {
  101.     test_t *test;
  102.     char c = 'a';
  103.    
  104.     for (test = tests; test->name != NULL; test++, c++)
  105.         printf("%c\t%s\t\t%s%s\n", c, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
  106.    
  107.     printf("*\t\t\tRun all safe tests\n");
  108. }
  109.  
  110. int main(int argc, char **argv)
  111. {
  112.     printf("Number of arguments: %d\n", argc);
  113.     if (argv) {
  114.         printf("Arguments:");
  115.         while (*argv) {
  116.             printf(" '%s'", *argv++);
  117.         }
  118.         printf("\n");
  119.     }
  120.  
  121.     while (1) {
  122.         char c;
  123.         test_t *test;
  124.        
  125.         list_tests();
  126.         printf("> ");
  127.        
  128.         c = getchar();
  129.         printf("%c\n", c);
  130.        
  131.         if ((c >= 'a') && (c <= 'z')) {
  132.             for (test = tests; test->name != NULL; test++, c--)
  133.                 if (c == 'a')
  134.                     break;
  135.            
  136.             if (c > 'a')
  137.                 printf("Unknown test\n\n");
  138.             else
  139.                 run_test(test);
  140.         } else if (c == '*') {
  141.             run_safe_tests();
  142.         } else if (c < 0) {
  143.             /* got EOF */
  144.             break;
  145.         } else {
  146.             printf("Invalid test\n\n");
  147.         }
  148.            
  149.     }
  150. }
  151.  
  152. /** @}
  153.  */
  154.