Hi,

To validate spsem03 test case I created a new test case by modifying
spsem02. Below is the description of the new test case:

Task: TA01 having priority 36, TA02 having priority 34, TA03 having
priority 32.

Throughout the course following actions are performed:

TA01 acquires S0
TA02 acquires S1 and then S0
TA03 acquires S1

Timeline:

TA01  acquires S0 with priority 36.
TA01 spawns TA02 having priority 32.
TA02 takes over as it has higher priority than TA01.
TA02 acquires S1 with priority 34.
TA02 tries to acquire S0 but it is locked so promotes TA01 priority to 34.
TA01 gains control and now creates TA03 having 32.
TA03 takes over and tries to acquire S1. But it is acquired by TA02.
TA03 promotes TA02 priority to 32. But it observe that TA02 is also waiting
on mutex held by TA01.

*TA03 promotes TA01 priority to 32 as well. (Indirect reference case).*
TA01 get control. It releases S0 and now its priority becomes 36 so TA02
takes over,
TA02 acquires S0. TA02 releases S0 and S1. And its priority now becomes
34(real priority)
TA03 takes over. It acquires S1. Releases S1 and suspends self.
Now TA02 gets control. It also suspends self.
Now TA01 gets control and exits the test.

Following is the output:
*** BEGIN OF TEST SPSEM 4 ***
init: S0 created
init: S1 created
init: TA01 created with priority 36
init: TA02 created with priority 34
init: TA03 created with priority 32
TA01: started with priority 36
TA01: priority 36, holding S0  (acquires S0)
TA02: started with priority 34  (creates TA02)
TA02: priority 34, holding S1   (acquires S1)
TA01: priority 34, holding S0 and now creating TA03
TA03: started with priority 32
*TA01: priority 32 Releasing s0 (Priority of TA02 and TA01 got promoted to
32).*
TA02: priority 32, holding S1,S0
TA02: priority 32 before releasing S0
TA02: priority 32 after releasing S0
TA02: priority 32 before releasing S1
TA03: priority 32, holding S1
TA03: priority 32
TA03: suspending
TA02: priority 34 after releasing S1
TA02: suspending
TA01: priority 36
TA01: exiting
*** END OF TEST SPSEM 4 ***
[Inferior 1 (process 42000) exited normally]


So this is sufficient to prove that spsem03 test passes as we just modelled
it above.




Thanks,

Saurabh Gadia

On Thu, Aug 13, 2015 at 2:28 AM, Saurabh Gadia <ga...@usc.edu> wrote:

> Hi,
>
> I have implemented uniprocessor model of nested mutex problem in rtems.
> its still in basic form. I tried to multiplex it with the existing solution
> but was finding hard time. To push ahead, I decided to have separate
> functions for uniprocessor and SMP(kept default behavior) and with your
> review comments will know what to do. Following is the link for the git
> repo: https://github.com/saurabhgadia4/rtems/commits/master and its JPF
> branch:
> https://github.com/saurabhgadia4/lock-model/blob/uniproc-new1/rtems/Mutex.java
>
> I have also tested spsem01, 02, 03 test cases. Following are the links for
> the test case results which states output before solution and after
> applying the solution. I am still not getting whether my code is passing
> spsem03 test or not. How can I verify that?
>
> Test Case Link:
> https://drive.google.com/folderview?id=0B44HRKVuGCkFfnFDVmxqQzZZUzljNUg4YmVPZmEybEp2Q0NNclpvS2FvemZ4Tm5Xa19nemM&usp=sharing
>
> Thanks,
>
> Saurabh Gadia
>
/*
 * Copyright (c) 2013 Gedare Bloom.
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#include <rtems.h>

#include <stdio.h>
#include "tmacros.h"

/* configuration information */
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_MAXIMUM_TASKS 4
#define CONFIGURE_MAXIMUM_SEMAPHORES 2
#define CONFIGURE_INIT
#include <rtems/confdefs.h>

const char rtems_test_name[] = "SPSEM 2";

rtems_task Task01(rtems_task_argument ignored);
rtems_task Task02(rtems_task_argument ignored);
rtems_task Task03(rtems_task_argument ignored);
rtems_task Init(rtems_task_argument ignored);

static int getprio(void)
{
  rtems_status_code status;
  rtems_task_priority pri;

  status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &pri);
  directive_failed( status, "rtems_task_set_priority");
  return (int)pri;
}

rtems_id   Task_id[3];
rtems_name Task_name[3];

rtems_id   sem_id[2];
rtems_name sem_name[2];

