xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ronald Rojas <ronladred@gmail.com>
To: xen-devel@lists.xen.org, george.dunlap@citrix.com,
	ian.jackson@eu.citrix.com, wei.liu2@citrix.com
Cc: Ronald Rojas <ronladred@gmail.com>
Subject: [PATCH RFC 8/8] golang/xenlight: Add tests host related functinality functions
Date: Wed, 18 Jan 2017 14:56:46 -0500	[thread overview]
Message-ID: <1484769406-17416-8-git-send-email-ronladred@gmail.com> (raw)
In-Reply-To: <1484769406-17416-1-git-send-email-ronladred@gmail.com>

Create tests for the following functions:
- GetVersionInfo
- GetPhysinfo
- GetDominfo
- GetMaxCpus
- GetOnlineCpus
- GetMaxNodes
- GetFreeMemory

Signed-off-by: Ronald Rojas <ronladred@gmail.com>

---
To do:
-Seperate GetMaxCpus, GetOnlineCpus, GetMaxNodes, and
GetFreeMemory into seperate tests
-create tests for cpupool and bitmap operations
---
 tools/golang/xenlight/test/dominfo/Makefile        | 19 ++++++++
 tools/golang/xenlight/test/dominfo/dominfo.c       | 30 ++++++++++++
 tools/golang/xenlight/test/dominfo/dominfo.go      | 48 +++++++++++++++++++
 tools/golang/xenlight/test/funcs/Makefile          | 20 ++++++++
 tools/golang/xenlight/test/funcs/func.c            | 34 ++++++++++++++
 tools/golang/xenlight/test/funcs/func.go           | 54 ++++++++++++++++++++++
 tools/golang/xenlight/test/physinfo/Makefile       | 20 ++++++++
 tools/golang/xenlight/test/physinfo/physinfo.c     | 31 +++++++++++++
 tools/golang/xenlight/test/physinfo/physinfo.go    | 36 +++++++++++++++
 tools/golang/xenlight/test/versioninfo/Makefile    | 20 ++++++++
 .../golang/xenlight/test/versioninfo/versioninfo.c | 18 ++++++++
 .../xenlight/test/versioninfo/versioninfo.go       | 33 +++++++++++++
 12 files changed, 363 insertions(+)
 create mode 100644 tools/golang/xenlight/test/dominfo/Makefile
 create mode 100644 tools/golang/xenlight/test/dominfo/dominfo.c
 create mode 100644 tools/golang/xenlight/test/dominfo/dominfo.go
 create mode 100644 tools/golang/xenlight/test/funcs/Makefile
 create mode 100644 tools/golang/xenlight/test/funcs/func.c
 create mode 100644 tools/golang/xenlight/test/funcs/func.go
 create mode 100644 tools/golang/xenlight/test/physinfo/Makefile
 create mode 100644 tools/golang/xenlight/test/physinfo/physinfo.c
 create mode 100644 tools/golang/xenlight/test/physinfo/physinfo.go
 create mode 100644 tools/golang/xenlight/test/versioninfo/Makefile
 create mode 100644 tools/golang/xenlight/test/versioninfo/versioninfo.c
 create mode 100644 tools/golang/xenlight/test/versioninfo/versioninfo.go

