Changeset 0719fc6 in rtems


Ignore:
Timestamp:
Oct 27, 2017, 7:04:54 AM (19 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
cf614ec
Parents:
8744498
git-author:
Sebastian Huber <sebastian.huber@…> (10/27/17 07:04:54)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/28/17 11:13:09)
Message:

sptests/spscheduler01: Test POSIX set/get affinity

Location:
testsuites/sptests/spscheduler01
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • testsuites/sptests/spscheduler01/init.c

    r8744498 r0719fc6  
    1818
    1919#define TEST_INIT
     20#define _GNU_SOURCE
    2021
    2122#include <rtems.h>
    2223#include <rtems/libcsupport.h>
    2324
     25#include <errno.h>
    2426#include <limits.h>
     27#include <string.h>
     28#include <pthread.h>
    2529
    2630#include "tmacros.h"
     
    3236#define RED rtems_build_name('r', 'e', 'd', ' ')
    3337
     38#define BIG_NUM_CPUS (2 * CHAR_BIT * sizeof(cpu_set_t))
     39
    3440static const rtems_id invalid_id = 1;
    3541
     
    3743
    3844static rtems_id sema_id;
     45
     46static void assert_eno(rtems_status_code sc, int eno)
     47{
     48  switch (sc) {
     49    case RTEMS_SUCCESSFUL:
     50      rtems_test_assert(eno == 0);
     51      break;
     52    case RTEMS_INVALID_ADDRESS:
     53      rtems_test_assert(eno == EFAULT);
     54      break;
     55    case RTEMS_INVALID_ID:
     56      rtems_test_assert(eno == ESRCH);
     57      break;
     58    case RTEMS_INVALID_NUMBER:
     59      rtems_test_assert(eno == EINVAL);
     60      break;
     61    default:
     62      rtems_test_assert(0);
     63  }
     64}
     65
     66static rtems_status_code task_get_affinity(
     67  rtems_id id,
     68  size_t cpusetsize,
     69  cpu_set_t *cpuset
     70)
     71{
     72  rtems_status_code sc;
     73  int eno;
     74  cpu_set_t *cpusetbig;
     75
     76  sc = rtems_task_get_affinity(id, cpusetsize, cpuset);
     77
     78  if (cpuset != NULL) {
     79    cpusetbig = CPU_ALLOC(BIG_NUM_CPUS);
     80    rtems_test_assert(cpusetbig != NULL);
     81
     82    memcpy(cpusetbig, cpuset, cpusetsize);
     83  } else {
     84    cpusetbig = NULL;
     85  }
     86
     87  eno = pthread_getaffinity_np(id, cpusetsize, cpusetbig);
     88
     89  if (cpuset != NULL) {
     90    rtems_test_assert(CPU_EQUAL_S(cpusetsize, cpusetbig, cpuset));
     91    CPU_FREE(cpusetbig);
     92  }
     93
     94  assert_eno(sc, eno);
     95
     96  return sc;
     97}
     98
     99static rtems_status_code task_set_affinity(
     100  rtems_id id,
     101  size_t cpusetsize,
     102  const cpu_set_t *cpuset
     103)
     104{
     105  rtems_status_code sc;
     106  int eno;
     107
     108  sc = rtems_task_set_affinity(id, cpusetsize, cpuset);
     109  eno = pthread_setaffinity_np(id, cpusetsize, cpuset);
     110  assert_eno(sc, eno);
     111
     112  return sc;
     113}
    39114
    40115static void test_task_get_set_affinity(void)
     
    46121  cpu_set_t cpusetall;
    47122  cpu_set_t cpuset;
    48   size_t big = 2 * CHAR_BIT * sizeof(cpu_set_t);
    49   size_t cpusetbigsize = CPU_ALLOC_SIZE(big);
     123  size_t cpusetbigsize = CPU_ALLOC_SIZE(BIG_NUM_CPUS);
    50124  cpu_set_t *cpusetbigone;
    51125  cpu_set_t *cpusetbig;
     
    66140  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    67141
    68   sc = rtems_task_get_affinity(RTEMS_SELF, sizeof(cpuset), NULL);
    69   rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
    70 
    71   sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(cpuset), NULL);
    72   rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
    73 
    74   sc = rtems_task_get_affinity(RTEMS_SELF, 0, &cpuset);
     142  sc = task_get_affinity(RTEMS_SELF, sizeof(cpuset), NULL);
     143  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
     144
     145  sc = task_set_affinity(RTEMS_SELF, sizeof(cpuset), NULL);
     146  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
     147
     148  sc = task_get_affinity(RTEMS_SELF, 0, &cpuset);
    75149  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
    76150
    77   sc = rtems_task_set_affinity(RTEMS_SELF, 0, &cpuset);
     151  sc = task_set_affinity(RTEMS_SELF, 0, &cpuset);
    78152  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
    79153
    80   sc = rtems_task_get_affinity(invalid_id, sizeof(cpuset), &cpuset);
    81   rtems_test_assert(sc == RTEMS_INVALID_ID);
    82 
    83   sc = rtems_task_set_affinity(invalid_id, sizeof(cpuset), &cpuset);
    84   rtems_test_assert(sc == RTEMS_INVALID_ID);
    85 
    86   sc = rtems_task_get_affinity(RTEMS_SELF, sizeof(cpuset), &cpuset);
     154  sc = task_get_affinity(invalid_id, sizeof(cpuset), &cpuset);
     155  rtems_test_assert(sc == RTEMS_INVALID_ID);
     156
     157  sc = task_set_affinity(invalid_id, sizeof(cpuset), &cpuset);
     158  rtems_test_assert(sc == RTEMS_INVALID_ID);
     159
     160  sc = task_get_affinity(RTEMS_SELF, sizeof(cpuset), &cpuset);
    87161  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    88162
    89163  rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
    90164
    91   sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(cpuset), &cpuset);
    92   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    93 
    94   sc = rtems_task_set_affinity(self_id, sizeof(cpuset), &cpuset);
    95   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    96 
    97   sc = rtems_task_set_affinity(task_id, sizeof(cpuset), &cpuset);
    98   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    99 
    100   sc = rtems_task_get_affinity(task_id, sizeof(cpuset), &cpuset);
     165  sc = task_set_affinity(RTEMS_SELF, sizeof(cpuset), &cpuset);
     166  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     167
     168  sc = task_set_affinity(self_id, sizeof(cpuset), &cpuset);
     169  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     170
     171  sc = task_set_affinity(task_id, sizeof(cpuset), &cpuset);
     172  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     173
     174  sc = task_get_affinity(task_id, sizeof(cpuset), &cpuset);
    101175  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    102176
    103177  rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
    104178
    105   sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(cpusetall), &cpusetall);
    106   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    107 
    108   sc = rtems_task_get_affinity(task_id, sizeof(cpuset), &cpuset);
     179  sc = task_set_affinity(RTEMS_SELF, sizeof(cpusetall), &cpusetall);
     180  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     181
     182  sc = task_get_affinity(task_id, sizeof(cpuset), &cpuset);
    109183  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    110184
    111185  rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
    112186
    113   cpusetbigone = CPU_ALLOC(big);
     187  cpusetbigone = CPU_ALLOC(BIG_NUM_CPUS);
    114188  rtems_test_assert(cpusetbigone != NULL);
    115189
    116   cpusetbig = CPU_ALLOC(big);
     190  cpusetbig = CPU_ALLOC(BIG_NUM_CPUS);
    117191  rtems_test_assert(cpusetbig != NULL);
    118192
     
    120194  CPU_SET_S(0, cpusetbigsize, cpusetbigone);
    121195
    122   sc = rtems_task_get_affinity(task_id, cpusetbigsize, cpusetbig);
     196  sc = task_get_affinity(task_id, cpusetbigsize, cpusetbig);
    123197  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    124198
    125199  rtems_test_assert(CPU_EQUAL_S(cpusetbigsize, cpusetbig, cpusetbigone));
    126200
    127   sc = rtems_task_set_affinity(task_id, cpusetbigsize, cpusetbig);
     201  sc = task_set_affinity(task_id, cpusetbigsize, cpusetbig);
    128202  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    129203
     
    409483  cpu_set_t cpusetone;
    410484  cpu_set_t cpuset;
    411   size_t big = 2 * CHAR_BIT * sizeof(cpu_set_t);
    412   size_t cpusetbigsize = CPU_ALLOC_SIZE(big);
     485  size_t cpusetbigsize = CPU_ALLOC_SIZE(BIG_NUM_CPUS);
    413486  cpu_set_t *cpusetbigone;
    414487  cpu_set_t *cpusetbig;
     
    434507  rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
    435508
    436   cpusetbigone = CPU_ALLOC(big);
     509  cpusetbigone = CPU_ALLOC(BIG_NUM_CPUS);
    437510  rtems_test_assert(cpusetbigone != NULL);
    438511
    439   cpusetbig = CPU_ALLOC(big);
     512  cpusetbig = CPU_ALLOC(BIG_NUM_CPUS);
    440513  rtems_test_assert(cpusetbig != NULL);
    441514
Note: See TracChangeset for help on using the changeset viewer.