Skip to content

Commit

Permalink
Add LibwasmvmVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed May 3, 2022
1 parent a70075b commit 9fa202e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
26 changes: 26 additions & 0 deletions api/version.go
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions api/version_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 9fa202e

Please sign in to comment.