Vc6.0 Memory leakage detection tool

Source: Internet
Author: User

In this article, I will introduce in detail how to use the test tool numbench devpartner (numbench.

Numbench is a dynamic testing tool mainly used in white box testing. The tool features simple learning, convenient use, and effective functions. Numbench has three independent sub-functions: boundschecker, truecoverage, and truetime. Boundschecker is the code error checking tool, truecoverage is the test coverage rate statistics tool, and truetime is the program running performance testing tool.

This article introduces how to use the three sub-functions of numbench in three chapters. The content of each part is independent. If you want to know the functions of numbench, it is recommended to read this article to block all content. If you only want to know the information about a subfunction provided by numbench, view the corresponding chapters in the directory.

One thing to note is that numbench, the test tool described in this document, specifically numbench for Visual C ++, is used for numbench for Visual Basic and numbench for Delphi, this is beyond the scope of this article. Please note that.

2 Installation

Numbench is easy to install. Click setup.exe to install the numega installation program. No special settings are required during installation.

However, before installing numbench, make sure that visual C ++ has been installed on your machine, only in this way can numbench be successfully integrated into the visual C ++ development environment.

Now, we will introduce how to use boundschecker, truecoverage, and truetime in three parts.

3 boundschecker

Boundschecker is a run-time error detection tool that mainly locates various errors that occur during running of a program. Boundschecker can detect the following errors:

1) 1. pointer operation and memory and resource leakage errors, such:

Memory leakage;

Resource leakage;

Incorrect operation on Pointer variables.

22. Memory Operation errors, such:

Memory read/write overflow;

Use uninitialized memory.

33. API function usage Error

After the boundschecker is successfully installed, a menu named boundschecker is displayed in your VC ++ integrated development environment, as shown below:

Figure 3-1 menu added by boundschecker in VC ++ integrated development environment

Boundschecker has been fully integrated into the VC ++ integrated development environment.

You can use boundschecker to detect running errors in two modes. One mode is activecheck, And the other mode is finalcheck. The following is an introduction.

3.1 activecheck

Activecheck is a convenient and fast error detection mode provided by boundschecker. It can detect a limited number of error types, including memory leakage errors, resource leakage errors, and API function usage errors.

To detect program running errors in activecheck mode, you only need to enable the boundschecker function in the VC ++ integrated development environment, and then run the program from the debugging status. In this case, activecheck runs automatically in the background and checks whether an error occurs in the program at any time. The following describes the procedure.

3.1.1 use activecheck to detect errors

Follow these steps to use activecheck:

First, open the program you want to test in the VC ++ integrated development environment, and ensure that the project is in the debug Compiling state.

In the VC ++ integrated development environment, make sure that the [boundschecker/Integrated debugging] menu items and [boundschecker/report errors and events] menu items are in the selected status. Only when these two items are selected will the boundschecker play a role in the running process.

Finally, select the [Build/start debug/go] menu command in the integrated development environment of VC ++, run the program in the debug state, and activecheck starts running in the background.

In this case, you can operate the program according to the developed test cases. Activecheck records any code that has been executed by the program if an error exists.

There is a [report errors immediately] in the [boundschecker] menu, as shown in:

Figure 3-2 menu items about [boundschecker/report errors immediately]

This menu item has the same effect on the activecheck mode and the finalcheck mode described below. That is, if this option is not selected, the boundschecker records various errors found during the program running, the report will be reported after the program ends. When this menu item is selected, the following dialog box will pop up immediately when the boundschecker finds an error during the program running:

Figure 3-3 Error Report Dialog Box

The buttons in the dialog box are described as follows:

Button 1: click this button to ignore this error and continue executing the program.

Button 2: click this button to jump to the problematic code line immediately. After the problem is solved, click the [Build/start debug/go] menu to continue executing the program for detection.

Button 3: click this button to add the error to the ignored error list. If this problem occurs again, the boundschecker will not report it.

Button 4: click this button to terminate the program execution immediately.

Button 5: click this button to display the current memory application and usage.

Button 6: click this button to get the help information for the current error.

Buttons 7 and 8: The two buttons have the same functions as the [boundschecker/report errors immediately] and [boundschecker/report errors and event] menu commands.

