From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: [PATCH kvm-unit-tests v2 07/14] Add sample test using the api test harness Date: Wed, 15 Dec 2010 18:09:36 +0200 Message-ID: <1292429383-15326-8-git-send-email-avi@redhat.com> References: <1292429383-15326-1-git-send-email-avi@redhat.com> To: Marcelo Tosatti , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:12263 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752040Ab0LOQKH (ORCPT ); Wed, 15 Dec 2010 11:10:07 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBFGA7GA003472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 15 Dec 2010 11:10:07 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oBFGA4HC015655 for ; Wed, 15 Dec 2010 11:10:07 -0500 In-Reply-To: <1292429383-15326-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Call a function setting a global variable. Signed-off-by: Avi Kivity --- api/api-sample.cc | 29 +++++++++++++++++++++++++++++ config-x86-common.mak | 7 +++++++ 2 files changed, 36 insertions(+), 0 deletions(-) create mode 100644 api/api-sample.cc diff --git a/api/api-sample.cc b/api/api-sample.cc new file mode 100644 index 0000000..8d57c09 --- /dev/null +++ b/api/api-sample.cc @@ -0,0 +1,29 @@ + +#include "api/kvmxx.hh" +#include "api/identity.hh" +#include "api/exception.hh" +#include "stdio.h" + +static int global = 0; + +static void set_global() +{ + global = 1; +} + +int test_main(int ac, char** av) +{ + kvm::system system; + kvm::vm vm(system); + identity::setup_vm(vm); + kvm::vcpu vcpu(vm, 0); + identity::vcpu thread(vcpu, set_global); + vcpu.run(); + printf("global %d\n", global); + return global == 1 ? 0 : 1; +} + +int main(int ac, char** av) +{ + return try_main(test_main, ac, av); +} diff --git a/config-x86-common.mak b/config-x86-common.mak index dde4f67..3e8e641 100644 --- a/config-x86-common.mak +++ b/config-x86-common.mak @@ -32,6 +32,8 @@ tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \ $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \ $(TEST_DIR)/kvmclock_test.flat +tests-common += api/api-sample + tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg test_cases: $(tests-common) $(tests) @@ -82,3 +84,8 @@ arch_clean: $(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o api/%.o: CFLAGS += -m32 + +api/api-sample: LDLIBS += -lstdc++ +api/api-sample: LDFLAGS += -m32 + +api/api-sample: api/api-sample.o api/kvmxx.o api/identity.o api/exception.o -- 1.7.1