Changeset 37b0ab6 in rtems-libbsd


Ignore:
Timestamp:
Oct 25, 2013, 1:37:06 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, afaeccc05a556f6aa25ba044a7e49d6aa634a59e, freebsd-9.3, master
Children:
24732b6
Parents:
5ddce1f
git-author:
Sebastian Huber <sebastian.huber@…> (10/25/13 13:37:06)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/31/13 12:18:50)
Message:

loopback01: Wait for client termination

File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuite/loopback01/test_main.c

    r5ddce1f r37b0ab6  
    2828#include <rtems.h>
    2929
     30static rtems_id masterTask;
     31
    3032/*
    3133 * Thread-safe output routines
     
    4244}
    4345#define printf printSafe
     46
     47static void
     48setSelfPrio(rtems_task_priority prio)
     49{
     50        rtems_status_code sc;
     51
     52        sc = rtems_task_set_priority(RTEMS_SELF, prio, &prio);
     53        assert(sc == RTEMS_SUCCESSFUL);
     54}
     55
     56static rtems_event_set argToClientEvent(rtems_task_argument arg)
     57{
     58    return 1U << arg;
     59}
     60
     61static void
     62sendClientEventToMasterTask(rtems_task_argument arg)
     63{
     64    rtems_status_code sc;
     65
     66    sc = rtems_event_send(masterTask, argToClientEvent(arg));
     67    assert(sc == RTEMS_SUCCESSFUL);
     68}
     69
     70static void
     71waitForClientEvents(rtems_event_set which)
     72{
     73    rtems_status_code sc;
     74    rtems_event_set events;
     75
     76    sc = rtems_event_receive(
     77        which,
     78        RTEMS_EVENT_ALL | RTEMS_WAIT,
     79        RTEMS_NO_TIMEOUT,
     80        &events
     81    );
     82    assert(sc == RTEMS_SUCCESSFUL);
     83}
    4484
    4585/*
     
    81121        if (i == 0)
    82122            break;
    83         rtems_task_wake_after(20); /* Simulate some processing delay */
    84123        i = sprintf(reply, "Server received %d (%s)", i, msg);
    85124        if ((i = write(s, reply, i+1)) < 0) {
     
    162201        goto close;
    163202    }
    164     rtems_task_wake_after(20); /* Simulate client delay */
    165203    i = sprintf(cbuf, "Hi there, server (%d).", arg);
    166204    i++;    /* Send the '\0', too */
     
    175213    }
    176214    printf("Read %d from server: %.*s\n", i, i, cbuf);
    177     rtems_task_wake_after(20); /* Simulate client delay */
    178215  close:
    179216    printf("Client closing connection.\n");
     
    188225{
    189226    clientWorker(arg);
     227    sendClientEventToMasterTask(arg);
    190228    printf("Client task terminating.\n");
    191229    rtems_task_delete( RTEMS_SELF );
     
    210248  };
    211249
     250  masterTask = rtems_task_self();
     251
     252  setSelfPrio(RTEMS_MAXIMUM_PRIORITY - 1);
     253
    212254  sc = rtems_semaphore_create(
    213255    rtems_build_name('P','m','t','x'),
     
    237279
    238280  printf("\nStart server.\n");
    239   spawnTask(serverTask, 150, 0);
     281  spawnTask(serverTask, 110, 0);
    240282
    241283  printf("\nTry running client with server present.\n");
    242284  spawnTask(clientTask, 120, 1);
    243   rtems_task_wake_after(500);
     285  waitForClientEvents(argToClientEvent(1));
    244286
    245287  printf("\nTry running two clients.\n");
    246288  spawnTask(clientTask, 120, 2);
    247289  spawnTask(clientTask, 120, 3);
    248   rtems_task_wake_after(500);
     290  waitForClientEvents(argToClientEvent(2) | argToClientEvent(3));
    249291
    250292  printf("\nTry running three clients.\n");
     
    252294  spawnTask(clientTask, 120, 5);
    253295  spawnTask(clientTask, 120, 6);
    254 
    255   rtems_task_wake_after(500);
     296  waitForClientEvents(argToClientEvent(4) | argToClientEvent(5) | argToClientEvent(6));
     297
    256298  puts( "*** END OF " TEST_NAME " TEST ***" );
    257299  exit( 0 );
Note: See TracChangeset for help on using the changeset viewer.