source: rtems/testsuites/smptests/smpschedaffinity03/init.c @ 98c6d50

5
Last change on this file since 98c6d50 was 98c6d50, checked in by Chris Johns <chrisj@…>, on 10/19/17 at 05:39:16

testsuite: Use printk for all test output where possible.

  • Remove the printf support leaving the direct printk support configured with TESTS_USE_PRINTK and all other output goes via a buffered vsniprintf call to printk.
  • Control the test's single init for functions and global data with TEST_INIT and not CONFIGURE_INIT. They are now separate.

Updates #3170.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 2014.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10/*
11 * Test to walk the affinity of the init task across all the cores.
12 */
13
14#ifdef HAVE_CONFIG_H
15  #include "config.h"
16#endif
17
18#define TEST_INIT
19
20#include <rtems.h>
21
22#include "tmacros.h"
23
24const char rtems_test_name[] = "SMPSCHEDAFFINITY 3";
25
26#define NUM_CPUS   4
27#define TASK_COUNT NUM_CPUS
28
29static void test_delay(int ticks)
30{
31  rtems_interval start, stop;
32  start = rtems_clock_get_ticks_since_boot();
33  do {
34    stop = rtems_clock_get_ticks_since_boot();
35  } while ( (stop - start) < ticks );
36}
37
38static void test(void)
39{
40  rtems_status_code   sc;
41  rtems_id            id;
42  uint32_t            cpu_count;
43  int                 cpu;
44  int                 i;
45  cpu_set_t           cpuset;
46
47  /* Get the number of processors that we are using. */
48  cpu_count = rtems_get_processor_count();
49 
50  id = rtems_task_self();
51
52  /*
53   * The Init task comes up on the maximum core so start at
54   * that core and walk the affinity down to core 0.
55   */
56  for( i=cpu_count-1; i >= 0; i--) {
57   
58    /* Move the affinity to the current core - 1 */
59    CPU_ZERO(&cpuset);
60    CPU_SET(i, &cpuset);
61    printf("Set Affinity for cpu %d\n", i);
62    sc = rtems_task_set_affinity( id, sizeof(cpuset), &cpuset );
63    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
64
65    /* Wait 100 clock ticks */
66    test_delay(100);
67
68    /* Check the cpu the Init task is running on */
69    cpu = rtems_get_current_processor();
70    printf("On cpu %d\n", cpu);
71    rtems_test_assert(cpu == i);
72  }
73}
74
75static void Init(rtems_task_argument arg)
76{
77  TEST_BEGIN();
78
79  test();
80
81  TEST_END();
82  rtems_test_exit(0);
83}
84
85#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
86#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
87
88#define CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP
89
90#define CONFIGURE_MAXIMUM_PROCESSORS NUM_CPUS
91
92#define CONFIGURE_MAXIMUM_TASKS          TASK_COUNT
93
94#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
95
96  #define CONFIGURE_INIT_TASK_PRIORITY      8
97#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
98
99#define CONFIGURE_INIT
100
101#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.