Source Code Coverage Tracking with Private Variable Instrumentation

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Manual participation of skilled personnel is required to obtain code coverage, increasing costs and complexity in obtaining code coverage metrics for source code quality assessment.

Innovation Solution

A method and apparatus that automatically adds private variables to methods not executed in the source code to record execution, enabling automated code coverage measurement without modifying startup commands, and allowing parallel testing across multiple devices.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If manual participation of skilled personnel is used to obtain code coverage, then code coverage measurement can be performed, but labor costs and operational complexity increase

Engineering Contradiction:
Improvecode coverage measurementVSAvoidmanual participation requirement
Core Design Contradiction:
Measurement precisionVSEase of operation

Solution Approach 1:

The code coverage measurement system performs self-service by automatically adding private variables to methods and recording execution status without requiring manual intervention. The system autonomously instruments the source code, executes tests, and generates coverage reports, eliminating the need for skilled personnel to manually perceive and record the measurement process.

Inventive Principle:
Principle #25Self-service

Solution Approach 2:

The patent introduces private variables as intermediaries to track code execution. These private variables act as mediators between the code execution process and the coverage measurement system, automatically recording whether each code statement is executed without requiring manual observation or intervention.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Measurement precision

If private variable is added before test execution, then code coverage can be recorded, but startup commands and instrumentation scenarios become complex

Engineering Contradiction:
Improvecode coverage recordingVSAvoidinstrumentation scenario complexity
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The system performs preliminary action by adding private variables to all methods in advance before test execution begins. This preliminary instrumentation ensures that when code is executed during testing, the private variables are already in place to record execution status, eliminating the need for complex runtime instrumentation scenarios.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent changes the parameter of variable visibility by using private variables within methods to track execution. This parameter change allows the system to record coverage information internally without affecting the external interface or startup commands, simplifying the overall instrumentation scenario.

Inventive Principle:
Principle #35Parameter changes

3Productivity

If automated code coverage measurement is implemented, then labor costs are reduced, but handling methods executing during private variable addition becomes difficult

Engineering Contradiction:
Improveautomation levelVSAvoidcode execution tracking
Core Design Contradiction:
ProductivityVSReliability

Solution Approach 1:

The system performs preliminary action by adding private variables to all methods before test execution begins. This preliminary instrumentation ensures that when code is executed during testing, the private variables are already in place to record execution status, eliminating the need for complex runtime instrumentation scenarios.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent ensures continuity of useful action by maintaining private variables throughout the entire test execution process. The private variables continuously record execution status from the beginning to the end of test execution, ensuring no code coverage information is lost even when methods are executed concurrently during the instrumentation phase.

Inventive Principle:
Principle #20Continuity of useful action

Data Source

PatentEP4675442A1Method and apparatus for processing source code, and storage medium
Publication Date: 2026.01.07 HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
  • EP4675442A1 patent drawingFigure 1~2
  • EP4675442A1 patent drawingFigure 3
  • EP4675442A1 patent drawingFigure 4

AI summary

This application discloses a source code processing method and apparatus, and a storage medium, and pertains to the computer field. The method includes: receiving an instruction for starting a code test, and adding a private variable to at least one first method included in first source code, where the at least one first method is a method that is not executed in the first source code, and the private variable in the first method is used to record execution of each code statement in the first method when the first method is executed; when a test on the first source code is completed by using a first test case, obtaining first code coverage information based on the private variable in the at least one first method, where the first code coverage information describes execution of a code statement in the at least one first method; and displaying a first code coverage result based on the first code coverage information, where the first code coverage result includes code coverage of the first source code. According to this application, the code coverage is automatically obtained, so that costs are reduced.