From 3d89c0b95331323feafcf12181f44ca26bdeb96d Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Mon, 15 Jul 2019 12:22:50 -0700 Subject: 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 Reviewed-by: George Burgess --- compiler_wrapper/testutil_test.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'compiler_wrapper/testutil_test.go') 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 { -- cgit v1.2.3