Skip to content

Conversation

@hdwhdw
Copy link
Contributor

@hdwhdw hdwhdw commented Dec 17, 2025

  • Replaces 8 separate 'go test' invocations with a single, consolidated 'go test ./...' command.
  • Takes the union of all flags (-race, -timeout 20m, etc.) and environment variables to create a single, unified test run.
  • Simplifies the coverage processing logic by removing the loop and merge step, as only one 'coverage.txt' file is now generated.
  • This makes the 'check_gotest' target significantly cleaner and easier to maintain.

Why I did it

How I did it

How to verify it

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

- Replaces 8 separate 'go test' invocations with a single, consolidated 'go test ./...' command.
- Takes the union of all flags (-race, -timeout 20m, etc.) and environment variables to create a single, unified test run.
- Simplifies the coverage processing logic by removing the loop and merge step, as only one 'coverage.txt' file is now generated.
- This makes the 'check_gotest' target significantly cleaner and easier to maintain.

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
Copilot AI review requested due to automatic review settings December 17, 2025 20:09
@mssonicbld
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the check_gotest target in the Makefile to consolidate multiple separate go test invocations into a single command, simplifying the test execution and coverage processing logic.

  • Replaces 8 individual go test commands (one per package) with a single go test ./... command
  • Consolidates test flags (-race, -timeout, -covermode, etc.) into one unified test execution
  • Simplifies coverage processing by eliminating the merge loop for multiple coverage files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Makefile Outdated
Comment on lines 213 to 217
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(TESTENV) \
$(GO) test -race -v -mod=vendor -timeout 20m \
-covermode=atomic -coverprofile=coverage.txt -coverpkg=./... \
$(BLD_FLAGS) \
./...
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consolidation removes the conditional execution of dialout tests based on ENABLE_DIALOUT_VALUE. The original code only ran dialout tests when ENABLE_DIALOUT_VALUE != 0, but the new consolidated command runs all tests unconditionally. This means dialout tests will now run even when dialout is disabled (ENABLE_DIALOUT=n), which may cause test failures or incorrect behavior when the dialout feature is not enabled.

Copilot uses AI. Check for mistakes.
@mssonicbld
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Adds the '//go:build !test' build constraint to the pyang client
generator template (main.j2).

This prevents the flag definitions in the generated 'main' packages
from being included in test builds, which resolves the 'flag redefined'
panic when running 'go test ./...'. This change unblocks the
consolidation of the test commands in the Makefile.

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
This commit refactors the main test target ('check_gotest') to be
more scalable and robust, enabled by a fix to the code generator.

- **fix(pyang):** Adds a '//go:build !test' build constraint to the
  pyang client generator template (main.j2). This prevents flag
  definition conflicts when testing, unblocking test consolidation.

- **refactor(Makefile):** Replaces the 8 separate 'go test' commands
  in 'check_gotest' with a single 'go test ./...' command. It also
  simplifies the coverage processing logic to handle the single
  coverage profile generated by the unified test run.

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
@hdwhdw hdwhdw force-pushed the refactor/consolidate-tests branch from ed7965c to 54a20ee Compare December 17, 2025 23:01
@mssonicbld
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

- Replaces the hardcoded 'go test ./...' with a dynamically generated
  list of packages.
- Excludes known 'main' packages (executables like generated gNOI clients,
  gnmi_server, telemetry, etc.) that cause 'flag redefined' panics when
  tested together in a single 'go test' invocation.
- This ensures test consolidation is viable by testing only library
  packages together, while respecting the project's architecture.

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
@mssonicbld
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

- Wraps the 'go list | grep' pipeline in a '' function.
- This fixes a syntax error where the command string itself was being
  passed as an argument to 'go test', instead of the command's output.
- The command now correctly generates a list of packages and passes
  them to the test runner, enabling the consolidated test approach.

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
@mssonicbld
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
@mssonicbld
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

The INTEGRATION_PKGS variable calculation was failing because the
$(space) variable wasn't defined, causing $(subst $(space),|,$(PURE_PKGS))
to not work properly. This resulted in an empty package list being
passed to go test.

Added the standard GNU make space variable definition to fix the
package filtering and ensure all 15 integration packages are
properly included in check_gotest.

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
Replace the complex package filtering approach with an explicit list
of integration packages based on the master branch's check_gotest target.

This approach is cleaner because:
- Single source of truth (no duplication with pure.mk)
- Explicit and maintainable package list
- Based on proven implementation from master
- Eliminates complex shell filtering and space variable issues

Integration packages: telemetry, sonic_db_config, gnmi_server,
dialout_client, sonic_data_client, sonic_service_client,
transl_utils, gnoi_client/system.

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
@mssonicbld
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Add a new `check_junit` target that demonstrates individual test
results in Azure DevOps pipeline UI using JUnit XML format.

Changes:
- New `check_junit` Makefile target that uses gotestsum to generate
  JUnit XML files from Go test output
- Tests two pure packages (pkg/gnoi/debug, internal/hash) to show
  variety of test results including subtests and fuzz tests
- Integrated into azure-pipelines.yml with PublishTestResults@2 task
- Generates both test results and coverage files per package
- Results stored in build/bin/test-results/ directory

This enables the "Tests" tab in Azure DevOps to show:
- Individual test case results with timing
- Test failure details and stack traces
- Test trend analysis over time
- Ability to filter and search specific tests

Total of 91 test cases across the two packages demonstrate the
detailed reporting capability.

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
@mssonicbld
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Comment out check_gotest and check_memleak steps in azure-pipelines.yml
to make pipeline runs faster while demonstrating JUnit XML test reporting.

The focus is now on:
- Fast pure package tests (make -f pure.mk azure-coverage)
- JUnit XML generation (make check_junit)
- Test results publishing (PublishTestResults@2)

This provides a quick pipeline run that demonstrates the individual
test result reporting in Azure DevOps without the long integration
test execution time.

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
@mssonicbld
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants