From 9fa202e6587bda29b56dffbe5f42a48b68a60862 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Sun, 10 Apr 2022 18:04:40 +0200 Subject: [PATCH] Add LibwasmvmVersion --- api/version.go | 26 ++++++++++++++++++++++++++ api/version_test.go | 13 +++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 api/version.go create mode 100644 api/version_test.go diff --git a/api/version.go b/api/version.go new file mode 100644 index 000000000..b0ad8baa3 --- /dev/null +++ b/api/version.go @@ -0,0 +1,26 @@ +package api + +// #include "bindings.h" +import "C" + +import ( + "fmt" +) + +// LibwasmvmVersion returns the version of the loaded library +// at runtime. This can be used to verify if the loaded version +// matches the expected version. +func LibwasmvmVersion() (string, error) { + version, err := C.version_number() + if err != nil { + return "", err + } + patch := version >> 0 & 0xFFFF + minor := version >> 16 & 0xFFFF + major := version >> 32 & 0xFFFF + error := version >> 48 & 0xFFFF + if error != 0 { + return "", fmt.Errorf("Error code from version_number call: %d", error) + } + return fmt.Sprintf("%d.%d.%d", major, minor, patch), nil +} diff --git a/api/version_test.go b/api/version_test.go new file mode 100644 index 000000000..6760d3a2c --- /dev/null +++ b/api/version_test.go @@ -0,0 +1,13 @@ +package api + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestLibwasmvmVersion(t *testing.T) { + version, err := LibwasmvmVersion() + require.NoError(t, err) + require.Equal(t, "1.0.0", version) +}