Changeset f2b3d3e in mainline for uspace/app/tester/ipc/starve.c


Ignore:
Timestamp:
2012-05-04T10:57:48Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
35a35651
Parents:
90924df (diff), d21e935c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/tester/ipc/starve.c

    r90924df rf2b3d3e  
    11/*
    2  * Copyright (c) 2009 Lukas Mejdrech
     2 * Copyright (c) 2012 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libc
    30  * @{
    31  */
     29#include <stdio.h>
     30#include <stdlib.h>
     31#include <sys/time.h>
     32#include <io/console.h>
     33#include <async.h>
     34#include "../tester.h"
    3235
    33 /** @file
    34  * Generic module functions.
    35  *
    36  * @todo MAKE IT POSSIBLE TO REMOVE THIS FILE VIA EITHER REPLACING PART OF ITS
    37  * FUNCTIONALITY OR VIA INTEGRATING ITS FUNCTIONALITY MORE TIGHTLY WITH THE REST
    38  * OF THE SYSTEM.
    39  */
     36#define DURATION_SECS      30
    4037
    41 #ifndef LIBC_MODULES_H_
    42 #define LIBC_MODULES_H_
     38const char *test_starve_ipc(void)
     39{
     40        const char *err = NULL;
     41        console_ctrl_t *console = console_init(stdin, stdout);
     42        if (console == NULL) {
     43                return "Failed to init connection with console.";
     44        }
     45       
     46        struct timeval start;
     47        if (gettimeofday(&start, NULL) != 0) {
     48                err = "Failed getting the time";
     49                goto leave;
     50        }
     51       
     52        TPRINTF("Intensive computation shall be imagined (for %ds)...\n", DURATION_SECS);
     53        TPRINTF("Press a key to terminate prematurely...\n");
     54        while (true) {
     55                struct timeval now;
     56                if (gettimeofday(&now, NULL) != 0) {
     57                        err = "Failed getting the time";
     58                        goto leave;
     59                }
     60               
     61                if (tv_sub(&now, &start) >= DURATION_SECS * 1000000L)
     62                        break;
     63               
     64                kbd_event_t ev;
     65                suseconds_t timeout = 0;
     66                bool has_event = console_get_kbd_event_timeout(console, &ev, &timeout);
     67                if (has_event && (ev.type == KEY_PRESS)) {
     68                        TPRINTF("Key %d pressed, terminating.\n", ev.key);
     69                        break;
     70                }
     71        }
    4372
    44 #include <async.h>
    45 #include <ipc/services.h>
    46 #include <sys/time.h>
     73        // FIXME - unless a key was pressed, the answer leaked as no one
     74        // will wait for it.
     75        // We cannot use async_forget() directly, though. Something like
     76        // console_forget_pending_kbd_event() shall come here.
    4777
    48 /** Connect to module function type definition.
    49  *
    50  * @return Session to the service.
    51  *
    52  */
    53 typedef async_sess_t *connect_module_t(services_t);
     78        TPRINTF("Terminating...\n");
    5479
    55 extern void answer_call(ipc_callid_t, int, ipc_call_t *, size_t);
    56 extern async_sess_t *bind_service(services_t, sysarg_t, sysarg_t, sysarg_t,
    57     async_client_conn_t);
    58 extern async_sess_t *connect_to_service(services_t);
    59 extern int data_reply(void *, size_t);
    60 extern void refresh_answer(ipc_call_t *, size_t *);
     80leave:
     81        console_done(console);
    6182
    62 #endif
    63 
    64 /** @}
    65  */
     83        return err;
     84}
Note: See TracChangeset for help on using the changeset viewer.