Add test for CGI exec directory
chdir to the given CGI script path. Fix #338
Merge #368 with fixes.