Bug 1675288 - Move FOG's tests into a 'tests' folder r=TravisLong

Differential Revision: https://phabricator.services.mozilla.com/D120015
This commit is contained in:
Chris H-C 2021-07-20 14:33:49 +00:00
parent 693b965fdd
commit 4f178c3f77
39 changed files with 53 additions and 57 deletions

View File

@ -64,7 +64,7 @@ documenting the compatibility in
If you add a GIFFT mirror, don't forget to test that the mirror works.
You should be able to do this by adding a task to
[`toolkit/components/glean/xpcshell/test_GIFFT.js`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/xpcshell/test_GIFFT.js).
[`toolkit/components/glean/tests/xpcshell/test_GIFFT.js`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/tests/xpcshell/test_GIFFT.js).
## Rust
@ -164,14 +164,14 @@ Each metric type has six pieces you'll need to cover:
Two languages means two test suites.
- Add a never-expiring test-only metric of your type to
[`test_metrics.yaml`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/test_metrics.yaml).
[`test_metrics.yaml`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/tests/test_metrics.yaml).
- Feel free to be clever with the name,
but be sure to make clear that it is test-only.
- **C++ Tests (GTest)** - Add a small test case to
[`gtest/TestFog.cpp`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/gtest/TestFog.cpp).
[`gtest/TestFog.cpp`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/tests/gtest/TestFog.cpp).
- For more details, peruse the [testing docs](testing.md).
- **JS Tests (xpcshell)** - Add a small test case to
[`xpcshell/test_Glean.js`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/xpcshell/test_Glean.js).
[`xpcshell/test_Glean.js`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/tests/xpcshell/test_Glean.js).
- For more details, peruse the [testing docs](testing.md).
### 7. API Documentation

View File

@ -7,12 +7,11 @@ testing FOG is a matter of choosing the right tool for the situation.
To run all the things, here's the tl;dr:
`MOZ_LOG="timestamp,sync,glean::*:5,fog::*:5,fog_control::*:5,glean_core::*:5"
./mach build && ./mach lint -Ww -o --fix
`./mach build && ./mach lint -Ww -o --fix
&& ./mach lint --linter clippy toolkit/components/glean/api/src
&& ./mach rusttests && ./mach gtest FOG*
&& python3 ./mach python-test toolkit/components/glean/pytest
&& ./mach test toolkit/components/glean/xpcshell
&& python3 ./mach python-test toolkit/components/glean/tests/pytest
&& ./mach test toolkit/components/glean/tests/xpcshell
&& ./mach telemetry-tests-client toolkit/components/telemetry/tests/marionette/tests/client/test_fog* --gecko-log "-"`
## Logging
@ -92,18 +91,18 @@ Because Gecko symbols aren't built for the
`rusttests` build,
any test that is written for code that uses Gecko symbols should be written as a
[`gtest`](https://github.com/google/googletest)
in `toolkit/components/glean/gtest/`.
in `toolkit/components/glean/tests/gtest/`.
You can write the actual test code in Rust.
It needs to be accompanied by a C++ GTest that calls a C FFI-exported Rust function.
See [Testing & Debugging Rust Code](/testing-rust-code/) for more.
See [`toolkit/components/glean/gtest/TestFog.cpp`](https://searchfox.org/mozilla-central/source/toolkit/components/glean/gtest/TestFog.cpp)
and [`toolkit/components/glean/gtest/test.rs`](https://searchfox.org/mozilla-central/source/toolkit/components/glean/gtest/test.rs)
See [`toolkit/components/glean/tests/gtest/TestFog.cpp`](https://searchfox.org/mozilla-central/source/toolkit/components/glean/tests/gtest/TestFog.cpp)
and [`toolkit/components/glean/tests/gtest/test.rs`](https://searchfox.org/mozilla-central/source/toolkit/components/glean/tests/gtest/test.rs)
for an example.
By necessity these can only be integration tests against the compiled crate.
**Note:** When adding a new test file, don't forget to add it to
`toolkit/components/glean/gtest/moz.build` and use the
`toolkit/components/glean/tests/gtest/moz.build` and use the
`FOG` prefix in your test names
(e.g. `TEST(FOG, YourTestName) { ... }`).
@ -115,18 +114,18 @@ The [Glean Parser](https://github.com/mozilla/glean_parser/)
has been augmented to generate FOG-specific APIs for Glean metrics.
This augmentation is tested by running:
`mach test toolkit/components/glean/pytest`
`mach test toolkit/components/glean/tests/pytest`
These tests require Python 3+.
If your default Python is Python 2, you may need to instead run:
`python3 mach python-test toolkit/components/glean/pytest`
`python3 mach python-test toolkit/components/glean/tests/pytest`
These tests check the code generator output against known good file contents.
If you change the code generator the files will need an update.
Run the test suite with the `UPDATE_EXPECT` environment variable set to do that automatically:
`UPDATE_EXPECT=1 mach test toolkit/components/glean/pytest`
`UPDATE_EXPECT=1 mach test toolkit/components/glean/tests/pytest`
## C++ (Treeherder symbol `GTest` (a build task))
@ -134,11 +133,11 @@ To test the C++ parts of FOG's implementation
(like metric types)
you should use `gtest`.
FOG's `gtest` tests are in
[`gtest/`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/gtest/).
[`gtest/`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/tests/gtest/).
You can either add a test case to an existing file or add a new file.
If you add a new file, remember to add it to the
[`moz.build`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/gtest/moz.build))
[`moz.build`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/tests/gtest/moz.build))
or the test runner won't be able to find it.
All tests should start with `FOG` so that all tests are run with
@ -150,15 +149,15 @@ To test the JS parts of FOG's implementation
(like metric types)
you should use `xpcshell`.
FOG's `xpcshell` tests are in
[`xpcshell/`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/xpcshell).
[`xpcshell/`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/tests/xpcshell).
You can either add a test case to an existing file or add a new file.
If you add a new file, remember to add it to the
[`xpcshell.ini`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/xpcshell/xpcshell.ini)
[`xpcshell.ini`](https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/glean/tests/xpcshell/xpcshell.ini)
or the test runner will not be able to find it.
To run FOG's JS tests, run:
`./mach test toolkit/components/glean/xpcshell`
`./mach test toolkit/components/glean/tests/xpcshell`
## Integration (Marionette, borrowing `telemetry-tests-client` Treeherder symbol `tt(c)`)

View File

@ -8,7 +8,7 @@
# New additions should be added to the bottom of the list.
metrics_yamls = [
"toolkit/components/glean/metrics.yaml",
"toolkit/components/glean/test_metrics.yaml",
"toolkit/components/glean/tests/test_metrics.yaml",
"toolkit/mozapps/update/metrics.yaml",
"browser/base/content/metrics.yaml",
]
@ -17,6 +17,6 @@ metrics_yamls = [
# New additions should be added to the bottom of the list.
pings_yamls = [
"toolkit/components/glean/pings.yaml",
"toolkit/components/glean/test_pings.yaml",
"toolkit/components/glean/tests/test_pings.yaml",
"toolkit/mozapps/update/pings.yaml",
]

View File

@ -6,10 +6,6 @@
SPHINX_TREES["/toolkit/components/glean"] = "docs"
PYTHON_UNITTEST_MANIFESTS += [
"pytest/python.ini",
]
# Needed so that we can include IPC things.
include("/ipc/chromium/chromium-config.mozbuild")
@ -90,12 +86,6 @@ SOURCES += [
"!EventExtraGIFFTMaps.cpp",
]
TEST_DIRS += [
"gtest",
]
XPCSHELL_TESTS_MANIFESTS += ["xpcshell/xpcshell.ini"]
# Provides us the list of dependent metrics|pings.yaml.
include("metrics_index.py")
# GeneratedFile's `inputs` are relative to our dir.
@ -194,6 +184,7 @@ GeneratedFile(
)
DIRS += [
"tests", # Must be in DIRS, not TEST_DIRS or python-test won't find it.
"xpcom",
]

View File

@ -6,7 +6,7 @@ license = "MPL-2.0"
description = "Tests for the FOG crate"
[dependencies]
fog = { path = "../api" }
fog = { path = "../../api" }
[lib]
path = "test.rs"

View File

@ -0,0 +1,14 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
PYTHON_UNITTEST_MANIFESTS += ["pytest/python.ini"]
TEST_DIRS += ["gtest"]
XPCSHELL_TESTS_MANIFESTS += ["xpcshell/xpcshell.ini"]
with Files("**"):
BUG_COMPONENT = ("Toolkit", "Telemetry")

View File

@ -11,7 +11,9 @@ import sys
from expect_helper import expect
# Shenanigans to import the FOG glean_parser runner
FOG_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir))
FOG_ROOT_PATH = path.abspath(
path.join(path.dirname(__file__), path.pardir, path.pardir)
)
sys.path.append(path.join(FOG_ROOT_PATH, "build_scripts", "glean_parser_ext"))
import run_glean_parser

View File

@ -11,7 +11,9 @@ import sys
from expect_helper import expect
# Shenanigans to import the cpp outputter extension
FOG_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir))
FOG_ROOT_PATH = path.abspath(
path.join(path.dirname(__file__), path.pardir, path.pardir)
)
sys.path.append(path.join(FOG_ROOT_PATH, "build_scripts", "glean_parser_ext"))
import cpp

View File

@ -11,7 +11,9 @@ import sys
from expect_helper import expect
# Shenanigans to import the js outputter extension
FOG_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir))
FOG_ROOT_PATH = path.abspath(
path.join(path.dirname(__file__), path.pardir, path.pardir)
)
sys.path.append(path.join(FOG_ROOT_PATH, "build_scripts", "glean_parser_ext"))
import js

View File

@ -12,7 +12,9 @@ import sys
from expect_helper import expect
# Shenanigans to import the rust outputter extension
FOG_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir))
FOG_ROOT_PATH = path.abspath(
path.join(path.dirname(__file__), path.pardir, path.pardir)
)
sys.path.append(path.join(FOG_ROOT_PATH, "build_scripts", "glean_parser_ext"))
import run_glean_parser
import rust

View File

@ -8,7 +8,9 @@ from pathlib import Path
import sys
# Shenanigans to import the metrics index's list of metrics.yamls
FOG_ROOT_PATH = path.abspath(path.join(path.dirname(__file__), path.pardir))
FOG_ROOT_PATH = path.abspath(
path.join(path.dirname(__file__), path.pardir, path.pardir)
)
sys.path.append(FOG_ROOT_PATH)
from metrics_index import metrics_yamls

View File

@ -1,12 +1,6 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* FIXME: Remove these global markers.
* FOG doesn't follow the stricter naming patterns as expected by tool configuration yet.
* See https://searchfox.org/mozilla-central/source/.eslintrc.js#24
* Reorganizing the directory structure will take this into account.
*/
/* global add_task, Assert, do_get_profile */
"use strict";
Cu.importGlobalProperties(["Glean"]);

View File

@ -1,12 +1,6 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* FIXME: Remove these global markers.
* FOG doesn't follow the stricter naming patterns as expected by tool configuration yet.
* See https://searchfox.org/mozilla-central/source/.eslintrc.js#24
* Reorganizing the directory structure will take this into account.
*/
/* global add_task, Assert, do_get_profile */
"use strict";
Cu.importGlobalProperties(["Glean", "GleanPings"]);

View File

@ -1,12 +1,6 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* FIXME: Remove these global markers.
* FOG doesn't follow the stricter naming patterns as expected by tool configuration yet.
* See https://searchfox.org/mozilla-central/source/.eslintrc.js#24
* Reorganizing the directory structure will take this into account.
*/
/* global add_task, Assert, do_get_profile, run_test_in_child, runningInParent */
"use strict";
Cu.importGlobalProperties(["Glean", "GleanPings"]);

View File

@ -45,7 +45,7 @@ nsstring-gtest = { path = "../../../../xpcom/rust/gtest/nsstring" }
xpcom-gtest = { path = "../../../../xpcom/rust/gtest/xpcom" }
gkrust-shared = { path = "../../rust/shared" }
gecko-fuzz-targets = { path = "../../../../tools/fuzzing/rust", optional = true }
fog-gtest = { path = "../../../components/glean/gtest" }
fog-gtest = { path = "../../../components/glean/tests/gtest" }
# Workarounds for https://github.com/rust-lang/rust/issues/58393
mozglue-static = { path = "../../../../mozglue/static/rust" }