tools/testing/selftests/kcmp/kcmp_test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/kcmp/kcmp_test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/kcmp/kcmp_test.c
Extension
.c
Size
3619 bytes
Lines
169
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (fd2 < 0) {
			perror("Can't open file");
			ksft_exit_fail();
		}

		/* An example of output and arguments */
		printf("pid1: %6d pid2: %6d FD: %2ld FILES: %2ld VM: %2ld "
		       "FS: %2ld SIGHAND: %2ld IO: %2ld SYSVSEM: %2ld "
		       "INV: %2ld\n",
		       pid1, pid2,
		       sys_kcmp(pid1, pid2, KCMP_FILE,		fd1, fd2),
		       sys_kcmp(pid1, pid2, KCMP_FILES,		0, 0),
		       sys_kcmp(pid1, pid2, KCMP_VM,		0, 0),
		       sys_kcmp(pid1, pid2, KCMP_FS,		0, 0),
		       sys_kcmp(pid1, pid2, KCMP_SIGHAND,	0, 0),
		       sys_kcmp(pid1, pid2, KCMP_IO,		0, 0),
		       sys_kcmp(pid1, pid2, KCMP_SYSVSEM,	0, 0),

			/* This one should fail */
		       sys_kcmp(pid1, pid2, KCMP_TYPES + 1,	0, 0));

		/* This one should return same fd */
		ret = sys_kcmp(pid1, pid2, KCMP_FILE, fd1, fd1);
		if (ret) {
			printf("FAIL: 0 expected but %d returned (%s)\n",
				ret, strerror(errno));
			ksft_inc_fail_cnt();
			ret = -1;
		} else {
			printf("PASS: 0 returned as expected\n");
			ksft_inc_pass_cnt();
		}

		/* Compare with self */
		ret = sys_kcmp(pid1, pid1, KCMP_VM, 0, 0);
		if (ret) {
			printf("FAIL: 0 expected but %d returned (%s)\n",
				ret, strerror(errno));
			ksft_inc_fail_cnt();
			ret = -1;
		} else {
			printf("PASS: 0 returned as expected\n");
			ksft_inc_pass_cnt();
		}

		/* Compare epoll target */
		epoll_slot = (struct kcmp_epoll_slot) {
			.efd	= epollfd,
			.tfd	= duped_num,
			.toff	= 0,
		};
		ret = sys_kcmp(pid1, pid1, KCMP_EPOLL_TFD, pipefd[1],
			       (unsigned long)(void *)&epoll_slot);
		if (ret) {
			printf("FAIL: 0 expected but %d returned (%s)\n",
				ret, strerror(errno));
			ksft_inc_fail_cnt();
			ret = -1;
		} else {
			printf("PASS: 0 returned as expected\n");
			ksft_inc_pass_cnt();
		}


		if (ret)
			ksft_exit_fail();
		else
			ksft_exit_pass();
	}

	waitpid(pid2, &status, P_ALL);

	return 0;
}

Annotation

Implementation Notes