Button 9: click this button to display/hide the function call stack related to the error and the location of the specific error code line.

Whether to select the [boundschecker/report errors immediately] menu item depends on your own preferences and the specific conditions during the test. If you want the boundschecker to report the detected errors to you in real time during the program running, select this menu item. If you want to wait until the operation ends, in addition, you do not have to select this menu item if you analyze the errors detected by the boundschecker during the operation. In general, I prefer the latter one.

3.1.2 Analysis Error

After you finish all the operations and exit the program,

The boundschecker displays a list of detected errors. We need to analyze the errors listed in the List to determine the cause and location of the errors.

In the error detection result list, all memory leaks, resource leaks, and API function usage errors detected by activecheck during program execution are listed. As shown in:

Figure 3-4 error detection results

In the left-side window, the program's memory, resources, and API function usage problems are listed one by one, including: the type of the problem, the number of times the problem occurs, and if the problem is caused by memory leakage, how much memory is lost and the code location where the problem occurs. When you click and select a record, the function call stack corresponding to the error record is displayed in the window on the right. When you double-click an error record, the source code that causes the error is located.

Now, how to use boundschecker in activecheck mode is complete. Is it easy?

When detecting a program in activecheck mode, the running speed of the program is basically not affected, but its disadvantage is that the types of errors detected are limited, you can only check for Memory leakage errors, resource leakage errors, and API function usage errors. Boundschecker provides another mode for detecting errors-finalcheck, that is, the second mode of boundschecker we mentioned earlier. Finalcheck can detect more errors in the program. Next we will introduce it.

3.2 use finalcheck to detect more errors

Finalcheck has all error checking functions provided by boundschecker. Finalcheck is a superset of activecheck. In addition to detecting errors that can be detected by activecheck, it can also discover many errors that cannot be detected by activecheck, including: pointer operation errors, Memory Operation overflow, use of uninitialized memory, and so on. finalcheck can provide more detailed information about errors that can be detected by activecheck. Therefore, we can regard finalcheck as the enhanced feature version of activecheck. The price we pay is that the program runs slowly, sometimes even slowly.

To test a program in finalcheck mode, you must use the compile connector provided by the integrated development environment of VC ++ to construct the program. Instead, you must use the compile connector provided by boundschecker to compile the Connection Program. When the boundschecker compilation connector compiles the Connection Program, it inserts some error detection code into the program, which is the reason why finalcheck can find more errors than activecheck.

Next

This section describes how to test a program in finalcheck mode:

1. Open the project you want to test in the VC ++ integrated development environment.

2. To use the compilation connector of boundschecker to re-compile the Connection Program, we construct a folder for boundschecker. In the integrated development environment of VC ++, the specific operation method is as follows:

A) Click the [Build/deployments...] menu command.

B) Click the Add button in the pop-up dialog box. Add the name of the folder you created for the boundschecker in the configuration editing box. This name is arbitrary. For example, we can name it boundchecker.

C) In the copy settings from combo box, selectXXX-Win32 debug itemClick OK, and then click Close.

Now, we have constructed a folder for finalcheck.

3. Click [Build/set Active configuration…]. Menu command, select the folder you just created for boundschecker, and click OK. In this way, the intermediate files and executable programs generated when the boundschecker compiles the Connection Program will be put in this folder.

4. Select the [boundschecker/rebuild all with boundschecker] menu command to recompile and connect the program. That is, the boundschecker adds an error detection code to the code of the program under test. After the compilation connection is complete, the boundschecker will generate an executable file in the folder you constructed for the boundschecker.

In finalcheck mode, all the preparations for detecting the program are ready. At this time, you can start the program to start testing,

The procedure is no different from that in activechecker mode. The procedure is as follows:

  1. Make sure that the [boundschecker/Integrated debugging] menu items and [boundschecker/report errors and events] menu items are selected in the VC ++ integrated development environment.
  2. Click the [Build/start debug] menu and select the "go" menu item. The program starts to run in the debug state.
  3. Operate the program according to the test cases you have developed.
  4. When the boundschecker detects an error, a window will pop up to report it to you. You can handle it at that time, or wait until all your operations are completed, after exiting the program, analyze the listed errors. This depends entirely on whether you have selected the [boundschecker/report errors immediately] menu item.
  5. After exiting the program, the boundschecker will provide a list of error detection results. The error list is the same as that shown in activechecker. However, the information reported in this list is more and more detailed.

