tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/filesystems/mount-notify/mount-notify_test.c
Extension
.c
Size
11617 bytes
Lines
529
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 (i > 0) {
				// Groups 1,2 should get EAGAIN
				ASSERT_EQ(len, -1);
				ASSERT_EQ(errno, EAGAIN);
			} else {
				// Group 0 should get events
				ASSERT_GT(len, 0);
			}
		}

		self->rem = len;
		self->next = (void *) self->buf;
	}

	meta = self->next;
	ASSERT_TRUE(FAN_EVENT_OK(meta, self->rem));

	thislen = meta->event_len;
	self->rem -= thislen;
	self->next += thislen;

	*mask = meta->mask;
	thislen -= sizeof(*meta);

	mnt = ((void *) meta) + meta->event_len - thislen;

	ASSERT_EQ(thislen, sizeof(*mnt));

	return mnt->mnt_id;
}

static void expect_notify_n(struct __test_metadata *const _metadata,
				 FIXTURE_DATA(fanotify) *self,
				 unsigned int n, uint64_t mask[], uint64_t mnts[])
{
	unsigned int i;

	for (i = 0; i < n; i++)
		mnts[i] = expect_notify(_metadata, self, &mask[i]);
}

static uint64_t expect_notify_mask(struct __test_metadata *const _metadata,
				   FIXTURE_DATA(fanotify) *self,
				   uint64_t expect_mask)
{
	uint64_t mntid, mask;

	mntid = expect_notify(_metadata, self, &mask);
	ASSERT_EQ(expect_mask, mask);

	return mntid;
}


static void expect_notify_mask_n(struct __test_metadata *const _metadata,
				 FIXTURE_DATA(fanotify) *self,
				 uint64_t mask, unsigned int n, uint64_t mnts[])
{
	unsigned int i;

	for (i = 0; i < n; i++)
		mnts[i] = expect_notify_mask(_metadata, self, mask);
}

static void verify_mount_ids(struct __test_metadata *const _metadata,
			     const uint64_t list1[], const uint64_t list2[],
			     size_t num)
{
	unsigned int i, j;

	// Check that neither list has any duplicates
	for (i = 0; i < num; i++) {
		for (j = 0; j < num; j++) {
			if (i != j) {
				ASSERT_NE(list1[i], list1[j]);
				ASSERT_NE(list2[i], list2[j]);
			}
		}
	}
	// Check that all list1 memebers can be found in list2. Together with
	// the above it means that the list1 and list2 represent the same sets.
	for (i = 0; i < num; i++) {
		for (j = 0; j < num; j++) {
			if (list1[i] == list2[j])
				break;
		}
		ASSERT_NE(j, num);
	}
}

Annotation

Implementation Notes