kernel/irq/irq_test.c

Source file repositories/reference/linux-study-clean/kernel/irq/irq_test.c

File Facts

System
Linux kernel
Corpus path
kernel/irq/irq_test.c
Extension
.c
Size
5720 bytes
Lines
237
Domain
Core OS
Bucket
Scheduler, Processes, Timers, Sync, And Syscalls
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

static void noop(struct irq_data *data) { }
static unsigned int noop_ret(struct irq_data *data) { return 0; }

static int noop_affinity(struct irq_data *data, const struct cpumask *dest,
			 bool force)
{
	irq_data_update_effective_affinity(data, dest);

	return 0;
}

static struct irq_chip fake_irq_chip = {
	.name           = "fake",
	.irq_startup    = noop_ret,
	.irq_shutdown   = noop,
	.irq_enable     = noop,
	.irq_disable    = noop,
	.irq_ack        = noop,
	.irq_mask       = noop,
	.irq_unmask     = noop,
	.irq_set_affinity = noop_affinity,
	.flags          = IRQCHIP_SKIP_SET_WAKE,
};

static int irq_test_setup_fake_irq(struct kunit *test, struct irq_affinity_desc *affd)
{
	struct irq_desc *desc;
	int virq;

	virq = irq_domain_alloc_descs(-1, 1, 0, NUMA_NO_NODE, affd);
	KUNIT_ASSERT_GE(test, virq, 0);

	irq_set_chip_and_handler(virq, &fake_irq_chip, handle_simple_irq);

	desc = irq_to_desc(virq);
	KUNIT_ASSERT_PTR_NE(test, desc, NULL);

	/* On some architectures, IRQs are NOREQUEST | NOPROBE by default. */
	irq_settings_clr_norequest(desc);

	return virq;
}

static void irq_disable_depth_test(struct kunit *test)
{
	struct irq_desc *desc;
	int virq, ret;

	virq = irq_test_setup_fake_irq(test, NULL);

	desc = irq_to_desc(virq);
	KUNIT_ASSERT_PTR_NE(test, desc, NULL);

	ret = request_irq(virq, noop_handler, 0, "test_irq", NULL);
	KUNIT_ASSERT_EQ(test, ret, 0);

	KUNIT_EXPECT_EQ(test, desc->depth, 0);

	disable_irq(virq);
	KUNIT_EXPECT_EQ(test, desc->depth, 1);

	enable_irq(virq);
	KUNIT_EXPECT_EQ(test, desc->depth, 0);

	free_irq(virq, NULL);
}

static void irq_free_disabled_test(struct kunit *test)
{
	struct irq_desc *desc;
	int virq, ret;

	virq = irq_test_setup_fake_irq(test, NULL);

	desc = irq_to_desc(virq);
	KUNIT_ASSERT_PTR_NE(test, desc, NULL);

	ret = request_irq(virq, noop_handler, 0, "test_irq", NULL);
	KUNIT_ASSERT_EQ(test, ret, 0);

	KUNIT_EXPECT_EQ(test, desc->depth, 0);

	disable_irq(virq);
	KUNIT_EXPECT_EQ(test, desc->depth, 1);

	free_irq(virq, NULL);
	KUNIT_EXPECT_GE(test, desc->depth, 1);

	ret = request_irq(virq, noop_handler, 0, "test_irq", NULL);
	KUNIT_ASSERT_EQ(test, ret, 0);

Annotation

Implementation Notes