Debugging XCTests on Linux


(Robert Atkins) #1

Hi all,

I'm trying to solve a simple (?) problem where a test suite runs fine on
macOS but fails on Linux
(https://github.com/antitypical/Result/pull/210#pullrequestreview-14963305).
I've downloaded and installed the Swift Linux Docker image
(https://ashfurrow.com/blog/swift-on-linux/) and got the project
building and testing, and, mercifully, I get the same failure locally as
I'm getting on Travis CI. But at this point I'm stuck.

1) I can't get the SPM-built module the project produces working
properly in the Swift REPL in order to just play around with it
(https://bugs.swift.org/browse/SR-1191). Can anyone help me with this?

2a) How do I use LLDB to set a breakpoint in a test method and step into
its execution so I can trace through the source of the test failure?
Saying "lldb swift test" does something, but doesn't know about any of
the lines I'm trying to set a breakpoint on—I suspect it thinks I'm
trying to set breakpoints in the swift binary itself, rather than the
test suite?

2b) Saying "swift -warnings-as-errors test" doesn't seem to do what I
want, complaining about "no such file or directory: 'test'", whereas
"swift test" works fine. Is there a way to pass flags to the swift
interpreter when it runs tests?

Thanks, Robert.


(Ankit Agarwal) #2

Using swift module in REPL:

Toolchain: January 4, 2017
Platform: Ubuntu 16.04

Add this at end of Package.swift:

products += [Product(name: "Result", type: .Library(.Dynamic), modules:
"Result")]

$ swift build
$ swift -I .build/debug -L .build/debug -lResult -I
/usr/lib/clang/3.8/include
Welcome to Swift version 3.1-dev (LLVM 217eb6c2b6, Clang 34a98ce92e, Swift
1eb5648c46). Type :help for assistance.
  1> import Result
  2> let a = Result<String, AnyError>("a")
  success = "a"
}
  3> a.dematerialize()
$R0: String = "a"

PS: Make sure you pass these flags when launching docker bash:
"--security-opt seccomp=unconfined"

···

a: Result.Result<String, Result.AnyError> = success {

On Thu, Jan 5, 2017 at 3:33 PM, Robert Atkins via swift-users < swift-users@swift.org> wrote:

Hi all,

I'm trying to solve a simple (?) problem where a test suite runs fine on
macOS but fails on Linux
(https://github.com/antitypical/Result/pull/210#pullrequestreview-14963305
).
I've downloaded and installed the Swift Linux Docker image
(https://ashfurrow.com/blog/swift-on-linux/) and got the project
building and testing, and, mercifully, I get the same failure locally as
I'm getting on Travis CI. But at this point I'm stuck.

1) I can't get the SPM-built module the project produces working
properly in the Swift REPL in order to just play around with it
(https://bugs.swift.org/browse/SR-1191). Can anyone help me with this?

2a) How do I use LLDB to set a breakpoint in a test method and step into
its execution so I can trace through the source of the test failure?
Saying "lldb swift test" does something, but doesn't know about any of
the lines I'm trying to set a breakpoint on—I suspect it thinks I'm
trying to set breakpoints in the swift binary itself, rather than the
test suite?

2b) Saying "swift -warnings-as-errors test" doesn't seem to do what I
want, complaining about "no such file or directory: 'test'", whereas
"swift test" works fine. Is there a way to pass flags to the swift
interpreter when it runs tests?

Thanks, Robert.
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
Ankit


(Robert Atkins) #3

Using swift module in REPL:

[...]

$ swift build

$ swift -I .build/debug -L .build/debug -lResult -I
/usr/lib/clang/3.8/include
Welcome to Swift version 3.1-dev (LLVM 217eb6c2b6, Clang 34a98ce92e,
Swift 1eb5648c46). Type :help for assistance.
  1> import Result

  2> let a = Result<String, AnyError>("a")

a: Result.Result<String, Result.AnyError> = success {

  success = "a"

}

Oh wait, this works for me! It was the specific thing I was trying to
do (wrapping an NSError instance in an AnyError) that breaks which
was leading me to think importing the Result library into the REPL
wasn't working:

$ swift -I.build/debug -L.build/debug -lResult
Welcome to Swift version 3.0.2 (swift-3.0.2-RELEASE). Type :help for
assistance.
  1> import Foundation

  2> import Result

  3> let r = Result<String, AnyError>("a")

r: Result.Result<String, Result.AnyError> = success {

  success = "a"

}

  4> let nse = NSError(domain: "Foo", code: 42, userInfo: nil)

nse: Foundation.NSError = {

  Foundation.NSObject = {}

  _domain = "Foo"

  _code = 42

  _userInfo = nil

}

  5> let ae = AnyError(nse)

ae: Result.AnyError = {

  error = <extracting data from value failed>

}

Execution interrupted. Enter code to recover and continue.

Enter LLDB commands to investigate (type :help for assistance.)

  6>

So it looks like I have a Foundation on Linux bug? I will do what the
REPL suggests and see if I can figure out what's going on.

Thanks, Robert.

···

On Thu, 5 Jan 2017, at 18:13, Ankit Agarwal wrote:


(Ankit Agarwal) #4

Might be, please file a JIRA with a minimal test case!

···

On Fri, Jan 6, 2017 at 3:11 PM, Robert Atkins < ratkins+swift-users@fastmail.fm> wrote:

On Thu, 5 Jan 2017, at 18:13, Ankit Agarwal wrote:

