Subversion Repositories HelenOS-historic

Rev

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

  1. /*
  2.  * Copyright (C) 2005 Martin Decky
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. #include "version.h"
  30. #include <ipc.h>
  31. #include <stdio.h>
  32. #include <unistd.h>
  33. #include <stdlib.h>
  34. #include <ns.h>
  35. #include <thread.h>
  36.  
  37. int a;
  38.  
  39. extern void utest(void *arg);
  40. void utest(void *arg)
  41. {
  42.     printf("Uspace thread started.\n");
  43.     for (;;)
  44.         ;
  45. }
  46.  
  47. static void test_printf(void)
  48. {
  49.     printf("Simple text.\n");
  50.     printf("Now insert '%s' string.\n","this");
  51.     printf("Signed formats on uns. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", 321, 321, 321, 321);
  52.     printf("Signed formats on sig. numbers: '%d', '%+d', '% d', '%u' (,+, ,u)\n", -321, -321, -321, -321);
  53.     printf("Signed with different sized: '%hhd', '%hd', '%d', '%ld', %lld;\n", -3, -32, -321, -32101l, -3210123ll);
  54.     printf("And now... '%hhd' byte! '%hd' word! '%d' int! \n", 11, 11111, 1111111111);
  55.     printf("Different bases: %#hx, %#hu, %#ho and %#hb\n", 123, 123, 123, 123);
  56.     printf("Different bases signed: %#hx, %#hu, %#ho and %#hb\n", -123, -123, -123, -123);
  57.     printf("'%llX' llX! Another '%llx' llx! \n", 0x1234567887654321ll, 0x1234567887654321ll);
  58.     printf("'%llX' with 64bit value and '%x' with 32 bit value. \n", 0x1234567887654321ll, 0x12345678 );
  59.     printf("'%llx' 64bit, '%x' 32bit, '%hhx' 8bit, '%hx' 16bit, '%llX' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, 0x1234567887654321ull, "Lovely string" );
  60.    
  61.     printf("Thats all, folks!\n");
  62. }
  63.  
  64.  
  65. extern char _heap;
  66. static void test_mremap(void)
  67. {
  68.     printf("Writing to good memory\n");
  69.     mremap(&_heap, 120000, 0);
  70.     printf("%P\n", ((char *)&_heap));
  71.     printf("%P\n", ((char *)&_heap) + 80000);
  72.     *(((char *)&_heap) + 80000) = 10;
  73.     printf("Making small\n");
  74.     mremap(&_heap, 16000, 0);
  75.     printf("Failing..\n");
  76.     *((&_heap) + 80000) = 10;
  77.  
  78.     printf("memory done\n");
  79. }
  80. /*
  81. static void test_sbrk(void)
  82. {
  83.     printf("Writing to good memory\n");
  84.     printf("Got: %P\n", sbrk(120000));
  85.     printf("%P\n", ((char *)&_heap));
  86.     printf("%P\n", ((char *)&_heap) + 80000);
  87.     *(((char *)&_heap) + 80000) = 10;
  88.     printf("Making small, got: %P\n",sbrk(-120000));
  89.     printf("Testing access to heap\n");
  90.     _heap = 10;
  91.     printf("Failing..\n");
  92.     *((&_heap) + 80000) = 10;
  93.  
  94.     printf("memory done\n");
  95. }
  96. */
  97. /*
  98. static void test_malloc(void)
  99. {
  100.     char *data;
  101.  
  102.     data = malloc(10);
  103.     printf("Heap: %P, data: %P\n", &_heap, data);
  104.     data[0] = 'a';
  105.     free(data);
  106. }
  107. */
  108.  
  109.  
  110. static void test_ping(void)
  111. {
  112.     ipcarg_t result;
  113.     int retval;
  114.  
  115.     retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
  116.     printf("Retval: %d - received: %P\n", retval, result);
  117. }
  118.  
  119. static void got_answer(void *private, int retval, ipc_data_t *data)
  120. {
  121.     printf("Retval: %d...%s...%zX, %zX\n", retval, private,
  122.            IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
  123. }
  124. static void test_async_ipc(void)
  125. {
  126.     ipc_call_t data;
  127.     int i;
  128.  
  129.     printf("Sending ping\n");
  130.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  131.              "Pong1", got_answer);
  132.     ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4,
  133.              "Pong2", got_answer);
  134.     ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4,
  135.              "Pong3", got_answer);
  136.     ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4,
  137.              "Pong4", got_answer);
  138.     ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4,
  139.              "Pong5", got_answer);
  140.     ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4,
  141.              "Pong6", got_answer);
  142.     printf("Waiting forever...\n");
  143.     for (i=0; i<100;i++)
  144.         printf(".");
  145.     printf("\n");
  146.     ipc_wait_for_call(&data, NULL);
  147.     printf("Received call???\n");
  148. }
  149.  
  150.  
  151. static void got_answer_2(void *private, int retval, ipc_data_t *data)
  152. {
  153.     printf("Pong\n");
  154. }
  155. static void test_advanced_ipc(void)
  156. {
  157.     int res;
  158.     unsigned long long taskid;
  159.     ipc_callid_t callid;
  160.     ipc_call_t data;
  161.     int i;
  162.  
  163.     printf("Asking 0 to connect to me...\n");
  164.     res = ipc_connect_to_me(0, 1, 2, &taskid);
  165.     printf("Result: %d - taskid: %llu\n", res, taskid);
  166.     for (i=0; i < 100; i++) {
  167.         printf("----------------\n");
  168.         ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov",
  169.                    got_answer_2);
  170.         callid = ipc_wait_for_call(&data, NULL);
  171.         printf("Received ping\n");
  172.         ipc_answer(callid, 0, 0, 0);
  173.     }
  174. //  callid = ipc_wait_for_call(&data, NULL);
  175. }
  176.  
  177. static void test_connection_ipc(void)
  178. {
  179.     int res;
  180.     ipcarg_t result;
  181.  
  182.     printf("Starting connect...\n");
  183.     res = ipc_connect_me_to(PHONE_NS, 10, 20);
  184.     printf("Connected: %d\n", res);
  185.     printf("pinging.\n");
  186.     res = ipc_call_sync(res, NS_PING, 0xbeef,&result);
  187.     printf("Retval: %d - received: %X\n", res, result);
  188.    
  189. }
  190.  
  191. static void test_hangup(void)
  192. {
  193.     int phoneid;
  194.     ipc_call_t data;
  195.     ipc_callid_t callid;
  196.     int i;
  197.  
  198.     printf("Starting connect...\n");
  199.     phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
  200.     printf("Phoneid: %d, pinging\n", phoneid);
  201.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  202.              "Pong1", got_answer);
  203.     printf("Hangin up\n");
  204.     ipc_hangup(phoneid);
  205.     printf("Connecting\n");
  206.     phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
  207.     printf("Newphid: %d\n", phoneid);
  208.     for (i=0; i < 1000; i++) {
  209.         if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
  210.             printf("callid: %d\n");
  211.     }
  212.     printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20));
  213. }
  214.  
  215. static void test_slam(void)
  216. {
  217.     int i;
  218.     ipc_call_t data;
  219.     ipc_callid_t callid;
  220.  
  221.     printf("ping");
  222.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  223.              "Pong1", got_answer);
  224.     printf("slam");
  225.     ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2,
  226.              "Hang", got_answer);
  227.     printf("ping2\n");
  228.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  229.              "Ping2", got_answer);
  230.    
  231.     for (i=0; i < 1000; i++) {
  232.         if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
  233.             printf("callid: %d\n");
  234.     }
  235.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  236.              "Pong1", got_answer);
  237.     printf("Closing file\n");
  238.     ipc_hangup(PHONE_NS);
  239.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  240.              "Pong1", got_answer);
  241.     ipc_wait_for_call(&data, 0);
  242. }
  243.  
  244. int main(int argc, char *argv[])
  245. {
  246.     int tid;
  247.     version_print();
  248.  
  249. /*  test_printf(); */
  250. //  test_ping();
  251. //  test_async_ipc();
  252. //  test_advanced_ipc();
  253. //  test_connection_ipc();
  254. //  test_hangup();
  255.     test_slam();
  256.  
  257. //  if ((tid = thread_create(utest, NULL, "utest") != -1)) {
  258. //      printf("Created thread tid=%d\n", tid);
  259. //  }
  260.     return 0;
  261. }
  262.