Changeset b42e148 in rtems


Ignore:
Timestamp:
06/24/14 07:53:11 (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
89f8eab5
Parents:
152ad7d1
Message:

smptests/smpmigration02: PR2183: Add test case

File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/smptests/smpmigration02/init.c

    r152ad7d1 rb42e148  
    1919#include <rtems.h>
    2020#include <rtems/libcsupport.h>
     21#include <rtems/score/objectimpl.h>
     22#include <rtems/score/threadimpl.h>
    2123
    2224#include "tmacros.h"
     
    4547static test_context test_instance;
    4648
    47 static void task(rtems_task_argument arg)
     49static void migration_task(rtems_task_argument arg)
    4850{
    4951  test_context *ctx = &test_instance;
     
    6466}
    6567
    66 static void test(void)
    67 {
    68   test_context *ctx = &test_instance;
     68static void test_migrations(test_context *ctx)
     69{
    6970  rtems_status_code sc;
    7071  uint32_t cpu_count = rtems_get_processor_count();
    71   uint32_t cpu_index;
    7272  uint32_t task_count = cpu_count + 1;
    7373  uint32_t task_index;
    74 
    75   for (cpu_index = 0; cpu_index < cpu_count; ++cpu_index) {
    76     sc = rtems_scheduler_ident(cpu_index, &ctx->scheduler_ids[cpu_index]);
    77     rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    78   }
    7974
    8075  for (task_index = 0; task_index < task_count; ++task_index) {
     
    9489    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    9590
    96     sc = rtems_task_start(task_id, task, task_index);
     91    sc = rtems_task_start(task_id, migration_task, task_index);
    9792    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
    9893
     
    115110}
    116111
     112static void busy_loop_task(rtems_task_argument arg)
     113{
     114  while (true) {
     115    /* Do nothing */
     116  }
     117}
     118
     119static Thread_Control *get_thread_by_id(rtems_id task_id)
     120{
     121  Objects_Locations location;
     122  Thread_Control *thread;
     123
     124  thread = _Thread_Get(task_id, &location);
     125  rtems_test_assert(location == OBJECTS_LOCAL);
     126  _Thread_Enable_dispatch();
     127
     128  return thread;
     129}
     130
     131static void test_double_migration(test_context *ctx)
     132{
     133  uint32_t cpu_count = rtems_get_processor_count();
     134
     135  if (cpu_count >= 2) {
     136    rtems_status_code sc;
     137    rtems_id task_id;
     138    rtems_id scheduler_id;
     139    uint32_t cpu_self_index = 0;
     140    uint32_t cpu_other_index = 1;
     141    Per_CPU_Control *cpu_self = _Per_CPU_Get_by_index(cpu_self_index);
     142    Per_CPU_Control *cpu_other = _Per_CPU_Get_by_index(cpu_other_index);
     143    Thread_Control *self;
     144    Thread_Control *other;
     145
     146    sc = rtems_task_get_scheduler(RTEMS_SELF, &scheduler_id);
     147    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     148
     149    rtems_test_assert(scheduler_id == ctx->scheduler_ids[cpu_self_index]);
     150
     151    sc = rtems_task_create(
     152      rtems_build_name('T', 'A', 'S', 'K'),
     153      2,
     154      RTEMS_MINIMUM_STACK_SIZE,
     155      RTEMS_DEFAULT_MODES,
     156      RTEMS_DEFAULT_ATTRIBUTES,
     157      &task_id
     158    );
     159    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     160
     161    other = get_thread_by_id(task_id);
     162
     163    sc = rtems_task_set_scheduler(
     164      task_id,
     165      ctx->scheduler_ids[cpu_other_index]
     166    );
     167    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     168
     169    sc = rtems_task_start(task_id, busy_loop_task, 0);
     170    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     171
     172    while (!_Thread_Is_executing_on_a_processor(other)) {
     173      /* Wait */
     174    }
     175
     176    _Thread_Disable_dispatch();
     177
     178    self = _Thread_Executing;
     179
     180    rtems_test_assert(cpu_self->executing == self);
     181    rtems_test_assert(cpu_self->heir == self);
     182    rtems_test_assert(!cpu_self->dispatch_necessary);
     183
     184    rtems_test_assert(cpu_other->executing == other);
     185    rtems_test_assert(cpu_other->heir == other);
     186    rtems_test_assert(!cpu_other->dispatch_necessary);
     187
     188    sc = rtems_task_set_scheduler(
     189      RTEMS_SELF,
     190      ctx->scheduler_ids[cpu_other_index]
     191    );
     192    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     193
     194    rtems_test_assert(cpu_self->executing == self);
     195    rtems_test_assert(cpu_self->heir != self);
     196    rtems_test_assert(cpu_self->dispatch_necessary);
     197
     198    while (_Thread_Is_executing_on_a_processor(other)) {
     199      /* Wait */
     200    }
     201
     202    rtems_test_assert(cpu_other->executing == self);
     203    rtems_test_assert(cpu_other->heir == self);
     204    rtems_test_assert(!cpu_other->dispatch_necessary);
     205
     206    sc = rtems_task_set_scheduler(
     207      RTEMS_SELF,
     208      ctx->scheduler_ids[cpu_self_index]
     209    );
     210    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     211
     212    rtems_test_assert(cpu_self->executing == self);
     213    rtems_test_assert(cpu_self->heir == self);
     214    rtems_test_assert(cpu_self->dispatch_necessary);
     215
     216    rtems_test_assert(cpu_other->heir == other);
     217
     218    _Thread_Enable_dispatch();
     219
     220    while (!_Thread_Is_executing_on_a_processor(other)) {
     221      /* Wait */
     222    }
     223
     224    sc = rtems_task_delete(task_id);
     225    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     226  }
     227}
     228
     229static void init_scheduler_ids(test_context *ctx)
     230{
     231  rtems_status_code sc;
     232  uint32_t cpu_count = rtems_get_processor_count();
     233  uint32_t cpu_index;
     234
     235  for (cpu_index = 0; cpu_index < cpu_count; ++cpu_index) {
     236    sc = rtems_scheduler_ident(cpu_index, &ctx->scheduler_ids[cpu_index]);
     237    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     238  }
     239}
     240
    117241static void Init(rtems_task_argument arg)
    118242{
     243  test_context *ctx = &test_instance;
    119244  rtems_resource_snapshot snapshot;
    120245
     
    123248  rtems_resource_snapshot_take(&snapshot);
    124249
    125   test();
     250  init_scheduler_ids(ctx);
     251  test_double_migration(ctx);
     252  test_migrations(ctx);
    126253
    127254  rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
Note: See TracChangeset for help on using the changeset viewer.