C test coverage in C IS will teach you how to use it
Software Test Coverage: The Key to Ensuring Code Quality
In software development, testing is crucial, and it ensures that the software runs as expected. The test coverage further ensures the comprehensiveness of the test and ensures that all branches and paths of the code are tested. Many modern programming languages provide libraries or tools to generate test coverage reports, but did you know that C also has a "native" tool?
Let's start with a simple C function that returns ±42:
<code class="c">#include <stdbool.h> int return_42(bool ret_neg) { if (ret_neg) return -42; return 42; }</stdbool.h></code>
The corresponding test code is as follows:
<code class="c">#include <assert.h> #include <stdbool.h> #include <stdio.h> int return_42(bool ret_neg); int main() { assert(return_42(false) == 42); assert(return_42(true) == -42); puts("Nice"); return 0; }</stdio.h></stdbool.h></assert.h></code>
Generate test coverage reports using GCC/G
We can use the GCC/G compiler and its related tools to generate test coverage reports. The compilation process requires the use of -fprofile-arcs
and -ftest-coverage
flags:
- Compile: Use the above flags to compile the code, which will generate an executable file and
.gcno
file. - Run test: Execute the compiled and generated test program. This generates a
.gcda
file after execution is finished. - Generate report (gcov): Use the
gcov
tool to process.gcda
and.gcno
files, and generate.gcov
files.gcov
will provide a simple coverage summary.
To view coverage results more intuitively, we can use the lcov
tool:
- Install lcov: Install
lcov
tools. - Collect data: Use
lcov -c -d . -o foobar.info
to collect coverage data. - Generate report: Use
lcov -l foobar.info
to generate more detailed reports. - Visual report (genhtml): Use
genhtml foobar.info -o bar_html
to generate HTML-formatted reports for easy viewing. This will generate a folder containing the visual coverage report.
Use genhtml
to generate highly customized reports, adjusting their appearance and content through various parameters.
Hope the above information will be helpful to you!
The above is the detailed content of C test coverage in C IS will teach you how to use it. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

Backup and Recovery Policy of GitLab under CentOS System In order to ensure data security and recoverability, GitLab on CentOS provides a variety of backup methods. This article will introduce several common backup methods, configuration parameters and recovery processes in detail to help you establish a complete GitLab backup and recovery strategy. 1. Manual backup Use the gitlab-rakegitlab:backup:create command to execute manual backup. This command backs up key information such as GitLab repository, database, users, user groups, keys, and permissions. The default backup file is stored in the /var/opt/gitlab/backups directory. You can modify /etc/gitlab

Complete Guide to Checking HDFS Configuration in CentOS Systems This article will guide you how to effectively check the configuration and running status of HDFS on CentOS systems. The following steps will help you fully understand the setup and operation of HDFS. Verify Hadoop environment variable: First, make sure the Hadoop environment variable is set correctly. In the terminal, execute the following command to verify that Hadoop is installed and configured correctly: hadoopversion Check HDFS configuration file: The core configuration file of HDFS is located in the /etc/hadoop/conf/ directory, where core-site.xml and hdfs-site.xml are crucial. use

Enable PyTorch GPU acceleration on CentOS system requires the installation of CUDA, cuDNN and GPU versions of PyTorch. The following steps will guide you through the process: CUDA and cuDNN installation determine CUDA version compatibility: Use the nvidia-smi command to view the CUDA version supported by your NVIDIA graphics card. For example, your MX450 graphics card may support CUDA11.1 or higher. Download and install CUDAToolkit: Visit the official website of NVIDIACUDAToolkit and download and install the corresponding version according to the highest CUDA version supported by your graphics card. Install cuDNN library:

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

The command to restart the SSH service is: systemctl restart sshd. Detailed steps: 1. Access the terminal and connect to the server; 2. Enter the command: systemctl restart sshd; 3. Verify the service status: systemctl status sshd.

PyTorch distributed training on CentOS system requires the following steps: PyTorch installation: The premise is that Python and pip are installed in CentOS system. Depending on your CUDA version, get the appropriate installation command from the PyTorch official website. For CPU-only training, you can use the following command: pipinstalltorchtorchvisiontorchaudio If you need GPU support, make sure that the corresponding version of CUDA and cuDNN are installed and use the corresponding PyTorch version for installation. Distributed environment configuration: Distributed training usually requires multiple machines or single-machine multiple GPUs. Place