rtems_task Init(rtems_task_argument ignored)
{
  rtems_status_code status;
  rtems_attribute sem_attr;

  TEST_BEGIN();

  sem_attr = RTEMS_INHERIT_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY;

  sem_name[0] = rtems_build_name( 'S','0',' ',' ');
  status = rtems_semaphore_create(
    sem_name[0],
    1,
    sem_attr,
    0,
    &sem_id[0]
  );
  directive_failed( status, "rtems_semaphore_create of S0");
  printf("init: S0 created\n");

  sem_name[1] = rtems_build_name( 'S','1',' ',' ');
  status = rtems_semaphore_create(
    sem_name[1],
    1,
    sem_attr,
    0,
    &sem_id[1]
  );
  directive_failed( status, "rtems_semaphore_create of S1");
  printf("init: S1 created\n");

  Task_name[0] = rtems_build_name( 'T','A','0','1');
  status = rtems_task_create(
    Task_name[0],
    36,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &Task_id[0]
  );
  directive_failed( status, "rtems_task_create of TA01");
  printf("init: TA01 created with priority 36\n");

  Task_name[1] = rtems_build_name( 'T','A','0','2');
  status = rtems_task_create(
    Task_name[1],
    34,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &Task_id[1]
  );
  directive_failed( status , "rtems_task_create of TA02\n");
  printf("init: TA02 created with priority 34\n");

  Task_name[2] = rtems_build_name( 'T','A','0','3');
  status = rtems_task_create(
    Task_name[2],
    32,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &Task_id[2]
  );
  directive_failed( status , "rtems_task_create of TA03\n");
  printf("init: TA03 created with priority 32\n");

  status = rtems_task_start( Task_id[0], Task01, 0);
  directive_failed( status, "rtems_task_start of TA01");

  status = rtems_task_delete( RTEMS_SELF);
  directive_failed( status, "rtems_task_delete of INIT");
}

/* Task01 starts with priority 36 */
rtems_task Task01(rtems_task_argument ignored)
{
  rtems_status_code status;
  printf("TA01: started with priority %d\n", getprio());

  status = rtems_semaphore_obtain( sem_id[0], RTEMS_WAIT, 0 );
  directive_failed( status, "rtems_semaphore_obtain of S0\n");
  printf("TA01: priority %d, holding S0\n", getprio());

  /* Start Task 2 (TA02) with priority 34. It will run immediately. */
  status = rtems_task_start( Task_id[1], Task02, 0);
  directive_failed( status, "rtems_task_start of TA02\n");

  /* Start Task 3 (TA03) with priority 32. It will run immediately. */
  printf("TA01: priority %d, holding S0 and now creating TA03\n", getprio());
  status = rtems_task_start( Task_id[2], Task03, 0);
  directive_failed( status, "rtems_task_start of TA03\n");
  
  printf("TA01: priority %d Releasing s0\n", getprio());
  status = rtems_semaphore_release(sem_id[0]);
  directive_failed( status, "rtems_semaphore_release of S0\n");
  printf("TA01: priority %d\n", getprio());

  printf("TA01: exiting\n");
  TEST_END();
  rtems_test_exit(0);
  
}

/* TA02 starts at Task02 with priority 34 */
rtems_task Task02(rtems_task_argument ignored)
{
  rtems_status_code status;

  printf("TA02: started with priority %d\n", getprio());

  /* Obtain S1, which should be held by TA01 by now */
  status = rtems_semaphore_obtain( sem_id[1], RTEMS_WAIT, 0 );
  directive_failed( status, " rtems_semaphore_obtain S1");
  printf("TA02: priority %d, holding S1\n", getprio());

  status = rtems_semaphore_obtain( sem_id[0], RTEMS_WAIT, 0 );
  directive_failed( status, " rtems_semaphore_obtain S1");
  printf("TA02: priority %d, holding S1,S0\n", getprio());

  printf("TA02: priority %d before releasing S0\n ", getprio());
  status = rtems_semaphore_release(sem_id[0]);
  directive_failed( status, "rtems_semaphore_release of S0\n");
  printf("TA02: priority %d after releasing S0\n ", getprio());

  printf("TA02: priority %d before releasing S1\n ", getprio());
  status = rtems_semaphore_release(sem_id[1]);
  directive_failed( status, "rtems_semaphore_release of S0\n");
  printf("TA02: priority %d after releasing S1\n", getprio());

  printf("TA02: suspending\n");
  status = rtems_task_suspend( RTEMS_SELF);
  directive_failed( status, "rtems_task_suspend TA02");
}

/* Task03 starts with priority 32 */
rtems_task Task03(rtems_task_argument ignored)
{
  rtems_status_code status;
  printf("TA03: started with priority %d\n", getprio());

  status = rtems_semaphore_obtain( sem_id[1], RTEMS_WAIT, 0 );
  directive_failed( status, "rtems_semaphore_obtain of S0\n");
  printf("TA03: priority %d, holding S1\n", getprio());

  status = rtems_semaphore_release(sem_id[1]);
  directive_failed( status, "rtems_semaphore_release of S0\n");
  printf("TA03: priority %d\n", getprio());

  printf("TA03: suspending\n");
  status = rtems_task_suspend( RTEMS_SELF);
  directive_failed( status, "rtems_task_suspend TA03");


}
_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to