Now, the use of boundschecker in finalcheck mode is also completed. Activechecker and finalcheck modes have different lengths in comparison. Activechecker is easy to use. You only need to run the program directly in the debug state, and the program runs fast, but the types of errors detected are limited. In finalcheck mode, you need to use the compilation connector of boundschecker to re-compile the connection to generate executable programs, and the program runs slowly. However, the types of errors detected and error-related information provided are more than activechecker. Therefore, when to use the mode should be determined based on the specific circumstances at that time.

3.3 check the compatibility of Win32 API functions

Boundschecker also provides a function to check the compatibility of Win32 API functions used in programs on different platforms. This function is independent of the activechecker and finalcheck modes mentioned above.

Although most Win32 API functions are applicable to Windows operating systems such as Win95, Win98, Win2000, and WinNT, not all API functions meet this situation. You may unconsciously Use API functions that are allowed on a platform but not on another platform. The project requirements are as follows: programs can run on these two platforms. Boundschecker provides this function to check the compatibility of Win32 API functions and can handle this problem.

This function is used as follows:

Start the [boundschecker/View/compliance report] menu command, as shown in:

Figure 3-5 enable the Win32 API function compatibility check function

The following window is displayed:

Figure 3-6win32 API function compatibility check

In the dialog box, select the platform that the program promises to run and other standards (Standard C and Standard C for expansion) to be followed, and click "OK, boundchecker provides a compatibility detection report.

3.4 ignore errors

In some cases, we need to ignore some errors reported by the boundschecker, including:

1. false positive. A code segment in the boundschecker specified program has an error, but after careful check, it is confirmed that the program does not have this error, which is a false positive of the boundschecker. After all, a tool is a tool. It can only act according to the algorithm it has developed, so there will be false positives. However, do not identify an error as a false positive easily. You must carefully analyze the error to identify it as a false positive.

2. Third-Party code. The error location specified by boundschecker is in the Code provided by a third party, including libraries, DLL, and OCX provided by a third party. In this case, we should first make a careful check to make sure that it is not caused by our incorrect use of third-party code. If it is not our reason, such an error report can be ignored.

3.5 others

Another point that needs to be emphasized is that the source code of the program is required when boundschecker is used to test the program. Without the source code, although boundschecker can open the EXE file and execute it, the test results are often incorrect, so it does not make much sense.

In addition to using boundchecker in the VC ++ integrated development environment, start boundchecker from the [Start Menu] and open the executable file generated by the boundchecker compilation connection, you can also test the program. The operation method is the same as that of boundchecker integrated into the VC ++ integrated development environment.

Now, all the functions provided by boundchecker are described.

4 truecoverage

Coverage is an important data for testing. After we have executed all the test cases for a functional module, we would like to know the coverage of the module code, that is, the test coverage rate, to determine whether the test can be completed. If the test target is not reached, how can we further supplement the test case.

To solve these problems, it is almost impossible to do it manually without the help of coverage statistics tools.

The function of truecoverage is to calculate the test coverage rate, which can help us solve the problem above. The coverage rate provided by truecoverage is "statement coverage", which is the coverage rate with the lowest coverage intensity. Therefore, we should try to reach 100% coverage after using truecoverage for our testing project.

The application phase of truecoverage is the unit test phase and the integration test phase.

Like boundchecker, after truecoverage is installed successfully, a menu named truecoverage is displayed in your VC ++ integrated development environment, as shown in:

Figure 4-1 menu added by truecoverage in the VC ++ integrated development environment

This indicates that truecoverage has been fully integrated into the VC ++ integrated development environment.

The following describes how to use truecoverage.

4.1 Use Truecoverage

To use truecoverage, follow these steps:

1. Open the project you want to test in the integrated development environment of VC ++.

2. Construct a folder for truecoverage:

