Commit 65a12ce2 authored by André Almeida's avatar André Almeida Committed by Thomas Gleixner
Browse files

selftests/futex: Refactor futex_requeue_pi_mismatched_ops with kselftest_harness.h



To reduce the boilerplate code, refactor futex_requeue_pi_mismatched_ops
test to use kselftest_harness header instead of futex's logging header.

Signed-off-by: default avatarAndré Almeida <andrealmeid@igalia.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent d060495a
Loading
Loading
Loading
Loading
+22 −64
Original line number Diff line number Diff line
@@ -23,67 +23,32 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "futextest.h"
#include "logging.h"

#define TEST_NAME "futex-requeue-pi-mismatched-ops"
#include "futextest.h"
#include "../../kselftest_harness.h"

futex_t f1 = FUTEX_INITIALIZER;
futex_t f2 = FUTEX_INITIALIZER;
int child_ret = 0;

void usage(char *prog)
{
	printf("Usage: %s\n", prog);
	printf("  -c	Use color\n");
	printf("  -h	Display this help message\n");
	printf("  -v L	Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
	       VQUIET, VCRITICAL, VINFO);
}

void *blocking_child(void *arg)
{
	child_ret = futex_wait(&f1, f1, NULL, FUTEX_PRIVATE_FLAG);
	if (child_ret < 0) {
		child_ret = -errno;
		error("futex_wait\n", errno);
		ksft_exit_fail_msg("futex_wait\n");
	}
	return (void *)&child_ret;
}

int main(int argc, char *argv[])
TEST(requeue_pi_mismatched_ops)
{
	int ret = RET_PASS;
	pthread_t child;
	int c;
	int ret;

	while ((c = getopt(argc, argv, "chv:")) != -1) {
		switch (c) {
		case 'c':
			log_color(1);
			break;
		case 'h':
			usage(basename(argv[0]));
			exit(0);
		case 'v':
			log_verbosity(atoi(optarg));
			break;
		default:
			usage(basename(argv[0]));
			exit(1);
		}
	}
	if (pthread_create(&child, NULL, blocking_child, NULL))
		ksft_exit_fail_msg("pthread_create\n");

	ksft_print_header();
	ksft_set_plan(1);
	ksft_print_msg("%s: Detect mismatched requeue_pi operations\n",
	       basename(argv[0]));

	if (pthread_create(&child, NULL, blocking_child, NULL)) {
		error("pthread_create\n", errno);
		ret = RET_ERROR;
		goto out;
	}
	/* Allow the child to block in the kernel. */
	sleep(1);

@@ -102,34 +67,27 @@ int main(int argc, char *argv[])
			 * FUTEX_WAKE.
			 */
			ret = futex_wake(&f1, 1, FUTEX_PRIVATE_FLAG);
			if (ret == 1) {
				ret = RET_PASS;
			} else if (ret < 0) {
				error("futex_wake\n", errno);
				ret = RET_ERROR;
			} else {
				error("futex_wake did not wake the child\n", 0);
				ret = RET_ERROR;
			}
			if (ret == 1)
				ret = 0;
			else if (ret < 0)
				ksft_exit_fail_msg("futex_wake\n");
			else
				ksft_exit_fail_msg("futex_wake did not wake the child\n");
		} else {
			error("futex_cmp_requeue_pi\n", errno);
			ret = RET_ERROR;
			ksft_exit_fail_msg("futex_cmp_requeue_pi\n");
		}
	} else if (ret > 0) {
		fail("futex_cmp_requeue_pi failed to detect the mismatch\n");
		ret = RET_FAIL;
		ksft_test_result_fail("futex_cmp_requeue_pi failed to detect the mismatch\n");
	} else {
		error("futex_cmp_requeue_pi found no waiters\n", 0);
		ret = RET_ERROR;
		ksft_exit_fail_msg("futex_cmp_requeue_pi found no waiters\n");
	}

	pthread_join(child, NULL);

	if (!ret)
		ret = child_ret;

 out:
	/* If the kernel crashes, we shouldn't return at all. */
	print_result(TEST_NAME, ret);
	return ret;
	if (!ret && !child_ret)
		ksft_test_result_pass("futex_requeue_pi_mismatched_ops passed\n");
	else
		ksft_test_result_pass("futex_requeue_pi_mismatched_ops failed\n");
}

TEST_HARNESS_MAIN
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ echo
./futex_requeue_pi

echo
./futex_requeue_pi_mismatched_ops $COLOR
./futex_requeue_pi_mismatched_ops

echo
./futex_requeue_pi_signal_restart $COLOR