source: rtems/testsuites/sptests/spcpuset01/test.c @ b06dbb26

5
Last change on this file since b06dbb26 was b06dbb26, checked in by Sebastian Huber <sebastian.huber@…>, on 06/07/17 at 06:47:47

spcpuset01: Update due to CPU_NAND_S() changes

Close #3032.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1#if HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5/*
6 *  Fully exercise CPU_SET() methods
7 */
8#include <rtems.h>
9#include <stdlib.h>
10#include <stdio.h>
11#include <assert.h>
12#include "system.h"
13
14void test_cpu_and_case_1(size_t cpu1, size_t cpu2);
15void test_cpu_nand_case_1(size_t cpu1, size_t cpu2);
16void test_cpu_or_case_1(size_t cpu1, size_t cpu2);
17void test_cpu_xor_case_1(size_t cpu1, size_t cpu2);
18static void test_logic01_setup(size_t cpu1, size_t cpu2);
19
20/*
21 *  Make these global so they can always be referenced. Optimization tends
22 *  to make them hard to see when on the stack.
23 */
24cpu_set_t set1;
25cpu_set_t set2;
26cpu_set_t set3;
27
28
29void test_cpu_and_case_1(size_t cpu1, size_t cpu2)
30{
31  size_t i;
32
33  /*  AND set1 and set2 */
34  DPRINT( "Exercise CPU_AND with bits %zd,%zd\n", cpu1, cpu2 );
35  CPU_AND(&set3, &set1, &set2);
36
37  /* test if all bits clear except cpu1 */
38  for (i=0 ; i<CPU_SETSIZE ; i++) {
39    if (i== cpu1)
40      rtems_test_assert( CPU_ISSET(i, &set3) == 1 );
41    else
42      rtems_test_assert( CPU_ISSET(i, &set3) == 0 );
43  }
44
45}
46
47void test_cpu_nand_case_1(size_t cpu1, size_t cpu2)
48{
49  size_t i;
50
51   /*  NAND set1 and set2 */
52  DPRINT( "Exercise CPU_NAND with bits %zd,%zd\n", cpu1, cpu2 );
53  CPU_NAND(&set3, &set1, &set2);
54
55  /* test if all bits clear except cpu1 */
56  for (i=0 ; i<CPU_SETSIZE ; i++) {
57    if (i== cpu2)
58      rtems_test_assert( CPU_ISSET(i, &set3) == 1 );
59    else
60      rtems_test_assert( CPU_ISSET(i, &set3) == 0 );
61  }
62}
63
64void test_cpu_or_case_1(size_t cpu1, size_t cpu2)
65{
66  size_t i;
67
68  /*  OR set1 and set2 */
69  DPRINT( "Exercise CPU_OR with bits %zd,%zd\n", cpu1, cpu2 );
70  CPU_OR(&set3, &set1, &set2);
71
72  /* test if all bits clear except cpu1 */
73  for (i=0 ; i<CPU_SETSIZE ; i++) {
74    if ((i== cpu1) || (i==cpu2))
75      rtems_test_assert( CPU_ISSET(i, &set3) == 1 );
76    else
77      rtems_test_assert( CPU_ISSET(i, &set3) == 0 );
78  }
79}
80
81void test_cpu_xor_case_1(size_t cpu1, size_t cpu2)
82{
83  size_t i;
84
85  /*  XOR set1 and set2 */
86  DPRINT( "Exercise CPU_XOR with bits %zd,%zd\n", cpu1, cpu2 );
87  CPU_XOR(&set3, &set1, &set2);
88
89  /* test if all bits clear except cpu1 */
90  for (i=0 ; i<CPU_SETSIZE ; i++) {
91    if (i==cpu2)
92      rtems_test_assert( CPU_ISSET(i, &set3) == 1 );
93    else
94      rtems_test_assert( CPU_ISSET(i, &set3) == 0 );
95  }
96}
97
98static void test_logic01_setup(size_t cpu1, size_t cpu2)
99{
100  /*
101   * Clear all bits except cpu1 in both sets and cpu2 in set1 only
102   */
103  CPU_ZERO(&set1);
104  CPU_SET(cpu1, &set1);
105  CPU_SET(cpu2, &set1);
106  CPU_COPY(&set1, &set2);
107  CPU_CLR(cpu2, &set2);
108}
109
110void cpuset_logic_test()
111{
112  size_t    i,j;
113
114  for (i=0 ; i<CPU_SETSIZE ; i++) {
115    for (j=0 ; j<CPU_SETSIZE ; j++) {
116      if (i != j){
117        test_logic01_setup(i,j);
118        test_cpu_and_case_1(i, j);
119        test_cpu_nand_case_1(i, j);
120        test_cpu_or_case_1(i, j);
121        test_cpu_xor_case_1(i, j);
122      }
123    }
124  }
125}
Note: See TracBrowser for help on using the repository browser.