...

Source file src/github.com/cespare/xxhash/v2/dynamic/dynamic_test.go

Documentation: github.com/cespare/xxhash/v2/dynamic

     1  //go:build linux || darwin
     2  // +build linux darwin
     3  
     4  package main
     5  
     6  import (
     7  	"bytes"
     8  	"log"
     9  	"os"
    10  	"os/exec"
    11  	"plugin"
    12  	"testing"
    13  )
    14  
    15  // This is a cursory test that checks whether things work under dynamic linking.
    16  
    17  func TestMain(m *testing.M) {
    18  	cmd := exec.Command(
    19  		"go", "build",
    20  		"-buildmode", "plugin",
    21  		"-o", "plugin.so",
    22  		"plugin.go",
    23  	)
    24  	var out bytes.Buffer
    25  	cmd.Stdout = &out
    26  	cmd.Stderr = &out
    27  	if err := cmd.Run(); err != nil {
    28  		log.Fatalf("Error building plugin: %s\nOutput:\n%s", err, out.String())
    29  	}
    30  	os.Exit(m.Run())
    31  }
    32  
    33  func TestDynamic(t *testing.T) {
    34  	plug, err := plugin.Open("plugin.so")
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  	for _, test := range []string{
    39  		"TestSum",
    40  		"TestDigest",
    41  	} {
    42  		f, err := plug.Lookup(test)
    43  		if err != nil {
    44  			t.Fatalf("cannot find func %s: %s", test, err)
    45  		}
    46  		f.(func(*testing.T))(t)
    47  	}
    48  }
    49  

View as plain text