diff options
author | Tobias Bosch <tbosch@google.com> | 2019-07-15 12:22:50 -0700 |
---|---|---|
committer | Tobias Bosch <tbosch@google.com> | 2019-07-18 09:09:26 +0000 |
commit | 3d89c0b95331323feafcf12181f44ca26bdeb96d (patch) | |
tree | ebbbb6cdae92f550a642aaf9d3c9f4432bb847db /compiler_wrapper/testutil_test.go | |
parent | 198a3c9519e5d93ffeb8f5e1b6694c34b178c5c4 (diff) | |
download | toolchain-utils-3d89c0b95331323feafcf12181f44ca26bdeb96d.tar.gz |
Create golden tests for sysroot wrapper.
- Golden files can be updated via the new "-updategolden" test flag.
- Golden files contain the wrapper command, commands executed by the wrapper
stdout, stderr, exitcode of the wrapper
- The commands in the golden files are also compared to the old wrapper
to make sure they are correct. We are also mocking less things in
the old wrapper now, allowing to compare against differnet wrappers via
golden tests in the future (e.g. clang_host_wrapper).
- Unit tests are no longer diffing against the old wrapper.
BUG=chromium:773875
TEST=unit test
Change-Id: I0755bfe11cd499474820c9354412d39a0fa04401
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1702633
Tested-by: Tobias Bosch <tbosch@google.com>
Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'compiler_wrapper/testutil_test.go')
-rw-r--r-- | compiler_wrapper/testutil_test.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/compiler_wrapper/testutil_test.go b/compiler_wrapper/testutil_test.go index 07d84b36..0ffe8d71 100644 --- a/compiler_wrapper/testutil_test.go +++ b/compiler_wrapper/testutil_test.go @@ -25,11 +25,9 @@ const gccArmV7Eabi = "./armv7m-cros-linux-eabi-gcc" const gccArmV8 = "./armv8m-cros-linux-gnu-gcc" const gccArmV8Eabi = "./armv8m-cros-linux-eabi-gcc" -const oldHardenedWrapperPathForTest = "/usr/x86_64-pc-linux-gnu/x86_64-cros-linux-gnu/gcc-bin/4.9.x/sysroot_wrapper.hardened" -const oldNonHardenedWrapperPathForTest = "/usr/x86_64-pc-linux-gnu/arm-none-eabi/gcc-bin/4.9.x/sysroot_wrapper" - type testContext struct { t *testing.T + wd string tempDir string env []string cfg *config @@ -51,13 +49,12 @@ func withTestContext(t *testing.T, work func(ctx *testContext)) { ctx := testContext{ t: t, + wd: tempDir, tempDir: tempDir, env: nil, cfg: &config{}, } - // Note: It's ok to use the hardened wrapper here, as we replace its config - // on each run. - ctx.updateConfig(oldHardenedWrapperPathForTest, &config{}) + ctx.updateConfig("", &config{}) work(&ctx) } @@ -79,7 +76,7 @@ func (ctx *testContext) environ() []string { } func (ctx *testContext) getwd() string { - return ctx.tempDir + return ctx.wd } func (ctx *testContext) stdout() io.Writer { @@ -141,10 +138,9 @@ func (ctx *testContext) mustFail(exitCode int) string { func (ctx *testContext) updateConfig(wrapperChrootPath string, cfg *config) { *ctx.cfg = *cfg - ctx.cfg.overwriteOldWrapperCfg = true ctx.cfg.mockOldWrapperCmds = true ctx.cfg.newWarningsDir = filepath.Join(ctx.tempDir, "fatal_clang_warnings") - if *crosRootDirFlag != "" { + if *crosRootDirFlag != "" && wrapperChrootPath != "" { ctx.cfg.oldWrapperPath = filepath.Join(*crosRootDirFlag, wrapperChrootPath) } else { ctx.cfg.oldWrapperPath = "" @@ -248,8 +244,12 @@ func verifyNoEnvUpdate(cmd *command, expectedRegex string) error { return nil } +func hasInternalError(stderr string) bool { + return strings.Contains(stderr, "Internal error") +} + func verifyInternalError(stderr string) error { - if !strings.Contains(stderr, "Internal error") { + if !hasInternalError(stderr) { return fmt.Errorf("expected an internal error. Got: %s", stderr) } if ok, _ := regexp.MatchString(`\w+.go:\d+`, stderr); !ok { @@ -259,7 +259,7 @@ func verifyInternalError(stderr string) error { } func verifyNonInternalError(stderr string, expectedRegex string) error { - if strings.Contains(stderr, "Internal error") { + if hasInternalError(stderr) { return fmt.Errorf("expected a non internal error. Got: %s", stderr) } if ok, _ := regexp.MatchString(`\w+.go:\d+`, stderr); ok { |