github.com/llir/llvm@v0.3.6/ir/constant/asm_test.go (about)

     1  package constant_test
     2  
     3  import (
     4  	"io/ioutil"
     5  	"log"
     6  	"path/filepath"
     7  	"testing"
     8  
     9  	"github.com/google/go-cmp/cmp"
    10  	"github.com/llir/llvm/asm"
    11  	"github.com/llir/llvm/internal/osutil"
    12  )
    13  
    14  func TestModule(t *testing.T) {
    15  	golden := []struct {
    16  		path string
    17  	}{
    18  		// LLVM IR compatibility.
    19  		{path: "../../testdata/llvm/test/Bitcode/compatibility.ll"},
    20  		// Hex floating-point constants.
    21  		{path: "../../testdata/llvm/test/Assembler/2002-04-07-HexFloatConstants.ll"},
    22  		{path: "../../testdata/llvm/test/Assembler/half-constprop.ll"},
    23  		// Constant expressions.
    24  		{path: "../../testdata/llvm/test/Transforms/ConstProp/constant-expr.ll"},
    25  		{path: "../../testdata/llvm/test/Assembler/insertextractvalue.ll"},
    26  		{path: "../../testdata/llvm/test/DebugInfo/ARM/selectiondag-deadcode.ll"},
    27  		//{path: "../../testdata/llvm/test/Transforms/InstCombine/fma.ll"}, // TODO: enable once https://github.com/llir/llvm/issues/133 is resolved.
    28  		{path: "../../testdata/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll"},
    29  		{path: "../../testdata/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll"},
    30  		// Coreutils.
    31  		{path: "../../testdata/coreutils/test/timeout.ll"},
    32  		{path: "../../testdata/coreutils/test/vdir.ll"},
    33  	}
    34  	hasTestdata := osutil.Exists("../../testdata/llvm")
    35  	for _, g := range golden {
    36  		if filepath.HasPrefix(g.path, "../../testdata") && !hasTestdata {
    37  			// Skip test cases from the llir/testdata submodule if not downloaded.
    38  			// Users may add this submodule using git clone --recursive.
    39  			continue
    40  		}
    41  		log.Printf("=== [ %s ] ===", g.path)
    42  		m, err := asm.ParseFile(g.path)
    43  		if err != nil {
    44  			t.Errorf("unable to parse %q into AST; %+v", g.path, err)
    45  			continue
    46  		}
    47  		path := g.path
    48  		if osutil.Exists(g.path + ".golden") {
    49  			path = g.path + ".golden"
    50  		}
    51  		buf, err := ioutil.ReadFile(path)
    52  		if err != nil {
    53  			t.Errorf("unable to read %q; %+v", path, err)
    54  			continue
    55  		}
    56  		want := string(buf)
    57  		got := m.String()
    58  		if diff := cmp.Diff(want, got); diff != "" {
    59  			t.Errorf("module %q mismatch (-want +got):\n%s", path, diff)
    60  			continue
    61  		}
    62  	}
    63  }