Hi Cyril:

For a long time.
I wanna know what do you think about this patch.

Can you give me some comments? or commit this?

Thanks a lot
-Wanlong Gao

> v1->v2: remove the __linux__ to make the code common.(Note followed)
> 
> This case create NB_CPU-1 children processes to verify that the
> child process which we asume to preempt the parent will run on
> the same CPU with its parent.
> 
> But, it cann't make thing goes well always, some time it goes to
> what you don't like.
> 
> So, just mask the CPU use set_affinity(), make sure parent and
> child can always run on the same CPU.
> 
> [Note: this patch moves the non portable affinity code into common
>       header that needs to be ported to your favorite UNIX]
> 
> Signed-off-by: Wanlong Gao <[email protected]>
> ---
>  .../conformance/interfaces/sched_setparam/9-1.c    |   75 
> +++++---------------
>  1 files changed, 18 insertions(+), 57 deletions(-)
> 
> diff --git 
> a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/9-1.c 
> b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/9-1.c
> index 349999c..401c9f5 100644
> --- 
> a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/9-1.c
> +++ 
> b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/9-1.c
> @@ -31,6 +31,7 @@
>   *      not, the test fail.
>   */
>  
> +#define _GNU_SOURCE
>  #include <sched.h>
>  #include <stdio.h>
>  #include <signal.h>
> @@ -40,6 +41,7 @@
>  #include <stdlib.h>
>  #include <errno.h>
>  #include "posixtest.h"
> +#include "affinity.h"
>  
>  #ifdef BSD
>  # include <sys/types.h>
> @@ -81,23 +83,14 @@ static int get_ncpu(void)
>       return ncpu;
>  }
>  
> -static void child_process(void)
> +static void test_process(void)
>  {
> -     struct sched_param param;
> -
> -     param.sched_priority = sched_get_priority_max(SCHED_FIFO);
> -     if (sched_setparam(getpid(), &param) != 0) {
> -             perror("An error occurs when calling sched_setparam()");
> +     int rc;
> +     rc = set_affinity(0);
> +     if (rc < 0) {
> +             perror("An error occurs when calling set_affinity()");
>               return;
>       }
> -
> -     /* to avoid blocking */
> -     alarm(2);
> -     while (1);
> -}
> -
> -static void test_process(void)
> -{
>       /* to avoid blocking */
>       alarm(2);
>  
> @@ -107,29 +100,17 @@ static void test_process(void)
>       }
>  }
>  
> -static void kill_children(int *child_pid)
> -{
> -     int i;
> -
> -     for (i = 0; i < nb_cpu; i++)
> -             kill(child_pid[i], SIGTERM);
> -}
> -
>  int main(void)
>  {
> -     int *child_pid, oldcount, newcount, shm_id, i, j;
> +     int child_pid, oldcount, newcount, shm_id, i, j, rc = 0;
>       struct sched_param param;
>       key_t key;
> -
> -     nb_cpu = get_ncpu();
> -
> -     if (nb_cpu == -1) {
> -             printf("Can not get the number of CPUs of your machines.\n");
> +     rc = set_affinity(0);
> +     if (rc < 0) {
> +             perror("An error occurs when calling set_affinity()");
>               return PTS_UNRESOLVED;
>       }
>  
> -     child_pid = malloc(nb_cpu * sizeof(int));
> -
>       key = ftok("conformance/interfaces/sched_setparam/9-1.c",1234);
>       shm_id = shmget(key, sizeof(int), IPC_CREAT|0600);
>       if (shm_id < 0) {
> @@ -155,31 +136,11 @@ int main(void)
>               return PTS_UNRESOLVED;
>       }
>  
> -     for (i = 0; i < (nb_cpu - 1); i++) {
> -             child_pid[i] = fork();
> -             if (child_pid[i] == -1) {
> -                     perror("An error occurs when calling fork()");
> -                     for (j = 0; j < i; j++) {
> -                             kill(child_pid[j], SIGTERM);
> -                     }
> -                     return PTS_UNRESOLVED;
> -             } else if (child_pid[i] == 0) {
> -
> -                     child_process();
> -
> -                     printf("This code should not be executed.\n");
> -                     return PTS_UNRESOLVED;
> -             }
> -     }
> -
> -     child_pid[i] = fork();
> -     if (child_pid[i] == -1) {
> +     child_pid = fork();
> +     if (child_pid == -1) {
>               perror("An error occurs when calling fork()");
> -             for (j = 0; j < i; j++) {
> -                     kill(child_pid[j], SIGTERM);
> -             }
>               return PTS_UNRESOLVED;
> -     } else if (child_pid[i] == 0) {
> +     } else if (child_pid == 0) {
>  
>               test_process();
>  
> @@ -193,20 +154,20 @@ int main(void)
>                               sched_get_priority_max(SCHED_FIFO)) / 2;
>  
>       oldcount = *shmptr;
> -     if (sched_setparam(child_pid[i], &param) != 0) {
> +     if (sched_setparam(child_pid, &param) != 0) {
>               perror("An error occurs when calling sched_setparam()");
> -             kill_children(child_pid);
> +             kill(child_pid, SIGTERM);
>               return PTS_UNRESOLVED;
>       }
>       newcount = *shmptr;
>  
>       if (newcount == oldcount) {
>               printf("The target process does not preempt the calling 
> process\n");
> -             kill_children(child_pid);
> +             kill(child_pid, SIGTERM);
>               return PTS_FAIL;
>       }
>  
>       printf("Test PASSED\n");
> -     kill_children(child_pid);
> +     kill(child_pid, SIGTERM);
>       return PTS_PASS;
>  }



------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to