1111
1212#define NEXT_PROGRAM "./vstate_exec_nolibc"
1313
14- int test_and_compare_child (long provided , long expected , int inherit )
14+ int test_and_compare_child (long provided , long expected , int inherit , int xtheadvector )
1515{
1616 int rc ;
1717
@@ -21,7 +21,7 @@ int test_and_compare_child(long provided, long expected, int inherit)
2121 provided , rc );
2222 return -1 ;
2323 }
24- rc = launch_test (NEXT_PROGRAM , inherit );
24+ rc = launch_test (NEXT_PROGRAM , inherit , xtheadvector );
2525 if (rc != expected ) {
2626 printf ("Test failed, check %d != %ld\n" , rc , expected );
2727 return -2 ;
@@ -36,7 +36,7 @@ TEST(get_control_no_v)
3636{
3737 long rc ;
3838
39- if (is_vector_supported ())
39+ if (is_vector_supported () || is_xtheadvector_supported () )
4040 SKIP (return , "Test expects vector to be not supported" );
4141
4242 rc = prctl (PR_RISCV_V_GET_CONTROL );
@@ -50,7 +50,7 @@ TEST(set_control_no_v)
5050{
5151 long rc ;
5252
53- if (is_vector_supported ())
53+ if (is_vector_supported () || is_xtheadvector_supported () )
5454 SKIP (return , "Test expects vector to be not supported" );
5555
5656 rc = prctl (PR_RISCV_V_SET_CONTROL , PR_RISCV_V_VSTATE_CTRL_ON );
@@ -65,20 +65,20 @@ TEST(vstate_on_current)
6565 long flag ;
6666 long rc ;
6767
68- if (!is_vector_supported ())
68+ if (!is_vector_supported () && ! is_xtheadvector_supported () )
6969 SKIP (return , "Vector not supported" );
7070
7171 flag = PR_RISCV_V_VSTATE_CTRL_ON ;
7272 rc = prctl (PR_RISCV_V_SET_CONTROL , flag );
73- EXPECT_EQ (0 , rc ) TH_LOG ("Enabling V for current should always success " );
73+ EXPECT_EQ (0 , rc ) TH_LOG ("Enabling V for current should always succeed " );
7474}
7575
7676TEST (vstate_off_eperm )
7777{
7878 long flag ;
7979 long rc ;
8080
81- if (!is_vector_supported ())
81+ if (!is_vector_supported () && ! is_xtheadvector_supported () )
8282 SKIP (return , "Vector not supported" );
8383
8484 flag = PR_RISCV_V_VSTATE_CTRL_OFF ;
@@ -92,97 +92,124 @@ TEST(vstate_off_eperm)
9292TEST (vstate_on_no_nesting )
9393{
9494 long flag ;
95+ int xtheadvector = 0 ;
9596
96- if (!is_vector_supported ())
97- SKIP (return , "Vector not supported" );
97+ if (!is_vector_supported ()) {
98+ if (is_xtheadvector_supported ())
99+ xtheadvector = 1 ;
100+ else
101+ SKIP (return , "Vector not supported" );
102+ }
98103
99104 /* Turn on next's vector explicitly and test */
100105 flag = PR_RISCV_V_VSTATE_CTRL_ON << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT ;
101106
102- EXPECT_EQ (0 ,
103- test_and_compare_child (flag , PR_RISCV_V_VSTATE_CTRL_ON , 0 ));
107+ EXPECT_EQ (0 , test_and_compare_child (flag , PR_RISCV_V_VSTATE_CTRL_ON , 0 , xtheadvector ));
104108}
105109
106110TEST (vstate_off_nesting )
107111{
108112 long flag ;
113+ int xtheadvector = 0 ;
109114
110- if (!is_vector_supported ())
111- SKIP (return , "Vector not supported" );
115+ if (!is_vector_supported ()) {
116+ if (is_xtheadvector_supported ())
117+ xtheadvector = 1 ;
118+ else
119+ SKIP (return , "Vector not supported" );
120+ }
112121
113122 /* Turn off next's vector explicitly and test */
114123 flag = PR_RISCV_V_VSTATE_CTRL_OFF << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT ;
115124
116- EXPECT_EQ (0 ,
117- test_and_compare_child (flag , PR_RISCV_V_VSTATE_CTRL_OFF , 1 ));
125+ EXPECT_EQ (0 , test_and_compare_child (flag , PR_RISCV_V_VSTATE_CTRL_OFF , 1 , xtheadvector ));
118126}
119127
120128TEST (vstate_on_inherit_no_nesting )
121129{
122130 long flag , expected ;
131+ int xtheadvector = 0 ;
123132
124- if (!is_vector_supported ())
125- SKIP (return , "Vector not supported" );
133+ if (!is_vector_supported ()) {
134+ if (is_xtheadvector_supported ())
135+ xtheadvector = 1 ;
136+ else
137+ SKIP (return , "Vector not supported" );
138+ }
126139
127140 /* Turn on next's vector explicitly and test no inherit */
128141 flag = PR_RISCV_V_VSTATE_CTRL_ON << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT ;
129142 flag |= PR_RISCV_V_VSTATE_CTRL_INHERIT ;
130143 expected = flag | PR_RISCV_V_VSTATE_CTRL_ON ;
131144
132- EXPECT_EQ (0 , test_and_compare_child (flag , expected , 0 ));
145+ EXPECT_EQ (0 , test_and_compare_child (flag , expected , 0 , xtheadvector ));
133146}
134147
135148TEST (vstate_on_inherit )
136149{
137150 long flag , expected ;
151+ int xtheadvector = 0 ;
138152
139- if (!is_vector_supported ())
140- SKIP (return , "Vector not supported" );
153+ if (!is_vector_supported ()) {
154+ if (is_xtheadvector_supported ())
155+ xtheadvector = 1 ;
156+ else
157+ SKIP (return , "Vector not supported" );
158+ }
141159
142160 /* Turn on next's vector explicitly and test inherit */
143161 flag = PR_RISCV_V_VSTATE_CTRL_ON << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT ;
144162 flag |= PR_RISCV_V_VSTATE_CTRL_INHERIT ;
145163 expected = flag | PR_RISCV_V_VSTATE_CTRL_ON ;
146164
147- EXPECT_EQ (0 , test_and_compare_child (flag , expected , 1 ));
165+ EXPECT_EQ (0 , test_and_compare_child (flag , expected , 1 , xtheadvector ));
148166}
149167
150168TEST (vstate_off_inherit_no_nesting )
151169{
152170 long flag , expected ;
171+ int xtheadvector = 0 ;
153172
154- if (!is_vector_supported ())
155- SKIP (return , "Vector not supported" );
156-
173+ if (!is_vector_supported ()) {
174+ if (is_xtheadvector_supported ())
175+ xtheadvector = 1 ;
176+ else
177+ SKIP (return , "Vector not supported" );
178+ }
157179 /* Turn off next's vector explicitly and test no inherit */
158180 flag = PR_RISCV_V_VSTATE_CTRL_OFF << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT ;
159181 flag |= PR_RISCV_V_VSTATE_CTRL_INHERIT ;
160182 expected = flag | PR_RISCV_V_VSTATE_CTRL_OFF ;
161183
162- EXPECT_EQ (0 , test_and_compare_child (flag , expected , 0 ));
184+ EXPECT_EQ (0 , test_and_compare_child (flag , expected , 0 , xtheadvector ));
163185}
164186
165187TEST (vstate_off_inherit )
166188{
167189 long flag , expected ;
190+ int xtheadvector = 0 ;
168191
169- if (!is_vector_supported ())
170- SKIP (return , "Vector not supported" );
192+ if (!is_vector_supported ()) {
193+ if (is_xtheadvector_supported ())
194+ xtheadvector = 1 ;
195+ else
196+ SKIP (return , "Vector not supported" );
197+ }
171198
172199 /* Turn off next's vector explicitly and test inherit */
173200 flag = PR_RISCV_V_VSTATE_CTRL_OFF << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT ;
174201 flag |= PR_RISCV_V_VSTATE_CTRL_INHERIT ;
175202 expected = flag | PR_RISCV_V_VSTATE_CTRL_OFF ;
176203
177- EXPECT_EQ (0 , test_and_compare_child (flag , expected , 1 ));
204+ EXPECT_EQ (0 , test_and_compare_child (flag , expected , 1 , xtheadvector ));
178205}
179206
180207/* arguments should fail with EINVAL */
181208TEST (inval_set_control_1 )
182209{
183210 int rc ;
184211
185- if (!is_vector_supported ())
212+ if (!is_vector_supported () && ! is_xtheadvector_supported () )
186213 SKIP (return , "Vector not supported" );
187214
188215 rc = prctl (PR_RISCV_V_SET_CONTROL , 0xff0 );
@@ -195,7 +222,7 @@ TEST(inval_set_control_2)
195222{
196223 int rc ;
197224
198- if (!is_vector_supported ())
225+ if (!is_vector_supported () && ! is_xtheadvector_supported () )
199226 SKIP (return , "Vector not supported" );
200227
201228 rc = prctl (PR_RISCV_V_SET_CONTROL , 0x3 );
@@ -208,7 +235,7 @@ TEST(inval_set_control_3)
208235{
209236 int rc ;
210237
211- if (!is_vector_supported ())
238+ if (!is_vector_supported () && ! is_xtheadvector_supported () )
212239 SKIP (return , "Vector not supported" );
213240
214241 rc = prctl (PR_RISCV_V_SET_CONTROL , 0xc );
0 commit comments