Skip to content

Commit c2b5aa7

Browse files
jones-drewavpatel
authored andcommitted
KVM: arm64: selftests: Remove print_reg's dependency on vcpu_config
print_reg() and its helpers only use the vcpu_config pointer for config_name(). So just pass the config name in instead, which is used as a prefix in asserts. print_reg() can now be compiled independently of config_name(). Signed-off-by: Andrew Jones <[email protected]> Signed-off-by: Haibo Xu <[email protected]> Signed-off-by: Anup Patel <[email protected]>
1 parent 2653860 commit c2b5aa7

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

tools/testing/selftests/kvm/aarch64/get-reg-list.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static bool check_supported_feat_reg(struct kvm_vcpu *vcpu, __u64 reg)
176176
#define CORE_SPSR_XX_NR_WORDS 2
177177
#define CORE_FPREGS_XX_NR_WORDS 4
178178

179-
static const char *core_id_to_str(struct vcpu_config *c, __u64 id)
179+
static const char *core_id_to_str(const char *prefix, __u64 id)
180180
{
181181
__u64 core_off = id & ~REG_MASK, idx;
182182

@@ -187,7 +187,7 @@ static const char *core_id_to_str(struct vcpu_config *c, __u64 id)
187187
case KVM_REG_ARM_CORE_REG(regs.regs[0]) ...
188188
KVM_REG_ARM_CORE_REG(regs.regs[30]):
189189
idx = (core_off - KVM_REG_ARM_CORE_REG(regs.regs[0])) / CORE_REGS_XX_NR_WORDS;
190-
TEST_ASSERT(idx < 31, "%s: Unexpected regs.regs index: %lld", config_name(c), idx);
190+
TEST_ASSERT(idx < 31, "%s: Unexpected regs.regs index: %lld", prefix, idx);
191191
return strdup_printf("KVM_REG_ARM_CORE_REG(regs.regs[%lld])", idx);
192192
case KVM_REG_ARM_CORE_REG(regs.sp):
193193
return "KVM_REG_ARM_CORE_REG(regs.sp)";
@@ -202,24 +202,24 @@ static const char *core_id_to_str(struct vcpu_config *c, __u64 id)
202202
case KVM_REG_ARM_CORE_REG(spsr[0]) ...
203203
KVM_REG_ARM_CORE_REG(spsr[KVM_NR_SPSR - 1]):
204204
idx = (core_off - KVM_REG_ARM_CORE_REG(spsr[0])) / CORE_SPSR_XX_NR_WORDS;
205-
TEST_ASSERT(idx < KVM_NR_SPSR, "%s: Unexpected spsr index: %lld", config_name(c), idx);
205+
TEST_ASSERT(idx < KVM_NR_SPSR, "%s: Unexpected spsr index: %lld", prefix, idx);
206206
return strdup_printf("KVM_REG_ARM_CORE_REG(spsr[%lld])", idx);
207207
case KVM_REG_ARM_CORE_REG(fp_regs.vregs[0]) ...
208208
KVM_REG_ARM_CORE_REG(fp_regs.vregs[31]):
209209
idx = (core_off - KVM_REG_ARM_CORE_REG(fp_regs.vregs[0])) / CORE_FPREGS_XX_NR_WORDS;
210-
TEST_ASSERT(idx < 32, "%s: Unexpected fp_regs.vregs index: %lld", config_name(c), idx);
210+
TEST_ASSERT(idx < 32, "%s: Unexpected fp_regs.vregs index: %lld", prefix, idx);
211211
return strdup_printf("KVM_REG_ARM_CORE_REG(fp_regs.vregs[%lld])", idx);
212212
case KVM_REG_ARM_CORE_REG(fp_regs.fpsr):
213213
return "KVM_REG_ARM_CORE_REG(fp_regs.fpsr)";
214214
case KVM_REG_ARM_CORE_REG(fp_regs.fpcr):
215215
return "KVM_REG_ARM_CORE_REG(fp_regs.fpcr)";
216216
}
217217

218-
TEST_FAIL("%s: Unknown core reg id: 0x%llx", config_name(c), id);
218+
TEST_FAIL("%s: Unknown core reg id: 0x%llx", prefix, id);
219219
return NULL;
220220
}
221221

