Runtime Function Override for Legacy Code Testing
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Legacy source code in programming languages like C++ often lacks reflection, making it difficult to abstract dependencies and test specific parts of the code without modifying the source or setting up complex test environments.
Innovation Solution
A computer system is configured to override the original behavior of a function at runtime without changing its source code. This is achieved by identifying an override behavior, encoding replacement code, and manipulating memory addresses to execute the replacement code temporarily before restoring the original code.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of operation
If source code modification is used to enable testing of legacy code, then testability is improved, but code integrity and reliability deteriorate
Solution Approach 1:
The patent introduces an intermediary layer (runtime override mechanism) between the test framework and the legacy code. This intermediary allows testing functionality to be injected without modifying the original source code, thus maintaining code integrity while enabling comprehensive testing capabilities through runtime behavior overriding.
2Manufacturing precision
If complex test environments are set up to test legacy code, then test coverage is improved, but system complexity deteriorate
Solution Approach 1:
The patent changes the parameter of code behavior at runtime rather than requiring complex test environment setups. By dynamically overriding function behaviors and return values during execution, the system achieves high test coverage through simple parameter modifications instead of complex environmental configurations.
3Adaptability or versatility
If runtime code modification is performed to override function behavior, then flexibility and testability are improved, but system stability deteriorates
Solution Approach 1:
The patent performs preliminary actions by saving the original function behavior before overriding it at runtime. This preliminary preservation allows the system to maintain stability by enabling easy restoration of original behavior, thus reducing the risks associated with runtime modifications while maintaining flexibility during testing.
Data Source
AI summary
A computer system is configured to override an original behavior of a function at runtime. Overriding the original behavior of the function at runtime includes identifying an override behavior for overriding the original behavior of the function, and encoding replacement code based on the override behavior. Further, a size of the replacement code is identified, and a first memory address of the function where code of the function is stored is also identified. The computer system then copies a block of code having the size of the replacement code from the first memory address to a second memory address, and copies the replacement code to the first memory address. After the replacement code is executed, copying the block of code stored at the second memory address back to the first memory address, restoring the code of the function.