First, click the [Build/deployments...] menu command.

Click Add in the pop-up dialog box.

Then, enter the name of the folder you created for truecoverage in the configuration editing box. This name is arbitrary, for example, truecoverage.

Finally, selectXXX-Win32 debug itemClick OK, and then click Close.

Now, we have constructed a folder for truecoverage.

3. Click [Build/set Active configuration…]. Menu command, select the folder you just created for truecoverage, and click OK.

4. Select the [truecoverage/rebuild all with truecoverage] menu command and recompile the program using the truecoverage compilation connector. The intermediate files and executable programs generated when the program is compiled and connected by truecoverage will be placed in the folder you just created for truecoverage. During this compilation connection, truecoverage inserts some information into the executable program, which is why truecoverage can track and measure test coverage.

5. Click the [truecoverage/run with truecoverage] menu command. truecoverage is started and then your program is executed. Now we can execute the test cases one by one in the program according to the prepared test cases. truecoverage will record the program execution coverage in the background.

There is a tool bar in the truecoverage interface. We need to explain it here. As follows:

Figure 4-2 Running Control Toolbar

After the tool bar is running, it changes from unavailable to available. The buttons on the toolbar are as follows:

Button 1: If you press this button during the running of the program, the coverage rate is calculated only here. You can continue to operate the program, however, no operations on the program are included in the coverage rate statistics.

Button 2: If you press this button while the program is running, truecoverage immediately displays the test coverage rate as of now. Then you can continue to operate the program. truecoverage will continue to record the program execution overwrite in the background.

Button 3: If you press this button during the running of the program, truecoverage will clear the overwrite data before this, so that the data of each coverage is zero. You can continue with the operation. truecoverage record the program execution coverage from scratch in the background.

6. When you exit the program, truecoverage will display the execution coverage of the program after the operation is completed, including: the coverage of the entire executable program, the coverage of each code file, and the coverage of each function in each code file can be saved as a file. To execute the program again, click the [Program/start] menu command in truecoverage.

We are unlikely to execute all the test cases at a time. Truecoverage reminds us of this. Every time we use truecoverage to run the program, execute some use cases, close the program, and save the coverage rate statistics, truecoverage will ask if you want to merge the test results into the total coverage rate statistical results. Generally, we can merge them.

The following describes the truecoverage interface, which is described by numbers in the figure.

Figure 4-3 running interface of truecoverage

1: indicates the test coverage after a program is executed. Double-click an entry to display details about this coverage rate in the window in sections 3 and 4. In this figure, the tester executes the program twice.

2: indicates the current total test coverage of the program. It is the result of merging multiple ones. Double-click the entry to display details about the total coverage in the window in sections 3 and 4.

3: The data displayed in this window corresponds to the overwrite statistical results of one or more tests you selected (1 and 2 as mentioned above ). The data displayed in this window includes program coverage and coverage of each code file. More detailed information is displayed in Window 4.

4: The data displayed in this window corresponds to your selection in window 3, showing the test coverage of each function. Double-click a function, and the source code of the function is displayed. truecoverage uses different colors to identify the executed and unexecuted code, as shown in:

Figure 4-4 truecoverage identifies executed and unexecuted code with different colors

By default, truecoverage uses green to represent executed code, and red to represent unexecuted code, use black to indicate unexecutable code (you can select the [Program/setting] menu command of truecoverage and set it on the Setting tab in the startup dialog box to change this default situation ). With this information, we can add and modify use cases to improve test coverage.

4.2 handling of inline functions

Although inline functions are in the form of functions, their mechanisms are completely different from those of functions. Therefore, different approaches are required for inline functions when using truecoverage to measure test coverage.

By default, truecoverage does not count the execution coverage of inline functions. If you need to obtain the coverage data of inline functions, You need to perform some additional settings. The specific method is to select [truecoverage/truecoverage setting...] In the integration environment of VC ++. menu command. The following dialog box is displayed:

Figure 4-5 inline function settings

Select the instrument Inline Function check box and click OK.

Then select the [truecoverage/rebuild all with truecoverage] menu command to re-compile the connection. For this executable program, truecoverage can record the coverage data of inline functions during its execution.

