mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 08:33:30 +00:00
Organize companion code and materials by book part: part-01/ Foundations part-02/ Kernel & driver fundamentals part-03/ Character & block devices part-04/ Networking & storage part-05/ Buses & advanced topics part-06/ Debugging & performance part-07/ Real-world drivers appendices/ Supplementary material README.md Overview and build instructions
42 lines
918 B
C
42 lines
918 B
C
/*-
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*
|
|
* stress_probe: loop open() and close() on a device node many times.
|
|
* Used as a rough correctness and leak test for the per-open state
|
|
* path in Chapter 8.
|
|
*
|
|
* Usage:
|
|
* stress_probe [path] [iterations]
|
|
*
|
|
* Default: path=/dev/myfirst/0, iterations=1000.
|
|
*
|
|
* Compile:
|
|
* cc -Wall -Werror -o stress_probe stress_probe.c
|
|
*/
|
|
|
|
#include <err.h>
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
const char *path = (argc > 1) ? argv[1] : "/dev/myfirst/0";
|
|
int iters = (argc > 2) ? atoi(argv[2]) : 1000;
|
|
int i, fd;
|
|
|
|
if (iters < 1)
|
|
errx(1, "iterations must be >= 1");
|
|
|
|
for (i = 0; i < iters; i++) {
|
|
fd = open(path, O_RDWR);
|
|
if (fd < 0)
|
|
err(1, "open (iter %d)", i);
|
|
if (close(fd) != 0)
|
|
err(1, "close (iter %d)", i);
|
|
}
|
|
printf("%d iterations completed\n", iters);
|
|
return (0);
|
|
}
|