Pass cwd and env to test command

Promote get cwd before test command running and pass cwd to test
command.

Fixes bug #1211606

Change-Id: I2e4d3258f6d591d3d0aadffcefa36487c9122023