4.3 truecoverage and Combined Use of boundschecker

Truecoverage andBoundschecker can be used in combination. In [boundschecker] and [Truecoverage] Under the menu, there is a [rebuild with boundschecker and truecoverage.Boundschecker (finalcheck) detection results.

However, there is a limitation here: it must be opened by the boundchecker to execute the EXE program, or run the EXE through debug in the VC ++ integrated development environment. In this way, after the program is executed, the truecoverage andBoundschecker (finalcheck) detection result,If you use truecoverage to execute a program, only the truecoverage detection result is obtained. Note This.

4.4 others

Like boundschecker, to use truecoverage, you must have the source code of the program to be tested. Without source code, truecoverage cannot calculate coverage.

In addition to using truecoverage in the integrated environment of VC ++, start truecoverage from the [Start Menu] and open the executable file generated by the truecoverage compilation connection, you can also perform coverage rate statistics. The operation method is the same as that of truecoverage integrated into the VC ++ integrated development environment.

The use of truecoverages has ended. This tool is useful for testing coverage rate statistics and complementing test cases.

5 truetime

How to Improve code running efficiency is an important issue in the development process. The running speed of an application is slow, but it is difficult to find out what is wrong. Therefore, finding the performance bottleneck is the key to adjusting the code performance. Truetime is a tool that analyzes the Running Performance of applications and finds program performance bottlenecks.

Truetime can collect and display data related to the application program running performance. The data includes the running performance of each module (such as EXE, DLL, and OCX), and the running performance of each function, for the source code, truetime also provides the running performance of each line of code. With this data, we can determine the performance bottleneck of the system and further optimize the program performance.

It is worth mentioning that truetime uses a technology called "quantum" to collect application program performance data. The "quantum" technology is used to separate the running time of the threads in the application you test from the running time of the threads of other applications running simultaneously in the operating system. That is to say, truetime only calculates the time slice that is spent on the thread of your application. In this way, the performance test results for the same application on the same computer will not change because of the number of programs running in the computer system. Therefore, as long as the hardware conditions of the program run remain unchanged, the truetime test results will remain unchanged. Therefore, the truetime test results can be reproduced.

After truetime is installed successfully, a menu named truetime will be displayed in your VC ++ integrated development environment, as shown in:

Figure 5-1 menu added by truetime in the VC ++ integrated development environment

This indicates that truetime has been fully integrated into the VC ++ integrated development environment.

The following describes how to use truetime.

5.1 use truetime

How to Use truetime:

1. Open the project you want to test in the VC ++ integrated development environment.

2. Construct a folder for truetime:

First, click the [Build/deployments...] menu command.

Click Add in the pop-up dialog box.

Then, enter the name of the folder you created for truetime in the configuration editing box. This name is arbitrary. For example, we name it truetime.

Finally, selectXXX-Win32 debug itemClick OK, and then click Close.

Now, we have constructed a folder for truetime.

3. Click [Build/set Active configuration…]. Menu command, select the folder you just created for truetime, and click OK.

4. Select the [truetime/rebuild all with truetime] menu command and use the truetime compilation connector to re-compile the program. The intermediate files and executable programs generated by the truetime compilation and connection will be put in the folder you created for truetime. During this compilation connection, truetime inserts some information into the executable program, which is why truetime can record program running performance.

5. Click the [truetime/run with truetime] menu command. The truetime is started, and then your program is started and executed.

In this case, the test cases are executed according to the prepared test cases. Truetime records the performance data of the executed program code.

There is a tool bar in the truetime interface. It looks exactly the same as the tool bar we mentioned in truecoverage and implements the same functions. It only controls coverage in truecoverage, here, it controls performance data. Let's explain it now. As follows:

Figure 5-2 Running Control Toolbar

After the tool bar is running, it changes from unavailable to available. The buttons on the toolbar are as follows:

Button 1: If you press this button during the running of the program, the performance statistics are only calculated here, although you can continue to operate the program, however, any operations on the program are not included in the Performance Statistics.

Button 2: If you press this button during the running of the program, truetime will immediately display the performance statistics as of now. Then you can continue to operate the program. truetime will continue to record the program performance data in the background.

Button 3: If you press this button while the program is running, truetime clears the previously recorded performance data so that the performance data is zero. You can continue to record the performance data of the program from scratch in the background.

6. When you exit the program, truetime displays the execution performance data of the modules, functions, and code lines that are executed during this operation. To start a new Performance Statistics for the program, click the [Program/start] menu command in truetime.

The truetime detection result interface is as follows:

Figure 5-3 running interface of truetime

Area 1:

Lists multiple performance detection results that are obtained after the application is run for multiple times. Double-click an item to display detailed performance data of the application during this operation in area 2 and Area 3.

Region 2:

The data displayed in this window corresponds to a one-time detection function in area 1. The data displayed in the window is displayed in units of modules (such as EXE and DLL). It lists the performance data of each module during a program execution. The detailed performance data of each module is displayed in Area 3.

Area 3:

The data displayed in this window corresponds to your selection in area 2 and displays the performance data of each function in the module. There are three tabs in Area 3: function List tab, source tab, and Session Summary tab. Each tab lists a set of performance data. In fact, we need to use truetime, that is, to understand the meaning of these performance data. The following explains the meaning of performance data on the tab:

Function List tab

On the Function List tab, double-click a function with the left mouse button. A dialog box is displayed, as shown in:

Figure 5-4 dialog box for viewing performance data

In this dialog box, you can view the performance information of the parent function (the function that calls the function) and subfunction (the function called by the function) of the function.

The function List tab lists the performance data of the functions contained in the selected module. The data includes:

Function name -- function name.

% In function -- this is a percentage. The numerator is the execution time of the function, and the denominator is the time from the start to the end of the system.

% With children -- this is a percentage of the time when the numerator executes the function, including the running time of the subfunction called in the function, the denominator is the time from the start to the end of the system.

Called: the number of times a function is called during this execution.

Image-the name of the module where the function is located (the module refers to EXE, DLL, ocx, etc ).

% In Image -- this is a percentage. The numerator is the execution time of the function, and the denominator is the execution time of the module where the function is located (exe, DLL, OCX.

Average: the average execution time of a function when it is run multiple times, excluding the running time of the sub-function called by the function.

First -- the time it takes to execute the function for the first time.

Minimum -- the minimum time spent in multiple executions of a function.

Maximum-the time used for the longest execution of the function.

Average with children -- average execution time when a function is executed multiple times, including the time when the function is called.

Real -- average execution time of the function, including the time when the sub-function called by the function runs. In addition, it also includes the time spent on the threads of other applications that run simultaneously in the system.

Address -- function entry address.

Source Tab

The "Source" tab lists the performance data of each line of program code contained in the specified source file of the selected module. The data includes:

Count -- the number of times this row of code is executed during the test.

% Of function -- this is a percentage. The numerator is the time when the code of the row is executed, and the denominator is the time when the function is executed.

% With children -- this is also a percentage. The numerator is the time when the code is executed, and the denominator is the time when the system starts running and ends.

Time -- the sum of the running time of the code of the row during system running.

Functions -- number of functions called by this line of code.

Line # -- the row number of the Code.

Source -- source code.

Session Summary Tab

The session summarye tab lists the summary of this performance statistics, which is well understood and will not be detailed here.

Truetime provides four different units for performance data: CPU clock cycle, delicate, millisecond, and second. You can use the [view/scale] menu item in truetime to set it as follows:

Figure 5-5 performance data unit settings menu

In the menu, the performance data is displayed in the unit of time.

5.2 others

Truetime can collect runtime performance data without source code (such as third-party DLL and OCX), but if we want to obtain detailed runtime performance data of a module, you still need the source code of this module.

In addition to using truetime in the VC ++ integrated environment, you can start truetime from the [Start Menu] and then open the executable file generated by the truetime compilation connection, you can also collect performance data in the same way as the truetime method integrated into the VC ++ integrated development environment.

The introduction of truetime is over.

6. End

Now, the usage of the three sub-functions of numbench for Visual C ++-boundchecker, truecoverage, and truetime have been described. What we should do now is to use numbench to test the program and learn more about this white box testing tool in practice.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.