diff --git a/tools/golang/xenlight/test/dominfo/Makefile b/tools/golang/xenlight/test/dominfo/Makefile
new file mode 100644
index 0000000..89ca1b3
--- /dev/null
+++ b/tools/golang/xenlight/test/dominfo/Makefile
@@ -0,0 +1,19 @@
+
+test: clean build
+	./dominfo.out >> c.output
+	go run dominfo.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "GetDominfo PASSED";\
+	else\
+		echo "GetDominfo FAILED";\
+	fi\
+
+build:
+	go build -o dominfo.a dominfo.go 
+	gcc dominfo.c -lxenlight -lyajl -o dominfo.out
+
+clean:
+	rm dominfo.a
+	rm dominfo.out
+	rm c.output
+	rm go.output
diff --git a/tools/golang/xenlight/test/dominfo/dominfo.c b/tools/golang/xenlight/test/dominfo/dominfo.c
new file mode 100644
index 0000000..ed0fe78
--- /dev/null
+++ b/tools/golang/xenlight/test/dominfo/dominfo.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+char * bool_to_string(bool b);
+int main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_dominfo info;
+    int err = libxl_domain_info(context, &info, 0);
+    if(err != 0){
+        return err;
+    }
+    
+    
+	printf("%d\n%d\n", info.domid, info.ssidref);
+	//printf("%s\n", info.ssid_label);
+	printf("%s\n%s\n%s\n%s\n%s\n%s\n", bool_to_string(info.running), bool_to_string(info.blocked ), bool_to_string(info.paused ),bool_to_string(info.shutdown ),bool_to_string(info.dying), bool_to_string(info.never_stop));
+	long cpu_time = info.cpu_time/((long)1<<35);
+	printf("%d\n%lu\n%lu\n%lu\n%lu\n%lu\n%lu\n%d\n%d\n%d\n", info.shutdown_reason, info.outstanding_memkb, info.current_memkb, info.shared_memkb, info.paged_memkb, info.max_memkb, cpu_time, info.vcpu_max_id, info.vcpu_online, info.cpupool);
+	printf("%d\n", info.domain_type);
+
+
+    libxl_ctx_free(context);
+
+}
+char * bool_to_string(bool b){
+    return b ? "true": "false";
+}
diff --git a/tools/golang/xenlight/test/dominfo/dominfo.go b/tools/golang/xenlight/test/dominfo/dominfo.go
new file mode 100644
index 0000000..268b118
--- /dev/null
+++ b/tools/golang/xenlight/test/dominfo/dominfo.go
@@ -0,0 +1,48 @@
+
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"xenlight"
+	"os"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil{
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	info, err:= ctx.DomainInfo(0)
+	if err != nil{
+		os.Exit(-1)
+	}
+
+	fmt.Printf("%d\n%d\n", info.Domid, info.Ssidref)
+	//fmt.Printf("%s\n", info.SsidLabel)
+	fmt.Printf("%t\n%t\n%t\n%t\n%t\n%t\n", info.Running, info.Blocked, info.Paused, info.Shutdown, info.Dying, info.NeverStop)
+	cpuTime := info.CpuTime/(1<<35)
+	fmt.Printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n", info.ShutdownReason, info.OutstandingMemkb, info.CurrentMemkb, info.SharedMemkb, info.PagedMemkb, info.MaxMemkb, cpuTime, info.VcpuMaxId, info.VcpuOnline, info.Cpupool)
+	fmt.Printf("%d\n", info.DomainType)
+
+}
+
+func replaceDomainType(n int32)(ret string){
+	switch n{
+	case -1:
+		ret = "invalid"
+	case 1:
+		ret = "hvm"
+	case 2:
+		ret = "pv"
+	}
+	return
+
+}
diff --git a/tools/golang/xenlight/test/funcs/Makefile b/tools/golang/xenlight/test/funcs/Makefile
new file mode 100644
index 0000000..d8c234c
--- /dev/null
+++ b/tools/golang/xenlight/test/funcs/Makefile
@@ -0,0 +1,20 @@
+
+test: clean build
+	./func.out >> c.output
+	go run func.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "same";\
+	else\
+		echo "diff"; \
+	fi\
+
+build:
+	go build -o func.a func.go
+	gcc func.c -lxenlight -lyajl -o func.out
+
+clean:
+	rm func.a
+	rm func.out
+	rm c.output
+	rm go.output
+
diff --git a/tools/golang/xenlight/test/funcs/func.c b/tools/golang/xenlight/test/funcs/func.c
new file mode 100644
index 0000000..3fdbf22
--- /dev/null
+++ b/tools/golang/xenlight/test/funcs/func.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+int main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_physinfo info ;
+    int err= libxl_get_physinfo(context,&info);
+    if(err != 0){
+        return err;
+    }
+
+    int max_cpus = libxl_get_max_cpus(context);
+    printf("%d\n", max_cpus);
+
+    int online_cpus = libxl_get_online_cpus(context);
+    printf("%d\n", online_cpus);
+
+    int max_nodes = libxl_get_max_nodes(context);
+    printf("%d\n", max_nodes);
+
+    uint64_t free_memory;
+    err = libxl_get_free_memory(context, &free_memory);
+    if(err < 0){
+        printf("%d\n", err);
+    }else{
+        printf("%lu\n", free_memory);
+    }
+    libxl_ctx_free(context);
+
+}
+
diff --git a/tools/golang/xenlight/test/funcs/func.go b/tools/golang/xenlight/test/funcs/func.go
new file mode 100644
index 0000000..fd83356
--- /dev/null
+++ b/tools/golang/xenlight/test/funcs/func.go
@@ -0,0 +1,54 @@
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"os"
+	"xenlight"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil {
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	if err != nil {
+		os.Exit(-1)
+	}
+
+	max_cpus, err := ctx.GetMaxCpus()
+	if err != nil {
+		fmt.Printf("%d\n", err)
+	} else {
+		fmt.Printf("%d\n", max_cpus)
+	}
+
+	online_cpus, err := ctx.GetOnlineCpus()
+	if err != nil {
+		fmt.Printf("%d\n", err)
+	} else {
+		fmt.Printf("%d\n", online_cpus)
+	}
+
+	max_nodes, err := ctx.GetMaxNodes()
+	if err != nil {
+		fmt.Printf("%d\n", err)
+	} else {
+		fmt.Printf("%d\n", max_nodes)
+	}
+
+	free_memory, err := ctx.GetFreeMemory()
+	if err != nil {
+		fmt.Printf("%d\n", err)
+	} else {
+		fmt.Printf("%d\n", free_memory)
+	}
+
+}
diff --git a/tools/golang/xenlight/test/physinfo/Makefile b/tools/golang/xenlight/test/physinfo/Makefile
new file mode 100644
index 0000000..cef23e7
--- /dev/null
+++ b/tools/golang/xenlight/test/physinfo/Makefile
@@ -0,0 +1,20 @@
+
+test: clean build
+	./physinfo.out >> c.output
+	go run physinfo.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "GetPhysinfo PASSED";\
+	else\
+		echo "GetPhysinfo FAILED"; \
+	fi\
+
+build:
+	go build -o physinfo.a physinfo.go 
+	gcc physinfo.c -lxenlight -lyajl -o physinfo.out
+
+clean:
+	rm physinfo.a
+	rm physinfo.out
+	rm c.output
+	rm go.output
+
diff --git a/tools/golang/xenlight/test/physinfo/physinfo.c b/tools/golang/xenlight/test/physinfo/physinfo.c
new file mode 100644
index 0000000..92c8f47
--- /dev/null
+++ b/tools/golang/xenlight/test/physinfo/physinfo.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+char *bool_to_string(bool b);
+int main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_physinfo info ;
+    int err= libxl_get_physinfo(context,&info);
+    if(err != 0){
+        return err;
+    }
+
+    printf("%d\n%d\n%d\n%d\n%d\n", info.threads_per_core, info.cores_per_socket, info.max_cpu_id, info.nr_cpus, info.cpu_khz);
+    printf("%lu\n%lu\n%lu\n%lu\n%lu\n%lu\n", info.total_pages, info.free_pages, info.scrub_pages, info.outstanding_pages, info.sharing_freed_pages, info.sharing_used_frames);
+    printf("%u\n",info.nr_nodes);
+    printf("%s\n%s\n", bool_to_string(info.cap_hvm), bool_to_string(info.cap_hvm_directio));
+
+    for(int i = 0; i < 8; i++){
+        printf("%u\n", info.hw_cap[i]);
+    }
+
+    libxl_ctx_free(context);
+
+}
+
+char * bool_to_string(bool b){
+    return b ? "true": "false";
+}
diff --git a/tools/golang/xenlight/test/physinfo/physinfo.go b/tools/golang/xenlight/test/physinfo/physinfo.go
new file mode 100644
index 0000000..e0b7a74
--- /dev/null
+++ b/tools/golang/xenlight/test/physinfo/physinfo.go
@@ -0,0 +1,36 @@
+
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"xenlight"
+	"os"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil{
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	info, err:= ctx.GetPhysinfo()
+	if err != nil{
+		os.Exit(-1)
+	}
+
+	fmt.Printf("%d\n%d\n%d\n%d\n%d\n", info.ThreadsPerCore, info.CoresPerSocket, info.MaxCpuId, info.NrCpus, info.CpuKhz)
+	fmt.Printf("%d\n%d\n%d\n%d\n%d\n%d\n", info.TotalPages, info.FreePages, info.ScrubPages, info.OutstandingPages, info.SharingFreedPages, info.SharingUsedFrames)
+	fmt.Printf("%d\n",info.NrNodes)
+	fmt.Printf("%t\n%t\n", info.CapHvm, info.CapHvmDirectio)
+
+	for i := 0; i < 8; i++ {
+	fmt.Printf("%d\n", info.HwCap[i]);
+	}
+}
diff --git a/tools/golang/xenlight/test/versioninfo/Makefile b/tools/golang/xenlight/test/versioninfo/Makefile
new file mode 100644
index 0000000..e269e2d
--- /dev/null
+++ b/tools/golang/xenlight/test/versioninfo/Makefile
@@ -0,0 +1,20 @@
+
+test: clean build
+	./versioninfo.out >> c.output
+	go run versioninfo.go >> go.output
+	if cmp -s "c.output" "go.output"; then\
+		echo "GetVersionInfo PASSED";\
+	else\
+		echo "GetVersionInfo FAILED"; \
+	fi\
+
+build:
+	go build -o versioninfo.a versioninfo.go 
+	gcc versioninfo.c -lxenlight -lyajl -o versioninfo.out
+
+clean:
+	rm versioninfo.a
+	rm versioninfo.out
+	rm c.output
+	rm go.output
+
diff --git a/tools/golang/xenlight/test/versioninfo/versioninfo.c b/tools/golang/xenlight/test/versioninfo/versioninfo.c
new file mode 100644
index 0000000..f40495d
--- /dev/null
+++ b/tools/golang/xenlight/test/versioninfo/versioninfo.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+main(){
+
+    libxl_ctx *context;
+    libxl_ctx_alloc(&context,LIBXL_VERSION, 0, NULL);
+    libxl_version_info* info = libxl_get_version_info(context);
+
+    printf("%d\n%d\n", info->xen_version_major, info->xen_version_minor);
+    printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n", info->xen_version_extra, info->compiler, info->compile_by, info->compile_domain, info->compile_date, info->capabilities, info->changeset);
+    printf("%lu\n%d\n", info->virt_start, info->pagesize);
+    printf("%s\n%s\n", info->commandline, info->build_id);
+
+    libxl_ctx_free(context);
+
+}
diff --git a/tools/golang/xenlight/test/versioninfo/versioninfo.go b/tools/golang/xenlight/test/versioninfo/versioninfo.go
new file mode 100644
index 0000000..e455b66
--- /dev/null
+++ b/tools/golang/xenlight/test/versioninfo/versioninfo.go
@@ -0,0 +1,33 @@
+
+package main
+
+/*
+#cgo LDFLAGS: -lxenlight -lyajl
+#include <stdlib.h>
+#include <libxl.h>
+*/
+import "C"
+import (
+	"fmt"
+	"xenlight"
+	"os"
+)
+
+func main() {
+	ctx := xenlight.Ctx
+	err := ctx.Open()
+	if err != nil{
+		os.Exit(-1)
+	}
+	defer ctx.Close()
+	info, err:= ctx.GetVersionInfo()
+	if err != nil{
+		os.Exit(-1)
+	}
+
+	fmt.Printf("%d\n%d\n", info.XenVersionMajor, info.XenVersionMinor);
+	fmt.Printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n", info.XenVersionExtra, info.Compiler, info.CompileBy, info.CompileDomain, info.CompileDate, info.Capabilities, info.Changeset);
+	fmt.Printf("%d\n%d\n", info.VirtStart, info.Pagesize);
+	fmt.Printf("%s\n%s\n", info.Commandline, info.BuildId);
+
+}
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-01-18 19:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18 19:56 [PATCH RFC 1/8] golang/xenlight: Create stub package Ronald Rojas
2017-01-18 19:56 ` [PATCH RFC 2/8] golang/xenlight: Add error constants and standard handling Ronald Rojas
2017-01-18 22:16   ` Dario Faggioli
2017-01-19 15:13     ` Ronald Rojas
2017-01-19 16:02       ` George Dunlap
2017-01-19 16:15         ` Wei Liu
2017-01-19 16:19         ` Dario Faggioli
2017-01-19 17:16   ` George Dunlap
2017-01-18 19:56 ` [PATCH RFC 3/8] golang/xenlight: Add host-related functionality Ronald Rojas
2017-01-19 17:51   ` George Dunlap
2017-01-18 19:56 ` [PATCH RFC 4/8] golang/xenlight: Implement libxl_domain_info and libxl_domain_unpause Ronald Rojas
2017-01-18 19:56 ` [PATCH RFC 5/8] golang/xenlight: Implement libxl_bitmap and helper operations Ronald Rojas
2017-01-18 19:56 ` [PATCH RFC 6/8] tools/xenlight: Implement libxl_scheduler enumeration Ronald Rojas
2017-01-18 19:56 ` [PATCH RFC 7/8] golang/xenlight: Implement cpupool operations Ronald Rojas
2017-01-18 19:56 ` Ronald Rojas [this message]
2017-01-18 22:10 ` [PATCH RFC 1/8] golang/xenlight: Create stub package Dario Faggioli
2017-01-18 22:37   ` Ronald Rojas
2017-01-19 12:03 ` Wei Liu
2017-01-19 15:15   ` Ronald Rojas
2017-01-19 16:16 ` George Dunlap
2017-01-19 16:40 ` George Dunlap
2017-01-19 16:45 ` George Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484769406-17416-8-git-send-email-ronladred@gmail.com \
    --to=ronladred@gmail.com \
    --cc=george.dunlap@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).