kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] kvm: selftests: Add TEST_FAIL macro
@ 2020-03-05 17:25 Wainer dos Santos Moschetta
  2020-03-05 17:25 ` [RFC PATCH 1/1] " Wainer dos Santos Moschetta
  2020-03-05 17:28 ` [RFC PATCH 0/1] " Paolo Bonzini
  0 siblings, 2 replies; 3+ messages in thread
From: Wainer dos Santos Moschetta @ 2020-03-05 17:25 UTC (permalink / raw)
  To: kvm, pbonzini
  Cc: shuah, tglx, thuth, sean.j.christopherson, linux-kselftest, linux-kernel

The following patch's commit message is self-explanatory about this proposal.

I adjusted to use TEST_FAIL only a few source files, in reality it will
need to change all the ones listed below. I will proceed with the
adjustments if this new macro idea is accepted.

$ find . -type f -name "*.c" -exec grep -l "TEST_ASSERT(false" {} \;
./lib/kvm_util.c
./lib/io.c
./lib/x86_64/processor.c
./lib/aarch64/ucall.c
./lib/aarch64/processor.c
./x86_64/vmx_dirty_log_test.c
./x86_64/state_test.c
./x86_64/vmx_tsc_adjust_test.c
./x86_64/svm_vmcall_test.c
./x86_64/evmcs_test.c
./x86_64/vmx_close_while_nested_test.c

Wainer dos Santos Moschetta (1):
  kvm: selftests: Add TEST_FAIL macro

 tools/testing/selftests/kvm/dirty_log_test.c             | 7 +++----
 tools/testing/selftests/kvm/include/test_util.h          | 3 +++
 tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)

-- 
2.17.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFC PATCH 1/1] kvm: selftests: Add TEST_FAIL macro
  2020-03-05 17:25 [RFC PATCH 0/1] kvm: selftests: Add TEST_FAIL macro Wainer dos Santos Moschetta
@ 2020-03-05 17:25 ` Wainer dos Santos Moschetta
  2020-03-05 17:28 ` [RFC PATCH 0/1] " Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Wainer dos Santos Moschetta @ 2020-03-05 17:25 UTC (permalink / raw)
  To: kvm, pbonzini
  Cc: shuah, tglx, thuth, sean.j.christopherson, linux-kselftest, linux-kernel

Some tests/utilities use the TEST_ASSERT(false, ...) pattern to
indicate a failure and stop execution.

This change introduces the TEST_FAIL macro which is a wrap around
TEST_ASSERT(false, ...) and so provides a direct alternative for
failing a test.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 tools/testing/selftests/kvm/dirty_log_test.c             | 7 +++----
 tools/testing/selftests/kvm/include/test_util.h          | 3 +++
 tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
index 5614222a6628..137c1cfec2cc 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -166,10 +166,9 @@ static void *vcpu_worker(void *data)
 			pages_count += TEST_PAGES_PER_LOOP;
 			generate_random_array(guest_array, TEST_PAGES_PER_LOOP);
 		} else {
-			TEST_ASSERT(false,
-				    "Invalid guest sync status: "
-				    "exit_reason=%s\n",
-				    exit_reason_str(run->exit_reason));
+			TEST_FAIL("Invalid guest sync status: "
+				  "exit_reason=%s\n",
+				  exit_reason_str(run->exit_reason));
 		}
 	}
 
diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
index a41db6fb7e24..336b16500b0f 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -39,4 +39,7 @@ void test_assert(bool exp, const char *exp_str,
 		    #a, #b, #a, (unsigned long) __a, #b, (unsigned long) __b); \
 } while (0)
 
+#define TEST_FAIL(fmt, ...) \
+        TEST_ASSERT(false, fmt, ##__VA_ARGS__)
+
 #endif /* SELFTEST_KVM_TEST_UTIL_H */
diff --git a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c b/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c
index 63cc9c3f5ab6..501d6217b9ed 100644
--- a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c
+++ b/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c
@@ -101,12 +101,12 @@ int main(int argc, char *argv[])
 			vcpu_sregs_set(vm, VCPU_ID, &sregs);
 			break;
 		case UCALL_ABORT:
-			TEST_ASSERT(false, "Guest CR4 bit (OSXSAVE) unsynchronized with CPUID bit.");
+			TEST_FAIL("Guest CR4 bit (OSXSAVE) unsynchronized with CPUID bit.");
 			break;
 		case UCALL_DONE:
 			goto done;
 		default:
-			TEST_ASSERT(false, "Unknown ucall 0x%x.", uc.cmd);
+			TEST_FAIL("Unknown ucall 0x%x.", uc.cmd);
 		}
 	}
 
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH 0/1] kvm: selftests: Add TEST_FAIL macro
  2020-03-05 17:25 [RFC PATCH 0/1] kvm: selftests: Add TEST_FAIL macro Wainer dos Santos Moschetta
  2020-03-05 17:25 ` [RFC PATCH 1/1] " Wainer dos Santos Moschetta
@ 2020-03-05 17:28 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-03-05 17:28 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta, kvm
  Cc: shuah, tglx, thuth, sean.j.christopherson, linux-kselftest, linux-kernel

On 05/03/20 18:25, Wainer dos Santos Moschetta wrote:
> The following patch's commit message is self-explanatory about this proposal.
> 
> I adjusted to use TEST_FAIL only a few source files, in reality it will
> need to change all the ones listed below. I will proceed with the
> adjustments if this new macro idea is accepted.
> 
> $ find . -type f -name "*.c" -exec grep -l "TEST_ASSERT(false" {} \;
> ./lib/kvm_util.c
> ./lib/io.c
> ./lib/x86_64/processor.c
> ./lib/aarch64/ucall.c
> ./lib/aarch64/processor.c
> ./x86_64/vmx_dirty_log_test.c
> ./x86_64/state_test.c
> ./x86_64/vmx_tsc_adjust_test.c
> ./x86_64/svm_vmcall_test.c
> ./x86_64/evmcs_test.c
> ./x86_64/vmx_close_while_nested_test.c
> 
> Wainer dos Santos Moschetta (1):
>   kvm: selftests: Add TEST_FAIL macro
> 
>  tools/testing/selftests/kvm/dirty_log_test.c             | 7 +++----
>  tools/testing/selftests/kvm/include/test_util.h          | 3 +++
>  tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c | 4 ++--
>  3 files changed, 8 insertions(+), 6 deletions(-)
> 

Yes, why not.

Paolo


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-05 17:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-05 17:25 [RFC PATCH 0/1] kvm: selftests: Add TEST_FAIL macro Wainer dos Santos Moschetta
2020-03-05 17:25 ` [RFC PATCH 1/1] " Wainer dos Santos Moschetta
2020-03-05 17:28 ` [RFC PATCH 0/1] " Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).