Subversion Repositories HelenOS-historic

Rev

Rev 1089 | Rev 1111 | 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.     printf("Pinging\n");
  116.     retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result);
  117.     printf("Retval: %d - received: %P\n", retval, result);
  118. }
  119.  
  120. static void got_answer(void *private, int retval, ipc_call_t *data)
  121. {
  122.     printf("Retval: %d...%s...%zX, %zX\n", retval, private,
  123.            IPC_GET_ARG1(*data), IPC_GET_ARG2(*data));
  124. }
  125. static void test_async_ipc(void)
  126. {
  127.     ipc_call_t data;
  128.     int i;
  129.  
  130.     printf("Sending ping\n");
  131.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  132.              "Pong1", got_answer);
  133.     ipc_call_async_2(PHONE_NS, NS_PING, 2, 0xbeefbee4,
  134.              "Pong2", got_answer);
  135.     ipc_call_async_2(PHONE_NS, NS_PING, 3, 0xbeefbee4,
  136.              "Pong3", got_answer);
  137.     ipc_call_async_2(PHONE_NS, NS_PING, 4, 0xbeefbee4,
  138.              "Pong4", got_answer);
  139.     ipc_call_async_2(PHONE_NS, NS_PING, 5, 0xbeefbee4,
  140.              "Pong5", got_answer);
  141.     ipc_call_async_2(PHONE_NS, NS_PING, 6, 0xbeefbee4,
  142.              "Pong6", got_answer);
  143.     printf("Waiting forever...\n");
  144.     for (i=0; i<100;i++)
  145.         printf(".");
  146.     printf("\n");
  147.     ipc_wait_for_call(&data, NULL);
  148.     printf("Received call???\n");
  149. }
  150.  
  151.  
  152. static void got_answer_2(void *private, int retval, ipc_call_t *data)
  153. {
  154.     printf("Pong\n");
  155. }
  156. static void test_advanced_ipc(void)
  157. {
  158.     int res;
  159.     ipcarg_t phonead;
  160.     ipc_callid_t callid;
  161.     ipc_call_t data;
  162.     int i;
  163.  
  164.     printf("Asking 0 to connect to me...\n");
  165.     res = ipc_connect_to_me(0, 1, 2, &phonead);
  166.     printf("Result: %d - phonead: %llu\n", res, phonead);
  167.     for (i=0; i < 100; i++) {
  168.         printf("----------------\n");
  169.         ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov",
  170.                    got_answer_2);
  171.         callid = ipc_wait_for_call(&data, NULL);
  172.         printf("Received ping\n");
  173.         ipc_answer(callid, 0, 0, 0);
  174.     }
  175. //  callid = ipc_wait_for_call(&data, NULL);
  176. }
  177.  
  178. static void test_connection_ipc(void)
  179. {
  180.     int res;
  181.     ipcarg_t result;
  182.     int phoneid;
  183.  
  184.     printf("Starting connect...\n");
  185.     res = ipc_connect_me_to(PHONE_NS, 10, 20);
  186.     printf("Connected: %d\n", res);
  187.     printf("pinging.\n");
  188.     res = ipc_call_sync(res, NS_PING, 0xbeef,&result);
  189.     printf("Retval: %d - received: %X\n", res, result);
  190.    
  191. }
  192.  
  193. static void test_hangup(void)
  194. {
  195.     int phoneid;
  196.     ipc_call_t data;
  197.     ipc_callid_t callid;
  198.     int i;
  199.  
  200.     printf("Starting connect...\n");
  201.     phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
  202.     printf("Phoneid: %d, pinging\n", phoneid);
  203.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  204.              "Pong1", got_answer);
  205.     printf("Hangin up\n");
  206.     ipc_hangup(phoneid);
  207.     printf("Connecting\n");
  208.     phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
  209.     printf("Newphid: %d\n", phoneid);
  210.     for (i=0; i < 1000; i++) {
  211.         if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
  212.             printf("callid: %d\n");
  213.     }
  214.     printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20));
  215. }
  216.  
  217. static void test_slam(void)
  218. {
  219.     int i;
  220.     ipc_call_t data;
  221.     ipc_callid_t callid;
  222.  
  223.     printf("ping");
  224.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  225.              "Pong1", got_answer);
  226.     printf("slam");
  227.     ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2,
  228.              "Hang", got_answer);
  229.     printf("ping2\n");
  230.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  231.              "Ping2", got_answer);
  232.    
  233.     for (i=0; i < 1000; i++) {
  234.         if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
  235.             printf("callid: %d\n");
  236.     }
  237.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  238.              "Pong1", got_answer);
  239.     printf("Closing file\n");
  240.     ipc_hangup(PHONE_NS);
  241.     ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
  242.              "Pong1", got_answer);
  243.     ipc_wait_for_call(&data, 0);
  244. }
  245.  
  246. int main(int argc, char *argv[])
  247. {
  248.     int tid;
  249.     version_print();
  250.  
  251. /*  test_printf(); */
  252. //  test_ping();
  253. //  test_async_ipc();
  254. //  test_advanced_ipc();
  255. //  test_connection_ipc();
  256. //  test_hangup();
  257. //  test_slam();
  258.  
  259.     if ((tid = thread_create(utest, NULL, "utest") != -1)) {
  260.         printf("Created thread tid=%d\n", tid);
  261.     }
  262.     return 0;
  263. }
  264.