On Tue, Oct 04, 2022, Vitaly Kuznetsov wrote: > +static void *vcpu_thread(void *arg) > +{ > + struct kvm_vcpu *vcpu = (struct kvm_vcpu *)arg; > + struct ucall uc; > + int old; > + int r; > + unsigned int exit_reason; > + > + r = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old); > + TEST_ASSERT(r == 0, > + "pthread_setcanceltype failed on vcpu_id=%u with errno=%d", > + vcpu->id, r); If possible, TEST_ASSERT(!r, pthread_setcanceltype() failed on vcpu_id=%u, vcpu->id); > + > + vcpu_run(vcpu); > + exit_reason = vcpu->run->exit_reason; > + > + TEST_ASSERT(exit_reason == KVM_EXIT_IO, > + "vCPU %u exited with unexpected exit reason %u-%s, expected KVM_EXIT_IO", > + vcpu->id, exit_reason, exit_reason_str(exit_reason)); > + > + if (get_ucall(vcpu, &uc) == UCALL_ABORT) { > + TEST_ASSERT(false, > + "vCPU %u exited with error: %s.\n", > + vcpu->id, (const char *)uc.args[0]); REPORT_GUEST_ASSERT_N? > + } > + > + return NULL; > +} > + > +static void cancel_join_vcpu_thread(pthread_t thread, struct kvm_vcpu *vcpu) > +{ > + void *retval; > + int r; > + > + r = pthread_cancel(thread); > + TEST_ASSERT(r == 0, > + "pthread_cancel on vcpu_id=%d failed with errno=%d", > + vcpu->id, r); > + > + r = pthread_join(thread, &retval); > + TEST_ASSERT(r == 0, > + "pthread_join on vcpu_id=%d failed with errno=%d", > + vcpu->id, r); Same assert/errno comment here. > + while (true) { > + r = _vcpu_run(vcpu[0]); > + exit_reason = vcpu[0]->run->exit_reason; > + > + TEST_ASSERT(!r, "vcpu_run failed: %d", r); Just use vcpu_run(). > + TEST_ASSERT(exit_reason == KVM_EXIT_IO, > + "unexpected exit reason: %u (%s)", > + exit_reason, exit_reason_str(exit_reason)); > + > + switch (get_ucall(vcpu[0], &uc)) { > + case UCALL_SYNC: > + TEST_ASSERT(uc.args[1] == stage, > + "Unexpected stage: %ld (%d expected)\n", > + uc.args[1], stage); > + break; > + case UCALL_ABORT: > + REPORT_GUEST_ASSERT(uc); > + /* NOT REACHED */ > + case UCALL_DONE: > + return 0; > + } > + > + stage++; > + } > + > + cancel_join_vcpu_thread(threads[0], vcpu[1]); > + cancel_join_vcpu_thread(threads[1], vcpu[2]); > + kvm_vm_free(vm); > + > + return 0; > +} > -- > 2.37.3 >