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

go test & run-tests.sh failing - expected 'package', found 'EOF' #26

Closed
carstenhag opened this issue Apr 14, 2017 · 12 comments
Closed

go test & run-tests.sh failing - expected 'package', found 'EOF' #26

carstenhag opened this issue Apr 14, 2017 · 12 comments
Labels
Milestone

Comments

@carstenhag
Copy link

I clone the repo, ran go get and then go test, but unfortunately it fails with a panic:

shell@shell-virtual-machine ~/g/s/g/e/c2go> go test
--- FAIL: TestIntegrationScripts (0.10s)
panic: '' [recovered]
	panic: ''

goroutine 10 [running]:
testing.tRunner.func1(0xc42006f380)
	/usr/local/go/src/testing/testing.go:622 +0x29d
panic(0x547960, 0xc420383a00)
	/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/elliotchance/c2go.resolveType(0x0, 0x0, 0x57e87e, 0x8)
	/home/shell/gocode/src/github.com/elliotchance/c2go/resolve.go:167 +0xc4f
github.com/elliotchance/c2go.(*TypedefDecl).RenderLine(0xc420372900, 0xc4201c88c0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/shell/gocode/src/github.com/elliotchance/c2go/typedef_decl.go:65 +0x162
github.com/elliotchance/c2go.Render(0xc4201c88c0, 0x551f60, 0xc420372900, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/shell/gocode/src/github.com/elliotchance/c2go/common.go:48 +0x102
github.com/elliotchance/c2go.(*TranslationUnitDecl).RenderLine(0xc42028e2a0, 0xc4201c88c0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/shell/gocode/src/github.com/elliotchance/c2go/translation_unit_decl.go:21 +0xa5
github.com/elliotchance/c2go.Render(0xc4201c88c0, 0x551f00, 0xc42028e2a0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/shell/gocode/src/github.com/elliotchance/c2go/common.go:48 +0x102
github.com/elliotchance/c2go.Start(0xc4203eaf78, 0x2, 0x2, 0x21, 0x40)
	/home/shell/gocode/src/github.com/elliotchance/c2go/main.go:156 +0x38b
github.com/elliotchance/c2go.TestIntegrationScripts(0xc42006f380)
	/home/shell/gocode/src/github.com/elliotchance/c2go/main_test.go:20 +0xbd
testing.tRunner(0xc42006f380, 0x58b3d0)
	/usr/local/go/src/testing/testing.go:657 +0x96
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:697 +0x2ca
exit status 2
FAIL	github.com/elliotchance/c2go	0.111s

run-tests.sh also seems to produce an empty panic:

shell@shell-virtual-machine ~/g/s/g/e/c2go> ./run-tests.sh 
CLANG_BIN=clang
CLANG_VERSION=clang version 3.8.1-12ubuntu1 (tags/RELEASE_381/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

tests/misc/user-input.c
panic: ''

goroutine 1 [running]:
main.resolveType(0x0, 0x0, 0x51a90a, 0x8)
	/home/shell/gocode/src/github.com/elliotchance/c2go/resolve.go:167 +0xc4f
main.(*TypedefDecl).RenderLine(0xc4200d4d80, 0xc420176000, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/shell/gocode/src/github.com/elliotchance/c2go/typedef_decl.go:65 +0x162
main.Render(0xc420176000, 0x4f8ca0, 0xc4200d4d80, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/shell/gocode/src/github.com/elliotchance/c2go/common.go:48 +0x102
main.(*TranslationUnitDecl).RenderLine(0xc4200a84b0, 0xc420176000, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/shell/gocode/src/github.com/elliotchance/c2go/translation_unit_decl.go:21 +0xa5
main.Render(0xc420176000, 0x4f8c40, 0xc4200a84b0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/shell/gocode/src/github.com/elliotchance/c2go/common.go:48 +0x102
main.Start(0xc42000a440, 0x2, 0x2, 0x0, 0x0)
	/home/shell/gocode/src/github.com/elliotchance/c2go/main.go:156 +0x38b
main.main()
	/home/shell/gocode/src/github.com/elliotchance/c2go/main.go:171 +0x49
can't load package: package github.com/elliotchance/c2go/build: 
main.go:1:1: expected 'package', found 'EOF'
=== out.go
cat: build/main.go: No such file or directory

@elliotchance
Copy link
Owner

Hi @carstenhag - this is almost certainly due to processing different header files that c2go cannot understand. The compiler environments are slightly different from those I've tested with my mac, ubuntu 14.04 and travis builds.

I realise the error is confusing, the error messages will become more useful over time. This specific error is caused by it trying to translate a C type into the equivalent Go type. Like unsigned int (C) -> uint32 (Go). However, in this case the type it is trying to translate is a blank string (hence the unhelpful message).

Try replacing the problematic line with something that can be seen in the output like:

// panic(fmt.Sprintf("'%s'", s))
return "!HERE!"

Hopefully, if this is the only issue you will be able to see !HERE! in the output Go and from there you will be able to see what data type it was trying to translate in the first place.

@elliotchance
Copy link
Owner

After changing that line you can simply run ./run-tests.sh again. It will handle the compilation.

The !HERE! token will cause the Go to fail to compile, that's OK. You want to see the output of build/main.go (that will be the most recently generated go from the tests) and also have a look at /tmp/pp.c - this is the preprocessed file that actually gets converted into Go.

@carstenhag
Copy link
Author

carstenhag commented Apr 14, 2017

@elliotchance Thanks for the quick answer! After modifying resolve.go, rebuilding etc, go test seems to return ok but it doesn't generate the build/main.go file. run-tests.sh does, this is the output:

[...]
type _IO_FILE_plus struct {
}

type __io_read_fn interface{}

type line !HERE!

type __io_seek_fn interface{}

type __io_close_fn interface{}

type off_t __off_t

type ssize_t __ssize_t

func main() {
        var number int
        fmt.Printf("Enter an integer\n")
        fmt.Scanf("%d", &number)
        fmt.Printf("Integer entered by you is %d\n", number)
        return
}

Gist for pp.c

@elliotchance
Copy link
Owner

If you are seeing that Go output then you did not hit the error on that particular file, try running ./run-tests.sh again.

Also, run-tests.sh does all the preparation and compilation for you, no need for any other commands :)

@zoeyfyi
Copy link
Contributor

zoeyfyi commented Apr 14, 2017

I have traced the issue back to this line: 0x55b9da8784b0 <line:341:1, line:342:16> line:341:19 __io_write_fn '__ssize_t (void *, const char *, size_t)

Calling Parse on this line produces:

&main.TypedefDecl{Address:"0x55b9da8784b0", Position:"line:341:1, line:342:16", Position2:"", Name:"line", Type:"", Type2:"", IsImplicit:false, IsReferenced:false, Childre
n:[]interface {}{}}

@zoeyfyi
Copy link
Contributor

zoeyfyi commented Apr 15, 2017

I believe the problem is in parseTypedefDecl the regex is looking for col: after the > however in this case the position is a line.

@elliotchance
Copy link
Owner

@bongo227 yes, that definitely looks like the issue. Can you please submit a PR for that change? With a test case

zoeyfyi added a commit to zoeyfyi/c2go that referenced this issue Apr 15, 2017
@zoeyfyi zoeyfyi mentioned this issue Apr 15, 2017
elliotchance added a commit that referenced this issue Apr 15, 2017
@elliotchance
Copy link
Owner

@bongo227 please try again with v0.8.4 and see if that fixes the issue.

@zoeyfyi
Copy link
Contributor

zoeyfyi commented Apr 16, 2017

Done. All tests parse.

@elliotchance
Copy link
Owner

Awesome. @carstenhag can you confirm this is now working for you? If so, close this issue.

@carstenhag
Copy link
Author

go test runs fine now, thanks!

Just a note, seems to take ~14sec now instead of the previous 6-7.

@elliotchance
Copy link
Owner

I have noticed the slow down with tests (well thats not really true, because it used to take the same amount of time with run-tests.sh) and especially what all the new tests in #30 .

I have created a ticket to address this #47.

@elliotchance elliotchance modified the milestone: v0.8.x Apr 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants