new file mode 100644
@@ -0,0 +1,41 @@
+XEN_ROOT = $(CURDIR)/../../../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+GO ?= go
+
+TESTS = dominfo freememory maxcpu onlinecpu physinfo versioninfo
+CBINARIES = $(TESTS:%=%-c)
+GOBINARIES = $(TESTS:%=%-go)
+
+CFLAGS += -Werror
+CFLAGS += $(CFLAGS_libxentoollog)
+CFLAGS += $(CFLAGS_libxenlight)
+
+LDLIBS += $(LDLIBS_libxentoollog)
+LDLIBS += $(LDLIBS_libxenlight)
+
+all: build
+
+test: clean build
+ for test in $(TESTS) ; do \
+ ./$$test-c >> c.output ; \
+ ./$$test-go >> go.output ; \
+ if cmp -s "c.output" "go.output"; then\
+ echo "$$test PASSED";\
+ else \
+ echo "$$test FAILED";\
+ fi ; \
+ done
+
+build: $(CBINARIES) $(GOBINARIES)
+
+%-c: %.c
+ gcc $(CFLAGS) -o $@ $< $(LDLIBS)
+
+%-go: %.go
+ GOPATH=$(XEN_ROOT)/tools/golang $(GO) build -o $@ $<
+
+clean:
+ rm -f *-c
+ rm -f *-go
+ rm -f *.output
new file mode 100644
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+ libxl_ctx *context;
+ libxl_dominfo info;
+ int err;
+ long cpu_time;
+ context = create_context();
+ libxl_dominfo_init(&info);
+ err = libxl_domain_info(context, &info, 0);
+ if (err != 0)
+ return err;
+
+ printf("%d\n%d\n", info.domid, info.ssidref);
+ 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));
+ 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);
+
+ destroy_context(context);
+
+}
new file mode 100644
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "xenproject.org/xenlight"
+)
+
+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)
+
+}
new file mode 100644
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+ libxl_ctx *context;
+ uint64_t free_memory;
+ int err;
+
+ context = create_context();
+
+ err = libxl_get_free_memory(context, &free_memory);
+ if (err < 0)
+ {
+ printf("%d\n", err);
+ }
+ else
+ {
+ printf("%lu\n", free_memory);
+ }
+ destroy_context(context);
+
+}
+
new file mode 100644
@@ -0,0 +1,25 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "xenproject.org/xenlight"
+)
+
+func main() {
+ ctx := xenlight.Ctx
+ err := ctx.Open()
+ if err != nil {
+ os.Exit(-1)
+ }
+
+ defer ctx.Close()
+
+ free_memory, err := ctx.GetFreeMemory()
+ if err != nil {
+ fmt.Printf("%d\n", err)
+ } else {
+ fmt.Printf("%d\n", free_memory)
+ }
+
+}
new file mode 100644
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+ libxl_ctx *context;
+ int max_cpus;
+
+ context = create_context();
+ max_cpus = libxl_get_max_cpus(context);
+ printf("%d\n", max_cpus);
+
+ destroy_context(context);
+
+}
+
new file mode 100644
@@ -0,0 +1,24 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "xenproject.org/xenlight"
+)
+
+func main() {
+ ctx := xenlight.Ctx
+ err := ctx.Open()
+ if err != nil {
+ os.Exit(-1)
+ }
+ defer ctx.Close()
+
+ max_cpus, err := ctx.GetMaxCpus()
+ if err != nil {
+ fmt.Printf("%d\n", err)
+ } else {
+ fmt.Printf("%d\n", max_cpus)
+ }
+
+}
new file mode 100644
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+
+int main(){
+
+ libxl_ctx *context;
+ context = create_context();
+
+ int max_nodes = libxl_get_max_nodes(context);
+ printf("%d\n", max_nodes);
+
+ destroy_context(context);
+}
+
new file mode 100644
@@ -0,0 +1,24 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "xenproject.org/xenlight"
+)
+
+func main() {
+ ctx := xenlight.Ctx
+ err := ctx.Open()
+ if err != nil {
+ os.Exit(-1)
+ }
+ defer ctx.Close()
+
+ max_nodes, err := ctx.GetMaxNodes()
+ if err != nil {
+ fmt.Printf("%d\n", err)
+ } else {
+ fmt.Printf("%d\n", max_nodes)
+ }
+
+}
new file mode 100644
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+ libxl_ctx *context;
+ int online_cpus;
+ context = create_context();
+
+ online_cpus = libxl_get_online_cpus(context);
+ printf("%d\n", online_cpus);
+
+ destroy_context(context);
+
+}
+
new file mode 100644
@@ -0,0 +1,24 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "xenproject.org/xenlight"
+)
+
+func main() {
+ ctx := xenlight.Ctx
+ err := ctx.Open()
+ if err != nil {
+ os.Exit(-1)
+ }
+ defer ctx.Close()
+
+ online_cpus, err := ctx.GetOnlineCpus()
+ if err != nil {
+ fmt.Printf("%d\n", err)
+ } else {
+ fmt.Printf("%d\n", online_cpus)
+ }
+
+}
new file mode 100644
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+ libxl_ctx *context;
+ libxl_physinfo info;
+ int err;
+ int i;
+ context = create_context();
+ libxl_physinfo_init(&info);
+ 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(i = 0; i < 8; i++){
+ printf("%u\n", info.hw_cap[i]);
+ }
+
+ libxl_physinfo_init(&info);
+ destroy_context(context);
+
+}
+
new file mode 100644
@@ -0,0 +1,32 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "xenproject.org/xenlight"
+)
+
+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])
+ }
+}
new file mode 100644
@@ -0,0 +1,22 @@
+xentoollog_logger_stdiostream *logger;
+
+static inline char *bool_to_string(bool a){
+ return (a ? "true" : "false");
+}
+
+static inline libxl_ctx *create_context(void){
+ libxl_ctx *context;
+ logger = xtl_createlogger_stdiostream(stderr,
+ XTL_ERROR, 0);
+ libxl_ctx_alloc(&context, LIBXL_VERSION, 0 , (xentoollog_logger*)logger);
+ return context;
+}
+
+static inline int destroy_context(libxl_ctx *context){
+ int err = libxl_ctx_free(context);
+ if (err != 0)
+ return err;
+ xtl_logger_destroy((xentoollog_logger*)logger);
+ return err;
+
+}
new file mode 100644
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxl.h>
+#include "print.h"
+
+int main(void){
+
+ libxl_ctx *context;
+ const libxl_version_info * info;
+ context = create_context();
+ 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);
+
+ destroy_context(context);
+
+}
new file mode 100644
@@ -0,0 +1,28 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "xenproject.org/xenlight"
+)
+
+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)
+
+}
new file mode 120000
@@ -0,0 +1 @@
+../../xenlight.go/usr/local/go/src/xenproject.org/xenlight/xenlight.go
\ No newline at end of file