Using swift module in REPL:

[...]

$ swift build
$ swift -I .build/debug -L .build/debug -lResult -I
/usr/lib/clang/3.8/include
Welcome to Swift version 3.1-dev (LLVM 217eb6c2b6, Clang 34a98ce92e, Swift
1eb5648c46). Type :help for assistance.
  1> import Result
  2> let a = Result<String, AnyError>("a")
a: Result.Result<String, Result.AnyError> = success {
  success = "a"
}

Oh wait, this works for me! It was the specific thing I was trying to do
(wrapping an NSError instance in an AnyError) that breaks which was leading
me to think importing the Result library into the REPL wasn't working:

$ swift -I.build/debug -L.build/debug -lResult

Welcome to Swift version 3.0.2 (swift-3.0.2-RELEASE). Type :help for
assistance.
  1> import Foundation
  2> import Result
  3> let r = Result<String, AnyError>("a")
r: Result.Result<String, Result.AnyError> = success {
  success = "a"
}
  4> let nse = NSError(domain: "Foo", code: 42, userInfo: nil)
nse: Foundation.NSError = {
  Foundation.NSObject = {}
  _domain = "Foo"
  _code = 42
  _userInfo = nil
}
  5> let ae = AnyError(nse)
ae: Result.AnyError = {
  error = <extracting data from value failed>

}
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)
  6>

So it looks like I have a Foundation on Linux bug? I will do what the REPL
suggests and see if I can figure out what's going on.

Thanks, Robert.

--
Ankit


(Robert Atkins) #5

As a first step I'm attempting to see if I get the same behaviour with
the latest Swift snapshot release but I'm having difficulty there too.
Simply downloading and un-tarring the Jan 4th snapshot and adding it to
my path (as described in https://swift.org/download/#using-downloads)
gets me a running swift 3.1-dev REPL but I can't import Foundation
because it doesn't know where to find its libs. I can't add them to the
library search paths with -F/-I/-L via the command line and invoke spm
at the same time to build Result either (see upthread).

Is there another environment variable I can use to set swift's framework
search path?

Cheers, Robert.

···

On Fri, 6 Jan 2017, at 09:45, Ankit Agarwal wrote:

Might be, please file a JIRA with a minimal test case!


(Ankit Agarwal) #6

Thats weird, you should be able to import Foundation from the toolchain

···

On Fri, Jan 6, 2017 at 4:28 PM, Robert Atkins < ratkins+swift-users@fastmail.fm> wrote:

On Fri, 6 Jan 2017, at 09:45, Ankit Agarwal wrote:

Might be, please file a JIRA with a minimal test case!

As a first step I'm attempting to see if I get the same behaviour with the
latest Swift snapshot release but I'm having difficulty there too. Simply
downloading and un-tarring the Jan 4th snapshot and adding it to my path
(as described in https://swift.org/download/#using-downloads) gets me a
running swift 3.1-dev REPL but I can't import Foundation because it doesn't
know where to find its libs. I can't add them to the library search paths
with -F/-I/-L via the command line and invoke spm at the same time to build
Result either (see upthread).

Is there another environment variable I can use to set swift's framework
search path?

Cheers, Robert.

--
Ankit


(Robert Atkins) #7

This is on Linux, so the toolchain stuff isn't relevant, is it?

Cheers, Robert.

···

On Fri, 6 Jan 2017, at 11:14, Ankit Agarwal wrote:

Thats weird, you should be able to import Foundation from the
toolchain


(Ankit Agarwal) #8

Yes you should be able to import Foundation in REPL using the latest
toolchain on linux. FWIW I am getting same error you are from latest
toolchain:

root@4027f71e87ff:/swiftpm# swift -I .build/debug -L .build/debug -lResult
-I /usr/lib/clang/3.8/include
Welcome to Swift version 3.1-dev (LLVM c3e057b06a, Clang 0540ceb7ad, Swift
093e275775). Type :help for assistance.
  1> import Foundation
  2> import Result
  3> let r = Result<String, AnyError>("a")
r: Result.Result<String, Result.AnyError> = success {
  success = "a"
}
  4> let nse = NSError(domain: "Foo", code: 42, userInfo: nil)
nse: Foundation.NSError = {
  Foundation.NSObject = {}
  _domain = "Foo"
  _code = 42
  _userInfo = nil
}
  5> let ae = AnyError(nse)
ae: Result.AnyError = {
  error = <extracting data from value failed>

}
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)
  6> ae
$R0: Result.AnyError = {
  error = {
    instance_type = 0x0000000000000000
  }
}

···

On Fri, Jan 6, 2017 at 5:50 PM, Robert Atkins < ratkins+swift-users@fastmail.fm> wrote:

On Fri, 6 Jan 2017, at 11:14, Ankit Agarwal wrote:

Thats weird, you should be able to import Foundation from the toolchain

This is on Linux, so the toolchain stuff isn't relevant, is it?

Cheers, Robert.

--
Ankit


(Robert Atkins) #9

Yes you should be able to import Foundation in REPL using the latest
toolchain on linux.

I couldn't get it to work, even after installing the snapshot via
swiftenv. I wonder what I'm doing wrong?

FWIW I am getting same error you are from latest toolchain:

Ah ok, thanks for that. I've filed the bug then:
https://bugs.swift.org/browse/SR-3565

Cheers, Robert.

···

On Fri, 6 Jan 2017, at 12:45, Ankit Agarwal wrote: