... sync
authorVolker Birk <vb@pep.foundation>
Thu, 30 Aug 2018 02:26:16 +0200
branchsync
changeset 2910e1a7270acdcf
parent 2909 13da9af3bd4f
child 2911 61e0cb26f440
...
sync/gen_statemachine.ysl2
test/src/engine_tests/SyncTests.cc
     1.1 --- a/sync/gen_statemachine.ysl2	Thu Aug 30 01:41:28 2018 +0200
     1.2 +++ b/sync/gen_statemachine.ysl2	Thu Aug 30 02:26:16 2018 +0200
     1.3 @@ -53,6 +53,8 @@
     1.4  
     1.5          «@name»_event_t *new_«@name»_event(«@name»_PR fsm, int event, «@name»_t *msg);
     1.6  
     1.7 +        #define «yml:ucase(@name)»_TIMEOUT_EVENT new_«@name»_event(«@name»_PR_NOTHING, 0, NULL);
     1.8 +
     1.9  
    1.10          // free_«@name»_event() - free memory occupied by event
    1.11          //
    1.12 @@ -80,10 +82,6 @@
    1.13  
    1.14          «@name»_event_t *new_«@name»_event(«@name»_PR fsm, int event, «@name»_t *msg)
    1.15          {
    1.16 -            assert(fsm > 0 && (event >= 0 |`> |` msg));
    1.17 -            if (!(fsm > 0 && (event >= 0 |`> |` msg)))
    1.18 -                return NULL;
    1.19 -
    1.20              «@name»_event_t *ev = («@name»_event_t *) calloc(1, sizeof(«@name»_event_t));
    1.21              assert(ev);
    1.22              if (!ev)
    1.23 @@ -218,11 +216,19 @@
    1.24                      int event
    1.25                  )
    1.26              {
    1.27 -                assert(session && fsm);
    1.28 -                if (!(session && fsm))
    1.29 +                assert(session);
    1.30 +                if (!session)
    1.31                      return PEP_ILLEGAL_VALUE;
    1.32  
    1.33                  switch (fsm) {
    1.34 +                    case None:
    1.35 +                        if (!event) {
    1.36 +                            // timeout occured
    1.37 +                        `` for "fsm" |>>>> «../@name»_driver(session, «../@name»_PR_«yml:lcase(@name)», None);
    1.38 +                            return PEP_STATUS_OK;
    1.39 +                        }
    1.40 +                        return PEP_ILLEGAL_VALUE;
    1.41 +
    1.42                      `` apply "fsm", mode=reset_state_machine;
    1.43                      default:
    1.44                          return PEP_ILLEGAL_VALUE;
    1.45 @@ -474,7 +480,7 @@
    1.46                  «@name»_PR fsm = (int) None;
    1.47                  int event = None;
    1.48  
    1.49 -                if (ev->event < Extra) {
    1.50 +                if (ev->event > None && ev->event < Extra) {
    1.51                      status = update_«@name»_state(session, ev->msg, &fsm, &event);
    1.52                      if (status)
    1.53                          goto the_end;
     2.1 --- a/test/src/engine_tests/SyncTests.cc	Thu Aug 30 01:41:28 2018 +0200
     2.2 +++ b/test/src/engine_tests/SyncTests.cc	Thu Aug 30 02:26:16 2018 +0200
     2.3 @@ -52,11 +52,25 @@
     2.4  Sync_event_t *Sync_Adapter::retrieve_next_sync_event(void *management, time_t threshold)
     2.5  {
     2.6      auto adapter = static_cast< Sync_Adapter *>(management);
     2.7 +    time_t started = time(nullptr);
     2.8 +    bool timeout = false;
     2.9  
    2.10      while (adapter->q.empty()) {
    2.11 +        int i = 0;
    2.12 +        ++i;
    2.13 +        if (i > 10) {
    2.14 +            if (time(nullptr) > started + threshold) {
    2.15 +                timeout = true;
    2.16 +                break;
    2.17 +            }
    2.18 +            i = 0;
    2.19 +        }
    2.20          nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
    2.21      }
    2.22  
    2.23 +    if (timeout)
    2.24 +        return SYNC_TIMEOUT_EVENT;
    2.25 +
    2.26      Sync_event_t *ev = adapter->q.pop_front();
    2.27      if (ev) {
    2.28          switch (ev->fsm) {