Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin: cannot load a plugin from a test where the plugin includes the tested package #17928

Closed
crawshaw opened this issue Nov 15, 2016 · 8 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@crawshaw
Copy link
Member

On #17832 @wendigo notes that a go test for package p cannot load a plugin that imports package p without an error message about incorrect versions. This example is provided:

https://github.com/wendigo/go-plugin-33161

This is caused by the go tool rebuilding a package to include the test files, making the package in the test program incompatible with the equivalent package in the plugin.

I don't think this necessarily needs to work, it is entirely possible to do the plugin work from an external test from a package p_test. But maybe we could use a more helpful error message.

Any suggestions?

cc @ianlancetaylor

@wendigo
Copy link

wendigo commented Nov 15, 2016

plugin.so built with particular version of go cannot be loaded in any test package built with the same go version. From my perspective it basically limits possible usage of plugins as I cannot load and use plugins in tests and cannot test plugin itself in a test.

@crawshaw
Copy link
Member Author

It cannot be loaded into a test that is inside a package included in the plugin. Try changing your test to a separate package, typically done by replacing the package declaration with package mypkg_test.

@wendigo
Copy link

wendigo commented Nov 15, 2016

Already done that in the attached test case - result is the same (it seems that test package name doesn't matter at all). Also plugin cannot be loaded from any package used by the test itself.

In my case I've tracked this error while developing https://github.com/wendigo/go-bind-plugin which generates API for wrapping symbols exported by a plugin. I've got package cli that loads, analyzes symbols using reflection and generates code for the wrapper. When cli is used in a cli_test package plugin.Open fails to load it with an error: plugin was built with a different version of package runtime. It works just fine when loading it outside of the go test (also without cherry-picked https://go-review.googlesource.com/#/c/33161/ it works just fine).

@wendigo
Copy link

wendigo commented Nov 15, 2016

Also I've noticed that for mismatched packages like runtime or os *pkghash.runtimehash is "" (empty string) when comparing it with non-empty pkghash.linktimehash in https://github.com/golang/go/blob/master/src/runtime/plugin.go#L45

@crawshaw crawshaw added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 15, 2016
@crawshaw crawshaw modified the milestones: Go1.8Maybe, Go1.9 Nov 15, 2016
@wendigo
Copy link

wendigo commented Nov 22, 2016

Any news @crawshaw? I noticed that sometimes plugin cannot be also loaded outside the test (plugin.Open: plugin was built with a different version of package runtime) and when I've examined md.pkghashes only mismatched packages in my case were os and runtime (both with empty runtimehash). I don't know how runtimehash is exactly calculated.

@wendigo
Copy link

wendigo commented Dec 4, 2016

Ping @crawshaw, @ianlancetaylor

@gopherbot
Copy link

CL https://golang.org/cl/33925 mentions this issue.

@wendigo
Copy link

wendigo commented Dec 6, 2016

Fixed for me 👍 Thx @crawshaw

@golang golang locked and limited conversation to collaborators Dec 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants