Clean producer and consumer env var between tests

We have different types of integration tests:
1. Some talk to a system tracing service started by the test itself on a
   custom socket. E.g. src/tracing/test/api_integrationtest.cc
2. Some want to talk to the real system tracing service on android. E.g.
   test/android_integrationtest.cc

Type 1 tests change PERFETTO_*_SOCK_NAME environment variables, in order
to redirect consumer and producer to the "testing" service. They don't
restore the previous values of the environment variables though.

Today (by chance?) we execute type 2 tests before type 1 in
perfetto_integrationtests. r.android.com/2203568 added a type 1 test
that was executed before the type 2 tests. The type 2 tests started
failing because suddenly they were redirected to the "testing" service
instead of the real one, because the type 1 tests were leaking the
environment variables.

This commit fixes the problem by restoring the previous values for the
environment variables on each test TearDown().

In one case (src/tracing/test/api_test_support.cc), this is not as
straightforward, because the code caches the "testing" server among
different test executions.

Tested by running `atest perfetto_integrationtests` with or without
r.android.com/2203568

Change-Id: I935d6a8fe964c039ad7f804ec1498466ba701a03
7 files changed
tree: 5af8284fcfef469a246b4d5682f6f1cd05fb29ac
  1. .github/
  2. bazel/
  3. build_overrides/
  4. buildtools/
  5. debian/
  6. docs/
  7. examples/
  8. gn/
  9. include/
  10. infra/
  11. protos/
  12. python/
  13. src/
  14. test/
  15. tools/
  16. ui/
  17. .clang-format
  18. .clang-tidy
  19. .gitattributes
  20. .gitignore
  21. .gn
  22. .style.yapf
  23. Android.bp
  24. Android.bp.extras
  25. BUILD
  26. BUILD.extras
  27. BUILD.gn
  28. CHANGELOG
  29. codereview.settings
  30. DIR_METADATA
  31. heapprofd.rc
  32. LICENSE
  33. meson.build
  34. METADATA
  35. MODULE_LICENSE_APACHE2
  36. OWNERS
  37. perfetto.rc
  38. PerfettoIntegrationTests.xml
  39. PRESUBMIT.py
  40. README.chromium
  41. README.md
  42. TEST_MAPPING
  43. traced_perf.rc
  44. WORKSPACE
README.md

Perfetto - System profiling, app tracing and trace analysis

Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis. It offers services and libraries and for recording system-level and app-level traces, native + java heap profiling, a library for analyzing traces using SQL and a web-based UI to visualize and explore multi-GB traces.

See https://perfetto.dev/docs or the /docs/ directory for documentation.