222-
static const char *sve_id_to_str(struct vcpu_config *c, __u64 id)
222+
static const char *sve_id_to_str(const char *prefix, __u64 id)
223223
{
224224
__u64 sve_off, n, i;
225225

@@ -229,37 +229,37 @@ static const char *sve_id_to_str(struct vcpu_config *c, __u64 id)
229229
sve_off = id & ~(REG_MASK | ((1ULL << 5) - 1));
230230
i = id & (KVM_ARM64_SVE_MAX_SLICES - 1);
231231

232-
TEST_ASSERT(i == 0, "%s: Currently we don't expect slice > 0, reg id 0x%llx", config_name(c), id);
232+
TEST_ASSERT(i == 0, "%s: Currently we don't expect slice > 0, reg id 0x%llx", prefix, id);
233233

234234
switch (sve_off) {
235235
case KVM_REG_ARM64_SVE_ZREG_BASE ...
236236
KVM_REG_ARM64_SVE_ZREG_BASE + (1ULL << 5) * KVM_ARM64_SVE_NUM_ZREGS - 1:
237237
n = (id >> 5) & (KVM_ARM64_SVE_NUM_ZREGS - 1);
238238
TEST_ASSERT(id == KVM_REG_ARM64_SVE_ZREG(n, 0),
239-
"%s: Unexpected bits set in SVE ZREG id: 0x%llx", config_name(c), id);
239+
"%s: Unexpected bits set in SVE ZREG id: 0x%llx", prefix, id);
240240
return strdup_printf("KVM_REG_ARM64_SVE_ZREG(%lld, 0)", n);
241241
case KVM_REG_ARM64_SVE_PREG_BASE ...
242242
KVM_REG_ARM64_SVE_PREG_BASE + (1ULL << 5) * KVM_ARM64_SVE_NUM_PREGS - 1:
243243
n = (id >> 5) & (KVM_ARM64_SVE_NUM_PREGS - 1);
244244
TEST_ASSERT(id == KVM_REG_ARM64_SVE_PREG(n, 0),
245-
"%s: Unexpected bits set in SVE PREG id: 0x%llx", config_name(c), id);
245+
"%s: Unexpected bits set in SVE PREG id: 0x%llx", prefix, id);
246246
return strdup_printf("KVM_REG_ARM64_SVE_PREG(%lld, 0)", n);
247247
case KVM_REG_ARM64_SVE_FFR_BASE:
248248
TEST_ASSERT(id == KVM_REG_ARM64_SVE_FFR(0),
249-
"%s: Unexpected bits set in SVE FFR id: 0x%llx", config_name(c), id);
249+
"%s: Unexpected bits set in SVE FFR id: 0x%llx", prefix, id);
250250
return "KVM_REG_ARM64_SVE_FFR(0)";
251251
}
252252

253253
return NULL;
254254
}
255255

256-
static void print_reg(struct vcpu_config *c, __u64 id)
256+
static void print_reg(const char *prefix, __u64 id)
257257
{
258258
unsigned op0, op1, crn, crm, op2;
259259
const char *reg_size = NULL;
260260

261261
TEST_ASSERT((id & KVM_REG_ARCH_MASK) == KVM_REG_ARM64,
262-
"%s: KVM_REG_ARM64 missing in reg id: 0x%llx", config_name(c), id);
262+
"%s: KVM_REG_ARM64 missing in reg id: 0x%llx", prefix, id);
263263

