// SPDX-License-Identifier: GPL-2.0-only
/*
 * KUnit tests for cpumask.
 *
 * Author: Sander Vanheule <sander@svanheule.net>
 */

#include <kunit/test.h>
#include <linux/cpu.h>
#include <linux/cpumask.h>

#define MASK_MSG(m) \
	"%s contains %sCPUs %*pbl", #m, (cpumask_weight(m) ? "" : "no "), \
	nr_cpumask_bits, cpumask_bits(m)

#define EXPECT_FOR_EACH_CPU_EQ(test, mask)			\
	do {							\
		const cpumask_t *m = (mask);			\
		int mask_weight = cpumask_weight(m);		\
		int cpu, iter = 0;				\
		for_each_cpu(cpu, m)				\
			iter++;					\
		KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(mask));	\
	} while (0)

#define EXPECT_FOR_EACH_CPU_OP_EQ(test, op, mask1, mask2)			\
	do {									\
		const cpumask_t *m1 = (mask1);					\
		const cpumask_t *m2 = (mask2);					\
		int weight;                                                     \
		int cpu, iter = 0;						\
		cpumask_##op(&mask_tmp, m1, m2);                                \
		weight = cpumask_weight(&mask_tmp);				\
		for_each_cpu_##op(cpu, mask1, mask2)				\
			iter++;							\
		KUNIT_EXPECT_EQ((test), weight, iter);				\
	} while (0)

#define EXPECT_FOR_EACH_CPU_WRAP_EQ(test, mask)			\
	do {							\
		const cpumask_t *m = (mask);			\
		int mask_weight = cpumask_weight(m);		\
		int cpu, iter = 0;				\
		for_each_cpu_wrap(cpu, m, nr_cpu_ids / 2)	\
			iter++;					\
		KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(mask));	\
	} while (0)

#define EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, name)		\
	do {							\
		int mask_weight = num_##name##_cpus();		\
		int cpu, iter = 0;				\
		for_each_##name##_cpu(cpu)			\
			iter++;					\
		KUNIT_EXPECT_EQ_MSG((test), mask_weight, iter, MASK_MSG(cpu_##name##_mask));	\
	} while (0)

static cpumask_t mask_empty;
static cpumask_t mask_all;
static cpumask_t mask_tmp;

static void test_cpumask_weight(struct kunit *test)
{
	KUNIT_EXPECT_TRUE_MSG(test, cpumask_empty(&mask_empty), MASK_MSG(&mask_empty));
	KUNIT_EXPECT_TRUE_MSG(test, cpumask_full(&mask_all), MASK_MSG(&mask_all));

	KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_weight(&mask_empty), MASK_MSG(&mask_empty));
	KUNIT_EXPECT_EQ_MSG(test, nr_cpu_ids, cpumask_weight(cpu_possible_mask),
			    MASK_MSG(cpu_possible_mask));
	KUNIT_EXPECT_EQ_MSG(test, nr_cpu_ids, cpumask_weight(&mask_all), MASK_MSG(&mask_all));
}

static void test_cpumask_first(struct kunit *test)
{
	KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_first(&mask_empty), MASK_MSG(&mask_empty));
	KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_first(cpu_possible_mask), MASK_MSG(cpu_possible_mask));

	KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_first_zero(&mask_empty), MASK_MSG(&mask_empty));
	KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_first_zero(cpu_possible_mask),
			    MASK_MSG(cpu_possible_mask));
}

static void test_cpumask_last(struct kunit *test)
{
	KUNIT_EXPECT_LE_MSG(test, nr_cpumask_bits, cpumask_last(&mask_empty),
			    MASK_MSG(&mask_empty));
	KUNIT_EXPECT_EQ_MSG(test, nr_cpu_ids - 1, cpumask_last(cpu_possible_mask),
			    MASK_MSG(cpu_possible_mask));
}

static void test_cpumask_next(struct kunit *test)
{
	KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_next_zero(-1, &mask_empty), MASK_MSG(&mask_empty));
	KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_next_zero(-1, cpu_possible_mask),
			    MASK_MSG(cpu_possible_mask));

	KUNIT_EXPECT_LE_MSG(test, nr_cpu_ids, cpumask_next(-1, &mask_empty),
			    MASK_MSG(&mask_empty));
	KUNIT_EXPECT_EQ_MSG(test, 0, cpumask_next(-1, cpu_possible_mask),
			    MASK_MSG(cpu_possible_mask));
}

static void test_cpumask_iterators(struct kunit *test)
{
	EXPECT_FOR_EACH_CPU_EQ(test, &mask_empty);
	EXPECT_FOR_EACH_CPU_WRAP_EQ(test, &mask_empty);
	EXPECT_FOR_EACH_CPU_OP_EQ(test, and, &mask_empty, &mask_empty);
	EXPECT_FOR_EACH_CPU_OP_EQ(test, and, cpu_possible_mask, &mask_empty);
	EXPECT_FOR_EACH_CPU_OP_EQ(test, andnot, &mask_empty, &mask_empty);

	EXPECT_FOR_EACH_CPU_EQ(test, cpu_possible_mask);
	EXPECT_FOR_EACH_CPU_WRAP_EQ(test, cpu_possible_mask);
	EXPECT_FOR_EACH_CPU_OP_EQ(test, and, cpu_possible_mask, cpu_possible_mask);
	EXPECT_FOR_EACH_CPU_OP_EQ(test, andnot, cpu_possible_mask, &mask_empty);
}

static void test_cpumask_iterators_builtin(struct kunit *test)
{
	EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, possible);

	/* Ensure the dynamic masks are stable while running the tests */
	cpu_hotplug_disable();

	EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, online);
	EXPECT_FOR_EACH_CPU_BUILTIN_EQ(test, present);

	cpu_hotplug_enable();
}

static int test_cpumask_init(struct kunit *test)
{
	cpumask_clear(&mask_empty);
	cpumask_setall(&mask_all);

	return 0;
}

static struct kunit_case test_cpumask_cases[] = {
	KUNIT_CASE(test_cpumask_weight),
	KUNIT_CASE(test_cpumask_first),
	KUNIT_CASE(test_cpumask_last),
	KUNIT_CASE(test_cpumask_next),
	KUNIT_CASE(test_cpumask_iterators),
	KUNIT_CASE(test_cpumask_iterators_builtin),
	{}
};

static struct kunit_suite test_cpumask_suite = {
	.name = "cpumask",
	.init = test_cpumask_init,
	.test_cases = test_cpumask_cases,
};
kunit_test_suite(test_cpumask_suite);

MODULE_DESCRIPTION("KUnit tests for cpumask");
MODULE_LICENSE("GPL");