264264
switch (id & KVM_REG_SIZE_MASK) {
265265
case KVM_REG_SIZE_U8:
@@ -291,16 +291,16 @@ static void print_reg(struct vcpu_config *c, __u64 id)
291291
break;
292292
default:
293293
TEST_FAIL("%s: Unexpected reg size: 0x%llx in reg id: 0x%llx",
294-
config_name(c), (id & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT, id);
294+
prefix, (id & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT, id);
295295
}
296296

297297
switch (id & KVM_REG_ARM_COPROC_MASK) {
298298
case KVM_REG_ARM_CORE:
299-
printf("\tKVM_REG_ARM64 | %s | KVM_REG_ARM_CORE | %s,\n", reg_size, core_id_to_str(c, id));
299+
printf("\tKVM_REG_ARM64 | %s | KVM_REG_ARM_CORE | %s,\n", reg_size, core_id_to_str(prefix, id));
300300
break;
301301
case KVM_REG_ARM_DEMUX:
302302
TEST_ASSERT(!(id & ~(REG_MASK | KVM_REG_ARM_DEMUX_ID_MASK | KVM_REG_ARM_DEMUX_VAL_MASK)),
303-
"%s: Unexpected bits set in DEMUX reg id: 0x%llx", config_name(c), id);
303+
"%s: Unexpected bits set in DEMUX reg id: 0x%llx", prefix, id);
304304
printf("\tKVM_REG_ARM64 | %s | KVM_REG_ARM_DEMUX | KVM_REG_ARM_DEMUX_ID_CCSIDR | %lld,\n",
305305
reg_size, id & KVM_REG_ARM_DEMUX_VAL_MASK);
306306
break;
@@ -311,25 +311,25 @@ static void print_reg(struct vcpu_config *c, __u64 id)
311311
crm = (id & KVM_REG_ARM64_SYSREG_CRM_MASK) >> KVM_REG_ARM64_SYSREG_CRM_SHIFT;
312312
op2 = (id & KVM_REG_ARM64_SYSREG_OP2_MASK) >> KVM_REG_ARM64_SYSREG_OP2_SHIFT;
313313
TEST_ASSERT(id == ARM64_SYS_REG(op0, op1, crn, crm, op2),
314-
"%s: Unexpected bits set in SYSREG reg id: 0x%llx", config_name(c), id);
314+
"%s: Unexpected bits set in SYSREG reg id: 0x%llx", prefix, id);
315315
printf("\tARM64_SYS_REG(%d, %d, %d, %d, %d),\n", op0, op1, crn, crm, op2);
316316
break;
317317
case KVM_REG_ARM_FW:
318318
TEST_ASSERT(id == KVM_REG_ARM_FW_REG(id & 0xffff),
319-
"%s: Unexpected bits set in FW reg id: 0x%llx", config_name(c), id);
319+
"%s: Unexpected bits set in FW reg id: 0x%llx", prefix, id);
320320
printf("\tKVM_REG_ARM_FW_REG(%lld),\n", id & 0xffff);
321321
break;
322322
case KVM_REG_ARM_FW_FEAT_BMAP:
323323
TEST_ASSERT(id == KVM_REG_ARM_FW_FEAT_BMAP_REG(id & 0xffff),
324-
"%s: Unexpected bits set in the bitmap feature FW reg id: 0x%llx", config_name(c), id);
324+
"%s: Unexpected bits set in the bitmap feature FW reg id: 0x%llx", prefix, id);
325325
printf("\tKVM_REG_ARM_FW_FEAT_BMAP_REG(%lld),\n", id & 0xffff);
326326
break;
327327
case KVM_REG_ARM64_SVE:
328-
printf("\t%s,\n", sve_id_to_str(c, id));
328+
printf("\t%s,\n", sve_id_to_str(prefix, id));
329329
break;
330330
default:
331331
TEST_FAIL("%s: Unexpected coproc type: 0x%llx in reg id: 0x%llx",
332-
config_name(c), (id & KVM_REG_ARM_COPROC_MASK) >> KVM_REG_ARM_COPROC_SHIFT, id);
332+
prefix, (id & KVM_REG_ARM_COPROC_MASK) >> KVM_REG_ARM_COPROC_SHIFT, id);
333333
}
334334
}
335335

@@ -458,7 +458,7 @@ static void run_test(struct vcpu_config *c)
458458
__u64 id = reg_list->reg[i];
459459
if ((print_list && !filter_reg(id)) ||
460460
(print_filtered && filter_reg(id)))
461-
print_reg(c, id);
461+
print_reg(config_name(c), id);
462462
}
463463
putchar('\n');
464464
return;
@@ -486,7 +486,7 @@ static void run_test(struct vcpu_config *c)
486486
ret = __vcpu_get_reg(vcpu, reg_list->reg[i], &addr);
487487
if (ret) {
488488
printf("%s: Failed to get ", config_name(c));
489-
print_reg(c, reg.id);
489+
print_reg(config_name(c), reg.id);
490490
putchar('\n');
491491
++failed_get;
492492
}
@@ -498,7 +498,7 @@ static void run_test(struct vcpu_config *c)
498498
ret = __vcpu_ioctl(vcpu, KVM_SET_ONE_REG, &reg);
499499
if (ret != -1 || errno != EPERM) {
500500
printf("%s: Failed to reject (ret=%d, errno=%d) ", config_name(c), ret, errno);
501-
print_reg(c, reg.id);
501+
print_reg(config_name(c), reg.id);
502502
putchar('\n');
503503
++failed_reject;
504504
}
@@ -510,7 +510,7 @@ static void run_test(struct vcpu_config *c)
510510
ret = __vcpu_ioctl(vcpu, KVM_SET_ONE_REG, &reg);
511511
if (ret) {
512512
printf("%s: Failed to set ", config_name(c));
513-
print_reg(c, reg.id);
513+
print_reg(config_name(c), reg.id);
514514
putchar('\n');
515515
++failed_set;
516516
}
@@ -548,15 +548,15 @@ static void run_test(struct vcpu_config *c)
548548
"Consider adding them to the blessed reg "
549549
"list with the following lines:\n\n", config_name(c), new_regs);
550550
for_each_new_reg(i)
551-
print_reg(c, reg_list->reg[i]);
551+
print_reg(config_name(c), reg_list->reg[i]);
552552
putchar('\n');
553553
}
554554

555555
if (missing_regs) {
556556
printf("\n%s: There are %d missing registers.\n"
557557
"The following lines are missing registers:\n\n", config_name(c), missing_regs);
558558
for_each_missing_reg(i)
559-
print_reg(c, blessed_reg[i]);
559+
print_reg(config_name(c), blessed_reg[i]);
560560
putchar('\n');
561561
}
562562

0 commit comments

Comments
 (0)